Skip to content

Commit 76b4443

Browse files
committed
** Increasing HDRP fined prunned light tile count to 64. **
* Missing offset * Adding the light counter as a centralized parameter in ShaderConfig.cs * Extra in comment * Making bit allocation of clustered size / counter be automatically packed from new config * Fixing some bugs with min / max * Extra comment on configuration for 8k rendering * Fixing flags for contact shadows and other review items from feedback * Changelog * Updated features and new doc for ShaderConfig light limit setting * Adding upgrade guide and what's new * Merging changes from fast PrepareLightsForGPU
1 parent 2732801 commit 76b4443

File tree

15 files changed

+85
-28
lines changed

15 files changed

+85
-28
lines changed

com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace UnityEngine.Rendering.HighDefinition
66
{
7+
internal enum FPTLMaxLightSizes
8+
{
9+
Small = 31,
10+
High = 63
11+
}
12+
713
/// <summary>
814
/// Project-wide shader configuration options.
915
/// </summary>
@@ -36,6 +42,13 @@ public enum ShaderOptions
3642

3743
/// <summary>Support to apply a global mip bias on all texture samplers of HDRP.</summary>
3844
GlobalMipBias = 1,
45+
46+
/// <summary>
47+
/// Maximum number of lights for a fine pruned light tile. This number can only be 3 prespecified possibilities, 23, 31 or 63.
48+
/// The reserved index is there for the count of the fined prunned tile list. The lower the count, some memory savings will occur for the tile light list.
49+
/// Note: For any rendering bigger than 4k (in native) it is recommended to use Medium or Small light counts per tile, to avoid possible artifacts.
50+
/// </summary>
51+
FPTLMaxLightCount = FPTLMaxLightSizes.High
3952
};
4053

4154
// Note: #define can't be use in include file in C# so we chose this way to configure both C# and hlsl
@@ -73,5 +86,8 @@ public class ShaderConfig
7386
/// <summary>Indicates whether to support application of global mip bias on all texture samplers of hdrp.</summary>
7487
///<seealso cref="ShaderOptions.GlobalMipBias"/>
7588
public static bool s_GlobalMipBias = (int)ShaderOptions.GlobalMipBias != 0;
89+
/// <summary>Indicates the maximum number of lights available for Fine Prunning Tile Lighting.</summary>
90+
/// <seealso cref="ShaderOptions.FPTLMaxLightCount"/>
91+
public static int FPTLMaxLightCount = (int)ShaderOptions.FPTLMaxLightCount;
7692
}
7793
}

com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define SHADEROPTIONS_AREA_LIGHTS (1)
1616
#define SHADEROPTIONS_BARN_DOOR (0)
1717
#define SHADEROPTIONS_GLOBAL_MIP_BIAS (1)
18+
#define SHADEROPTIONS_FPTLMAX_LIGHT_COUNT (63)
1819

1920

2021
#endif

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4545

4646
### Added
4747
- Added public API to edit materials from script at runtime.
48+
- Added new configuration ShderOptions.FPTLMaxLightCount in ShaderConfig.cs for maximum light count per fine pruned tile.
4849

4950
### Fixed
5051
- Fixed impossibility to release the cursor in the template.
@@ -104,6 +105,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
104105
- Path-traced volumetric scattering now takes fog color into account, adding scattered contribution on top of the non-scattered result (cases 1346105, 1358783).
105106
- Fixed minor readability issues in the ray tracing code.
106107
- PrepareLightsForGPU CPU Light loop performance improvement (40% to 70% faster), utilizing burst and optimized. Utilizing better sorting, distributing work in jobs and improving cache access of light data.
108+
- Maximum light count per fine prunned tile (opaque deferred) is now 63 instead of 23.
107109

108110
## [12.0.0] - 2021-01-11
109111

com.unity.render-pipelines.high-definition/Documentation~/HDRP-Features.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ Real time raytracing effect are currently in Preview and behavior could change i
318318

319319
<a name="Camera"></a>
320320

