Skip to content

Commit 971a876

Browse files
Check if parent is actually a runtime array
1 parent c637858 commit 971a876

32 files changed

+766
-326
lines changed

spirv_reflect.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,19 @@ static SpvReflectResult ParseDescriptorBlocks(SpvReflectPrvParser* p_parser, Spv
30013001

30023002
p_descriptor->block.name = p_descriptor->name;
30033003

3004-
bool is_parent_rta = (p_descriptor->descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER);
3004+
// We quick find if there is a runtime array in the top level of the struct (they can't be nested)
3005+
// Would be ideal to have this integrated into ParseDescriptorBlockVariableSizes() itself, but might need to re-work size logic
3006+
bool is_parent_rta = false;
3007+
if (p_descriptor->block.member_count != 0) {
3008+
for (uint32_t member_index = 0; member_index < p_descriptor->block.member_count; ++member_index) {
3009+
SpvReflectBlockVariable* p_member_var = &p_descriptor->block.members[member_index];
3010+
SpvReflectTypeDescription* p_member_type = p_member_var->type_description;
3011+
if (p_member_type && p_member_type->op == SpvOpTypeRuntimeArray) {
3012+
is_parent_rta = true;
3013+
}
3014+
}
3015+
}
3016+
30053017
result = ParseDescriptorBlockVariableSizes(p_parser, p_module, true, false, is_parent_rta, &p_descriptor->block);
30063018
if (result != SPV_REFLECT_RESULT_SUCCESS) {
30073019
return result;

tests/glsl/buffer_handle_0.spv.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ all_block_variables:
10281028
offset: 0
10291029
absolute_offset: 0
10301030
size: 4
1031-
padded_size: 4
1031+
padded_size: 8
10321032
decorations: 0x00000000 # NONE
10331033
numeric:
10341034
scalar: { width: 32, signedness: 1 }
@@ -1095,7 +1095,7 @@ all_block_variables:
10951095
offset: 0
10961096
absolute_offset: 0
10971097
size: 8
1098-
padded_size: 8
1098+
padded_size: 16
10991099
decorations: 0x00000000 # NONE
11001100
numeric:
11011101
scalar: { width: 0, signedness: 0 }
@@ -1114,8 +1114,8 @@ all_block_variables:
11141114
name: "s5"
11151115
offset: 0
11161116
absolute_offset: 0
1117-
size: 0
1118-
padded_size: 0
1117+
size: 16
1118+
padded_size: 16
11191119
decorations: 0x00000000 # NONE
11201120
numeric:
11211121
scalar: { width: 0, signedness: 0 }
@@ -1132,7 +1132,7 @@ all_block_variables:
11321132
offset: 0
11331133
absolute_offset: 0
11341134
size: 4
1135-
padded_size: 4
1135+
padded_size: 8
11361136
decorations: 0x00000000 # NONE
11371137
numeric:
11381138
scalar: { width: 32, signedness: 1 }
@@ -1148,7 +1148,7 @@ all_block_variables:
11481148
offset: 0
11491149
absolute_offset: 0
11501150
size: 4
1151-
padded_size: 4
1151+
padded_size: 8
11521152
decorations: 0x00000000 # NONE
11531153
numeric:
11541154
scalar: { width: 32, signedness: 1 }
@@ -1198,7 +1198,7 @@ all_block_variables:
11981198
offset: 0
11991199
absolute_offset: 0
12001200
size: 8
1201-
padded_size: 8
1201+
padded_size: 16
12021202
decorations: 0x00000000 # NONE
12031203
numeric:
12041204
scalar: { width: 0, signedness: 0 }
@@ -1234,8 +1234,8 @@ all_block_variables:
12341234
name: "x"
12351235
offset: 0
12361236
absolute_offset: 0
1237-
size: 0
1238-
padded_size: 0
1237+
size: 32
1238+
padded_size: 32
12391239
decorations: 0x00000000 # NONE
12401240
numeric:
12411241
scalar: { width: 0, signedness: 0 }

tests/glsl/buffer_handle_1.spv.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ all_block_variables:
455455
offset: 0
456456
absolute_offset: 0
457457
size: 4
458-
padded_size: 4
458+
padded_size: 8
459459
decorations: 0x00000000 # NONE
460460
numeric:
461461
scalar: { width: 32, signedness: 1 }
@@ -471,7 +471,7 @@ all_block_variables:
471471
offset: 0
472472
absolute_offset: 0
473473
size: 4
474-
padded_size: 4
474+
padded_size: 8
475475
decorations: 0x00000000 # NONE
476476
numeric:
477477
scalar: { width: 32, signedness: 1 }
@@ -505,7 +505,7 @@ all_block_variables:
505505
offset: 0
506506
absolute_offset: 0
507507
size: 8
508-
padded_size: 8
508+
padded_size: 16
509509
decorations: 0x00000000 # NONE
510510
numeric:
511511
scalar: { width: 0, signedness: 0 }
@@ -522,8 +522,8 @@ all_block_variables:
522522
name: "s5"
523523
offset: 0
524524
absolute_offset: 0
525-
size: 0
526-
padded_size: 0
525+
size: 16
526+
padded_size: 16
527527
decorations: 0x00000000 # NONE
528528
numeric:
529529
scalar: { width: 0, signedness: 0 }
@@ -540,7 +540,7 @@ all_block_variables:
540540
offset: 0
541541
absolute_offset: 0
542542
size: 4
543-
padded_size: 4
543+
padded_size: 8
544544
decorations: 0x00000000 # NONE
545545
numeric:
546546
scalar: { width: 32, signedness: 1 }
@@ -556,7 +556,7 @@ all_block_variables:
556556
offset: 0
557557
absolute_offset: 0
558558
size: 4
559-
padded_size: 4
559+
padded_size: 8
560560
decorations: 0x00000000 # NONE
561561
numeric:
562562
scalar: { width: 32, signedness: 1 }
@@ -572,7 +572,7 @@ all_block_variables:
572572
offset: 0
573573
absolute_offset: 0
574574
size: 4
575-
padded_size: 4
575+
padded_size: 8
576576
decorations: 0x00000000 # NONE
577577
numeric:
578578
scalar: { width: 32, signedness: 1 }
@@ -623,8 +623,8 @@ all_block_variables:
623623
name: "x"
624624
offset: 0
625625
absolute_offset: 0
626-
size: 0
627-
padded_size: 0
626+
size: 16
627+
padded_size: 16
628628
decorations: 0x00000000 # NONE
629629
numeric:
630630
scalar: { width: 0, signedness: 0 }

tests/glsl/buffer_handle_2.spv.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ all_block_variables:
618618
offset: 0
619619
absolute_offset: 0
620620
size: 8
621-
padded_size: 8
621+
padded_size: 32
622622
decorations: 0x00000000 # NONE
623623
numeric:
624624
scalar: { width: 32, signedness: 1 }
@@ -634,7 +634,7 @@ all_block_variables:
634634
offset: 32
635635
absolute_offset: 32
636636
size: 4
637-
padded_size: 4
637+
padded_size: 16
638638
decorations: 0x00000000 # NONE
639639
numeric:
640640
scalar: { width: 32, signedness: 1 }
@@ -650,7 +650,7 @@ all_block_variables:
650650
offset: 0
651651
absolute_offset: 0
652652
size: 8
653-
padded_size: 8
653+
padded_size: 32
654654
decorations: 0x00000000 # NONE
655655
numeric:
656656
scalar: { width: 32, signedness: 1 }
@@ -666,7 +666,7 @@ all_block_variables:
666666
offset: 32
667667
absolute_offset: 0
668668
size: 4
669-
padded_size: 4
669+
padded_size: 16
670670
decorations: 0x00000000 # NONE
671671
numeric:
672672
scalar: { width: 32, signedness: 1 }
@@ -682,7 +682,7 @@ all_block_variables:
682682
offset: 48
683683
absolute_offset: 48
684684
size: 0
685-
padded_size: 0
685+
padded_size: 32
686686
decorations: 0x00000000 # NONE
687687
numeric:
688688
scalar: { width: 0, signedness: 0 }
@@ -701,8 +701,8 @@ all_block_variables:
701701
name: "x"
702702
offset: 0
703703
absolute_offset: 0
704-
size: 0
705-
padded_size: 0
704+
size: 80
705+
padded_size: 80
706706
decorations: 0x00000000 # NONE
707707
numeric:
708708
scalar: { width: 0, signedness: 0 }

tests/glsl/buffer_handle_3.spv.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ all_block_variables:
258258
offset: 0
259259
absolute_offset: 0
260260
size: 4
261-
padded_size: 4
261+
padded_size: 8
262262
decorations: 0x00000000 # NONE
263263
numeric:
264264
scalar: { width: 32, signedness: 1 }
@@ -291,7 +291,7 @@ all_block_variables:
291291
offset: 0
292292
absolute_offset: 0
293293
size: 8
294-
padded_size: 8
294+
padded_size: 16
295295
decorations: 0x00000000 # NONE
296296
numeric:
297297
scalar: { width: 0, signedness: 0 }
@@ -308,8 +308,8 @@ all_block_variables:
308308
name: "s5"
309309
offset: 0
310310
absolute_offset: 0
311-
size: 0
312-
padded_size: 0
311+
size: 16
312+
padded_size: 16
313313
decorations: 0x00000000 # NONE
314314
numeric:
315315
scalar: { width: 0, signedness: 0 }
@@ -326,7 +326,7 @@ all_block_variables:
326326
offset: 0
327327
absolute_offset: 0
328328
size: 4
329-
padded_size: 4
329+
padded_size: 8
330330
decorations: 0x00000000 # NONE
331331
numeric:
332332
scalar: { width: 32, signedness: 1 }
@@ -358,8 +358,8 @@ all_block_variables:
358358
name: "x"
359359
offset: 0
360360
absolute_offset: 0
361-
size: 0
362-
padded_size: 0
361+
size: 16
362+
padded_size: 16
363363
decorations: 0x00000000 # NONE
364364
numeric:
365365
scalar: { width: 0, signedness: 0 }

tests/glsl/buffer_handle_8.spv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ all_block_variables:
131131
name: "x"
132132
offset: 0
133133
absolute_offset: 0
134-
size: 0
135-
padded_size: 0
134+
size: 48
135+
padded_size: 48
136136
decorations: 0x00000000 # NONE
137137
numeric:
138138
scalar: { width: 0, signedness: 0 }

tests/glsl/buffer_handle_uvec2_ssbo.spv.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ all_block_variables:
4242
offset: 0
4343
absolute_offset: 0
4444
size: 8
45-
padded_size: 8
45+
padded_size: 16
4646
decorations: 0x00000000 # NONE
4747
numeric:
4848
scalar: { width: 32, signedness: 0 }
@@ -57,8 +57,8 @@ all_block_variables:
5757
name: "ssbo"
5858
offset: 0
5959
absolute_offset: 0
60-
size: 0
61-
padded_size: 0
60+
size: 16
61+
padded_size: 16
6262
decorations: 0x00000000 # NONE
6363
numeric:
6464
scalar: { width: 0, signedness: 0 }

tests/glsl/readonly_writeonly.spv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ all_block_variables:
142142
name: "foo"
143143
offset: 0
144144
absolute_offset: 0
145-
size: 0
146-
padded_size: 0
145+
size: 768
146+
padded_size: 768
147147
decorations: 0x00000080 # NON_WRITABLE
148148
numeric:
149149
scalar: { width: 0, signedness: 0 }

tests/glsl/storage_buffer.spv.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ all_block_variables:
109109
name: ""
110110
offset: 0
111111
absolute_offset: 0
112-
size: 0
113-
padded_size: 0
112+
size: 256
113+
padded_size: 256
114114
decorations: 0x00000000 # NONE
115115
numeric:
116116
scalar: { width: 0, signedness: 0 }
@@ -142,8 +142,8 @@ all_block_variables:
142142
name: ""
143143
offset: 0
144144
absolute_offset: 0
145-
size: 0
146-
padded_size: 0
145+
size: 256
146+
padded_size: 256
147147
decorations: 0x00000000 # NONE
148148
numeric:
149149
scalar: { width: 0, signedness: 0 }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#version 450
2+
#extension GL_EXT_scalar_block_layout : enable
3+
4+
// 16 byte large storage buffer
5+
// (Note: In HLSL/Slang all storage buffers are runtime array so there is no size)
6+
layout(set = 0, binding = 0, scalar) buffer D0 {
7+
int a;
8+
int b[3];
9+
} ssbo;
10+
11+
// runtime storage buffer - no known length
12+
layout(set = 2, binding = 0, scalar) buffer D1 {
13+
int x;
14+
int y[];
15+
} ssbo_runtime;
16+
17+
// 16 byte large uniform buffer
18+
layout(set = 1, binding = 0, scalar) uniform D2 {
19+
int s;
20+
int t[3];
21+
} ubo;
22+
23+
void main() {
24+
ssbo.b[1] = ubo.t[1] + ssbo_runtime.y[ubo.s];
25+
}

0 commit comments

Comments
 (0)