From e16e128c48982ddfae4559f87222a66092aca79c Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 7 Jan 2021 13:47:30 +0100 Subject: [PATCH 1/2] Fix issue with spilling of registers --- .../lightlistbuild-clustered.compute | 52 +++++++++--- .../Lighting/LightLoop/scrbound.compute | 82 ++++++++++++------- 2 files changed, 93 insertions(+), 41 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/lightlistbuild-clustered.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/lightlistbuild-clustered.compute index c37acc22e1c..2faf906107d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/lightlistbuild-clustered.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/lightlistbuild-clustered.compute @@ -69,6 +69,38 @@ groupshared float4 lightPlanes[4*6]; // Each plane is defined by a float4. 6 pla groupshared uint lightOffs; +groupshared int categoryListCountScratch[NR_THREADS * LIGHTCATEGORY_COUNT]; +groupshared int shiftIndexScratch[NR_THREADS * LIGHTCATEGORY_COUNT]; + +void ZeroCategoryListCountAndShiftIndex(uint threadIdx) +{ + for (int i = 0; i < LIGHTCATEGORY_COUNT; ++i) + { + categoryListCountScratch[threadIdx * LIGHTCATEGORY_COUNT + i] = 0; + shiftIndexScratch[threadIdx * LIGHTCATEGORY_COUNT + i] = 0; + } +} + +void WriteShiftIndex(uint threadIdx, uint index, int value) +{ + shiftIndexScratch[threadIdx * LIGHTCATEGORY_COUNT + index] = value; +} + +int ReadShiftIndex(uint threadIdx, uint index) +{ + return shiftIndexScratch[threadIdx * LIGHTCATEGORY_COUNT + index]; +} + +void IncrementCategoryListCount(uint threadIdx, uint index) +{ + categoryListCountScratch[threadIdx * LIGHTCATEGORY_COUNT + index]++; +} + +int ReadCategoryListCount(uint threadIdx, uint index) +{ + return categoryListCountScratch[threadIdx * LIGHTCATEGORY_COUNT + index]; +} + #ifdef ENABLE_DEPTH_TEXTURE_BACKPLANE groupshared uint ldsZMax; #endif @@ -379,15 +411,11 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID) // All our cull data are in the same list, but at render time envLights are separated so we need to shift the index // to make it work correctly - int shiftIndex[LIGHTCATEGORY_COUNT]; - ZERO_INITIALIZE_ARRAY(int, shiftIndex, LIGHTCATEGORY_COUNT); - shiftIndex[LIGHTCATEGORY_ENV] = _EnvLightIndexShift; - shiftIndex[LIGHTCATEGORY_DECAL] = _DecalIndexShift; - shiftIndex[LIGHTCATEGORY_DENSITY_VOLUME] = _DensityVolumeIndexShift; - shiftIndex[LIGHTCATEGORY_PROBE_VOLUME] = _ProbeVolumeIndexShift; + ZeroCategoryListCountAndShiftIndex(t); - int categoryListCount[LIGHTCATEGORY_COUNT]; // number of direct lights, reflection probes, decals, density volumes, and probe volumes - ZERO_INITIALIZE_ARRAY(int, categoryListCount, LIGHTCATEGORY_COUNT); + WriteShiftIndex(t, LIGHTCATEGORY_ENV, _EnvLightIndexShift); + WriteShiftIndex(t, LIGHTCATEGORY_DECAL, _DecalIndexShift); + WriteShiftIndex(t, LIGHTCATEGORY_DENSITY_VOLUME, _DensityVolumeIndexShift); uint offs = start; for(int ll=0; ll Date: Thu, 7 Jan 2021 15:50:31 +0100 Subject: [PATCH 2/2] Changelog and small comment change. --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/Lighting/LightLoop/scrbound.compute | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 797b99b9e93..5080e7bac97 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue with half res ssgi upscale. - Fixed Clearcoat on Stacklit or Lit breaks when URP is imported into the project (case 1297806) - Fixed timing issues with accumulation motion blur +- Fixed register spilling on FXC in light list shaders. ### Changed - Removed the material pass probe volumes evaluation mode. diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/scrbound.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/scrbound.compute index 7f56b33b770..521759b54b3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/scrbound.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/scrbound.compute @@ -216,8 +216,7 @@ groupshared uint gs_NdcAaBbMaxPtW[LIGHTS_PER_GROUP]; // View-space Z coordinate #endif // PLATFORM_SUPPORTS_WAVE_INTRINSICS -/// -------------- tmp - +// ----------- Use LDS for the vertex ring buffer as otherwise on FXC we create register spilling groupshared float gs_VertexRingBufferX[MAX_CLIP_VERTS * THREADS_PER_GROUP]; groupshared float gs_VertexRingBufferY[MAX_CLIP_VERTS * THREADS_PER_GROUP]; @@ -241,7 +240,7 @@ void WriteToRingBuffer(uint threadIdx, uint entry, float4 value) gs_VertexRingBufferZ[threadIdx * MAX_CLIP_VERTS + entry] = value.z; gs_VertexRingBufferW[threadIdx * MAX_CLIP_VERTS + entry] = value.w; } -/////////////////////////// +///////////////////////////////////////////////////////// // Returns 'true' if it manages to cull the face.