Skip to content

Fixed error Maximum allowed thread group count is 65535 when resolution is very high. #2068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma kernel ClearList

RWStructuredBuffer<uint> _LightListToClear;
int _LightListEntries;
int2 _LightListEntriesAndOffset;

#define _LightListEntries (uint)_LightListEntriesAndOffset.x
#define _LightListOffset (uint)_LightListEntriesAndOffset.y

[numthreads(64, 1, 1)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do'nt used _LightListOffset in the code, don't think it is expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, forgot to stage the full file! Staging now and pushing

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down