From 30ba70832e11304051d92551bf51fd0e55e4acc7 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Wed, 22 May 2024 19:29:23 +0200 Subject: [PATCH] Mesh Shading works as well --- res/shaders/MeshletPass.slang | 6 ++--- res/shaders/ViewCullingTask.slang | 30 ++++++++++++------------- src/Engine/Graphics/Vulkan/Graphics.cpp | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/res/shaders/MeshletPass.slang b/res/shaders/MeshletPass.slang index 2185d8f..6724f30 100644 --- a/res/shaders/MeshletPass.slang +++ b/res/shaders/MeshletPass.slang @@ -18,9 +18,9 @@ void meshMain( out vertices FragmentParameter vertices[MAX_VERTICES], out indices uint3 indices[MAX_PRIMITIVES] ){ - InstanceData inst = pScene.instanceData[meshPayload.instanceId]; - MeshData data = pScene.meshData[meshPayload.instanceId]; - MeshletDescription m = pScene.meshletInfos[data.meshletOffset + groupID]; + InstanceData inst = pScene.instances[meshPayload.instanceId]; + //MeshData data = pScene.meshData[meshPayload.instanceId]; + MeshletDescription m = pScene.meshletInfos[meshPayload.culledMeshlets[groupID]]; SetMeshOutputCounts(m.vertexCount, m.primitiveCount); for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE) diff --git a/res/shaders/ViewCullingTask.slang b/res/shaders/ViewCullingTask.slang index 88922c8..6544f5e 100644 --- a/res/shaders/ViewCullingTask.slang +++ b/res/shaders/ViewCullingTask.slang @@ -28,24 +28,22 @@ void taskMain( viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]); viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]); viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]); - //p.instanceId = pOffsets.instanceOffset + groupID; - p.instanceData = instance; - p.meshData = mesh; + p.instanceId = pOffsets.instanceOffset + groupID; //p.cullingOffset = pScene.cullingOffsets[pOffsets.cullingCounterOffset + groupID]; } GroupMemoryBarrierWithGroupSync(); - //for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE) - //{ - // uint m = mesh.meshletOffset + i; - // MeshletDescription meshlet = pScene.meshletInfos[m]; - // //if(meshlet.bounding.insideFrustum(viewFrustum)) - // { - // uint index; - // InterlockedAdd(head, 1, index); - // p.culledMeshlets[index] = m; - // //pScene.culledMeshlets[p.cullingOffset + index] = m; - // } - //} - //GroupMemoryBarrierWithGroupSync(); + for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE) + { + uint m = mesh.meshletOffset + i; + MeshletDescription meshlet = pScene.meshletInfos[m]; + if(meshlet.bounding.insideFrustum(viewFrustum)) + { + uint index; + InterlockedAdd(head, 1, index); + p.culledMeshlets[index] = m; + //pScene.culledMeshlets[p.cullingOffset + index] = m; + } + } + GroupMemoryBarrierWithGroupSync(); DispatchMesh(mesh.numMeshlets, 1, 1, p); } \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 70a2311..08eb0e9 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -496,7 +496,7 @@ void Graphics::pickPhysicalDevice() { if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0) { - //meshShadingEnabled = true; + meshShadingEnabled = true; break; } }