KhronosGroup / KhronosGroup/SPIRV-Cross
Array with size using specialization constant passed as function parameter error
- Dominant language
- GLSL
- Stars
- 2.5k
- Forks
- 713
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 16
Description
origin glsl:
```
#version 460
#extension GL_EXT_shader_explicit_arithmetic_types : enable
layout(constant_id = 0) const uint32_t RANK_OUT = 4;
layout(local_size_x = 64) in;
void outputOffsetToIndex(uint[RANK_OUT] shape, uint offset, out uint[RANK_OUT] index) {
for(uint32_t i = RANK_OUT - 1; i >= 0; i--) {
index[i] = offset % shape[i];
offset /= shape[i];
}
}
void main() {
uint offset = gl_GlobalInvocationID.x;
uint[RANK_OUT] shape;
if (RANK_OUT == 4)
{
shape[0] = 1;
shape[1] = 4;
shape[2] = 4;
shape[3] = 1;
}
uint[RANK_OUT] index;
outputOffsetToIndex(shape, offset, index);
}
```
compile with glslang and used SPIRV-Cross to get decompiled glsl again, get following code:
```
#version 460
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(constant_id = 0) const uint RANK_OUT = 4u;
const uint _19 = (RANK_OUT - 1u);
const bool _53 = (RANK_OUT == 4u);
void outputOffsetToIndex(uint shape[RANK_OUT], inout uint offset, inout uint index[RANK_OUT])
{
for (uint i = _19; i >= 0u; i--)
{
index[i] = offset % shape[i];
offset /= shape[i];
}
}
void main()
{
uint offset = gl_GlobalInvocationID.x;
uint shape[RANK_OUT];
if (_53)
{
shape[0] = 1u;
shape[1] = 4u;
shape[2] = 4u;
shape[3] = 1u;
}
uint param[RANK_OUT] = shape;
uint param_1 = offset;
uint param_2[RANK_OUT];
outputOffsetToIndex(param, param_1, param_2);
uint index[RANK_OUT] = param_2;
}
```
but this code got compile error: 'initializer' : can't use with types containing arrays sized with a specialization constant
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the GLSL-to-SPIR-V-to-GLSL round trip using the specialization-constant array and function-parameter example in the issue, first checking the glslang compilation and SPIRV-Cross decompilation. Compare the generated initializer-based code with the reported GLSL compiler error; done means the decompiled shader compiles without the specialization-constant array initializer failure.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100