Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ RWStructuredBuffer<uint> lightIndexCounter : register(u0);
RWStructuredBuffer<uint> lightIndexList : register(u1);
RWStructuredBuffer<LightGrid> lightGrid : register(u2);

groupshared Light sharedLights[GROUP_SIZE];

bool LightIntersectsCluster(float3 position, float radiusSquared, ClusterAABB cluster)
{
float3 closest = max(cluster.minPoint.xyz, min(position, cluster.maxPoint.xyz));
Expand All @@ -42,14 +40,10 @@ bool LightIntersectsCluster(float3 position, float radiusSquared, ClusterAABB cl

ClusterAABB cluster = clusters[clusterIndex];

if (groupIndex < LightCount) {
uint lightIndex = groupIndex;
Light light = lights[lightIndex];
sharedLights[groupIndex] = light;
}

GroupMemoryBarrierWithGroupSync();

// Threads read the global lights buffer directly (cached); with no
// inter-thread sharing there is nothing to synchronize, so no barriers. Dead
// groupshared staging was removed here -- do not re-add: Light[GROUP_SIZE] is
// 96 KB, over the 32 KB LDS limit, so a live read would not compile.
for (uint i = 0; i < LightCount; i++) {
Light light = lights[i];

Expand All @@ -74,8 +68,6 @@ bool LightIntersectsCluster(float3 position, float radiusSquared, ClusterAABB cl
}
}

GroupMemoryBarrierWithGroupSync();

uint offset = 0;
InterlockedAdd(lightIndexCounter[0], visibleLightCount, offset);

Expand Down
5 changes: 4 additions & 1 deletion features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#define NUMTHREAD_Y 16
#define NUMTHREAD_Z 4
#define GROUP_SIZE (NUMTHREAD_X * NUMTHREAD_Y * NUMTHREAD_Z)
#define MAX_CLUSTER_LIGHTS 256
// Per-cluster light cap. MUST match LightLimitFix::CLUSTER_MAX_LIGHTS: the C++
// side sizes the global lightIndexList pool as clusterCount * that value, so a
// larger cap here can overrun the pool.
#define MAX_CLUSTER_LIGHTS 128
Comment thread
alandtse marked this conversation as resolved.

namespace LightFlags
{
Expand Down
3 changes: 3 additions & 0 deletions src/Features/LightLimitFix.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ struct LightLimitFix : OverlayFeature
{
private:
static constexpr uint32_t MAX_LIGHTS = 1024;
// Per-cluster visible-light cap; sizes the global lightIndexList pool as
// clusterCount * CLUSTER_MAX_LIGHTS. MUST match MAX_CLUSTER_LIGHTS in the
// shader-side Common.hlsli or the cull pass can overrun the pool.
static constexpr uint32_t CLUSTER_MAX_LIGHTS = 128;

public:
Expand Down
Loading