From 016b596dea8fe4babe2c4c719f30e6150f8a9182 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 1 Oct 2020 11:17:29 +0200 Subject: [PATCH 1/4] Fix issue when we need more than 65535 --- .../LightLoop/ClearLightLists.compute | 5 ++++- .../Runtime/Lighting/LightLoop/LightLoop.cs | 22 +++++++++++++++++-- .../RenderPipeline/HDStringConstants.cs | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) 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..b4a2146d201 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,7 +1,10 @@ #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) 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 30671f5e233..14ac1ab2776 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,28 @@ 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; + int numberOfNeededDispatches = HDUtils.DivRoundUp(totalNumberOfGroupsNeeded, maxAllowedGroups); + + // 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 e0c8883b760..b087bc193be 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"); From a812793878574904f0c96f2daeac8fb6b0650f57 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 1 Oct 2020 11:21:19 +0200 Subject: [PATCH 2/4] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 6a43baa1257..09798a06d73 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -115,6 +115,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a warning in materialevalulation - Fixed an error when building the player. - Fixed issue with box light not visible if range is below one and range attenuation is off. +- 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. From 2213dde2789a0e9c518590d2d4083c9898072059 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Thu, 1 Oct 2020 16:13:52 +0200 Subject: [PATCH 3/4] Push rest of file --- .../Runtime/Lighting/LightLoop/ClearLightLists.compute | 2 +- .../Runtime/Lighting/LightLoop/LightLoop.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) 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 b4a2146d201..2155ef9507c 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 @@ -9,6 +9,6 @@ int2 _LightListEntriesAndOffset; [numthreads(64, 1, 1)] void ClearList(uint3 id : SV_DispatchThreadID) { - if (id.x < (uint)_LightListEntries) + if ((id.x + _LightListOffset) < (uint)_LightListEntries) _LightListToClear[id.x] = 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 14ac1ab2776..eb9ddacb9e0 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 @@ -3065,8 +3065,6 @@ static void ClearLightList(in BuildGPULightListParameters parameters, CommandBuf int totalNumberOfGroupsNeeded = (bufferToClear.count + groupSize - 1) / groupSize; const int maxAllowedGroups = 65535; - int numberOfNeededDispatches = HDUtils.DivRoundUp(totalNumberOfGroupsNeeded, maxAllowedGroups); - // 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) From de574539ef54f83fdd139311125995c9c9941a27 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 2 Oct 2020 12:11:25 +0200 Subject: [PATCH 4/4] Missing offset --- .../Runtime/Lighting/LightLoop/ClearLightLists.compute | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2155ef9507c..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 @@ -10,5 +10,5 @@ int2 _LightListEntriesAndOffset; void ClearList(uint3 id : SV_DispatchThreadID) { if ((id.x + _LightListOffset) < (uint)_LightListEntries) - _LightListToClear[id.x] = 0; + _LightListToClear[id.x + _LightListOffset] = 0; }