Stabilize 3DGS D3D12 phase 3 and sort key setup
This commit is contained in:
43
MVS/3DGS-D3D12/shaders/BuildSortKeysCS.hlsl
Normal file
43
MVS/3DGS-D3D12/shaders/BuildSortKeysCS.hlsl
Normal file
@@ -0,0 +1,43 @@
|
||||
#define GROUP_SIZE 64
|
||||
|
||||
cbuffer FrameConstants : register(b0)
|
||||
{
|
||||
float4x4 gViewProjection;
|
||||
float4x4 gView;
|
||||
float4x4 gProjection;
|
||||
float4 gCameraWorldPos;
|
||||
float4 gScreenParams;
|
||||
float4 gSettings;
|
||||
};
|
||||
|
||||
ByteAddressBuffer gPositions : register(t0);
|
||||
StructuredBuffer<uint> gOrderBuffer : register(t1);
|
||||
RWStructuredBuffer<uint> gSortKeys : register(u0);
|
||||
|
||||
float3 LoadFloat3(ByteAddressBuffer buffer, uint byteOffset)
|
||||
{
|
||||
return asfloat(buffer.Load3(byteOffset));
|
||||
}
|
||||
|
||||
uint FloatToSortableUint(float value)
|
||||
{
|
||||
uint bits = asuint(value);
|
||||
uint mask = (0u - (bits >> 31)) | 0x80000000u;
|
||||
return bits ^ mask;
|
||||
}
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
void MainCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
uint index = dispatchThreadId.x;
|
||||
uint splatCount = (uint)gSettings.x;
|
||||
if (index >= splatCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uint splatIndex = gOrderBuffer[index];
|
||||
float3 position = LoadFloat3(gPositions, splatIndex * 12);
|
||||
float3 viewPosition = mul(float4(position, 1.0), gView).xyz;
|
||||
gSortKeys[index] = FloatToSortableUint(viewPosition.z);
|
||||
}
|
||||
Reference in New Issue
Block a user