2
0

table.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_TABLE_H_
  15. #define SOURCE_TABLE_H_
  16. #include "source/extensions.h"
  17. #include "source/latest_version_spirv_header.h"
  18. #include "spirv-tools/libspirv.hpp"
  19. typedef struct spv_opcode_desc_t {
  20. const char* name;
  21. const spv::Op opcode;
  22. const uint32_t numAliases;
  23. const char** aliases;
  24. const uint32_t numCapabilities;
  25. const spv::Capability* capabilities;
  26. // operandTypes[0..numTypes-1] describe logical operands for the instruction.
  27. // The operand types include result id and result-type id, followed by
  28. // the types of arguments.
  29. const uint16_t numTypes;
  30. spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger?
  31. const bool hasResult; // Does the instruction have a result ID operand?
  32. const bool hasType; // Does the instruction have a type ID operand?
  33. // A set of extensions that enable this feature. If empty then this operand
  34. // value is in core and its availability is subject to minVersion. The
  35. // assembler, binary parser, and disassembler ignore this rule, so you can
  36. // freely process invalid modules.
  37. const uint32_t numExtensions;
  38. const spvtools::Extension* extensions;
  39. // Minimal core SPIR-V version required for this feature, if without
  40. // extensions. ~0u means reserved for future use. ~0u and non-empty extension
  41. // lists means only available in extensions.
  42. const uint32_t minVersion;
  43. const uint32_t lastVersion;
  44. } spv_opcode_desc_t;
  45. typedef struct spv_operand_desc_t {
  46. const char* name;
  47. const uint32_t value;
  48. const uint32_t numAliases;
  49. const char** aliases;
  50. const uint32_t numCapabilities;
  51. const spv::Capability* capabilities;
  52. // A set of extensions that enable this feature. If empty then this operand
  53. // value is in core and its availability is subject to minVersion. The
  54. // assembler, binary parser, and disassembler ignore this rule, so you can
  55. // freely process invalid modules.
  56. const uint32_t numExtensions;
  57. const spvtools::Extension* extensions;
  58. const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger?
  59. // Minimal core SPIR-V version required for this feature, if without
  60. // extensions. ~0u means reserved for future use. ~0u and non-empty extension
  61. // lists means only available in extensions.
  62. const uint32_t minVersion;
  63. const uint32_t lastVersion;
  64. } spv_operand_desc_t;
  65. typedef struct spv_operand_desc_group_t {
  66. const spv_operand_type_t type;
  67. const uint32_t count;
  68. const spv_operand_desc_t* entries;
  69. } spv_operand_desc_group_t;
  70. typedef struct spv_ext_inst_desc_t {
  71. const char* name;
  72. const uint32_t ext_inst;
  73. const uint32_t numCapabilities;
  74. const spv::Capability* capabilities;
  75. const spv_operand_type_t operandTypes[40]; // vksp needs at least 40
  76. } spv_ext_inst_desc_t;
  77. typedef struct spv_ext_inst_group_t {
  78. const spv_ext_inst_type_t type;
  79. const uint32_t count;
  80. const spv_ext_inst_desc_t* entries;
  81. } spv_ext_inst_group_t;
  82. typedef struct spv_opcode_table_t {
  83. const uint32_t count;
  84. const spv_opcode_desc_t* entries;
  85. } spv_opcode_table_t;
  86. typedef struct spv_operand_table_t {
  87. const uint32_t count;
  88. const spv_operand_desc_group_t* types;
  89. } spv_operand_table_t;
  90. typedef struct spv_ext_inst_table_t {
  91. const uint32_t count;
  92. const spv_ext_inst_group_t* groups;
  93. } spv_ext_inst_table_t;
  94. typedef const spv_opcode_desc_t* spv_opcode_desc;
  95. typedef const spv_operand_desc_t* spv_operand_desc;
  96. typedef const spv_ext_inst_desc_t* spv_ext_inst_desc;
  97. typedef const spv_opcode_table_t* spv_opcode_table;
  98. typedef const spv_operand_table_t* spv_operand_table;
  99. typedef const spv_ext_inst_table_t* spv_ext_inst_table;
  100. struct spv_context_t {
  101. const spv_target_env target_env;
  102. const spv_opcode_table opcode_table;
  103. const spv_operand_table operand_table;
  104. const spv_ext_inst_table ext_inst_table;
  105. spvtools::MessageConsumer consumer;
  106. };
  107. namespace spvtools {
  108. // Sets the message consumer to |consumer| in the given |context|. The original
  109. // message consumer will be overwritten.
  110. void SetContextMessageConsumer(spv_context context, MessageConsumer consumer);
  111. } // namespace spvtools
  112. // Populates *table with entries for env.
  113. spv_result_t spvOpcodeTableGet(spv_opcode_table* table, spv_target_env env);
  114. // Populates *table with entries for env.
  115. spv_result_t spvOperandTableGet(spv_operand_table* table, spv_target_env env);
  116. // Populates *table with entries for env.
  117. spv_result_t spvExtInstTableGet(spv_ext_inst_table* table, spv_target_env env);
  118. #endif // SOURCE_TABLE_H_