Dejan Mircevski | b6fe02f | 2016-01-07 13:44:22 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
Lei Zhang | 2a0b773 | 2015-11-11 13:57:43 -0500 | [diff] [blame] | 2 | // |
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | // copy of this software and/or associated documentation files (the |
| 5 | // "Materials"), to deal in the Materials without restriction, including |
| 6 | // without limitation the rights to use, copy, modify, merge, publish, |
| 7 | // distribute, sublicense, and/or sell copies of the Materials, and to |
| 8 | // permit persons to whom the Materials are furnished to do so, subject to |
| 9 | // the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included |
| 12 | // in all copies or substantial portions of the Materials. |
| 13 | // |
| 14 | // MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
| 15 | // KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
| 16 | // SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
| 17 | // https://www.khronos.org/registry/ |
| 18 | // |
| 19 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 22 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 23 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 24 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 25 | // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 26 | |
Lei Zhang | 7a222e4 | 2015-11-11 12:40:25 -0500 | [diff] [blame] | 27 | #include "ext_inst.h" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 28 | |
| 29 | #include <string.h> |
| 30 | |
Lei Zhang | 6fa3f8a | 2016-03-31 17:26:31 -0400 | [diff] [blame] | 31 | #include "spirv/GLSL.std.450.h" |
| 32 | #include "spirv/OpenCL.std.h" |
David Neto | d1bb51d | 2016-02-17 12:17:04 -0500 | [diff] [blame] | 33 | #include "spirv_definition.h" |
| 34 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 35 | static const spv_ext_inst_desc_t glslStd450Entries[] = { |
Dejan Mircevski | e26fdc6 | 2016-04-07 14:09:48 -0400 | [diff] [blame^] | 36 | #include "glsl.std.450.insts-1-0.inc" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 39 | static const spv_ext_inst_desc_t openclEntries[] = { |
Dejan Mircevski | e26fdc6 | 2016-04-07 14:09:48 -0400 | [diff] [blame^] | 40 | #include "opencl.std.insts-1-0.inc" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 43 | spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 44 | if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 45 | |
| 46 | static const spv_ext_inst_group_t groups[] = { |
| 47 | {SPV_EXT_INST_TYPE_GLSL_STD_450, |
David Neto | ba73a7c | 2016-01-06 13:08:39 -0500 | [diff] [blame] | 48 | static_cast<uint32_t>(sizeof(glslStd450Entries) / |
| 49 | sizeof(spv_ext_inst_desc_t)), |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 50 | glslStd450Entries}, |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 51 | {SPV_EXT_INST_TYPE_OPENCL_STD, |
David Neto | ba73a7c | 2016-01-06 13:08:39 -0500 | [diff] [blame] | 52 | static_cast<uint32_t>(sizeof(openclEntries) / |
| 53 | sizeof(spv_ext_inst_desc_t)), |
| 54 | openclEntries}, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static const spv_ext_inst_table_t table = { |
David Neto | ba73a7c | 2016-01-06 13:08:39 -0500 | [diff] [blame] | 58 | static_cast<uint32_t>(sizeof(groups) / sizeof(spv_ext_inst_group_t)), |
| 59 | groups}; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 60 | |
| 61 | *pExtInstTable = &table; |
| 62 | |
| 63 | return SPV_SUCCESS; |
| 64 | } |
| 65 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 66 | spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) { |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 67 | // The names are specified by the respective extension instruction |
| 68 | // specifications. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 69 | if (!strcmp("GLSL.std.450", name)) { |
| 70 | return SPV_EXT_INST_TYPE_GLSL_STD_450; |
| 71 | } |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 72 | if (!strcmp("OpenCL.std", name)) { |
| 73 | return SPV_EXT_INST_TYPE_OPENCL_STD; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 74 | } |
| 75 | return SPV_EXT_INST_TYPE_NONE; |
| 76 | } |
| 77 | |
| 78 | spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table, |
| 79 | const spv_ext_inst_type_t type, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 80 | const char* name, |
| 81 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 82 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 83 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 84 | |
| 85 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 86 | auto& group = table->groups[groupIndex]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 87 | if (type == group.type) { |
| 88 | for (uint32_t index = 0; index < group.count; index++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 89 | auto& entry = group.entries[index]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 90 | if (!strcmp(name, entry.name)) { |
| 91 | *pEntry = &table->groups[groupIndex].entries[index]; |
| 92 | return SPV_SUCCESS; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return SPV_ERROR_INVALID_LOOKUP; |
| 99 | } |
| 100 | |
| 101 | spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table, |
| 102 | const spv_ext_inst_type_t type, |
| 103 | const uint32_t value, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 104 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 105 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 106 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 107 | |
| 108 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 109 | auto& group = table->groups[groupIndex]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 110 | if (type == group.type) { |
| 111 | for (uint32_t index = 0; index < group.count; index++) { |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 112 | auto& entry = group.entries[index]; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 113 | if (value == entry.ext_inst) { |
| 114 | *pEntry = &table->groups[groupIndex].entries[index]; |
| 115 | return SPV_SUCCESS; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return SPV_ERROR_INVALID_LOOKUP; |
| 122 | } |