KhronosGroup / KhronosGroup/SPIRV-Reflect

SPIRV-Reflect incorrectly reports padded_size for members of a storage block

Open
#305 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
871
Forks
188
Avg merge
19m
Merged PRs (30d)
1

Description

Given the following shader I think SPIRV-Reflect does not properly report `padded_size` for the members of SBO:

```
struct S
{
float aa;
float bb;
};

layout(binding = 0, std140) buffer SBO
{
S s1[2][3];
S s2;
} sbo;

void main()
{
gl_Position = vec4(sbo.s1[0][0].aa, 0, 0, 0);
}
```

I get 4 for both `aa` and `bb`, which makes it impossible to correctly compute offsets for members of SBO. In a full reflection of `SBO` I'd expect to get the following offsets:

```
s1[0][0].aa -> 0
s1[0][0].bb -> 4
s1[0][1].aa -> 16
s1[0][1].bb -> 20
s1[0][2].aa -> 32
s1[0][2].bb -> 36
s1[1][0].aa -> 48
s1[1][0].bb -> 52
s1[1][1].aa -> 64
s1[1][1].bb -> 68
s1[1][2].aa -> 80
s1[1][2].bb -> 84
s2.aa -> 96
s2.bb -> 100
```

Instead what I see is this:

```
s1[0][0].aa -> 0
s1[0][0].bb -> 4
s1[0][1].aa -> 8
s1[0][1].bb -> 12
s1[0][2].aa -> 16
s1[0][2].bb -> 20
s1[1][0].aa -> 24
s1[1][0].bb -> 28
s1[1][1].aa -> 32
s1[1][1].bb -> 36
s1[1][2].aa -> 40
s1[1][2].bb -> 44
s2.aa -> 48
s2.bb -> 52
```

Interestingly this works fine for uniform blocks, i.e. if I replace `buffer` with `uniform` in my example, `padded_size` gets reported correctly.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the shader reproducer in the issue and compare reflection of the std140 storage block with the uniform-block variant, focusing on how nested array members contribute to padded_size. Done means the storage-block offsets match the listed expected offsets for s1 and s2, while the existing uniform-block behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.