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 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 29 | #include <cassert> |
| 30 | #include <cstring> |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 31 | |
Lei Zhang | 10dba91 | 2016-04-14 14:05:53 -0400 | [diff] [blame] | 32 | #include "spirv/1.0/GLSL.std.450.h" |
| 33 | #include "spirv/1.0/OpenCL.std.h" |
David Neto | d1bb51d | 2016-02-17 12:17:04 -0500 | [diff] [blame] | 34 | #include "spirv_definition.h" |
| 35 | |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 36 | #include "macro.h" |
| 37 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 38 | static const spv_ext_inst_desc_t glslStd450Entries_1_0[] = { |
Lei Zhang | 10dba91 | 2016-04-14 14:05:53 -0400 | [diff] [blame] | 39 | #include "glsl.std.450.insts-1.0.inc" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 42 | static const spv_ext_inst_desc_t openclEntries_1_0[] = { |
Lei Zhang | 10dba91 | 2016-04-14 14:05:53 -0400 | [diff] [blame] | 43 | #include "opencl.std.insts-1.0.inc" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 44 | }; |
| 45 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 46 | spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable, |
| 47 | spv_target_env env) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 48 | if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 49 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 50 | static const spv_ext_inst_group_t groups_1_0[] = { |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 51 | {SPV_EXT_INST_TYPE_GLSL_STD_450, ARRAY_SIZE(glslStd450Entries_1_0), |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 52 | glslStd450Entries_1_0}, |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 53 | {SPV_EXT_INST_TYPE_OPENCL_STD, ARRAY_SIZE(openclEntries_1_0), |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 54 | openclEntries_1_0}, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 57 | static const spv_ext_inst_table_t table_1_0 = {ARRAY_SIZE(groups_1_0), |
| 58 | groups_1_0}; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 59 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 60 | switch (env) { |
| 61 | // The extended instruction sets are all version 1.0 so far. |
| 62 | case SPV_ENV_UNIVERSAL_1_0: |
| 63 | case SPV_ENV_VULKAN_1_0: |
| 64 | case SPV_ENV_UNIVERSAL_1_1: |
David Neto | c296701 | 2016-08-05 18:19:30 -0400 | [diff] [blame^] | 65 | case SPV_ENV_OPENCL_2_1: |
| 66 | case SPV_ENV_OPENCL_2_2: |
| 67 | case SPV_ENV_OPENGL_4_0: |
| 68 | case SPV_ENV_OPENGL_4_1: |
| 69 | case SPV_ENV_OPENGL_4_2: |
| 70 | case SPV_ENV_OPENGL_4_3: |
| 71 | case SPV_ENV_OPENGL_4_5: |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 72 | *pExtInstTable = &table_1_0; |
| 73 | return SPV_SUCCESS; |
| 74 | default: |
| 75 | assert(0 && "Unknown spv_target_env in spvExtInstTableGet()"); |
| 76 | return SPV_ERROR_INVALID_TABLE; |
| 77 | } |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 80 | spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) { |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 81 | // The names are specified by the respective extension instruction |
| 82 | // specifications. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 83 | if (!strcmp("GLSL.std.450", name)) { |
| 84 | return SPV_EXT_INST_TYPE_GLSL_STD_450; |
| 85 | } |
David Neto | 21c4ad4 | 2015-10-14 17:02:11 -0400 | [diff] [blame] | 86 | if (!strcmp("OpenCL.std", name)) { |
| 87 | return SPV_EXT_INST_TYPE_OPENCL_STD; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 88 | } |
| 89 | return SPV_EXT_INST_TYPE_NONE; |
| 90 | } |
| 91 | |
| 92 | spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table, |
| 93 | const spv_ext_inst_type_t type, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 94 | const char* name, |
| 95 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 96 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 97 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 98 | |
| 99 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 100 | const auto& group = table->groups[groupIndex]; |
| 101 | if (type != group.type) continue; |
| 102 | for (uint32_t index = 0; index < group.count; index++) { |
| 103 | const auto& entry = group.entries[index]; |
| 104 | if (!strcmp(name, entry.name)) { |
| 105 | *pEntry = &entry; |
| 106 | return SPV_SUCCESS; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return SPV_ERROR_INVALID_LOOKUP; |
| 112 | } |
| 113 | |
| 114 | spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table, |
| 115 | const spv_ext_inst_type_t type, |
| 116 | const uint32_t value, |
Lei Zhang | 1a0334e | 2015-11-02 09:41:20 -0500 | [diff] [blame] | 117 | spv_ext_inst_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 118 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 119 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 120 | |
| 121 | for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 122 | const auto& group = table->groups[groupIndex]; |
| 123 | if (type != group.type) continue; |
| 124 | for (uint32_t index = 0; index < group.count; index++) { |
| 125 | const auto& entry = group.entries[index]; |
| 126 | if (value == entry.ext_inst) { |
| 127 | *pEntry = &entry; |
| 128 | return SPV_SUCCESS; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return SPV_ERROR_INVALID_LOOKUP; |
| 134 | } |