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
- Upstream: https://github.com/KhronosGroup/SPIRV-Reflect
- Version: git (c0ce03a43ca77fedb5abfd1976ae2fd0eeb0e611, 2021)
- Version: git (272e050728de8d4a4ce9e7101c1244e6ff56e5b0, 2021)
- License: Apache 2.0
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
index 0fc979a8a4..3e3643717a 100644
index 1c94a2e00e..2786a7f3ad 100644
--- a/thirdparty/spirv-reflect/spirv_reflect.c
+++ b/thirdparty/spirv-reflect/spirv_reflect.c
@@ -124,6 +124,9 @@ typedef struct Decorations {
NumberDecoration location;
NumberDecoration offset;
NumberDecoration uav_counter_buffer;
@@ -124,6 +124,9 @@ typedef struct SpvReflectPrvDecorations {
SpvReflectPrvNumberDecoration location;
SpvReflectPrvNumberDecoration offset;
SpvReflectPrvNumberDecoration uav_counter_buffer;
+// -- GODOT begin --
+ NumberDecoration specialization_constant;
+ SpvReflectPrvNumberDecoration specialization_constant;
+// -- GODOT end --
StringDecoration semantic;
uint32_t array_stride;
uint32_t matrix_stride;
@@ -610,6 +613,9 @@ static SpvReflectResult ParseNodes(Parser* p_parser)
SpvReflectPrvStringDecoration semantic;
uint32_t array_stride;
uint32_t matrix_stride;
@@ -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.uav_counter_buffer.value = (uint32_t)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
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);
}
break;
@ -41,7 +41,16 @@ index 0fc979a8a4..3e3643717a 100644
case SpvOpSpecConstantComposite:
case SpvOpSpecConstantOp: {
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;
}
break;
@ -51,7 +60,7 @@ index 0fc979a8a4..3e3643717a 100644
case SpvDecorationBlock:
case SpvDecorationBufferBlock:
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;
}
break;
@ -67,7 +76,7 @@ index 0fc979a8a4..3e3643717a 100644
case SpvReflectDecorationHlslCounterBufferGOOGLE: {
uint32_t word_offset = p_node->word_offset + member_offset+ 3;
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;
}
break;
@ -81,17 +90,17 @@ index 0fc979a8a4..3e3643717a 100644
}
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;
}
+// -- 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_constants = NULL;
+ 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) {
+ p_module->specialization_constant_count++;
+ }
@ -106,7 +115,7 @@ index 0fc979a8a4..3e3643717a 100644
+ uint32_t index = 0;
+
+ 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) {
+ default: continue;
+ 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 + 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) {
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT;
@ -148,10 +157,10 @@ index 0fc979a8a4..3e3643717a 100644
+}
+// -- GODOT end --
+
static SpvReflectResult ParsePushConstantBlocks(Parser* p_parser, SpvReflectShaderModule* p_module)
{
for (size_t i = 0; i < p_parser->node_count; ++i) {
@@ -3562,6 +3654,12 @@ SpvReflectResult spvReflectCreateShaderModule(
static SpvReflectResult ParsePushConstantBlocks(
SpvReflectPrvParser* p_parser,
SpvReflectShaderModule* p_module)
@@ -3613,6 +3705,12 @@ SpvReflectResult spvReflectCreateShaderModule(
result = ParsePushConstantBlocks(&parser, p_module);
SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
}
@ -164,7 +173,7 @@ index 0fc979a8a4..3e3643717a 100644
if (result == SPV_REFLECT_RESULT_SUCCESS) {
result = ParseEntryPoints(&parser, p_module);
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_module->entry_points);
@ -174,14 +183,14 @@ index 0fc979a8a4..3e3643717a 100644
// Push constants
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;
}
+// -- GODOT begin --
+SpvReflectResult spvReflectEnumerateSpecializationConstants(
+ const SpvReflectShaderModule* p_module,
+ uint32_t* p_count,
+ const SpvReflectShaderModule* p_module,
+ uint32_t* p_count,
+ SpvReflectSpecializationConstant** pp_constants
+)
+{
@ -214,7 +223,7 @@ index 0fc979a8a4..3e3643717a 100644
const SpvReflectShaderModule* p_module,
uint32_t* p_count,
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
+++ b/thirdparty/spirv-reflect/spirv_reflect.h
@@ -292,6 +292,28 @@ typedef struct SpvReflectTypeDescription {
@ -247,9 +256,9 @@ index a5a956e9e8..21f8160770 100644
/*! @struct SpvReflectInterfaceVariable
@@ -439,6 +461,10 @@ typedef struct SpvReflectShaderModule {
SpvReflectInterfaceVariable* interface_variables;
uint32_t push_constant_block_count;
SpvReflectBlockVariable* push_constant_blocks;
SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
uint32_t push_constant_block_count; // Uses value(s) from first entry point
SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
+ // -- GODOT begin --
+ uint32_t specialization_constant_count;
+ 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_R64G64B64_UINT = 116, // = VK_FORMAT_R64G64B64_UINT
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_SINT = 120, // = VK_FORMAT_R64G64B64A64_SINT
SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT = 121, // = VK_FORMAT_R64G64B64A64_SFLOAT
@ -447,20 +447,20 @@ typedef struct SpvReflectShaderModule {
uint32_t source_language_version;
const char* source_file;
const char* source_source;
SpvExecutionModel spirv_execution_model;
SpvReflectShaderStageFlagBits shader_stage;
uint32_t descriptor_binding_count;
SpvReflectDescriptorBinding* descriptor_bindings;
uint32_t descriptor_set_count;
SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS];
uint32_t input_variable_count;
SpvReflectInterfaceVariable** input_variables;
uint32_t output_variable_count;
SpvReflectInterfaceVariable** output_variables;
uint32_t interface_variable_count;
SpvReflectInterfaceVariable* interface_variables;
uint32_t push_constant_block_count;
SpvReflectBlockVariable* push_constant_blocks;
SpvExecutionModel spirv_execution_model; // Uses value(s) from first entry point
SpvReflectShaderStageFlagBits shader_stage; // Uses value(s) from first entry point
uint32_t descriptor_binding_count; // Uses value(s) from first entry point
SpvReflectDescriptorBinding* descriptor_bindings; // Uses value(s) from first entry point
uint32_t descriptor_set_count; // Uses value(s) from first entry point
SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS]; // Uses value(s) from first entry point
uint32_t input_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable** input_variables; // Uses value(s) from first entry point
uint32_t output_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable** output_variables; // Uses value(s) from first entry point
uint32_t interface_variable_count; // Uses value(s) from first entry point
SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
uint32_t push_constant_block_count; // Uses value(s) from first entry point
SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
// -- GODOT begin --
uint32_t specialization_constant_count;
SpvReflectSpecializationConstant* specialization_constants;
@ -1426,6 +1426,9 @@ public:
ShaderModule(const std::vector<uint32_t>& code);
~ShaderModule();
ShaderModule(ShaderModule&& other);
ShaderModule& operator=(ShaderModule&& other);
SpvReflectResult GetResult() const;
const SpvReflectShaderModule& GetShaderModule() const;
@ -1437,8 +1440,9 @@ public:
const char* GetSourceFile() const;
uint32_t GetEntryPointCount() const;
const char* GetEntryPointName(uint32_t index) const;
uint32_t GetEntryPointCount() const;
const char* GetEntryPointName(uint32_t index) const;
SpvReflectShaderStageFlagBits GetEntryPointShaderStage(uint32_t index) const;
SpvReflectShaderStageFlagBits GetShaderStage() const;
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
@return
@ -1644,9 +1662,18 @@ inline const char* ShaderModule::GetEntryPointName(uint32_t index) const {
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
@return Returns Vulkan shader stage
@return Returns shader stage for the first entry point
*/
inline SpvReflectShaderStageFlagBits ShaderModule::GetShaderStage() const {