2024-03-29 08:49:03 +01:00
|
|
|
import Bounding;
|
2023-10-24 15:01:09 +02:00
|
|
|
|
2025-04-15 00:33:49 +02:00
|
|
|
struct PoolRange
|
|
|
|
|
{
|
|
|
|
|
uint32_t offset;
|
|
|
|
|
uint32_t size;
|
|
|
|
|
};
|
|
|
|
|
|
2023-10-07 19:29:53 +02:00
|
|
|
struct MeshletDescription
|
|
|
|
|
{
|
2024-05-30 21:24:21 +02:00
|
|
|
AABB bounding;
|
2025-04-15 00:33:49 +02:00
|
|
|
// range into vertexIndices array
|
|
|
|
|
PoolRange vertexIndices;
|
|
|
|
|
// range into primitiveIndices array
|
|
|
|
|
PoolRange primitiveIndices;
|
2024-05-30 21:24:21 +02:00
|
|
|
uint32_t indicesOffset;
|
2025-05-13 10:29:05 +02:00
|
|
|
uint32_t lod;
|
|
|
|
|
uint32_t pad0;
|
|
|
|
|
uint32_t pad1;
|
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;
|
2025-04-15 00:33:49 +02:00
|
|
|
PoolRange meshletRange;
|
|
|
|
|
// offset into the global index buffer
|
|
|
|
|
PoolRange indicesRange;
|
2023-10-24 15:01:09 +02:00
|
|
|
};
|
|
|
|
|
|
2025-03-09 22:42:05 +01:00
|
|
|
static const uint32_t MAX_VERTICES = 256;
|
|
|
|
|
static const uint32_t MAX_PRIMITIVES = 256;
|
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-19 10:33:19 +02:00
|
|
|
uint32_t visible;
|
|
|
|
|
bool wasVisible()
|
2024-05-30 21:24:21 +02:00
|
|
|
{
|
2024-06-19 10:33:19 +02:00
|
|
|
return bool(visible);
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
2024-05-30 16:56:22 +02:00
|
|
|
};
|
|
|
|
|
|
2024-09-27 17:42:50 +02:00
|
|
|
struct DrawCallOffsets
|
2024-05-12 19:36:32 +02:00
|
|
|
{
|
2024-07-10 21:07:10 +02:00
|
|
|
uint instanceOffset;
|
2024-06-18 19:19:05 +02:00
|
|
|
uint textureOffset;
|
|
|
|
|
uint samplerOffset;
|
|
|
|
|
uint floatOffset;
|
2024-09-27 17:42:50 +02:00
|
|
|
};
|
|
|
|
|
#ifdef RAY_TRACING
|
|
|
|
|
layout(shaderRecordEXT)
|
|
|
|
|
#else
|
|
|
|
|
layout(push_constant)
|
|
|
|
|
#endif
|
|
|
|
|
ConstantBuffer<DrawCallOffsets> pOffsets;
|
2024-05-12 19:36:32 +02:00
|
|
|
|
2023-10-24 15:01:09 +02:00
|
|
|
struct Scene
|
|
|
|
|
{
|
2025-05-12 22:48:01 +02:00
|
|
|
StructuredBuffer<float> positions;
|
|
|
|
|
StructuredBuffer<uint> indexBuffer;
|
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-04-23 19:11:06 +02:00
|
|
|
ParameterBlock<Scene> pScene;
|
2023-10-07 19:29:53 +02:00
|
|
|
|
2024-06-19 10:33:19 +02:00
|
|
|
uint32_t encodePrimitive(uint32_t meshletId)
|
2024-05-30 21:24:21 +02:00
|
|
|
{
|
2024-06-19 10:33:19 +02:00
|
|
|
return meshletId;
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-19 10:33:19 +02:00
|
|
|
uint decodePrimitive(uint32_t encoded)
|
2024-05-30 21:24:21 +02:00
|
|
|
{
|
2024-06-19 10:33:19 +02:00
|
|
|
return encoded;
|
2024-05-30 21:24:21 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-12 19:36:32 +02:00
|
|
|
struct MeshPayload
|
|
|
|
|
{
|
2025-03-09 22:42:05 +01:00
|
|
|
uint culledMeshlets[2048];
|
2024-05-30 21:24:21 +02:00
|
|
|
uint instanceId;
|
|
|
|
|
uint meshletOffset;
|
|
|
|
|
uint cullingOffset;
|
2024-05-12 19:36:32 +02:00
|
|
|
};
|
|
|
|
|
|