Caching descriptor set updates

This commit is contained in:
Dynamitos
2024-05-29 10:40:35 +02:00
parent e0961bce24
commit 4b6022237b
15 changed files with 405 additions and 315 deletions
+4 -4
View File
@@ -15,10 +15,10 @@ void computeFrustums(ComputeShaderInput in)
{
float3 origin = float3(0, 0, 0);
float3 corners[4] = {
screenToView(float4(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToView(float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToView(float4(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToView(float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f)).xyz
screenToWorld(float4(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToWorld(float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 0) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToWorld(float4(float2(in.dispatchThreadID.x + 0, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f)).xyz,
screenToWorld(float4(float2(in.dispatchThreadID.x + 1, in.dispatchThreadID.y + 1) * BLOCK_SIZE, -1.0f, 1.0f)).xyz
};
Frustum frustum;
frustum.sides[0] = computePlane(origin, corners[2], corners[0]);
+11 -10
View File
@@ -29,7 +29,6 @@ groupshared uint uMinDepth;
groupshared uint uMaxDepth;
groupshared Frustum groupFrustum;
groupshared float4x4 viewMatrix;
groupshared uint oLightCount;
groupshared uint oLightIndexStartOffset;
@@ -70,7 +69,6 @@ void cullLights(ComputeShaderInput in)
uint uDepth = asuint(fDepth);
if(in.groupIndex == 0)
{
viewMatrix = pViewParams.viewMatrix;
uMinDepth = 0xffffffff;
uMaxDepth = 0x0;
oLightCount = 0;
@@ -88,27 +86,30 @@ void cullLights(ComputeShaderInput in)
float fMinDepth = asfloat(uMinDepth);
float fMaxDepth = asfloat(uMaxDepth);
float minDepthVS = clipToView(float4(0, 0, fMinDepth, 1)).z;
float maxDepthVS = clipToView(float4(0, 0, fMaxDepth, 1)).z;
float nearClipVS = clipToView(float4(0, 0, 0, 1)).z;
float minDepthWS = clipToWorld(float4(0, 0, fMinDepth, 1)).z;
float maxDepthWS = clipToWorld(float4(0, 0, fMaxDepth, 1)).z;
float nearClipWS = clipToWorld(float4(0, 0, 0, 1)).z;
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
Plane minPlane = {float3(0, 0, -1), -minDepthWS};
for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
{
PointLight light = pLightEnv.pointLights[i];
float3 light_VS = mul(viewMatrix, float4(light.position_WS.xyz, 1.0f)).xyz;
//if(light.insideFrustum(groupFrustum, light_VS, nearClipVS, maxDepthVS))
#ifdef LIGHT_CULLING
if(light.insideFrustum(groupFrustum, light.getPosition(), nearClipWS, maxDepthWS))
#endif
{
tAppendLight(i);
//if(!light.insidePlane(minPlane, light_VS))
#ifdef LIGHT_CULLING
if(!light.insidePlane(minPlane, light.getPosition()))
#endif
{
oAppendLight(i);
}
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
if(in.groupIndex == 0)
{
+7
View File
@@ -48,6 +48,13 @@ float4 clipToView(float4 clip)
return view;
}
float4 clipToWorld(float4 clip)
{
float4 view = clipToView(clip);
return viewToWorld(view);
}
float4 screenToView(float4 screen)
{
float2 texCoord = screen.xy / pViewParams.screenDimensions;
+4
View File
@@ -52,6 +52,10 @@ struct PointLight : ILightEnv
}
return result;
}
float3 getPosition()
{
return position_WS.xyz;
}
};
struct LightEnv