Dejan Mircevski | b6fe02f | 2016-01-07 13:44:22 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 2 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 6 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 8 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 14 | |
dan sinclair | 58a6876 | 2018-08-03 08:05:33 -0400 | [diff] [blame] | 15 | #ifndef SOURCE_SPIRV_CONSTANT_H_ |
| 16 | #define SOURCE_SPIRV_CONSTANT_H_ |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 17 | |
dan sinclair | eda2cfb | 2018-08-03 15:06:09 -0400 | [diff] [blame] | 18 | #include "source/latest_version_spirv_header.h" |
David Neto | 5a70335 | 2016-02-17 14:44:00 -0500 | [diff] [blame] | 19 | #include "spirv-tools/libspirv.h" |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 20 | |
David Neto | 3d348a8 | 2015-11-12 19:40:21 -0500 | [diff] [blame] | 21 | // Version number macros. |
| 22 | |
| 23 | // Evaluates to a well-formed version header word, given valid |
David Neto | 8ddd4ec | 2015-11-17 16:37:10 -0500 | [diff] [blame] | 24 | // SPIR-V version major and minor version numbers. |
| 25 | #define SPV_SPIRV_VERSION_WORD(MAJOR, MINOR) \ |
| 26 | ((uint32_t(uint8_t(MAJOR)) << 16) | (uint32_t(uint8_t(MINOR)) << 8)) |
David Neto | 3d348a8 | 2015-11-12 19:40:21 -0500 | [diff] [blame] | 27 | // Returns the major version extracted from a version header word. |
| 28 | #define SPV_SPIRV_VERSION_MAJOR_PART(WORD) ((uint32_t(WORD) >> 16) & 0xff) |
| 29 | // Returns the minor version extracted from a version header word. |
| 30 | #define SPV_SPIRV_VERSION_MINOR_PART(WORD) ((uint32_t(WORD) >> 8) & 0xff) |
David Neto | 3d348a8 | 2015-11-12 19:40:21 -0500 | [diff] [blame] | 31 | |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 32 | // Header indices |
| 33 | |
| 34 | #define SPV_INDEX_MAGIC_NUMBER 0u |
| 35 | #define SPV_INDEX_VERSION_NUMBER 1u |
| 36 | #define SPV_INDEX_GENERATOR_NUMBER 2u |
| 37 | #define SPV_INDEX_BOUND 3u |
| 38 | #define SPV_INDEX_SCHEMA 4u |
| 39 | #define SPV_INDEX_INSTRUCTION 5u |
| 40 | |
| 41 | // Universal limits |
| 42 | |
| 43 | // SPIR-V 1.0 limits |
| 44 | #define SPV_LIMIT_INSTRUCTION_WORD_COUNT_MAX 0xffff |
| 45 | #define SPV_LIMIT_LITERAL_STRING_UTF8_CHARS_MAX 0xffff |
| 46 | |
| 47 | // A single Unicode character in UTF-8 encoding can take |
| 48 | // up 4 bytes. |
| 49 | #define SPV_LIMIT_LITERAL_STRING_BYTES_MAX \ |
| 50 | (SPV_LIMIT_LITERAL_STRING_UTF8_CHARS_MAX * 4) |
| 51 | |
| 52 | // NOTE: These are set to the minimum maximum values |
| 53 | // TODO(dneto): Check these. |
| 54 | |
| 55 | // libspirv limits. |
| 56 | #define SPV_LIMIT_RESULT_ID_BOUND 0x00400000 |
| 57 | #define SPV_LIMIT_CONTROL_FLOW_NEST_DEPTH 0x00000400 |
| 58 | #define SPV_LIMIT_GLOBAL_VARIABLES_MAX 0x00010000 |
| 59 | #define SPV_LIMIT_LOCAL_VARIABLES_MAX 0x00080000 |
| 60 | // TODO: Decorations per target ID max, depends on decoration table size |
| 61 | #define SPV_LIMIT_EXECUTION_MODE_PER_ENTRY_POINT_MAX 0x00000100 |
| 62 | #define SPV_LIMIT_INDICIES_MAX_ACCESS_CHAIN_COMPOSITE_MAX 0x00000100 |
| 63 | #define SPV_LIMIT_FUNCTION_PARAMETERS_PER_FUNCTION_DECL 0x00000100 |
| 64 | #define SPV_LIMIT_FUNCTION_CALL_ARGUMENTS_MAX 0x00000100 |
| 65 | #define SPV_LIMIT_EXT_FUNCTION_CALL_ARGUMENTS_MAX 0x00000100 |
| 66 | #define SPV_LIMIT_SWITCH_LITERAL_LABEL_PAIRS_MAX 0x00004000 |
| 67 | #define SPV_LIMIT_STRUCT_MEMBERS_MAX 0x0000400 |
| 68 | #define SPV_LIMIT_STRUCT_NESTING_DEPTH_MAX 0x00000100 |
| 69 | |
| 70 | // Enumerations |
| 71 | |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 72 | // Values mapping to registered tools. See the registry at |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 73 | // https://www.khronos.org/registry/spir-v/api/spir-v.xml |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 74 | // These values occupy the higher order 16 bits of the generator magic word. |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 75 | typedef enum spv_generator_t { |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 76 | // TODO(dneto) Values 0 through 5 were registered only as vendor. |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 77 | SPV_GENERATOR_KHRONOS = 0, |
| 78 | SPV_GENERATOR_LUNARG = 1, |
| 79 | SPV_GENERATOR_VALVE = 2, |
| 80 | SPV_GENERATOR_CODEPLAY = 3, |
| 81 | SPV_GENERATOR_NVIDIA = 4, |
| 82 | SPV_GENERATOR_ARM = 5, |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 83 | // These are vendor and tool. |
| 84 | SPV_GENERATOR_KHRONOS_LLVM_TRANSLATOR = 6, |
| 85 | SPV_GENERATOR_KHRONOS_ASSEMBLER = 7, |
David Neto | 2266ba1 | 2015-11-13 12:03:28 -0600 | [diff] [blame] | 86 | SPV_GENERATOR_KHRONOS_GLSLANG = 8, |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 87 | SPV_GENERATOR_NUM_ENTRIES, |
| 88 | SPV_FORCE_16_BIT_ENUM(spv_generator_t) |
Lei Zhang | aa056cd | 2015-11-11 14:24:04 -0500 | [diff] [blame] | 89 | } spv_generator_t; |
| 90 | |
David Neto | 14b93e4 | 2015-11-12 18:33:47 -0500 | [diff] [blame] | 91 | // Evaluates to a well-formed generator magic word from a tool value and |
| 92 | // miscellaneous 16-bit value. |
| 93 | #define SPV_GENERATOR_WORD(TOOL, MISC) \ |
| 94 | ((uint32_t(uint16_t(TOOL)) << 16) | uint16_t(MISC)) |
| 95 | // Returns the tool component of the generator word. |
| 96 | #define SPV_GENERATOR_TOOL_PART(WORD) (uint32_t(WORD) >> 16) |
| 97 | // Returns the misc part of the generator word. |
| 98 | #define SPV_GENERATOR_MISC_PART(WORD) (uint32_t(WORD) & 0xFFFF) |
| 99 | |
dan sinclair | 58a6876 | 2018-08-03 08:05:33 -0400 | [diff] [blame] | 100 | #endif // SOURCE_SPIRV_CONSTANT_H_ |