Skip to content

Commit efbcf97

Browse files
committed
Fix up a bunch of shader warnings. HLSL struggles with early outs - often flags them as use of initialized variable.
Clean up a bunch more shader warnings. HLSL really does not like early outs. Silence two more compiler warnings
1 parent 03dd07b commit efbcf97

File tree

14 files changed

+420
-369
lines changed

14 files changed

+420
-369
lines changed

com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,31 @@ real3 GetIndexColor(int index)
4848

4949
bool SampleDebugFont(int2 pixCoord, uint digit)
5050
{
51-
if (pixCoord.x < 0 || pixCoord.y < 0 || pixCoord.x >= 5 || pixCoord.y >= 9 || digit > 9)
52-
return false;
51+
bool isForeground = false;
5352

53+
if ((pixCoord.x < 0 || pixCoord.y < 0 || pixCoord.x >= 5 || pixCoord.y >= 9 || digit > 9))
54+
{
5455
#define PACK_BITS25(_x0,_x1,_x2,_x3,_x4,_x5,_x6,_x7,_x8,_x9,_x10,_x11,_x12,_x13,_x14,_x15,_x16,_x17,_x18,_x19,_x20,_x21,_x22,_x23,_x24) (_x0|(_x1<<1)|(_x2<<2)|(_x3<<3)|(_x4<<4)|(_x5<<5)|(_x6<<6)|(_x7<<7)|(_x8<<8)|(_x9<<9)|(_x10<<10)|(_x11<<11)|(_x12<<12)|(_x13<<13)|(_x14<<14)|(_x15<<15)|(_x16<<16)|(_x17<<17)|(_x18<<18)|(_x19<<19)|(_x20<<20)|(_x21<<21)|(_x22<<22)|(_x23<<23)|(_x24<<24))
5556
#define _ 0
5657
#define x 1
57-
uint fontData[9][2] = {
58-
{ PACK_BITS25(_,_,x,_,_, _,_,x,_,_, _,x,x,x,_, x,x,x,x,x, _,_,_,x,_), PACK_BITS25(x,x,x,x,x, _,x,x,x,_, x,x,x,x,x, _,x,x,x,_, _,x,x,x,_) },
59-
{ PACK_BITS25(_,x,_,x,_, _,x,x,_,_, x,_,_,_,x, _,_,_,_,x, _,_,_,x,_), PACK_BITS25(x,_,_,_,_, x,_,_,_,x, _,_,_,_,x, x,_,_,_,x, x,_,_,_,x) },
60-
{ PACK_BITS25(x,_,_,_,x, x,_,x,_,_, x,_,_,_,x, _,_,_,x,_, _,_,x,x,_), PACK_BITS25(x,_,_,_,_, x,_,_,_,_, _,_,_,x,_, x,_,_,_,x, x,_,_,_,x) },
61-
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,_,_,x, _,_,x,_,_, _,x,_,x,_), PACK_BITS25(x,_,x,x,_, x,_,_,_,_, _,_,_,x,_, x,_,_,_,x, x,_,_,_,x) },
62-
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,_,x,_, _,x,x,x,_, _,x,_,x,_), PACK_BITS25(x,x,_,_,x, x,x,x,x,_, _,_,x,_,_, _,x,x,x,_, _,x,x,x,x) },
63-
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,x,_,_, _,_,_,_,x, x,_,_,x,_), PACK_BITS25(_,_,_,_,x, x,_,_,_,x, _,_,x,_,_, x,_,_,_,x, _,_,_,_,x) },
64-
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,x,_,_,_, _,_,_,_,x, x,x,x,x,x), PACK_BITS25(_,_,_,_,x, x,_,_,_,x, _,x,_,_,_, x,_,_,_,x, _,_,_,_,x) },
65-
{ PACK_BITS25(_,x,_,x,_, _,_,x,_,_, x,_,_,_,_, x,_,_,_,x, _,_,_,x,_), PACK_BITS25(x,_,_,_,x, x,_,_,_,x, _,x,_,_,_, x,_,_,_,x, x,_,_,_,x) },
66-
{ PACK_BITS25(_,_,x,_,_, x,x,x,x,x, x,x,x,x,x, _,x,x,x,_, _,_,_,x,_), PACK_BITS25(_,x,x,x,_, _,x,x,x,_, _,x,_,_,_, _,x,x,x,_, _,x,x,x,_) }
67-
};
58+
uint fontData[9][2] = {
59+
{ PACK_BITS25(_,_,x,_,_, _,_,x,_,_, _,x,x,x,_, x,x,x,x,x, _,_,_,x,_), PACK_BITS25(x,x,x,x,x, _,x,x,x,_, x,x,x,x,x, _,x,x,x,_, _,x,x,x,_) },
60+
{ PACK_BITS25(_,x,_,x,_, _,x,x,_,_, x,_,_,_,x, _,_,_,_,x, _,_,_,x,_), PACK_BITS25(x,_,_,_,_, x,_,_,_,x, _,_,_,_,x, x,_,_,_,x, x,_,_,_,x) },
61+
{ PACK_BITS25(x,_,_,_,x, x,_,x,_,_, x,_,_,_,x, _,_,_,x,_, _,_,x,x,_), PACK_BITS25(x,_,_,_,_, x,_,_,_,_, _,_,_,x,_, x,_,_,_,x, x,_,_,_,x) },
62+
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,_,_,x, _,_,x,_,_, _,x,_,x,_), PACK_BITS25(x,_,x,x,_, x,_,_,_,_, _,_,_,x,_, x,_,_,_,x, x,_,_,_,x) },
63+
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,_,x,_, _,x,x,x,_, _,x,_,x,_), PACK_BITS25(x,x,_,_,x, x,x,x,x,_, _,_,x,_,_, _,x,x,x,_, _,x,x,x,x) },
64+
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,_,x,_,_, _,_,_,_,x, x,_,_,x,_), PACK_BITS25(_,_,_,_,x, x,_,_,_,x, _,_,x,_,_, x,_,_,_,x, _,_,_,_,x) },
65+
{ PACK_BITS25(x,_,_,_,x, _,_,x,_,_, _,x,_,_,_, _,_,_,_,x, x,x,x,x,x), PACK_BITS25(_,_,_,_,x, x,_,_,_,x, _,x,_,_,_, x,_,_,_,x, _,_,_,_,x) },
66+
{ PACK_BITS25(_,x,_,x,_, _,_,x,_,_, x,_,_,_,_, x,_,_,_,x, _,_,_,x,_), PACK_BITS25(x,_,_,_,x, x,_,_,_,x, _,x,_,_,_, x,_,_,_,x, x,_,_,_,x) },
67+
{ PACK_BITS25(_,_,x,_,_, x,x,x,x,x, x,x,x,x,x, _,x,x,x,_, _,_,_,x,_), PACK_BITS25(_,x,x,x,_, _,x,x,x,_, _,x,_,_,_, _,x,x,x,_, _,x,x,x,_) }
68+
};
6869
#undef _
6970
#undef x
7071
#undef PACK_BITS25
71-
return (fontData[8 - pixCoord.y][digit >= 5] >> ((digit % 5) * 5 + pixCoord.x)) & 1;
72+
isForeground = (fontData[8 - pixCoord.y][digit >= 5] >> ((digit % 5) * 5 + pixCoord.x)) & 1;
73+
}
74+
75+
return isForeground;
7276
}
7377

