KhronosGroup / KhronosGroup/glslang
Using a buffer_reference buffer within a struct within a SSBO causes invalid const errors
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
These are snippets from my local project where I experience this issue.
```glsl
layout(buffer_reference, scalar) restrict readonly buffer UvBuffer {
vec2 uvs[];
};
struct PrimitiveDraw {
...
UvBuffer uvBuffers[maxUvSets]; // I use an array here, but it doesn't actually matter. Same behaviour with a single buffer.
};
layout(set = 1, binding = 4, scalar) restrict readonly buffer PrimitiveDrawBuffer {
PrimitiveDraw primitives[];
};
void main() {
const PrimitiveDraw draw = primitives[gl_DrawID]; // This is line 39 with the error
}
```
When I remove that array of buffer references the code compiles fine, but just adding that array (not using it) gives this:
```
ERROR: shaders/shadow_map.task.glsl:39: 'qualifier' : variables with reference type can't have qualifier 'const'
ERROR: shaders/shadow_map.task.glsl:39: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.
```
Removing the `const` qualifier does fix the error, but I don't think that is intended behaviour. How can a reference not be const, and why should using a buffer_reference have any effect on that? I'm using the glslangValidator as a compiler from the latest 1.3.283 SDK.
Contributor guide
Research direction
Reproduce the reported shader with glslangValidator from the 1.3.283 SDK, using the buffer_reference member inside PrimitiveDraw and the const assignment in main(). Trace how const qualifiers are validated for structs containing buffer references. Done means the example compiles without the invalid const error while preserving the reported behavior.
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