Using global meshlet culling list
This commit is contained in:
@@ -1,63 +1,8 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Scene;
|
||||
import VertexData;
|
||||
import MaterialParameter;
|
||||
|
||||
struct MeshPayload
|
||||
{
|
||||
uint instanceId[MAX_MESHLETS_PER_MESH];
|
||||
uint meshletId[MAX_MESHLETS_PER_MESH];
|
||||
};
|
||||
|
||||
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
|
||||
){
|
||||
InstanceData instance = pScene.instances[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]);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
MeshData mesh = pScene.meshData[groupID];
|
||||
for(uint i = threadID; i < MAX_MESHLETS_PER_MESH; i += TASK_GROUP_SIZE)
|
||||
{
|
||||
if(i < mesh.numMeshlets)
|
||||
{
|
||||
uint m = mesh.meshletOffset + i;
|
||||
MeshletDescription meshlet = pScene.meshletInfos[m];
|
||||
if(meshlet.bounding.insideFrustum(viewFrustum))
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.meshletId[index] = m;
|
||||
p.instanceId[index] = groupID;
|
||||
}
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
DispatchMesh(head, 1, 1, p);
|
||||
}
|
||||
|
||||
struct PrimitiveAttributes
|
||||
{
|
||||
@@ -74,9 +19,8 @@ void meshMain(
|
||||
out vertices FragmentParameter vertices[MAX_VERTICES],
|
||||
out indices uint3 indices[MAX_PRIMITIVES]
|
||||
){
|
||||
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
|
||||
MeshData md = pScene.meshData[meshPayload.instanceId[groupID]];
|
||||
MeshletDescription m = pScene.meshletInfos[meshPayload.meshletId[groupID]];
|
||||
InstanceData inst = pScene.instances[meshPayload.instanceId];
|
||||
MeshletDescription m = pScene.meshletInfos[pScene.culledMeshlets[meshPayload.cullingOffset + groupID]];
|
||||
SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
|
||||
|
||||
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
|
||||
@@ -97,7 +41,6 @@ void meshMain(
|
||||
VertexAttributes attr = pVertexData.getAttributes(m.indicesOffset + vertexIndex);
|
||||
attr.meshletId = -1;
|
||||
vertices[v] = attr.getParameter(inst.transformMatrix);
|
||||
//vertices[v].vertexColor = m.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import Common;
|
||||
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
|
||||
){
|
||||
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);
|
||||
}
|
||||
@@ -24,7 +24,6 @@ static const uint MAX_VERTICES = 256;
|
||||
static const uint MAX_PRIMITIVES = 256;
|
||||
static const uint TASK_GROUP_SIZE = 128;
|
||||
static const uint MESH_GROUP_SIZE = 32;
|
||||
static const uint MAX_MESHLETS_PER_MESH = 512;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
@@ -32,6 +31,14 @@ struct InstanceData
|
||||
float4x4 inverseTransformMatrix;
|
||||
};
|
||||
|
||||
struct DrawCallOffsets
|
||||
{
|
||||
uint32_t instanceOffset;
|
||||
uint32_t cullingCounterOffset;
|
||||
};
|
||||
layout(push_constant)
|
||||
ConstantBuffer<DrawCallOffsets> pOffsets;
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
@@ -39,7 +46,15 @@ struct Scene
|
||||
StructuredBuffer<MeshletDescription> meshletInfos;
|
||||
StructuredBuffer<uint8_t> primitiveIndices;
|
||||
StructuredBuffer<uint32_t> vertexIndices;
|
||||
StructuredBuffer<uint32_t> cullingOffsets;
|
||||
RWStructuredBuffer<uint32_t> culledMeshlets;
|
||||
};
|
||||
layout(set=2)
|
||||
ParameterBlock<Scene> pScene;
|
||||
|
||||
struct MeshPayload
|
||||
{
|
||||
uint instanceId;
|
||||
uint cullingOffset;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user