7478
bool SampleDebugFontNumber(int2 pixCoord, uint number)

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, i
173173
// The two following parameter are for float representation
174174
// leading0 is used when drawing frac part of a float to draw the leading 0 (call is in charge of it)
175175
// forceNegativeSign is used to force to display a negative sign as -0 is not recognize
176-
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int leading0, bool forceNegativeSign)
176+
void DrawIntegerWithLeadingZeros(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int leading0, bool forceNegativeSign)
177177
{
178178
const uint maxStringSize = 16;
179179

@@ -218,9 +218,45 @@ void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout
218218
fixedUnormCoord.x += (numEntries + 2) * DEBUG_FONT_TEXT_SCALE_WIDTH;
219219
}
220220

221+
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, bool forceNegativeSign)
222+
{
223+
const uint maxStringSize = 16;
224+
225+
uint absIntValue = abs(intValue);
226+
227+
// 1. Get size of the number of display
228+
int numEntries = min((intValue == 0 ? 0 : log10(absIntValue)) + ((intValue < 0 || forceNegativeSign) ? 1 : 0), maxStringSize);
229+
230+
// 2. Shift curseur to last location as we will go reverse
231+
fixedUnormCoord.x += numEntries * DEBUG_FONT_TEXT_SCALE_WIDTH;
232+
233+
// 3. Display the number
234+
bool drawCharacter = true; // bit weird, but it is to appease the compiler.
235+
for (uint j = 0; j < maxStringSize; ++j)
236+
{
237+
// Numeric value incurrent font start on the second row at 0
238+
if(drawCharacter)
239+
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
240+
241+
if (absIntValue < 10)
242+
drawCharacter = false;
243+
244+
absIntValue /= 10;
245+
}
246+
247+
// 5. Display sign
248+
if (intValue < 0 || forceNegativeSign)
249+
{
250+
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
251+
}
252+
253+
// 6. Reset cursor at end location
254+
fixedUnormCoord.x += (numEntries + 2) * DEBUG_FONT_TEXT_SCALE_WIDTH;
255+
}
256+
221257
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
222258
{
223-
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, false);
259+
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, false);
224260
}
225261

