Adding cached depth renderpass
This commit is contained in:
@@ -3,47 +3,29 @@ import Scene;
|
||||
|
||||
groupshared MeshPayload p;
|
||||
groupshared uint head;
|
||||
groupshared Frustum viewFrustum;
|
||||
|
||||
[numthreads(TASK_GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("amplification")]
|
||||
void taskMain(
|
||||
uint threadID: SV_GroupIndex,
|
||||
uint groupID: SV_GroupID
|
||||
uint groupID: SV_GroupID,
|
||||
){
|
||||
InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID];
|
||||
MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID];
|
||||
if(threadID == 0)
|
||||
{
|
||||
head = 0;
|
||||
float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz;
|
||||
const float offset = 0.0f;
|
||||
float3 corners[4] = {
|
||||
screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz,
|
||||
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz,
|
||||
screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz,
|
||||
screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz
|
||||
};
|
||||
viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]);
|
||||
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.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);
|
||||
pScene.culledMeshlets[p.cullingOffset + index] = m;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
DispatchMesh(head, 1, 1, p);
|
||||
}
|
||||
//head = 0;
|
||||
//GroupMemoryBarrierWithGroupSync();
|
||||
//for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
|
||||
//{
|
||||
// uint m = mesh.meshletOffset + i;
|
||||
// MeshletDescription meshlet = pScene.meshletInfos[m];
|
||||
// MeshletCullingInfo culling = pScene.culledMeshlets[instance.meshletCullingOffset];
|
||||
// if(culling.anyVisible())
|
||||
// {
|
||||
// uint index;
|
||||
// InterlockedAdd(head, 1, index);
|
||||
// p.culledMeshlets[index] = m;
|
||||
// }
|
||||
//}
|
||||
//GroupMemoryBarrierWithGroupSync();
|
||||
//DispatchMesh(head, 1, 1, p);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import Common;
|
||||
import Scene;
|
||||
|
||||
groupshared MeshPayload p;
|
||||
groupshared uint head;
|
||||
|
||||
[numthreads(TASK_GROUP_SIZE, 1, 1)]
|
||||
[shader("amplification")]
|
||||
void taskMain(
|
||||
uint threadID: SV_GroupIndex,
|
||||
uint groupID: SV_GroupID, )
|
||||
{
|
||||
if (threadID == 0)
|
||||
{
|
||||
head = 0;
|
||||
p.instanceId = pOffsets.instanceOffset + groupID;
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
MeshData mesh = pScene.meshData[p.instanceId];
|
||||
for (uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
|
||||
{
|
||||
uint m = mesh.meshletOffset + i;
|
||||
//MeshletDescription meshlet = pScene.meshletInfos[m];
|
||||
//MeshletCullingInfo culling = pScene.culledMeshlets[pScene.cullingOffsets[p.instanceId] + i];
|
||||
//if(culling.anyVisible())
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.culledMeshlets[i] = m;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
DispatchMesh(mesh.numMeshlets, 1, 1, p);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Scene;
|
||||
import VertexData;
|
||||
import MaterialParameter;
|
||||
|
||||
struct PrimitiveAttributes
|
||||
{
|
||||
uint cull: SV_CullPrimitive;
|
||||
};
|
||||
|
||||
struct CulledMeshletList
|
||||
{
|
||||
StructuredBuffer<uint> meshletIndices;
|
||||
};
|
||||
ParameterBlock<CulledMeshletList> pCullingList;
|
||||
|
||||
[numthreads(MESH_GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("mesh")]
|
||||
void meshMain(
|
||||
in uint threadID: SV_GroupIndex,
|
||||
in uint groupID: SV_GroupID,
|
||||
out vertices FragmentParameter vertices[MAX_VERTICES],
|
||||
out indices uint3 indices[MAX_PRIMITIVES]
|
||||
){
|
||||
uint meshletIndex = pCullingList.meshletIndices[groupID];
|
||||
MeshletDescription m = pScene.meshletInfos[meshletIndex];
|
||||
SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
|
||||
|
||||
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
|
||||
{
|
||||
uint p = min(i, m.primitiveCount - 1);
|
||||
{
|
||||
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||
}
|
||||
}
|
||||
for(uint i = threadID; i < MAX_VERTICES; i+=MESH_GROUP_SIZE)
|
||||
{
|
||||
uint v = min(i, m.vertexCount - 1);
|
||||
{
|
||||
uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
|
||||
VertexAttributes attr = pVertexData.getAttributes(m.indicesOffset + vertexIndex);
|
||||
attr.meshletId = meshletIndex;
|
||||
vertices[v] = attr.getParameter(float4x4(1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ void taskMain(
|
||||
viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]);
|
||||
viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]);
|
||||
p.instanceId = pOffsets.instanceOffset + groupID;
|
||||
//p.cullingOffset = pScene.cullingOffsets[pOffsets.cullingCounterOffset + groupID];
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE)
|
||||
@@ -43,7 +42,6 @@ void taskMain(
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.culledMeshlets[index] = m;
|
||||
//pScene.culledMeshlets[p.cullingOffset + index] = m;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
@@ -31,9 +31,25 @@ struct InstanceData
|
||||
float4x4 inverseTransformMatrix;
|
||||
};
|
||||
|
||||
struct MeshletCullingInfo
|
||||
{
|
||||
uint64_t cull[MAX_PRIMITIVES / 64];
|
||||
// lookup if a specific triangle is visible
|
||||
bool triangleVisible(uint32_t primIndex)
|
||||
{
|
||||
uint32_t arrIdx = primIndex / 64;
|
||||
uint32_t cullIdx = primIndex % 64;
|
||||
return (cull[arrIdx] & (1 << cullIdx)) != 0;
|
||||
}
|
||||
bool anyVisible()
|
||||
{
|
||||
return (cull[0] | cull[1] | cull[2] | cull[3]) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct DrawCallOffsets
|
||||
{
|
||||
uint32_t instanceOffset;
|
||||
uint32_t instanceOffset;
|
||||
};
|
||||
layout(push_constant)
|
||||
ConstantBuffer<DrawCallOffsets> pOffsets;
|
||||
@@ -45,8 +61,8 @@ struct Scene
|
||||
StructuredBuffer<MeshletDescription> meshletInfos;
|
||||
StructuredBuffer<uint8_t> primitiveIndices;
|
||||
StructuredBuffer<uint32_t> vertexIndices;
|
||||
// StructuredBuffer<uint32_t> cullingOffsets;
|
||||
// RWStructuredBuffer<uint32_t> culledMeshlets;
|
||||
StructuredBuffer<MeshletCullingInfo> culledMeshlets;
|
||||
StructuredBuffer<uint32_t> cullingOffsets;
|
||||
};
|
||||
layout(set=2)
|
||||
ParameterBlock<Scene> pScene;
|
||||
|
||||
Reference in New Issue
Block a user