diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 3169bd060ae..005e3a9c54e 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed XR shadows culling - Fixed volument component creation via script. - Fixed issue with exposure history being uninitialized on second frame. +- Fixed error Maximum allowed thread group count is 65535 when resolution is very high. ### Changed - Removed XRSystemTests. The GC verification is now done during playmode tests (case 1285012). diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ClearLightLists.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ClearLightLists.compute index 32274fae94b..941732df6da 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ClearLightLists.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ClearLightLists.compute @@ -1,11 +1,14 @@ #pragma kernel ClearList RWStructuredBuffer _LightListToClear; -int _LightListEntries; +int2 _LightListEntriesAndOffset; + +#define _LightListEntries (uint)_LightListEntriesAndOffset.x +#define _LightListOffset (uint)_LightListEntriesAndOffset.y [numthreads(64, 1, 1)] void ClearList(uint3 id : SV_DispatchThreadID) { - if (id.x < (uint)_LightListEntries) - _LightListToClear[id.x] = 0; + if ((id.x + _LightListOffset) < (uint)_LightListEntries) + _LightListToClear[id.x + _LightListOffset] = 0; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index e8215942c9c..193a8e3afc1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -3126,9 +3126,27 @@ void ClearLightList(HDCamera camera, CommandBuffer cmd, ComputeBuffer bufferToCl var kernel = cs.FindKernel("ClearList"); cmd.SetComputeBufferParam(cs, kernel, HDShaderIDs._LightListToClear, bufferToClear); - cmd.SetComputeIntParam(cs, HDShaderIDs._LightListEntries, bufferToClear.count); + Vector2 countAndOffset = new Vector2Int(bufferToClear.count, 0); int groupSize = 64; + int totalNumberOfGroupsNeeded = (bufferToClear.count + groupSize - 1) / groupSize; + + const int maxAllowedGroups = 65535; + // On higher resolutions we might end up with more than 65535 group which is not allowed, so we need to to have multiple dispatches. + int i = 0; + while (totalNumberOfGroupsNeeded > 0) + { + countAndOffset.y = maxAllowedGroups * i; + cmd.SetComputeVectorParam(cs, HDShaderIDs._LightListEntriesAndOffset, countAndOffset); + + int currGroupCount = Math.Min(maxAllowedGroups, totalNumberOfGroupsNeeded); + + cmd.DispatchCompute(cs, kernel, currGroupCount, 1, 1); + + totalNumberOfGroupsNeeded -= currGroupCount; + i++; + } + cmd.DispatchCompute(cs, kernel, (bufferToClear.count + groupSize - 1) / groupSize, 1, 1); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 0414b52ecca..ba6cf0f715b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -172,7 +172,7 @@ static class HDShaderIDs public static readonly int g_vLayeredOffsetsBuffer = Shader.PropertyToID("g_vLayeredOffsetsBuffer"); public static readonly int _LightListToClear = Shader.PropertyToID("_LightListToClear"); - public static readonly int _LightListEntries = Shader.PropertyToID("_LightListEntries"); + public static readonly int _LightListEntriesAndOffset = Shader.PropertyToID("_LightListEntriesAndOffset"); public static readonly int _ViewTilesFlags = Shader.PropertyToID("_ViewTilesFlags"); public static readonly int _MousePixelCoord = Shader.PropertyToID("_MousePixelCoord");