226262
void DrawFloatExplicitPrecision(float floatValue, float3 fontColor, uint2 currentUnormCoord, uint digitCount, inout uint2 fixedUnormCoord, inout float3 color)
@@ -235,11 +271,11 @@ void DrawFloatExplicitPrecision(float floatValue, float3 fontColor, uint2 curren
235271
{
236272
int intValue = int(floatValue);
237273
bool forceNegativeSign = floatValue >= 0.0f ? false : true;
238-
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, forceNegativeSign);
274+
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, forceNegativeSign);
239275
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
240276
int fracValue = int(frac(abs(floatValue)) * pow(10, digitCount));
241277
int leading0 = digitCount - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
242-
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
278+
DrawIntegerWithLeadingZeros(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
243279
}
244280
}
245281

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugExposure.shader

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,33 @@ Shader "Hidden/HDRP/DebugExposure"
237237
{
238238
float2 borderSize = 2 * _ScreenSize.zw * _RTHandleScale.xy;
239239

240-
if (uv.y > frameHeight) return false;
240+
bool res = false;
241241

242-
// ---- Draw General frame ----
243-
if (uv.x < borderSize.x || uv.x >(1.0f - borderSize.x))
242+
if (uv.y <= frameHeight)
244243
{
245-
outColor = 0.0;
246-
return false;
247-
}
248-
else if (uv.y > frameHeight - borderSize.y)
249-
{
250-
outColor = 0.0;
251-
return false;
252-
}
253-
else
254-
{
255-
outColor = lerp(outColor, frameColor, frameAlpha);
256-
}
244+
// ---- Draw General frame ----
245+
if (uv.x < borderSize.x || uv.x >(1.0f - borderSize.x))
246+
{
247+
outColor = 0.0;
248+
}
249+
else if (uv.y > frameHeight - borderSize.y)
250+
{
251+
outColor = 0.0;
252+
}
253+
else
254+
{
255+
outColor = lerp(outColor, frameColor, frameAlpha);
256+
res = true;
257+
}
257258

258-
// ---- Draw label bar -----
259-
if (uv.y < heightLabelBar)
260-
{
261-
outColor = outColor * 0.075f;
262-
}
259+
// ---- Draw label bar -----
260+
if (uv.y < heightLabelBar)
261+
{
262+
outColor = outColor * 0.075f;
263+
}
264+
}
263265

264-
return true;
266+
return res;
265267
}
266268

267269
float2 GetMinMaxLabelRange(float currEV)

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma kernel Deferred_Direct_Fptl SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl
22
#pragma kernel Deferred_Direct_Fptl_DebugDisplay SHADE_OPAQUE_ENTRY=Deferred_Direct_Fptl_DebugDisplay DEBUG_DISPLAY
33

