KhronosGroup / KhronosGroup/glslang
Incorrect offsets when using --hlsl-offsets switch
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
When using the HLSL offsets mode the following buffer definitions generate offsets that improperly straddle 16-byte boundaries. This means that they are not compatible with Vulkan's relaxed layouts, and I think that they are supposed to be.
```
struct {
float x;
struct { // Alignment 8, Offset 8
float a;
vec2 b; // Offset 4 within the struct => offset 12, and improperly straddles to 20
} y;
};
```
```
struct {
float a; // Offset 0
vec2 b; // Offset 4
float c; // Offset 12
float d; // Offset 16
} x[2]; // Alignment 8 => Array stride of 24
```
`x[1].b` improperly straddles from offset 28 to 36.
Contributor guide
Research direction
Start by reproducing the two buffer-layout cases with the --hlsl-offsets switch and inspect the compiler path that calculates their nested-member and array offsets. Compare the generated offsets with Vulkan relaxed-layout requirements; the work is done when the nested vec2 and x[1].b no longer straddle 16-byte boundaries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100