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

[#87] Increase task shader group size to 32

parent 85228f00
No related branches found
No related tags found
1 merge request!74Resolve "Mesh Shader Implementation"
Pipeline #26474 failed
......@@ -27,6 +27,6 @@ vec3 colorFromIndex(uint i){
}
void main() {
//outColor = normalize(passNormal) * 0.5 + 0.5;
outColor = normalize(passNormal) * 0.5 + 0.5;
outColor = colorFromIndex(passTaskIndex);
}
\ No newline at end of file
......@@ -43,12 +43,13 @@ layout(std430, binding = 2) readonly buffer meshletBuffer
};
taskNV in Task {
uint meshletIndex;
uint meshletIndices[32];
} IN;
void main() {
Meshlet meshlet = meshlets[IN.meshletIndex];
uint meshletIndex = IN.meshletIndices[gl_WorkGroupID.x];
Meshlet meshlet = meshlets[meshletIndex];
// set vertices
for(uint i = 0; i < 2; i++){
......@@ -63,7 +64,7 @@ void main() {
gl_MeshVerticesNV[workIndex].gl_Position = mvp * vec4(vertex.position, 1);
passNormal[workIndex] = vertex.normal;
passTaskIndex[workIndex] = IN.meshletIndex;
passTaskIndex[workIndex] = meshletIndex;
}
// set local indices
......
......@@ -2,13 +2,23 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_NV_mesh_shader : require
layout(local_size_x=1) in;
layout(local_size_x=32) in;
taskNV out Task {
uint meshletIndex;
uint meshletIndices[32];
} OUT;
layout( push_constant ) uniform constants{
mat4 mvp;
uint meshletCount;
};
void main() {
gl_TaskCountNV = 1;
OUT.meshletIndex = gl_GlobalInvocationID.x;
if(gl_LocalInvocationID.x == 0){
int taskCount = int(gl_WorkGroupID.x * 32);
// use signed ints to avoid underflow
int superflousTaskCount = max(taskCount - int(meshletCount), 0);
gl_TaskCountNV = 32 - superflousTaskCount;
}
OUT.meshletIndices[gl_LocalInvocationID.x] = gl_GlobalInvocationID.x;
}
\ No newline at end of file
......@@ -9,10 +9,12 @@ layout(location = 1) out uint dummyOutput;
layout( push_constant ) uniform constants{
mat4 mvp;
uint padding; // pad to same size as mesh shader constants
};
void main() {
gl_Position = mvp * vec4(inPosition, 1.0);
dummyOutput = 0;
passNormal = inNormal;
dummyOutput = padding * 0; // padding must be used, else compiler shrinks constant size
}
\ No newline at end of file
......@@ -226,33 +226,40 @@ int main(int argc, const char** argv) {
continue;
}
auto end = std::chrono::system_clock::now();
auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
start = end;
auto end = std::chrono::system_clock::now();
auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
start = end;
cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
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;
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
struct PushConstants {
glm::mat4 mvp;
uint32_t meshletCount;
};
PushConstants pushConstants{ mvp, meshShaderModelData.meshlets.size() };
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
const bool useMeshShader = true;
vkcv::PushConstants pushConstantData(sizeof(glm::mat4));
pushConstantData.appendDrawcall(mvp);
vkcv::PushConstants pushConstantData(sizeof(pushConstants));
pushConstantData.appendDrawcall(pushConstants);
if (useMeshShader) {
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(meshShaderDescriptorSet).vulkanHandle);
const uint32_t taskCount = (meshShaderModelData.meshlets.size() + 31) / 32;
core.recordMeshShaderDrawcalls(
cmdStream,
renderPass,
meshShaderPipeline,
pushConstantData,
{ vkcv::MeshShaderDrawcall({descriptorUsage}, meshShaderModelData.meshlets.size())},
{ vkcv::MeshShaderDrawcall({descriptorUsage}, taskCount)},
{ renderTargets });
}
else {
......
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