spirv_constant.h 3.8 KB

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