From dc6582bf8c1520a632dca98b11974048ad89fe16 Mon Sep 17 00:00:00 2001 From: Spencer Fricke <115671160+spencer-lunarg@users.noreply.github.com> Date: Sat, 18 Nov 2023 20:14:41 +0900 Subject: [PATCH] rerun clang-format with 132 line width (#233) --- .clang-format | 1 + common/output_stream.cpp | 403 ++--- common/output_stream.h | 22 +- examples/arg_parser.cpp | 58 +- examples/arg_parser.h | 78 +- examples/common.cpp | 31 +- examples/common.h | 4 +- examples/main_descriptors.cpp | 21 +- examples/main_explorer.cpp | 21 +- examples/main_hlsl_resource_types.cpp | 35 +- examples/main_io_variables.cpp | 27 +- main.cpp | 90 +- spirv_reflect.c | 2060 +++++++++---------------- spirv_reflect.h | 3 + 14 files changed, 1049 insertions(+), 1805 deletions(-) diff --git a/.clang-format b/.clang-format index 1d43c4ed..551b185e 100644 --- a/.clang-format +++ b/.clang-format @@ -3,4 +3,5 @@ Language: Cpp BasedOnStyle: Google DerivePointerAlignment: false SortIncludes: true +ColumnLimit: 132 ... diff --git a/common/output_stream.cpp b/common/output_stream.cpp index b2331eec..6ac08f8f 100644 --- a/common/output_stream.cpp +++ b/common/output_stream.cpp @@ -513,8 +513,7 @@ static std::string ToStringSpvBuiltIn(SpvBuiltIn built_in) { return ss.str(); } -std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, - bool preface) { +std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, bool preface) { std::stringstream ss; if (variable.decoration_flags & SPV_REFLECT_DECORATION_BLOCK) { if (preface) { @@ -636,11 +635,10 @@ std::string ToStringTypeFlags(SpvReflectTypeFlags type_flags) { return "UNDEFINED"; } -#define PRINT_AND_CLEAR_TYPE_FLAG(stream, flags, bit) \ - if (((flags) & (SPV_REFLECT_TYPE_FLAG_##bit)) == \ - (SPV_REFLECT_TYPE_FLAG_##bit)) { \ - stream << #bit << " "; \ - flags ^= SPV_REFLECT_TYPE_FLAG_##bit; \ +#define PRINT_AND_CLEAR_TYPE_FLAG(stream, flags, bit) \ + if (((flags) & (SPV_REFLECT_TYPE_FLAG_##bit)) == (SPV_REFLECT_TYPE_FLAG_##bit)) { \ + stream << #bit << " "; \ + flags ^= SPV_REFLECT_TYPE_FLAG_##bit; \ } std::stringstream sstream; PRINT_AND_CLEAR_TYPE_FLAG(sstream, type_flags, ARRAY); @@ -664,17 +662,15 @@ std::string ToStringTypeFlags(SpvReflectTypeFlags type_flags) { return sstream.str(); } -std::string ToStringDecorationFlags( - SpvReflectDecorationFlags decoration_flags) { +std::string ToStringDecorationFlags(SpvReflectDecorationFlags decoration_flags) { if (decoration_flags == SPV_REFLECT_DECORATION_NONE) { return "NONE"; } -#define PRINT_AND_CLEAR_DECORATION_FLAG(stream, flags, bit) \ - if (((flags) & (SPV_REFLECT_DECORATION_##bit)) == \ - (SPV_REFLECT_DECORATION_##bit)) { \ - stream << #bit << " "; \ - flags ^= SPV_REFLECT_DECORATION_##bit; \ +#define PRINT_AND_CLEAR_DECORATION_FLAG(stream, flags, bit) \ + if (((flags) & (SPV_REFLECT_DECORATION_##bit)) == (SPV_REFLECT_DECORATION_##bit)) { \ + stream << #bit << " "; \ + flags ^= SPV_REFLECT_DECORATION_##bit; \ } std::stringstream sstream; PRINT_AND_CLEAR_DECORATION_FLAG(sstream, decoration_flags, NON_WRITABLE); @@ -884,8 +880,7 @@ static std::string ToStringHlslType(const SpvReflectTypeDescription& type) { return ToStringScalarType(type); } -std::string ToStringType(SpvSourceLanguage src_lang, - const SpvReflectTypeDescription& type) { +std::string ToStringType(SpvSourceLanguage src_lang, const SpvReflectTypeDescription& type) { if (src_lang == SpvSourceLanguageHLSL) { return ToStringHlslType(type); } @@ -893,8 +888,7 @@ std::string ToStringType(SpvSourceLanguage src_lang, return ToStringGlslType(type); } -std::string ToStringComponentType(const SpvReflectTypeDescription& type, - uint32_t member_decoration_flags) { +std::string ToStringComponentType(const SpvReflectTypeDescription& type, uint32_t member_decoration_flags) { uint32_t masked_type = type.type_flags & 0xF; if (masked_type == 0) { return ""; @@ -938,11 +932,8 @@ std::string ToStringComponentType(const SpvReflectTypeDescription& type, return ss.str(); } -void ParseBlockMembersToTextLines(const char* indent, int indent_depth, - bool flatten_cbuffers, - const std::string& parent_name, - uint32_t member_count, - const SpvReflectBlockVariable* p_members, +void ParseBlockMembersToTextLines(const char* indent, int indent_depth, bool flatten_cbuffers, const std::string& parent_name, + uint32_t member_count, const SpvReflectBlockVariable* p_members, std::vector* p_text_lines) { const char* t = indent; for (uint32_t member_index = 0; member_index < member_count; ++member_index) { @@ -958,29 +949,22 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, // TODO 212 - If a buffer ref has an array of itself, all members are null continue; } - bool is_struct = - ((member.type_description->type_flags & - static_cast(SPV_REFLECT_TYPE_FLAG_STRUCT)) != 0); - bool is_ref = - ((member.type_description->type_flags & - static_cast(SPV_REFLECT_TYPE_FLAG_REF)) != 0); + bool is_struct = ((member.type_description->type_flags & static_cast(SPV_REFLECT_TYPE_FLAG_STRUCT)) != 0); + bool is_ref = ((member.type_description->type_flags & static_cast(SPV_REFLECT_TYPE_FLAG_REF)) != 0); if (is_struct) { const std::string name = (member.name == nullptr ? "" : member.name); // Begin struct TextLine tl = {}; tl.indent = expanded_indent; - tl.type_name = (member.type_description->type_name == nullptr - ? "" - : member.type_description->type_name); + tl.type_name = (member.type_description->type_name == nullptr ? "" : member.type_description->type_name); tl.absolute_offset = member.absolute_offset; tl.relative_offset = member.offset; tl.size = member.size; tl.padded_size = member.padded_size; tl.array_stride = member.array.stride; tl.block_variable_flags = member.flags; - tl.text_line_flags = - is_ref ? TEXT_LINE_TYPE_REF_BEGIN : TEXT_LINE_TYPE_STRUCT_BEGIN; + tl.text_line_flags = is_ref ? TEXT_LINE_TYPE_REF_BEGIN : TEXT_LINE_TYPE_STRUCT_BEGIN; if (!flatten_cbuffers) { p_text_lines->push_back(tl); } @@ -989,14 +973,11 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, tl = {}; std::string current_parent_name; if (flatten_cbuffers) { - current_parent_name = - parent_name.empty() ? name : (parent_name + "." + name); + current_parent_name = parent_name.empty() ? name : (parent_name + "." + name); } - std::vector* p_target_text_line = - flatten_cbuffers ? p_text_lines : &tl.lines; - ParseBlockMembersToTextLines(t, indent_depth + 1, flatten_cbuffers, - current_parent_name, member.member_count, - member.members, p_target_text_line); + std::vector* p_target_text_line = flatten_cbuffers ? p_text_lines : &tl.lines; + ParseBlockMembersToTextLines(t, indent_depth + 1, flatten_cbuffers, current_parent_name, member.member_count, member.members, + p_target_text_line); tl.text_line_flags = TEXT_LINE_TYPE_LINES; p_text_lines->push_back(tl); @@ -1004,23 +985,18 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, tl = {}; tl.indent = expanded_indent; tl.name = name; - if ((member.array.dims_count > 0) || - (member.type_description->traits.array.dims[0] > 0)) { - const SpvReflectArrayTraits* p_array_info = - (member.array.dims_count > 0) ? &member.array : nullptr; + if ((member.array.dims_count > 0) || (member.type_description->traits.array.dims[0] > 0)) { + const SpvReflectArrayTraits* p_array_info = (member.array.dims_count > 0) ? &member.array : nullptr; if (p_array_info == nullptr) { // // glslang based compilers stores array information in the type and // not the variable // - p_array_info = (member.type_description->traits.array.dims[0] > 0) - ? &member.type_description->traits.array - : nullptr; + p_array_info = (member.type_description->traits.array.dims[0] > 0) ? &member.type_description->traits.array : nullptr; } if (p_array_info != nullptr) { std::stringstream ss_array; - for (uint32_t array_dim_index = 0; - array_dim_index < p_array_info->dims_count; ++array_dim_index) { + for (uint32_t array_dim_index = 0; array_dim_index < p_array_info->dims_count; ++array_dim_index) { uint32_t dim = p_array_info->dims[array_dim_index]; // // dim = 0 means it's an unbounded array @@ -1040,8 +1016,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, tl.padded_size = member.padded_size; tl.array_stride = member.array.stride; tl.block_variable_flags = member.flags; - tl.text_line_flags = - is_ref ? TEXT_LINE_TYPE_REF_END : TEXT_LINE_TYPE_STRUCT_END; + tl.text_line_flags = is_ref ? TEXT_LINE_TYPE_REF_END : TEXT_LINE_TYPE_STRUCT_END; if (!flatten_cbuffers) { p_text_lines->push_back(tl); } @@ -1055,13 +1030,11 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, TextLine tl = {}; tl.indent = expanded_indent; - tl.type_name = ToStringComponentType(*member.type_description, - member.decoration_flags); + tl.type_name = ToStringComponentType(*member.type_description, member.decoration_flags); tl.name = name; if (member.array.dims_count > 0) { std::stringstream ss_array; - for (uint32_t array_dim_index = 0; - array_dim_index < member.array.dims_count; ++array_dim_index) { + for (uint32_t array_dim_index = 0; array_dim_index < member.array.dims_count; ++array_dim_index) { uint32_t dim = member.array.dims[array_dim_index]; ss_array << "[" << dim << "]"; } @@ -1078,15 +1051,12 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth, } } -void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers, - const SpvReflectBlockVariable& block_var, +void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers, const SpvReflectBlockVariable& block_var, std::vector* p_text_lines) { // Begin block TextLine tl = {}; tl.indent = indent; - tl.type_name = (block_var.type_description->type_name != nullptr) - ? block_var.type_description->type_name - : ""; + tl.type_name = (block_var.type_description->type_name != nullptr) ? block_var.type_description->type_name : ""; tl.size = block_var.size; tl.padded_size = block_var.padded_size; tl.text_line_flags = TEXT_LINE_TYPE_BLOCK_BEGIN; @@ -1094,9 +1064,7 @@ void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers, // Members tl = {}; - ParseBlockMembersToTextLines(indent, 2, flatten_cbuffers, "", - block_var.member_count, block_var.members, - &tl.lines); + ParseBlockMembersToTextLines(indent, 2, flatten_cbuffers, "", block_var.member_count, block_var.members, &tl.lines); tl.text_line_flags = TEXT_LINE_TYPE_LINES; p_text_lines->push_back(tl); @@ -1112,9 +1080,7 @@ void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers, p_text_lines->push_back(tl); } -void FormatTextLines(const std::vector& text_lines, - const char* indent, - std::vector* p_formatted_lines) { +void FormatTextLines(const std::vector& text_lines, const char* indent, std::vector* p_formatted_lines) { size_t modifier_width = 0; size_t type_name_width = 0; size_t name_width = 0; @@ -1135,8 +1101,7 @@ void FormatTextLines(const std::vector& text_lines, auto& tl = text_lines[i]; std::stringstream ss; - if ((tl.text_line_flags == TEXT_LINE_TYPE_BLOCK_BEGIN) || - (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_BEGIN) || + if ((tl.text_line_flags == TEXT_LINE_TYPE_BLOCK_BEGIN) || (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_BEGIN) || (tl.text_line_flags == TEXT_LINE_TYPE_REF_BEGIN)) { ss << indent; ss << tl.indent; @@ -1144,8 +1109,7 @@ void FormatTextLines(const std::vector& text_lines, ss << "struct "; ss << tl.type_name; ss << " {"; - } else if ((tl.text_line_flags == TEXT_LINE_TYPE_BLOCK_END) || - (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_END) || + } else if ((tl.text_line_flags == TEXT_LINE_TYPE_BLOCK_END) || (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_END) || (tl.text_line_flags == TEXT_LINE_TYPE_REF_END)) { ss << indent; ss << tl.indent; @@ -1190,9 +1154,7 @@ void FormatTextLines(const std::vector& text_lines, } } -void StreamWriteTextLines(std::ostream& os, const char* indent, - bool flatten_cbuffers, - const std::vector& text_lines) { +void StreamWriteTextLines(std::ostream& os, const char* indent, bool flatten_cbuffers, const std::vector& text_lines) { std::vector formatted_lines; FormatTextLines(text_lines, indent, &formatted_lines); @@ -1209,15 +1171,11 @@ void StreamWriteTextLines(std::ostream& os, const char* indent, continue; } line_width = std::max(line_width, tl.formatted_line.length()); - absolute_offset_width = std::max( - absolute_offset_width, tl.formatted_absolute_offset.length()); - offset_width = - std::max(offset_width, tl.formatted_relative_offset.length()); + absolute_offset_width = std::max(absolute_offset_width, tl.formatted_absolute_offset.length()); + offset_width = std::max(offset_width, tl.formatted_relative_offset.length()); size_width = std::max(size_width, tl.formatted_size.length()); - padded_size_width = - std::max(padded_size_width, tl.formatted_padded_size.length()); - array_stride_width = std::max(array_stride_width, - tl.formatted_array_stride.length()); + padded_size_width = std::max(padded_size_width, tl.formatted_padded_size.length()); + array_stride_width = std::max(array_stride_width, tl.formatted_array_stride.length()); } size_t n = formatted_lines.size(); @@ -1245,8 +1203,7 @@ void StreamWriteTextLines(std::ostream& os, const char* indent, if (i < (n - 1)) { os << "\n"; } - } else if (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_BEGIN || - tl.text_line_flags == TEXT_LINE_TYPE_REF_BEGIN) { + } else if (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_BEGIN || tl.text_line_flags == TEXT_LINE_TYPE_REF_BEGIN) { if (!flatten_cbuffers) { if (i > 0) { os << "\n"; @@ -1274,8 +1231,7 @@ void StreamWriteTextLines(std::ostream& os, const char* indent, os << std::setw(line_width) << std::left << tl.formatted_line; } - } else if (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_END || - tl.text_line_flags == TEXT_LINE_TYPE_REF_END) { + } else if (tl.text_line_flags == TEXT_LINE_TYPE_STRUCT_END || tl.text_line_flags == TEXT_LINE_TYPE_REF_END) { if (!flatten_cbuffers) { os << std::setw(line_width) << std::left << tl.formatted_line; if (i < (n - 1)) { @@ -1287,20 +1243,15 @@ void StreamWriteTextLines(std::ostream& os, const char* indent, os << " " << "//" << " "; - os << "abs offset = " << std::setw(absolute_offset_width) << std::right - << tl.formatted_absolute_offset << ", "; + os << "abs offset = " << std::setw(absolute_offset_width) << std::right << tl.formatted_absolute_offset << ", "; if (!flatten_cbuffers) { - os << "rel offset = " << std::setw(offset_width) << std::right - << tl.formatted_relative_offset << ", "; + os << "rel offset = " << std::setw(offset_width) << std::right << tl.formatted_relative_offset << ", "; } - os << "size = " << std::setw(size_width) << std::right - << tl.formatted_size << ", "; - os << "padded size = " << std::setw(padded_size_width) << std::right - << tl.formatted_padded_size; + os << "size = " << std::setw(size_width) << std::right << tl.formatted_size << ", "; + os << "padded size = " << std::setw(padded_size_width) << std::right << tl.formatted_padded_size; if (tl.array_stride > 0) { os << ", "; - os << "array stride = " << std::setw(array_stride_width) - << tl.formatted_array_stride; + os << "array stride = " << std::setw(array_stride_width) << tl.formatted_array_stride; } if (!tl.formatted_block_variable_flags.empty()) { os << " "; @@ -1314,15 +1265,13 @@ void StreamWriteTextLines(std::ostream& os, const char* indent, } } -void StreamWritePushConstantsBlock(std::ostream& os, - const SpvReflectBlockVariable& obj, - bool flatten_cbuffers, const char* indent) { +void StreamWritePushConstantsBlock(std::ostream& os, const SpvReflectBlockVariable& obj, bool flatten_cbuffers, + const char* indent) { const char* t = indent; os << t << "spirv id : " << obj.spirv_id << "\n"; os << t << "name : " << ((obj.name != nullptr) ? obj.name : ""); - if ((obj.type_description->type_name != nullptr) && - (strlen(obj.type_description->type_name) > 0)) { + if ((obj.type_description->type_name != nullptr) && (strlen(obj.type_description->type_name) > 0)) { os << " " << "(" << obj.type_description->type_name << ")"; } @@ -1336,9 +1285,7 @@ void StreamWritePushConstantsBlock(std::ostream& os, } } -void StreamWriteDescriptorBinding(std::ostream& os, - const SpvReflectDescriptorBinding& obj, - bool write_set, bool flatten_cbuffers, +void StreamWriteDescriptorBinding(std::ostream& os, const SpvReflectDescriptorBinding& obj, bool write_set, bool flatten_cbuffers, const char* indent) { const char* t = indent; os << t << "spirv id : " << obj.spirv_id << "\n"; @@ -1357,8 +1304,7 @@ void StreamWriteDescriptorBinding(std::ostream& os, // array if (obj.array.dims_count > 0) { os << t << "array : "; - for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; - ++dim_index) { + for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; ++dim_index) { os << "[" << obj.array.dims[dim_index] << "]"; } os << "\n"; @@ -1379,8 +1325,7 @@ void StreamWriteDescriptorBinding(std::ostream& os, os << t << "accessed : " << (obj.accessed ? "true" : "false") << "\n"; os << t << "name : " << ((obj.name != nullptr) ? obj.name : ""); - if ((obj.type_description->type_name != nullptr) && - (strlen(obj.type_description->type_name) > 0)) { + if ((obj.type_description->type_name != nullptr) && (strlen(obj.type_description->type_name) > 0)) { os << " " << "(" << obj.type_description->type_name << ")"; } @@ -1388,8 +1333,7 @@ void StreamWriteDescriptorBinding(std::ostream& os, if (obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER || obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) { std::vector text_lines; - ParseBlockVariableToTextLines(" ", flatten_cbuffers, obj.block, - &text_lines); + ParseBlockVariableToTextLines(" ", flatten_cbuffers, obj.block, &text_lines); if (!text_lines.empty()) { os << "\n"; StreamWriteTextLines(os, t, flatten_cbuffers, text_lines); @@ -1398,9 +1342,7 @@ void StreamWriteDescriptorBinding(std::ostream& os, } } -void StreamWriteInterfaceVariable(std::ostream& os, - const SpvReflectInterfaceVariable& obj, - const char* indent) { +void StreamWriteInterfaceVariable(std::ostream& os, const SpvReflectInterfaceVariable& obj, const char* indent) { const char* t = indent; os << t << "spirv id : " << obj.spirv_id << "\n"; os << t << "location : "; @@ -1410,24 +1352,20 @@ void StreamWriteInterfaceVariable(std::ostream& os, os << obj.location; } os << "\n"; - os << t << "type : " << ToStringComponentType(*obj.type_description, 0) - << "\n"; + os << t << "type : " << ToStringComponentType(*obj.type_description, 0) << "\n"; // array if (obj.array.dims_count > 0) { os << t << "array : "; - for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; - ++dim_index) { + for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; ++dim_index) { os << "[" << obj.array.dims[dim_index] << "]"; } os << "\n"; } - os << t << "semantic : " << (obj.semantic != NULL ? obj.semantic : "") - << "\n"; + os << t << "semantic : " << (obj.semantic != NULL ? obj.semantic : "") << "\n"; os << t << "name : " << (obj.name != NULL ? obj.name : ""); - if ((obj.type_description->type_name != nullptr) && - (strlen(obj.type_description->type_name) > 0)) { + if ((obj.type_description->type_name != nullptr) && (strlen(obj.type_description->type_name) > 0)) { os << " " << "(" << obj.type_description->type_name << ")"; } @@ -1440,39 +1378,27 @@ void StreamWriteInterfaceVariable(std::ostream& os, } } -void StreamWriteEntryPoint(std::ostream& os, const SpvReflectEntryPoint& obj, - const char* indent) { +void StreamWriteEntryPoint(std::ostream& os, const SpvReflectEntryPoint& obj, const char* indent) { os << indent << "entry point : " << obj.name; os << " (stage=" << ToStringShaderStage(obj.shader_stage) << ")"; if (obj.shader_stage == SPV_REFLECT_SHADER_STAGE_COMPUTE_BIT) { os << "\n"; os << "local size : " - << "(" - << (obj.local_size.x == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT - ? "Spec Constant" - : std::to_string(obj.local_size.x)) + << "(" << (obj.local_size.x == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT ? "Spec Constant" : std::to_string(obj.local_size.x)) << ", " - << (obj.local_size.y == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT - ? "Spec Constant" - : std::to_string(obj.local_size.y)) + << (obj.local_size.y == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT ? "Spec Constant" : std::to_string(obj.local_size.y)) << ", " - << (obj.local_size.z == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT - ? "Spec Constant" - : std::to_string(obj.local_size.z)) + << (obj.local_size.z == SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT ? "Spec Constant" : std::to_string(obj.local_size.z)) << ")"; } } -void StreamWriteShaderModule(std::ostream& os, - const SpvReflectShaderModule& obj, - const char* indent) { +void StreamWriteShaderModule(std::ostream& os, const SpvReflectShaderModule& obj, const char* indent) { (void)indent; os << "generator : " << ToStringGenerator(obj.generator) << "\n"; - os << "source lang : " << spvReflectSourceLanguage(obj.source_language) - << "\n"; + os << "source lang : " << spvReflectSourceLanguage(obj.source_language) << "\n"; os << "source lang ver : " << obj.source_language_version << "\n"; - os << "source file : " << (obj.source_file != NULL ? obj.source_file : "") - << "\n"; + os << "source file : " << (obj.source_file != NULL ? obj.source_file : "") << "\n"; // os << "shader stage : " << ToStringShaderStage(obj.shader_stage) << // "\n"; @@ -1491,8 +1417,7 @@ void StreamWriteShaderModule(std::ostream& os, #define USE_ASSERT(x) ((void)(x)) #endif -void WriteReflection(const spv_reflect::ShaderModule& obj, - bool flatten_cbuffers, std::ostream& os) { +void WriteReflection(const spv_reflect::ShaderModule& obj, bool flatten_cbuffers, std::ostream& os) { const char* t = " "; const char* tt = " "; const char* ttt = " "; @@ -1576,14 +1501,12 @@ void WriteReflection(const spv_reflect::ShaderModule& obj, bindings.resize(count); result = obj.EnumerateDescriptorBindings(&count, bindings.data()); USE_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); - std::sort(std::begin(bindings), std::end(bindings), - [](SpvReflectDescriptorBinding* a, - SpvReflectDescriptorBinding* b) -> bool { - if (a->set != b->set) { - return a->set < b->set; - } - return a->binding < b->binding; - }); + std::sort(std::begin(bindings), std::end(bindings), [](SpvReflectDescriptorBinding* a, SpvReflectDescriptorBinding* b) -> bool { + if (a->set != b->set) { + return a->set < b->set; + } + return a->binding < b->binding; + }); if (count > 0) { os << "\n"; os << "\n"; @@ -1605,13 +1528,10 @@ void WriteReflection(const spv_reflect::ShaderModule& obj, ////////////////////////////////// -SpvReflectToYaml::SpvReflectToYaml(const SpvReflectShaderModule& shader_module, - uint32_t verbosity) +SpvReflectToYaml::SpvReflectToYaml(const SpvReflectShaderModule& shader_module, uint32_t verbosity) : sm_(shader_module), verbosity_(verbosity) {} -void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, - const SpvReflectTypeDescription& td, - uint32_t indent_level) { +void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, const SpvReflectTypeDescription& td, uint32_t indent_level) { // YAML anchors can only refer to points earlier in the doc, so child type // descriptions must be processed before the parent. for (uint32_t i = 0; i < td.member_count; ++i) { @@ -1624,10 +1544,8 @@ void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, const std::string t4 = Indent(indent_level + 4); // Determine the index of this type within the shader module's list. - assert(type_description_to_index_.find(&td) == - type_description_to_index_.end()); - uint32_t type_description_index = - static_cast(type_description_to_index_.size()); + assert(type_description_to_index_.find(&td) == type_description_to_index_.end()); + uint32_t type_description_index = static_cast(type_description_to_index_.size()); type_description_to_index_[&td] = type_description_index; os << t0 << "- &td" << type_description_index << std::endl; @@ -1639,17 +1557,14 @@ void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, // const char* type_name; os << t1 << "type_name: " << SafeString(td.type_name) << std::endl; // const char* struct_member_name; - os << t1 << "struct_member_name: " << SafeString(td.struct_member_name) - << std::endl; + os << t1 << "struct_member_name: " << SafeString(td.struct_member_name) << std::endl; // SpvStorageClass storage_class; - os << t1 << "storage_class: " << td.storage_class << " # " - << ToStringSpvStorageClass(td.storage_class) << std::endl; + os << t1 << "storage_class: " << td.storage_class << " # " << ToStringSpvStorageClass(td.storage_class) << std::endl; // SpvReflectTypeFlags type_flags; - os << t1 << "type_flags: " << AsHexString(td.type_flags) << " # " - << ToStringTypeFlags(td.type_flags) << std::endl; + os << t1 << "type_flags: " << AsHexString(td.type_flags) << " # " << ToStringTypeFlags(td.type_flags) << std::endl; // SpvReflectDecorationFlags decoration_flags; - os << t1 << "decoration_flags: " << AsHexString(td.decoration_flags) << " # " - << ToStringDecorationFlags(td.decoration_flags) << std::endl; + os << t1 << "decoration_flags: " << AsHexString(td.decoration_flags) << " # " << ToStringDecorationFlags(td.decoration_flags) + << std::endl; // struct Traits { os << t1 << "traits:" << std::endl; // SpvReflectNumericTraits numeric; @@ -1699,8 +1614,7 @@ void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, os << "image_format: " << td.traits.image.image_format; // } SpvReflectImageTraits; os << " }" - << " # dim=" << ToStringSpvDim(td.traits.image.dim) - << " image_format=" << ToStringSpvImageFormat(td.traits.image.image_format) + << " # dim=" << ToStringSpvDim(td.traits.image.dim) << " image_format=" << ToStringSpvImageFormat(td.traits.image.image_format) << std::endl; // SpvReflectArrayTraits array; @@ -1725,15 +1639,12 @@ void SpvReflectToYaml::WriteTypeDescription(std::ostream& os, // struct SpvReflectTypeDescription* members; os << t1 << "members:" << std::endl; for (uint32_t i_member = 0; i_member < td.member_count; ++i_member) { - os << t2 << "- *td" << type_description_to_index_[&(td.members[i_member])] - << std::endl; + os << t2 << "- *td" << type_description_to_index_[&(td.members[i_member])] << std::endl; } // } SpvReflectTypeDescription; } -void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, - const SpvReflectBlockVariable& bv, - uint32_t indent_level) { +void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, const SpvReflectBlockVariable& bv, uint32_t indent_level) { for (uint32_t i = 0; i < bv.member_count; ++i) { WriteBlockVariable(os, bv.members[i], indent_level); } @@ -1744,8 +1655,7 @@ void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, const std::string t3 = Indent(indent_level + 3); assert(block_variable_to_index_.find(&bv) == block_variable_to_index_.end()); - uint32_t block_variable_index = - static_cast(block_variable_to_index_.size()); + uint32_t block_variable_index = static_cast(block_variable_to_index_.size()); block_variable_to_index_[&bv] = block_variable_index; os << t0 << "- &bv" << block_variable_index << std::endl; @@ -1761,8 +1671,8 @@ void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, // uint32_t padded_size; // Measured in bytes os << t1 << "padded_size: " << bv.padded_size << std::endl; // SpvReflectDecorationFlags decoration_flags; - os << t1 << "decorations: " << AsHexString(bv.decoration_flags) << " # " - << ToStringDecorationFlags(bv.decoration_flags) << std::endl; + os << t1 << "decorations: " << AsHexString(bv.decoration_flags) << " # " << ToStringDecorationFlags(bv.decoration_flags) + << std::endl; // SpvReflectNumericTraits numeric; // typedef struct SpvReflectNumericTraits { os << t1 << "numeric:" << std::endl; @@ -1777,8 +1687,7 @@ void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, // uint32_t component_count; // } vector; os << t2 << "vector: { "; - os << "component_count: " << bv.numeric.vector.component_count << " }" - << std::endl; + os << "component_count: " << bv.numeric.vector.component_count << " }" << std::endl; // struct Matrix { // uint32_t column_count; // uint32_t row_count; @@ -1829,9 +1738,7 @@ void SpvReflectToYaml::WriteBlockVariable(std::ostream& os, // } SpvReflectBlockVariable; } -void SpvReflectToYaml::WriteDescriptorBinding( - std::ostream& os, const SpvReflectDescriptorBinding& db, - uint32_t indent_level) { +void SpvReflectToYaml::WriteDescriptorBinding(std::ostream& os, const SpvReflectDescriptorBinding& db, uint32_t indent_level) { if (db.uav_counter_binding != nullptr) { auto itor = descriptor_binding_to_index_.find(db.uav_counter_binding); if (itor == descriptor_binding_to_index_.end()) { @@ -1855,8 +1762,7 @@ void SpvReflectToYaml::WriteDescriptorBinding( } } - uint32_t descriptor_binding_index = - static_cast(descriptor_binding_to_index_.size()); + uint32_t descriptor_binding_index = static_cast(descriptor_binding_to_index_.size()); descriptor_binding_to_index_[&db] = descriptor_binding_index; os << t0 << "- &db" << descriptor_binding_index << std::endl; @@ -1868,16 +1774,13 @@ void SpvReflectToYaml::WriteDescriptorBinding( // uint32_t binding; os << t1 << "binding: " << db.binding << std::endl; // uint32_t input_attachment_index; - os << t1 << "input_attachment_index: " << db.input_attachment_index - << std::endl; + os << t1 << "input_attachment_index: " << db.input_attachment_index << std::endl; // uint32_t set; os << t1 << "set: " << db.set << std::endl; // SpvReflectDescriptorType descriptor_type; - os << t1 << "descriptor_type: " << db.descriptor_type << " # " - << ToStringDescriptorType(db.descriptor_type) << std::endl; + os << t1 << "descriptor_type: " << db.descriptor_type << " # " << ToStringDescriptorType(db.descriptor_type) << std::endl; // SpvReflectResourceType resource_type; - os << t1 << "resource_type: " << db.resource_type << " # " - << ToStringResourceType(db.resource_type) << std::endl; + os << t1 << "resource_type: " << db.resource_type << " # " << ToStringResourceType(db.resource_type) << std::endl; // SpvReflectImageTraits image; os << t1 << "image: { "; // typedef struct SpvReflectImageTraits { @@ -1895,16 +1798,13 @@ void SpvReflectToYaml::WriteDescriptorBinding( os << "image_format: " << db.image.image_format; // } SpvReflectImageTraits; os << " }" - << " # dim=" << ToStringSpvDim(db.image.dim) - << " image_format=" << ToStringSpvImageFormat(db.image.image_format) - << std::endl; + << " # dim=" << ToStringSpvDim(db.image.dim) << " image_format=" << ToStringSpvImageFormat(db.image.image_format) << std::endl; // SpvReflectBlockVariable block; { auto itor = block_variable_to_index_.find(&db.block); assert(itor != block_variable_to_index_.end()); - os << t1 << "block: *bv" << itor->second << " # " - << SafeString(db.block.name) << std::endl; + os << t1 << "block: *bv" << itor->second << " # " << SafeString(db.block.name) << std::endl; } // SpvReflectBindingArrayTraits array; os << t1 << "array: { "; @@ -1930,8 +1830,7 @@ void SpvReflectToYaml::WriteDescriptorBinding( } else { auto itor = descriptor_binding_to_index_.find(db.uav_counter_binding); assert(itor != descriptor_binding_to_index_.end()); - os << t1 << "uav_counter_binding: *db" << itor->second << " # " - << SafeString(db.uav_counter_binding->name) << std::endl; + os << t1 << "uav_counter_binding: *db" << itor->second << " # " << SafeString(db.uav_counter_binding->name) << std::endl; } if (verbosity_ >= 1) { // SpvReflectTypeDescription* type_description; @@ -1952,12 +1851,9 @@ void SpvReflectToYaml::WriteDescriptorBinding( // } SpvReflectDescriptorBinding; } -void SpvReflectToYaml::WriteInterfaceVariable( - std::ostream& os, const SpvReflectInterfaceVariable& iv, - uint32_t indent_level) { +void SpvReflectToYaml::WriteInterfaceVariable(std::ostream& os, const SpvReflectInterfaceVariable& iv, uint32_t indent_level) { for (uint32_t i = 0; i < iv.member_count; ++i) { - assert(interface_variable_to_index_.find(&iv.members[i]) == - interface_variable_to_index_.end()); + assert(interface_variable_to_index_.find(&iv.members[i]) == interface_variable_to_index_.end()); WriteInterfaceVariable(os, iv.members[i], indent_level); } @@ -1966,8 +1862,7 @@ void SpvReflectToYaml::WriteInterfaceVariable( const std::string t2 = Indent(indent_level + 2); const std::string t3 = Indent(indent_level + 3); - uint32_t interface_variable_index = - static_cast(interface_variable_to_index_.size()); + uint32_t interface_variable_index = static_cast(interface_variable_to_index_.size()); interface_variable_to_index_[&iv] = interface_variable_index; // typedef struct SpvReflectInterfaceVariable { @@ -1979,13 +1874,12 @@ void SpvReflectToYaml::WriteInterfaceVariable( // uint32_t location; os << t1 << "location: " << iv.location << std::endl; // SpvStorageClass storage_class; - os << t1 << "storage_class: " << iv.storage_class << " # " - << ToStringSpvStorageClass(iv.storage_class) << std::endl; + os << t1 << "storage_class: " << iv.storage_class << " # " << ToStringSpvStorageClass(iv.storage_class) << std::endl; // const char* semantic; os << t1 << "semantic: " << SafeString(iv.semantic) << std::endl; // SpvReflectDecorationFlags decoration_flags; - os << t1 << "decoration_flags: " << AsHexString(iv.decoration_flags) << " # " - << ToStringDecorationFlags(iv.decoration_flags) << std::endl; + os << t1 << "decoration_flags: " << AsHexString(iv.decoration_flags) << " # " << ToStringDecorationFlags(iv.decoration_flags) + << std::endl; // SpvBuiltIn built_in; os << t1 << "built_in: "; if (iv.decoration_flags & SPV_REFLECT_DECORATION_BLOCK) { @@ -2013,8 +1907,7 @@ void SpvReflectToYaml::WriteInterfaceVariable( // uint32_t component_count; // } vector; os << t2 << "vector: { "; - os << "component_count: " << iv.numeric.vector.component_count << " }" - << std::endl; + os << "component_count: " << iv.numeric.vector.component_count << " }" << std::endl; // struct Matrix { // uint32_t column_count; // uint32_t row_count; @@ -2050,13 +1943,11 @@ void SpvReflectToYaml::WriteInterfaceVariable( for (uint32_t i = 0; i < iv.member_count; ++i) { auto itor = interface_variable_to_index_.find(&iv.members[i]); assert(itor != interface_variable_to_index_.end()); - os << t2 << "- *iv" << itor->second << " # " - << SafeString(iv.members[i].name) << std::endl; + os << t2 << "- *iv" << itor->second << " # " << SafeString(iv.members[i].name) << std::endl; } // SpvReflectFormat format; - os << t1 << "format: " << iv.format << " # " << ToStringFormat(iv.format) - << std::endl; + os << t1 << "format: " << iv.format << " # " << ToStringFormat(iv.format) << std::endl; if (verbosity_ >= 1) { // SpvReflectTypeDescription* type_description; @@ -2072,18 +1963,14 @@ void SpvReflectToYaml::WriteInterfaceVariable( // struct { // uint32_t location; // } word_offset; - os << t1 << "word_offset: { location: " << iv.word_offset.location << " }" - << std::endl; + os << t1 << "word_offset: { location: " << iv.word_offset.location << " }" << std::endl; // } SpvReflectInterfaceVariable; } -void SpvReflectToYaml::WriteBlockVariableTypes( - std::ostream& os, const SpvReflectBlockVariable& bv, - uint32_t indent_level) { +void SpvReflectToYaml::WriteBlockVariableTypes(std::ostream& os, const SpvReflectBlockVariable& bv, uint32_t indent_level) { const auto* td = bv.type_description; - if (td && - type_description_to_index_.find(td) == type_description_to_index_.end()) { + if (td && type_description_to_index_.find(td) == type_description_to_index_.end()) { WriteTypeDescription(os, *td, indent_level); } @@ -2091,9 +1978,7 @@ void SpvReflectToYaml::WriteBlockVariableTypes( WriteBlockVariableTypes(os, bv.members[i], indent_level); } } -void SpvReflectToYaml::WriteDescriptorBindingTypes( - std::ostream& os, const SpvReflectDescriptorBinding& db, - uint32_t indent_level) { +void SpvReflectToYaml::WriteDescriptorBindingTypes(std::ostream& os, const SpvReflectDescriptorBinding& db, uint32_t indent_level) { WriteBlockVariableTypes(os, db.block, indent_level); if (db.uav_counter_binding) { @@ -2101,17 +1986,13 @@ void SpvReflectToYaml::WriteDescriptorBindingTypes( } const auto* td = db.type_description; - if (td && - type_description_to_index_.find(td) == type_description_to_index_.end()) { + if (td && type_description_to_index_.find(td) == type_description_to_index_.end()) { WriteTypeDescription(os, *td, indent_level); } } -void SpvReflectToYaml::WriteInterfaceVariableTypes( - std::ostream& os, const SpvReflectInterfaceVariable& iv, - uint32_t indent_level) { +void SpvReflectToYaml::WriteInterfaceVariableTypes(std::ostream& os, const SpvReflectInterfaceVariable& iv, uint32_t indent_level) { const auto* td = iv.type_description; - if (td && - type_description_to_index_.find(td) == type_description_to_index_.end()) { + if (td && type_description_to_index_.find(td) == type_description_to_index_.end()) { WriteTypeDescription(os, *td, indent_level); } @@ -2141,28 +2022,23 @@ void SpvReflectToYaml::Write(std::ostream& os) { // are reachable from there, though most of them are purely internal & not // referenced by any of the public-facing structures. for (size_t i = 0; i < sm_._internal->type_description_count; ++i) { - WriteTypeDescription(os, sm_._internal->type_descriptions[i], - indent_level + 1); + WriteTypeDescription(os, sm_._internal->type_descriptions[i], indent_level + 1); } } else if (verbosity_ >= 1) { os << t0 << "all_type_descriptions:" << std::endl; // Iterate through all public-facing structures and write any type // descriptions we find (and their children). for (uint32_t i = 0; i < sm_.descriptor_binding_count; ++i) { - WriteDescriptorBindingTypes(os, sm_.descriptor_bindings[i], - indent_level + 1); + WriteDescriptorBindingTypes(os, sm_.descriptor_bindings[i], indent_level + 1); } for (uint32_t i = 0; i < sm_.push_constant_block_count; ++i) { - WriteBlockVariableTypes(os, sm_.push_constant_blocks[i], - indent_level + 1); + WriteBlockVariableTypes(os, sm_.push_constant_blocks[i], indent_level + 1); } for (uint32_t i = 0; i < sm_.input_variable_count; ++i) { - WriteInterfaceVariableTypes(os, *sm_.input_variables[i], - indent_level + 1); + WriteInterfaceVariableTypes(os, *sm_.input_variables[i], indent_level + 1); } for (uint32_t i = 0; i < sm_.output_variable_count; ++i) { - WriteInterfaceVariableTypes(os, *sm_.output_variables[i], - indent_level + 1); + WriteInterfaceVariableTypes(os, *sm_.output_variables[i], indent_level + 1); } } @@ -2193,35 +2069,28 @@ void SpvReflectToYaml::Write(std::ostream& os) { // struct SpvReflectShaderModule { os << t0 << "module:" << std::endl; // uint16_t generator; - os << t1 << "generator: " << sm_.generator << " # " - << ToStringGenerator(sm_.generator) << std::endl; + os << t1 << "generator: " << sm_.generator << " # " << ToStringGenerator(sm_.generator) << std::endl; // const char* entry_point_name; - os << t1 << "entry_point_name: " << SafeString(sm_.entry_point_name) - << std::endl; + os << t1 << "entry_point_name: " << SafeString(sm_.entry_point_name) << std::endl; // uint32_t entry_point_id; os << t1 << "entry_point_id: " << sm_.entry_point_id << std::endl; // SpvSourceLanguage source_language; - os << t1 << "source_language: " << sm_.source_language << " # " - << ToStringSpvSourceLanguage(sm_.source_language) << std::endl; + os << t1 << "source_language: " << sm_.source_language << " # " << ToStringSpvSourceLanguage(sm_.source_language) << std::endl; // uint32_t source_language_version; - os << t1 << "source_language_version: " << sm_.source_language_version - << std::endl; + os << t1 << "source_language_version: " << sm_.source_language_version << std::endl; // SpvExecutionModel spirv_execution_model; os << t1 << "spirv_execution_model: " << sm_.spirv_execution_model << " # " << ToStringSpvExecutionModel(sm_.spirv_execution_model) << std::endl; // SpvShaderStageFlagBits shader_stage; - os << t1 << "shader_stage: " << AsHexString(sm_.shader_stage) << " # " - << ToStringShaderStage(sm_.shader_stage) << std::endl; + os << t1 << "shader_stage: " << AsHexString(sm_.shader_stage) << " # " << ToStringShaderStage(sm_.shader_stage) << std::endl; // uint32_t descriptor_binding_count; - os << t1 << "descriptor_binding_count: " << sm_.descriptor_binding_count - << std::endl; + os << t1 << "descriptor_binding_count: " << sm_.descriptor_binding_count << std::endl; // SpvReflectDescriptorBinding* descriptor_bindings; os << t1 << "descriptor_bindings:" << std::endl; for (uint32_t i = 0; i < sm_.descriptor_binding_count; ++i) { auto itor = descriptor_binding_to_index_.find(&sm_.descriptor_bindings[i]); assert(itor != descriptor_binding_to_index_.end()); - os << t2 << "- *db" << itor->second << " # " - << SafeString(sm_.descriptor_bindings[i].name) << std::endl; + os << t2 << "- *db" << itor->second << " # " << SafeString(sm_.descriptor_bindings[i].name) << std::endl; } // uint32_t descriptor_set_count; os << t1 << "descriptor_set_count: " << sm_.descriptor_set_count << std::endl; @@ -2240,8 +2109,7 @@ void SpvReflectToYaml::Write(std::ostream& os) { for (uint32_t i_binding = 0; i_binding < dset.binding_count; ++i_binding) { auto itor = descriptor_binding_to_index_.find(dset.bindings[i_binding]); assert(itor != descriptor_binding_to_index_.end()); - os << t3 << "- *db" << itor->second << " # " - << SafeString(dset.bindings[i_binding]->name) << std::endl; + os << t3 << "- *db" << itor->second << " # " << SafeString(dset.bindings[i_binding]->name) << std::endl; } // } SpvReflectDescriptorSet; } @@ -2252,8 +2120,7 @@ void SpvReflectToYaml::Write(std::ostream& os) { for (uint32_t i = 0; i < sm_.input_variable_count; ++i) { auto itor = interface_variable_to_index_.find(sm_.input_variables[i]); assert(itor != interface_variable_to_index_.end()); - os << t2 << "- *iv" << itor->second << " # " - << SafeString(sm_.input_variables[i]->name) << std::endl; + os << t2 << "- *iv" << itor->second << " # " << SafeString(sm_.input_variables[i]->name) << std::endl; } // uint32_t output_variable_count; os << t1 << "output_variable_count: " << sm_.output_variable_count << ",\n"; @@ -2262,8 +2129,7 @@ void SpvReflectToYaml::Write(std::ostream& os) { for (uint32_t i = 0; i < sm_.output_variable_count; ++i) { auto itor = interface_variable_to_index_.find(sm_.output_variables[i]); assert(itor != interface_variable_to_index_.end()); - os << t2 << "- *iv" << itor->second << " # " - << SafeString(sm_.output_variables[i]->name) << std::endl; + os << t2 << "- *iv" << itor->second << " # " << SafeString(sm_.output_variables[i]->name) << std::endl; } // uint32_t push_constant_count; os << t1 << "push_constant_count: " << sm_.push_constant_block_count << ",\n"; @@ -2272,8 +2138,7 @@ void SpvReflectToYaml::Write(std::ostream& os) { for (uint32_t i = 0; i < sm_.push_constant_block_count; ++i) { auto itor = block_variable_to_index_.find(&sm_.push_constant_blocks[i]); assert(itor != block_variable_to_index_.end()); - os << t2 << "- *bv" << itor->second << " # " - << SafeString(sm_.push_constant_blocks[i].name) << std::endl; + os << t2 << "- *bv" << itor->second << " # " << SafeString(sm_.push_constant_blocks[i].name) << std::endl; } if (verbosity_ >= 2) { @@ -2292,17 +2157,13 @@ void SpvReflectToYaml::Write(std::ostream& os) { } os << "]" << std::endl; // uint32_t spirv_word_count; - os << t2 << "spirv_word_count: " << sm_._internal->spirv_word_count - << std::endl; + os << t2 << "spirv_word_count: " << sm_._internal->spirv_word_count << std::endl; // size_t type_description_count; - os << t2 - << "type_description_count: " << sm_._internal->type_description_count - << std::endl; + os << t2 << "type_description_count: " << sm_._internal->type_description_count << std::endl; // SpvReflectTypeDescription* type_descriptions; os << t2 << "type_descriptions:" << std::endl; for (uint32_t i = 0; i < sm_._internal->type_description_count; ++i) { - auto itor = type_description_to_index_.find( - &sm_._internal->type_descriptions[i]); + auto itor = type_description_to_index_.find(&sm_._internal->type_descriptions[i]); assert(itor != type_description_to_index_.end()); os << t3 << "- *td" << itor->second << std::endl; } diff --git a/common/output_stream.h b/common/output_stream.h index d574ef94..d29014a7 100644 --- a/common/output_stream.h +++ b/common/output_stream.h @@ -1,17 +1,17 @@ #ifndef SPIRV_REFLECT_OUTPUT_STREAM_H #define SPIRV_REFLECT_OUTPUT_STREAM_H -#include "spirv_reflect.h" #include #include #include +#include "spirv_reflect.h" + std::string ToStringSpvSourceLanguage(SpvSourceLanguage lang); std::string ToStringSpvExecutionModel(SpvExecutionModel model); std::string ToStringSpvStorageClass(SpvStorageClass storage_class); std::string ToStringSpvDim(SpvDim dim); -std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, - bool preface); +std::string ToStringSpvBuiltIn(const SpvReflectInterfaceVariable& variable, bool preface); std::string ToStringSpvImageFormat(SpvImageFormat fmt); std::string ToStringGenerator(SpvReflectGenerator generator); @@ -25,29 +25,27 @@ std::string ToStringFormat(SpvReflectFormat fmt); std::string ToStringComponentType(const SpvReflectTypeDescription& type, uint32_t member_decoration_flags); std::string ToStringType(SpvSourceLanguage src_lang, const SpvReflectTypeDescription& type); -//std::ostream& operator<<(std::ostream& os, const spv_reflect::ShaderModule& obj); +// std::ostream& operator<<(std::ostream& os, const spv_reflect::ShaderModule& obj); void WriteReflection(const spv_reflect::ShaderModule& obj, bool flatten_cbuffers, std::ostream& os); class SpvReflectToYaml { -public: + public: // verbosity = 0: top-level tables only (module, block variables, interface variables, descriptor bindings). // verbosity = 1: everything above, plus type description tables for all public objects. // verbosity = 2: everything above, plus SPIRV bytecode and full type description table. HUGE. explicit SpvReflectToYaml(const SpvReflectShaderModule& shader_module, uint32_t verbosity = 0); - friend std::ostream& operator<<(std::ostream& os, SpvReflectToYaml& to_yaml) - { + friend std::ostream& operator<<(std::ostream& os, SpvReflectToYaml& to_yaml) { to_yaml.Write(os); return os; } -private: + + private: void Write(std::ostream& os); SpvReflectToYaml(const SpvReflectToYaml&) = delete; SpvReflectToYaml(const SpvReflectToYaml&&) = delete; - static std::string Indent(uint32_t level) { - return std::string(2*level, ' '); - } + static std::string Indent(uint32_t level) { return std::string(2 * level, ' '); } static std::string SafeString(const char* str) { return str ? (std::string("\"") + str + "\"") : ""; } void WriteTypeDescription(std::ostream& os, const SpvReflectTypeDescription& td, uint32_t indent_level); void WriteBlockVariable(std::ostream& os, const SpvReflectBlockVariable& bv, uint32_t indent_level); @@ -60,7 +58,6 @@ class SpvReflectToYaml { void WriteDescriptorBindingTypes(std::ostream& os, const SpvReflectDescriptorBinding& db, uint32_t indent_level); void WriteInterfaceVariableTypes(std::ostream& os, const SpvReflectInterfaceVariable& iv, uint32_t indent_level); - const SpvReflectShaderModule& sm_; uint32_t verbosity_ = 0; std::map type_description_to_index_; @@ -69,5 +66,4 @@ class SpvReflectToYaml { std::map interface_variable_to_index_; }; - #endif \ No newline at end of file diff --git a/examples/arg_parser.cpp b/examples/arg_parser.cpp index 93b0f6bc..86f509a5 100644 --- a/examples/arg_parser.cpp +++ b/examples/arg_parser.cpp @@ -8,60 +8,47 @@ ArgParser::ArgParser() {} ArgParser::~ArgParser() {} -ArgParser::Option* ArgParser::FindOptionByShortName( - const std::string& short_name) { +ArgParser::Option* ArgParser::FindOptionByShortName(const std::string& short_name) { ArgParser::Option* p_option = nullptr; auto it = std::find_if(std::begin(m_options), std::end(m_options), - [short_name](const ArgParser::Option& elem) -> bool { - return elem.short_name == short_name; - }); + [short_name](const ArgParser::Option& elem) -> bool { return elem.short_name == short_name; }); if (it != std::end(m_options)) { p_option = &(*it); } return p_option; } -const ArgParser::Option* ArgParser::FindOptionByShortName( - const std::string& short_name) const { +const ArgParser::Option* ArgParser::FindOptionByShortName(const std::string& short_name) const { const ArgParser::Option* p_option = nullptr; auto it = std::find_if(std::begin(m_options), std::end(m_options), - [short_name](const ArgParser::Option& elem) -> bool { - return elem.short_name == short_name; - }); + [short_name](const ArgParser::Option& elem) -> bool { return elem.short_name == short_name; }); if (it != std::end(m_options)) { p_option = &(*it); } return p_option; } -ArgParser::Option* ArgParser::FindOptionByLongName( - const std::string& long_name) { +ArgParser::Option* ArgParser::FindOptionByLongName(const std::string& long_name) { ArgParser::Option* p_option = nullptr; auto it = std::find_if(std::begin(m_options), std::end(m_options), - [long_name](const ArgParser::Option& elem) -> bool { - return elem.long_name == long_name; - }); + [long_name](const ArgParser::Option& elem) -> bool { return elem.long_name == long_name; }); if (it != std::end(m_options)) { p_option = &(*it); } return p_option; } -const ArgParser::Option* ArgParser::FindOptionByLongName( - const std::string& long_name) const { +const ArgParser::Option* ArgParser::FindOptionByLongName(const std::string& long_name) const { const ArgParser::Option* p_option = nullptr; auto it = std::find_if(std::begin(m_options), std::end(m_options), - [long_name](const ArgParser::Option& elem) -> bool { - return elem.long_name == long_name; - }); + [long_name](const ArgParser::Option& elem) -> bool { return elem.long_name == long_name; }); if (it != std::end(m_options)) { p_option = &(*it); } return p_option; } -bool ArgParser::AddFlag(const std::string& short_name, - const std::string& long_name, const std::string& desc) { +bool ArgParser::AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc) { Option option = {}; option.short_name = short_name; option.long_name = long_name; @@ -76,9 +63,7 @@ bool ArgParser::AddFlag(const std::string& short_name, return true; } -bool ArgParser::AddOptionString(const std::string& short_name, - const std::string& long_name, - const std::string& desc, +bool ArgParser::AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc, const std::string& default_value) { Option option = {}; option.short_name = short_name; @@ -95,9 +80,8 @@ bool ArgParser::AddOptionString(const std::string& short_name, return true; } -bool ArgParser::AddOptionInt(const std::string& short_name, - const std::string& long_name, - const std::string& desc, int default_value) { +bool ArgParser::AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc, + int default_value) { Option option = {}; option.short_name = short_name; option.long_name = long_name; @@ -113,9 +97,8 @@ bool ArgParser::AddOptionInt(const std::string& short_name, return true; } -bool ArgParser::AddOptionFloat(const std::string& short_name, - const std::string& long_name, - const std::string& desc, float default_value) { +bool ArgParser::AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc, + float default_value) { Option option = {}; option.short_name = short_name; option.long_name = long_name; @@ -228,8 +211,7 @@ bool ArgParser::GetArg(size_t i, std::string* p_value) const { const std::vector& ArgParser::GetArgs() const { return m_args; } -bool ArgParser::GetFlag(const std::string& short_name, - const std::string& long_name) const { +bool ArgParser::GetFlag(const std::string& short_name, const std::string& long_name) const { auto p_short = FindOptionByShortName(short_name); auto p_long = FindOptionByLongName(long_name); @@ -252,9 +234,7 @@ bool ArgParser::GetFlag(const std::string& short_name, return p_option->parsed; } -bool ArgParser::GetString(const std::string& short_name, - const std::string& long_name, - std::string* p_value) const { +bool ArgParser::GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const { auto p_short = FindOptionByShortName(short_name); auto p_long = FindOptionByLongName(long_name); @@ -281,8 +261,7 @@ bool ArgParser::GetString(const std::string& short_name, return true; } -bool ArgParser::GetInt(const std::string& short_name, - const std::string& long_name, int* p_value) const { +bool ArgParser::GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const { auto p_short = FindOptionByShortName(short_name); auto p_long = FindOptionByLongName(long_name); @@ -309,8 +288,7 @@ bool ArgParser::GetInt(const std::string& short_name, return true; } -bool ArgParser::GetFloat(const std::string& short_name, - const std::string& long_name, float* p_value) const { +bool ArgParser::GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const { auto p_short = FindOptionByShortName(short_name); auto p_long = FindOptionByLongName(long_name); diff --git a/examples/arg_parser.h b/examples/arg_parser.h index 627ab144..40f7059a 100644 --- a/examples/arg_parser.h +++ b/examples/arg_parser.h @@ -3,67 +3,63 @@ #include #include -#include #include +#include class ArgParser { -public: - enum OptionType { - OPTION_TYPE_UNDEFINED = 0, - OPTION_TYPE_FLAG, - OPTION_TYPE_STRING, - OPTION_TYPE_INT, - OPTION_TYPE_FLOAT - }; + public: + enum OptionType { OPTION_TYPE_UNDEFINED = 0, OPTION_TYPE_FLAG, OPTION_TYPE_STRING, OPTION_TYPE_INT, OPTION_TYPE_FLOAT }; struct OptionValue { - std::string str; + std::string str; union { - int i32; - float f32; + int i32; + float f32; }; }; struct Option { - std::string short_name; - std::string long_name; - OptionType type; - std::string desc; - OptionValue value; - OptionValue default_value; - bool parsed; + std::string short_name; + std::string long_name; + OptionType type; + std::string desc; + OptionValue value; + OptionValue default_value; + bool parsed; }; ArgParser(); ~ArgParser(); - bool AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc); - bool AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc, const std::string& default_value = ""); - bool AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc, int default_value = 0); - bool AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc, float default_value = 0); + bool AddFlag(const std::string& short_name, const std::string& long_name, const std::string& desc); + bool AddOptionString(const std::string& short_name, const std::string& long_name, const std::string& desc, + const std::string& default_value = ""); + bool AddOptionInt(const std::string& short_name, const std::string& long_name, const std::string& desc, int default_value = 0); + bool AddOptionFloat(const std::string& short_name, const std::string& long_name, const std::string& desc, + float default_value = 0); + + bool Parse(int argc, char** argv, std::ostream& os); - bool Parse(int argc, char** argv, std::ostream& os); - - size_t GetArgCount() const; - bool GetArg(size_t i, std::string* p_value) const; + size_t GetArgCount() const; + bool GetArg(size_t i, std::string* p_value) const; const std::vector& GetArgs() const; - bool GetFlag(const std::string& short_name, const std::string& long_name) const; - bool GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const; - bool GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const; - bool GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const; + bool GetFlag(const std::string& short_name, const std::string& long_name) const; + bool GetString(const std::string& short_name, const std::string& long_name, std::string* p_value) const; + bool GetInt(const std::string& short_name, const std::string& long_name, int* p_value) const; + bool GetFloat(const std::string& short_name, const std::string& long_name, float* p_value) const; - void PrintHelp(std::ostream& os); + void PrintHelp(std::ostream& os); -private: - ArgParser::Option* FindOptionByShortName(const std::string& short_name); - const ArgParser::Option* FindOptionByShortName(const std::string& short_name) const; - ArgParser::Option* FindOptionByLongName(const std::string& long_name); - const ArgParser::Option* FindOptionByLongName(const std::string& long_name) const; + private: + ArgParser::Option* FindOptionByShortName(const std::string& short_name); + const ArgParser::Option* FindOptionByShortName(const std::string& short_name) const; + ArgParser::Option* FindOptionByLongName(const std::string& long_name); + const ArgParser::Option* FindOptionByLongName(const std::string& long_name) const; -private: - std::vector m_options; - std::vector m_args; + private: + std::vector m_options; + std::vector m_args; }; -#endif // __VERIFLECT_ARG_PARSER_H__ \ No newline at end of file +#endif // __VERIFLECT_ARG_PARSER_H__ \ No newline at end of file diff --git a/examples/common.cpp b/examples/common.cpp index 2e70509a..9317cdae 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -6,11 +6,9 @@ #include "../common/output_stream.h" -void PrintModuleInfo(std::ostream& os, const SpvReflectShaderModule& obj, - const char* /*indent*/) { +void PrintModuleInfo(std::ostream& os, const SpvReflectShaderModule& obj, const char* /*indent*/) { os << "entry point : " << obj.entry_point_name << "\n"; - os << "source lang : " << spvReflectSourceLanguage(obj.source_language) - << "\n"; + os << "source lang : " << spvReflectSourceLanguage(obj.source_language) << "\n"; os << "source lang ver : " << obj.source_language_version << "\n"; if (obj.source_language == SpvSourceLanguageHLSL) { os << "stage : "; @@ -39,8 +37,7 @@ void PrintModuleInfo(std::ostream& os, const SpvReflectShaderModule& obj, } } -void PrintDescriptorSet(std::ostream& os, const SpvReflectDescriptorSet& obj, - const char* indent) { +void PrintDescriptorSet(std::ostream& os, const SpvReflectDescriptorSet& obj, const char* indent) { const char* t = indent; std::string tt = std::string(indent) + " "; std::string ttttt = std::string(indent) + " "; @@ -59,22 +56,18 @@ void PrintDescriptorSet(std::ostream& os, const SpvReflectDescriptorSet& obj, } } -void PrintDescriptorBinding(std::ostream& os, - const SpvReflectDescriptorBinding& obj, - bool write_set, const char* indent) { +void PrintDescriptorBinding(std::ostream& os, const SpvReflectDescriptorBinding& obj, bool write_set, const char* indent) { const char* t = indent; os << t << "binding : " << obj.binding << "\n"; if (write_set) { os << t << "set : " << obj.set << "\n"; } - os << t << "type : " << ToStringDescriptorType(obj.descriptor_type) - << "\n"; + os << t << "type : " << ToStringDescriptorType(obj.descriptor_type) << "\n"; // array if (obj.array.dims_count > 0) { os << t << "array : "; - for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; - ++dim_index) { + for (uint32_t dim_index = 0; dim_index < obj.array.dims_count; ++dim_index) { os << "[" << obj.array.dims[dim_index] << "]"; } os << "\n"; @@ -92,15 +85,13 @@ void PrintDescriptorBinding(std::ostream& os, } os << t << "name : " << obj.name; - if ((obj.type_description->type_name != nullptr) && - (strlen(obj.type_description->type_name) > 0)) { + if ((obj.type_description->type_name != nullptr) && (strlen(obj.type_description->type_name) > 0)) { os << " " << "(" << obj.type_description->type_name << ")"; } } -void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, - const SpvReflectInterfaceVariable& obj, +void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, const SpvReflectInterfaceVariable& obj, const char* indent) { const char* t = indent; os << t << "location : "; @@ -113,8 +104,7 @@ void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, if (obj.semantic != nullptr) { os << t << "semantic : " << obj.semantic << "\n"; } - os << t << "type : " << ToStringType(src_lang, *obj.type_description) - << "\n"; + os << t << "type : " << ToStringType(src_lang, *obj.type_description) << "\n"; os << t << "format : " << ToStringFormat(obj.format) << "\n"; os << t << "qualifier : "; if (obj.decoration_flags & SPV_REFLECT_DECORATION_FLAT) { @@ -131,8 +121,7 @@ void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, os << "\n"; os << t << "name : " << obj.name; - if ((obj.type_description->type_name != nullptr) && - (strlen(obj.type_description->type_name) > 0)) { + if ((obj.type_description->type_name != nullptr) && (strlen(obj.type_description->type_name) > 0)) { os << " " << "(" << obj.type_description->type_name << ")"; } diff --git a/examples/common.h b/examples/common.h index 83590382..c9e8b4a6 100644 --- a/examples/common.h +++ b/examples/common.h @@ -2,11 +2,13 @@ #define SPIRV_REFLECT_EXAMPLES_COMMON_H #include + #include "spirv_reflect.h" void PrintModuleInfo(std::ostream& os, const SpvReflectShaderModule& obj, const char* indent = ""); void PrintDescriptorSet(std::ostream& os, const SpvReflectDescriptorSet& obj, const char* indent = ""); void PrintDescriptorBinding(std::ostream& os, const SpvReflectDescriptorBinding& obj, bool write_set, const char* indent = ""); -void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, const SpvReflectInterfaceVariable& obj, const char* indent); +void PrintInterfaceVariable(std::ostream& os, SpvSourceLanguage src_lang, const SpvReflectInterfaceVariable& obj, + const char* indent); #endif diff --git a/examples/main_descriptors.cpp b/examples/main_descriptors.cpp index f6bfb2d6..6a4bddc5 100644 --- a/examples/main_descriptors.cpp +++ b/examples/main_descriptors.cpp @@ -14,8 +14,7 @@ struct DescriptorSetLayoutData { int main(int argn, char** argv) { SpvReflectShaderModule module = {}; - SpvReflectResult result = - spvReflectCreateShaderModule(sizeof(k_sample_spv), k_sample_spv, &module); + SpvReflectResult result = spvReflectCreateShaderModule(sizeof(k_sample_spv), k_sample_spv, &module); assert(result == SPV_REFLECT_RESULT_SUCCESS); uint32_t count = 0; @@ -29,30 +28,24 @@ int main(int argn, char** argv) { #if defined(SPIRV_REFLECT_HAS_VULKAN_H) // Demonstrates how to generate all necessary data structures to create a // VkDescriptorSetLayout for each descriptor set in this shader. - std::vector set_layouts(sets.size(), - DescriptorSetLayoutData{}); + std::vector set_layouts(sets.size(), DescriptorSetLayoutData{}); for (size_t i_set = 0; i_set < sets.size(); ++i_set) { const SpvReflectDescriptorSet& refl_set = *(sets[i_set]); DescriptorSetLayoutData& layout = set_layouts[i_set]; layout.bindings.resize(refl_set.binding_count); - for (uint32_t i_binding = 0; i_binding < refl_set.binding_count; - ++i_binding) { - const SpvReflectDescriptorBinding& refl_binding = - *(refl_set.bindings[i_binding]); + for (uint32_t i_binding = 0; i_binding < refl_set.binding_count; ++i_binding) { + const SpvReflectDescriptorBinding& refl_binding = *(refl_set.bindings[i_binding]); VkDescriptorSetLayoutBinding& layout_binding = layout.bindings[i_binding]; layout_binding.binding = refl_binding.binding; - layout_binding.descriptorType = - static_cast(refl_binding.descriptor_type); + layout_binding.descriptorType = static_cast(refl_binding.descriptor_type); layout_binding.descriptorCount = 1; for (uint32_t i_dim = 0; i_dim < refl_binding.array.dims_count; ++i_dim) { layout_binding.descriptorCount *= refl_binding.array.dims[i_dim]; } - layout_binding.stageFlags = - static_cast(module.shader_stage); + layout_binding.stageFlags = static_cast(module.shader_stage); } layout.set_number = refl_set.set; - layout.create_info.sType = - VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layout.create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; layout.create_info.bindingCount = refl_set.binding_count; layout.create_info.pBindings = layout.bindings.data(); } diff --git a/examples/main_explorer.cpp b/examples/main_explorer.cpp index ca05ea9b..a5b5755a 100644 --- a/examples/main_explorer.cpp +++ b/examples/main_explorer.cpp @@ -44,8 +44,7 @@ int main(int argn, char** argv) { std::ifstream spv_ifstream(input_spv_path.c_str(), std::ios::binary); if (!spv_ifstream.is_open()) { - std::cerr << "ERROR: could not open '" << input_spv_path - << "' for reading\n"; + std::cerr << "ERROR: could not open '" << input_spv_path << "' for reading\n"; return EXIT_FAILURE; } @@ -57,8 +56,7 @@ int main(int argn, char** argv) { spv_ifstream.read(spv_data.data(), size); SpvReflectShaderModule module = {}; - SpvReflectResult result = - spvReflectCreateShaderModule(spv_data.size(), spv_data.data(), &module); + SpvReflectResult result = spvReflectCreateShaderModule(spv_data.size(), spv_data.data(), &module); assert(result == SPV_REFLECT_RESULT_SUCCESS); // Go through each enumerate to examine it @@ -73,35 +71,30 @@ int main(int argn, char** argv) { result = spvReflectEnumerateDescriptorBindings(&module, &count, NULL); assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector bindings(count); - result = - spvReflectEnumerateDescriptorBindings(&module, &count, bindings.data()); + result = spvReflectEnumerateDescriptorBindings(&module, &count, bindings.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); result = spvReflectEnumerateInterfaceVariables(&module, &count, NULL); assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector interface_variables(count); - result = spvReflectEnumerateInterfaceVariables(&module, &count, - interface_variables.data()); + result = spvReflectEnumerateInterfaceVariables(&module, &count, interface_variables.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); result = spvReflectEnumerateInputVariables(&module, &count, NULL); assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector input_variables(count); - result = spvReflectEnumerateInputVariables(&module, &count, - input_variables.data()); + result = spvReflectEnumerateInputVariables(&module, &count, input_variables.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); result = spvReflectEnumerateOutputVariables(&module, &count, NULL); assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector output_variables(count); - result = spvReflectEnumerateOutputVariables(&module, &count, - output_variables.data()); + result = spvReflectEnumerateOutputVariables(&module, &count, output_variables.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); result = spvReflectEnumeratePushConstantBlocks(&module, &count, NULL); assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector push_constant(count); - result = spvReflectEnumeratePushConstantBlocks(&module, &count, - push_constant.data()); + result = spvReflectEnumeratePushConstantBlocks(&module, &count, push_constant.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); // Can set a breakpoint here and explorer the various variables enumerated. diff --git a/examples/main_hlsl_resource_types.cpp b/examples/main_hlsl_resource_types.cpp index bf294f11..5122c376 100644 --- a/examples/main_hlsl_resource_types.cpp +++ b/examples/main_hlsl_resource_types.cpp @@ -31,8 +31,7 @@ #include "examples/common.h" #include "spirv_reflect.h" -void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj, - bool write_set, const char* indent = "") { +void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj, bool write_set, const char* indent = "") { const char* t = indent; os << " " << obj.name; @@ -43,10 +42,8 @@ void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj, << "(" << ToStringResourceType(obj.resource_type) << ")"; if ((obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE) || - (obj.descriptor_type == - SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) || - (obj.descriptor_type == - SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) { + (obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) || + (obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) { os << "\n"; os << t; os << "dim=" << obj.image.dim << ", "; @@ -57,17 +54,13 @@ void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj, } } -void StreamWrite(std::ostream& os, const SpvReflectShaderModule& obj, - const char* indent = "") { +void StreamWrite(std::ostream& os, const SpvReflectShaderModule& obj, const char* indent = "") { os << "entry point : " << obj.entry_point_name << "\n"; - os << "source lang : " << spvReflectSourceLanguage(obj.source_language) - << "\n"; + os << "source lang : " << spvReflectSourceLanguage(obj.source_language) << "\n"; os << "source lang ver : " << obj.source_language_version; } -void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj) { - StreamWrite(os, obj, true, " "); -} +void StreamWrite(std::ostream& os, const SpvReflectDescriptorBinding& obj) { StreamWrite(os, obj, true, " "); } // Specialized stream-writer that only includes descriptor bindings. void StreamWrite(std::ostream& os, const spv_reflect::ShaderModule& obj) { @@ -109,12 +102,10 @@ void StreamWrite(std::ostream& os, const spv_reflect::ShaderModule& obj) { // PrintUsage() // ================================================================================================= void PrintUsage() { - std::cout - << "Usage: hlsl_resource_types [OPTIONS] path/to/SPIR-V/bytecode.spv" - << std::endl - << "Options:" << std::endl - << " --help: Display this message" << std::endl - << std::endl; + std::cout << "Usage: hlsl_resource_types [OPTIONS] path/to/SPIR-V/bytecode.spv" << std::endl + << "Options:" << std::endl + << " --help: Display this message" << std::endl + << std::endl; } // ================================================================================================= @@ -132,8 +123,7 @@ int main(int argn, char** argv) { std::ifstream spv_ifstream(input_spv_path.c_str(), std::ios::binary); if (!spv_ifstream.is_open()) { - std::cerr << "ERROR: could not open '" << input_spv_path << "' for reading" - << std::endl; + std::cerr << "ERROR: could not open '" << input_spv_path << "' for reading" << std::endl; return EXIT_FAILURE; } @@ -147,8 +137,7 @@ int main(int argn, char** argv) { spv_reflect::ShaderModule reflection(spv_data.size(), spv_data.data()); if (reflection.GetResult() != SPV_REFLECT_RESULT_SUCCESS) { - std::cerr << "ERROR: could not process '" << input_spv_path - << "' (is it a valid SPIR-V bytecode?)" << std::endl; + std::cerr << "ERROR: could not process '" << input_spv_path << "' (is it a valid SPIR-V bytecode?)" << std::endl; return EXIT_FAILURE; } diff --git a/examples/main_io_variables.cpp b/examples/main_io_variables.cpp index 20205c1d..b5b8f988 100644 --- a/examples/main_io_variables.cpp +++ b/examples/main_io_variables.cpp @@ -394,8 +394,7 @@ static uint32_t FormatSize(VkFormat format) { int main(int argn, char** argv) { SpvReflectShaderModule module = {}; - SpvReflectResult result = - spvReflectCreateShaderModule(sizeof(k_sample_spv), k_sample_spv, &module); + SpvReflectResult result = spvReflectCreateShaderModule(sizeof(k_sample_spv), k_sample_spv, &module); assert(result == SPV_REFLECT_RESULT_SUCCESS); uint32_t count = 0; @@ -403,8 +402,7 @@ int main(int argn, char** argv) { assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector input_vars(count); - result = - spvReflectEnumerateInputVariables(&module, &count, input_vars.data()); + result = spvReflectEnumerateInputVariables(&module, &count, input_vars.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); count = 0; @@ -412,8 +410,7 @@ int main(int argn, char** argv) { assert(result == SPV_REFLECT_RESULT_SUCCESS); std::vector output_vars(count); - result = - spvReflectEnumerateOutputVariables(&module, &count, output_vars.data()); + result = spvReflectEnumerateOutputVariables(&module, &count, output_vars.data()); assert(result == SPV_REFLECT_RESULT_SUCCESS); #if defined(SPIRV_REFLECT_HAS_VULKAN_H) @@ -452,10 +449,8 @@ int main(int argn, char** argv) { attribute_descriptions.push_back(attr_desc); } // Sort attributes by location - std::sort(std::begin(attribute_descriptions), - std::end(attribute_descriptions), - [](const VkVertexInputAttributeDescription& a, - const VkVertexInputAttributeDescription& b) { + std::sort(std::begin(attribute_descriptions), std::end(attribute_descriptions), + [](const VkVertexInputAttributeDescription& a, const VkVertexInputAttributeDescription& b) { return a.location < b.location; }); // Compute final offsets of each attribute, and total vertex stride. @@ -486,8 +481,7 @@ int main(int argn, char** argv) { // input variables can also be retrieved directly from the module, by // location (unless the location is (uint32_t)-1, as is the case with // built-in inputs) - auto p_var2 = - spvReflectGetInputVariableByLocation(&module, p_var->location, &result); + auto p_var2 = spvReflectGetInputVariableByLocation(&module, p_var->location, &result); if (p_var->location == UINT32_MAX) { assert(result == SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); assert(p_var2 == nullptr); @@ -499,8 +493,7 @@ int main(int argn, char** argv) { // input variables can also be retrieved directly from the module, by // semantic (if present) - p_var2 = - spvReflectGetInputVariableBySemantic(&module, p_var->semantic, &result); + p_var2 = spvReflectGetInputVariableBySemantic(&module, p_var->semantic, &result); if (!p_var->semantic) { assert(result == SPV_REFLECT_RESULT_ERROR_NULL_POINTER); assert(p_var2 == nullptr); @@ -527,8 +520,7 @@ int main(int argn, char** argv) { // output variables can also be retrieved directly from the module, by // location (unless the location is (uint32_t)-1, as is the case with // built-in outputs) - auto p_var2 = spvReflectGetOutputVariableByLocation( - &module, p_var->location, &result); + auto p_var2 = spvReflectGetOutputVariableByLocation(&module, p_var->location, &result); if (p_var->location == UINT32_MAX) { assert(result == SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); assert(p_var2 == nullptr); @@ -540,8 +532,7 @@ int main(int argn, char** argv) { // output variables can also be retrieved directly from the module, by // semantic (if present) - p_var2 = spvReflectGetOutputVariableBySemantic(&module, p_var->semantic, - &result); + p_var2 = spvReflectGetOutputVariableBySemantic(&module, p_var->semantic, &result); if (!p_var->semantic) { assert(result == SPV_REFLECT_RESULT_ERROR_NULL_POINTER); assert(p_var2 == nullptr); diff --git a/main.cpp b/main.cpp index 320406ae..3f041295 100644 --- a/main.cpp +++ b/main.cpp @@ -33,48 +33,44 @@ // PrintUsage() // ================================================================================================= void PrintUsage() { - std::cout - << "Usage: spirv-reflect [OPTIONS] path/to/SPIR-V/bytecode.spv" - << std::endl - << "Prints a summary of the reflection data extracted from SPIR-V " - "bytecode." - << std::endl - << "Options:" << std::endl - << " --help Display this message" << std::endl - << " -y,--yaml Format output as YAML. [default: disabled]" - << std::endl - << " -v VERBOSITY Specify output verbosity (YAML output " - "only):" - << std::endl - << " 0: shader info, block variables, interface " - "variables," - << std::endl - << " descriptor bindings. No type " - "descriptions. [default]" - << std::endl - << " 1: Everything above, plus type " - "descriptions." - << std::endl - << " 2: Everything above, plus SPIR-V bytecode " - "and all internal" - << std::endl - << " type descriptions. If you're not " - "working on SPIRV-Reflect" - << std::endl - << " itself, you probably don't want this." - << std::endl - << "-e,--entrypoint Prints the entry point found in shader " - "module." - << std::endl - << "-s,--stage Prints the Vulkan shader stage found in " - "shader module." - << std::endl - << "-f,--file Prints the source file found in shader " - "module." - << std::endl - << "-fcb,--flatten_cbuffers Flatten constant buffers on non-YAML " - "output." - << std::endl; + std::cout << "Usage: spirv-reflect [OPTIONS] path/to/SPIR-V/bytecode.spv" << std::endl + << "Prints a summary of the reflection data extracted from SPIR-V " + "bytecode." + << std::endl + << "Options:" << std::endl + << " --help Display this message" << std::endl + << " -y,--yaml Format output as YAML. [default: disabled]" << std::endl + << " -v VERBOSITY Specify output verbosity (YAML output " + "only):" + << std::endl + << " 0: shader info, block variables, interface " + "variables," + << std::endl + << " descriptor bindings. No type " + "descriptions. [default]" + << std::endl + << " 1: Everything above, plus type " + "descriptions." + << std::endl + << " 2: Everything above, plus SPIR-V bytecode " + "and all internal" + << std::endl + << " type descriptions. If you're not " + "working on SPIRV-Reflect" + << std::endl + << " itself, you probably don't want this." << std::endl + << "-e,--entrypoint Prints the entry point found in shader " + "module." + << std::endl + << "-s,--stage Prints the Vulkan shader stage found in " + "shader module." + << std::endl + << "-f,--file Prints the source file found in shader " + "module." + << std::endl + << "-fcb,--flatten_cbuffers Flatten constant buffers on non-YAML " + "output." + << std::endl; } // ================================================================================================= @@ -119,8 +115,7 @@ int main(int argn, char** argv) { std::ifstream spv_ifstream(input_spv_path.c_str(), std::ios::binary); if (!spv_ifstream.is_open()) { - std::cerr << "ERROR: could not open '" << input_spv_path << "' for reading" - << std::endl; + std::cerr << "ERROR: could not open '" << input_spv_path << "' for reading" << std::endl; return EXIT_FAILURE; } @@ -134,8 +129,7 @@ int main(int argn, char** argv) { spv_reflect::ShaderModule reflection(spv_data.size(), spv_data.data()); if (reflection.GetResult() != SPV_REFLECT_RESULT_SUCCESS) { - std::cerr << "ERROR: could not process '" << input_spv_path - << "' (is it a valid SPIR-V bytecode?)" << std::endl; + std::cerr << "ERROR: could not process '" << input_spv_path << "' (is it a valid SPIR-V bytecode?)" << std::endl; return EXIT_FAILURE; } @@ -166,9 +160,7 @@ int main(int argn, char** argv) { if (printed_count > 0) { std::cout << ";"; } - std::cout << (reflection.GetSourceFile() != NULL - ? reflection.GetSourceFile() - : ""); + std::cout << (reflection.GetSourceFile() != NULL ? reflection.GetSourceFile() : ""); } std::cout << std::endl; diff --git a/spirv_reflect.c b/spirv_reflect.c index bbe24cd3..3a124af3 100644 --- a/spirv_reflect.c +++ b/spirv_reflect.c @@ -21,22 +21,21 @@ #include #if defined(WIN32) - #define _CRTDBG_MAP_ALLOC - #include - #include +#define _CRTDBG_MAP_ALLOC +#include +#include #else - #include +#include #endif #if defined(__clang__) || defined(__GNUC__) || defined(__APPLE_CC__) - #define FALLTHROUGH __attribute__((fallthrough)) +#define FALLTHROUGH __attribute__((fallthrough)) #else - #define FALLTHROUGH +#define FALLTHROUGH #endif #if defined(SPIRV_REFLECT_ENABLE_ASSERTS) - #define SPV_REFLECT_ASSERT(COND) \ - assert(COND); +#define SPV_REFLECT_ASSERT(COND) assert(COND); #else #define SPV_REFLECT_ASSERT(COND) #endif @@ -50,9 +49,7 @@ enum { SpvReflectDecorationHlslCounterBufferGOOGLE = 5634, SpvReflectDecorationHlslSemanticGOOGLE = 5635, }; -// clang-format on -// clang-format off enum { SPIRV_STARTING_WORD_INDEX = 5, SPIRV_WORD_SIZE = sizeof(uint32_t), @@ -61,37 +58,27 @@ enum { SPIRV_DATA_ALIGNMENT = 4 * SPIRV_WORD_SIZE, // 16 SPIRV_ACCESS_CHAIN_INDEX_OFFSET = 4, }; -// clang-format on -// clang-format off enum { INVALID_VALUE = 0xFFFFFFFF, }; -// clang-format on -// clang-format off enum { MAX_NODE_NAME_LENGTH = 1024, // Number of unique PhysicalStorageBuffer structs tracked to detect recursion MAX_RECURSIVE_PHYSICAL_POINTER_CHECK = 128, }; -// clang-format on -// clang-format off enum { IMAGE_SAMPLED = 1, IMAGE_STORAGE = 2, }; -// clang-format on -// clang-format off typedef struct SpvReflectPrvArrayTraits { uint32_t element_type_id; uint32_t length_id; } SpvReflectPrvArrayTraits; -// clang-format on -// clang-format off typedef struct SpvReflectPrvImageTraits { uint32_t sampled_type_id; SpvDim dim; @@ -101,23 +88,17 @@ typedef struct SpvReflectPrvImageTraits { uint32_t sampled; SpvImageFormat image_format; } SpvReflectPrvImageTraits; -// clang-format on -// clang-format off typedef struct SpvReflectPrvNumberDecoration { uint32_t word_offset; uint32_t value; } SpvReflectPrvNumberDecoration; -// clang-format on -// clang-format off typedef struct SpvReflectPrvStringDecoration { uint32_t word_offset; const char* value; } SpvReflectPrvStringDecoration; -// clang-format on -// clang-format off typedef struct SpvReflectPrvDecorations { bool is_relaxed_precision; bool is_block; @@ -144,9 +125,7 @@ typedef struct SpvReflectPrvDecorations { uint32_t matrix_stride; SpvBuiltIn built_in; } SpvReflectPrvDecorations; -// clang-format on -// clang-format off typedef struct SpvReflectPrvNode { uint32_t result_id; SpvOp op; @@ -168,16 +147,12 @@ typedef struct SpvReflectPrvNode { const char** member_names; SpvReflectPrvDecorations* member_decorations; } SpvReflectPrvNode; -// clang-format on -// clang-format off typedef struct SpvReflectPrvString { uint32_t result_id; const char* string; } SpvReflectPrvString; -// clang-format on -// clang-format off typedef struct SpvReflectPrvFunction { uint32_t id; uint32_t callee_count; @@ -186,9 +161,7 @@ typedef struct SpvReflectPrvFunction { uint32_t accessed_ptr_count; uint32_t* accessed_ptrs; } SpvReflectPrvFunction; -// clang-format on -// clang-format off typedef struct SpvReflectPrvAccessChain { uint32_t result_id; uint32_t result_type_id; @@ -207,9 +180,7 @@ typedef struct SpvReflectPrvAccessChain { // Block variable ac is pointing to (for block references) SpvReflectBlockVariable* block_var; } SpvReflectPrvAccessChain; -// clang-format on -// clang-format off typedef struct SpvReflectPrvParser { size_t spirv_word_count; uint32_t* spirv_code; @@ -240,30 +211,22 @@ typedef struct SpvReflectPrvParser { static uint32_t Max(uint32_t a, uint32_t b) { return a > b ? a : b; } static uint32_t Min(uint32_t a, uint32_t b) { return a < b ? a : b; } -static uint32_t RoundUp( - uint32_t value, - uint32_t multiple) -{ +static uint32_t RoundUp(uint32_t value, uint32_t multiple) { assert(multiple && ((multiple & (multiple - 1)) == 0)); return (value + multiple - 1) & ~(multiple - 1); } -#define IsNull(ptr) \ - (ptr == NULL) +#define IsNull(ptr) (ptr == NULL) -#define IsNotNull(ptr) \ - (ptr != NULL) +#define IsNotNull(ptr) (ptr != NULL) -#define SafeFree(ptr) \ - { \ - free((void*)ptr); \ - ptr = NULL; \ +#define SafeFree(ptr) \ + { \ + free((void*)ptr); \ + ptr = NULL; \ } -static int SortCompareUint32( - const void* a, - const void* b) -{ +static int SortCompareUint32(const void* a, const void* b) { const uint32_t* p_a = (const uint32_t*)a; const uint32_t* p_b = (const uint32_t*)b; @@ -277,8 +240,7 @@ static int SortCompareUint32( // arranged into "runs" so that all the entries with one // value are adjacent. // -static size_t DedupSortedUint32(uint32_t* arr, size_t size) -{ +static size_t DedupSortedUint32(uint32_t* arr, size_t size) { if (size == 0) { return 0; } @@ -289,14 +251,10 @@ static size_t DedupSortedUint32(uint32_t* arr, size_t size) arr[dedup_idx] = arr[i]; } } - return dedup_idx+1; + return dedup_idx + 1; } -static bool SearchSortedUint32( - const uint32_t* arr, - size_t size, - uint32_t target) -{ +static bool SearchSortedUint32(const uint32_t* arr, size_t size, uint32_t target) { size_t lo = 0; size_t hi = size; while (lo < hi) { @@ -304,7 +262,7 @@ static bool SearchSortedUint32( if (arr[mid] == target) { return true; } else if (arr[mid] < target) { - lo = mid+1; + lo = mid + 1; } else { hi = mid; } @@ -312,15 +270,8 @@ static bool SearchSortedUint32( return false; } -static SpvReflectResult IntersectSortedUint32( - const uint32_t* p_arr0, - size_t arr0_size, - const uint32_t* p_arr1, - size_t arr1_size, - uint32_t** pp_res, - size_t* res_size -) -{ +static SpvReflectResult IntersectSortedUint32(const uint32_t* p_arr0, size_t arr0_size, const uint32_t* p_arr1, size_t arr1_size, + uint32_t** pp_res, size_t* res_size) { *pp_res = NULL; *res_size = 0; if (IsNull(p_arr0) || IsNull(p_arr1)) { @@ -367,11 +318,7 @@ static SpvReflectResult IntersectSortedUint32( return SPV_REFLECT_RESULT_SUCCESS; } - -static bool InRange( - const SpvReflectPrvParser* p_parser, - uint32_t index) -{ +static bool InRange(const SpvReflectPrvParser* p_parser, uint32_t index) { bool in_range = false; if (IsNotNull(p_parser)) { in_range = (index < p_parser->spirv_word_count); @@ -379,11 +326,7 @@ static bool InRange( return in_range; } -static SpvReflectResult ReadU32( - SpvReflectPrvParser* p_parser, - uint32_t word_offset, - uint32_t* p_value) -{ +static SpvReflectResult ReadU32(SpvReflectPrvParser* p_parser, uint32_t word_offset, uint32_t* p_value) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); assert(InRange(p_parser, word_offset)); @@ -395,30 +338,25 @@ static SpvReflectResult ReadU32( return result; } -#define UNCHECKED_READU32(parser, word_offset, value) \ - { \ - (void) ReadU32(parser, word_offset, (uint32_t*)&(value)); \ - } +#define UNCHECKED_READU32(parser, word_offset, value) \ + { (void)ReadU32(parser, word_offset, (uint32_t*)&(value)); } -#define CHECKED_READU32(parser, word_offset, value) \ - { \ - SpvReflectResult checked_readu32_result = ReadU32(parser, \ - word_offset, (uint32_t*)&(value)); \ - if (checked_readu32_result != SPV_REFLECT_RESULT_SUCCESS) { \ - return checked_readu32_result; \ - } \ +#define CHECKED_READU32(parser, word_offset, value) \ + { \ + SpvReflectResult checked_readu32_result = ReadU32(parser, word_offset, (uint32_t*)&(value)); \ + if (checked_readu32_result != SPV_REFLECT_RESULT_SUCCESS) { \ + return checked_readu32_result; \ + } \ } -#define CHECKED_READU32_CAST(parser, word_offset, cast_to_type, value) \ - { \ - uint32_t checked_readu32_cast_u32 = UINT32_MAX; \ - SpvReflectResult checked_readu32_cast_result = ReadU32(parser, \ - word_offset, \ - (uint32_t*)&(checked_readu32_cast_u32)); \ - if (checked_readu32_cast_result != SPV_REFLECT_RESULT_SUCCESS) { \ - return checked_readu32_cast_result; \ - } \ - value = (cast_to_type)checked_readu32_cast_u32; \ +#define CHECKED_READU32_CAST(parser, word_offset, cast_to_type, value) \ + { \ + uint32_t checked_readu32_cast_u32 = UINT32_MAX; \ + SpvReflectResult checked_readu32_cast_result = ReadU32(parser, word_offset, (uint32_t*)&(checked_readu32_cast_u32)); \ + if (checked_readu32_cast_result != SPV_REFLECT_RESULT_SUCCESS) { \ + return checked_readu32_cast_result; \ + } \ + value = (cast_to_type)checked_readu32_cast_u32; \ } #define IF_READU32(result, parser, word_offset, value) \ @@ -435,15 +373,8 @@ static SpvReflectResult ReadU32( } \ } -static SpvReflectResult ReadStr( - SpvReflectPrvParser* p_parser, - uint32_t word_offset, - uint32_t word_index, - uint32_t word_count, - uint32_t* p_buf_size, - char* p_buf -) -{ +static SpvReflectResult ReadStr(SpvReflectPrvParser* p_parser, uint32_t word_offset, uint32_t word_index, uint32_t word_count, + uint32_t* p_buf_size, char* p_buf) { uint32_t limit = (word_offset + word_count); assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); @@ -470,8 +401,7 @@ static SpvReflectResult ReadStr( memcpy(p_buf, c_str, length_with_terminator); result = SPV_REFLECT_RESULT_SUCCESS; } - } - else { + } else { if (IsNotNull(p_buf_size)) { *p_buf_size = length_with_terminator; result = SPV_REFLECT_RESULT_SUCCESS; @@ -482,8 +412,7 @@ static SpvReflectResult ReadStr( return result; } -static SpvReflectDecorationFlags ApplyDecorations(const SpvReflectPrvDecorations* p_decoration_fields) -{ +static SpvReflectDecorationFlags ApplyDecorations(const SpvReflectPrvDecorations* p_decoration_fields) { SpvReflectDecorationFlags decorations = SPV_REFLECT_DECORATION_NONE; if (p_decoration_fields->is_relaxed_precision) { decorations |= SPV_REFLECT_DECORATION_RELAXED_PRECISION; @@ -527,13 +456,11 @@ static SpvReflectDecorationFlags ApplyDecorations(const SpvReflectPrvDecorations return decorations; } -static void ApplyNumericTraits(const SpvReflectTypeDescription* p_type, SpvReflectNumericTraits* p_numeric_traits) -{ +static void ApplyNumericTraits(const SpvReflectTypeDescription* p_type, SpvReflectNumericTraits* p_numeric_traits) { memcpy(p_numeric_traits, &p_type->traits.numeric, sizeof(p_type->traits.numeric)); } -static void ApplyArrayTraits(const SpvReflectTypeDescription* p_type, SpvReflectArrayTraits* p_array_traits) -{ +static void ApplyArrayTraits(const SpvReflectTypeDescription* p_type, SpvReflectArrayTraits* p_array_traits) { memcpy(p_array_traits, &p_type->traits.array, sizeof(p_type->traits.array)); } @@ -541,10 +468,7 @@ static bool IsSpecConstant(const SpvReflectPrvNode* p_node) { return (p_node->op == SpvOpSpecConstant || p_node->op == SpvOpSpecConstantOp); } -static SpvReflectPrvNode* FindNode( - SpvReflectPrvParser* p_parser, - uint32_t result_id) -{ +static SpvReflectPrvNode* FindNode(SpvReflectPrvParser* p_parser, uint32_t result_id) { SpvReflectPrvNode* p_node = NULL; for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_elem = &(p_parser->nodes[i]); @@ -556,8 +480,7 @@ static SpvReflectPrvNode* FindNode( return p_node; } -static SpvReflectTypeDescription* FindType(SpvReflectShaderModule* p_module, uint32_t type_id) -{ +static SpvReflectTypeDescription* FindType(SpvReflectShaderModule* p_module, uint32_t type_id) { SpvReflectTypeDescription* p_type = NULL; for (size_t i = 0; i < p_module->_internal->type_description_count; ++i) { SpvReflectTypeDescription* p_elem = &(p_module->_internal->type_descriptions[i]); @@ -569,8 +492,7 @@ static SpvReflectTypeDescription* FindType(SpvReflectShaderModule* p_module, uin return p_type; } -static SpvReflectPrvAccessChain* FindAccessChain(SpvReflectPrvParser* p_parser, - uint32_t id) { +static SpvReflectPrvAccessChain* FindAccessChain(SpvReflectPrvParser* p_parser, uint32_t id) { uint32_t ac_cnt = p_parser->access_chain_count; for (uint32_t i = 0; i < ac_cnt; i++) { if (p_parser->access_chains[i].result_id == id) { @@ -580,8 +502,7 @@ static SpvReflectPrvAccessChain* FindAccessChain(SpvReflectPrvParser* p_parser, return 0; } -static uint32_t FindBaseId(SpvReflectPrvParser* p_parser, - SpvReflectPrvAccessChain* ac) { +static uint32_t FindBaseId(SpvReflectPrvParser* p_parser, SpvReflectPrvAccessChain* ac) { uint32_t base_id = ac->base_id; SpvReflectPrvNode* base_node = FindNode(p_parser, base_id); // TODO - This is just a band-aid to fix crashes. @@ -591,22 +512,19 @@ static uint32_t FindBaseId(SpvReflectPrvParser* p_parser, return 0; } while (base_node->op != SpvOpVariable) { - switch (base_node->op) { - case SpvOpLoad: { - UNCHECKED_READU32(p_parser, base_node->word_offset + 3, base_id); - } - break; - case SpvOpFunctionParameter: { - UNCHECKED_READU32(p_parser, base_node->word_offset + 2, base_id); - } - break; - default: { - assert(false); - } - break; - } - - SpvReflectPrvAccessChain* base_ac = FindAccessChain(p_parser, base_id); + switch (base_node->op) { + case SpvOpLoad: { + UNCHECKED_READU32(p_parser, base_node->word_offset + 3, base_id); + } break; + case SpvOpFunctionParameter: { + UNCHECKED_READU32(p_parser, base_node->word_offset + 2, base_id); + } break; + default: { + assert(false); + } break; + } + + SpvReflectPrvAccessChain* base_ac = FindAccessChain(p_parser, base_id); if (base_ac == 0) { return 0; } @@ -619,8 +537,7 @@ static uint32_t FindBaseId(SpvReflectPrvParser* p_parser, return base_id; } -static SpvReflectBlockVariable* GetRefBlkVar(SpvReflectPrvParser* p_parser, - SpvReflectPrvAccessChain* ac) { +static SpvReflectBlockVariable* GetRefBlkVar(SpvReflectPrvParser* p_parser, SpvReflectPrvAccessChain* ac) { uint32_t base_id = ac->base_id; SpvReflectPrvNode* base_node = FindNode(p_parser, base_id); assert(base_node->op == SpvOpLoad); @@ -646,11 +563,7 @@ bool IsPointerToPointer(SpvReflectPrvParser* p_parser, uint32_t type_id) { return pte_node->op == SpvOpTypePointer; } -static SpvReflectResult CreateParser( - size_t size, - void* p_code, - SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult CreateParser(size_t size, void* p_code, SpvReflectPrvParser* p_parser) { if (p_code == NULL) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -672,8 +585,7 @@ static SpvReflectResult CreateParser( return SPV_REFLECT_RESULT_SUCCESS; } -static void DestroyParser(SpvReflectPrvParser* p_parser) -{ +static void DestroyParser(SpvReflectPrvParser* p_parser) { if (!IsNull(p_parser->nodes)) { // Free nodes for (size_t i = 0; i < p_parser->node_count; ++i) { @@ -707,8 +619,7 @@ static void DestroyParser(SpvReflectPrvParser* p_parser) } } -static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); @@ -783,12 +694,12 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) p_node->word_count = node_word_count; switch (p_node->op) { - default: break; + default: + break; case SpvOpString: { ++(p_parser->string_count); - } - break; + } break; case SpvOpSource: { CHECKED_READU32_CAST(p_parser, p_node->word_offset + 1, SpvSourceLanguage, p_parser->source_language); @@ -806,17 +717,16 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } - #ifdef _WIN32 +#ifdef _WIN32 strcpy_s(p_source_temp, source_len + 1, p_source); - #else +#else strcpy(p_source_temp, p_source); - #endif +#endif SafeFree(p_parser->source_embedded); p_parser->source_embedded = p_source_temp; } - } - break; + } break; case SpvOpSourceContinued: { const char* p_source = (const char*)(p_parser->spirv_code + p_node->word_offset + 1); @@ -829,44 +739,38 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } - #ifdef _WIN32 +#ifdef _WIN32 strcpy_s(p_continued_source, embedded_source_len + 1, p_parser->source_embedded); strcat_s(p_continued_source, embedded_source_len + source_len + 1, p_source); - #else +#else strcpy(p_continued_source, p_parser->source_embedded); strcat(p_continued_source, p_source); - #endif +#endif SafeFree(p_parser->source_embedded); p_parser->source_embedded = p_continued_source; - } - break; + } break; case SpvOpEntryPoint: { ++(p_parser->entry_point_count); - } - break; + } break; case SpvOpCapability: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->capability); ++(p_parser->capability_count); - } - break; + } break; case SpvOpName: - case SpvOpMemberName: - { + case SpvOpMemberName: { uint32_t member_offset = (p_node->op == SpvOpMemberName) ? 1 : 0; uint32_t name_start = p_node->word_offset + member_offset + 2; p_node->name = (const char*)(p_parser->spirv_code + name_start); - } - break; + } break; - case SpvOpTypeStruct: - { + case SpvOpTypeStruct: { p_node->member_count = p_node->word_count - 2; FALLTHROUGH; - } // Fall through + } // Fall through // This is all the rest of OpType* that need to be tracked // Possible new extensions might expose new type, will need to be added @@ -904,30 +808,26 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) CHECKED_READU32(p_parser, p_node->word_offset + 7, p_node->image_traits.sampled); CHECKED_READU32(p_parser, p_node->word_offset + 8, p_node->image_traits.image_format); p_node->is_type = true; - } - break; + } break; case SpvOpTypeSampledImage: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->image_type_id); p_node->is_type = true; - } - break; + } break; - case SpvOpTypeArray: { + case SpvOpTypeArray: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->array_traits.element_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 3, p_node->array_traits.length_id); p_node->is_type = true; - } - break; + } break; - case SpvOpTypeRuntimeArray: { + case SpvOpTypeRuntimeArray: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->array_traits.element_type_id); p_node->is_type = true; - } - break; + } break; case SpvOpTypePointer: { uint32_t result_id; @@ -942,16 +842,13 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->storage_class); CHECKED_READU32(p_parser, p_node->word_offset + 3, p_node->type_id); p_node->is_type = true; - } - break; + } break; - case SpvOpTypeForwardPointer: - { + case SpvOpTypeForwardPointer: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->storage_class); p_node->is_type = true; - } - break; + } break; case SpvOpConstantTrue: case SpvOpConstantFalse: @@ -961,8 +858,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) case SpvOpConstantNull: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); - } - break; + } break; case SpvOpSpecConstantTrue: case SpvOpSpecConstantFalse: @@ -971,27 +867,21 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) case SpvOpSpecConstantOp: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); - } - break; + } break; - case SpvOpVariable: - { + case SpvOpVariable: { CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->type_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 3, p_node->storage_class); - } - break; + } break; - case SpvOpLoad: - { + case SpvOpLoad: { // Only load enough so OpDecorate can reference the node, skip the remaining operands. CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); - } - break; + } break; - case SpvOpAccessChain: - { + case SpvOpAccessChain: { SpvReflectPrvAccessChain* p_access_chain = &(p_parser->access_chains[access_chain_index]); CHECKED_READU32(p_parser, p_node->word_offset + 1, p_access_chain->result_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_access_chain->result_id); @@ -1003,7 +893,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) p_access_chain->index_count = (node_word_count - SPIRV_ACCESS_CHAIN_INDEX_OFFSET); if (p_access_chain->index_count > 0) { p_access_chain->indexes = (uint32_t*)calloc(p_access_chain->index_count, sizeof(*(p_access_chain->indexes))); - if (IsNull( p_access_chain->indexes)) { + if (IsNull(p_access_chain->indexes)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } // Parse any index values for access chain @@ -1024,40 +914,32 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) } } ++access_chain_index; - } - break; + } break; - case SpvOpFunction: - { + case SpvOpFunction: { CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); // Count function definitions, not function declarations. To determine // the difference, set an in-function variable, and then if an OpLabel // is reached before the end of the function increment the function // count. function_node = node_index; - } - break; + } break; - case SpvOpLabel: - { + case SpvOpLabel: { if (function_node != (uint32_t)INVALID_VALUE) { SpvReflectPrvNode* p_func_node = &(p_parser->nodes[function_node]); CHECKED_READU32(p_parser, p_func_node->word_offset + 2, p_func_node->result_id); ++(p_parser->function_count); } FALLTHROUGH; - } // Fall through + } // Fall through - case SpvOpFunctionEnd: - { + case SpvOpFunctionEnd: { function_node = (uint32_t)INVALID_VALUE; - } - break; - case SpvOpFunctionParameter: - { - CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); - } - break; + } break; + case SpvOpFunctionParameter: { + CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); + } break; } if (p_node->is_type) { @@ -1071,8 +953,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseStrings(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseStrings(SpvReflectPrvParser* p_parser) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); assert(IsNotNull(p_parser->nodes)); @@ -1115,8 +996,7 @@ static SpvReflectResult ParseStrings(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseSource(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseSource(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); @@ -1132,9 +1012,8 @@ static SpvReflectResult ParseSource(SpvReflectPrvParser* p_parser, SpvReflectSha } } - //Source code - if (IsNotNull(p_parser->source_embedded)) - { + // Source code + if (IsNotNull(p_parser->source_embedded)) { const size_t source_len = strlen(p_parser->source_embedded); char* p_source = (char*)calloc(source_len + 1, sizeof(char)); @@ -1142,11 +1021,11 @@ static SpvReflectResult ParseSource(SpvReflectPrvParser* p_parser, SpvReflectSha return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } - #ifdef _WIN32 +#ifdef _WIN32 strcpy_s(p_source, source_len + 1, p_parser->source_embedded); - #else +#else strcpy(p_source, p_parser->source_embedded); - #endif +#endif p_module->source_source = p_source; } @@ -1155,12 +1034,8 @@ static SpvReflectResult ParseSource(SpvReflectPrvParser* p_parser, SpvReflectSha return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseFunction( - SpvReflectPrvParser* p_parser, - SpvReflectPrvNode* p_func_node, - SpvReflectPrvFunction* p_func, - size_t first_label_index) -{ +static SpvReflectResult ParseFunction(SpvReflectPrvParser* p_parser, SpvReflectPrvNode* p_func_node, SpvReflectPrvFunction* p_func, + size_t first_label_index) { p_func->id = p_func_node->result_id; p_func->callee_count = 0; @@ -1174,8 +1049,7 @@ static SpvReflectResult ParseFunction( switch (p_node->op) { case SpvOpFunctionCall: { ++(p_func->callee_count); - } - break; + } break; case SpvOpLoad: case SpvOpAccessChain: case SpvOpInBoundsAccessChain: @@ -1184,32 +1058,27 @@ static SpvReflectResult ParseFunction( case SpvOpGenericPtrMemSemantics: case SpvOpInBoundsPtrAccessChain: case SpvOpStore: - case SpvOpImageTexelPointer: - { + case SpvOpImageTexelPointer: { ++(p_func->accessed_ptr_count); - } - break; + } break; case SpvOpCopyMemory: - case SpvOpCopyMemorySized: - { + case SpvOpCopyMemorySized: { p_func->accessed_ptr_count += 2; - } - break; - default: break; + } break; + default: + break; } } if (p_func->callee_count > 0) { - p_func->callees = (uint32_t*)calloc(p_func->callee_count, - sizeof(*(p_func->callees))); + p_func->callees = (uint32_t*)calloc(p_func->callee_count, sizeof(*(p_func->callees))); if (IsNull(p_func->callees)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } } if (p_func->accessed_ptr_count > 0) { - p_func->accessed_ptrs = (uint32_t*)calloc(p_func->accessed_ptr_count, - sizeof(*(p_func->accessed_ptrs))); + p_func->accessed_ptrs = (uint32_t*)calloc(p_func->accessed_ptr_count, sizeof(*(p_func->accessed_ptrs))); if (IsNull(p_func->accessed_ptrs)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -1224,11 +1093,9 @@ static SpvReflectResult ParseFunction( } switch (p_node->op) { case SpvOpFunctionCall: { - CHECKED_READU32(p_parser, p_node->word_offset + 3, - p_func->callees[p_func->callee_count]); + CHECKED_READU32(p_parser, p_node->word_offset + 3, p_func->callees[p_func->callee_count]); (++p_func->callee_count); - } - break; + } break; case SpvOpLoad: case SpvOpAccessChain: case SpvOpInBoundsAccessChain: @@ -1236,63 +1103,46 @@ static SpvReflectResult ParseFunction( case SpvOpArrayLength: case SpvOpGenericPtrMemSemantics: case SpvOpInBoundsPtrAccessChain: - case SpvOpImageTexelPointer: - { - CHECKED_READU32(p_parser, p_node->word_offset + 3, - p_func->accessed_ptrs[p_func->accessed_ptr_count]); + case SpvOpImageTexelPointer: { + CHECKED_READU32(p_parser, p_node->word_offset + 3, p_func->accessed_ptrs[p_func->accessed_ptr_count]); (++p_func->accessed_ptr_count); - } - break; - case SpvOpStore: - { - CHECKED_READU32(p_parser, p_node->word_offset + 2, - p_func->accessed_ptrs[p_func->accessed_ptr_count]); + } break; + case SpvOpStore: { + CHECKED_READU32(p_parser, p_node->word_offset + 2, p_func->accessed_ptrs[p_func->accessed_ptr_count]); (++p_func->accessed_ptr_count); - } - break; + } break; case SpvOpCopyMemory: - case SpvOpCopyMemorySized: - { - CHECKED_READU32(p_parser, p_node->word_offset + 2, - p_func->accessed_ptrs[p_func->accessed_ptr_count]); + case SpvOpCopyMemorySized: { + CHECKED_READU32(p_parser, p_node->word_offset + 2, p_func->accessed_ptrs[p_func->accessed_ptr_count]); (++p_func->accessed_ptr_count); - CHECKED_READU32(p_parser, p_node->word_offset + 3, - p_func->accessed_ptrs[p_func->accessed_ptr_count]); + CHECKED_READU32(p_parser, p_node->word_offset + 3, p_func->accessed_ptrs[p_func->accessed_ptr_count]); (++p_func->accessed_ptr_count); - } - break; - default: break; + } break; + default: + break; } } if (p_func->callee_count > 0) { - qsort(p_func->callees, p_func->callee_count, - sizeof(*(p_func->callees)), SortCompareUint32); + qsort(p_func->callees, p_func->callee_count, sizeof(*(p_func->callees)), SortCompareUint32); } - p_func->callee_count = (uint32_t)DedupSortedUint32(p_func->callees, - p_func->callee_count); + p_func->callee_count = (uint32_t)DedupSortedUint32(p_func->callees, p_func->callee_count); if (p_func->accessed_ptr_count > 0) { - qsort(p_func->accessed_ptrs, p_func->accessed_ptr_count, - sizeof(*(p_func->accessed_ptrs)), SortCompareUint32); + qsort(p_func->accessed_ptrs, p_func->accessed_ptr_count, sizeof(*(p_func->accessed_ptrs)), SortCompareUint32); } - p_func->accessed_ptr_count = (uint32_t)DedupSortedUint32(p_func->accessed_ptrs, - p_func->accessed_ptr_count); + p_func->accessed_ptr_count = (uint32_t)DedupSortedUint32(p_func->accessed_ptrs, p_func->accessed_ptr_count); return SPV_REFLECT_RESULT_SUCCESS; } -static int SortCompareFunctions( - const void* a, - const void* b) -{ +static int SortCompareFunctions(const void* a, const void* b) { const SpvReflectPrvFunction* af = (const SpvReflectPrvFunction*)a; const SpvReflectPrvFunction* bf = (const SpvReflectPrvFunction*)b; return (int)af->id - (int)bf->id; } -static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); assert(IsNotNull(p_parser->nodes)); @@ -1302,8 +1152,7 @@ static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } - p_parser->functions = (SpvReflectPrvFunction*)calloc(p_parser->function_count, - sizeof(*(p_parser->functions))); + p_parser->functions = (SpvReflectPrvFunction*)calloc(p_parser->function_count, sizeof(*(p_parser->functions))); if (IsNull(p_parser->functions)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -1342,8 +1191,7 @@ static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) ++function_index; } - qsort(p_parser->functions, p_parser->function_count, - sizeof(*(p_parser->functions)), SortCompareFunctions); + qsort(p_parser->functions, p_parser->function_count, sizeof(*(p_parser->functions)), SortCompareFunctions); // Once they're sorted, link the functions with pointers to improve graph // traversal efficiency @@ -1352,8 +1200,7 @@ static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) if (p_func->callee_count == 0) { continue; } - p_func->callee_ptrs = (SpvReflectPrvFunction**)calloc(p_func->callee_count, - sizeof(*(p_func->callee_ptrs))); + p_func->callee_ptrs = (SpvReflectPrvFunction**)calloc(p_func->callee_count, sizeof(*(p_func->callee_ptrs))); for (size_t j = 0, k = 0; j < p_func->callee_count; ++j) { while (p_parser->functions[k].id != p_func->callees[j]) { ++k; @@ -1370,8 +1217,7 @@ static SpvReflectResult ParseFunctions(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseMemberCounts(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseMemberCounts(SpvReflectPrvParser* p_parser) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); assert(IsNotNull(p_parser->nodes)); @@ -1406,7 +1252,7 @@ static SpvReflectResult ParseMemberCounts(SpvReflectPrvParser* p_parser) continue; } - p_node->member_names = (const char **)calloc(p_node->member_count, sizeof(*(p_node->member_names))); + p_node->member_names = (const char**)calloc(p_node->member_count, sizeof(*(p_node->member_names))); if (IsNull(p_node->member_names)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -1420,8 +1266,7 @@ static SpvReflectResult ParseMemberCounts(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseNames(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseNames(SpvReflectPrvParser* p_parser) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->spirv_code)); assert(IsNotNull(p_parser->nodes)); @@ -1454,18 +1299,15 @@ static SpvReflectResult ParseNames(SpvReflectPrvParser* p_parser) return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) -{ +static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) { for (uint32_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_node = &(p_parser->nodes[i]); - if (((uint32_t)p_node->op != (uint32_t)SpvOpDecorate) && - ((uint32_t)p_node->op != (uint32_t)SpvOpMemberDecorate) && + if (((uint32_t)p_node->op != (uint32_t)SpvOpDecorate) && ((uint32_t)p_node->op != (uint32_t)SpvOpMemberDecorate) && ((uint32_t)p_node->op != (uint32_t)SpvReflectOpDecorateId) && ((uint32_t)p_node->op != (uint32_t)SpvReflectOpDecorateStringGOOGLE) && - ((uint32_t)p_node->op != (uint32_t)SpvReflectOpMemberDecorateStringGOOGLE)) - { - continue; + ((uint32_t)p_node->op != (uint32_t)SpvReflectOpMemberDecorateStringGOOGLE)) { + continue; } // Need to adjust the read offset if this is a member decoration @@ -1484,8 +1326,7 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) switch (decoration) { default: { skip = true; - } - break; + } break; case SpvDecorationRelaxedPrecision: case SpvDecorationBlock: case SpvDecorationBufferBlock: @@ -1510,8 +1351,7 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) case SpvReflectDecorationHlslCounterBufferGOOGLE: case SpvReflectDecorationHlslSemanticGOOGLE: { skip = false; - } - break; + } break; } if (skip) { continue; @@ -1539,71 +1379,60 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) } switch (decoration) { - default: break; + default: + break; case SpvDecorationRelaxedPrecision: { p_target_decorations->is_relaxed_precision = true; - } - break; + } break; case SpvDecorationBlock: { p_target_decorations->is_block = true; - } - break; + } break; case SpvDecorationBufferBlock: { p_target_decorations->is_buffer_block = true; - } - break; + } break; case SpvDecorationColMajor: { p_target_decorations->is_column_major = true; - } - break; + } break; case SpvDecorationRowMajor: { p_target_decorations->is_row_major = true; - } - break; + } break; case SpvDecorationArrayStride: { uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->array_stride); - } - break; + } break; case SpvDecorationMatrixStride: { uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->matrix_stride); - } - break; + } break; case SpvDecorationBuiltIn: { p_target_decorations->is_built_in = true; uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32_CAST(p_parser, word_offset, SpvBuiltIn, p_target_decorations->built_in); - } - break; + } break; case SpvDecorationNoPerspective: { p_target_decorations->is_noperspective = true; - } - break; + } break; case SpvDecorationFlat: { p_target_decorations->is_flat = true; - } - break; + } break; case SpvDecorationNonWritable: { p_target_decorations->is_non_writable = true; - } - break; + } break; case SpvDecorationNonReadable: { p_target_decorations->is_non_readable = true; - } - break; + } break; case SpvDecorationPatch: { p_target_decorations->is_patch = true; @@ -1621,68 +1450,55 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->location.value); p_target_decorations->location.word_offset = word_offset; - } - break; + } break; case SpvDecorationComponent: { uint32_t word_offset = p_node->word_offset + member_offset + 3; - CHECKED_READU32(p_parser, word_offset, - p_target_decorations->component.value); + CHECKED_READU32(p_parser, word_offset, p_target_decorations->component.value); p_target_decorations->component.word_offset = word_offset; } break; case SpvDecorationBinding: { - uint32_t word_offset = p_node->word_offset + member_offset+ 3; + uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->binding.value); p_target_decorations->binding.word_offset = word_offset; - } - break; + } break; case SpvDecorationDescriptorSet: { - uint32_t word_offset = p_node->word_offset + member_offset+ 3; + uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->set.value); p_target_decorations->set.word_offset = word_offset; - } - break; + } break; case SpvDecorationOffset: { - uint32_t word_offset = p_node->word_offset + member_offset+ 3; + uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->offset.value); p_target_decorations->offset.word_offset = word_offset; - } - break; + } break; case SpvDecorationInputAttachmentIndex: { - uint32_t word_offset = p_node->word_offset + member_offset+ 3; + uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->input_attachment_index.value); p_target_decorations->input_attachment_index.word_offset = word_offset; - } - break; + } break; case SpvReflectDecorationHlslCounterBufferGOOGLE: { - uint32_t word_offset = p_node->word_offset + member_offset+ 3; + uint32_t word_offset = p_node->word_offset + member_offset + 3; CHECKED_READU32(p_parser, word_offset, p_target_decorations->uav_counter_buffer.value); p_target_decorations->uav_counter_buffer.word_offset = word_offset; - } - break; + } break; case SpvReflectDecorationHlslSemanticGOOGLE: { uint32_t word_offset = p_node->word_offset + member_offset + 3; p_target_decorations->semantic.value = (const char*)(p_parser->spirv_code + word_offset); p_target_decorations->semantic.word_offset = word_offset; - } - break; + } break; } } return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult EnumerateAllUniforms( - SpvReflectShaderModule* p_module, - size_t* p_uniform_count, - uint32_t** pp_uniforms -) -{ +static SpvReflectResult EnumerateAllUniforms(SpvReflectShaderModule* p_module, size_t* p_uniform_count, uint32_t** pp_uniforms) { *p_uniform_count = p_module->descriptor_binding_count; if (*p_uniform_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; @@ -1696,19 +1512,13 @@ static SpvReflectResult EnumerateAllUniforms( for (size_t i = 0; i < *p_uniform_count; ++i) { (*pp_uniforms)[i] = p_module->descriptor_bindings[i].spirv_id; } - qsort(*pp_uniforms, *p_uniform_count, sizeof(**pp_uniforms), - SortCompareUint32); + qsort(*pp_uniforms, *p_uniform_count, sizeof(**pp_uniforms), SortCompareUint32); return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseType( - SpvReflectPrvParser* p_parser, - SpvReflectPrvNode* p_node, - SpvReflectPrvDecorations* p_struct_member_decorations, - SpvReflectShaderModule* p_module, - SpvReflectTypeDescription* p_type -) -{ +static SpvReflectResult ParseType(SpvReflectPrvParser* p_parser, SpvReflectPrvNode* p_node, + SpvReflectPrvDecorations* p_struct_member_decorations, SpvReflectShaderModule* p_module, + SpvReflectTypeDescription* p_type) { SpvReflectResult result = SPV_REFLECT_RESULT_SUCCESS; if (p_node->member_count > 0) { @@ -1723,8 +1533,7 @@ static SpvReflectResult ParseType( p_member_type->op = (SpvOp)INVALID_VALUE; p_member_type->storage_class = (SpvStorageClass)INVALID_VALUE; } - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } } @@ -1742,7 +1551,8 @@ static SpvReflectResult ParseType( p_type->decoration_flags = ApplyDecorations(&p_node->decorations); switch (p_node->op) { - default: break; + default: + break; case SpvOpTypeVoid: p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_VOID; break; @@ -1755,14 +1565,12 @@ static SpvReflectResult ParseType( p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_INT; IF_READU32(result, p_parser, p_node->word_offset + 2, p_type->traits.numeric.scalar.width); IF_READU32(result, p_parser, p_node->word_offset + 3, p_type->traits.numeric.scalar.signedness); - } - break; + } break; case SpvOpTypeFloat: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_FLOAT; IF_READU32(result, p_parser, p_node->word_offset + 2, p_type->traits.numeric.scalar.width); - } - break; + } break; case SpvOpTypeVector: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_VECTOR; @@ -1773,13 +1581,11 @@ static SpvReflectResult ParseType( SpvReflectPrvNode* p_next_node = FindNode(p_parser, component_type_id); if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); } - } - break; + } break; case SpvOpTypeMatrix: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_MATRIX; @@ -1789,8 +1595,7 @@ static SpvReflectResult ParseType( SpvReflectPrvNode* p_next_node = FindNode(p_parser, column_type_id); if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); } @@ -1800,8 +1605,7 @@ static SpvReflectResult ParseType( if (IsNotNull(p_struct_member_decorations)) { p_type->traits.numeric.matrix.stride = p_struct_member_decorations->matrix_stride; } - } - break; + } break; case SpvOpTypeImage: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_IMAGE; @@ -1810,8 +1614,7 @@ static SpvReflectResult ParseType( SpvReflectPrvNode* p_next_node = FindNode(p_parser, sampled_type_id); if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; } IF_READU32_CAST(result, p_parser, p_node->word_offset + 3, SpvDim, p_type->traits.image.dim); @@ -1820,13 +1623,11 @@ static SpvReflectResult ParseType( IF_READU32(result, p_parser, p_node->word_offset + 6, p_type->traits.image.ms); IF_READU32(result, p_parser, p_node->word_offset + 7, p_type->traits.image.sampled); IF_READU32_CAST(result, p_parser, p_node->word_offset + 8, SpvImageFormat, p_type->traits.image.image_format); - } - break; + } break; case SpvOpTypeSampler: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLER; - } - break; + } break; case SpvOpTypeSampledImage: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLED_IMAGE; @@ -1835,13 +1636,11 @@ static SpvReflectResult ParseType( SpvReflectPrvNode* p_next_node = FindNode(p_parser, image_type_id); if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); } - } - break; + } break; case SpvOpTypeArray: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_ARRAY; @@ -1858,8 +1657,7 @@ static SpvReflectResult ParseType( if (IsNotNull(p_length_node)) { uint32_t dim_index = p_type->traits.array.dims_count; if (IsSpecConstant(p_length_node)) { - p_type->traits.array.dims[dim_index] = - (uint32_t)SPV_REFLECT_ARRAY_DIM_SPEC_CONSTANT; + p_type->traits.array.dims[dim_index] = (uint32_t)SPV_REFLECT_ARRAY_DIM_SPEC_CONSTANT; p_type->traits.array.spec_constant_op_ids[dim_index] = length_id; p_type->traits.array.dims_count += 1; } else { @@ -1868,8 +1666,7 @@ static SpvReflectResult ParseType( if (result == SPV_REFLECT_RESULT_SUCCESS) { // Write the array dim and increment the count and offset p_type->traits.array.dims[dim_index] = length; - p_type->traits.array.spec_constant_op_ids[dim_index] = - (uint32_t)SPV_REFLECT_ARRAY_DIM_SPEC_CONSTANT; + p_type->traits.array.spec_constant_op_ids[dim_index] = (uint32_t)SPV_REFLECT_ARRAY_DIM_SPEC_CONSTANT; p_type->traits.array.dims_count += 1; } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; @@ -1881,14 +1678,12 @@ static SpvReflectResult ParseType( if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); } - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); } } - } - break; + } break; case SpvOpTypeRuntimeArray: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_ARRAY; @@ -1896,21 +1691,18 @@ static SpvReflectResult ParseType( IF_READU32(result, p_parser, p_node->word_offset + 2, element_type_id); p_type->traits.array.stride = p_node->decorations.array_stride; uint32_t dim_index = p_type->traits.array.dims_count; - p_type->traits.array.dims[dim_index] = - (uint32_t)SPV_REFLECT_ARRAY_DIM_RUNTIME; + p_type->traits.array.dims[dim_index] = (uint32_t)SPV_REFLECT_ARRAY_DIM_RUNTIME; p_type->traits.array.spec_constant_op_ids[dim_index] = 0; p_type->traits.array.dims_count += 1; // Parse next dimension or element type SpvReflectPrvNode* p_next_node = FindNode(p_parser, element_type_id); if (IsNotNull(p_next_node)) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); - } - else { + } else { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); } - } - break; + } break; case SpvOpTypeStruct: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_STRUCT; @@ -1941,13 +1733,13 @@ static SpvReflectResult ParseType( break; } // This looks wrong - //p_member_type->type_name = p_member_node->name; + // p_member_type->type_name = p_member_node->name; p_member_type->struct_member_name = p_node->member_names[member_index]; } - } - break; + } break; - case SpvOpTypeOpaque: break; + case SpvOpTypeOpaque: + break; case SpvOpTypePointer: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_REF; @@ -1963,11 +1755,9 @@ static SpvReflectResult ParseType( } } if (!found_recursion) { - p_parser->physical_pointer_check[p_parser->physical_pointer_count] = - p_type->id; + p_parser->physical_pointer_check[p_parser->physical_pointer_count] = p_type->id; p_parser->physical_pointer_count++; - if (p_parser->physical_pointer_count >= - MAX_RECURSIVE_PHYSICAL_POINTER_CHECK) { + if (p_parser->physical_pointer_count >= MAX_RECURSIVE_PHYSICAL_POINTER_CHECK) { return SPV_REFLECT_RESULT_ERROR_SPIRV_MAX_RECURSIVE_EXCEEDED; } } @@ -1980,17 +1770,14 @@ static SpvReflectResult ParseType( if (IsNull(p_next_node)) { result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; SPV_REFLECT_ASSERT(false); - } - else if (!found_recursion) { + } else if (!found_recursion) { result = ParseType(p_parser, p_next_node, NULL, p_module, p_type); } - } - break; + } break; case SpvOpTypeAccelerationStructureKHR: { p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE; - } - break; + } break; } if (result == SPV_REFLECT_RESULT_SUCCESS) { @@ -2005,10 +1792,7 @@ static SpvReflectResult ParseType( return result; } -static SpvReflectResult ParseTypes( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseTypes(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { if (p_parser->type_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -2031,7 +1815,7 @@ static SpvReflectResult ParseTypes( size_t type_index = 0; for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_node = &(p_parser->nodes[i]); - if (! p_node->is_type) { + if (!p_node->is_type) { continue; } @@ -2046,17 +1830,13 @@ static SpvReflectResult ParseTypes( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseCapabilities( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseCapabilities(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { if (p_parser->capability_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } p_module->capability_count = p_parser->capability_count; - p_module->capabilities = (SpvReflectCapability*)calloc(p_module->capability_count, - sizeof(*(p_module->capabilities))); + p_module->capabilities = (SpvReflectCapability*)calloc(p_module->capability_count, sizeof(*(p_module->capabilities))); if (IsNull(p_module->capabilities)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -2084,8 +1864,7 @@ static SpvReflectResult ParseCapabilities( return SPV_REFLECT_RESULT_SUCCESS; } -static int SortCompareDescriptorBinding(const void* a, const void* b) -{ +static int SortCompareDescriptorBinding(const void* a, const void* b) { const SpvReflectDescriptorBinding* p_elem_a = (const SpvReflectDescriptorBinding*)a; const SpvReflectDescriptorBinding* p_elem_b = (const SpvReflectDescriptorBinding*)b; int value = (int)(p_elem_a->binding) - (int)(p_elem_b->binding); @@ -2098,18 +1877,13 @@ static int SortCompareDescriptorBinding(const void* a, const void* b) return value; } -static SpvReflectResult ParseDescriptorBindings( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseDescriptorBindings(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { p_module->descriptor_binding_count = 0; for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_node = &(p_parser->nodes[i]); if ((p_node->op != SpvOpVariable) || - ((p_node->storage_class != SpvStorageClassUniform) && - (p_node->storage_class != SpvStorageClassStorageBuffer) && - (p_node->storage_class != SpvStorageClassUniformConstant))) - { + ((p_node->storage_class != SpvStorageClassUniform) && (p_node->storage_class != SpvStorageClassStorageBuffer) && + (p_node->storage_class != SpvStorageClassUniformConstant))) { continue; } if ((p_node->decorations.set.value == INVALID_VALUE) || (p_node->decorations.binding.value == INVALID_VALUE)) { @@ -2123,7 +1897,8 @@ static SpvReflectResult ParseDescriptorBindings( return SPV_REFLECT_RESULT_SUCCESS; } - p_module->descriptor_bindings = (SpvReflectDescriptorBinding*)calloc(p_module->descriptor_binding_count, sizeof(*(p_module->descriptor_bindings))); + p_module->descriptor_bindings = + (SpvReflectDescriptorBinding*)calloc(p_module->descriptor_binding_count, sizeof(*(p_module->descriptor_bindings))); if (IsNull(p_module->descriptor_bindings)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -2142,10 +1917,8 @@ static SpvReflectResult ParseDescriptorBindings( for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_node = &(p_parser->nodes[i]); if ((p_node->op != SpvOpVariable) || - ((p_node->storage_class != SpvStorageClassUniform) && - (p_node->storage_class != SpvStorageClassStorageBuffer) && - (p_node->storage_class != SpvStorageClassUniformConstant))) - { + ((p_node->storage_class != SpvStorageClassUniform) && (p_node->storage_class != SpvStorageClassStorageBuffer) && + (p_node->storage_class != SpvStorageClassUniformConstant))) { continue; } if ((p_node->decorations.set.value == INVALID_VALUE) || (p_node->decorations.binding.value == INVALID_VALUE)) { @@ -2221,7 +1994,6 @@ static SpvReflectResult ParseDescriptorBindings( // Count - p_descriptor->word_offset.binding = p_node->decorations.binding.word_offset; p_descriptor->word_offset.set = p_node->decorations.set.word_offset; @@ -2229,17 +2001,14 @@ static SpvReflectResult ParseDescriptorBindings( } if (p_module->descriptor_binding_count > 0) { - qsort(p_module->descriptor_bindings, - p_module->descriptor_binding_count, - sizeof(*(p_module->descriptor_bindings)), + qsort(p_module->descriptor_bindings, p_module->descriptor_binding_count, sizeof(*(p_module->descriptor_bindings)), SortCompareDescriptorBinding); } return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDescriptorType(SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseDescriptorType(SpvReflectShaderModule* p_module) { if (p_module->descriptor_binding_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -2250,90 +2019,122 @@ static SpvReflectResult ParseDescriptorType(SpvReflectShaderModule* p_module) if ((int)p_descriptor->descriptor_type == (int)INVALID_VALUE) { switch (p_type->type_flags & SPV_REFLECT_TYPE_FLAG_EXTERNAL_MASK) { - default: assert(false && "unknown type flag"); break; + default: + assert(false && "unknown type flag"); + break; case SPV_REFLECT_TYPE_FLAG_EXTERNAL_IMAGE: { if (p_descriptor->image.dim == SpvDimBuffer) { switch (p_descriptor->image.sampled) { - default: assert(false && "unknown texel buffer sampled value"); break; - case IMAGE_SAMPLED: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; break; - case IMAGE_STORAGE: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; break; + default: + assert(false && "unknown texel buffer sampled value"); + break; + case IMAGE_SAMPLED: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; + break; + case IMAGE_STORAGE: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; + break; } - } - else if(p_descriptor->image.dim == SpvDimSubpassData) { + } else if (p_descriptor->image.dim == SpvDimSubpassData) { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; - } - else { + } else { switch (p_descriptor->image.sampled) { - default: assert(false && "unknown image sampled value"); break; - case IMAGE_SAMPLED: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE; break; - case IMAGE_STORAGE: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE; break; + default: + assert(false && "unknown image sampled value"); + break; + case IMAGE_SAMPLED: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + break; + case IMAGE_STORAGE: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE; + break; } } - } - break; + } break; case SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLER: { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER; - } - break; + } break; case (SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLED_IMAGE | SPV_REFLECT_TYPE_FLAG_EXTERNAL_IMAGE): { // This is a workaround for: https://github.com/KhronosGroup/glslang/issues/1096 if (p_descriptor->image.dim == SpvDimBuffer) { switch (p_descriptor->image.sampled) { - default: assert(false && "unknown texel buffer sampled value"); break; - case IMAGE_SAMPLED: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; break; - case IMAGE_STORAGE: p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; break; + default: + assert(false && "unknown texel buffer sampled value"); + break; + case IMAGE_SAMPLED: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; + break; + case IMAGE_STORAGE: + p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; + break; } - } - else { + } else { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; } - } - break; + } break; case SPV_REFLECT_TYPE_FLAG_EXTERNAL_BLOCK: { if (p_type->decoration_flags & SPV_REFLECT_DECORATION_BLOCK) { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - } - else if (p_type->decoration_flags & SPV_REFLECT_DECORATION_BUFFER_BLOCK) { + } else if (p_type->decoration_flags & SPV_REFLECT_DECORATION_BUFFER_BLOCK) { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER; - } - else { + } else { assert(false && "unknown struct"); } - } - break; + } break; case SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE: { p_descriptor->descriptor_type = SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR; - } - break; + } break; } } switch (p_descriptor->descriptor_type) { - case SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SAMPLER; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : p_descriptor->resource_type = (SpvReflectResourceType)(SPV_REFLECT_RESOURCE_FLAG_SAMPLER | SPV_REFLECT_RESOURCE_FLAG_SRV); break; - case SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_CBV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_CBV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; break; - case SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT : break; - case SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR : p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; break; + case SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SAMPLER; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: + p_descriptor->resource_type = (SpvReflectResourceType)(SPV_REFLECT_RESOURCE_FLAG_SAMPLER | SPV_REFLECT_RESOURCE_FLAG_SRV); + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_CBV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_CBV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_UAV; + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: + break; + case SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: + p_descriptor->resource_type = SPV_REFLECT_RESOURCE_FLAG_SRV; + break; } } return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module) { char name[MAX_NODE_NAME_LENGTH]; const char* k_count_tag = "@count"; @@ -2347,7 +2148,8 @@ static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module SpvReflectDescriptorBinding* p_counter_descriptor = NULL; // Use UAV counter buffer id if present... if (p_descriptor->uav_counter_id != UINT32_MAX) { - for (uint32_t counter_descriptor_index = 0; counter_descriptor_index < p_module->descriptor_binding_count; ++counter_descriptor_index) { + for (uint32_t counter_descriptor_index = 0; counter_descriptor_index < p_module->descriptor_binding_count; + ++counter_descriptor_index) { SpvReflectDescriptorBinding* p_test_counter_descriptor = &(p_module->descriptor_bindings[counter_descriptor_index]); if (p_test_counter_descriptor->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) { continue; @@ -2360,7 +2162,7 @@ static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module } // ...otherwise use old @count convention. else { - const size_t descriptor_name_length = p_descriptor->name? strlen(p_descriptor->name): 0; + const size_t descriptor_name_length = p_descriptor->name ? strlen(p_descriptor->name) : 0; memset(name, 0, MAX_NODE_NAME_LENGTH); memcpy(name, p_descriptor->name, descriptor_name_length); @@ -2370,7 +2172,8 @@ static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module strcat(name, k_count_tag); #endif - for (uint32_t counter_descriptor_index = 0; counter_descriptor_index < p_module->descriptor_binding_count; ++counter_descriptor_index) { + for (uint32_t counter_descriptor_index = 0; counter_descriptor_index < p_module->descriptor_binding_count; + ++counter_descriptor_index) { SpvReflectDescriptorBinding* p_test_counter_descriptor = &(p_module->descriptor_bindings[counter_descriptor_index]); if (p_test_counter_descriptor->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) { continue; @@ -2390,13 +2193,8 @@ static SpvReflectResult ParseUAVCounterBindings(SpvReflectShaderModule* p_module return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDescriptorBlockVariable( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module, - SpvReflectTypeDescription* p_type, - SpvReflectBlockVariable* p_var -) -{ +static SpvReflectResult ParseDescriptorBlockVariable(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module, + SpvReflectTypeDescription* p_type, SpvReflectBlockVariable* p_var) { bool has_non_writable = false; if (IsNotNull(p_type->members) && (p_type->member_count > 0)) { @@ -2414,8 +2212,7 @@ static SpvReflectResult ParseDescriptorBlockVariable( while (p_type_node->op == SpvOpTypeArray || p_type_node->op == SpvOpTypeRuntimeArray) { if (p_type_node->op == SpvOpTypeArray) { p_type_node = FindNode(p_parser, p_type_node->array_traits.element_type_id); - } - else { + } else { // Element type description SpvReflectTypeDescription* p_type_temp = FindType(p_module, p_type_node->array_traits.element_type_id); if (IsNull(p_type_temp)) { @@ -2438,8 +2235,7 @@ static SpvReflectResult ParseDescriptorBlockVariable( bool found_recursion = false; if (p_member_type->op == SpvOpTypePointer) { - if (p_member_type->storage_class == - SpvStorageClassPhysicalStorageBuffer) { + if (p_member_type->storage_class == SpvStorageClassPhysicalStorageBuffer) { // Need to make sure we haven't started an infinite recursive loop for (uint32_t i = 0; i < p_parser->physical_pointer_count; i++) { if (p_member_type->id == p_parser->physical_pointer_check[i]) { @@ -2448,11 +2244,9 @@ static SpvReflectResult ParseDescriptorBlockVariable( } } if (!found_recursion) { - p_parser->physical_pointer_check[p_parser->physical_pointer_count] = - p_member_type->id; + p_parser->physical_pointer_check[p_parser->physical_pointer_count] = p_member_type->id; p_parser->physical_pointer_count++; - if (p_parser->physical_pointer_count >= - MAX_RECURSIVE_PHYSICAL_POINTER_CHECK) { + if (p_parser->physical_pointer_count >= MAX_RECURSIVE_PHYSICAL_POINTER_CHECK) { return SPV_REFLECT_RESULT_ERROR_SPIRV_MAX_RECURSIVE_EXCEEDED; } } @@ -2460,8 +2254,7 @@ static SpvReflectResult ParseDescriptorBlockVariable( // Remember the original type p_member_ptr_type = p_member_type; - SpvReflectPrvNode* p_member_type_node = - FindNode(p_parser, p_member_type->id); + SpvReflectPrvNode* p_member_type_node = FindNode(p_parser, p_member_type->id); if (IsNull(p_member_type_node)) { return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; } @@ -2479,8 +2272,7 @@ static SpvReflectResult ParseDescriptorBlockVariable( } } - if (p_type_node->storage_class == SpvStorageClassPhysicalStorageBuffer && - !p_type_node->member_names) { + if (p_type_node->storage_class == SpvStorageClassPhysicalStorageBuffer && !p_type_node->member_names) { // TODO 212 - If a buffer ref has an array of itself, all members are null continue; } @@ -2498,8 +2290,7 @@ static SpvReflectResult ParseDescriptorBlockVariable( } p_member_var->word_offset.offset = p_type_node->member_decorations[member_index].offset.word_offset; - p_member_var->type_description = - p_member_ptr_type ? p_member_ptr_type : p_member_type; + p_member_var->type_description = p_member_ptr_type ? p_member_ptr_type : p_member_type; } } @@ -2512,15 +2303,9 @@ static SpvReflectResult ParseDescriptorBlockVariable( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDescriptorBlockVariableSizes( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module, - bool is_parent_root, - bool is_parent_aos, - bool is_parent_rta, - SpvReflectBlockVariable* p_var -) -{ +static SpvReflectResult ParseDescriptorBlockVariableSizes(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module, + bool is_parent_root, bool is_parent_aos, bool is_parent_rta, + SpvReflectBlockVariable* p_var) { if (p_var->member_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -2534,10 +2319,7 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( p_member_var->absolute_offset = p_member_var->offset; } else { p_member_var->absolute_offset = - is_parent_aos - ? 0 - : (is_parent_ref ? p_member_var->offset - : p_member_var->offset + p_var->absolute_offset); + is_parent_aos ? 0 : (is_parent_ref ? p_member_var->offset : p_member_var->offset + p_var->absolute_offset); } } @@ -2553,31 +2335,26 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( switch (p_member_type->op) { case SpvOpTypeBool: { p_member_var->size = SPIRV_WORD_SIZE; - } - break; + } break; case SpvOpTypeInt: case SpvOpTypeFloat: { p_member_var->size = p_member_type->traits.numeric.scalar.width / SPIRV_BYTE_WIDTH; - } - break; + } break; case SpvOpTypeVector: { - uint32_t size = p_member_type->traits.numeric.vector.component_count * - (p_member_type->traits.numeric.scalar.width / SPIRV_BYTE_WIDTH); + uint32_t size = + p_member_type->traits.numeric.vector.component_count * (p_member_type->traits.numeric.scalar.width / SPIRV_BYTE_WIDTH); p_member_var->size = size; - } - break; + } break; case SpvOpTypeMatrix: { if (p_member_var->decoration_flags & SPV_REFLECT_DECORATION_COLUMN_MAJOR) { p_member_var->size = p_member_var->numeric.matrix.column_count * p_member_var->numeric.matrix.stride; - } - else if (p_member_var->decoration_flags & SPV_REFLECT_DECORATION_ROW_MAJOR) { + } else if (p_member_var->decoration_flags & SPV_REFLECT_DECORATION_ROW_MAJOR) { p_member_var->size = p_member_var->numeric.matrix.row_count * p_member_var->numeric.matrix.stride; } - } - break; + } break; case SpvOpTypeArray: { // If array of structs, parse members first... @@ -2594,8 +2371,7 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( element_count *= p_member_var->array.dims[i]; } p_member_var->size = element_count * p_member_var->array.stride; - } - break; + } break; case SpvOpTypeRuntimeArray: { bool is_struct = (p_member_type->type_flags & SPV_REFLECT_TYPE_FLAG_STRUCT) == SPV_REFLECT_TYPE_FLAG_STRUCT; @@ -2605,8 +2381,7 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( return result; } } - } - break; + } break; case SpvOpTypePointer: { // Reference. Get to underlying struct type. @@ -2624,12 +2399,12 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( } case SpvOpTypeStruct: { - SpvReflectResult result = ParseDescriptorBlockVariableSizes(p_parser, p_module, false, is_parent_aos, is_parent_rta, p_member_var); + SpvReflectResult result = + ParseDescriptorBlockVariableSizes(p_parser, p_module, false, is_parent_aos, is_parent_rta, p_member_var); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } - } - break; + } break; default: break; @@ -2652,7 +2427,7 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( // subtract the offset. if (p_var->member_count > 0) { SpvReflectBlockVariable* p_member_var = &p_var->members[p_var->member_count - 1]; - p_member_var->padded_size = RoundUp(p_member_var->offset + p_member_var->size, SPIRV_DATA_ALIGNMENT) - p_member_var->offset; + p_member_var->padded_size = RoundUp(p_member_var->offset + p_member_var->size, SPIRV_DATA_ALIGNMENT) - p_member_var->offset; if (p_member_var->size > p_member_var->padded_size) { p_member_var->size = p_member_var->padded_size; } @@ -2668,45 +2443,36 @@ static SpvReflectResult ParseDescriptorBlockVariableSizes( } // @TODO validate this with assertion - p_var->size = p_var->members[p_var->member_count - 1].offset + - p_var->members[p_var->member_count - 1].padded_size; + p_var->size = p_var->members[p_var->member_count - 1].offset + p_var->members[p_var->member_count - 1].padded_size; p_var->padded_size = p_var->size; return SPV_REFLECT_RESULT_SUCCESS; } -static void MarkSelfAndAllMemberVarsAsUsed(SpvReflectBlockVariable* p_var) -{ +static void MarkSelfAndAllMemberVarsAsUsed(SpvReflectBlockVariable* p_var) { // Clear the current variable's UNUSED flag p_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED; SpvOp op_type = p_var->type_description->op; switch (op_type) { - default: break; + default: + break; case SpvOpTypeArray: { - } - break; + } 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; + } break; } } -static SpvReflectResult ParseDescriptorBlockVariableUsage( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module, - SpvReflectPrvAccessChain* p_access_chain, - uint32_t index_index, - SpvOp override_op_type, - SpvReflectBlockVariable* p_var -) -{ +static SpvReflectResult ParseDescriptorBlockVariableUsage(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module, + SpvReflectPrvAccessChain* p_access_chain, uint32_t index_index, + SpvOp override_op_type, SpvReflectBlockVariable* p_var) { // Clear the current variable's UNUSED flag p_var->flags &= ~SPV_REFLECT_VARIABLE_FLAGS_UNUSED; @@ -2719,7 +2485,8 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage( } switch (op_type) { - default: break; + default: + break; case SpvOpTypeArray: { // Parse through array's type hierarchy to find the actual/non-array element type @@ -2748,13 +2515,8 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage( // 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, - p_type->op, - p_var); + 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; } @@ -2762,8 +2524,7 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage( // Clear UNUSED flag for remaining variables MarkSelfAndAllMemberVarsAsUsed(p_var); } - } - break; + } break; case SpvOpTypePointer: { // Reference. Get to underlying struct type. @@ -2811,35 +2572,25 @@ static SpvReflectResult ParseDescriptorBlockVariableUsage( // See: https://github.com/KhronosGroup/SPIRV-Reflect/issues/78 // if (index_index < p_access_chain->index_count) { - SpvReflectResult result = ParseDescriptorBlockVariableUsage( - p_parser, - p_module, - p_access_chain, - index_index, - (SpvOp)INVALID_VALUE, - p_member_var); - if (result != SPV_REFLECT_RESULT_SUCCESS) { - return result; - } - } - else if (IsPointerToPointer(p_parser, p_access_chain->result_type_id)) { + SpvReflectResult result = + ParseDescriptorBlockVariableUsage(p_parser, p_module, p_access_chain, index_index, (SpvOp)INVALID_VALUE, p_member_var); + if (result != SPV_REFLECT_RESULT_SUCCESS) { + return result; + } + } else if (IsPointerToPointer(p_parser, p_access_chain->result_type_id)) { // Remember block var for this access chain for downstream dereference p_access_chain->block_var = p_member_var; } else { // Clear UNUSED flag for remaining variables MarkSelfAndAllMemberVarsAsUsed(p_member_var); } - } - break; + } break; } return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDescriptorBlocks( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseDescriptorBlocks(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { if (p_module->descriptor_binding_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -2848,8 +2599,7 @@ static SpvReflectResult ParseDescriptorBlocks( SpvReflectDescriptorBinding* p_descriptor = &(p_module->descriptor_bindings[descriptor_index]); SpvReflectTypeDescription* p_type = p_descriptor->type_description; if ((p_descriptor->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER) && - (p_descriptor->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) ) - { + (p_descriptor->descriptor_type != SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER)) { continue; } @@ -2868,13 +2618,7 @@ static SpvReflectResult ParseDescriptorBlocks( if (p_descriptor->spirv_id != p_access_chain->base_id) { continue; } - result = ParseDescriptorBlockVariableUsage( - p_parser, - p_module, - p_access_chain, - 0, - (SpvOp)INVALID_VALUE, - &p_descriptor->block); + result = ParseDescriptorBlockVariableUsage(p_parser, p_module, p_access_chain, 0, (SpvOp)INVALID_VALUE, &p_descriptor->block); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -2897,11 +2641,7 @@ static SpvReflectResult ParseDescriptorBlocks( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseFormat( - const SpvReflectTypeDescription* p_type, - SpvReflectFormat* p_format -) -{ +static SpvReflectResult ParseFormat(const SpvReflectTypeDescription* p_type, SpvReflectFormat* p_format) { SpvReflectResult result = SPV_REFLECT_RESULT_ERROR_INTERNAL_ERROR; bool signedness = (p_type->traits.numeric.scalar.signedness != 0); uint32_t bit_width = p_type->traits.numeric.scalar.width; @@ -2911,65 +2651,95 @@ static SpvReflectResult ParseFormat( switch (bit_width) { case 16: { switch (component_count) { - case 2: *p_format = SPV_REFLECT_FORMAT_R16G16_SFLOAT; break; - case 3: *p_format = SPV_REFLECT_FORMAT_R16G16B16_SFLOAT; break; - case 4: *p_format = SPV_REFLECT_FORMAT_R16G16B16A16_SFLOAT; break; + case 2: + *p_format = SPV_REFLECT_FORMAT_R16G16_SFLOAT; + break; + case 3: + *p_format = SPV_REFLECT_FORMAT_R16G16B16_SFLOAT; + break; + case 4: + *p_format = SPV_REFLECT_FORMAT_R16G16B16A16_SFLOAT; + break; } - } - break; + } break; case 32: { switch (component_count) { - case 2: *p_format = SPV_REFLECT_FORMAT_R32G32_SFLOAT; break; - case 3: *p_format = SPV_REFLECT_FORMAT_R32G32B32_SFLOAT; break; - case 4: *p_format = SPV_REFLECT_FORMAT_R32G32B32A32_SFLOAT; break; + case 2: + *p_format = SPV_REFLECT_FORMAT_R32G32_SFLOAT; + break; + case 3: + *p_format = SPV_REFLECT_FORMAT_R32G32B32_SFLOAT; + break; + case 4: + *p_format = SPV_REFLECT_FORMAT_R32G32B32A32_SFLOAT; + break; } - } - break; + } break; case 64: { switch (component_count) { - case 2: *p_format = SPV_REFLECT_FORMAT_R64G64_SFLOAT; break; - case 3: *p_format = SPV_REFLECT_FORMAT_R64G64B64_SFLOAT; break; - case 4: *p_format = SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT; break; + case 2: + *p_format = SPV_REFLECT_FORMAT_R64G64_SFLOAT; + break; + case 3: + *p_format = SPV_REFLECT_FORMAT_R64G64B64_SFLOAT; + break; + case 4: + *p_format = SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT; + break; } } } result = SPV_REFLECT_RESULT_SUCCESS; - } - else if (p_type->type_flags & (SPV_REFLECT_TYPE_FLAG_INT | SPV_REFLECT_TYPE_FLAG_BOOL)) { + } else if (p_type->type_flags & (SPV_REFLECT_TYPE_FLAG_INT | SPV_REFLECT_TYPE_FLAG_BOOL)) { switch (bit_width) { case 16: { switch (component_count) { - case 2: *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16_SINT : SPV_REFLECT_FORMAT_R16G16_UINT; break; - case 3: *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16B16_SINT : SPV_REFLECT_FORMAT_R16G16B16_UINT; break; - case 4: *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16B16A16_SINT : SPV_REFLECT_FORMAT_R16G16B16A16_UINT; break; + case 2: + *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16_SINT : SPV_REFLECT_FORMAT_R16G16_UINT; + break; + case 3: + *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16B16_SINT : SPV_REFLECT_FORMAT_R16G16B16_UINT; + break; + case 4: + *p_format = signedness ? SPV_REFLECT_FORMAT_R16G16B16A16_SINT : SPV_REFLECT_FORMAT_R16G16B16A16_UINT; + break; } - } - break; + } break; case 32: { switch (component_count) { - case 2: *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32_SINT : SPV_REFLECT_FORMAT_R32G32_UINT; break; - case 3: *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32B32_SINT : SPV_REFLECT_FORMAT_R32G32B32_UINT; break; - case 4: *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32B32A32_SINT : SPV_REFLECT_FORMAT_R32G32B32A32_UINT; break; + case 2: + *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32_SINT : SPV_REFLECT_FORMAT_R32G32_UINT; + break; + case 3: + *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32B32_SINT : SPV_REFLECT_FORMAT_R32G32B32_UINT; + break; + case 4: + *p_format = signedness ? SPV_REFLECT_FORMAT_R32G32B32A32_SINT : SPV_REFLECT_FORMAT_R32G32B32A32_UINT; + break; } - } - break; + } break; case 64: { switch (component_count) { - case 2: *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64_SINT : SPV_REFLECT_FORMAT_R64G64_UINT; break; - case 3: *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64B64_SINT : SPV_REFLECT_FORMAT_R64G64B64_UINT; break; - case 4: *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64B64A64_SINT : SPV_REFLECT_FORMAT_R64G64B64A64_UINT; break; + case 2: + *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64_SINT : SPV_REFLECT_FORMAT_R64G64_UINT; + break; + case 3: + *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64B64_SINT : SPV_REFLECT_FORMAT_R64G64B64_UINT; + break; + case 4: + *p_format = signedness ? SPV_REFLECT_FORMAT_R64G64B64A64_SINT : SPV_REFLECT_FORMAT_R64G64B64A64_UINT; + break; } } } result = SPV_REFLECT_RESULT_SUCCESS; } - } - else if (p_type->type_flags & SPV_REFLECT_TYPE_FLAG_FLOAT) { - switch(bit_width) { + } else if (p_type->type_flags & SPV_REFLECT_TYPE_FLAG_FLOAT) { + switch (bit_width) { case 16: *p_format = SPV_REFLECT_FORMAT_R16_SFLOAT; break; @@ -2981,37 +2751,33 @@ static SpvReflectResult ParseFormat( break; } result = SPV_REFLECT_RESULT_SUCCESS; - } - else if (p_type->type_flags & (SPV_REFLECT_TYPE_FLAG_INT | SPV_REFLECT_TYPE_FLAG_BOOL)) { - switch(bit_width) { + } else if (p_type->type_flags & (SPV_REFLECT_TYPE_FLAG_INT | SPV_REFLECT_TYPE_FLAG_BOOL)) { + switch (bit_width) { case 16: - *p_format = signedness ? SPV_REFLECT_FORMAT_R16_SINT : SPV_REFLECT_FORMAT_R16_UINT; break; + *p_format = signedness ? SPV_REFLECT_FORMAT_R16_SINT : SPV_REFLECT_FORMAT_R16_UINT; + break; break; case 32: - *p_format = signedness ? SPV_REFLECT_FORMAT_R32_SINT : SPV_REFLECT_FORMAT_R32_UINT; break; + *p_format = signedness ? SPV_REFLECT_FORMAT_R32_SINT : SPV_REFLECT_FORMAT_R32_UINT; + break; break; case 64: - *p_format = signedness ? SPV_REFLECT_FORMAT_R64_SINT : SPV_REFLECT_FORMAT_R64_UINT; break; + *p_format = signedness ? SPV_REFLECT_FORMAT_R64_SINT : SPV_REFLECT_FORMAT_R64_UINT; + break; } result = SPV_REFLECT_RESULT_SUCCESS; - } - else if (p_type->type_flags & SPV_REFLECT_TYPE_FLAG_STRUCT) { + } else if (p_type->type_flags & SPV_REFLECT_TYPE_FLAG_STRUCT) { *p_format = SPV_REFLECT_FORMAT_UNDEFINED; result = SPV_REFLECT_RESULT_SUCCESS; } return result; } -static SpvReflectResult ParseInterfaceVariable( - SpvReflectPrvParser* p_parser, - const SpvReflectPrvDecorations* p_var_node_decorations, - const SpvReflectPrvDecorations* p_type_node_decorations, - SpvReflectShaderModule* p_module, - SpvReflectTypeDescription* p_type, - SpvReflectInterfaceVariable* p_var, - bool* p_has_built_in -) -{ +static SpvReflectResult ParseInterfaceVariable(SpvReflectPrvParser* p_parser, + const SpvReflectPrvDecorations* p_var_node_decorations, + const SpvReflectPrvDecorations* p_type_node_decorations, + SpvReflectShaderModule* p_module, SpvReflectTypeDescription* p_type, + SpvReflectInterfaceVariable* p_var, bool* p_has_built_in) { SpvReflectPrvNode* p_type_node = FindNode(p_parser, p_type->id); if (IsNull(p_type_node)) { return SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE; @@ -3032,7 +2798,8 @@ static SpvReflectResult ParseInterfaceVariable( // Storage class is the same throughout the whole struct p_member_var->storage_class = p_var->storage_class; - SpvReflectResult result = ParseInterfaceVariable(p_parser, NULL, p_member_decorations, p_module, p_member_type, p_member_var, p_has_built_in); + SpvReflectResult result = + ParseInterfaceVariable(p_parser, NULL, p_member_decorations, p_module, p_member_type, p_member_var, p_has_built_in); if (result != SPV_REFLECT_RESULT_SUCCESS) { SPV_REFLECT_ASSERT(false); return result; @@ -3072,14 +2839,9 @@ static SpvReflectResult ParseInterfaceVariable( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseInterfaceVariables( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module, - SpvReflectEntryPoint* p_entry, - uint32_t interface_variable_count, - uint32_t* p_interface_variable_ids -) -{ +static SpvReflectResult ParseInterfaceVariables(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module, + SpvReflectEntryPoint* p_entry, uint32_t interface_variable_count, + uint32_t* p_interface_variable_ids) { if (interface_variable_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -3096,28 +2858,30 @@ static SpvReflectResult ParseInterfaceVariables( if (p_node->storage_class == SpvStorageClassInput) { p_entry->input_variable_count += 1; - } - else if (p_node->storage_class == SpvStorageClassOutput) { + } else if (p_node->storage_class == SpvStorageClassOutput) { p_entry->output_variable_count += 1; } - } + } - if (p_entry->input_variable_count > 0) { - p_entry->input_variables = (SpvReflectInterfaceVariable**)calloc(p_entry->input_variable_count, sizeof(*(p_entry->input_variables))); - if (IsNull(p_entry->input_variables)) { - return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; - } - } + if (p_entry->input_variable_count > 0) { + p_entry->input_variables = + (SpvReflectInterfaceVariable**)calloc(p_entry->input_variable_count, sizeof(*(p_entry->input_variables))); + if (IsNull(p_entry->input_variables)) { + return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; + } + } - if (p_entry->output_variable_count > 0) { - p_entry->output_variables = (SpvReflectInterfaceVariable**)calloc(p_entry->output_variable_count, sizeof(*(p_entry->output_variables))); - if (IsNull(p_entry->output_variables)) { - return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; - } - } + if (p_entry->output_variable_count > 0) { + p_entry->output_variables = + (SpvReflectInterfaceVariable**)calloc(p_entry->output_variable_count, sizeof(*(p_entry->output_variables))); + if (IsNull(p_entry->output_variables)) { + return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; + } + } if (p_entry->interface_variable_count > 0) { - p_entry->interface_variables = (SpvReflectInterfaceVariable*)calloc(p_entry->interface_variable_count, sizeof(*(p_entry->interface_variables))); + p_entry->interface_variables = + (SpvReflectInterfaceVariable*)calloc(p_entry->interface_variable_count, sizeof(*(p_entry->interface_variables))); if (IsNull(p_entry->interface_variables)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -3156,17 +2920,11 @@ static SpvReflectResult ParseInterfaceVariables( } SpvReflectInterfaceVariable* p_var = &(p_entry->interface_variables[i]); - p_var->storage_class = p_node->storage_class; + p_var->storage_class = p_node->storage_class; bool has_built_in = p_node->decorations.is_built_in; - SpvReflectResult result = ParseInterfaceVariable( - p_parser, - &p_node->decorations, - &p_type_node->decorations, - p_module, - p_type, - p_var, - &has_built_in); + SpvReflectResult result = + ParseInterfaceVariable(p_parser, &p_node->decorations, &p_type_node->decorations, p_module, p_type, p_var, &has_built_in); if (result != SPV_REFLECT_RESULT_SUCCESS) { SPV_REFLECT_ASSERT(false); return result; @@ -3175,9 +2933,8 @@ static SpvReflectResult ParseInterfaceVariables( // Input and output variables if (p_var->storage_class == SpvStorageClassInput) { p_entry->input_variables[input_index] = p_var; - ++input_index; - } - else if (p_node->storage_class == SpvStorageClassOutput) { + ++input_index; + } else if (p_node->storage_class == SpvStorageClassOutput) { p_entry->output_variables[output_index] = p_var; ++output_index; } @@ -3208,12 +2965,8 @@ static SpvReflectResult ParseInterfaceVariables( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult EnumerateAllPushConstants( - SpvReflectShaderModule* p_module, - size_t* p_push_constant_count, - uint32_t** p_push_constants -) -{ +static SpvReflectResult EnumerateAllPushConstants(SpvReflectShaderModule* p_module, size_t* p_push_constant_count, + uint32_t** p_push_constants) { *p_push_constant_count = p_module->push_constant_block_count; if (*p_push_constant_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; @@ -3227,19 +2980,12 @@ static SpvReflectResult EnumerateAllPushConstants( for (size_t i = 0; i < *p_push_constant_count; ++i) { (*p_push_constants)[i] = p_module->push_constant_blocks[i].spirv_id; } - qsort(*p_push_constants, *p_push_constant_count, sizeof(**p_push_constants), - SortCompareUint32); + qsort(*p_push_constants, *p_push_constant_count, sizeof(**p_push_constants), SortCompareUint32); return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult TraverseCallGraph( - SpvReflectPrvParser* p_parser, - SpvReflectPrvFunction* p_func, - size_t* p_func_count, - uint32_t* p_func_ids, - uint32_t depth -) -{ +static SpvReflectResult TraverseCallGraph(SpvReflectPrvParser* p_parser, SpvReflectPrvFunction* p_func, size_t* p_func_count, + uint32_t* p_func_ids, uint32_t depth) { if (depth > p_parser->function_count) { // Vulkan does not permit recursion (Vulkan spec Appendix A): // "Recursion: The static function-call graph for an entry point must not @@ -3252,8 +2998,7 @@ static SpvReflectResult TraverseCallGraph( ++*p_func_count; } for (size_t i = 0; i < p_func->callee_count; ++i) { - SpvReflectResult result = TraverseCallGraph( - p_parser, p_func->callee_ptrs[i], p_func_count, p_func_ids, depth + 1); + SpvReflectResult result = TraverseCallGraph(p_parser, p_func->callee_ptrs[i], p_func_count, p_func_ids, depth + 1); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3261,16 +3006,9 @@ static SpvReflectResult TraverseCallGraph( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseStaticallyUsedResources( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module, - SpvReflectEntryPoint* p_entry, - size_t uniform_count, - uint32_t* uniforms, - size_t push_constant_count, - uint32_t* push_constants -) -{ +static SpvReflectResult ParseStaticallyUsedResources(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module, + SpvReflectEntryPoint* p_entry, size_t uniform_count, uint32_t* uniforms, + size_t push_constant_count, uint32_t* push_constants) { // Find function with the right id SpvReflectPrvFunction* p_func = NULL; for (size_t i = 0; i < p_parser->function_count; ++i) { @@ -3284,12 +3022,7 @@ static SpvReflectResult ParseStaticallyUsedResources( } size_t called_function_count = 0; - SpvReflectResult result = TraverseCallGraph( - p_parser, - p_func, - &called_function_count, - NULL, - 0); + SpvReflectResult result = TraverseCallGraph(p_parser, p_func, &called_function_count, NULL, 0); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3303,22 +3036,13 @@ static SpvReflectResult ParseStaticallyUsedResources( } called_function_count = 0; - result = TraverseCallGraph( - p_parser, - p_func, - &called_function_count, - p_called_functions, - 0); + result = TraverseCallGraph(p_parser, p_func, &called_function_count, p_called_functions, 0); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } if (called_function_count > 0) { - qsort( - p_called_functions, - called_function_count, - sizeof(*p_called_functions), - SortCompareUint32); + qsort(p_called_functions, called_function_count, sizeof(*p_called_functions), SortCompareUint32); } called_function_count = DedupSortedUint32(p_called_functions, called_function_count); @@ -3333,8 +3057,7 @@ static SpvReflectResult ParseStaticallyUsedResources( } uint32_t* used_variables = NULL; if (used_variable_count > 0) { - used_variables = (uint32_t*)calloc(used_variable_count, - sizeof(*used_variables)); + used_variables = (uint32_t*)calloc(used_variable_count, sizeof(*used_variables)); if (IsNull(used_variables)) { SafeFree(p_called_functions); return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; @@ -3346,47 +3069,31 @@ static SpvReflectResult ParseStaticallyUsedResources( ++j; } - memcpy(&used_variables[used_variable_count], - p_parser->functions[j].accessed_ptrs, + memcpy(&used_variables[used_variable_count], p_parser->functions[j].accessed_ptrs, p_parser->functions[j].accessed_ptr_count * sizeof(*used_variables)); used_variable_count += p_parser->functions[j].accessed_ptr_count; } SafeFree(p_called_functions); if (used_variable_count > 0) { - qsort(used_variables, used_variable_count, sizeof(*used_variables), - SortCompareUint32); + qsort(used_variables, used_variable_count, sizeof(*used_variables), SortCompareUint32); } - used_variable_count = (uint32_t)DedupSortedUint32(used_variables, - used_variable_count); + used_variable_count = (uint32_t)DedupSortedUint32(used_variables, used_variable_count); // Do set intersection to find the used uniform and push constants size_t used_uniform_count = 0; // - SpvReflectResult result0 = IntersectSortedUint32( - used_variables, - used_variable_count, - uniforms, - uniform_count, - &p_entry->used_uniforms, - &used_uniform_count); + SpvReflectResult result0 = IntersectSortedUint32(used_variables, used_variable_count, uniforms, uniform_count, + &p_entry->used_uniforms, &used_uniform_count); size_t used_push_constant_count = 0; // - SpvReflectResult result1 = IntersectSortedUint32( - used_variables, - used_variable_count, - push_constants, - push_constant_count, - &p_entry->used_push_constants, - &used_push_constant_count); + SpvReflectResult result1 = IntersectSortedUint32(used_variables, used_variable_count, push_constants, push_constant_count, + &p_entry->used_push_constants, &used_push_constant_count); for (uint32_t j = 0; j < p_module->descriptor_binding_count; ++j) { SpvReflectDescriptorBinding* p_binding = &p_module->descriptor_bindings[j]; - bool found = SearchSortedUint32( - used_variables, - used_variable_count, - p_binding->spirv_id); + bool found = SearchSortedUint32(used_variables, used_variable_count, p_binding->spirv_id); if (found) { p_binding->accessed = 1; } @@ -3406,17 +3113,13 @@ static SpvReflectResult ParseStaticallyUsedResources( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseEntryPoints( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseEntryPoints(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { if (p_parser->entry_point_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } p_module->entry_point_count = p_parser->entry_point_count; - p_module->entry_points = (SpvReflectEntryPoint*)calloc(p_module->entry_point_count, - sizeof(*(p_module->entry_points))); + p_module->entry_points = (SpvReflectEntryPoint*)calloc(p_module->entry_point_count, sizeof(*(p_module->entry_points))); if (IsNull(p_module->entry_points)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -3424,14 +3127,12 @@ static SpvReflectResult ParseEntryPoints( SpvReflectResult result; size_t uniform_count = 0; uint32_t* uniforms = NULL; - if ((result = EnumerateAllUniforms(p_module, &uniform_count, &uniforms)) != - SPV_REFLECT_RESULT_SUCCESS) { + if ((result = EnumerateAllUniforms(p_module, &uniform_count, &uniforms)) != SPV_REFLECT_RESULT_SUCCESS) { return result; } size_t push_constant_count = 0; uint32_t* push_constants = NULL; - if ((result = EnumerateAllPushConstants(p_module, &push_constant_count, &push_constants)) != - SPV_REFLECT_RESULT_SUCCESS) { + if ((result = EnumerateAllPushConstants(p_module, &push_constant_count, &push_constants)) != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3447,23 +3148,56 @@ static SpvReflectResult ParseEntryPoints( CHECKED_READU32(p_parser, p_node->word_offset + 2, p_entry_point->id); switch (p_entry_point->spirv_execution_model) { - default: break; - case SpvExecutionModelVertex : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_VERTEX_BIT; break; - case SpvExecutionModelTessellationControl : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TESSELLATION_CONTROL_BIT; break; - case SpvExecutionModelTessellationEvaluation : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; break; - case SpvExecutionModelGeometry : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_GEOMETRY_BIT; break; - case SpvExecutionModelFragment : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_FRAGMENT_BIT; break; - case SpvExecutionModelGLCompute : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_COMPUTE_BIT; break; - case SpvExecutionModelTaskNV : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV; break; - case SpvExecutionModelTaskEXT : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TASK_BIT_EXT; break; - case SpvExecutionModelMeshNV : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV; break; - case SpvExecutionModelMeshEXT : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MESH_BIT_EXT; break; - case SpvExecutionModelRayGenerationKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_RAYGEN_BIT_KHR; break; - case SpvExecutionModelIntersectionKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_INTERSECTION_BIT_KHR; break; - case SpvExecutionModelAnyHitKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_ANY_HIT_BIT_KHR; break; - case SpvExecutionModelClosestHitKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_CLOSEST_HIT_BIT_KHR; break; - case SpvExecutionModelMissKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MISS_BIT_KHR; break; - case SpvExecutionModelCallableKHR : p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_CALLABLE_BIT_KHR; break; + default: + break; + case SpvExecutionModelVertex: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_VERTEX_BIT; + break; + case SpvExecutionModelTessellationControl: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + break; + case SpvExecutionModelTessellationEvaluation: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + break; + case SpvExecutionModelGeometry: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_GEOMETRY_BIT; + break; + case SpvExecutionModelFragment: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_FRAGMENT_BIT; + break; + case SpvExecutionModelGLCompute: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_COMPUTE_BIT; + break; + case SpvExecutionModelTaskNV: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV; + break; + case SpvExecutionModelTaskEXT: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_TASK_BIT_EXT; + break; + case SpvExecutionModelMeshNV: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV; + break; + case SpvExecutionModelMeshEXT: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MESH_BIT_EXT; + break; + case SpvExecutionModelRayGenerationKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_RAYGEN_BIT_KHR; + break; + case SpvExecutionModelIntersectionKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_INTERSECTION_BIT_KHR; + break; + case SpvExecutionModelAnyHitKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_ANY_HIT_BIT_KHR; + break; + case SpvExecutionModelClosestHitKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_CLOSEST_HIT_BIT_KHR; + break; + case SpvExecutionModelMissKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_MISS_BIT_KHR; + break; + case SpvExecutionModelCallableKHR: + p_entry_point->shader_stage = SPV_REFLECT_SHADER_STAGE_CALLABLE_BIT_KHR; + break; } ++entry_point_index; @@ -3471,7 +3205,8 @@ static SpvReflectResult ParseEntryPoints( // Name length is required to calculate next operand uint32_t name_start_word_offset = 3; uint32_t name_length_with_terminator = 0; - result = ReadStr(p_parser, p_node->word_offset + name_start_word_offset, 0, p_node->word_count, &name_length_with_terminator, NULL); + result = + ReadStr(p_parser, p_node->word_offset + name_start_word_offset, 0, p_node->word_count, &name_length_with_terminator, NULL); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3494,25 +3229,14 @@ static SpvReflectResult ParseEntryPoints( p_interface_variables[var_index] = var_result_id; } - result = ParseInterfaceVariables( - p_parser, - p_module, - p_entry_point, - interface_variable_count, - p_interface_variables); + result = ParseInterfaceVariables(p_parser, p_module, p_entry_point, interface_variable_count, p_interface_variables); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } SafeFree(p_interface_variables); - result = ParseStaticallyUsedResources( - p_parser, - p_module, - p_entry_point, - uniform_count, - uniforms, - push_constant_count, - push_constants); + result = ParseStaticallyUsedResources(p_parser, p_module, p_entry_point, uniform_count, uniforms, push_constant_count, + push_constants); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3524,10 +3248,7 @@ static SpvReflectResult ParseEntryPoints( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseExecutionModes( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseExecutionModes(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { assert(IsNotNull(p_parser)); assert(IsNotNull(p_parser->nodes)); assert(IsNotNull(p_module)); @@ -3535,8 +3256,7 @@ static SpvReflectResult ParseExecutionModes( if (IsNotNull(p_parser) && IsNotNull(p_parser->spirv_code) && IsNotNull(p_parser->nodes)) { for (size_t node_idx = 0; node_idx < p_parser->node_count; ++node_idx) { SpvReflectPrvNode* p_node = &(p_parser->nodes[node_idx]); - if (p_node->op != SpvOpExecutionMode && - p_node->op != SpvOpExecutionModeId) { + if (p_node->op != SpvOpExecutionMode && p_node->op != SpvOpExecutionModeId) { continue; } @@ -3565,15 +3285,13 @@ static SpvReflectResult ParseExecutionModes( switch (execution_mode) { case SpvExecutionModeInvocations: { CHECKED_READU32(p_parser, p_node->word_offset + 3, p_entry_point->invocations); - } - break; + } break; case SpvExecutionModeLocalSize: { CHECKED_READU32(p_parser, p_node->word_offset + 3, p_entry_point->local_size.x); CHECKED_READU32(p_parser, p_node->word_offset + 4, p_entry_point->local_size.y); CHECKED_READU32(p_parser, p_node->word_offset + 5, p_entry_point->local_size.z); - } - break; + } break; case SpvExecutionModeLocalSizeId: { uint32_t local_size_x_id = 0; uint32_t local_size_y_id = 0; @@ -3587,27 +3305,21 @@ static SpvReflectResult ParseExecutionModes( SpvReflectPrvNode* z_node = FindNode(p_parser, local_size_z_id); if (IsNotNull(x_node) && IsNotNull(y_node) && IsNotNull(z_node)) { if (IsSpecConstant(x_node)) { - p_entry_point->local_size.x = - (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; + p_entry_point->local_size.x = (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; } else { - CHECKED_READU32(p_parser, x_node->word_offset + 3, - p_entry_point->local_size.x); + CHECKED_READU32(p_parser, x_node->word_offset + 3, p_entry_point->local_size.x); } if (IsSpecConstant(y_node)) { - p_entry_point->local_size.y = - (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; + p_entry_point->local_size.y = (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; } else { - CHECKED_READU32(p_parser, y_node->word_offset + 3, - p_entry_point->local_size.y); + CHECKED_READU32(p_parser, y_node->word_offset + 3, p_entry_point->local_size.y); } if (IsSpecConstant(z_node)) { - p_entry_point->local_size.z = - (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; + p_entry_point->local_size.z = (uint32_t)SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT; } else { - CHECKED_READU32(p_parser, z_node->word_offset + 3, - p_entry_point->local_size.z); + CHECKED_READU32(p_parser, z_node->word_offset + 3, p_entry_point->local_size.z); } } } break; @@ -3621,8 +3333,7 @@ static SpvReflectResult ParseExecutionModes( case SpvExecutionModeIsolines: case SpvExecutionModeOutputVertices: { CHECKED_READU32(p_parser, p_node->word_offset + 3, p_entry_point->output_vertices); - } - break; + } break; default: break; @@ -3676,10 +3387,7 @@ static SpvReflectResult ParseExecutionModes( return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParsePushConstantBlocks( - SpvReflectPrvParser* p_parser, - SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParsePushConstantBlocks(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) { for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectPrvNode* p_node = &(p_parser->nodes[i]); if ((p_node->op != SpvOpVariable) || (p_node->storage_class != SpvStorageClassPushConstant)) { @@ -3693,7 +3401,8 @@ static SpvReflectResult ParsePushConstantBlocks( return SPV_REFLECT_RESULT_SUCCESS; } - p_module->push_constant_blocks = (SpvReflectBlockVariable*)calloc(p_module->push_constant_block_count, sizeof(*p_module->push_constant_blocks)); + p_module->push_constant_blocks = + (SpvReflectBlockVariable*)calloc(p_module->push_constant_block_count, sizeof(*p_module->push_constant_blocks)); if (IsNull(p_module->push_constant_blocks)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -3736,21 +3445,15 @@ static SpvReflectResult ParsePushConstantBlocks( return result; } - for (uint32_t access_chain_index = 0; - access_chain_index < p_parser->access_chain_count; - ++access_chain_index) { - SpvReflectPrvAccessChain* p_access_chain = - &(p_parser->access_chains[access_chain_index]); + for (uint32_t access_chain_index = 0; access_chain_index < p_parser->access_chain_count; ++access_chain_index) { + SpvReflectPrvAccessChain* p_access_chain = &(p_parser->access_chains[access_chain_index]); // Skip any access chains that aren't touching this push constant block if (p_push_constant->spirv_id != FindBaseId(p_parser, p_access_chain)) { continue; } SpvReflectBlockVariable* p_var = - (p_access_chain->base_id == p_push_constant->spirv_id) - ? p_push_constant - : GetRefBlkVar(p_parser, p_access_chain); - result = ParseDescriptorBlockVariableUsage( - p_parser, p_module, p_access_chain, 0, (SpvOp)INVALID_VALUE, p_var); + (p_access_chain->base_id == p_push_constant->spirv_id) ? p_push_constant : GetRefBlkVar(p_parser, p_access_chain); + result = ParseDescriptorBlockVariableUsage(p_parser, p_module, p_access_chain, 0, (SpvOp)INVALID_VALUE, p_var); if (result != SPV_REFLECT_RESULT_SUCCESS) { return result; } @@ -3776,8 +3479,7 @@ static SpvReflectResult ParsePushConstantBlocks( return SPV_REFLECT_RESULT_SUCCESS; } -static int SortCompareDescriptorSet(const void* a, const void* b) -{ +static int SortCompareDescriptorSet(const void* a, const void* b) { const SpvReflectDescriptorSet* p_elem_a = (const SpvReflectDescriptorSet*)a; const SpvReflectDescriptorSet* p_elem_b = (const SpvReflectDescriptorSet*)b; int value = (int)(p_elem_a->set) - (int)(p_elem_b->set); @@ -3799,10 +3501,7 @@ static SpvReflectResult ParseEntrypointDescriptorSets(SpvReflectShaderModule* p_ for (uint32_t j = 0; j < p_module->descriptor_set_count; ++j) { const SpvReflectDescriptorSet* p_set = &p_module->descriptor_sets[j]; for (uint32_t k = 0; k < p_set->binding_count; ++k) { - bool found = SearchSortedUint32( - p_entry->used_uniforms, - p_entry->used_uniform_count, - p_set->bindings[k]->spirv_id); + bool found = SearchSortedUint32(p_entry->used_uniforms, p_entry->used_uniform_count, p_set->bindings[k]->spirv_id); if (found) { ++p_entry->descriptor_set_count; break; @@ -3812,8 +3511,7 @@ static SpvReflectResult ParseEntrypointDescriptorSets(SpvReflectShaderModule* p_ p_entry->descriptor_sets = NULL; if (p_entry->descriptor_set_count > 0) { - p_entry->descriptor_sets = (SpvReflectDescriptorSet*)calloc(p_entry->descriptor_set_count, - sizeof(*p_entry->descriptor_sets)); + p_entry->descriptor_sets = (SpvReflectDescriptorSet*)calloc(p_entry->descriptor_set_count, sizeof(*p_entry->descriptor_sets)); if (IsNull(p_entry->descriptor_sets)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } @@ -3823,10 +3521,7 @@ static SpvReflectResult ParseEntrypointDescriptorSets(SpvReflectShaderModule* p_ const SpvReflectDescriptorSet* p_set = &p_module->descriptor_sets[j]; uint32_t count = 0; for (uint32_t k = 0; k < p_set->binding_count; ++k) { - bool found = SearchSortedUint32( - p_entry->used_uniforms, - p_entry->used_uniform_count, - p_set->bindings[k]->spirv_id); + bool found = SearchSortedUint32(p_entry->used_uniforms, p_entry->used_uniform_count, p_set->bindings[k]->spirv_id); if (found) { ++count; } @@ -3834,19 +3529,14 @@ static SpvReflectResult ParseEntrypointDescriptorSets(SpvReflectShaderModule* p_ if (count == 0) { continue; } - SpvReflectDescriptorSet* p_entry_set = &p_entry->descriptor_sets[ - p_entry->descriptor_set_count++]; + SpvReflectDescriptorSet* p_entry_set = &p_entry->descriptor_sets[p_entry->descriptor_set_count++]; p_entry_set->set = p_set->set; - p_entry_set->bindings = (SpvReflectDescriptorBinding**)calloc(count, - sizeof(*p_entry_set->bindings)); + p_entry_set->bindings = (SpvReflectDescriptorBinding**)calloc(count, sizeof(*p_entry_set->bindings)); if (IsNull(p_entry_set->bindings)) { return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED; } for (uint32_t k = 0; k < p_set->binding_count; ++k) { - bool found = SearchSortedUint32( - p_entry->used_uniforms, - p_entry->used_uniform_count, - p_set->bindings[k]->spirv_id); + bool found = SearchSortedUint32(p_entry->used_uniforms, p_entry->used_uniform_count, p_set->bindings[k]->spirv_id); if (found) { p_entry_set->bindings[p_entry_set->binding_count++] = p_set->bindings[k]; } @@ -3857,8 +3547,7 @@ static SpvReflectResult ParseEntrypointDescriptorSets(SpvReflectShaderModule* p_ return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult ParseDescriptorSets(SpvReflectShaderModule* p_module) -{ +static SpvReflectResult ParseDescriptorSets(SpvReflectShaderModule* p_module) { // Count the descriptors in each set for (uint32_t i = 0; i < p_module->descriptor_binding_count; ++i) { SpvReflectDescriptorBinding* p_descriptor = &(p_module->descriptor_bindings[i]); @@ -3902,16 +3591,14 @@ static SpvReflectResult ParseDescriptorSets(SpvReflectShaderModule* p_module) // Sort the descriptor sets based on numbers if (p_module->descriptor_set_count > 0) { - qsort(p_module->descriptor_sets, - p_module->descriptor_set_count, - sizeof(*(p_module->descriptor_sets)), + qsort(p_module->descriptor_sets, p_module->descriptor_set_count, sizeof(*(p_module->descriptor_sets)), SortCompareDescriptorSet); } // Build descriptor pointer array - for (uint32_t i = 0; i descriptor_set_count; ++i) { + for (uint32_t i = 0; i < p_module->descriptor_set_count; ++i) { SpvReflectDescriptorSet* p_set = &(p_module->descriptor_sets[i]); - p_set->bindings = (SpvReflectDescriptorBinding **)calloc(p_set->binding_count, sizeof(*(p_set->bindings))); + p_set->bindings = (SpvReflectDescriptorBinding**)calloc(p_set->binding_count, sizeof(*(p_set->bindings))); uint32_t descriptor_index = 0; for (uint32_t j = 0; j < p_module->descriptor_binding_count; ++j) { @@ -3927,8 +3614,7 @@ static SpvReflectResult ParseDescriptorSets(SpvReflectShaderModule* p_module) return ParseEntrypointDescriptorSets(p_module); } -static SpvReflectResult DisambiguateStorageBufferSrvUav(SpvReflectShaderModule* p_module) -{ +static SpvReflectResult DisambiguateStorageBufferSrvUav(SpvReflectShaderModule* p_module) { if (p_module->descriptor_binding_count == 0) { return SPV_REFLECT_RESULT_SUCCESS; } @@ -3954,8 +3640,7 @@ static SpvReflectResult DisambiguateStorageBufferSrvUav(SpvReflectShaderModule* return SPV_REFLECT_RESULT_SUCCESS; } -static SpvReflectResult SynchronizeDescriptorSets(SpvReflectShaderModule* p_module) -{ +static SpvReflectResult SynchronizeDescriptorSets(SpvReflectShaderModule* p_module) { // Free and reset all descriptor set numbers for (uint32_t i = 0; i < SPV_REFLECT_MAX_DESCRIPTOR_SETS; ++i) { SpvReflectDescriptorSet* p_set = &p_module->descriptor_sets[i]; @@ -3970,13 +3655,7 @@ static SpvReflectResult SynchronizeDescriptorSets(SpvReflectShaderModule* p_modu return result; } -static SpvReflectResult CreateShaderModule( - uint32_t flags, - size_t size, - const void* p_code, - SpvReflectShaderModule* p_module -) -{ +static SpvReflectResult CreateShaderModule(uint32_t flags, size_t size, const void* p_code, SpvReflectShaderModule* p_module) { // Initialize all module fields to zero memset(p_module, 0, sizeof(*p_module)); @@ -3996,13 +3675,12 @@ static SpvReflectResult CreateShaderModule( // Set internal size and pointer to args passed in p_module->_internal->spirv_size = size; #if defined(__cplusplus) - p_module->_internal->spirv_code = const_cast(static_cast(p_code)); // cast that const away + p_module->_internal->spirv_code = const_cast(static_cast(p_code)); // cast that const away #else - p_module->_internal->spirv_code = (void*)p_code; // cast that const away + p_module->_internal->spirv_code = (void*)p_code; // cast that const away #endif p_module->_internal->spirv_word_count = (uint32_t)(size / SPIRV_WORD_SIZE); - } - else { + } else { // Allocate SPIR-V code storage p_module->_internal->spirv_size = size; p_module->_internal->spirv_code = (uint32_t*)calloc(1, p_module->_internal->spirv_size); @@ -4020,9 +3698,7 @@ static SpvReflectResult CreateShaderModule( memset(&parser, 0, sizeof(SpvReflectPrvParser)); // Create parser - SpvReflectResult result = CreateParser(p_module->_internal->spirv_size, - p_module->_internal->spirv_code, - &parser); + SpvReflectResult result = CreateParser(p_module->_internal->spirv_size, p_module->_internal->spirv_code, &parser); // Generator { @@ -4140,36 +3816,19 @@ static SpvReflectResult CreateShaderModule( return result; } -SpvReflectResult spvReflectCreateShaderModule( - size_t size, - const void* p_code, - SpvReflectShaderModule* p_module -) -{ - return CreateShaderModule(0, size, p_code, p_module); +SpvReflectResult spvReflectCreateShaderModule(size_t size, const void* p_code, SpvReflectShaderModule* p_module) { + return CreateShaderModule(0, size, p_code, p_module); } -SpvReflectResult spvReflectCreateShaderModule2( - uint32_t flags, - size_t size, - const void* p_code, - SpvReflectShaderModule* p_module -) -{ +SpvReflectResult spvReflectCreateShaderModule2(uint32_t flags, size_t size, const void* p_code, SpvReflectShaderModule* p_module) { return CreateShaderModule(flags, size, p_code, p_module); } -SpvReflectResult spvReflectGetShaderModule( - size_t size, - const void* p_code, - SpvReflectShaderModule* p_module -) -{ - return spvReflectCreateShaderModule(size, p_code, p_module); +SpvReflectResult spvReflectGetShaderModule(size_t size, const void* p_code, SpvReflectShaderModule* p_module) { + return spvReflectCreateShaderModule(size, p_code, p_module); } -static void SafeFreeTypes(SpvReflectTypeDescription* p_type) -{ +static void SafeFreeTypes(SpvReflectTypeDescription* p_type) { if (IsNull(p_type)) { return; } @@ -4185,8 +3844,7 @@ static void SafeFreeTypes(SpvReflectTypeDescription* p_type) } } -static void SafeFreeBlockVariables(SpvReflectBlockVariable* p_block) -{ +static void SafeFreeBlockVariables(SpvReflectBlockVariable* p_block) { if (IsNull(p_block)) { return; } @@ -4202,8 +3860,7 @@ static void SafeFreeBlockVariables(SpvReflectBlockVariable* p_block) } } -static void SafeFreeInterfaceVariable(SpvReflectInterfaceVariable* p_interface) -{ +static void SafeFreeInterfaceVariable(SpvReflectInterfaceVariable* p_interface) { if (IsNull(p_interface)) { return; } @@ -4219,8 +3876,7 @@ static void SafeFreeInterfaceVariable(SpvReflectInterfaceVariable* p_interface) } } -void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) -{ +void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) { if (IsNull(p_module->_internal)) { return; } @@ -4284,8 +3940,7 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) SafeFree(p_module->_internal); } -uint32_t spvReflectGetCodeSize(const SpvReflectShaderModule* p_module) -{ +uint32_t spvReflectGetCodeSize(const SpvReflectShaderModule* p_module) { if (IsNull(p_module)) { return 0; } @@ -4293,8 +3948,7 @@ uint32_t spvReflectGetCodeSize(const SpvReflectShaderModule* p_module) return (uint32_t)(p_module->_internal->spirv_size); } -const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module) -{ +const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module) { if (IsNull(p_module)) { return NULL; } @@ -4302,10 +3956,7 @@ const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module) return p_module->_internal->spirv_code; } -const SpvReflectEntryPoint* spvReflectGetEntryPoint( - const SpvReflectShaderModule* p_module, - const char* entry_point -) { +const SpvReflectEntryPoint* spvReflectGetEntryPoint(const SpvReflectShaderModule* p_module, const char* entry_point) { if (IsNull(p_module) || IsNull(entry_point)) { return NULL; } @@ -4318,12 +3969,8 @@ const SpvReflectEntryPoint* spvReflectGetEntryPoint( return NULL; } -SpvReflectResult spvReflectEnumerateDescriptorBindings( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectDescriptorBinding** pp_bindings -) -{ +SpvReflectResult spvReflectEnumerateDescriptorBindings(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectDescriptorBinding** pp_bindings) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4340,21 +3987,15 @@ SpvReflectResult spvReflectEnumerateDescriptorBindings( SpvReflectDescriptorBinding* p_bindings = (SpvReflectDescriptorBinding*)&p_module->descriptor_bindings[index]; pp_bindings[index] = p_bindings; } - } - else { + } else { *p_count = p_module->descriptor_binding_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectDescriptorBinding** pp_bindings -) -{ +SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectDescriptorBinding** pp_bindings) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4362,18 +4003,14 @@ SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } uint32_t count = 0; for (uint32_t i = 0; i < p_module->descriptor_binding_count; ++i) { - bool found = SearchSortedUint32( - p_entry->used_uniforms, - p_entry->used_uniform_count, - p_module->descriptor_bindings[i].spirv_id); + bool found = SearchSortedUint32(p_entry->used_uniforms, p_entry->used_uniform_count, p_module->descriptor_bindings[i].spirv_id); if (found) { if (IsNotNull(pp_bindings)) { if (count >= *p_count) { @@ -4395,12 +4032,8 @@ SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings( return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateDescriptorSets( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectDescriptorSet** pp_sets -) -{ +SpvReflectResult spvReflectEnumerateDescriptorSets(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectDescriptorSet** pp_sets) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4417,21 +4050,15 @@ SpvReflectResult spvReflectEnumerateDescriptorSets( SpvReflectDescriptorSet* p_set = (SpvReflectDescriptorSet*)&p_module->descriptor_sets[index]; pp_sets[index] = p_set; } - } - else { + } else { *p_count = p_module->descriptor_set_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectDescriptorSet** pp_sets -) -{ +SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectDescriptorSet** pp_sets) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4439,8 +4066,7 @@ SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } @@ -4454,20 +4080,15 @@ SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets( SpvReflectDescriptorSet* p_set = (SpvReflectDescriptorSet*)&p_entry->descriptor_sets[index]; pp_sets[index] = p_set; } - } - else { + } else { *p_count = p_entry->descriptor_set_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateInterfaceVariables( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateInterfaceVariables(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4484,21 +4105,15 @@ SpvReflectResult spvReflectEnumerateInterfaceVariables( SpvReflectInterfaceVariable* p_var = &p_module->interface_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_module->interface_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4506,8 +4121,7 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } @@ -4521,20 +4135,15 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( SpvReflectInterfaceVariable* p_var = &p_entry->interface_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_entry->interface_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateInputVariables( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateInputVariables(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4551,21 +4160,15 @@ SpvReflectResult spvReflectEnumerateInputVariables( SpvReflectInterfaceVariable* p_var = p_module->input_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_module->input_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateEntryPointInputVariables( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateEntryPointInputVariables(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4573,8 +4176,7 @@ SpvReflectResult spvReflectEnumerateEntryPointInputVariables( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } @@ -4588,20 +4190,15 @@ SpvReflectResult spvReflectEnumerateEntryPointInputVariables( SpvReflectInterfaceVariable* p_var = p_entry->input_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_entry->input_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateOutputVariables( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateOutputVariables(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4618,21 +4215,15 @@ SpvReflectResult spvReflectEnumerateOutputVariables( SpvReflectInterfaceVariable* p_var = p_module->output_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_module->output_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumerateEntryPointOutputVariables( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectInterfaceVariable** pp_variables -) -{ +SpvReflectResult spvReflectEnumerateEntryPointOutputVariables(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4640,8 +4231,7 @@ SpvReflectResult spvReflectEnumerateEntryPointOutputVariables( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } @@ -4655,20 +4245,15 @@ SpvReflectResult spvReflectEnumerateEntryPointOutputVariables( SpvReflectInterfaceVariable* p_var = p_entry->output_variables[index]; pp_variables[index] = p_var; } - } - else { + } else { *p_count = p_entry->output_variable_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumeratePushConstantBlocks( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectBlockVariable** pp_blocks -) -{ +SpvReflectResult spvReflectEnumeratePushConstantBlocks(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectBlockVariable** pp_blocks) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4685,29 +4270,19 @@ SpvReflectResult spvReflectEnumeratePushConstantBlocks( SpvReflectBlockVariable* p_push_constant_blocks = (SpvReflectBlockVariable*)&p_module->push_constant_blocks[index]; pp_blocks[index] = p_push_constant_blocks; } - } - else { + } else { *p_count = p_module->push_constant_block_count; } return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectEnumeratePushConstants( - const SpvReflectShaderModule* p_module, - uint32_t* p_count, - SpvReflectBlockVariable** pp_blocks -) -{ +SpvReflectResult spvReflectEnumeratePushConstants(const SpvReflectShaderModule* p_module, uint32_t* p_count, + SpvReflectBlockVariable** pp_blocks) { return spvReflectEnumeratePushConstantBlocks(p_module, p_count, pp_blocks); } -SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t* p_count, - SpvReflectBlockVariable** pp_blocks -) -{ +SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -4715,18 +4290,15 @@ SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } - - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } uint32_t count = 0; for (uint32_t i = 0; i < p_module->push_constant_block_count; ++i) { - bool found = SearchSortedUint32(p_entry->used_push_constants, - p_entry->used_push_constant_count, - p_module->push_constant_blocks[i].spirv_id); + bool found = SearchSortedUint32(p_entry->used_push_constants, p_entry->used_push_constant_count, + p_module->push_constant_blocks[i].spirv_id); if (found) { if (IsNotNull(pp_blocks)) { if (count >= *p_count) { @@ -4748,13 +4320,8 @@ SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks( return SPV_REFLECT_RESULT_SUCCESS; } -const SpvReflectDescriptorBinding* spvReflectGetDescriptorBinding( - const SpvReflectShaderModule* p_module, - uint32_t binding_number, - uint32_t set_number, - SpvReflectResult* p_result -) -{ +const SpvReflectDescriptorBinding* spvReflectGetDescriptorBinding(const SpvReflectShaderModule* p_module, uint32_t binding_number, + uint32_t set_number, SpvReflectResult* p_result) { const SpvReflectDescriptorBinding* p_descriptor = NULL; if (IsNotNull(p_module)) { for (uint32_t index = 0; index < p_module->descriptor_binding_count; ++index) { @@ -4767,23 +4334,16 @@ const SpvReflectDescriptorBinding* spvReflectGetDescriptorBinding( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_descriptor) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_descriptor; } -const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t binding_number, - uint32_t set_number, - SpvReflectResult* p_result -) -{ - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); +const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding(const SpvReflectShaderModule* p_module, + const char* entry_point, uint32_t binding_number, + uint32_t set_number, SpvReflectResult* p_result) { + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -4794,10 +4354,7 @@ const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding( if (IsNotNull(p_module)) { for (uint32_t index = 0; index < p_module->descriptor_binding_count; ++index) { const SpvReflectDescriptorBinding* p_potential = &p_module->descriptor_bindings[index]; - bool found = SearchSortedUint32( - p_entry->used_uniforms, - p_entry->used_uniform_count, - p_potential->spirv_id); + bool found = SearchSortedUint32(p_entry->used_uniforms, p_entry->used_uniform_count, p_potential->spirv_id); if ((p_potential->binding == binding_number) && (p_potential->set == set_number) && found) { p_descriptor = p_potential; break; @@ -4806,19 +4363,14 @@ const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_descriptor) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_descriptor; } -const SpvReflectDescriptorSet* spvReflectGetDescriptorSet( - const SpvReflectShaderModule* p_module, - uint32_t set_number, - SpvReflectResult* p_result -) -{ +const SpvReflectDescriptorSet* spvReflectGetDescriptorSet(const SpvReflectShaderModule* p_module, uint32_t set_number, + SpvReflectResult* p_result) { const SpvReflectDescriptorSet* p_set = NULL; if (IsNotNull(p_module)) { for (uint32_t index = 0; index < p_module->descriptor_set_count; ++index) { @@ -4830,19 +4382,14 @@ const SpvReflectDescriptorSet* spvReflectGetDescriptorSet( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_set) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_set; } -const SpvReflectDescriptorSet* spvReflectGetEntryPointDescriptorSet( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t set_number, - SpvReflectResult* p_result) -{ +const SpvReflectDescriptorSet* spvReflectGetEntryPointDescriptorSet(const SpvReflectShaderModule* p_module, const char* entry_point, + uint32_t set_number, SpvReflectResult* p_result) { const SpvReflectDescriptorSet* p_set = NULL; if (IsNotNull(p_module)) { const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); @@ -4861,20 +4408,14 @@ const SpvReflectDescriptorSet* spvReflectGetEntryPointDescriptorSet( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_set) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_set; } - -const SpvReflectInterfaceVariable* spvReflectGetInputVariableByLocation( - const SpvReflectShaderModule* p_module, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetInputVariableByLocation(const SpvReflectShaderModule* p_module, uint32_t location, + SpvReflectResult* p_result) { if (location == INVALID_VALUE) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -4892,28 +4433,19 @@ const SpvReflectInterfaceVariable* spvReflectGetInputVariableByLocation( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetInputVariable( - const SpvReflectShaderModule* p_module, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetInputVariable(const SpvReflectShaderModule* p_module, uint32_t location, + SpvReflectResult* p_result) { return spvReflectGetInputVariableByLocation(p_module, location, p_result); } -const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocation( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocation(const SpvReflectShaderModule* p_module, + const char* entry_point, uint32_t location, + SpvReflectResult* p_result) { if (location == INVALID_VALUE) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -4923,8 +4455,7 @@ const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocatio const SpvReflectInterfaceVariable* p_var = NULL; if (IsNotNull(p_module)) { - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -4940,19 +4471,14 @@ const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocatio } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetInputVariableBySemantic( - const SpvReflectShaderModule* p_module, - const char* semantic, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetInputVariableBySemantic(const SpvReflectShaderModule* p_module, + const char* semantic, SpvReflectResult* p_result) { if (IsNull(semantic)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_NULL_POINTER; @@ -4976,20 +4502,15 @@ const SpvReflectInterfaceVariable* spvReflectGetInputVariableBySemantic( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableBySemantic( - const SpvReflectShaderModule* p_module, - const char* entry_point, - const char* semantic, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableBySemantic(const SpvReflectShaderModule* p_module, + const char* entry_point, const char* semantic, + SpvReflectResult* p_result) { if (IsNull(semantic)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_NULL_POINTER; @@ -5020,19 +4541,14 @@ const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableBySemanti } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetOutputVariableByLocation( - const SpvReflectShaderModule* p_module, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetOutputVariableByLocation(const SpvReflectShaderModule* p_module, uint32_t location, + SpvReflectResult* p_result) { if (location == INVALID_VALUE) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -5050,28 +4566,19 @@ const SpvReflectInterfaceVariable* spvReflectGetOutputVariableByLocation( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetOutputVariable( - const SpvReflectShaderModule* p_module, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetOutputVariable(const SpvReflectShaderModule* p_module, uint32_t location, + SpvReflectResult* p_result) { return spvReflectGetOutputVariableByLocation(p_module, location, p_result); } -const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableByLocation( - const SpvReflectShaderModule* p_module, - const char* entry_point, - uint32_t location, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableByLocation(const SpvReflectShaderModule* p_module, + const char* entry_point, uint32_t location, + SpvReflectResult* p_result) { if (location == INVALID_VALUE) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -5097,19 +4604,14 @@ const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableByLocati } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetOutputVariableBySemantic( - const SpvReflectShaderModule* p_module, - const char* semantic, - SpvReflectResult* p_result -) -{ +const SpvReflectInterfaceVariable* spvReflectGetOutputVariableBySemantic(const SpvReflectShaderModule* p_module, + const char* semantic, SpvReflectResult* p_result) { if (IsNull(semantic)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_NULL_POINTER; @@ -5133,19 +4635,15 @@ const SpvReflectInterfaceVariable* spvReflectGetOutputVariableBySemantic( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableBySemantic( - const SpvReflectShaderModule* p_module, - const char* entry_point, - const char* semantic, - SpvReflectResult* p_result) -{ +const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableBySemantic(const SpvReflectShaderModule* p_module, + const char* entry_point, const char* semantic, + SpvReflectResult* p_result) { if (IsNull(semantic)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_NULL_POINTER; @@ -5176,19 +4674,14 @@ const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableBySemant } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_var) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_var; } -const SpvReflectBlockVariable* spvReflectGetPushConstantBlock( - const SpvReflectShaderModule* p_module, - uint32_t index, - SpvReflectResult* p_result -) -{ +const SpvReflectBlockVariable* spvReflectGetPushConstantBlock(const SpvReflectShaderModule* p_module, uint32_t index, + SpvReflectResult* p_result) { const SpvReflectBlockVariable* p_push_constant = NULL; if (IsNotNull(p_module)) { if (index < p_module->push_constant_block_count) { @@ -5197,30 +4690,21 @@ const SpvReflectBlockVariable* spvReflectGetPushConstantBlock( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_push_constant) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_push_constant; } -const SpvReflectBlockVariable* spvReflectGetPushConstant( - const SpvReflectShaderModule* p_module, - uint32_t index, - SpvReflectResult* p_result -) -{ +const SpvReflectBlockVariable* spvReflectGetPushConstant(const SpvReflectShaderModule* p_module, uint32_t index, + SpvReflectResult* p_result) { return spvReflectGetPushConstantBlock(p_module, index, p_result); } -const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock( - const SpvReflectShaderModule* p_module, - const char* entry_point, - SpvReflectResult* p_result) -{ +const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock(const SpvReflectShaderModule* p_module, + const char* entry_point, SpvReflectResult* p_result) { const SpvReflectBlockVariable* p_push_constant = NULL; if (IsNotNull(p_module)) { - const SpvReflectEntryPoint* p_entry = - spvReflectGetEntryPoint(p_module, entry_point); + const SpvReflectEntryPoint* p_entry = spvReflectGetEntryPoint(p_module, entry_point); if (IsNull(p_entry)) { if (IsNotNull(p_result)) { *p_result = SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; @@ -5228,10 +4712,8 @@ const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock( return NULL; } for (uint32_t i = 0; i < p_module->push_constant_block_count; ++i) { - bool found = SearchSortedUint32( - p_entry->used_push_constants, - p_entry->used_push_constant_count, - p_module->push_constant_blocks[i].spirv_id); + bool found = SearchSortedUint32(p_entry->used_push_constants, p_entry->used_push_constant_count, + p_module->push_constant_blocks[i].spirv_id); if (found) { p_push_constant = &p_module->push_constant_blocks[i]; break; @@ -5240,20 +4722,15 @@ const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock( } if (IsNotNull(p_result)) { *p_result = IsNotNull(p_push_constant) - ? SPV_REFLECT_RESULT_SUCCESS - : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER - : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); + ? SPV_REFLECT_RESULT_SUCCESS + : (IsNull(p_module) ? SPV_REFLECT_RESULT_ERROR_NULL_POINTER : SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND); } return p_push_constant; } -SpvReflectResult spvReflectChangeDescriptorBindingNumbers( - SpvReflectShaderModule* p_module, - const SpvReflectDescriptorBinding* p_binding, - uint32_t new_binding_number, - uint32_t new_set_binding -) -{ +SpvReflectResult spvReflectChangeDescriptorBindingNumbers(SpvReflectShaderModule* p_module, + const SpvReflectDescriptorBinding* p_binding, uint32_t new_binding_number, + uint32_t new_set_binding) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -5263,7 +4740,7 @@ SpvReflectResult spvReflectChangeDescriptorBindingNumbers( SpvReflectDescriptorBinding* p_target_descriptor = NULL; for (uint32_t index = 0; index < p_module->descriptor_binding_count; ++index) { - if(&p_module->descriptor_bindings[index] == p_binding) { + if (&p_module->descriptor_bindings[index] == p_binding) { p_target_descriptor = &p_module->descriptor_bindings[index]; break; } @@ -5293,25 +4770,14 @@ SpvReflectResult spvReflectChangeDescriptorBindingNumbers( } return result; } -SpvReflectResult spvReflectChangeDescriptorBindingNumber( - SpvReflectShaderModule* p_module, - const SpvReflectDescriptorBinding* p_descriptor_binding, - uint32_t new_binding_number, - uint32_t optional_new_set_number -) -{ - return spvReflectChangeDescriptorBindingNumbers( - p_module,p_descriptor_binding, - new_binding_number, - optional_new_set_number); +SpvReflectResult spvReflectChangeDescriptorBindingNumber(SpvReflectShaderModule* p_module, + const SpvReflectDescriptorBinding* p_descriptor_binding, + uint32_t new_binding_number, uint32_t optional_new_set_number) { + return spvReflectChangeDescriptorBindingNumbers(p_module, p_descriptor_binding, new_binding_number, optional_new_set_number); } -SpvReflectResult spvReflectChangeDescriptorSetNumber( - SpvReflectShaderModule* p_module, - const SpvReflectDescriptorSet* p_set, - uint32_t new_set_number -) -{ +SpvReflectResult spvReflectChangeDescriptorSetNumber(SpvReflectShaderModule* p_module, const SpvReflectDescriptorSet* p_set, + uint32_t new_set_number) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -5347,12 +4813,8 @@ SpvReflectResult spvReflectChangeDescriptorSetNumber( return result; } -static SpvReflectResult ChangeVariableLocation( - SpvReflectShaderModule* p_module, - SpvReflectInterfaceVariable* p_variable, - uint32_t new_location -) -{ +static SpvReflectResult ChangeVariableLocation(SpvReflectShaderModule* p_module, SpvReflectInterfaceVariable* p_variable, + uint32_t new_location) { if (p_variable->word_offset.location > (p_module->_internal->spirv_word_count - 1)) { return SPV_REFLECT_RESULT_ERROR_RANGE_EXCEEDED; } @@ -5362,12 +4824,8 @@ static SpvReflectResult ChangeVariableLocation( return SPV_REFLECT_RESULT_SUCCESS; } -SpvReflectResult spvReflectChangeInputVariableLocation( - SpvReflectShaderModule* p_module, - const SpvReflectInterfaceVariable* p_input_variable, - uint32_t new_location -) -{ +SpvReflectResult spvReflectChangeInputVariableLocation(SpvReflectShaderModule* p_module, + const SpvReflectInterfaceVariable* p_input_variable, uint32_t new_location) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -5375,19 +4833,16 @@ SpvReflectResult spvReflectChangeInputVariableLocation( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } for (uint32_t index = 0; index < p_module->input_variable_count; ++index) { - if(p_module->input_variables[index] == p_input_variable) { + if (p_module->input_variables[index] == p_input_variable) { return ChangeVariableLocation(p_module, p_module->input_variables[index], new_location); } } return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } -SpvReflectResult spvReflectChangeOutputVariableLocation( - SpvReflectShaderModule* p_module, - const SpvReflectInterfaceVariable* p_output_variable, - uint32_t new_location -) -{ +SpvReflectResult spvReflectChangeOutputVariableLocation(SpvReflectShaderModule* p_module, + const SpvReflectInterfaceVariable* p_output_variable, + uint32_t new_location) { if (IsNull(p_module)) { return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } @@ -5395,25 +4850,33 @@ SpvReflectResult spvReflectChangeOutputVariableLocation( return SPV_REFLECT_RESULT_ERROR_NULL_POINTER; } for (uint32_t index = 0; index < p_module->output_variable_count; ++index) { - if(p_module->output_variables[index] == p_output_variable) { + if (p_module->output_variables[index] == p_output_variable) { return ChangeVariableLocation(p_module, p_module->output_variables[index], new_location); } } return SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND; } -const char* spvReflectSourceLanguage(SpvSourceLanguage source_lang) -{ +const char* spvReflectSourceLanguage(SpvSourceLanguage source_lang) { switch (source_lang) { - case SpvSourceLanguageESSL : return "ESSL"; - case SpvSourceLanguageGLSL : return "GLSL"; - case SpvSourceLanguageOpenCL_C : return "OpenCL_C"; - case SpvSourceLanguageOpenCL_CPP : return "OpenCL_CPP"; - case SpvSourceLanguageHLSL : return "HLSL"; - case SpvSourceLanguageCPP_for_OpenCL : return "CPP_for_OpenCL"; - case SpvSourceLanguageSYCL : return "SYCL"; - case SpvSourceLanguageHERO_C : return "Hero C"; - case SpvSourceLanguageNZSL : return "NZSL"; + case SpvSourceLanguageESSL: + return "ESSL"; + case SpvSourceLanguageGLSL: + return "GLSL"; + case SpvSourceLanguageOpenCL_C: + return "OpenCL_C"; + case SpvSourceLanguageOpenCL_CPP: + return "OpenCL_CPP"; + case SpvSourceLanguageHLSL: + return "HLSL"; + case SpvSourceLanguageCPP_for_OpenCL: + return "CPP_for_OpenCL"; + case SpvSourceLanguageSYCL: + return "SYCL"; + case SpvSourceLanguageHERO_C: + return "Hero C"; + case SpvSourceLanguageNZSL: + return "NZSL"; default: break; } @@ -5422,12 +4885,9 @@ const char* spvReflectSourceLanguage(SpvSourceLanguage source_lang) return "Unknown"; } -const char* spvReflectBlockVariableTypeName( - const SpvReflectBlockVariable* p_var -) -{ - if (p_var == NULL) { - return NULL; - } - return p_var->type_description->type_name; +const char* spvReflectBlockVariableTypeName(const SpvReflectBlockVariable* p_var) { + if (p_var == NULL) { + return NULL; + } + return p_var->type_description->type_name; } diff --git a/spirv_reflect.h b/spirv_reflect.h index d2870f25..df80949d 100644 --- a/spirv_reflect.h +++ b/spirv_reflect.h @@ -22,6 +22,7 @@ VERSION HISTORY */ +// clang-format off /*! @file spirv_reflect.h @@ -2337,3 +2338,5 @@ inline SpvReflectResult ShaderModule::ChangeOutputVariableLocation( } // namespace spv_reflect #endif // defined(__cplusplus) && !defined(SPIRV_REFLECT_DISABLE_CPP_WRAPPER) #endif // SPIRV_REFLECT_H + +// clang-format on \ No newline at end of file