Working on visibility pass

This commit is contained in:
Dynamitos
2024-06-07 09:19:47 +02:00
parent ad00e16cf9
commit cb21e8a85a
24 changed files with 450 additions and 373 deletions
+5 -4
View File
@@ -3,17 +3,18 @@ import Scene;
groupshared MeshPayload p;
groupshared uint head;
groupshared MeshData mesh;
[numthreads(TASK_GROUP_SIZE, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupIndex,
uint threadID: SV_GroupThreadID,
uint groupID: SV_GroupID, )
{
MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
if (threadID == 0)
{
head = 0;
mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
p.instanceId = pOffsets.instanceOffset + groupID;
p.meshletOffset = mesh.meshletOffset;
p.cullingOffset = pScene.cullingOffsets[p.instanceId];
@@ -24,8 +25,8 @@ void taskMain(
uint m = p.meshletOffset + i;
uint cull = p.cullingOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m];
MeshletCullingInfo culling = pScene.culledMeshlets[cull];
if(false)
MeshletCullingInfo culling = pScene.cullingInfos[cull];
//if(!culling.anyVisible())
{
uint index;
InterlockedAdd(head, 1, index);
+2 -2
View File
@@ -8,7 +8,7 @@ groupshared MeshData mesh;
[numthreads(TASK_GROUP_SIZE, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupIndex,
uint threadID: SV_GroupThreadID,
uint groupID: SV_GroupID, )
{
if (threadID == 0)
@@ -25,7 +25,7 @@ void taskMain(
uint m = p.meshletOffset + i;
uint cull = p.cullingOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m];
MeshletCullingInfo culling = pScene.culledMeshlets[cull];
MeshletCullingInfo culling = pScene.cullingInfos[cull];
if(culling.anyVisible())
{
uint index;
+2 -2
View File
@@ -15,7 +15,7 @@ struct PrimitiveAttributes
[outputtopology("triangle")]
[shader("mesh")]
void meshMain(
in uint threadID: SV_GroupIndex,
in uint threadID: SV_GroupThreadID,
in uint groupID: SV_GroupID,
in payload MeshPayload meshPayload,
out vertices FragmentParameter vertices[MAX_VERTICES],
@@ -27,7 +27,7 @@ void meshMain(
uint meshletId = meshPayload.cullingOffset + meshletNumber;
InstanceData inst = pScene.instances[meshPayload.instanceId];
MeshletDescription m = pScene.meshletInfos[meshPayload.meshletOffset + meshletNumber];
MeshletCullingInfo cull = pScene.culledMeshlets[meshletId];
MeshletCullingInfo cull = pScene.cullingInfos[meshletId];
SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
+8 -28
View File
@@ -8,35 +8,15 @@ struct VisibilityCullingData
};
ParameterBlock<VisibilityCullingData> pVisibilityParams;
groupshared MeshletCullingInfo cullInfo;
[numthreads(BLOCK_SIZE, 1, 1)]
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
[shader("compute")]
void computeMain(
uint threadID: SV_GroupIndex,
uint groupID: SV_GroupID,
uint3 dispatchThreadID: SV_DispatchThreadID,
){
if (threadID < MAX_PRIMITIVES / 32)
{
cullInfo.visible[threadID] = 0;
}
GroupMemoryBarrierWithGroupSync();
for (uint y = 0; y < pViewParams.screenDimensions.y; y++)
{
for (uint x = threadID; x < pViewParams.screenDimensions.x; x += BLOCK_SIZE)
{
int3 texCoords = int3(x, y, 0);
uint encoded = pVisibilityParams.visibilityTexture.Load(texCoords).r;
uint2 decoded = decodePrimitive(encoded);
uint base = decoded.y == groupID ? 1 : 0;
uint arrIdx = decoded.x / 32;
uint bit = decoded.x % 32;
cullInfo.visible[arrIdx] |= (base << bit);
}
}
GroupMemoryBarrierWithGroupSync();
if (threadID < MAX_PRIMITIVES / 32)
{
pVisibilityParams.cullingInfos[groupID].visible[threadID] = cullInfo.visible[threadID];
}
int3 texCoords = int3(dispatchThreadID.xy, 0);
uint encoded = pVisibilityParams.visibilityTexture.Load(texCoords).r;
uint2 decoded = decodePrimitive(encoded);
uint arrIdx = decoded.x / 32;
uint bit = decoded.x % 32;
pVisibilityParams.cullingInfos[decoded.y].visible[arrIdx] |= (1 << bit);
}
+2 -2
View File
@@ -66,10 +66,10 @@ struct Scene
StructuredBuffer<MeshletDescription> meshletInfos;
StructuredBuffer<uint8_t> primitiveIndices;
StructuredBuffer<uint32_t> vertexIndices;
StructuredBuffer<MeshletCullingInfo> culledMeshlets;
StructuredBuffer<uint32_t> cullingOffsets;
StructuredBuffer<MeshletCullingInfo> cullingInfos;
};
layout(set = 2)
layout(set=2)
ParameterBlock<Scene> pScene;
uint32_t encodePrimitive(uint32_t primitiveId, uint32_t meshletId)