diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 0d4965f7316..6bcd8eb81c9 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -122,6 +122,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed Light skin not properly applied on the LookDev when switching from Dark Skin (case 1278802) - Fixed accumulation on DX11 - Fixed issue with screen space UI not drawing on the graphics compositor (case 1279272). +- Fixed error Maximum allowed thread group count is 65535 when resolution is very high. ### Changed - Preparation pass for RTSSShadows to be supported by render graph. 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 809ee6feb34..0e390699687 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 @@ -3059,10 +3059,26 @@ BuildGPULightListResources PrepareBuildGPULightListResources(TileAndClusterData static void ClearLightList(in BuildGPULightListParameters parameters, CommandBuffer cmd, ComputeBuffer bufferToClear) { cmd.SetComputeBufferParam(parameters.clearLightListCS, parameters.clearLightListKernel, HDShaderIDs._LightListToClear, bufferToClear); - cmd.SetComputeIntParam(parameters.clearLightListCS, HDShaderIDs._LightListEntries, bufferToClear.count); + Vector2 countAndOffset = new Vector2Int(bufferToClear.count, 0); int groupSize = 64; - cmd.DispatchCompute(parameters.clearLightListCS, parameters.clearLightListKernel, (bufferToClear.count + groupSize - 1) / groupSize, 1, 1); + 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(parameters.clearLightListCS, HDShaderIDs._LightListEntriesAndOffset, countAndOffset); + + int currGroupCount = Math.Min(maxAllowedGroups, totalNumberOfGroupsNeeded); + + cmd.DispatchCompute(parameters.clearLightListCS, parameters.clearLightListKernel, currGroupCount, 1, 1); + + totalNumberOfGroupsNeeded -= currGroupCount; + i++; + } } static void ClearLightLists( in BuildGPULightListParameters parameters, 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 1763a0a51d2..b69648400b5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -127,7 +127,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 _ClusterDebugMode = Shader.PropertyToID("_ClusterDebugMode");