Skip to content

Commit 1cb7447

Browse files
committed
fix infinite recusion in ParseDescriptorBlockVariableUsage()
and enable the test cbuffer_unused_001.hlsl, it no longer crashes.
1 parent 7fa215c commit 1cb7447

File tree

5 files changed

+3421
-24
lines changed

5 files changed

+3421
-24
lines changed

spirv_reflect.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,31 +2217,30 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage(
22172217
case SpvOpTypeArray: {
22182218
// Parse through array's type hierarchy to find the actual/non-array element type
22192219
SpvReflectTypeDescription* p_type = p_var->type_description;
2220-
while ((p_type->op == SpvOpTypeArray) && (index_index < p_access_chain->index_count)) {
2221-
// Find the array element type id
2222-
Node* p_node = FindNode(p_parser, p_type->id);
2223-
if (p_node == NULL) {
2224-
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
2225-
}
2226-
uint32_t element_type_id = p_node->array_traits.element_type_id;
2227-
// Get the array element type
2228-
p_type = FindType(p_module, element_type_id);
2229-
if (p_type == NULL) {
2230-
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
2231-
}
2232-
// Next access index
2233-
index_index += 1;
2220+
// Find the array element type id
2221+
Node* p_node = FindNode(p_parser, p_type->id);
2222+
if (p_node == NULL) {
2223+
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
22342224
}
2235-
// Parse current var again with a type override and advanced index index
2236-
SpvReflectResult result = ParseDescriptorBlockVariableUsage(
2237-
p_parser,
2238-
p_module,
2239-
p_access_chain,
2240-
index_index,
2241-
p_type->op,
2242-
p_var);
2243-
if (result != SPV_REFLECT_RESULT_SUCCESS) {
2244-
return result;
2225+
uint32_t element_type_id = p_node->array_traits.element_type_id;
2226+
// Get the array element type
2227+
p_type = FindType(p_module, element_type_id);
2228+
if (p_type == NULL) {
2229+
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
2230+
}
2231+
2232+
if (index_index < p_access_chain->index_count) {
2233+
// Parse current var again with a type override and advanced index index
2234+
SpvReflectResult result = ParseDescriptorBlockVariableUsage(
2235+
p_parser,
2236+
p_module,
2237+
p_access_chain,
2238+
index_index+1,
2239+
p_type->op,
2240+
p_var);
2241+
if (result != SPV_REFLECT_RESULT_SUCCESS) {
2242+
return result;
2243+
}
22452244
}
22462245
}
22472246
break;

tests/build_all_shaders.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def my_which(cmd):
3636
{'source':"hlsl/counter_buffers.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
3737
{'source':"hlsl/semantics.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
3838
{'source':"hlsl/structuredbuffer.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
39+
{'source':"cbuffer_unused/cbuffer_unused_001.hlsl", 'entry':"main", 'profile':'vs_6_0', 'stage':'vert'},
3940
]
4041

4142
if __name__ == "__main__":
25.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)