321+
### Light count limit
322+
323+
HDRP has a maximum limit on the number of lights a single pixel can get influence from. This setting can be configured through the ShaderConfig.cs file as the FPTLMaxLightCount. By default, HDRP's maximum light count per pixel is 64.
324+
The only two possible values HDRP supports are 32 and 64. For more information on how to configure this setting, please see [HDRP Config package](HDRP-Config-Package.md).
325+
321326
## Camera
322327

323328
### Post-processing

com.unity.render-pipelines.high-definition/Documentation~/Upgrading-from-2021.1-to-2021.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The algorithm to calculate the contribution of ambient occlusion and specular oc
3434
### Light list
3535

3636
The previous `g_vLightListGlobal` uniform have been rename to explicit `g_vLightListTile` and `g_vLightListCluster` light list name. This work required to fix a wrong behavior on console.
37+
Added a new setting in ShaderConfig.cs, FPTLMaxLightCount. This setting can now set the maximum number of lights per tile on the GPU. A new Shader config project must be generated to upgrade. See the [HDRP-Config-Package](HDRP-Config-Package.md) guide for information on how to upgrade.
3738

3839
## Density Volumes
3940

com.unity.render-pipelines.high-definition/Documentation~/whats-new-12.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ From HDRP 12.0, HDRP includes a new [Light Anchor](light-anchor.md) component. Y
6060
![](Images/LightAnchor0.png)
6161

6262

63+
### Maximum light count for gpu
64+
The new default maximum light count per pixel for Fine Prunning Tile List is now 64.
65+
Added a new setting in ShaderConfig.cs, FPTLMaxLightCount. This setting can now set the maximum number of lights per tile on the GPU. A new Shader config project must be generated to upgrade. See the [HDRP-Config-Package](HDRP-Config-Package.md) guide for information on how to upgrade.
6366

6467
## New upsampling methods
6568

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ void RegisterLightingDebug()
15341534
data.fullScreenContactShadowLightIndex = value;
15351535
},
15361536
min = () => - 1, // -1 will display all contact shadow
1537-
max = () => LightDefinitions.s_LightListMaxPrunedEntries - 1
1537+
max = () => ShaderConfig.FPTLMaxLightCount - 1
15381538
},
15391539
}
15401540
});

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Shader "Hidden/HDRP/DebugViewTiles"
190190

191191
#ifdef DISABLE_TILE_MODE
192192
// Tile debug mode is not supported in MSAA (only cluster)
193-
int maxLights = 32;
193+
int maxLights = (LIGHT_CLUSTER_PACKING_COUNT_MASK + 1);
194194
const int textSize = 23;
195195
const int text[textSize] = {'N', 'o', 't', ' ', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e', 'd', ' ', 'w', 'i', 't', 'h', ' ', 'M', 'S', 'A', 'A'};
196196
if (input.positionCS.y < DEBUG_FONT_TEXT_HEIGHT)
@@ -209,7 +209,7 @@ Shader "Hidden/HDRP/DebugViewTiles"
209209
// Tile overlap counter
210210
if (n >= 0)
211211
{
212-
const uint maxLightsPerTile = 31;
212+
const uint maxLightsPerTile = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT;
213213
const float opacity = 0.3f;
214214
result = OverlayHeatMap(int2(posInput.positionSS.xy), GetTileSize(), n, maxLightsPerTile, opacity);
215215
}
@@ -224,8 +224,8 @@ Shader "Hidden/HDRP/DebugViewTiles"
224224
}
225225

