KhronosGroup / KhronosGroup/glslang
Validation for sync in varying flow control
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
FXC HLSL compiler has a useful validation feature that catches invalid synchronization, such as barriers in varying flow control.
Consider the following example HLSL shader:
```
RWBuffer g_buf0;
RWBuffer g_buf1;
groupshared uint g_scratch[64];
[numthreads(64, 1, 1)]
void main(uint3 dtid : SV_DispatchThreadID)
{
g_scratch[dtid.x] = g_buf0[dtid.x];
if((dtid.x & 1) == 0)
{
GroupMemoryBarrierWithGroupSync();
g_buf1[dtid.x/2] = g_scratch[dtid.x] + g_scratch[dtid.x + 1];
}
}
```
FXC reports the following error:
```
unknown(10,9-41): error X3663: thread sync operation found in varying flow control, consider reformulating your algorithm so all threads will hit the sync simultaneously
unknown(8,5-14): error X3663: this variable dependent on potentially varying data: dtid
```
It would be very useful to get similar analysis and error reporting in glslang (for HLSL and GLSL) and perhaps also in other parts of shader toolchain (SPIRV-Tools).
One can try using different compilers (FXC, DXC and glslang) here: http://shader-playground.timjones.io/3be1160d4a42fad22ecceceb4a75f8da
A similar issue is filed for DXC here: https://github.com/Microsoft/DirectXShaderCompiler/issues/1306
Contributor guide
Research direction
Start with the supplied HLSL shader and compare its diagnostics across FXC, DXC, and glslang using the linked Shader Playground example. Define completion as glslang reporting invalid synchronization in varying flow control for HLSL and GLSL, with useful source locations and an explanation comparable to FXC; the issue names no repository files or tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100