Skip to content

Commit 278a3ba

Browse files
Detect first level of BDA pointers
1 parent 3c17af9 commit 278a3ba

20 files changed

+1504
-22
lines changed

spirv_reflect.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,19 +2829,11 @@ static void MarkSelfAndAllMemberVarsAsUsed(SpvReflectBlockVariable* p_var) {
28292829
p_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED;
28302830

28312831
SpvOp op_type = p_var->type_description->op;
2832-
switch (op_type) {
2833-
default:
2834-
break;
2835-
2836-
case SpvOpTypeArray: {
2837-
} break;
2838-
2839-
case SpvOpTypeStruct: {
2840-
for (uint32_t i = 0; i < p_var->member_count; ++i) {
2841-
SpvReflectBlockVariable* p_member_var = &p_var->members[i];
2842-
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
2843-
}
2844-
} break;
2832+
if (op_type == SpvOpTypeStruct) {
2833+
for (uint32_t i = 0; i < p_var->member_count; ++i) {
2834+
SpvReflectBlockVariable* p_member_var = &p_var->members[i];
2835+
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
2836+
}
28452837
}
28462838
}
28472839

@@ -2958,7 +2950,10 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage(SpvReflectPrvParser* p
29582950
if (result != SPV_REFLECT_RESULT_SUCCESS) {
29592951
return result;
29602952
}
2961-
} else if (!is_pointer_to_pointer) {
2953+
} else if (is_pointer_to_pointer) {
2954+
// Clear UNUSED flag, but only for the pointer
2955+
p_member_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED;
2956+
} else {
29622957
// Clear UNUSED flag for remaining variables
29632958
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
29642959
}

spirv_reflect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ typedef struct SpvReflectInterfaceVariable {
431431
SpvStorageClass storage_class;
432432
const char* semantic;
433433
SpvReflectDecorationFlags decoration_flags;
434-
434+
435435
// The builtin id (SpvBuiltIn) if the variable is a builtin, and -1 otherwise.
436436
int built_in;
437437
SpvReflectNumericTraits numeric;

tests/access_chains/pointer_access_chain_phy_storage_buffer.spv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ all_block_variables:
102102
vector: { component_count: 0 }
103103
matrix: { column_count: 0, row_count: 0, stride: 0 }
104104
array: { dims_count: 0, dims: [], stride: 0 }
105-
flags: 0x00000001 # UNUSED
105+
flags: 0x00000000 # NONE
106106
member_count: 0
107107
members:
108108
type_description: *td0
@@ -134,7 +134,7 @@ all_block_variables:
134134
vector: { component_count: 0 }
135135
matrix: { column_count: 0, row_count: 0, stride: 0 }
136136
array: { dims_count: 0, dims: [], stride: 0 }
137-
flags: 0x00000001 # UNUSED
137+
flags: 0x00000000 # NONE
138138
member_count: 1
139139
members:
140140
- *bv1

tests/glsl/buffer_handle_1.spv.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ all_block_variables:
512512
vector: { component_count: 0 }
513513
matrix: { column_count: 0, row_count: 0, stride: 0 }
514514
array: { dims_count: 0, dims: [], stride: 0 }
515-
flags: 0x00000001 # UNUSED
515+
flags: 0x00000000 # NONE
516516
member_count: 2
517517
members:
518518
- *bv0
@@ -613,7 +613,7 @@ all_block_variables:
613613
vector: { component_count: 0 }
614614
matrix: { column_count: 0, row_count: 0, stride: 0 }
615615
array: { dims_count: 0, dims: [], stride: 0 }
616-
flags: 0x00000001 # UNUSED
616+
flags: 0x00000000 # NONE
617617
member_count: 2
618618
members:
619619
- *bv6

tests/push_constants/pointer_in_struct.spv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ all_block_variables:
169169
vector: { component_count: 0 }
170170
matrix: { column_count: 0, row_count: 0, stride: 0 }
171171
array: { dims_count: 0, dims: [], stride: 0 }
172-
flags: 0x00000001 # UNUSED
172+
flags: 0x00000000 # NONE
173173
member_count: 0
174174
members:
175175
type_description: *td3

tests/push_constants/pointer_in_struct_2.spv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ all_block_variables:
271271
vector: { component_count: 0 }
272272
matrix: { column_count: 0, row_count: 0, stride: 0 }
273273
array: { dims_count: 0, dims: [], stride: 0 }
274-
flags: 0x00000001 # UNUSED
274+
flags: 0x00000000 # NONE
275275
member_count: 2
276276
members:
277277
- *bv3

tests/push_constants/push_constant_basic_2.spv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ all_block_variables:
324324
vector: { component_count: 0 }
325325
matrix: { column_count: 0, row_count: 0, stride: 0 }
326326
array: { dims_count: 0, dims: [], stride: 0 }
327-
flags: 0x00000001 # UNUSED
327+
flags: 0x00000000 # NONE
328328
member_count: 0
329329
members:
330330
type_description: *td8

tests/test-spirv-reflect.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ const std::vector<const char*> all_spirv_paths = {
906906
"../tests/variable_access/copy_struct_1.spv",
907907
"../tests/variable_access/descriptor_indexing_0.spv",
908908
"../tests/variable_access/descriptor_indexing_1.spv",
909+
"../tests/variable_access/phy_storage_buffer_used_0.spv",
910+
"../tests/variable_access/phy_storage_buffer_used_1.spv",
911+
"../tests/variable_access/phy_storage_buffer_used_2.spv",
912+
"../tests/variable_access/phy_storage_buffer_used_3.spv",
909913
// clang-format on
910914
};
911915
} // namespace
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#version 450
2+
#extension GL_EXT_buffer_reference : enable
3+
4+
layout(buffer_reference, std430) buffer Node {
5+
uint payload;
6+
};
7+
8+
layout(buffer_reference, std430) buffer BadNode {
9+
uint bad_payload;
10+
};
11+
12+
layout(set = 0, binding = 0, std430) buffer SSBO {
13+
Node first_node;
14+
BadNode bad_node; // used
15+
uint placeholder;
16+
} x;
17+
18+
void main() {
19+
x.placeholder = 0;
20+
x.first_node.payload = 3;
21+
}
1.01 KB
Binary file not shown.

0 commit comments

Comments
 (0)