Skip to content

Commit 076c476

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.3] UUM-98082 - Fixed GPU Crash when disabling ZBinning with Forward+
1 parent 7b65a9f commit 076c476

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

Packages/com.unity.render-pipelines.universal/ShaderLibrary/Clustering.hlsl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ ClusterIterator ClusterInit(float2 normalizedScreenSpaceUV, float3 positionWS, i
7777
#if !URP_FP_DISABLE_ZBINNING
7878
uint header = Select4(asuint(urp_ZBins[zBinHeaderIndex / 4]), zBinHeaderIndex % 4);
7979
#else
80-
uint header = headerIndex == 0 ? ((URP_FP_PROBES_BEGIN - 1) << 16) : (((URP_FP_WORDS_PER_TILE * 32 - 1) << 16) | URP_FP_PROBES_BEGIN);
80+
uint header;
81+
if (headerIndex == 0)
82+
{
83+
// If URP_FP_PROBES_BEGIN is 0, set the header to an invalid header that skips iteration
84+
header = (int(URP_FP_PROBES_BEGIN) - 1) < 0 ? 0x0000FFFFu : ((URP_FP_PROBES_BEGIN - 1) << 16);
85+
}
86+
else
87+
{
88+
header = (((URP_FP_WORDS_PER_TILE * 32 - 1) << 16) | URP_FP_PROBES_BEGIN);
89+
}
8190
#endif
8291
#if MAX_LIGHTS_PER_TILE > 32 || CLUSTER_HAS_REFLECTION_PROBES
8392
state.entityIndexNextMax = header;
@@ -87,8 +96,12 @@ ClusterIterator ClusterInit(float2 normalizedScreenSpaceUV, float3 positionWS, i
8796
if (URP_FP_WORDS_PER_TILE > 0)
8897
{
8998
state.tileMask =
99+
#if !URP_FP_DISABLE_TILING
90100
Select4(asuint(urp_Tiles[tileWordIndex / 4]), tileWordIndex % 4) &
101+
#endif
102+
#if !URP_FP_DISABLE_ZBINNING
91103
Select4(asuint(urp_ZBins[zBinWordIndex / 4]), zBinWordIndex % 4) &
104+
#endif
92105
(0xFFFFFFFFu << (header & 0x1F)) & (0xFFFFFFFFu >> (31 - (header >> 16)));
93106
}
94107
#endif
@@ -123,12 +136,12 @@ bool ClusterNext(inout ClusterIterator it, out uint entityIndex)
123136
#endif
124137
bool hasNext = it.tileMask != 0;
125138
uint bitIndex = FIRST_BIT_LOW(it.tileMask);
126-
it.tileMask ^= (1 << bitIndex);
139+
it.tileMask ^= (1u << bitIndex);
127140
#if MAX_LIGHTS_PER_TILE > 32 || CLUSTER_HAS_REFLECTION_PROBES
128141
// Subtract 32 because it stores the index of the _next_ word to fetch, but we want the current.
129142
// The upper 16 bits and bits representing values < 32 are masked out. The latter is due to the fact that it will be
130143
// included in what FIRST_BIT_LOW returns.
131-
entityIndex = (((it.entityIndexNextMax - 32) & (0xFFFF & ~31))) + bitIndex;
144+
entityIndex = (((it.entityIndexNextMax - 32) & (0xFFFFu & ~31))) + bitIndex;
132145
#else
133146
entityIndex = bitIndex;
134147
#endif

0 commit comments

Comments
 (0)