Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 1 | #include <libspirv/libspirv.h> |
| 2 | |
| 3 | #include <string.h> |
| 4 | |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 5 | /// Generate a spv_ext_inst_desc_t literal for a GLSL std450 extended |
| 6 | /// instruction with one/two/three <id> parameter(s). |
| 7 | #define GLSL450Inst1(name) \ |
Lei Zhang | dca65b3 | 2015-08-27 10:00:16 -0400 | [diff] [blame] | 8 | #name, GLSLstd450::GLSLstd450##name, { SPV_OPERAND_TYPE_ID } |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 9 | #define GLSL450Inst2(name) \ |
Lei Zhang | dca65b3 | 2015-08-27 10:00:16 -0400 | [diff] [blame] | 10 | #name, GLSLstd450::GLSLstd450##name, { \ |
| 11 | SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_ID \ |
| 12 | } |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 13 | #define GLSL450Inst3(name) \ |
Lei Zhang | dca65b3 | 2015-08-27 10:00:16 -0400 | [diff] [blame] | 14 | #name, GLSLstd450::GLSLstd450##name, { \ |
| 15 | SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_ID, SPV_OPERAND_TYPE_ID \ |
| 16 | } |
Andrew Woloszyn | 1d2a87e | 2015-08-21 13:39:34 -0400 | [diff] [blame] | 17 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 18 | static const spv_ext_inst_desc_t glslStd450Entries[] = { |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 19 | {GLSL450Inst1(Round)}, |
| 20 | {GLSL450Inst1(RoundEven)}, |
| 21 | {GLSL450Inst1(Trunc)}, |
| 22 | {GLSL450Inst1(FAbs)}, |
| 23 | {GLSL450Inst1(SAbs)}, |
| 24 | {GLSL450Inst1(FSign)}, |
| 25 | {GLSL450Inst1(SSign)}, |
| 26 | {GLSL450Inst1(Floor)}, |
| 27 | {GLSL450Inst1(Ceil)}, |
| 28 | {GLSL450Inst1(Fract)}, |
| 29 | {GLSL450Inst1(Radians)}, |
| 30 | {GLSL450Inst1(Degrees)}, |
| 31 | {GLSL450Inst1(Sin)}, |
| 32 | {GLSL450Inst1(Cos)}, |
| 33 | {GLSL450Inst1(Tan)}, |
| 34 | {GLSL450Inst1(Asin)}, |
| 35 | {GLSL450Inst1(Acos)}, |
| 36 | {GLSL450Inst1(Atan)}, |
| 37 | {GLSL450Inst1(Sinh)}, |
| 38 | {GLSL450Inst1(Cosh)}, |
| 39 | {GLSL450Inst1(Tanh)}, |
| 40 | {GLSL450Inst1(Asinh)}, |
| 41 | {GLSL450Inst1(Acosh)}, |
| 42 | {GLSL450Inst1(Atanh)}, |
| 43 | {GLSL450Inst2(Atan2)}, |
| 44 | {GLSL450Inst2(Pow)}, |
| 45 | {GLSL450Inst1(Exp)}, |
| 46 | {GLSL450Inst1(Log)}, |
| 47 | {GLSL450Inst1(Exp2)}, |
| 48 | {GLSL450Inst1(Log2)}, |
| 49 | {GLSL450Inst1(Sqrt)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 50 | {GLSL450Inst1(InverseSqrt)}, |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 51 | {GLSL450Inst1(Determinant)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 52 | {GLSL450Inst1(MatrixInverse)}, |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 53 | {GLSL450Inst2(Modf)}, |
| 54 | {GLSL450Inst1(ModfStruct)}, |
| 55 | {GLSL450Inst2(FMin)}, |
| 56 | {GLSL450Inst2(UMin)}, |
| 57 | {GLSL450Inst2(SMin)}, |
| 58 | {GLSL450Inst2(FMax)}, |
| 59 | {GLSL450Inst2(UMax)}, |
| 60 | {GLSL450Inst2(SMax)}, |
| 61 | {GLSL450Inst3(FClamp)}, |
| 62 | {GLSL450Inst3(UClamp)}, |
| 63 | {GLSL450Inst3(SClamp)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 64 | {GLSL450Inst3(FMix)}, |
| 65 | {GLSL450Inst3(IMix)}, |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 66 | {GLSL450Inst2(Step)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 67 | {GLSL450Inst3(SmoothStep)}, |
Lei Zhang | 2d879b9 | 2015-08-27 11:22:14 -0400 | [diff] [blame] | 68 | {GLSL450Inst3(Fma)}, |
| 69 | {GLSL450Inst2(Frexp)}, |
| 70 | {GLSL450Inst1(FrexpStruct)}, |
| 71 | {GLSL450Inst2(Ldexp)}, |
Dejan Mircevski | afdbd2d | 2015-08-27 13:57:08 -0400 | [diff] [blame] | 72 | {GLSL450Inst1(PackSnorm4x8)}, |
| 73 | {GLSL450Inst1(PackUnorm4x8)}, |
| 74 | {GLSL450Inst1(PackSnorm2x16)}, |
| 75 | {GLSL450Inst1(PackUnorm2x16)}, |
| 76 | {GLSL450Inst1(PackHalf2x16)}, |
| 77 | {GLSL450Inst1(PackDouble2x32)}, |
| 78 | {GLSL450Inst1(UnpackSnorm2x16)}, |
| 79 | {GLSL450Inst1(UnpackUnorm2x16)}, |
| 80 | {GLSL450Inst1(UnpackHalf2x16)}, |
| 81 | {GLSL450Inst1(UnpackSnorm4x8)}, |
| 82 | {GLSL450Inst1(UnpackUnorm4x8)}, |
| 83 | {GLSL450Inst1(UnpackDouble2x32)}, |
Lei Zhang | 3cb5896 | 2015-08-27 13:44:31 -0400 | [diff] [blame] | 84 | {GLSL450Inst1(Length)}, |
| 85 | {GLSL450Inst2(Distance)}, |
| 86 | {GLSL450Inst2(Cross)}, |
| 87 | {GLSL450Inst1(Normalize)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 88 | {GLSL450Inst3(FaceForward)}, |
Lei Zhang | 3cb5896 | 2015-08-27 13:44:31 -0400 | [diff] [blame] | 89 | {GLSL450Inst2(Reflect)}, |
| 90 | {GLSL450Inst3(Refract)}, |
David Neto | dbaf407 | 2015-09-22 16:23:06 -0400 | [diff] [blame] | 91 | {GLSL450Inst1(FindILsb)}, |
| 92 | {GLSL450Inst1(FindSMsb)}, |
| 93 | {GLSL450Inst1(FindUMsb)}, |
Lei Zhang | 5b73214 | 2015-08-27 14:20:19 -0400 | [diff] [blame] | 94 | {GLSL450Inst1(InterpolateAtCentroid)}, |
| 95 | {GLSL450Inst2(InterpolateAtSample)}, |
| 96 | {GLSL450Inst2(InterpolateAtOffset)}, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 97 | }; |
| 98 | |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 99 | static const spv_ext_inst_desc_t openclEntries[] = { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 100 | #define ExtInst(Name, Opcode, OperandList) \ |
| 101 | { #Name, Opcode, OperandList } \ |
| 102 | , |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 103 | #define EmptyList \ |
| 104 | {} |
| 105 | #define List(...) \ |
| 106 | { __VA_ARGS__ } |
| 107 | #define OperandId SPV_OPERAND_TYPE_ID |
David Neto | 1bb8b70 | 2015-10-16 14:16:00 -0400 | [diff] [blame] | 108 | #define OperandLiteralNumber SPV_OPERAND_TYPE_LITERAL_INTEGER |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 109 | #define OperandFPRoundingMode SPV_OPERAND_TYPE_FP_ROUNDING_MODE |
| 110 | #define OperandVariableIds SPV_OPERAND_TYPE_VARIABLE_ID |
| 111 | #include "opencl_std_ext_inst.inc" |
| 112 | #undef ExtList |
| 113 | #undef EmptyList |
| 114 | #undef List |
| 115 | #undef OperandId |
| 116 | #undef OperandLiteralNumber |
| 117 | #undef OperandFPRoundingMode |
| 118 | #undef OperandVariableIds |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 121 | spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 122 | if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 123 | |
| 124 | static const spv_ext_inst_group_t groups[] = { |
| 125 | {SPV_EXT_INST_TYPE_GLSL_STD_450, |
| 126 | sizeof(glslStd450Entries) / sizeof(spv_ext_inst_desc_t), |
| 127 | glslStd450Entries}, |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 128 | {SPV_EXT_INST_TYPE_OPENCL_STD, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 129 | sizeof(openclEntries) / sizeof(spv_ext_inst_desc_t), openclEntries}, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | static const spv_ext_inst_table_t table = { |
| 133 | sizeof(groups) / sizeof(spv_ext_inst_group_t), groups}; |
| 134 | |
| 135 | *pExtInstTable = &table; |
| 136 | |
| 137 | return SPV_SUCCESS; |
| 138 | } |
| 139 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 140 | spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) { |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 141 | // The names are specified by the respective extension instruction |
| 142 | // specifications. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 143 | if (!strcmp("GLSL.std.450", name)) { |
| 144 | return SPV_EXT_INST_TYPE_GLSL_STD_450; |
| 145 | } |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 146 | if (!strcmp("OpenCL.std", name)) { |
| 147 | return SPV_EXT_INST_TYPE_OPENCL_STD; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 148 | } |
| 149 | return SPV_EXT_INST_TYPE_NONE; |
| 150 | } |
| 151 | |
| 152 | spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table, |
| 153 | const spv_ext_inst_type_t type, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 154 | const char* name, |
| 155 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 156 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 157 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 158 | |
| 159 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 160 | auto& group = table->groups[groupIndex]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 161 | if (type == group.type) { |
| 162 | for (uint32_t index = 0; index < group.count; index++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 163 | auto& entry = group.entries[index]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 164 | if (!strcmp(name, entry.name)) { |
| 165 | *pEntry = &table->groups[groupIndex].entries[index]; |
| 166 | return SPV_SUCCESS; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return SPV_ERROR_INVALID_LOOKUP; |
| 173 | } |
| 174 | |
| 175 | spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table, |
| 176 | const spv_ext_inst_type_t type, |
| 177 | const uint32_t value, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 178 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 179 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 180 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 181 | |
| 182 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 183 | auto& group = table->groups[groupIndex]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 184 | if (type == group.type) { |
| 185 | for (uint32_t index = 0; index < group.count; index++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 186 | auto& entry = group.entries[index]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 187 | if (value == entry.ext_inst) { |
| 188 | *pEntry = &table->groups[groupIndex].entries[index]; |
| 189 | return SPV_SUCCESS; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return SPV_ERROR_INVALID_LOOKUP; |
| 196 | } |