Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,19 @@ static SpvReflectResult ParseDescriptorBlocks(SpvReflectPrvParser* p_parser, Spv

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

bool is_parent_rta = (p_descriptor->descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER);
// We quick find if there is a runtime array in the top level of the struct (they can't be nested)
// Would be ideal to have this integrated into ParseDescriptorBlockVariableSizes() itself, but might need to re-work size logic
bool is_parent_rta = false;
if (p_descriptor->block.member_count != 0) {
for (uint32_t member_index = 0; member_index < p_descriptor->block.member_count; ++member_index) {
SpvReflectBlockVariable* p_member_var = &p_descriptor->block.members[member_index];
SpvReflectTypeDescription* p_member_type = p_member_var->type_description;
if (p_member_type && p_member_type->op == SpvOpTypeRuntimeArray) {
is_parent_rta = true;
}
}
}

result = ParseDescriptorBlockVariableSizes(p_parser, p_module, true, false, is_parent_rta, &p_descriptor->block);
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return result;
Expand Down
18 changes: 9 additions & 9 deletions tests/glsl/buffer_handle_0.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -1095,7 +1095,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -1114,8 +1114,8 @@ all_block_variables:
name: "s5"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -1132,7 +1132,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -1148,7 +1148,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -1198,7 +1198,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down Expand Up @@ -1234,8 +1234,8 @@ all_block_variables:
name: "x"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 32
padded_size: 32
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
20 changes: 10 additions & 10 deletions tests/glsl/buffer_handle_1.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -471,7 +471,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -505,7 +505,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -522,8 +522,8 @@ all_block_variables:
name: "s5"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -540,7 +540,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -556,7 +556,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -572,7 +572,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -623,8 +623,8 @@ all_block_variables:
name: "x"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
14 changes: 7 additions & 7 deletions tests/glsl/buffer_handle_2.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 32
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -634,7 +634,7 @@ all_block_variables:
offset: 32
absolute_offset: 32
size: 4
padded_size: 4
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -650,7 +650,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 32
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -666,7 +666,7 @@ all_block_variables:
offset: 32
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand All @@ -682,7 +682,7 @@ all_block_variables:
offset: 48
absolute_offset: 48
size: 0
padded_size: 0
padded_size: 32
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -701,8 +701,8 @@ all_block_variables:
name: "x"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 80
padded_size: 80
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
14 changes: 7 additions & 7 deletions tests/glsl/buffer_handle_3.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -291,7 +291,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -308,8 +308,8 @@ all_block_variables:
name: "s5"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand All @@ -326,7 +326,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 4
padded_size: 4
padded_size: 8
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 1 }
Expand Down Expand Up @@ -358,8 +358,8 @@ all_block_variables:
name: "x"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
4 changes: 2 additions & 2 deletions tests/glsl/buffer_handle_8.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ all_block_variables:
name: "x"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 48
padded_size: 48
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
6 changes: 3 additions & 3 deletions tests/glsl/buffer_handle_uvec2_ssbo.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ all_block_variables:
offset: 0
absolute_offset: 0
size: 8
padded_size: 8
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 32, signedness: 0 }
Expand All @@ -57,8 +57,8 @@ all_block_variables:
name: "ssbo"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 16
padded_size: 16
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
4 changes: 2 additions & 2 deletions tests/glsl/readonly_writeonly.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ all_block_variables:
name: "foo"
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 768
padded_size: 768
decorations: 0x00000080 # NON_WRITABLE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
8 changes: 4 additions & 4 deletions tests/glsl/storage_buffer.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ all_block_variables:
name: ""
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 256
padded_size: 256
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down Expand Up @@ -142,8 +142,8 @@ all_block_variables:
name: ""
offset: 0
absolute_offset: 0
size: 0
padded_size: 0
size: 256
padded_size: 256
decorations: 0x00000000 # NONE
numeric:
scalar: { width: 0, signedness: 0 }
Expand Down
25 changes: 25 additions & 0 deletions tests/glsl/storage_buffer_runtime.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#version 450
#extension GL_EXT_scalar_block_layout : enable

// 16 byte large storage buffer
// (Note: In HLSL/Slang all storage buffers are runtime array so there is no size)
layout(set = 0, binding = 0, scalar) buffer D0 {
int a;
int b[3];
} ssbo;

// runtime storage buffer - no known length
layout(set = 2, binding = 0, scalar) buffer D1 {
int x;
int y[];
} ssbo_runtime;

// 16 byte large uniform buffer
layout(set = 1, binding = 0, scalar) uniform D2 {
int s;
int t[3];
} ubo;

void main() {
ssbo.b[1] = ubo.t[1] + ssbo_runtime.y[ubo.s];
}
Binary file added tests/glsl/storage_buffer_runtime.spv
Binary file not shown.
Loading
Loading