Add GPU sorting for gaussian splat rendering
This commit is contained in:
@@ -150,9 +150,17 @@ Shader "Builtin Gaussian Splat Utilities"
|
||||
void GaussianSplatPrepareOrderCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
const uint splatCount = (uint)gSplatParams.x;
|
||||
const uint sortCapacity = max((uint)gSplatParams.y, splatCount);
|
||||
const uint index = dispatchThreadId.x;
|
||||
if (index >= sortCapacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (index >= splatCount)
|
||||
{
|
||||
GaussianSplatSortDistances[index] = 0xffffffffu;
|
||||
GaussianSplatOrderBuffer[index] = 0u;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,5 +209,63 @@ Shader "Builtin Gaussian Splat Utilities"
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "GaussianSplatBitonicSort"
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
#pragma compute GaussianSplatBitonicSortCS
|
||||
|
||||
cbuffer PerObjectConstants
|
||||
{
|
||||
float4x4 gProjectionMatrix;
|
||||
float4x4 gViewMatrix;
|
||||
float4x4 gModelMatrix;
|
||||
float4 gCameraRight;
|
||||
float4 gCameraUp;
|
||||
float4 gScreenParams;
|
||||
float4 gSplatParams;
|
||||
};
|
||||
|
||||
RWStructuredBuffer<uint> GaussianSplatSortDistances;
|
||||
RWStructuredBuffer<uint> GaussianSplatOrderBuffer;
|
||||
|
||||
[numthreads(256, 1, 1)]
|
||||
void GaussianSplatBitonicSortCS(uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
const uint sortCapacity = (uint)gSplatParams.y;
|
||||
const uint partnerMask = (uint)gSplatParams.z;
|
||||
const uint levelMask = (uint)gSplatParams.w;
|
||||
const uint index = dispatchThreadId.x;
|
||||
if (index >= sortCapacity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const uint partnerIndex = index ^ partnerMask;
|
||||
if (partnerIndex >= sortCapacity || partnerIndex <= index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const uint leftDistance = GaussianSplatSortDistances[index];
|
||||
const uint rightDistance = GaussianSplatSortDistances[partnerIndex];
|
||||
const uint leftOrder = GaussianSplatOrderBuffer[index];
|
||||
const uint rightOrder = GaussianSplatOrderBuffer[partnerIndex];
|
||||
const bool ascending = (index & levelMask) == 0u;
|
||||
const bool shouldSwap = ascending ? (leftDistance > rightDistance) : (leftDistance < rightDistance);
|
||||
if (!shouldSwap)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GaussianSplatSortDistances[index] = rightDistance;
|
||||
GaussianSplatSortDistances[partnerIndex] = leftDistance;
|
||||
GaussianSplatOrderBuffer[index] = rightOrder;
|
||||
GaussianSplatOrderBuffer[partnerIndex] = leftOrder;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user