Skip to content

Commit

Permalink
fix infinite recusion in ParseDescriptorBlockVariableUsage()
Browse files Browse the repository at this point in the history
and enable the test cbuffer_unused_001.hlsl, it no longer crashes.
  • Loading branch information
xxxbxxx committed Aug 8, 2019
1 parent 7fa215c commit 1cb7447
Show file tree
Hide file tree
Showing 5 changed files with 3,421 additions and 24 deletions.
47 changes: 23 additions & 24 deletions spirv_reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2217,31 +2217,30 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage(
case SpvOpTypeArray: {
// Parse through array's type hierarchy to find the actual/non-array element type
SpvReflectTypeDescription* p_type = p_var->type_description;
while ((p_type->op == SpvOpTypeArray) && (index_index < p_access_chain->index_count)) {
// Find the array element type id
Node* p_node = FindNode(p_parser, p_type->id);
if (p_node == NULL) {
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
}
uint32_t element_type_id = p_node->array_traits.element_type_id;
// Get the array element type
p_type = FindType(p_module, element_type_id);
if (p_type == NULL) {
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
}
// Next access index
index_index += 1;
// Find the array element type id
Node* p_node = FindNode(p_parser, p_type->id);
if (p_node == NULL) {
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
}
// Parse current var again with a type override and advanced index index
SpvReflectResult result = ParseDescriptorBlockVariableUsage(
p_parser,
p_module,
p_access_chain,
index_index,
p_type->op,
p_var);
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return result;
uint32_t element_type_id = p_node->array_traits.element_type_id;
// Get the array element type
p_type = FindType(p_module, element_type_id);
if (p_type == NULL) {
return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
}

if (index_index < p_access_chain->index_count) {
// Parse current var again with a type override and advanced index index
SpvReflectResult result = ParseDescriptorBlockVariableUsage(
p_parser,
p_module,
p_access_chain,
index_index+1,
p_type->op,
p_var);
if (result != SPV_REFLECT_RESULT_SUCCESS) {
return result;
}
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions tests/build_all_shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def my_which(cmd):
{'source':"hlsl/counter_buffers.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
{'source':"hlsl/semantics.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
{'source':"hlsl/structuredbuffer.hlsl", 'entry':"main", 'profile':'ps_6_0', 'stage':'frag'},
{'source':"cbuffer_unused/cbuffer_unused_001.hlsl", 'entry':"main", 'profile':'vs_6_0', 'stage':'vert'},
]

if __name__ == "__main__":
Expand Down
Binary file added tests/cbuffer_unused/cbuffer_unused_001.spv
Binary file not shown.
Loading

0 comments on commit 1cb7447

Please sign in to comment.