Skip to content

Commit

Permalink
Detect first level of BDA pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jan 15, 2025
1 parent e8f0079 commit fdd1e2f
Show file tree
Hide file tree
Showing 20 changed files with 1,504 additions and 22 deletions.
23 changes: 9 additions & 14 deletions spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2829,19 +2829,11 @@ static void MarkSelfAndAllMemberVarsAsUsed(SpvReflectBlockVariable* p_var) {
p_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED;

SpvOp op_type = p_var->type_description->op;
switch (op_type) {
default:
break;

case SpvOpTypeArray: {
} break;

case SpvOpTypeStruct: {
for (uint32_t i = 0; i < p_var->member_count; ++i) {
SpvReflectBlockVariable* p_member_var = &p_var->members[i];
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
}
} break;
if (op_type == SpvOpTypeStruct) {
for (uint32_t i = 0; i < p_var->member_count; ++i) {
SpvReflectBlockVariable* p_member_var = &p_var->members[i];
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
}
}
}

Expand Down Expand Up @@ -2958,7 +2950,10 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage(SpvReflectPrvParser* p
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return result;
}
} else if (!is_pointer_to_pointer) {
} else if (is_pointer_to_pointer) {
// Clear UNUSED flag, but only for the pointer
p_member_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED;
} else {
// Clear UNUSED flag for remaining variables
MarkSelfAndAllMemberVarsAsUsed(p_member_var);
}
Expand Down
2 changes: 1 addition & 1 deletion spirv_reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ typedef struct SpvReflectInterfaceVariable {
SpvStorageClass storage_class;
const char* semantic;
SpvReflectDecorationFlags decoration_flags;

// The builtin id (SpvBuiltIn) if the variable is a builtin, and -1 otherwise.
int built_in;
SpvReflectNumericTraits numeric;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 0
members:
type_description: *td0
Expand Down Expand Up @@ -134,7 +134,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 1
members:
- *bv1
Expand Down
4 changes: 2 additions & 2 deletions tests/glsl/buffer_handle_1.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 2
members:
- *bv0
Expand Down Expand Up @@ -613,7 +613,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 2
members:
- *bv6
Expand Down
2 changes: 1 addition & 1 deletion tests/push_constants/pointer_in_struct.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 0
members:
type_description: *td3
Expand Down
2 changes: 1 addition & 1 deletion tests/push_constants/pointer_in_struct_2.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 2
members:
- *bv3
Expand Down
2 changes: 1 addition & 1 deletion tests/push_constants/push_constant_basic_2.spv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ all_block_variables:
vector: { component_count: 0 }
matrix: { column_count: 0, row_count: 0, stride: 0 }
array: { dims_count: 0, dims: [], stride: 0 }
flags: 0x00000001 # UNUSED
flags: 0x00000000 # NONE
member_count: 0
members:
type_description: *td8
Expand Down
4 changes: 4 additions & 0 deletions tests/test-spirv-reflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ const std::vector<const char*> all_spirv_paths = {
"../tests/variable_access/copy_struct_1.spv",
"../tests/variable_access/descriptor_indexing_0.spv",
"../tests/variable_access/descriptor_indexing_1.spv",
"../tests/variable_access/phy_storage_buffer_used_0.spv",
"../tests/variable_access/phy_storage_buffer_used_1.spv",
"../tests/variable_access/phy_storage_buffer_used_2.spv",
"../tests/variable_access/phy_storage_buffer_used_3.spv",
// clang-format on
};
} // namespace
Expand Down
21 changes: 21 additions & 0 deletions tests/variable_access/phy_storage_buffer_used_0.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 450
#extension GL_EXT_buffer_reference : enable

layout(buffer_reference, std430) buffer Node {
uint payload;
};

layout(buffer_reference, std430) buffer BadNode {
uint bad_payload;
};

layout(set = 0, binding = 0, std430) buffer SSBO {
Node first_node;
BadNode bad_node; // used
uint placeholder;
} x;

void main() {
x.placeholder = 0;
x.first_node.payload = 3;
}
Binary file not shown.
Loading

0 comments on commit fdd1e2f

Please sign in to comment.