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//
36// Parameterize the SPIR-V enumerants.
37//
38
39#pragma once
40
41#include "spirv.hpp"
42
43#include <vector>
44
45namespace spv {
46
47// Fill in all the parameters
48void Parameterize();
49
50// Return the English names of all the enums.
51const char* SourceString(int);
52const char* AddressingString(int);
53const char* MemoryString(int);
54const char* ExecutionModelString(int);
55const char* ExecutionModeString(int);
56const char* StorageClassString(int);
57const char* DecorationString(int);
58const char* BuiltInString(int);
59const char* DimensionString(int);
60const char* SelectControlString(int);
61const char* LoopControlString(int);
62const char* FunctionControlString(int);
63const char* SamplerAddressingModeString(int);
64const char* SamplerFilterModeString(int);
65const char* ImageFormatString(int);
66const char* ImageChannelOrderString(int);
67const char* ImageChannelTypeString(int);
68const char* ImageChannelDataTypeString(int type);
69const char* ImageOperandsString(int format);
70const char* ImageOperands(int);
71const char* FPFastMathString(int);
72const char* FPRoundingModeString(int);
73const char* LinkageTypeString(int);
74const char* FuncParamAttrString(int);
75const char* AccessQualifierString(int);
76const char* MemorySemanticsString(int);
77const char* MemoryAccessString(int);
78const char* ExecutionScopeString(int);
79const char* GroupOperationString(int);
80const char* KernelEnqueueFlagsString(int);
81const char* KernelProfilingInfoString(int);
82const char* CapabilityString(int);
83const char* OpcodeString(int);
84const char* ScopeString(int mem);
85
86// For grouping opcodes into subsections
87enum OpcodeClass {
88 OpClassMisc,
89 OpClassDebug,
90 OpClassAnnotate,
91 OpClassExtension,
92 OpClassMode,
93 OpClassType,
94 OpClassConstant,
95 OpClassMemory,
96 OpClassFunction,
97 OpClassImage,
98 OpClassConvert,
99 OpClassComposite,
100 OpClassArithmetic,
101 OpClassBit,
102 OpClassRelationalLogical,
103 OpClassDerivative,
104 OpClassFlowControl,
105 OpClassAtomic,
106 OpClassPrimitive,
107 OpClassBarrier,
108 OpClassGroup,
109 OpClassDeviceSideEnqueue,
110 OpClassPipe,
111
112 OpClassCount,
113 OpClassMissing // all instructions start out as missing
114};
115
116// For parameterizing operands.
117enum OperandClass {
118 OperandNone,
119 OperandId,
120 OperandVariableIds,
121 OperandOptionalLiteral,
122 OperandOptionalLiteralString,
123 OperandVariableLiterals,
124 OperandVariableIdLiteral,
125 OperandVariableLiteralId,
126 OperandLiteralNumber,
127 OperandLiteralString,
128 OperandVariableLiteralStrings,
129 OperandSource,
130 OperandExecutionModel,
131 OperandAddressing,
132 OperandMemory,
133 OperandExecutionMode,
134 OperandStorage,
135 OperandDimensionality,
136 OperandSamplerAddressingMode,
137 OperandSamplerFilterMode,
138 OperandSamplerImageFormat,
139 OperandImageChannelOrder,
140 OperandImageChannelDataType,
141 OperandImageOperands,
142 OperandFPFastMath,
143 OperandFPRoundingMode,
144 OperandLinkageType,
145 OperandAccessQualifier,
146 OperandFuncParamAttr,
147 OperandDecoration,
148 OperandBuiltIn,
149 OperandSelect,
150 OperandLoop,
151 OperandFunction,
152 OperandMemorySemantics,
153 OperandMemoryAccess,
154 OperandScope,
155 OperandGroupOperation,
156 OperandKernelEnqueueFlags,
157 OperandKernelProfilingInfo,
158 OperandCapability,
159 OperandCooperativeMatrixOperands,
160
161 OperandOpcode,
162
163 OperandCount
164};
165
166// Any specific enum can have a set of capabilities that allow it:
167typedef std::vector<Capability> EnumCaps;
168
169// Parameterize a set of operands with their OperandClass(es) and descriptions.
170class OperandParameters {
171public:
172 OperandParameters() { }
173 void push(OperandClass oc, const char* d, bool opt = false)
174 {
175 opClass.push_back(x: oc);
176 desc.push_back(x: d);
177 optional.push_back(x: opt);
178 }
179 void setOptional();
180 OperandClass getClass(int op) const { return opClass[op]; }
181 const char* getDesc(int op) const { return desc[op]; }
182 bool isOptional(int op) const { return optional[op]; }
183 int getNum() const { return (int)opClass.size(); }
184
185protected:
186 std::vector<OperandClass> opClass;
187 std::vector<const char*> desc;
188 std::vector<bool> optional;
189};
190
191// Parameterize an enumerant
192class EnumParameters {
193public:
194 EnumParameters() : desc(nullptr) { }
195 const char* desc;
196};
197
198// Parameterize a set of enumerants that form an enum
199class EnumDefinition : public EnumParameters {
200public:
201 EnumDefinition() :
202 ceiling(0), bitmask(false), getName(nullptr), enumParams(nullptr), operandParams(nullptr) { }
203 void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
204 {
205 ceiling = ceil;
206 getName = name;
207 bitmask = mask;
208 enumParams = ep;
209 }
210 void setOperands(OperandParameters* op) { operandParams = op; }
211 int ceiling; // ceiling of enumerants
212 bool bitmask; // true if these enumerants combine into a bitmask
213 const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
214 EnumParameters* enumParams; // parameters for each individual enumerant
215 OperandParameters* operandParams; // sets of operands
216};
217
218// Parameterize an instruction's logical format, including its known set of operands,
219// per OperandParameters above.
220class InstructionParameters {
221public:
222 InstructionParameters() :
223 opDesc("TBD"),
224 opClass(OpClassMissing),
225 typePresent(true), // most normal, only exceptions have to be spelled out
226 resultPresent(true) // most normal, only exceptions have to be spelled out
227 { }
228
229 void setResultAndType(bool r, bool t)
230 {
231 resultPresent = r;
232 typePresent = t;
233 }
234
235 bool hasResult() const { return resultPresent != 0; }
236 bool hasType() const { return typePresent != 0; }
237
238 const char* opDesc;
239 OpcodeClass opClass;
240 OperandParameters operands;
241
242protected:
243 bool typePresent : 1;
244 bool resultPresent : 1;
245};
246
247// The set of objects that hold all the instruction/operand
248// parameterization information.
249extern InstructionParameters InstructionDesc[];
250
251// These hold definitions of the enumerants used for operands
252extern EnumDefinition OperandClassParams[];
253
254const char* GetOperandDesc(OperandClass operand);
255void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
256const char* AccessQualifierString(int attr);
257
258void PrintOperands(const OperandParameters& operands, int reservedOperands);
259
260} // end namespace spv
261

source code of qtshadertools/src/3rdparty/glslang/SPIRV/doc.h