Home | History | Annotate | Download | only in source
      1 // Copyright (c) 2015-2016 The Khronos Group Inc.
      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 
     27 #ifndef LIBSPIRV_SPIRV_CONSTANT_H_
     28 #define LIBSPIRV_SPIRV_CONSTANT_H_
     29 
     30 #include "spirv-tools/libspirv.h"
     31 #include "spirv/1.1/spirv.h"
     32 
     33 // Version number macros.
     34 
     35 // Evaluates to a well-formed version header word, given valid
     36 // SPIR-V version major and minor version numbers.
     37 #define SPV_SPIRV_VERSION_WORD(MAJOR, MINOR) \
     38   ((uint32_t(uint8_t(MAJOR)) << 16) | (uint32_t(uint8_t(MINOR)) << 8))
     39 // Returns the major version extracted from a version header word.
     40 #define SPV_SPIRV_VERSION_MAJOR_PART(WORD) ((uint32_t(WORD) >> 16) & 0xff)
     41 // Returns the minor version extracted from a version header word.
     42 #define SPV_SPIRV_VERSION_MINOR_PART(WORD) ((uint32_t(WORD) >> 8) & 0xff)
     43 
     44 // Returns the version number for the given SPIR-V target environment.
     45 uint32_t spvVersionForTargetEnv(spv_target_env env);
     46 
     47 // Header indices
     48 
     49 #define SPV_INDEX_MAGIC_NUMBER 0u
     50 #define SPV_INDEX_VERSION_NUMBER 1u
     51 #define SPV_INDEX_GENERATOR_NUMBER 2u
     52 #define SPV_INDEX_BOUND 3u
     53 #define SPV_INDEX_SCHEMA 4u
     54 #define SPV_INDEX_INSTRUCTION 5u
     55 
     56 // Universal limits
     57 
     58 // SPIR-V 1.0 limits
     59 #define SPV_LIMIT_INSTRUCTION_WORD_COUNT_MAX 0xffff
     60 #define SPV_LIMIT_LITERAL_STRING_UTF8_CHARS_MAX 0xffff
     61 
     62 // A single Unicode character in UTF-8 encoding can take
     63 // up 4 bytes.
     64 #define SPV_LIMIT_LITERAL_STRING_BYTES_MAX \
     65   (SPV_LIMIT_LITERAL_STRING_UTF8_CHARS_MAX * 4)
     66 
     67 // NOTE: These are set to the minimum maximum values
     68 // TODO(dneto): Check these.
     69 
     70 // libspirv limits.
     71 #define SPV_LIMIT_RESULT_ID_BOUND 0x00400000
     72 #define SPV_LIMIT_CONTROL_FLOW_NEST_DEPTH 0x00000400
     73 #define SPV_LIMIT_GLOBAL_VARIABLES_MAX 0x00010000
     74 #define SPV_LIMIT_LOCAL_VARIABLES_MAX 0x00080000
     75 // TODO: Decorations per target ID max, depends on decoration table size
     76 #define SPV_LIMIT_EXECUTION_MODE_PER_ENTRY_POINT_MAX 0x00000100
     77 #define SPV_LIMIT_INDICIES_MAX_ACCESS_CHAIN_COMPOSITE_MAX 0x00000100
     78 #define SPV_LIMIT_FUNCTION_PARAMETERS_PER_FUNCTION_DECL 0x00000100
     79 #define SPV_LIMIT_FUNCTION_CALL_ARGUMENTS_MAX 0x00000100
     80 #define SPV_LIMIT_EXT_FUNCTION_CALL_ARGUMENTS_MAX 0x00000100
     81 #define SPV_LIMIT_SWITCH_LITERAL_LABEL_PAIRS_MAX 0x00004000
     82 #define SPV_LIMIT_STRUCT_MEMBERS_MAX 0x0000400
     83 #define SPV_LIMIT_STRUCT_NESTING_DEPTH_MAX 0x00000100
     84 
     85 // Enumerations
     86 
     87 // Values mapping to registered tools.  See the registry at
     88 // https://www.khronos.org/registry/spir-v/api/spir-v.xml
     89 // These values occupy the higher order 16 bits of the generator magic word.
     90 typedef enum spv_generator_t {
     91   // TODO(dneto) Values 0 through 5 were registered only as vendor.
     92   SPV_GENERATOR_KHRONOS = 0,
     93   SPV_GENERATOR_LUNARG = 1,
     94   SPV_GENERATOR_VALVE = 2,
     95   SPV_GENERATOR_CODEPLAY = 3,
     96   SPV_GENERATOR_NVIDIA = 4,
     97   SPV_GENERATOR_ARM = 5,
     98   // These are vendor and tool.
     99   SPV_GENERATOR_KHRONOS_LLVM_TRANSLATOR = 6,
    100   SPV_GENERATOR_KHRONOS_ASSEMBLER = 7,
    101   SPV_GENERATOR_KHRONOS_GLSLANG = 8,
    102   SPV_GENERATOR_NUM_ENTRIES,
    103   SPV_FORCE_16_BIT_ENUM(spv_generator_t)
    104 } spv_generator_t;
    105 
    106 // Evaluates to a well-formed generator magic word from a tool value and
    107 // miscellaneous 16-bit value.
    108 #define SPV_GENERATOR_WORD(TOOL, MISC) \
    109   ((uint32_t(uint16_t(TOOL)) << 16) | uint16_t(MISC))
    110 // Returns the tool component of the generator word.
    111 #define SPV_GENERATOR_TOOL_PART(WORD) (uint32_t(WORD) >> 16)
    112 // Returns the misc part of the generator word.
    113 #define SPV_GENERATOR_MISC_PART(WORD) (uint32_t(WORD) & 0xFFFF)
    114 
    115 #endif  // LIBSPIRV_SPIRV_CONSTANT_H_
    116