Polymorphic Map and threadpool
This commit is contained in:
@@ -3,18 +3,18 @@ import Common;
|
||||
|
||||
struct ComputeShaderInput
|
||||
{
|
||||
uint3 groupID : SV_GroupID;
|
||||
uint3 groupThreadID : SV_GroupThreadID;
|
||||
uint3 dispatchThreadID : SV_DispatchThreadID;
|
||||
uint groupIndex : SV_GroupIndex;
|
||||
uint3 groupID : SV_GroupID;
|
||||
uint3 groupThreadID : SV_GroupThreadID;
|
||||
uint3 dispatchThreadID : SV_DispatchThreadID;
|
||||
uint groupIndex : SV_GroupIndex;
|
||||
};
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 1)
|
||||
cbuffer DispatchParams
|
||||
{
|
||||
uint3 numThreadGroups;
|
||||
uint pad0;
|
||||
uint3 numThreads;
|
||||
uint pad1;
|
||||
uint3 numThreadGroups;
|
||||
uint pad0;
|
||||
uint3 numThreads;
|
||||
uint pad1;
|
||||
}
|
||||
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 2)
|
||||
@@ -52,90 +52,90 @@ groupshared uint tLightList[1024];
|
||||
|
||||
void oAppendLight(uint lightIndex)
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(oLightCount, 1, index);
|
||||
if(index < 1024)
|
||||
{
|
||||
oLightList[index] = lightIndex;
|
||||
}
|
||||
uint index;
|
||||
InterlockedAdd(oLightCount, 1, index);
|
||||
if(index < 1024)
|
||||
{
|
||||
oLightList[index] = lightIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void tAppendLight(uint lightIndex)
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(tLightCount, 1, index);
|
||||
if(index < 1024)
|
||||
{
|
||||
tLightList[index] = lightIndex;
|
||||
}
|
||||
uint index;
|
||||
InterlockedAdd(tLightCount, 1, index);
|
||||
if(index < 1024)
|
||||
{
|
||||
tLightList[index] = lightIndex;
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(BLOCK_SIZE, BLOCK_SIZE, 1)]
|
||||
[shader("compute")]
|
||||
void cullLights(ComputeShaderInput in)
|
||||
{
|
||||
int3 texCoord = int3(in.dispatchThreadID.xy, 0);
|
||||
float fDepth = depthTextureVS.Load(texCoord).r;
|
||||
int3 texCoord = int3(in.dispatchThreadID.xy, 0);
|
||||
float fDepth = depthTextureVS.Load(texCoord).r;
|
||||
|
||||
uint uDepth = asuint(fDepth);
|
||||
if(in.groupIndex == 0)
|
||||
{
|
||||
uMinDepth = 0xffffffff;
|
||||
uMaxDepth = 0x0;
|
||||
oLightCount = 0;
|
||||
tLightCount = 0;
|
||||
uint uDepth = asuint(fDepth);
|
||||
if(in.groupIndex == 0)
|
||||
{
|
||||
uMinDepth = 0xffffffff;
|
||||
uMaxDepth = 0x0;
|
||||
oLightCount = 0;
|
||||
tLightCount = 0;
|
||||
groupFrustum = frustums[in.groupID.x + (in.groupID.y * numThreadGroups.x)];
|
||||
}
|
||||
}
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
InterlockedMin(uMinDepth, uDepth);
|
||||
InterlockedMax(uMaxDepth, uDepth);
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
InterlockedMin(uMinDepth, uDepth);
|
||||
InterlockedMax(uMaxDepth, uDepth);
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
float fMinDepth = asfloat(uMinDepth);
|
||||
float fMaxDepth = asfloat(uMaxDepth);
|
||||
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.0f)).z;
|
||||
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.0f)).z;
|
||||
|
||||
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
|
||||
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
|
||||
|
||||
for ( uint i = in.groupIndex; i < numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
{
|
||||
PointLight light = pointLights[i];
|
||||
//TODO: why doesn't this check go through?
|
||||
//if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
||||
{
|
||||
tAppendLight(i);
|
||||
//TODO: why doesn't this check go through?
|
||||
//if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
||||
{
|
||||
tAppendLight(i);
|
||||
if(!light.insidePlane(minPlane))
|
||||
{
|
||||
oAppendLight(i);
|
||||
}
|
||||
}
|
||||
{
|
||||
oAppendLight(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
if(in.groupIndex == 0)
|
||||
{
|
||||
InterlockedAdd(oLightIndexCounter[0], (uint)oLightCount, oLightIndexStartOffset);
|
||||
oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
|
||||
|
||||
InterlockedAdd(tLightIndexCounter[0], (uint)tLightCount, tLightIndexStartOffset);
|
||||
tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
for (uint j = in.groupIndex; j < (uint)oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
|
||||
{
|
||||
oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
|
||||
}
|
||||
|
||||
// For transparent geometry.
|
||||
for ( uint k = in.groupIndex; k < (uint)tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
if(in.groupIndex == 0)
|
||||
{
|
||||
InterlockedAdd(oLightIndexCounter[0], (uint)oLightCount, oLightIndexStartOffset);
|
||||
oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
|
||||
|
||||
InterlockedAdd(tLightIndexCounter[0], (uint)tLightCount, tLightIndexStartOffset);
|
||||
tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
for (uint j = in.groupIndex; j < (uint)oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
|
||||
{
|
||||
oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
|
||||
}
|
||||
|
||||
// For transparent geometry.
|
||||
for ( uint k = in.groupIndex; k < (uint)tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user