4+
// warning X4714: sum of temp registers and indexable temp registers times 64 threads exceeds the recommended total 16384.
5+
// This warning has been around since we started using HDRP if I remember correctly. Going to silent it so we can get to zero warnings.
6+
#pragma warning(disable: 4714)
7+
48
// Variant with and without shadowmask
59
#pragma kernel Deferred_Indirect_Fptl_Variant0 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant0 USE_INDIRECT VARIANT=0
610
#pragma kernel Deferred_Indirect_Fptl_Variant1 SHADE_OPAQUE_ENTRY=Deferred_Indirect_Fptl_Variant1 USE_INDIRECT VARIANT=1

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagation.hlsl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,16 @@ bool IsFarFromCamera(float3 worldPosition, float rangeInFrontOfCamera, float ran
1616
{
1717
float3 V = (worldPosition - _WorldSpaceCameraPos.xyz);
1818
float distAlongV = dot(GetViewForwardDir(), V);
19-
if (!(distAlongV < rangeInFrontOfCamera && distAlongV > -rangeBehindCamera))
20-
{
21-
return true;
22-
}
23-
24-
return false;
19+
return !(distAlongV < rangeInFrontOfCamera && distAlongV > -rangeBehindCamera);
2520
}
2621

2722
float3 ReadPreviousPropagationAxis(uint probeIndex, uint axisIndex)
2823
{
2924
const uint index = probeIndex * NEIGHBOR_AXIS_COUNT + axisIndex;
3025

3126
// TODO: remove this if check with stricter checks on construction side in C#
32-
if(index < (uint)_RadianceCacheAxisCount)
33-
{
34-
return _PreviousRadianceCacheAxis[index];
35-
}
27+
return (index < (uint)_RadianceCacheAxisCount) ? _PreviousRadianceCacheAxis[index] : 0;
3628

37-
return 0;
3829
}
3930

4031
float3 NormalizeOutputRadiance(float4 lightingAndWeight, float probeValidity)

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProceduralNeighborsMesh.hlsl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ float3 _ProbeVolumeDGIBoundsCenter;
1818

1919
void OrhoNormalAxis(float3 n, out float3 b1, out float3 b2)
2020
{
21-
if(n.z < -0.9999999)
22-
{
23-
b1 = float3( 0.0, -1.0, 0.0);
24-
b2 = float3 (-1.0, 0.0, 0.0);
25-
return;
26-
}
27-
28-
const float a = 1.0/(1.0 + n.z);
29-
const float b = -n.x*n.y*a;
30-
b1 = float3 (1.0 - n.x*n.x*a, b, -n.x);
31-
b2 = float3(b, 1.0 - n.y*n.y*a, -n.y);
21+
float a = 1.0 / (1.0 + n.z);
22+
float b = -n.x * n.y * a;
23+
bool isNegativeZFrame = n.z < -0.9999999;
24+
b1 = isNegativeZFrame ? float3(0.0, -1.0, 0.0) : float3(1.0 - n.x * n.x * a, b, -n.x);
25+
b2 = isNegativeZFrame ? float3(-1.0, 0.0, 0.0) : float3(b, 1.0 - n.y * n.y * a, -n.y);
3226
}
3327

3428
float3 ProbeIndexToProbeCoordinates(uint probeIndex)
@@ -77,7 +71,7 @@ VaryingsType VertMeshProcedural(uint vertexID, uint instanceID)
7771

7872
float3 normal = UnpackNormal(neighborData.normalAxis);
7973
float4 albedoDistance = UnpackAlbedoAndDistance(neighborData.albedoDistance, _ProbeVolumeDGIMaxNeighborDistance);
80-
float3 axis = UnpackAxis(neighborData.normalAxis);
74+
float3 axis = UnpackAxis(neighborData.normalAxis).xyz;
8175

8276
float3x3 probeVolumeLtw = float3x3(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp, cross(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp));
8377
axis = mul(axis, probeVolumeLtw);

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeAtlasBlit.compute

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// warning X4714: sum of temp registers and indexable temp registers times 64 threads exceeds the recommended total 16384.
2+
#pragma warning(disable: 4714)
3+
14
#pragma kernel ProbeVolumeAtlasBlitKernel PROBE_VOLUME_ATLAS_BLIT_KERNEL=ProbeVolumeAtlasBlitKernel
25

36
#ifdef SHADER_API_PSSL

0 commit comments

Comments
 (0)