2021-07-09 21:48:28 +02:00
|
|
|
diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c
|
2024-02-05 20:39:02 +01:00
|
|
|
index 3b9d6bfecc..e97d1b0438 100644
|
2021-07-09 21:48:28 +02:00
|
|
|
--- a/thirdparty/spirv-reflect/spirv_reflect.c
|
|
|
|
+++ b/thirdparty/spirv-reflect/spirv_reflect.c
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -122,6 +122,9 @@ typedef struct SpvReflectPrvDecorations {
|
2023-09-01 11:11:12 +02:00
|
|
|
SpvReflectPrvNumberDecoration component;
|
2021-08-14 14:51:21 +02:00
|
|
|
SpvReflectPrvNumberDecoration offset;
|
|
|
|
SpvReflectPrvNumberDecoration uav_counter_buffer;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT begin --
|
2021-08-14 14:51:21 +02:00
|
|
|
+ SpvReflectPrvNumberDecoration specialization_constant;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT end --
|
2021-08-14 14:51:21 +02:00
|
|
|
SpvReflectPrvStringDecoration semantic;
|
|
|
|
uint32_t array_stride;
|
|
|
|
uint32_t matrix_stride;
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -708,6 +711,9 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) {
|
2021-07-09 21:48:28 +02:00
|
|
|
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;
|
|
|
|
+// -- GODOT begin --
|
|
|
|
+ p_parser->nodes[i].decorations.specialization_constant.value = (SpvBuiltIn)INVALID_VALUE;
|
|
|
|
+// -- GODOT end --
|
|
|
|
}
|
|
|
|
// Mark source file id node
|
|
|
|
p_parser->source_file_id = (uint32_t)INVALID_VALUE;
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -907,7 +913,13 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser) {
|
2023-09-01 11:11:12 +02:00
|
|
|
|
2021-07-09 21:48:28 +02:00
|
|
|
case SpvOpSpecConstantTrue:
|
|
|
|
case SpvOpSpecConstantFalse:
|
|
|
|
- case SpvOpSpecConstant:
|
2023-09-01 11:11:12 +02:00
|
|
|
+// -- GODOT begin --
|
2021-07-09 21:48:28 +02:00
|
|
|
+ case SpvOpSpecConstant: {
|
|
|
|
+ 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);
|
|
|
|
+ p_node->is_type = true;
|
2024-02-05 20:39:02 +01:00
|
|
|
+ } break;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT end --
|
|
|
|
case SpvOpSpecConstantComposite:
|
|
|
|
case SpvOpSpecConstantOp: {
|
|
|
|
CHECKED_READU32(p_parser, p_node->word_offset + 1, p_node->result_type_id);
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -1385,6 +1397,9 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) {
|
|
|
|
default: {
|
2021-07-09 21:48:28 +02:00
|
|
|
skip = true;
|
2024-02-05 20:39:02 +01:00
|
|
|
} break;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT begin --
|
|
|
|
+ case SpvDecorationSpecId:
|
|
|
|
+// -- GODOT end --
|
2022-02-11 18:42:11 +01:00
|
|
|
case SpvDecorationRelaxedPrecision:
|
2021-07-09 21:48:28 +02:00
|
|
|
case SpvDecorationBlock:
|
|
|
|
case SpvDecorationBufferBlock:
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -1542,6 +1557,14 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) {
|
|
|
|
p_target_decorations->input_attachment_index.word_offset = word_offset;
|
|
|
|
} break;
|
2023-09-01 11:11:12 +02:00
|
|
|
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT begin --
|
|
|
|
+ case SpvDecorationSpecId: {
|
|
|
|
+ uint32_t word_offset = p_node->word_offset + member_offset+ 3;
|
|
|
|
+ CHECKED_READU32(p_parser, word_offset, p_target_decorations->specialization_constant.value);
|
|
|
|
+ p_target_decorations->specialization_constant.word_offset = word_offset;
|
2024-02-05 20:39:02 +01:00
|
|
|
+ } break;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT end --
|
2023-09-01 11:11:12 +02:00
|
|
|
+
|
2021-07-09 21:48:28 +02:00
|
|
|
case SpvReflectDecorationHlslCounterBufferGOOGLE: {
|
2024-02-05 20:39:02 +01:00
|
|
|
uint32_t word_offset = p_node->word_offset + member_offset + 3;
|
2021-07-09 21:48:28 +02:00
|
|
|
CHECKED_READU32(p_parser, word_offset, p_target_decorations->uav_counter_buffer.value);
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -1851,6 +1874,13 @@ static SpvReflectResult ParseType(SpvReflectPrvParser* p_parser, SpvReflectPrvNo
|
|
|
|
case SpvOpTypeAccelerationStructureKHR: {
|
2021-07-09 21:48:28 +02:00
|
|
|
p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE;
|
2024-02-05 20:39:02 +01:00
|
|
|
} break;
|
2023-09-01 11:11:12 +02:00
|
|
|
+
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT begin --
|
|
|
|
+ case SpvOpSpecConstantTrue:
|
|
|
|
+ case SpvOpSpecConstantFalse:
|
|
|
|
+ case SpvOpSpecConstant: {
|
2024-02-05 20:39:02 +01:00
|
|
|
+ } break;
|
2021-07-09 21:48:28 +02:00
|
|
|
+// -- GODOT end --
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == SPV_REFLECT_RESULT_SUCCESS) {
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -3522,6 +3552,68 @@ static SpvReflectResult ParseExecutionModes(SpvReflectPrvParser* p_parser, SpvRe
|
2021-07-09 21:48:28 +02:00
|
|
|
return SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
+// -- GODOT begin --
|
2024-02-05 20:39:02 +01:00
|
|
|
+static SpvReflectResult ParseSpecializationConstants(SpvReflectPrvParser* p_parser, SpvReflectShaderModule* p_module) {
|
2021-07-09 21:48:28 +02:00
|
|
|
+ p_module->specialization_constant_count = 0;
|
|
|
|
+ p_module->specialization_constants = NULL;
|
|
|
|
+ for (size_t i = 0; i < p_parser->node_count; ++i) {
|
2021-08-14 14:51:21 +02:00
|
|
|
+ SpvReflectPrvNode* p_node = &(p_parser->nodes[i]);
|
2021-07-09 21:48:28 +02:00
|
|
|
+ if (p_node->op == SpvOpSpecConstantTrue || p_node->op == SpvOpSpecConstantFalse || p_node->op == SpvOpSpecConstant) {
|
|
|
|
+ p_module->specialization_constant_count++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (p_module->specialization_constant_count == 0) {
|
|
|
|
+ return SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p_module->specialization_constants = (SpvReflectSpecializationConstant*)calloc(p_module->specialization_constant_count, sizeof(SpvReflectSpecializationConstant));
|
|
|
|
+
|
|
|
|
+ uint32_t index = 0;
|
|
|
|
+
|
|
|
|
+ for (size_t i = 0; i < p_parser->node_count; ++i) {
|
2021-08-14 14:51:21 +02:00
|
|
|
+ SpvReflectPrvNode* p_node = &(p_parser->nodes[i]);
|
2021-07-09 21:48:28 +02:00
|
|
|
+ switch(p_node->op) {
|
|
|
|
+ default: continue;
|
|
|
|
+ case SpvOpSpecConstantTrue: {
|
|
|
|
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL;
|
|
|
|
+ p_module->specialization_constants[index].default_value.int_bool_value = 1;
|
|
|
|
+ } break;
|
|
|
|
+ case SpvOpSpecConstantFalse: {
|
|
|
|
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL;
|
|
|
|
+ p_module->specialization_constants[index].default_value.int_bool_value = 0;
|
|
|
|
+ } break;
|
|
|
|
+ case SpvOpSpecConstant: {
|
|
|
|
+ SpvReflectResult result = SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
+ uint32_t element_type_id = (uint32_t)INVALID_VALUE;
|
|
|
|
+ uint32_t default_value = 0;
|
|
|
|
+ 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);
|
|
|
|
+
|
2021-08-14 14:51:21 +02:00
|
|
|
+ SpvReflectPrvNode* p_next_node = FindNode(p_parser, element_type_id);
|
2021-07-09 21:48:28 +02:00
|
|
|
+
|
|
|
|
+ if (p_next_node->op == SpvOpTypeInt) {
|
|
|
|
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT;
|
|
|
|
+ } else if (p_next_node->op == SpvOpTypeFloat) {
|
|
|
|
+ p_module->specialization_constants[index].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT;
|
|
|
|
+ } else {
|
|
|
|
+ return SPV_REFLECT_RESULT_ERROR_PARSE_FAILED;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p_module->specialization_constants[index].default_value.int_bool_value = default_value; //bits are the same for int and float
|
|
|
|
+ } break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ p_module->specialization_constants[index].name = p_node->name;
|
|
|
|
+ p_module->specialization_constants[index].constant_id = p_node->decorations.specialization_constant.value;
|
|
|
|
+ p_module->specialization_constants[index].spirv_id = p_node->result_id;
|
|
|
|
+ index++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
+}
|
|
|
|
+// -- GODOT end --
|
|
|
|
+
|
2024-02-05 20:39:02 +01:00
|
|
|
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]);
|
|
|
|
@@ -3908,6 +4000,12 @@ static SpvReflectResult CreateShaderModule(uint32_t flags, size_t size, const vo
|
2021-07-09 21:48:28 +02:00
|
|
|
result = ParsePushConstantBlocks(&parser, p_module);
|
|
|
|
SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
+// -- GODOT begin --
|
|
|
|
+ if (result == SPV_REFLECT_RESULT_SUCCESS) {
|
|
|
|
+ result = ParseSpecializationConstants(&parser, p_module);
|
|
|
|
+ SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
|
|
|
|
+ }
|
|
|
|
+// -- GODOT end --
|
|
|
|
if (result == SPV_REFLECT_RESULT_SUCCESS) {
|
|
|
|
result = ParseEntryPoints(&parser, p_module);
|
|
|
|
SPV_REFLECT_ASSERT(result == SPV_REFLECT_RESULT_SUCCESS);
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -4056,6 +4154,9 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) {
|
2021-07-09 21:48:28 +02:00
|
|
|
}
|
2022-10-31 13:47:11 +01:00
|
|
|
SafeFree(p_module->capabilities);
|
2021-07-09 21:48:28 +02:00
|
|
|
SafeFree(p_module->entry_points);
|
|
|
|
+// -- GODOT begin --
|
|
|
|
+ SafeFree(p_module->specialization_constants);
|
|
|
|
+// -- GODOT end --
|
|
|
|
|
|
|
|
// Push constants
|
|
|
|
for (size_t i = 0; i < p_module->push_constant_block_count; ++i) {
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -4283,6 +4384,36 @@ SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables(const SpvReflec
|
2021-07-09 21:48:28 +02:00
|
|
|
return SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
+// -- GODOT begin --
|
|
|
|
+SpvReflectResult spvReflectEnumerateSpecializationConstants(
|
2021-08-14 14:51:21 +02:00
|
|
|
+ const SpvReflectShaderModule* p_module,
|
|
|
|
+ uint32_t* p_count,
|
2021-07-09 21:48:28 +02:00
|
|
|
+ SpvReflectSpecializationConstant** pp_constants
|
2024-02-05 20:39:02 +01:00
|
|
|
+) {
|
2021-07-09 21:48:28 +02:00
|
|
|
+ if (IsNull(p_module)) {
|
|
|
|
+ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER;
|
|
|
|
+ }
|
|
|
|
+ if (IsNull(p_count)) {
|
|
|
|
+ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (IsNotNull(pp_constants)) {
|
|
|
|
+ if (*p_count != p_module->specialization_constant_count) {
|
|
|
|
+ return SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (uint32_t index = 0; index < *p_count; ++index) {
|
|
|
|
+ SpvReflectSpecializationConstant *p_const = &p_module->specialization_constants[index];
|
|
|
|
+ pp_constants[index] = p_const;
|
|
|
|
+ }
|
2024-02-05 20:39:02 +01:00
|
|
|
+ } else {
|
2021-07-09 21:48:28 +02:00
|
|
|
+ *p_count = p_module->specialization_constant_count;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return SPV_REFLECT_RESULT_SUCCESS;
|
|
|
|
+}
|
|
|
|
+// -- GODOT end --
|
|
|
|
+
|
2024-02-05 20:39:02 +01:00
|
|
|
SpvReflectResult spvReflectEnumerateInputVariables(const SpvReflectShaderModule* p_module, uint32_t* p_count,
|
|
|
|
SpvReflectInterfaceVariable** pp_variables) {
|
|
|
|
if (IsNull(p_module)) {
|
2021-07-09 21:48:28 +02:00
|
|
|
diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h
|
2024-02-05 20:39:02 +01:00
|
|
|
index 08550e8f02..24446f1c1b 100644
|
2021-07-09 21:48:28 +02:00
|
|
|
--- a/thirdparty/spirv-reflect/spirv_reflect.h
|
|
|
|
+++ b/thirdparty/spirv-reflect/spirv_reflect.h
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -374,6 +374,30 @@ typedef struct SpvReflectTypeDescription {
|
2021-07-09 21:48:28 +02:00
|
|
|
struct SpvReflectTypeDescription* members;
|
|
|
|
} SpvReflectTypeDescription;
|
|
|
|
|
|
|
|
+// -- GODOT begin --
|
2024-02-05 20:39:02 +01:00
|
|
|
+/*! @enum SpvReflectSpecializationConstantType
|
2021-07-09 21:48:28 +02:00
|
|
|
+
|
|
|
|
+*/
|
|
|
|
+typedef enum SpvReflectSpecializationConstantType {
|
|
|
|
+ SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL = 0,
|
|
|
|
+ SPV_REFLECT_SPECIALIZATION_CONSTANT_INT = 1,
|
|
|
|
+ SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT = 2,
|
|
|
|
+} SpvReflectSpecializationConstantType;
|
|
|
|
+
|
2024-02-05 20:39:02 +01:00
|
|
|
+/*! @struct SpvReflectSpecializationConstant
|
|
|
|
+
|
|
|
|
+*/
|
2021-07-09 21:48:28 +02:00
|
|
|
+typedef struct SpvReflectSpecializationConstant {
|
|
|
|
+ const char* name;
|
|
|
|
+ uint32_t spirv_id;
|
|
|
|
+ uint32_t constant_id;
|
|
|
|
+ SpvReflectSpecializationConstantType constant_type;
|
|
|
|
+ union {
|
|
|
|
+ float float_value;
|
|
|
|
+ uint32_t int_bool_value;
|
|
|
|
+ } default_value;
|
|
|
|
+} SpvReflectSpecializationConstant;
|
|
|
|
+// -- GODOT end --
|
|
|
|
|
|
|
|
/*! @struct SpvReflectInterfaceVariable
|
2023-09-01 11:11:12 +02:00
|
|
|
@brief The OpVariable that is either an Input or Output to the module
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -549,6 +573,10 @@ typedef struct SpvReflectShaderModule {
|
2021-08-14 14:51:21 +02:00
|
|
|
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
|
2024-02-05 20:39:02 +01:00
|
|
|
+// -- GODOT begin --
|
2021-07-09 21:48:28 +02:00
|
|
|
+ uint32_t specialization_constant_count;
|
|
|
|
+ SpvReflectSpecializationConstant* specialization_constants;
|
2024-02-05 20:39:02 +01:00
|
|
|
+// -- GODOT end --
|
2021-07-09 21:48:28 +02:00
|
|
|
|
|
|
|
struct Internal {
|
2022-02-11 18:42:11 +01:00
|
|
|
SpvReflectModuleFlags module_flags;
|
2024-02-05 20:39:02 +01:00
|
|
|
@@ -821,6 +849,32 @@ SpvReflectResult spvReflectEnumerateInputVariables(
|
2021-07-09 21:48:28 +02:00
|
|
|
SpvReflectInterfaceVariable** pp_variables
|
|
|
|
);
|
|
|
|
|
|
|
|
+// -- GOODT begin --
|
|
|
|
+/*! @fn spvReflectEnumerateSpecializationConstants
|
|
|
|
+ @brief If the module contains multiple entry points, this will only get
|
|
|
|
+ the specialization constants for the first one.
|
|
|
|
+ @param p_module Pointer to an instance of SpvReflectShaderModule.
|
|
|
|
+ @param p_count If pp_constants is NULL, the module's specialization constant
|
|
|
|
+ count will be stored here.
|
|
|
|
+ If pp_variables is not NULL, *p_count must contain
|
|
|
|
+ the module's specialization constant count.
|
|
|
|
+ @param pp_variables If NULL, the module's specialization constant count will be
|
|
|
|
+ written to *p_count.
|
|
|
|
+ If non-NULL, pp_constants must point to an array with
|
|
|
|
+ *p_count entries, where pointers to the module's
|
|
|
|
+ specialization constants will be written. The caller must not
|
|
|
|
+ free the specialization constants written to this array.
|
|
|
|
+ @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
|
|
|
|
+ Otherwise, the error code indicates the cause of the
|
|
|
|
+ failure.
|
|
|
|
+*/
|
|
|
|
+SpvReflectResult spvReflectEnumerateSpecializationConstants(
|
|
|
|
+ const SpvReflectShaderModule* p_module,
|
|
|
|
+ uint32_t* p_count,
|
|
|
|
+ SpvReflectSpecializationConstant** pp_constants
|
|
|
|
+);
|
|
|
|
+// -- GODOT end --
|
|
|
|
+
|
|
|
|
/*! @fn spvReflectEnumerateEntryPointInputVariables
|
|
|
|
@brief Enumerate the input variables for a given entry point.
|
|
|
|
@param entry_point The name of the entry point to get the input variables for.
|