Skip to content
Snippets Groups Projects
Commit 60ab534c authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#87] Render bunny with mesh shader

parent 4d5ec8ef
No related branches found
No related tags found
1 merge request!74Resolve "Mesh Shader Implementation"
Pipeline #26257 passed
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
#extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require #extension GL_NV_mesh_shader : require
layout(local_size_x=32) in; layout(local_size_x=30) in;
layout(triangles) out; layout(triangles) out;
layout(max_vertices=64, max_primitives=126) out; layout(max_vertices=30, max_primitives=10) out;
layout( push_constant ) uniform constants{ layout( push_constant ) uniform constants{
mat4 mvp; mat4 mvp;
...@@ -15,8 +15,8 @@ layout(location = 0) out vec3 passNormal[]; ...@@ -15,8 +15,8 @@ layout(location = 0) out vec3 passNormal[];
struct Vertex struct Vertex
{ {
vec3 position; vec3 position; float padding0;
vec3 normal; vec3 normal; float padding1;
}; };
layout(std430, binding = 0) readonly buffer vertexBuffer layout(std430, binding = 0) readonly buffer vertexBuffer
...@@ -29,20 +29,26 @@ layout(std430, binding = 1) readonly buffer indexBuffer ...@@ -29,20 +29,26 @@ layout(std430, binding = 1) readonly buffer indexBuffer
uint indices[]; // breaks for 16 bit indices uint indices[]; // breaks for 16 bit indices
}; };
taskNV in Task {
uint baseID;
} IN;
void main() { void main() {
if(gl_LocalInvocationID.x == 0)
{ uint workIndex = gl_LocalInvocationID.x;
gl_PrimitiveCountNV = 1; gl_PrimitiveIndicesNV[workIndex] = workIndex;
gl_PrimitiveIndicesNV[0] = 0;
gl_PrimitiveIndicesNV[1] = 1; const uint verticesPerMeshTask = 30;
gl_PrimitiveIndicesNV[2] = 2; uint previousMeshGroupCount = IN.baseID;
uint indexBufferIndex = previousMeshGroupCount * verticesPerMeshTask + workIndex;
gl_MeshVerticesNV[0].gl_Position = mvp * vec4(-0.5, 0.5, 0.5, 1); uint index = indices[indexBufferIndex];
gl_MeshVerticesNV[1].gl_Position = mvp * vec4( 0.5, 0.5, 0.5, 1);
gl_MeshVerticesNV[2].gl_Position = mvp * vec4( 0 , -0.5, 0.5, 1); vec3 inPos = vertices[index].position;
vec3 inNormal = vertices[index].normal;
passNormal[0] = vec3(1, 0, 0); gl_MeshVerticesNV[workIndex].gl_Position = mvp * vec4(inPos, 1);
passNormal[1] = vec3(0, 1, 0); passNormal[workIndex] = inNormal;
passNormal[2] = vec3(0, 0, 1);
} if(gl_LocalInvocationID.x == 0){
gl_PrimitiveCountNV = 10;
}
} }
\ No newline at end of file
...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
#extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require #extension GL_NV_mesh_shader : require
layout(local_size_x=32) in; layout(local_size_x=1) in;
//taskNV out Task { taskNV out Task {
// uint baseID; uint baseID;
// uint subIDs[32]; } OUT;
//} OUT;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() { void main() {
if(gl_LocalInvocationID.x == 0) gl_TaskCountNV = 1;
{ OUT.baseID = gl_GlobalInvocationID.x;
gl_TaskCountNV = 1;
}
} }
\ No newline at end of file
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
#include "MeshStruct.hpp" #include "MeshStruct.hpp"
struct Vertex { struct Vertex {
glm::vec3 position; glm::vec3 position;
glm::vec3 normal; float padding0;
glm::vec3 normal;
float padding1;
}; };
std::vector<Vertex> convertToVertices( std::vector<Vertex> convertToVertices(
...@@ -254,26 +256,28 @@ int main(int argc, const char** argv) { ...@@ -254,26 +256,28 @@ int main(int argc, const char** argv) {
glm::mat4 modelMatrix = *reinterpret_cast<glm::mat4*>(&mesh.meshes.front().modelMatrix); glm::mat4 modelMatrix = *reinterpret_cast<glm::mat4*>(&mesh.meshes.front().modelMatrix);
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP() * modelMatrix; glm::mat4 mvp = cameraManager.getActiveCamera().getMVP() * modelMatrix;
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer }; const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics); auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
const bool useMeshShader = true; const bool useMeshShader = true;
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
if (useMeshShader) { if (useMeshShader) {
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(meshShaderDescriptorSet).vulkanHandle); vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(meshShaderDescriptorSet).vulkanHandle);
const uint32_t verticesPerTask = 30;
core.recordMeshShaderDrawcalls( core.recordMeshShaderDrawcalls(
cmdStream, cmdStream,
renderPass, renderPass,
meshShaderPipeline, meshShaderPipeline,
pushConstantData, pushConstantData,
{ vkcv::MeshShaderDrawcall({descriptorUsage}, 1) }, { vkcv::MeshShaderDrawcall({descriptorUsage}, glm::ceil(bunny.numIndices / float(verticesPerTask))) },
{ renderTargets }); { renderTargets });
} }
else { else {
core.recordDrawcallsToCmdStream( core.recordDrawcallsToCmdStream(
cmdStream, cmdStream,
renderPass, renderPass,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment