2024-03-29 08:49:03 +01:00
|
|
|
import Bounding;
|
2023-10-24 15:01:09 +02:00
|
|
|
|
2023-10-07 19:29:53 +02:00
|
|
|
struct MeshletDescription
|
|
|
|
|
{
|
2024-05-30 21:24:21 +02:00
|
|
|
AABB bounding;
|
|
|
|
|
uint32_t vertexCount;
|
|
|
|
|
uint32_t primitiveCount;
|
|
|
|
|
uint32_t vertexOffset;
|
|
|
|
|
uint32_t primitiveOffset;
|
|
|
|
|
float3 color;
|
|
|
|
|
uint32_t indicesOffset;
|
2023-10-07 19:29:53 +02:00
|
|
|
};
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
struct MeshData
|
|
|
|
|
{
|
2024-05-30 21:24:21 +02:00
|
|
|
AABB bounding;
|
|
|
|
|
uint32_t numMeshlets;
|
|
|
|
|
uint32_t meshletOffset;
|
|
|
|
|
uint32_t firstIndex;
|
|
|
|
|
uint32_t numIndices;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
|
|
|
|
|
2024-06-04 21:34:14 +02:00
|
|
|
static const uint32_t MAX_VERTICES = 256;
|
|
|
|
|
static const uint32_t MAX_PRIMITIVES = 256;
|
|
|
|
|
static const uint32_t TASK_GROUP_SIZE = 128;
|
|
|
|
|
static const uint32_t MESH_GROUP_SIZE = 32;
|
|
|
|
|
static const uint32_t MAX_MESHLETS_PER_INSTANCE = 2048;
|
2023-10-24 15:01:09 +02:00
|
|
|
|
|
|
|
|
struct InstanceData
|
|
|
|
|
{
|
2024-05-30 21:24:21 +02:00
|
|
|
float4x4 transformMatrix;
|
|
|
|
|
float4x4 inverseTransformMatrix;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
|
|
|
|
|
2024-05-30 16:56:22 +02:00
|
|
|
struct MeshletCullingInfo
|
|
|
|
|
{
|
2024-06-04 21:34:14 +02:00
|
|
|
uint32_t visible[MAX_PRIMITIVES / 32];
|
2024-05-30 21:24:21 +02:00
|
|
|
// lookup if a specific triangle is visible
|
|
|
|
|
bool triangleVisible(uint32_t primIndex)
|
|
|
|
|
{
|
2024-06-04 21:34:14 +02:00
|
|
|
uint32_t arrIdx = primIndex / 32;
|
|
|
|
|
uint32_t cullIdx = primIndex % 32;
|
2024-05-30 21:24:21 +02:00
|
|
|
return (visible[arrIdx] & (1 << cullIdx)) != 0;
|
|
|
|
|
}
|
|
|
|
|
bool triangleCulled(uint32_t primIndex)
|
|
|
|
|
{
|
|
|
|
|
return !triangleVisible(primIndex);
|
|
|
|
|
}
|
|
|
|
|
bool anyVisible()
|
|
|
|
|
{
|
2024-06-07 14:56:42 +02:00
|
|
|
uint result = 0;
|
|
|
|
|
for(uint i = 0; i < MAX_PRIMITIVES / 32; ++i)
|
|
|
|
|
{
|
|
|
|
|
result |= visible[i];
|
|
|
|
|
}
|
|
|
|
|
return result != 0;
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
2024-05-30 16:56:22 +02:00
|
|
|
};
|
|
|
|
|
|
2024-05-12 19:36:32 +02:00
|
|
|
struct DrawCallOffsets
|
|
|
|
|
{
|
2024-05-30 16:56:22 +02:00
|
|
|
uint32_t instanceOffset;
|
2024-06-18 19:19:05 +02:00
|
|
|
uint textureOffset;
|
|
|
|
|
uint samplerOffset;
|
|
|
|
|
uint floatOffset;
|
2024-05-12 19:36:32 +02:00
|
|
|
};
|
|
|
|
|
layout(push_constant)
|
|
|
|
|
ConstantBuffer<DrawCallOffsets> pOffsets;
|
|
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
struct Scene
|
|
|
|
|
{
|
2024-05-30 21:24:21 +02:00
|
|
|
StructuredBuffer<InstanceData> instances;
|
|
|
|
|
StructuredBuffer<MeshData> meshData;
|
|
|
|
|
StructuredBuffer<MeshletDescription> meshletInfos;
|
|
|
|
|
StructuredBuffer<uint8_t> primitiveIndices;
|
|
|
|
|
StructuredBuffer<uint32_t> vertexIndices;
|
|
|
|
|
StructuredBuffer<uint32_t> cullingOffsets;
|
2024-06-07 09:19:47 +02:00
|
|
|
StructuredBuffer<MeshletCullingInfo> cullingInfos;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
2024-06-07 09:19:47 +02:00
|
|
|
layout(set=2)
|
2024-04-23 19:11:06 +02:00
|
|
|
ParameterBlock<Scene> pScene;
|
2023-10-07 19:29:53 +02:00
|
|
|
|
2024-06-04 21:34:14 +02:00
|
|
|
uint32_t encodePrimitive(uint32_t primitiveId, uint32_t meshletId)
|
2024-05-30 21:24:21 +02:00
|
|
|
{
|
2024-06-04 21:34:14 +02:00
|
|
|
return primitiveId + (meshletId * uint(MAX_PRIMITIVES));
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 21:34:14 +02:00
|
|
|
uint2 decodePrimitive(uint32_t encoded)
|
2024-05-30 21:24:21 +02:00
|
|
|
{
|
|
|
|
|
uint prim = uint(encoded % MAX_PRIMITIVES);
|
|
|
|
|
encoded = encoded / MAX_PRIMITIVES;
|
2024-06-04 21:34:14 +02:00
|
|
|
uint meshletId = uint(encoded);
|
|
|
|
|
return uint2(prim, meshletId);
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-12 19:36:32 +02:00
|
|
|
struct MeshPayload
|
|
|
|
|
{
|
2024-05-31 14:21:32 +02:00
|
|
|
uint culledMeshlets[MAX_MESHLETS_PER_INSTANCE];
|
2024-05-30 21:24:21 +02:00
|
|
|
uint instanceId;
|
|
|
|
|
uint meshletOffset;
|
|
|
|
|
uint cullingOffset;
|
2024-05-12 19:36:32 +02:00
|
|
|
};
|
|
|
|
|
|