Upgrade spirv-reflect

This commit is contained in:
Pedro J. Estébanez 2021-08-14 14:51:21 +02:00
parent 3a3be769b8
commit d29a0d5753
4 changed files with 368 additions and 281 deletions

View File

@ -602,7 +602,7 @@ Godot. Please check the file to know what's new.
## spirv-reflect ## spirv-reflect
- Upstream: https://github.com/KhronosGroup/SPIRV-Reflect - Upstream: https://github.com/KhronosGroup/SPIRV-Reflect
- Version: git (c0ce03a43ca77fedb5abfd1976ae2fd0eeb0e611, 2021) - Version: git (272e050728de8d4a4ce9e7101c1244e6ff56e5b0, 2021)
- License: Apache 2.0 - License: Apache 2.0
Files extracted from upstream source: Files extracted from upstream source:

View File

@ -1,18 +1,18 @@
diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c
index 0fc979a8a4..3e3643717a 100644 index 1c94a2e00e..2786a7f3ad 100644
--- a/thirdparty/spirv-reflect/spirv_reflect.c --- a/thirdparty/spirv-reflect/spirv_reflect.c
+++ b/thirdparty/spirv-reflect/spirv_reflect.c +++ b/thirdparty/spirv-reflect/spirv_reflect.c
@@ -124,6 +124,9 @@ typedef struct Decorations { @@ -124,6 +124,9 @@ typedef struct SpvReflectPrvDecorations {
NumberDecoration location; SpvReflectPrvNumberDecoration location;
NumberDecoration offset; SpvReflectPrvNumberDecoration offset;
NumberDecoration uav_counter_buffer; SpvReflectPrvNumberDecoration uav_counter_buffer;
+// -- GODOT begin -- +// -- GODOT begin --
+ NumberDecoration specialization_constant; + SpvReflectPrvNumberDecoration specialization_constant;
+// -- GODOT end -- +// -- GODOT end --
StringDecoration semantic; SpvReflectPrvStringDecoration semantic;
uint32_t array_stride; uint32_t array_stride;
uint32_t matrix_stride; uint32_t matrix_stride;
@@ -610,6 +613,9 @@ static SpvReflectResult ParseNodes(Parser* p_parser) @@ -629,6 +632,9 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser)
p_parser->nodes[i].decorations.offset.value = (uint32_t)INVALID_VALUE; p_parser->nodes[i].decorations.offset.value = (uint32_t)INVALID_VALUE;
p_parser->nodes[i].decorations.uav_counter_buffer.value = (uint32_t)INVALID_VALUE; p_parser->nodes[i].decorations.uav_counter_buffer.value = (uint32_t)INVALID_VALUE;
p_parser->nodes[i].decorations.built_in = (SpvBuiltIn)INVALID_VALUE; p_parser->nodes[i].decorations.built_in = (SpvBuiltIn)INVALID_VALUE;
@ -22,7 +22,7 @@ index 0fc979a8a4..3e3643717a 100644
} }
// Mark source file id node // Mark source file id node
p_parser->source_file_id = (uint32_t)INVALID_VALUE; p_parser->source_file_id = (uint32_t)INVALID_VALUE;
@@ -800,10 +806,16 @@ static SpvReflectResult ParseNodes(Parser* p_parser) @@ -819,10 +825,16 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser)
CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id); CHECKED_READU32(p_parser, p_node->word_offset + 2, p_node->result_id);
} }
break; break;
@ -41,7 +41,16 @@ index 0fc979a8a4..3e3643717a 100644
case SpvOpSpecConstantComposite: case SpvOpSpecConstantComposite:
case SpvOpSpecConstantOp: { case SpvOpSpecConstantOp: {
CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id); CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id);
@@ -1309,6 +1321,9 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) @@ -854,7 +866,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser)
CHECKED_READU32(p_parser, p_node->word_offset + 3, p_access_chain->base_id);
//
// SPIRV_ACCESS_CHAIN_INDEX_OFFSET (4) is the number of words up until the first index:
- // [Node, Result Type Id, Result Id, Base Id, <Indexes>]
+ // [SpvReflectPrvNode, Result Type Id, Result Id, Base Id, <Indexes>]
//
p_access_chain->index_count = (node_word_count - SPIRV_ACCESS_CHAIN_INDEX_OFFSET);
if (p_access_chain->index_count > 0) {
@@ -1334,6 +1346,9 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser)
skip = true; skip = true;
} }
break; break;
@ -51,7 +60,7 @@ index 0fc979a8a4..3e3643717a 100644
case SpvDecorationBlock: case SpvDecorationBlock:
case SpvDecorationBufferBlock: case SpvDecorationBufferBlock:
case SpvDecorationColMajor: case SpvDecorationColMajor:
@@ -1441,7 +1456,14 @@ static SpvReflectResult ParseDecorations(Parser* p_parser) @@ -1466,7 +1481,14 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser)
p_target_decorations->input_attachment_index.word_offset = word_offset; p_target_decorations->input_attachment_index.word_offset = word_offset;
} }
break; break;
@ -67,7 +76,7 @@ index 0fc979a8a4..3e3643717a 100644
case SpvReflectDecorationHlslCounterBufferGOOGLE: { 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); CHECKED_READU32(p_parser, word_offset, p_target_decorations->uav_counter_buffer.value);
@@ -1731,6 +1753,13 @@ static SpvReflectResult ParseType( @@ -1766,6 +1788,13 @@ static SpvReflectResult ParseType(
p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE; p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE;
} }
break; break;
@ -81,17 +90,17 @@ index 0fc979a8a4..3e3643717a 100644
} }
if (result == SPV_REFLECT_RESULT_SUCCESS) { if (result == SPV_REFLECT_RESULT_SUCCESS) {
@@ -3187,6 +3216,69 @@ static SpvReflectResult ParseExecutionModes(Parser* p_parser, SpvReflectShaderMo @@ -3236,6 +3265,69 @@ static SpvReflectResult ParseExecutionModes(
return SPV_REFLECT_RESULT_SUCCESS; return SPV_REFLECT_RESULT_SUCCESS;
} }
+// -- GODOT begin -- +// -- GODOT begin --
+static SpvReflectResult ParseSpecializationConstants(Parser* p_parser, SpvReflectShaderModule* p_module) +static SpvReflectResult ParseSpecializationConstants(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module)
+{ +{
+ p_module->specialization_constant_count = 0; + p_module->specialization_constant_count = 0;
+ p_module->specialization_constants = NULL; + p_module->specialization_constants = NULL;
+ for (size_t i = 0; i < p_parser->node_count; ++i) { + for (size_t i = 0; i < p_parser->node_count; ++i) {
+ Node* p_node = &(p_parser->nodes[i]); + SpvReflectPrvNode* p_node = &(p_parser->nodes[i]);
+ if (p_node->op == SpvOpSpecConstantTrue || p_node->op == SpvOpSpecConstantFalse || p_node->op == SpvOpSpecConstant) { + if (p_node->op == SpvOpSpecConstantTrue || p_node->op == SpvOpSpecConstantFalse || p_node->op == SpvOpSpecConstant) {
+ p_module->specialization_constant_count++; + p_module->specialization_constant_count++;
+ } + }
@ -106,7 +115,7 @@ index 0fc979a8a4..3e3643717a 100644
+ uint32_t index = 0; + uint32_t index = 0;
+ +
+ for (size_t i = 0; i < p_parser->node_count; ++i) { + for (size_t i = 0; i < p_parser->node_count; ++i) {
+ Node* p_node = &(p_parser->nodes[i]); + SpvReflectPrvNode* p_node = &(p_parser->nodes[i]);
+ switch(p_node->op) { + switch(p_node->op) {
+ default: continue; + default: continue;
+ case SpvOpSpecConstantTrue: { + case SpvOpSpecConstantTrue: {
@ -124,7 +133,7 @@ index 0fc979a8a4..3e3643717a 100644
+ IF_READU32(result, p_parser, p_node->word_offset + 1, element_type_id); + IF_READU32(result, p_parser, p_node->word_offset + 1, element_type_id);
+ IF_READU32(result, p_parser, p_node->word_offset + 3, default_value); + IF_READU32(result, p_parser, p_node->word_offset + 3, default_value);
+ +
+ Node* p_next_node = FindNode(p_parser, element_type_id); + SpvReflectPrvNode* p_next_node = FindNode(p_parser, element_type_id);
+ +
+ if (p_next_node->op == SpvOpTypeInt) { + if (p_next_node->op == SpvOpTypeInt) {
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT; + p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT;
@ -148,10 +157,10 @@ index 0fc979a8a4..3e3643717a 100644
+} +}
+// -- GODOT end -- +// -- GODOT end --
+ +
static SpvReflectResult ParsePushConstantBlocks(Parser* p_parser, SpvReflectShaderModule* p_module) static SpvReflectResult ParsePushConstantBlocks(
{ SpvReflectPrvParser* p_parser,
for (size_t i = 0; i < p_parser->node_count; ++i) { SpvReflectShaderModule* p_module)
@@ -3562,6 +3654,12 @@ SpvReflectResult spvReflectCreateShaderModule( @@ -3613,6 +3705,12 @@ SpvReflectResult spvReflectCreateShaderModule(
result = ParsePushConstantBlocks(&parser, p_module); result = ParsePushConstantBlocks(&parser, p_module);
SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
} }
@ -164,7 +173,7 @@ index 0fc979a8a4..3e3643717a 100644
if (result == SPV_REFLECT_RESULT_SUCCESS) { if (result == SPV_REFLECT_RESULT_SUCCESS) {
result = ParseEntryPoints(&parser, p_module); result = ParseEntryPoints(&parser, p_module);
SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS); SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
@@ -3691,6 +3789,9 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) @@ -3742,6 +3840,9 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module)
SafeFree(p_entry->used_push_constants); SafeFree(p_entry->used_push_constants);
} }
SafeFree(p_module->entry_points); SafeFree(p_module->entry_points);
@ -174,14 +183,14 @@ index 0fc979a8a4..3e3643717a 100644
// Push constants // Push constants
for (size_t i = 0; i < p_module->push_constant_block_count; ++i) { for (size_t i = 0; i < p_module->push_constant_block_count; ++i) {
@@ -3959,6 +4060,38 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables( @@ -4010,6 +4111,38 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables(
return SPV_REFLECT_RESULT_SUCCESS; return SPV_REFLECT_RESULT_SUCCESS;
} }
+// -- GODOT begin -- +// -- GODOT begin --
+SpvReflectResult spvReflectEnumerateSpecializationConstants( +SpvReflectResult spvReflectEnumerateSpecializationConstants(
+ const SpvReflectShaderModule* p_module, + const SpvReflectShaderModule* p_module,
+ uint32_t* p_count, + uint32_t* p_count,
+ SpvReflectSpecializationConstant** pp_constants + SpvReflectSpecializationConstant** pp_constants
+) +)
+{ +{
@ -214,7 +223,7 @@ index 0fc979a8a4..3e3643717a 100644
const SpvReflectShaderModule* p_module, const SpvReflectShaderModule* p_module,
uint32_t* p_count, uint32_t* p_count,
diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h
index a5a956e9e8..21f8160770 100644 index da05400973..50cc65222b 100644
--- a/thirdparty/spirv-reflect/spirv_reflect.h --- a/thirdparty/spirv-reflect/spirv_reflect.h
+++ b/thirdparty/spirv-reflect/spirv_reflect.h +++ b/thirdparty/spirv-reflect/spirv_reflect.h
@@ -292,6 +292,28 @@ typedef struct SpvReflectTypeDescription { @@ -292,6 +292,28 @@ typedef struct SpvReflectTypeDescription {
@ -247,9 +256,9 @@ index a5a956e9e8..21f8160770 100644
/*! @struct SpvReflectInterfaceVariable /*! @struct SpvReflectInterfaceVariable
@@ -439,6 +461,10 @@ typedef struct SpvReflectShaderModule { @@ -439,6 +461,10 @@ typedef struct SpvReflectShaderModule {
SpvReflectInterfaceVariable* interface_variables; SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
uint32_t push_constant_block_count; uint32_t push_constant_block_count; // Uses value(s) from first entry point
SpvReflectBlockVariable* push_constant_blocks; SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
+ // -- GODOT begin -- + // -- GODOT begin --
+ uint32_t specialization_constant_count; + uint32_t specialization_constant_count;
+ SpvReflectSpecializationConstant* specialization_constants; + SpvReflectSpecializationConstant* specialization_constants;

File diff suppressed because it is too large Load Diff

View File

@ -152,7 +152,7 @@ typedef enum SpvReflectFormat {
SPV_REFLECT_FORMAT_R64G64_SFLOAT = 115, // = VK_FORMAT_R64G64_SFLOAT SPV_REFLECT_FORMAT_R64G64_SFLOAT = 115, // = VK_FORMAT_R64G64_SFLOAT
SPV_REFLECT_FORMAT_R64G64B64_UINT = 116, // = VK_FORMAT_R64G64B64_UINT SPV_REFLECT_FORMAT_R64G64B64_UINT = 116, // = VK_FORMAT_R64G64B64_UINT
SPV_REFLECT_FORMAT_R64G64B64_SINT = 117, // = VK_FORMAT_R64G64B64_SINT SPV_REFLECT_FORMAT_R64G64B64_SINT = 117, // = VK_FORMAT_R64G64B64_SINT
SPV_REFLECT_FORMAT_R64G64B64_SFLOAT = 118, // = VK_FORMAT_R64G64B64_FLOAT SPV_REFLECT_FORMAT_R64G64B64_SFLOAT = 118, // = VK_FORMAT_R64G64B64_SFLOAT
SPV_REFLECT_FORMAT_R64G64B64A64_UINT = 119, // = VK_FORMAT_R64G64B64A64_UINT SPV_REFLECT_FORMAT_R64G64B64A64_UINT = 119, // = VK_FORMAT_R64G64B64A64_UINT
SPV_REFLECT_FORMAT_R64G64B64A64_SINT = 120, // = VK_FORMAT_R64G64B64A64_SINT SPV_REFLECT_FORMAT_R64G64B64A64_SINT = 120, // = VK_FORMAT_R64G64B64A64_SINT
SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT = 121, // = VK_FORMAT_R64G64B64A64_SFLOAT SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT = 121, // = VK_FORMAT_R64G64B64A64_SFLOAT
@ -447,20 +447,20 @@ typedef struct SpvReflectShaderModule {
uint32_t source_language_version; uint32_t source_language_version;
const char* source_file; const char* source_file;
const char* source_source; const char* source_source;
SpvExecutionModel spirv_execution_model; SpvExecutionModel spirv_execution_model; // Uses value(s) from first entry point
SpvReflectShaderStageFlagBits shader_stage; SpvReflectShaderStageFlagBits shader_stage; // Uses value(s) from first entry point
uint32_t descriptor_binding_count; uint32_t descriptor_binding_count; // Uses value(s) from first entry point
SpvReflectDescriptorBinding* descriptor_bindings; SpvReflectDescriptorBinding* descriptor_bindings; // Uses value(s) from first entry point
uint32_t descriptor_set_count; uint32_t descriptor_set_count; // Uses value(s) from first entry point
SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS]; SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS]; // Uses value(s) from first entry point
uint32_t input_variable_count; uint32_t input_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable** input_variables; SpvReflectInterfaceVariable** input_variables; // Uses value(s) from first entry point
uint32_t output_variable_count; uint32_t output_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable** output_variables; SpvReflectInterfaceVariable** output_variables; // Uses value(s) from first entry point
uint32_t interface_variable_count; uint32_t interface_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable* interface_variables; SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
uint32_t push_constant_block_count; uint32_t push_constant_block_count; // Uses value(s) from first entry point
SpvReflectBlockVariable* push_constant_blocks; SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
// -- GODOT begin -- // -- GODOT begin --
uint32_t specialization_constant_count; uint32_t specialization_constant_count;
SpvReflectSpecializationConstant* specialization_constants; SpvReflectSpecializationConstant* specialization_constants;
@ -1426,6 +1426,9 @@ public:
ShaderModule(const std::vector<uint32_t>& code); ShaderModule(const std::vector<uint32_t>& code);
~ShaderModule(); ~ShaderModule();
ShaderModule(ShaderModule&& other);
ShaderModule& operator=(ShaderModule&& other);
SpvReflectResult GetResult() const; SpvReflectResult GetResult() const;
const SpvReflectShaderModule& GetShaderModule() const; const SpvReflectShaderModule& GetShaderModule() const;
@ -1437,8 +1440,9 @@ public:
const char* GetSourceFile() const; const char* GetSourceFile() const;
uint32_t GetEntryPointCount() const; uint32_t GetEntryPointCount() const;
const char* GetEntryPointName(uint32_t index) const; const char* GetEntryPointName(uint32_t index) const;
SpvReflectShaderStageFlagBits GetEntryPointShaderStage(uint32_t index) const;
SpvReflectShaderStageFlagBits GetShaderStage() const; SpvReflectShaderStageFlagBits GetShaderStage() const;
SPV_REFLECT_DEPRECATED("Renamed to GetShaderStage") SPV_REFLECT_DEPRECATED("Renamed to GetShaderStage")
@ -1568,6 +1572,20 @@ inline ShaderModule::~ShaderModule() {
} }
inline ShaderModule::ShaderModule(ShaderModule&& other)
{
*this = std::move(other);
}
inline ShaderModule& ShaderModule::operator=(ShaderModule&& other)
{
m_result = std::move(other.m_result);
m_module = std::move(other.m_module);
other.m_module = {};
return *this;
}
/*! @fn GetResult /*! @fn GetResult
@return @return
@ -1644,9 +1662,18 @@ inline const char* ShaderModule::GetEntryPointName(uint32_t index) const {
return m_module.entry_points[index].name; return m_module.entry_points[index].name;
} }
/*! @fn GetEntryPointShaderStage
@param index
@return Returns the shader stage for the entry point at \b index
*/
inline SpvReflectShaderStageFlagBits ShaderModule::GetEntryPointShaderStage(uint32_t index) const {
return m_module.entry_points[index].shader_stage;
}
/*! @fn GetShaderStage /*! @fn GetShaderStage
@return Returns Vulkan shader stage @return Returns shader stage for the first entry point
*/ */
inline SpvReflectShaderStageFlagBits ShaderModule::GetShaderStage() const { inline SpvReflectShaderStageFlagBits ShaderModule::GetShaderStage() const {