doc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // Copyright (C) 2014-2015 LunarG, Inc.
  3. //
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions
  8. // are met:
  9. //
  10. // Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. //
  13. // Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following
  15. // disclaimer in the documentation and/or other materials provided
  16. // with the distribution.
  17. //
  18. // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19. // contributors may be used to endorse or promote products derived
  20. // from this software without specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. // POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. // Parameterize the SPIR-V enumerants.
  36. //
  37. #pragma once
  38. #include "spirv.hpp"
  39. #include <vector>
  40. namespace spv {
  41. // Fill in all the parameters
  42. void Parameterize();
  43. // Return the English names of all the enums.
  44. const char* SourceString(int);
  45. const char* AddressingString(int);
  46. const char* MemoryString(int);
  47. const char* ExecutionModelString(int);
  48. const char* ExecutionModeString(int);
  49. const char* StorageClassString(int);
  50. const char* DecorationString(int);
  51. const char* BuiltInString(int);
  52. const char* DimensionString(int);
  53. const char* SelectControlString(int);
  54. const char* LoopControlString(int);
  55. const char* FunctionControlString(int);
  56. const char* SamplerAddressingModeString(int);
  57. const char* SamplerFilterModeString(int);
  58. const char* ImageFormatString(int);
  59. const char* ImageChannelOrderString(int);
  60. const char* ImageChannelTypeString(int);
  61. const char* ImageChannelDataTypeString(int type);
  62. const char* ImageOperandsString(int format);
  63. const char* ImageOperands(int);
  64. const char* FPFastMathString(int);
  65. const char* FPRoundingModeString(int);
  66. const char* LinkageTypeString(int);
  67. const char* FuncParamAttrString(int);
  68. const char* AccessQualifierString(int);
  69. const char* MemorySemanticsString(int);
  70. const char* MemoryAccessString(int);
  71. const char* ExecutionScopeString(int);
  72. const char* GroupOperationString(int);
  73. const char* KernelEnqueueFlagsString(int);
  74. const char* KernelProfilingInfoString(int);
  75. const char* CapabilityString(int);
  76. const char* OpcodeString(int);
  77. const char* ScopeString(int mem);
  78. // For grouping opcodes into subsections
  79. enum OpcodeClass {
  80. OpClassMisc,
  81. OpClassDebug,
  82. OpClassAnnotate,
  83. OpClassExtension,
  84. OpClassMode,
  85. OpClassType,
  86. OpClassConstant,
  87. OpClassMemory,
  88. OpClassFunction,
  89. OpClassImage,
  90. OpClassConvert,
  91. OpClassComposite,
  92. OpClassArithmetic,
  93. OpClassBit,
  94. OpClassRelationalLogical,
  95. OpClassDerivative,
  96. OpClassFlowControl,
  97. OpClassAtomic,
  98. OpClassPrimitive,
  99. OpClassBarrier,
  100. OpClassGroup,
  101. OpClassDeviceSideEnqueue,
  102. OpClassPipe,
  103. OpClassCount,
  104. OpClassMissing // all instructions start out as missing
  105. };
  106. // For parameterizing operands.
  107. enum OperandClass {
  108. OperandNone,
  109. OperandId,
  110. OperandVariableIds,
  111. OperandOptionalLiteral,
  112. OperandOptionalLiteralString,
  113. OperandVariableLiterals,
  114. OperandVariableIdLiteral,
  115. OperandVariableLiteralId,
  116. OperandLiteralNumber,
  117. OperandLiteralString,
  118. OperandSource,
  119. OperandExecutionModel,
  120. OperandAddressing,
  121. OperandMemory,
  122. OperandExecutionMode,
  123. OperandStorage,
  124. OperandDimensionality,
  125. OperandSamplerAddressingMode,
  126. OperandSamplerFilterMode,
  127. OperandSamplerImageFormat,
  128. OperandImageChannelOrder,
  129. OperandImageChannelDataType,
  130. OperandImageOperands,
  131. OperandFPFastMath,
  132. OperandFPRoundingMode,
  133. OperandLinkageType,
  134. OperandAccessQualifier,
  135. OperandFuncParamAttr,
  136. OperandDecoration,
  137. OperandBuiltIn,
  138. OperandSelect,
  139. OperandLoop,
  140. OperandFunction,
  141. OperandMemorySemantics,
  142. OperandMemoryAccess,
  143. OperandScope,
  144. OperandGroupOperation,
  145. OperandKernelEnqueueFlags,
  146. OperandKernelProfilingInfo,
  147. OperandCapability,
  148. OperandOpcode,
  149. OperandCount
  150. };
  151. // Any specific enum can have a set of capabilities that allow it:
  152. typedef std::vector<Capability> EnumCaps;
  153. // Parameterize a set of operands with their OperandClass(es) and descriptions.
  154. class OperandParameters {
  155. public:
  156. OperandParameters() { }
  157. void push(OperandClass oc, const char* d, bool opt = false)
  158. {
  159. opClass.push_back(oc);
  160. desc.push_back(d);
  161. optional.push_back(opt);
  162. }
  163. void setOptional();
  164. OperandClass getClass(int op) const { return opClass[op]; }
  165. const char* getDesc(int op) const { return desc[op]; }
  166. bool isOptional(int op) const { return optional[op]; }
  167. int getNum() const { return (int)opClass.size(); }
  168. protected:
  169. std::vector<OperandClass> opClass;
  170. std::vector<const char*> desc;
  171. std::vector<bool> optional;
  172. };
  173. // Parameterize an enumerant
  174. class EnumParameters {
  175. public:
  176. EnumParameters() : desc(0) { }
  177. const char* desc;
  178. };
  179. // Parameterize a set of enumerants that form an enum
  180. class EnumDefinition : public EnumParameters {
  181. public:
  182. EnumDefinition() :
  183. ceiling(0), bitmask(false), getName(0), enumParams(0), operandParams(0) { }
  184. void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
  185. {
  186. ceiling = ceil;
  187. getName = name;
  188. bitmask = mask;
  189. enumParams = ep;
  190. }
  191. void setOperands(OperandParameters* op) { operandParams = op; }
  192. int ceiling; // ceiling of enumerants
  193. bool bitmask; // true if these enumerants combine into a bitmask
  194. const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
  195. EnumParameters* enumParams; // parameters for each individual enumerant
  196. OperandParameters* operandParams; // sets of operands
  197. };
  198. // Parameterize an instruction's logical format, including its known set of operands,
  199. // per OperandParameters above.
  200. class InstructionParameters {
  201. public:
  202. InstructionParameters() :
  203. opDesc("TBD"),
  204. opClass(OpClassMissing),
  205. typePresent(true), // most normal, only exceptions have to be spelled out
  206. resultPresent(true) // most normal, only exceptions have to be spelled out
  207. { }
  208. void setResultAndType(bool r, bool t)
  209. {
  210. resultPresent = r;
  211. typePresent = t;
  212. }
  213. bool hasResult() const { return resultPresent != 0; }
  214. bool hasType() const { return typePresent != 0; }
  215. const char* opDesc;
  216. OpcodeClass opClass;
  217. OperandParameters operands;
  218. protected:
  219. int typePresent : 1;
  220. int resultPresent : 1;
  221. };
  222. // The set of objects that hold all the instruction/operand
  223. // parameterization information.
  224. extern InstructionParameters InstructionDesc[];
  225. // These hold definitions of the enumerants used for operands
  226. extern EnumDefinition OperandClassParams[];
  227. const char* GetOperandDesc(OperandClass operand);
  228. void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
  229. const char* AccessQualifierString(int attr);
  230. void PrintOperands(const OperandParameters& operands, int reservedOperands);
  231. } // end namespace spv