Debian Codegraph @

thirdparty/spirv-reflect/patches/0001-specialization-constants.patch

raw
1 diff --git a/thirdparty/spirv-reflect/spirv_reflect.c b/thirdparty/spirv-reflect/spirv_reflect.c
2 index b4f6bc17c2..ba64a3f54d 100644
3 --- a/thirdparty/spirv-reflect/spirv_reflect.c
4 +++ b/thirdparty/spirv-reflect/spirv_reflect.c
5 @@ -1571,6 +1571,8 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser, SpvRefle
6 } break;
7
8 case SpvDecorationSpecId: {
9 + uint32_t word_offset = p_node->word_offset + member_offset+ 3;
10 + CHECKED_READU32(p_parser, word_offset, p_target_decorations->spec_id);
11 spec_constant_count++;
12 } break;
13
14 @@ -1692,21 +1694,43 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser, SpvRefle
15 }
16 for (uint32_t i = 0; i < p_parser->node_count; ++i) {
17 SpvReflectPrvNode* p_node = &(p_parser->nodes[i]);
18 - if (p_node->op == SpvOpDecorate) {
19 - uint32_t decoration = (uint32_t)INVALID_VALUE;
20 - CHECKED_READU32(p_parser, p_node->word_offset + 2, decoration);
21 - if (decoration == SpvDecorationSpecId) {
22 - const uint32_t count = p_module->spec_constant_count;
23 - CHECKED_READU32(p_parser, p_node->word_offset + 1, p_module->spec_constants[count].spirv_id);
24 - CHECKED_READU32(p_parser, p_node->word_offset + 3, p_module->spec_constants[count].constant_id);
25 - // If being used for a OpSpecConstantComposite (ex. LocalSizeId), there won't be a name
26 - SpvReflectPrvNode* target_node = FindNode(p_parser, p_module->spec_constants[count].spirv_id);
27 - if (IsNotNull(target_node)) {
28 - p_module->spec_constants[count].name = target_node->name;
29 + const uint32_t count = p_module->spec_constant_count;
30 + switch(p_node->op) {
31 + default: continue;
32 + case SpvOpSpecConstantTrue: {
33 + p_module->spec_constants[count].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL;
34 + p_module->spec_constants[count].default_value.int_bool_value = 1;
35 + } break;
36 + case SpvOpSpecConstantFalse: {
37 + p_module->spec_constants[count].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL;
38 + p_module->spec_constants[count].default_value.int_bool_value = 0;
39 + } break;
40 + case SpvOpSpecConstant: {
41 + SpvReflectResult result = SPV_REFLECT_RESULT_SUCCESS;
42 + uint32_t element_type_id = (uint32_t)INVALID_VALUE;
43 + uint32_t default_value = 0;
44 + CHECKED_READU32(p_parser, p_node->word_offset + 1, element_type_id);
45 + CHECKED_READU32(p_parser, p_node->word_offset + 3, default_value);
46 +
47 + SpvReflectPrvNode* p_next_node = FindNode(p_parser, element_type_id);
48 +
49 + if (p_next_node->op == SpvOpTypeInt) {
50 + p_module->spec_constants[count].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_INT;
51 + } else if (p_next_node->op == SpvOpTypeFloat) {
52 + p_module->spec_constants[count].constant_type = SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT;
53 + } else {
54 + return SPV_REFLECT_RESULT_ERROR_PARSE_FAILED;
55 }
56 - p_module->spec_constant_count++;
57 - }
58 +
59 + p_module->spec_constants[count].default_value.int_bool_value = default_value; //bits are the same for int and float
60 + } break;
61 }
62 +
63 + p_module->spec_constants[count].name = p_node->name;
64 + p_module->spec_constants[count].constant_id = p_node->decorations.spec_id;
65 + p_module->spec_constants[count].spirv_id = p_node->result_id;
66 +
67 + p_module->spec_constant_count++;
68 }
69
70 return SPV_REFLECT_RESULT_SUCCESS;
71 diff --git a/thirdparty/spirv-reflect/spirv_reflect.h b/thirdparty/spirv-reflect/spirv_reflect.h
72 index 9a42f14eed..cf8cfe2183 100644
73 --- a/thirdparty/spirv-reflect/spirv_reflect.h
74 +++ b/thirdparty/spirv-reflect/spirv_reflect.h
75 @@ -568,6 +568,15 @@ typedef struct SpvReflectCapability {
76 } SpvReflectCapability;
77
78
79 +/*! @enum SpvReflectSpecializationConstantType
80 +
81 +*/
82 +typedef enum SpvReflectSpecializationConstantType {
83 + SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL = 0,
84 + SPV_REFLECT_SPECIALIZATION_CONSTANT_INT = 1,
85 + SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT = 2,
86 +} SpvReflectSpecializationConstantType;
87 +
88 /*! @struct SpvReflectSpecId
89
90 */
91 @@ -575,6 +584,11 @@ typedef struct SpvReflectSpecializationConstant {
92 uint32_t spirv_id;
93 uint32_t constant_id;
94 const char* name;
95 + SpvReflectSpecializationConstantType constant_type;
96 + union {
97 + float float_value;
98 + uint32_t int_bool_value;
99 + } default_value;
100 } SpvReflectSpecializationConstant;
101
102 /*! @struct SpvReflectShaderModule