KhronosGroup / KhronosGroup/glslang
Feature request: warning about push_constant/uniform member's offset and alignment
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
This feature request actually comes in two parts.
### Warning about bug inducing member ordering
Consider this:
```glsl
layout(push_constant) uniform Pc {
vec3 m1;
vec4 m2;
float m3;
float m4;
} pc;
```
The offset of `m2` will be 16 instead of 12, and trying to access any following members will give you incorrect values. Even though this behavior follows the rules specified in section `14.5.4` of Vulkan spec, it is not immediately obvious to newcomers like myself that the bug relates to these rules. It would be nice if some warning would be raised while compiling to notify the developer about this potential problem and how it can be fixed (in this example, swapping `m2` and `m3`'s order will do).
### More helpful error message for incorrect offset value in layout
Additionally, I actually started out explicitly specifying the offset for all the members like this:
```glsl
layout(push_constant) uniform Pc {
layout(offset=0) vec3 m1;
layout(offset=12) vec4 m2;
layout(offset=28) float m3;
layout(offset=32) float m4;
} pc;
```
This is clearly incorrect now I know about the rules, but the error message given by the compiler is just `'offset' : must be a multiple of the member's alignment`, which isn't really all that helpful. Would it be possible to state which member is wrong and what the correct offset should be in the error message?
Contributor guide
Research direction
The issue names no source files or tests. Start by tracing glslang's validation and diagnostic handling for push-constant and uniform member layouts, then identify existing tests for offset and alignment errors. Done should include a warning for risky member ordering and a diagnostic that identifies the invalid member and expected offset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100