226226
// Print light lists for selected tile at the bottom of the screen
227-
int maxLights = 32;
228-
if (tileCoord.y < LIGHTCATEGORY_COUNT && tileCoord.x < maxLights + 3)
227+
int maxAreaWidth = SHADEROPTIONS_FPTLMAX_LIGHT_COUNT + 4;
228+
if (tileCoord.y < LIGHTCATEGORY_COUNT && tileCoord.x < maxAreaWidth)
229229
{
230230
float depthMouse = GetTileDepth(_MousePixelCoord.xy);
231231

com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void GetContactShadowMask(HDAdditionalLightData hdAdditionalLightData, B
221221
// If contact shadows are not enabled or we already reached the manimal number of contact shadows
222222
// or this is not rasterization
223223
if ((!hdAdditionalLightData.useContactShadow.Value(contactShadowEnabled))
224-
|| m_ContactShadowIndex >= LightDefinitions.s_LightListMaxPrunedEntries)
224+
|| m_ContactShadowIndex >= LightDefinitions.s_ContactShadowMaskMask)
225225
return;
226226

227227
// Evaluate the contact shadow index of this light

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,16 @@ class LightDefinitions
107107

108108
// light list limits
109109
public static int s_LightListMaxCoarseEntries = 64;
110-
public static int s_LightListMaxPrunedEntries = 24;
111110
public static int s_LightClusterMaxCoarseEntries = 128;
112111

112+
// We have room for ShaderConfig.FPTLMaxLightCount lights, plus 1 implicit value for length.
113+
// We allocate only 16 bits per light index & length, thus we divide by 2, and store in a word buffer.
114+
public static int s_LightDwordPerFptlTile = ((ShaderConfig.FPTLMaxLightCount + 1)) / 2;
115+
public static int s_LightClusterPackingCountBits = (int)Mathf.Ceil(Mathf.Log(Mathf.NextPowerOfTwo(ShaderConfig.FPTLMaxLightCount), 2));
116+
public static int s_LightClusterPackingCountMask = (1 << s_LightClusterPackingCountBits) - 1;
117+
public static int s_LightClusterPackingOffsetBits = 32 - s_LightClusterPackingCountBits;
118+
public static int s_LightClusterPackingOffsetMask = (1 << s_LightClusterPackingOffsetBits) - 1;
119+
113120
// Following define the maximum number of bits use in each feature category.
114121
public static uint s_LightFeatureMaskFlags = 0xFFF000;
115122
public static uint s_LightFeatureMaskFlagsOpaque = 0xFFF000 & ~((uint)LightFeatureFlags.SSRefraction); // Opaque don't support screen space refraction
@@ -121,6 +128,13 @@ class LightDefinitions
121128
public static uint s_ScreenSpaceColorShadowFlag = 0x100;
122129
public static uint s_InvalidScreenSpaceShadow = 0xff;
123130
public static uint s_ScreenSpaceShadowIndexMask = 0xff;
131+
132+
//Contact shadow bit definitions
133+
public static int s_ContactShadowFadeBits = 8;
134+
public static int s_ContactShadowMaskBits = 32 - s_ContactShadowFadeBits;
135+
public static int s_ContactShadowFadeMask = (1 << s_ContactShadowFadeBits) - 1;
136+
public static int s_ContactShadowMaskMask = (1 << s_ContactShadowMaskBits) - 1;
137+
124138
}
125139

126140
[GenerateHLSL]
@@ -2130,14 +2144,15 @@ bool WillRenderContactShadow()
21302144

21312145
// The first rendered 24 lights that have contact shadow enabled have a mask used to select the bit that contains
21322146
// the contact shadow shadowed information (occluded or not). Otherwise -1 is written
2147+
// 8 bits are reserved for the fading.
21332148
void GetContactShadowMask(HDAdditionalLightData hdAdditionalLightData, BoolScalableSetting contactShadowEnabled, HDCamera hdCamera, bool isRasterization, ref int contactShadowMask, ref float rayTracingShadowFlag)
21342149
{
21352150
contactShadowMask = 0;
21362151
rayTracingShadowFlag = 0.0f;
21372152
// If contact shadows are not enabled or we already reached the manimal number of contact shadows
21382153
// or this is not rasterization
21392154
if ((!hdAdditionalLightData.useContactShadow.Value(contactShadowEnabled))
2140-
|| m_ContactShadowIndex >= LightDefinitions.s_LightListMaxPrunedEntries
2155+
|| m_ContactShadowIndex >= LightDefinitions.s_ContactShadowMaskMask
21412156
|| !isRasterization)
21422157
return;
21432158

0 commit comments

Comments
 (0)