blob: 18012d5602ac057ffd7a04f2ce838bb25cc948c9 [file] [log] [blame]
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001// Copyright (c) 2015 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#include "operand.h"
28
29#include <assert.h>
30#include <string.h>
31
32static const spv_operand_desc_t sourceLanguageEntries[] = {
33 {"Unknown",
34 SourceLanguageUnknown,
35 SPV_OPCODE_FLAGS_NONE,
36 0,
37 {SPV_OPERAND_TYPE_NONE}},
38 {"ESSL",
39 SourceLanguageESSL,
40 SPV_OPCODE_FLAGS_NONE,
41 0,
42 {SPV_OPERAND_TYPE_NONE}},
43 {"GLSL",
44 SourceLanguageGLSL,
45 SPV_OPCODE_FLAGS_NONE,
46 0,
47 {SPV_OPERAND_TYPE_NONE}},
48 {"OpenCL",
49 SourceLanguageOpenCL,
50 SPV_OPCODE_FLAGS_NONE,
51 0,
52 {SPV_OPERAND_TYPE_NONE}},
53};
54
55static const spv_operand_desc_t executionModelEntries[] = {
56 {"Vertex",
57 ExecutionModelVertex,
58 SPV_OPCODE_FLAGS_CAPABILITIES,
59 CapabilityShader,
60 {SPV_OPERAND_TYPE_NONE}},
61 {"TessellationControl",
62 ExecutionModelTessellationControl,
63 SPV_OPCODE_FLAGS_CAPABILITIES,
64 CapabilityTessellation,
65 {SPV_OPERAND_TYPE_NONE}},
66 {"TessellationEvaluation",
67 ExecutionModelTessellationEvaluation,
68 SPV_OPCODE_FLAGS_CAPABILITIES,
69 CapabilityTessellation,
70 {SPV_OPERAND_TYPE_NONE}},
71 {"Geometry",
72 ExecutionModelGeometry,
73 SPV_OPCODE_FLAGS_CAPABILITIES,
74 CapabilityGeometry,
75 {SPV_OPERAND_TYPE_NONE}},
76 {"Fragment",
77 ExecutionModelFragment,
78 SPV_OPCODE_FLAGS_CAPABILITIES,
79 CapabilityShader,
80 {SPV_OPERAND_TYPE_NONE}},
81 {"GLCompute",
82 ExecutionModelGLCompute,
83 SPV_OPCODE_FLAGS_CAPABILITIES,
84 CapabilityShader,
85 {SPV_OPERAND_TYPE_NONE}},
86 {"Kernel",
87 ExecutionModelKernel,
88 SPV_OPCODE_FLAGS_CAPABILITIES,
89 CapabilityKernel,
90 {SPV_OPERAND_TYPE_NONE}},
91};
92
93static const spv_operand_desc_t addressingModelEntries[] = {
94 {"Logical",
95 AddressingModelLogical,
96 SPV_OPCODE_FLAGS_NONE,
97 0,
98 {SPV_OPERAND_TYPE_NONE}},
99 {"Physical32",
100 AddressingModelPhysical32,
101 SPV_OPCODE_FLAGS_CAPABILITIES,
102 CapabilityAddresses,
103 {SPV_OPERAND_TYPE_NONE}},
104 {"Physical64",
105 AddressingModelPhysical64,
106 SPV_OPCODE_FLAGS_CAPABILITIES,
107 CapabilityAddresses,
108 {SPV_OPERAND_TYPE_NONE}},
109};
110
111static const spv_operand_desc_t memoryModelEntries[] = {
112 {"Simple",
113 MemoryModelSimple,
114 SPV_OPCODE_FLAGS_CAPABILITIES,
115 CapabilityShader,
116 {SPV_OPERAND_TYPE_NONE}},
117 {"GLSL450",
118 MemoryModelGLSL450,
119 SPV_OPCODE_FLAGS_CAPABILITIES,
120 CapabilityShader,
121 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400122 {"OpenCL",
123 MemoryModelOpenCL,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100124 SPV_OPCODE_FLAGS_CAPABILITIES,
125 CapabilityKernel,
126 {SPV_OPERAND_TYPE_NONE}},
127};
128
129static const spv_operand_desc_t executionModeEntries[] = {
130 {"Invocations",
131 ExecutionModeInvocations,
132 SPV_OPCODE_FLAGS_CAPABILITIES,
133 CapabilityGeometry,
134 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
135 {"SpacingEqual",
136 ExecutionModeSpacingEqual,
137 SPV_OPCODE_FLAGS_CAPABILITIES,
138 CapabilityTessellation,
139 {SPV_OPERAND_TYPE_NONE}},
140 {"SpacingFractionalEven",
141 ExecutionModeSpacingFractionalEven,
142 SPV_OPCODE_FLAGS_CAPABILITIES,
143 CapabilityTessellation,
144 {SPV_OPERAND_TYPE_NONE}},
145 {"SpacingFractionalOdd",
146 ExecutionModeSpacingFractionalOdd,
147 SPV_OPCODE_FLAGS_CAPABILITIES,
148 CapabilityTessellation,
149 {SPV_OPERAND_TYPE_NONE}},
150 {"VertexOrderCw",
151 ExecutionModeVertexOrderCw,
152 SPV_OPCODE_FLAGS_CAPABILITIES,
153 CapabilityTessellation,
154 {SPV_OPERAND_TYPE_NONE}},
155 {"VertexOrderCcw",
156 ExecutionModeVertexOrderCcw,
157 SPV_OPCODE_FLAGS_CAPABILITIES,
158 CapabilityTessellation,
159 {SPV_OPERAND_TYPE_NONE}},
160 {"PixelCenterInteger",
161 ExecutionModePixelCenterInteger,
162 SPV_OPCODE_FLAGS_CAPABILITIES,
163 CapabilityShader,
164 {SPV_OPERAND_TYPE_NONE}},
165 {"OriginUpperLeft",
166 ExecutionModeOriginUpperLeft,
167 SPV_OPCODE_FLAGS_CAPABILITIES,
168 CapabilityShader,
169 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400170 {
171 "OriginLowerLeft",
172 ExecutionModeOriginLowerLeft,
173 SPV_OPCODE_FLAGS_CAPABILITIES,
174 CapabilityShader,
175 {SPV_OPERAND_TYPE_NONE},
176 },
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100177 {"EarlyFragmentTests",
178 ExecutionModeEarlyFragmentTests,
179 SPV_OPCODE_FLAGS_CAPABILITIES,
180 CapabilityShader,
181 {SPV_OPERAND_TYPE_NONE}},
182 {"PointMode",
183 ExecutionModePointMode,
184 SPV_OPCODE_FLAGS_CAPABILITIES,
185 CapabilityTessellation,
186 {SPV_OPERAND_TYPE_NONE}},
187 {"Xfb",
188 ExecutionModeXfb,
189 SPV_OPCODE_FLAGS_CAPABILITIES,
190 CapabilityShader,
191 {SPV_OPERAND_TYPE_NONE}},
192 {"DepthReplacing",
193 ExecutionModeDepthReplacing,
194 SPV_OPCODE_FLAGS_CAPABILITIES,
195 CapabilityShader,
196 {SPV_OPERAND_TYPE_NONE}},
197 {"DepthAny",
198 ExecutionModeDepthAny,
199 SPV_OPCODE_FLAGS_CAPABILITIES,
200 CapabilityShader,
201 {SPV_OPERAND_TYPE_NONE}},
202 {"DepthGreater",
203 ExecutionModeDepthGreater,
204 SPV_OPCODE_FLAGS_CAPABILITIES,
205 CapabilityShader,
206 {SPV_OPERAND_TYPE_NONE}},
207 {"DepthLess",
208 ExecutionModeDepthLess,
209 SPV_OPCODE_FLAGS_CAPABILITIES,
210 CapabilityShader,
211 {SPV_OPERAND_TYPE_NONE}},
212 {"DepthUnchanged",
213 ExecutionModeDepthUnchanged,
214 SPV_OPCODE_FLAGS_CAPABILITIES,
215 CapabilityShader,
216 {SPV_OPERAND_TYPE_NONE}},
217 {"LocalSize",
218 ExecutionModeLocalSize,
219 SPV_OPCODE_FLAGS_NONE,
220 0,
221 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_LITERAL_NUMBER,
222 SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
223 {"LocalSizeHint",
224 ExecutionModeLocalSizeHint,
225 SPV_OPCODE_FLAGS_CAPABILITIES,
226 CapabilityKernel,
227 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_LITERAL_NUMBER,
228 SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
229 {"InputPoints",
230 ExecutionModeInputPoints,
231 SPV_OPCODE_FLAGS_CAPABILITIES,
232 CapabilityGeometry,
233 {SPV_OPERAND_TYPE_NONE}},
234 {"InputLines",
235 ExecutionModeInputLines,
236 SPV_OPCODE_FLAGS_CAPABILITIES,
237 CapabilityGeometry,
238 {SPV_OPERAND_TYPE_NONE}},
239 {"InputLinesAdjacency",
240 ExecutionModeInputLinesAdjacency,
241 SPV_OPCODE_FLAGS_CAPABILITIES,
242 CapabilityGeometry,
243 {SPV_OPERAND_TYPE_NONE}},
244 {"InputTriangles",
245 ExecutionModeInputTriangles,
246 SPV_OPCODE_FLAGS_CAPABILITIES,
247 CapabilityGeometry | CapabilityTessellation,
248 {SPV_OPERAND_TYPE_NONE}},
249 {"InputTrianglesAdjacency",
250 ExecutionModeInputTrianglesAdjacency,
251 SPV_OPCODE_FLAGS_CAPABILITIES,
252 CapabilityGeometry,
253 {SPV_OPERAND_TYPE_NONE}},
254 {"InputQuads",
255 ExecutionModeInputQuads,
256 SPV_OPCODE_FLAGS_CAPABILITIES,
257 CapabilityTessellation,
258 {SPV_OPERAND_TYPE_NONE}},
259 {"InputIsolines",
260 ExecutionModeInputIsolines,
261 SPV_OPCODE_FLAGS_CAPABILITIES,
262 CapabilityTessellation,
263 {SPV_OPERAND_TYPE_NONE}},
264 {"OutputVertices",
265 ExecutionModeOutputVertices,
266 SPV_OPCODE_FLAGS_CAPABILITIES,
267 CapabilityGeometry | CapabilityTessellation,
268 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
269 {"OutputPoints",
270 ExecutionModeOutputPoints,
271 SPV_OPCODE_FLAGS_CAPABILITIES,
272 CapabilityGeometry,
273 {SPV_OPERAND_TYPE_NONE}},
274 {"OutputLineStrip",
275 ExecutionModeOutputLineStrip,
276 SPV_OPCODE_FLAGS_CAPABILITIES,
277 CapabilityGeometry,
278 {SPV_OPERAND_TYPE_NONE}},
279 {"OutputTriangleStrip",
280 ExecutionModeOutputTriangleStrip,
281 SPV_OPCODE_FLAGS_CAPABILITIES,
282 CapabilityGeometry,
283 {SPV_OPERAND_TYPE_NONE}},
284 {"VecTypeHint",
285 ExecutionModeVecTypeHint,
286 SPV_OPCODE_FLAGS_CAPABILITIES,
287 CapabilityKernel,
Andrew Woloszyne0d351b2015-09-22 15:49:27 -0400288 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100289 {"ContractionOff",
290 ExecutionModeContractionOff,
291 SPV_OPCODE_FLAGS_CAPABILITIES,
292 CapabilityKernel,
293 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100294};
295
296static const spv_operand_desc_t storageClassEntries[] = {
David Neto5494dd42015-09-15 16:41:38 -0400297 // TODO(dneto): There are more storage classes in Rev32 and later.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100298 {"UniformConstant",
299 StorageClassUniformConstant,
300 SPV_OPCODE_FLAGS_NONE,
301 0,
302 {SPV_OPERAND_TYPE_NONE}},
303 {"Input",
304 StorageClassInput,
305 SPV_OPCODE_FLAGS_CAPABILITIES,
306 CapabilityShader,
307 {SPV_OPERAND_TYPE_NONE}},
308 {"Uniform",
309 StorageClassUniform,
310 SPV_OPCODE_FLAGS_CAPABILITIES,
311 CapabilityShader,
312 {SPV_OPERAND_TYPE_NONE}},
313 {"Output",
314 StorageClassOutput,
315 SPV_OPCODE_FLAGS_CAPABILITIES,
316 CapabilityShader,
317 {SPV_OPERAND_TYPE_NONE}},
318 {"WorkgroupLocal",
319 StorageClassWorkgroupLocal,
320 SPV_OPCODE_FLAGS_NONE,
321 0,
322 {SPV_OPERAND_TYPE_NONE}},
323 {"WorkgroupGlobal",
324 StorageClassWorkgroupGlobal,
325 SPV_OPCODE_FLAGS_NONE,
326 0,
327 {SPV_OPERAND_TYPE_NONE}},
328 {"PrivateGlobal",
329 StorageClassPrivateGlobal,
330 SPV_OPCODE_FLAGS_CAPABILITIES,
331 CapabilityShader,
332 {SPV_OPERAND_TYPE_NONE}},
333 {"Function",
334 StorageClassFunction,
335 SPV_OPCODE_FLAGS_NONE,
336 0,
337 {SPV_OPERAND_TYPE_NONE}},
338 {"Generic",
339 StorageClassGeneric,
340 SPV_OPCODE_FLAGS_CAPABILITIES,
341 CapabilityKernel,
342 {SPV_OPERAND_TYPE_NONE}},
343 {"AtomicCounter",
344 StorageClassAtomicCounter,
345 SPV_OPCODE_FLAGS_CAPABILITIES,
346 CapabilityShader,
347 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400348 {"Image",
349 StorageClassImage,
350 SPV_OPCODE_FLAGS_NONE,
351 0,
352 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100353};
354
355static const spv_operand_desc_t dimensionalityEntries[] = {
356 {"1D", Dim1D, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}},
357 {"2D", Dim2D, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}},
358 {"3D", Dim3D, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}},
359 {"Cube",
360 DimCube,
361 SPV_OPCODE_FLAGS_CAPABILITIES,
362 CapabilityShader,
363 {SPV_OPERAND_TYPE_NONE}},
364 {"Rect",
365 DimRect,
366 SPV_OPCODE_FLAGS_CAPABILITIES,
367 CapabilityShader,
368 {SPV_OPERAND_TYPE_NONE}},
369 {"Buffer", DimBuffer, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}},
370};
371
372static const spv_operand_desc_t samplerAddressingModeEntries[] = {
373 {"None",
374 SamplerAddressingModeNone,
375 SPV_OPCODE_FLAGS_CAPABILITIES,
376 CapabilityKernel,
377 {SPV_OPERAND_TYPE_NONE}},
378 {"ClampToEdge",
379 SamplerAddressingModeClampToEdge,
380 SPV_OPCODE_FLAGS_CAPABILITIES,
381 CapabilityKernel,
382 {SPV_OPERAND_TYPE_NONE}},
383 {"Clamp",
384 SamplerAddressingModeClamp,
385 SPV_OPCODE_FLAGS_CAPABILITIES,
386 CapabilityKernel,
387 {SPV_OPERAND_TYPE_NONE}},
388 {"Repeat",
389 SamplerAddressingModeRepeat,
390 SPV_OPCODE_FLAGS_CAPABILITIES,
391 CapabilityKernel,
392 {SPV_OPERAND_TYPE_NONE}},
393 {"RepeatMirrored",
394 SamplerAddressingModeRepeatMirrored,
395 SPV_OPCODE_FLAGS_CAPABILITIES,
396 CapabilityKernel,
397 {SPV_OPERAND_TYPE_NONE}},
398};
399
400static const spv_operand_desc_t samplerFilterModeEntries[] = {
401 {"Nearest",
402 SamplerFilterModeNearest,
403 SPV_OPCODE_FLAGS_CAPABILITIES,
404 CapabilityKernel,
405 {SPV_OPERAND_TYPE_NONE}},
406 {"Linear",
407 SamplerFilterModeLinear,
408 SPV_OPCODE_FLAGS_CAPABILITIES,
409 CapabilityKernel,
410 {SPV_OPERAND_TYPE_NONE}},
411};
412
David Netob30a0c52015-09-16 15:56:43 -0400413static const spv_operand_desc_t samplerImageFormatEntries[] = {
414// In Rev31, all the cases depend on the Shader capability.
415// TODO(dneto): In Rev32, many of these depend on the AdvancedFormats
416// capability instead.
417#define CASE(NAME) \
418 { \
419 #NAME, ImageFormat##NAME, SPV_OPCODE_FLAGS_CAPABILITIES, CapabilityShader, \
420 { \
421 SPV_OPERAND_TYPE_NONE \
422 } \
423 }
424 // clang-format off
425 CASE(Unknown),
426 CASE(Rgba32f),
427 CASE(Rgba16f),
428 CASE(R32f),
429 CASE(Rgba8),
430 CASE(Rgba8Snorm),
431 CASE(Rg32f),
432 CASE(Rg16f),
433 CASE(R11fG11fB10f),
434 CASE(R16f),
435 CASE(Rgba16),
436 CASE(Rgb10A2),
437 CASE(Rg16),
438 CASE(Rg8),
439 CASE(R16),
440 CASE(R8),
441 CASE(Rgba16Snorm),
442 CASE(Rg16Snorm),
443 CASE(Rg8Snorm),
444 CASE(R16Snorm),
445 CASE(R8Snorm),
446 CASE(Rgba32i),
447 CASE(Rgba16i),
448 CASE(Rgba8i),
449 CASE(R32i),
450 CASE(Rg32i),
451 CASE(Rg16i),
452 CASE(Rg8i),
453 CASE(R16i),
454 CASE(R8i),
455 CASE(Rgba32ui),
456 CASE(Rgba16ui),
457 CASE(Rgba8ui),
458 CASE(R32ui),
459 CASE(Rgb10a2ui),
460 CASE(Rg32ui),
461 CASE(Rg16ui),
462 CASE(Rg8ui),
463 CASE(R16ui),
464 CASE(R8ui),
465 // clang-format on
466#undef CASE
467};
468
David Netoee1b3bb2015-09-18 11:19:18 -0400469// Image operand definitions. Each enum value is a mask. When that mask
470// bit is set, the instruction should have further ID operands.
471// Some mask values depend on a capability.
472static const spv_operand_desc_t imageOperandEntries[] = {
473// Rev32 and later adds many more enums.
474#define CASE(NAME) \
475 #NAME, spv::ImageOperands##NAME##Mask, SPV_OPCODE_FLAGS_NONE, 0
476#define CASE_CAP(NAME, CAP) \
477 #NAME, spv::ImageOperands##NAME##Mask, SPV_OPCODE_FLAGS_CAPABILITIES, CAP
478#define ID SPV_OPERAND_TYPE_ID
479#define NONE SPV_OPERAND_TYPE_NONE
480 {"None", spv::ImageOperandsMaskNone, SPV_OPCODE_FLAGS_NONE, 0, {NONE}},
481 {CASE_CAP(Bias, CapabilityShader), {ID, NONE}},
482 {CASE(Lod), {ID, NONE}},
483 {CASE(Grad), {ID, ID, NONE}},
484 {CASE(ConstOffset), {ID, NONE}},
485 {CASE_CAP(Offset, CapabilityImageGatherExtended), {ID, NONE}},
486 {CASE(ConstOffsets), {ID, NONE}},
487 {CASE(Sample), {ID, NONE}},
488#undef CASE
489#undef CASE_CAP
490#undef ID
491#undef NONE
492};
493
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100494static const spv_operand_desc_t fpFastMathModeEntries[] = {
495 {"None",
496 FPFastMathModeMaskNone,
497 SPV_OPCODE_FLAGS_NONE,
498 0,
499 {SPV_OPERAND_TYPE_NONE}},
500 {"NotNaN",
501 FPFastMathModeNotNaNMask,
502 SPV_OPCODE_FLAGS_CAPABILITIES,
503 CapabilityKernel,
504 {SPV_OPERAND_TYPE_NONE}},
505 {"NotInf",
506 FPFastMathModeNotInfMask,
507 SPV_OPCODE_FLAGS_CAPABILITIES,
508 CapabilityKernel,
509 {SPV_OPERAND_TYPE_NONE}},
510 {"NSZ",
511 FPFastMathModeNSZMask,
512 SPV_OPCODE_FLAGS_CAPABILITIES,
513 CapabilityKernel,
514 {SPV_OPERAND_TYPE_NONE}},
515 {"AllowRecip",
516 FPFastMathModeAllowRecipMask,
517 SPV_OPCODE_FLAGS_CAPABILITIES,
518 CapabilityKernel,
519 {SPV_OPERAND_TYPE_NONE}},
520 {"Fast",
521 FPFastMathModeFastMask,
522 SPV_OPCODE_FLAGS_CAPABILITIES,
523 CapabilityKernel,
524 {SPV_OPERAND_TYPE_NONE}},
525};
526
527static const spv_operand_desc_t fpRoundingModeEntries[] = {
528 {"RTE",
529 FPRoundingModeRTE,
530 SPV_OPCODE_FLAGS_CAPABILITIES,
531 CapabilityKernel,
532 {SPV_OPERAND_TYPE_NONE}},
533 {"RTZ",
534 FPRoundingModeRTZ,
535 SPV_OPCODE_FLAGS_CAPABILITIES,
536 CapabilityKernel,
537 {SPV_OPERAND_TYPE_NONE}},
538 {"RTP",
539 FPRoundingModeRTP,
540 SPV_OPCODE_FLAGS_CAPABILITIES,
541 CapabilityKernel,
542 {SPV_OPERAND_TYPE_NONE}},
543 {"RTN",
544 FPRoundingModeRTN,
545 SPV_OPCODE_FLAGS_CAPABILITIES,
546 CapabilityKernel,
547 {SPV_OPERAND_TYPE_NONE}},
548};
549
550static const spv_operand_desc_t linkageTypeEntries[] = {
551 {"Export",
552 LinkageTypeExport,
553 SPV_OPCODE_FLAGS_CAPABILITIES,
554 CapabilityLinkage,
555 {SPV_OPERAND_TYPE_NONE}},
556 {"Import",
557 LinkageTypeImport,
558 SPV_OPCODE_FLAGS_CAPABILITIES,
559 CapabilityLinkage,
560 {SPV_OPERAND_TYPE_NONE}},
561};
562
563static const spv_operand_desc_t accessQualifierEntries[] = {
564 {"ReadOnly",
565 AccessQualifierReadOnly,
566 SPV_OPCODE_FLAGS_CAPABILITIES,
567 CapabilityKernel,
568 {SPV_OPERAND_TYPE_NONE}},
569 {"WriteOnly",
570 AccessQualifierWriteOnly,
571 SPV_OPCODE_FLAGS_CAPABILITIES,
572 CapabilityKernel,
573 {SPV_OPERAND_TYPE_NONE}},
574 {"ReadWrite",
575 AccessQualifierReadWrite,
576 SPV_OPCODE_FLAGS_CAPABILITIES,
577 CapabilityKernel,
578 {SPV_OPERAND_TYPE_NONE}},
579};
580
581static const spv_operand_desc_t functionParameterAttributeEntries[] = {
582 {"Zext",
583 FunctionParameterAttributeZext,
584 SPV_OPCODE_FLAGS_CAPABILITIES,
585 CapabilityKernel,
586 {SPV_OPERAND_TYPE_NONE}},
587 {"Sext",
588 FunctionParameterAttributeSext,
589 SPV_OPCODE_FLAGS_CAPABILITIES,
590 CapabilityKernel,
591 {SPV_OPERAND_TYPE_NONE}},
592 {"ByVal",
593 FunctionParameterAttributeByVal,
594 SPV_OPCODE_FLAGS_CAPABILITIES,
595 CapabilityKernel,
596 {SPV_OPERAND_TYPE_NONE}},
597 {"Sret",
598 FunctionParameterAttributeSret,
599 SPV_OPCODE_FLAGS_CAPABILITIES,
600 CapabilityKernel,
601 {SPV_OPERAND_TYPE_NONE}},
602 {"NoAlias",
603 FunctionParameterAttributeNoAlias,
604 SPV_OPCODE_FLAGS_CAPABILITIES,
605 CapabilityKernel,
606 {SPV_OPERAND_TYPE_NONE}},
David Neto37547b22015-09-10 13:23:11 -0400607 {"NoCapture",
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100608 FunctionParameterAttributeNoCapture,
609 SPV_OPCODE_FLAGS_CAPABILITIES,
610 CapabilityKernel,
611 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100612 {"NoWrite",
613 FunctionParameterAttributeNoWrite,
614 SPV_OPCODE_FLAGS_CAPABILITIES,
615 CapabilityKernel,
616 {SPV_OPERAND_TYPE_NONE}},
617 {"NoReadWrite",
618 FunctionParameterAttributeNoReadWrite,
619 SPV_OPCODE_FLAGS_CAPABILITIES,
620 CapabilityKernel,
621 {SPV_OPERAND_TYPE_NONE}},
622};
623
624static const spv_operand_desc_t decorationEntries[] = {
Lei Zhang604e5ce2015-08-14 14:46:43 -0400625 {"RelaxedPrecision",
626 DecorationRelaxedPrecision,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100627 SPV_OPCODE_FLAGS_CAPABILITIES,
628 CapabilityShader,
629 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400630 {
631 "SpecId",
632 DecorationSpecId,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100633 SPV_OPCODE_FLAGS_CAPABILITIES,
634 CapabilityShader,
Lei Zhang604e5ce2015-08-14 14:46:43 -0400635 {SPV_OPERAND_TYPE_LITERAL_NUMBER},
636 },
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100637 {"Block",
638 DecorationBlock,
639 SPV_OPCODE_FLAGS_CAPABILITIES,
640 CapabilityShader,
641 {SPV_OPERAND_TYPE_NONE}},
642 {"BufferBlock",
643 DecorationBufferBlock,
644 SPV_OPCODE_FLAGS_CAPABILITIES,
645 CapabilityShader,
646 {SPV_OPERAND_TYPE_NONE}},
647 {"RowMajor",
648 DecorationRowMajor,
649 SPV_OPCODE_FLAGS_CAPABILITIES,
650 CapabilityMatrix,
651 {SPV_OPERAND_TYPE_NONE}},
652 {"ColMajor",
653 DecorationColMajor,
654 SPV_OPCODE_FLAGS_CAPABILITIES,
655 CapabilityMatrix,
656 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400657 {"ArrayStride",
658 DecorationArrayStride,
659 SPV_OPCODE_FLAGS_CAPABILITIES,
660 CapabilityShader,
661 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
662 {"MatrixStride",
663 DecorationMatrixStride,
664 SPV_OPCODE_FLAGS_CAPABILITIES,
665 CapabilityShader,
666 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100667 {"GLSLShared",
668 DecorationGLSLShared,
669 SPV_OPCODE_FLAGS_CAPABILITIES,
670 CapabilityShader,
671 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100672 {"GLSLPacked",
673 DecorationGLSLPacked,
674 SPV_OPCODE_FLAGS_CAPABILITIES,
675 CapabilityShader,
676 {SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400677 {"CPacked",
678 DecorationCPacked,
679 SPV_OPCODE_FLAGS_CAPABILITIES,
680 CapabilityKernel,
681 {SPV_OPERAND_TYPE_NONE}},
682 {"BuiltIn",
683 DecorationBuiltIn,
684 SPV_OPCODE_FLAGS_CAPABILITIES,
685 CapabilityShader,
686 {SPV_OPERAND_TYPE_BUILT_IN, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100687 {"Smooth",
688 DecorationSmooth,
689 SPV_OPCODE_FLAGS_CAPABILITIES,
690 CapabilityShader,
691 {SPV_OPERAND_TYPE_NONE}},
692 {"Noperspective",
693 DecorationNoperspective,
694 SPV_OPCODE_FLAGS_CAPABILITIES,
695 CapabilityShader,
696 {SPV_OPERAND_TYPE_NONE}},
697 {"Flat",
698 DecorationFlat,
699 SPV_OPCODE_FLAGS_CAPABILITIES,
700 CapabilityShader,
701 {SPV_OPERAND_TYPE_NONE}},
702 {"Patch",
703 DecorationPatch,
704 SPV_OPCODE_FLAGS_CAPABILITIES,
705 CapabilityTessellation,
706 {SPV_OPERAND_TYPE_NONE}},
707 {"Centroid",
708 DecorationCentroid,
709 SPV_OPCODE_FLAGS_CAPABILITIES,
710 CapabilityShader,
711 {SPV_OPERAND_TYPE_NONE}},
712 {"Sample",
713 DecorationSample,
714 SPV_OPCODE_FLAGS_CAPABILITIES,
715 CapabilityShader,
716 {SPV_OPERAND_TYPE_NONE}},
717 {"Invariant",
718 DecorationInvariant,
719 SPV_OPCODE_FLAGS_CAPABILITIES,
720 CapabilityShader,
721 {SPV_OPERAND_TYPE_NONE}},
722 {"Restrict",
723 DecorationRestrict,
724 SPV_OPCODE_FLAGS_NONE,
725 0,
726 {SPV_OPERAND_TYPE_NONE}},
727 {"Aliased",
728 DecorationAliased,
729 SPV_OPCODE_FLAGS_NONE,
730 0,
731 {SPV_OPERAND_TYPE_NONE}},
732 {"Volatile",
733 DecorationVolatile,
734 SPV_OPCODE_FLAGS_NONE,
735 0,
736 {SPV_OPERAND_TYPE_NONE}},
737 {"Constant",
738 DecorationConstant,
739 SPV_OPCODE_FLAGS_CAPABILITIES,
740 CapabilityKernel,
741 {SPV_OPERAND_TYPE_NONE}},
742 {"Coherent",
743 DecorationCoherent,
744 SPV_OPCODE_FLAGS_NONE,
745 0,
746 {SPV_OPERAND_TYPE_NONE}},
747 {"Nonwritable",
748 DecorationNonwritable,
749 SPV_OPCODE_FLAGS_NONE,
750 0,
751 {SPV_OPERAND_TYPE_NONE}},
752 {"Nonreadable",
753 DecorationNonreadable,
754 SPV_OPCODE_FLAGS_NONE,
755 0,
756 {SPV_OPERAND_TYPE_NONE}},
757 {"Uniform",
758 DecorationUniform,
759 SPV_OPCODE_FLAGS_CAPABILITIES,
760 CapabilityShader,
761 {SPV_OPERAND_TYPE_NONE}},
762 {"NoStaticUse",
763 DecorationNoStaticUse,
764 SPV_OPCODE_FLAGS_NONE,
765 0,
766 {SPV_OPERAND_TYPE_NONE}},
David Neto37547b22015-09-10 13:23:11 -0400767 {"SaturatedConversion",
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100768 DecorationSaturatedConversion,
769 SPV_OPCODE_FLAGS_CAPABILITIES,
770 CapabilityKernel,
771 {SPV_OPERAND_TYPE_NONE}},
772 {"Stream",
773 DecorationStream,
774 SPV_OPCODE_FLAGS_CAPABILITIES,
775 CapabilityGeometry,
776 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
777 {"Location",
778 DecorationLocation,
779 SPV_OPCODE_FLAGS_CAPABILITIES,
780 CapabilityShader,
781 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
782 {"Component",
783 DecorationComponent,
784 SPV_OPCODE_FLAGS_CAPABILITIES,
785 CapabilityShader,
786 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
787 {"Index",
788 DecorationIndex,
789 SPV_OPCODE_FLAGS_CAPABILITIES,
790 CapabilityShader,
791 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
792 {"Binding",
793 DecorationBinding,
794 SPV_OPCODE_FLAGS_CAPABILITIES,
795 CapabilityShader,
796 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
797 {"DescriptorSet",
798 DecorationDescriptorSet,
799 SPV_OPCODE_FLAGS_CAPABILITIES,
800 CapabilityShader,
801 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
802 {"Offset",
803 DecorationOffset,
804 SPV_OPCODE_FLAGS_NONE,
805 0,
806 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100807 {"XfbBuffer",
808 DecorationXfbBuffer,
809 SPV_OPCODE_FLAGS_CAPABILITIES,
810 CapabilityShader,
811 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
Lei Zhang604e5ce2015-08-14 14:46:43 -0400812 {"XfbStride",
813 DecorationXfbStride,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100814 SPV_OPCODE_FLAGS_CAPABILITIES,
815 CapabilityShader,
816 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100817 {"FuncParamAttr",
818 DecorationFuncParamAttr,
819 SPV_OPCODE_FLAGS_CAPABILITIES,
820 CapabilityKernel,
821 {SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE, SPV_OPERAND_TYPE_NONE}},
822 {"FPRoundingMode",
823 DecorationFPRoundingMode,
824 SPV_OPCODE_FLAGS_CAPABILITIES,
825 CapabilityKernel,
826 {SPV_OPERAND_TYPE_FP_ROUNDING_MODE, SPV_OPERAND_TYPE_NONE}},
827 {"FPFastMathMode",
David Neto37547b22015-09-10 13:23:11 -0400828 DecorationFPFastMathMode,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100829 SPV_OPCODE_FLAGS_CAPABILITIES,
830 CapabilityKernel,
831 {SPV_OPERAND_TYPE_FP_FAST_MATH_MODE, SPV_OPERAND_TYPE_NONE}},
832 {"LinkageAttributes",
833 DecorationLinkageAttributes,
834 SPV_OPCODE_FLAGS_CAPABILITIES,
835 CapabilityLinkage,
David Neto55bdfcb2015-09-10 15:51:57 -0400836 {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LINKAGE_TYPE, SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100837};
838
839static const spv_operand_desc_t builtInEntries[] = {
840 {"Position",
841 BuiltInPosition,
842 SPV_OPCODE_FLAGS_CAPABILITIES,
843 CapabilityShader,
844 {SPV_OPERAND_TYPE_NONE}},
845 {"PointSize",
846 BuiltInPointSize,
847 SPV_OPCODE_FLAGS_CAPABILITIES,
848 CapabilityShader,
849 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100850 {"ClipDistance",
851 BuiltInClipDistance,
852 SPV_OPCODE_FLAGS_CAPABILITIES,
853 CapabilityShader,
854 {SPV_OPERAND_TYPE_NONE}},
855 {"CullDistance",
856 BuiltInCullDistance,
857 SPV_OPCODE_FLAGS_CAPABILITIES,
858 CapabilityShader,
859 {SPV_OPERAND_TYPE_NONE}},
860 {"VertexId",
861 BuiltInVertexId,
862 SPV_OPCODE_FLAGS_CAPABILITIES,
863 CapabilityShader,
864 {SPV_OPERAND_TYPE_NONE}},
865 {"InstanceId",
866 BuiltInInstanceId,
867 SPV_OPCODE_FLAGS_CAPABILITIES,
868 CapabilityShader,
869 {SPV_OPERAND_TYPE_NONE}},
870 {"PrimitiveId",
871 BuiltInPrimitiveId,
872 SPV_OPCODE_FLAGS_CAPABILITIES,
873 CapabilityGeometry | CapabilityTessellation,
874 {SPV_OPERAND_TYPE_NONE}},
875 {"InvocationId",
876 BuiltInInvocationId,
877 SPV_OPCODE_FLAGS_CAPABILITIES,
878 CapabilityGeometry | CapabilityTessellation,
879 {SPV_OPERAND_TYPE_NONE}},
880 {"Layer",
881 BuiltInLayer,
882 SPV_OPCODE_FLAGS_CAPABILITIES,
883 CapabilityGeometry,
884 {SPV_OPERAND_TYPE_NONE}},
885 {"ViewportIndex",
886 BuiltInViewportIndex,
887 SPV_OPCODE_FLAGS_CAPABILITIES,
888 CapabilityGeometry,
889 {SPV_OPERAND_TYPE_NONE}},
890 {"TessLevelOuter",
891 BuiltInTessLevelOuter,
892 SPV_OPCODE_FLAGS_CAPABILITIES,
893 CapabilityTessellation,
894 {SPV_OPERAND_TYPE_NONE}},
895 {"TessLevelInner",
896 BuiltInTessLevelInner,
897 SPV_OPCODE_FLAGS_CAPABILITIES,
898 CapabilityTessellation,
899 {SPV_OPERAND_TYPE_NONE}},
900 {"TessCoord",
901 BuiltInTessCoord,
902 SPV_OPCODE_FLAGS_CAPABILITIES,
903 CapabilityTessellation,
904 {SPV_OPERAND_TYPE_NONE}},
905 {"PatchVertices",
906 BuiltInPatchVertices,
907 SPV_OPCODE_FLAGS_CAPABILITIES,
908 CapabilityTessellation,
909 {SPV_OPERAND_TYPE_NONE}},
910 {"FragCoord",
911 BuiltInFragCoord,
912 SPV_OPCODE_FLAGS_CAPABILITIES,
913 CapabilityShader,
914 {SPV_OPERAND_TYPE_NONE}},
915 {"PointCoord",
916 BuiltInPointCoord,
917 SPV_OPCODE_FLAGS_CAPABILITIES,
918 CapabilityShader,
919 {SPV_OPERAND_TYPE_NONE}},
920 {"FrontFacing",
921 BuiltInFrontFacing,
922 SPV_OPCODE_FLAGS_CAPABILITIES,
923 CapabilityShader,
924 {SPV_OPERAND_TYPE_NONE}},
925 {"SampleId",
926 BuiltInSampleId,
927 SPV_OPCODE_FLAGS_CAPABILITIES,
928 CapabilityShader,
929 {SPV_OPERAND_TYPE_NONE}},
930 {"SamplePosition",
931 BuiltInSamplePosition,
932 SPV_OPCODE_FLAGS_CAPABILITIES,
933 CapabilityShader,
934 {SPV_OPERAND_TYPE_NONE}},
935 {"SampleMask",
936 BuiltInSampleMask,
937 SPV_OPCODE_FLAGS_CAPABILITIES,
938 CapabilityShader,
939 {SPV_OPERAND_TYPE_NONE}},
940 {"FragColor",
941 BuiltInFragColor,
942 SPV_OPCODE_FLAGS_CAPABILITIES,
943 CapabilityShader,
944 {SPV_OPERAND_TYPE_NONE}},
945 {"FragDepth",
946 BuiltInFragDepth,
947 SPV_OPCODE_FLAGS_CAPABILITIES,
948 CapabilityShader,
949 {SPV_OPERAND_TYPE_NONE}},
950 {"HelperInvocation",
951 BuiltInHelperInvocation,
952 SPV_OPCODE_FLAGS_CAPABILITIES,
953 CapabilityShader,
954 {SPV_OPERAND_TYPE_NONE}},
955 {"NumWorkgroups",
956 BuiltInNumWorkgroups,
957 SPV_OPCODE_FLAGS_NONE,
958 0,
959 {SPV_OPERAND_TYPE_NONE}},
960 {"WorkgroupSize",
961 BuiltInWorkgroupSize,
962 SPV_OPCODE_FLAGS_NONE,
963 0,
964 {SPV_OPERAND_TYPE_NONE}},
965 {"WorkgroupId",
966 BuiltInWorkgroupId,
967 SPV_OPCODE_FLAGS_NONE,
968 0,
969 {SPV_OPERAND_TYPE_NONE}},
970 {"LocalInvocationId",
971 BuiltInLocalInvocationId,
972 SPV_OPCODE_FLAGS_NONE,
973 0,
974 {SPV_OPERAND_TYPE_NONE}},
975 {"GlobalInvocationId",
976 BuiltInGlobalInvocationId,
977 SPV_OPCODE_FLAGS_NONE,
978 0,
979 {SPV_OPERAND_TYPE_NONE}},
980 {"LocalInvocationIndex",
David Neto37547b22015-09-10 13:23:11 -0400981 BuiltInLocalInvocationIndex,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +0100982 SPV_OPCODE_FLAGS_CAPABILITIES,
983 CapabilityShader,
984 {SPV_OPERAND_TYPE_NONE}},
985 {"WorkDim",
986 BuiltInWorkDim,
987 SPV_OPCODE_FLAGS_CAPABILITIES,
988 CapabilityKernel,
989 {SPV_OPERAND_TYPE_NONE}},
990 {"GlobalSize",
991 BuiltInGlobalSize,
992 SPV_OPCODE_FLAGS_CAPABILITIES,
993 CapabilityKernel,
994 {SPV_OPERAND_TYPE_NONE}},
995 {"EnqueuedWorkgroupSize",
996 BuiltInEnqueuedWorkgroupSize,
997 SPV_OPCODE_FLAGS_CAPABILITIES,
998 CapabilityKernel,
999 {SPV_OPERAND_TYPE_NONE}},
1000 {"GlobalOffset",
1001 BuiltInGlobalOffset,
1002 SPV_OPCODE_FLAGS_CAPABILITIES,
1003 CapabilityKernel,
1004 {SPV_OPERAND_TYPE_NONE}},
1005 {"GlobalLinearId",
1006 BuiltInGlobalLinearId,
1007 SPV_OPCODE_FLAGS_CAPABILITIES,
1008 CapabilityKernel,
1009 {SPV_OPERAND_TYPE_NONE}},
1010 {"WorkgroupLinearId",
1011 BuiltInWorkgroupLinearId,
1012 SPV_OPCODE_FLAGS_CAPABILITIES,
1013 CapabilityKernel,
1014 {SPV_OPERAND_TYPE_NONE}},
1015 {"SubgroupSize",
1016 BuiltInSubgroupSize,
1017 SPV_OPCODE_FLAGS_CAPABILITIES,
1018 CapabilityKernel,
1019 {SPV_OPERAND_TYPE_NONE}},
1020 {"SubgroupMaxSize",
1021 BuiltInSubgroupMaxSize,
1022 SPV_OPCODE_FLAGS_CAPABILITIES,
1023 CapabilityKernel,
1024 {SPV_OPERAND_TYPE_NONE}},
1025 {"NumSubgroups",
1026 BuiltInNumSubgroups,
1027 SPV_OPCODE_FLAGS_CAPABILITIES,
1028 CapabilityKernel,
1029 {SPV_OPERAND_TYPE_NONE}},
1030 {"NumEnqueuedSubgroups",
1031 BuiltInNumEnqueuedSubgroups,
1032 SPV_OPCODE_FLAGS_CAPABILITIES,
1033 CapabilityKernel,
1034 {SPV_OPERAND_TYPE_NONE}},
1035 {"SubgroupId",
David Neto37547b22015-09-10 13:23:11 -04001036 BuiltInSubgroupId,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001037 SPV_OPCODE_FLAGS_CAPABILITIES,
1038 CapabilityKernel,
1039 {SPV_OPERAND_TYPE_NONE}},
1040 {"SubgroupLocalInvocationId",
1041 BuiltInSubgroupLocalInvocationId,
1042 SPV_OPCODE_FLAGS_CAPABILITIES,
1043 CapabilityKernel,
1044 {SPV_OPERAND_TYPE_NONE}},
1045};
1046
1047static const spv_operand_desc_t selectionControlEntries[] = {
1048 {"None",
1049 SelectionControlMaskNone,
1050 SPV_OPCODE_FLAGS_NONE,
1051 0,
1052 {SPV_OPERAND_TYPE_NONE}},
1053 {"Flatten",
1054 SelectionControlFlattenMask,
1055 SPV_OPCODE_FLAGS_NONE,
1056 0,
1057 {SPV_OPERAND_TYPE_NONE}},
1058 {"DontFlatten",
1059 SelectionControlDontFlattenMask,
1060 SPV_OPCODE_FLAGS_NONE,
1061 0,
1062 {SPV_OPERAND_TYPE_NONE}},
1063};
1064
1065static const spv_operand_desc_t loopControlEntries[] = {
1066 {"None",
1067 LoopControlMaskNone,
1068 SPV_OPCODE_FLAGS_NONE,
1069 0,
1070 {SPV_OPERAND_TYPE_NONE}},
1071 {"Unroll",
1072 LoopControlUnrollMask,
1073 SPV_OPCODE_FLAGS_NONE,
1074 0,
1075 {SPV_OPERAND_TYPE_NONE}},
1076 {"DontUnroll",
1077 LoopControlDontUnrollMask,
1078 SPV_OPCODE_FLAGS_NONE,
1079 0,
1080 {SPV_OPERAND_TYPE_NONE}},
1081};
1082
1083static const spv_operand_desc_t functionControlEntries[] = {
1084 {"None",
1085 FunctionControlMaskNone,
1086 SPV_OPCODE_FLAGS_NONE,
1087 0,
1088 {SPV_OPERAND_TYPE_NONE}},
David Netof4fde6c2015-09-14 14:50:37 -04001089 {"Inline",
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001090 FunctionControlInlineMask,
1091 SPV_OPCODE_FLAGS_NONE,
1092 0,
1093 {SPV_OPERAND_TYPE_NONE}},
1094 {"DontInline",
1095 FunctionControlDontInlineMask,
1096 SPV_OPCODE_FLAGS_NONE,
1097 0,
1098 {SPV_OPERAND_TYPE_NONE}},
1099 {"Pure",
1100 FunctionControlPureMask,
1101 SPV_OPCODE_FLAGS_NONE,
1102 0,
1103 {SPV_OPERAND_TYPE_NONE}},
1104 {"Const",
1105 FunctionControlConstMask,
1106 SPV_OPCODE_FLAGS_NONE,
1107 0,
1108 {SPV_OPERAND_TYPE_NONE}},
1109};
1110
1111static const spv_operand_desc_t memorySemanticsEntries[] = {
1112 {"None",
1113 MemorySemanticsMaskNone,
1114 SPV_OPCODE_FLAGS_NONE,
1115 0,
1116 {SPV_OPERAND_TYPE_NONE}},
1117 {"Relaxed",
1118 MemorySemanticsRelaxedMask,
1119 SPV_OPCODE_FLAGS_NONE,
1120 0,
1121 {SPV_OPERAND_TYPE_NONE}},
1122 {"SequentiallyConsistent",
1123 MemorySemanticsSequentiallyConsistentMask,
1124 SPV_OPCODE_FLAGS_NONE,
1125 0,
1126 {SPV_OPERAND_TYPE_NONE}},
1127 {"Acquire",
1128 MemorySemanticsAcquireMask,
1129 SPV_OPCODE_FLAGS_NONE,
1130 0,
1131 {SPV_OPERAND_TYPE_NONE}},
1132 {"Release",
1133 MemorySemanticsReleaseMask,
1134 SPV_OPCODE_FLAGS_NONE,
1135 0,
1136 {SPV_OPERAND_TYPE_NONE}},
1137 {"UniformMemory",
1138 MemorySemanticsUniformMemoryMask,
1139 SPV_OPCODE_FLAGS_CAPABILITIES,
1140 CapabilityShader,
1141 {SPV_OPERAND_TYPE_NONE}},
1142 {"SubgroupMemory",
1143 MemorySemanticsSubgroupMemoryMask,
1144 SPV_OPCODE_FLAGS_NONE,
1145 0,
1146 {SPV_OPERAND_TYPE_NONE}},
1147 {"WorkgroupLocalMemory",
1148 MemorySemanticsWorkgroupLocalMemoryMask,
1149 SPV_OPCODE_FLAGS_NONE,
1150 0,
1151 {SPV_OPERAND_TYPE_NONE}},
1152 {"WorkgroupGlobalMemory",
1153 MemorySemanticsWorkgroupGlobalMemoryMask,
1154 SPV_OPCODE_FLAGS_NONE,
1155 0,
1156 {SPV_OPERAND_TYPE_NONE}},
1157 {"AtomicCounterMemory",
1158 MemorySemanticsAtomicCounterMemoryMask,
1159 SPV_OPCODE_FLAGS_CAPABILITIES,
1160 CapabilityShader,
1161 {SPV_OPERAND_TYPE_NONE}},
1162 {
1163 "ImageMemory",
1164 MemorySemanticsImageMemoryMask,
1165 SPV_OPCODE_FLAGS_NONE,
1166 0,
1167 {SPV_OPERAND_TYPE_NONE},
1168 },
1169};
1170
1171static const spv_operand_desc_t memoryAccessEntries[] = {
1172 {"None",
1173 MemoryAccessMaskNone,
1174 SPV_OPCODE_FLAGS_NONE,
1175 0,
1176 {SPV_OPERAND_TYPE_NONE}},
1177 {"Volatile",
1178 MemoryAccessVolatileMask,
1179 SPV_OPCODE_FLAGS_NONE,
1180 0,
1181 {SPV_OPERAND_TYPE_NONE}},
1182 {
1183 "Aligned",
1184 MemoryAccessAlignedMask,
1185 SPV_OPCODE_FLAGS_NONE,
1186 0,
David Neto4a291312015-09-14 15:08:48 -04001187 {SPV_OPERAND_TYPE_LITERAL_NUMBER, SPV_OPERAND_TYPE_NONE},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001188 },
1189};
1190
1191static const spv_operand_desc_t scopeEntries[] = {
1192 {"CrossDevice",
1193 ScopeCrossDevice,
1194 SPV_OPCODE_FLAGS_NONE,
1195 0,
1196 {SPV_OPERAND_TYPE_NONE}},
1197 {"Device", ScopeDevice, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}},
1198 {"Workgroup",
1199 ScopeWorkgroup,
1200 SPV_OPCODE_FLAGS_NONE,
1201 0,
1202 {SPV_OPERAND_TYPE_NONE}},
1203 {"Subgroup",
1204 ScopeSubgroup,
1205 SPV_OPCODE_FLAGS_NONE,
1206 0,
1207 {SPV_OPERAND_TYPE_NONE}},
1208 {
1209 "Invocation",
1210 ScopeInvocation,
1211 SPV_OPCODE_FLAGS_NONE,
1212 0,
1213 {SPV_OPERAND_TYPE_NONE},
1214 },
1215};
1216
1217static const spv_operand_desc_t groupOperationEntries[] = {
1218 {"Reduce",
1219 GroupOperationReduce,
1220 SPV_OPCODE_FLAGS_CAPABILITIES,
1221 CapabilityKernel,
1222 {SPV_OPERAND_TYPE_NONE}},
1223 {"InclusiveScan",
1224 GroupOperationInclusiveScan,
1225 SPV_OPCODE_FLAGS_CAPABILITIES,
1226 CapabilityKernel,
1227 {SPV_OPERAND_TYPE_NONE}},
1228 {"ExclusiveScan",
1229 GroupOperationExclusiveScan,
1230 SPV_OPCODE_FLAGS_CAPABILITIES,
1231 CapabilityKernel,
1232 {SPV_OPERAND_TYPE_NONE}},
1233};
1234
1235static const spv_operand_desc_t kernelKernelEnqueueFlagssEntries[] = {
1236 {"NoWait",
1237 KernelEnqueueFlagsNoWait,
1238 SPV_OPCODE_FLAGS_CAPABILITIES,
1239 CapabilityKernel,
1240 {SPV_OPERAND_TYPE_NONE}},
1241 {"WaitKernel",
1242 KernelEnqueueFlagsWaitKernel,
1243 SPV_OPCODE_FLAGS_CAPABILITIES,
1244 CapabilityKernel,
1245 {SPV_OPERAND_TYPE_NONE}},
1246 {"WaitWorkGroup",
1247 KernelEnqueueFlagsWaitWorkGroup,
1248 SPV_OPCODE_FLAGS_CAPABILITIES,
1249 CapabilityKernel,
1250 {SPV_OPERAND_TYPE_NONE}},
1251};
1252
1253static const spv_operand_desc_t kernelProfilingInfoEntries[] = {
1254 {"None",
1255 KernelProfilingInfoMaskNone,
1256 SPV_OPCODE_FLAGS_NONE,
1257 0,
1258 {SPV_OPERAND_TYPE_NONE}},
1259 {"CmdExecTime",
1260 KernelProfilingInfoCmdExecTimeMask,
1261 SPV_OPCODE_FLAGS_CAPABILITIES,
1262 CapabilityKernel,
1263 {SPV_OPERAND_TYPE_NONE}},
1264};
1265
1266static const spv_operand_desc_t capabilityInfoEntries[] = {
1267 {"Matrix",
1268 CapabilityMatrix,
1269 SPV_OPCODE_FLAGS_NONE,
1270 0,
1271 {SPV_OPERAND_TYPE_NONE}},
1272 {"Shader",
1273 CapabilityShader,
1274 SPV_OPCODE_FLAGS_CAPABILITIES,
1275 CapabilityMatrix,
1276 {SPV_OPERAND_TYPE_NONE}},
1277 {"Geometry",
1278 CapabilityGeometry,
1279 SPV_OPCODE_FLAGS_CAPABILITIES,
1280 CapabilityShader,
1281 {SPV_OPERAND_TYPE_NONE}},
1282 {"Tessellation",
1283 CapabilityTessellation,
1284 SPV_OPCODE_FLAGS_CAPABILITIES,
1285 CapabilityShader,
1286 {SPV_OPERAND_TYPE_NONE}},
1287 {"Addresses",
1288 CapabilityAddresses,
1289 SPV_OPCODE_FLAGS_NONE,
1290 0,
1291 {SPV_OPERAND_TYPE_NONE}},
1292 {"Linkage",
1293 CapabilityLinkage,
1294 SPV_OPCODE_FLAGS_NONE,
1295 0,
1296 {SPV_OPERAND_TYPE_NONE}},
1297 {"Kernel",
1298 CapabilityKernel,
1299 SPV_OPCODE_FLAGS_NONE,
1300 0,
1301 {SPV_OPERAND_TYPE_NONE}},
1302 {"Vector16",
1303 CapabilityVector16,
1304 SPV_OPCODE_FLAGS_NONE,
1305 0,
1306 {SPV_OPERAND_TYPE_NONE}},
1307 {"Float16Buffer",
1308 CapabilityFloat16Buffer,
1309 SPV_OPCODE_FLAGS_NONE,
1310 0,
1311 {SPV_OPERAND_TYPE_NONE}},
1312 {"Float16",
1313 CapabilityFloat16,
1314 SPV_OPCODE_FLAGS_NONE,
1315 0,
1316 {SPV_OPERAND_TYPE_NONE}},
1317 {"Float64",
1318 CapabilityFloat64,
1319 SPV_OPCODE_FLAGS_NONE,
1320 0,
1321 {SPV_OPERAND_TYPE_NONE}},
1322 {"Int64",
1323 CapabilityInt64,
1324 SPV_OPCODE_FLAGS_NONE,
1325 0,
1326 {SPV_OPERAND_TYPE_NONE}},
1327 {"Int64Atomics",
1328 CapabilityInt64Atomics,
1329 SPV_OPCODE_FLAGS_NONE,
1330 0,
1331 {SPV_OPERAND_TYPE_NONE}},
1332 {"ImageBasic",
1333 CapabilityImageBasic,
1334 SPV_OPCODE_FLAGS_NONE,
1335 0,
1336 {SPV_OPERAND_TYPE_NONE}},
1337 {"ImageReadWrite",
1338 CapabilityImageReadWrite,
1339 SPV_OPCODE_FLAGS_NONE,
1340 0,
1341 {SPV_OPERAND_TYPE_NONE}},
David Netoc6402d62015-09-10 16:39:09 -04001342 {"ImageMipmap",
1343 CapabilityImageMipmap,
1344 SPV_OPCODE_FLAGS_NONE,
1345 0,
1346 {SPV_OPERAND_TYPE_NONE}},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001347 {"ImageSRGBWrite",
1348 CapabilityImageSRGBWrite,
1349 SPV_OPCODE_FLAGS_NONE,
1350 0,
1351 {SPV_OPERAND_TYPE_NONE}},
1352 {"Pipes",
1353 CapabilityPipes,
1354 SPV_OPCODE_FLAGS_NONE,
1355 0,
1356 {SPV_OPERAND_TYPE_NONE}},
1357 {"Groups",
1358 CapabilityGroups,
1359 SPV_OPCODE_FLAGS_NONE,
1360 0,
1361 {SPV_OPERAND_TYPE_NONE}},
1362 {"DeviceEnqueue",
1363 CapabilityDeviceEnqueue,
1364 SPV_OPCODE_FLAGS_NONE,
1365 0,
1366 {SPV_OPERAND_TYPE_NONE}},
David Netoc6402d62015-09-10 16:39:09 -04001367// A macro for defining a capability that doesn't depend on other capabilities.
David Netoe994e2e2015-09-11 12:15:58 -04001368// TODO(dneto): Rev32 adds many dependencies between capbilities.
David Netoc6402d62015-09-10 16:39:09 -04001369#define CASE(NAME) { #NAME, Capability##NAME, SPV_OPCODE_FLAGS_NONE, 0, {SPV_OPERAND_TYPE_NONE}}
1370 CASE(LiteralSampler),
1371 CASE(AtomicStorage),
1372 CASE(Int16),
1373 CASE(TessellationPointSize),
1374 CASE(GeometryPointSize),
1375 CASE(ImageGatherExtended),
1376 CASE(StorageImageExtendedFormats),
1377 CASE(StorageImageMultisample),
1378 CASE(UniformBufferArrayDynamicIndexing),
1379 CASE(SampledImageArrayDynamicIndexing),
1380 CASE(StorageBufferArrayDynamicIndexing),
1381 CASE(StorageImageArrayDynamicIndexing),
1382 CASE(ClipDistance),
1383 CASE(CullDistance),
1384 CASE(ImageCubeArray),
1385 CASE(SampleRateShading),
1386#undef CASE
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001387};
1388
1389static const spv_operand_desc_group_t opcodeEntryTypes[] = {
1390 {SPV_OPERAND_TYPE_SOURCE_LANGUAGE,
1391 sizeof(sourceLanguageEntries) / sizeof(spv_operand_desc_t),
1392 sourceLanguageEntries},
1393 {SPV_OPERAND_TYPE_EXECUTION_MODEL,
1394 sizeof(executionModelEntries) / sizeof(spv_operand_desc_t),
1395 executionModelEntries},
1396 {SPV_OPERAND_TYPE_ADDRESSING_MODEL,
1397 sizeof(addressingModelEntries) / sizeof(spv_operand_desc_t),
1398 addressingModelEntries},
1399 {SPV_OPERAND_TYPE_MEMORY_MODEL,
1400 sizeof(memoryModelEntries) / sizeof(spv_operand_desc_t),
1401 memoryModelEntries},
1402 {SPV_OPERAND_TYPE_EXECUTION_MODE,
1403 sizeof(executionModeEntries) / sizeof(spv_operand_desc_t),
1404 executionModeEntries},
1405 {SPV_OPERAND_TYPE_STORAGE_CLASS,
1406 sizeof(storageClassEntries) / sizeof(spv_operand_desc_t),
1407 storageClassEntries},
1408 {SPV_OPERAND_TYPE_DIMENSIONALITY,
1409 sizeof(dimensionalityEntries) / sizeof(spv_operand_desc_t),
1410 dimensionalityEntries},
1411 {SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE,
1412 sizeof(samplerAddressingModeEntries) / sizeof(spv_operand_desc_t),
1413 samplerAddressingModeEntries},
1414 {SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE,
1415 sizeof(samplerFilterModeEntries) / sizeof(spv_operand_desc_t),
1416 samplerFilterModeEntries},
David Netob30a0c52015-09-16 15:56:43 -04001417 {SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT,
1418 sizeof(samplerImageFormatEntries) / sizeof(spv_operand_desc_t),
1419 samplerImageFormatEntries},
David Netoee1b3bb2015-09-18 11:19:18 -04001420 {SPV_OPERAND_TYPE_OPTIONAL_IMAGE,
1421 sizeof(imageOperandEntries) / sizeof(spv_operand_desc_t),
1422 imageOperandEntries},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001423 {SPV_OPERAND_TYPE_FP_FAST_MATH_MODE,
1424 sizeof(fpFastMathModeEntries) / sizeof(spv_operand_desc_t),
1425 fpFastMathModeEntries},
1426 {SPV_OPERAND_TYPE_FP_ROUNDING_MODE,
1427 sizeof(fpRoundingModeEntries) / sizeof(spv_operand_desc_t),
1428 fpRoundingModeEntries},
1429 {SPV_OPERAND_TYPE_LINKAGE_TYPE,
1430 sizeof(linkageTypeEntries) / sizeof(spv_operand_desc_t),
1431 linkageTypeEntries},
1432 {SPV_OPERAND_TYPE_ACCESS_QUALIFIER,
1433 sizeof(accessQualifierEntries) / sizeof(spv_operand_desc_t),
1434 accessQualifierEntries},
1435 {SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE,
1436 sizeof(functionParameterAttributeEntries) / sizeof(spv_operand_desc_t),
1437 functionParameterAttributeEntries},
1438 {SPV_OPERAND_TYPE_DECORATION,
1439 sizeof(decorationEntries) / sizeof(spv_operand_desc_t), decorationEntries},
1440 {SPV_OPERAND_TYPE_BUILT_IN,
1441 sizeof(builtInEntries) / sizeof(spv_operand_desc_t), builtInEntries},
1442 {SPV_OPERAND_TYPE_SELECTION_CONTROL,
1443 sizeof(selectionControlEntries) / sizeof(spv_operand_desc_t),
1444 selectionControlEntries},
1445 {SPV_OPERAND_TYPE_LOOP_CONTROL,
1446 sizeof(loopControlEntries) / sizeof(spv_operand_desc_t),
1447 loopControlEntries},
1448 {SPV_OPERAND_TYPE_FUNCTION_CONTROL,
1449 sizeof(functionControlEntries) / sizeof(spv_operand_desc_t),
1450 functionControlEntries},
1451 {SPV_OPERAND_TYPE_MEMORY_SEMANTICS,
1452 sizeof(memorySemanticsEntries) / sizeof(spv_operand_desc_t),
1453 memorySemanticsEntries},
David Neto78c3b432015-08-27 13:03:52 -04001454 {SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001455 sizeof(memoryAccessEntries) / sizeof(spv_operand_desc_t),
1456 memoryAccessEntries},
1457 {SPV_OPERAND_TYPE_EXECUTION_SCOPE,
1458 sizeof(scopeEntries) / sizeof(spv_operand_desc_t), scopeEntries},
1459 {SPV_OPERAND_TYPE_GROUP_OPERATION,
1460 sizeof(groupOperationEntries) / sizeof(spv_operand_desc_t),
1461 groupOperationEntries},
1462 {SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS,
1463 sizeof(kernelKernelEnqueueFlagssEntries) / sizeof(spv_operand_desc_t),
1464 kernelKernelEnqueueFlagssEntries},
David Neto47994822015-08-27 13:11:01 -04001465 {SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001466 sizeof(kernelProfilingInfoEntries) / sizeof(spv_operand_desc_t),
1467 kernelProfilingInfoEntries},
1468 {SPV_OPERAND_TYPE_CAPABILITY,
1469 sizeof(capabilityInfoEntries) / sizeof(spv_operand_desc_t),
1470 capabilityInfoEntries},
1471};
1472
1473spv_result_t spvOperandTableGet(spv_operand_table *pOperandTable) {
Lei Zhang40056702015-09-11 14:31:27 -04001474 if (!pOperandTable) return SPV_ERROR_INVALID_POINTER;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001475
1476 static const spv_operand_table_t table = {
1477 sizeof(opcodeEntryTypes) / sizeof(spv_operand_desc_group_t),
1478 opcodeEntryTypes};
1479
1480 *pOperandTable = &table;
1481
1482 return SPV_SUCCESS;
1483}
1484
1485spv_result_t spvOperandTableNameLookup(const spv_operand_table table,
1486 const spv_operand_type_t type,
David Neto388c40d2015-09-16 16:42:56 -04001487 const char* name,
1488 const size_t nameLength,
1489 spv_operand_desc* pEntry) {
Lei Zhang40056702015-09-11 14:31:27 -04001490 if (!table) return SPV_ERROR_INVALID_TABLE;
1491 if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001492
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001493 for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
1494 if (type == table->types[typeIndex].type) {
1495 for (uint64_t operandIndex = 0;
1496 operandIndex < table->types[typeIndex].count; ++operandIndex) {
1497 if (nameLength ==
1498 strlen(table->types[typeIndex].entries[operandIndex].name) &&
1499 !strncmp(table->types[typeIndex].entries[operandIndex].name, name,
David Neto388c40d2015-09-16 16:42:56 -04001500 nameLength)) {
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001501 *pEntry = &table->types[typeIndex].entries[operandIndex];
1502 return SPV_SUCCESS;
1503 }
1504 }
1505 }
1506 }
1507
1508 return SPV_ERROR_INVALID_LOOKUP;
1509}
1510
1511spv_result_t spvOperandTableValueLookup(const spv_operand_table table,
1512 const spv_operand_type_t type,
1513 const uint32_t value,
1514 spv_operand_desc *pEntry) {
Lei Zhang40056702015-09-11 14:31:27 -04001515 if (!table) return SPV_ERROR_INVALID_TABLE;
1516 if (!pEntry) return SPV_ERROR_INVALID_POINTER;
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001517
1518 for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
1519 if (type == table->types[typeIndex].type) {
1520 for (uint64_t operandIndex = 0;
1521 operandIndex < table->types[typeIndex].count; ++operandIndex) {
1522 if (value == table->types[typeIndex].entries[operandIndex].value) {
1523 *pEntry = &table->types[typeIndex].entries[operandIndex];
1524 return SPV_SUCCESS;
1525 }
1526 }
1527 }
1528 }
1529
1530 return SPV_ERROR_INVALID_LOOKUP;
1531}
1532
1533const char *spvOperandTypeStr(spv_operand_type_t type) {
1534 switch (type) {
1535 case SPV_OPERAND_TYPE_ID:
David Netofadbf622015-09-14 17:07:11 -04001536 case SPV_OPERAND_TYPE_OPTIONAL_ID:
1537 case SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE:
1538 return "ID";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001539 case SPV_OPERAND_TYPE_RESULT_ID:
1540 return "result ID";
1541 case SPV_OPERAND_TYPE_LITERAL:
1542 return "literal";
1543 case SPV_OPERAND_TYPE_LITERAL_NUMBER:
1544 return "literal number";
Lei Zhangb41d1502015-09-14 15:22:23 -04001545 case SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER:
1546 return "multiple word literal number";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001547 case SPV_OPERAND_TYPE_LITERAL_STRING:
1548 return "literal string";
1549 case SPV_OPERAND_TYPE_SOURCE_LANGUAGE:
1550 return "source langauge";
1551 case SPV_OPERAND_TYPE_EXECUTION_MODEL:
1552 return "execution model";
1553 case SPV_OPERAND_TYPE_ADDRESSING_MODEL:
1554 return "addressing model";
1555 case SPV_OPERAND_TYPE_MEMORY_MODEL:
1556 return "memory model";
1557 case SPV_OPERAND_TYPE_EXECUTION_MODE:
1558 return "execution mode";
1559 case SPV_OPERAND_TYPE_STORAGE_CLASS:
1560 return "storage class";
1561 case SPV_OPERAND_TYPE_DIMENSIONALITY:
1562 return "dimensionality";
1563 case SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE:
1564 return "addressing mode";
1565 case SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE:
1566 return "sampler filter mode";
David Netob30a0c52015-09-16 15:56:43 -04001567 case SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT:
1568 return "sampler image format";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001569 case SPV_OPERAND_TYPE_FP_FAST_MATH_MODE:
1570 return "floating pointer fast math mode";
1571 case SPV_OPERAND_TYPE_FP_ROUNDING_MODE:
1572 return "floating point rounding mode";
1573 case SPV_OPERAND_TYPE_LINKAGE_TYPE:
1574 return "linkage type";
1575 case SPV_OPERAND_TYPE_ACCESS_QUALIFIER:
1576 return "access qualifier";
1577 case SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE:
1578 return "function parameter attribute";
1579 case SPV_OPERAND_TYPE_DECORATION:
1580 return "decoration";
1581 case SPV_OPERAND_TYPE_BUILT_IN:
1582 return "built in";
1583 case SPV_OPERAND_TYPE_SELECTION_CONTROL:
1584 return "selection control";
1585 case SPV_OPERAND_TYPE_LOOP_CONTROL:
1586 return "loop control";
1587 case SPV_OPERAND_TYPE_FUNCTION_CONTROL:
1588 return "function control";
1589 case SPV_OPERAND_TYPE_MEMORY_SEMANTICS:
1590 return "memory semantics";
David Neto78c3b432015-08-27 13:03:52 -04001591 case SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001592 return "memory access";
1593 case SPV_OPERAND_TYPE_EXECUTION_SCOPE:
David Netofadbf622015-09-14 17:07:11 -04001594 return "execution scope ID";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001595 case SPV_OPERAND_TYPE_GROUP_OPERATION:
1596 return "group operation";
1597 case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS:
1598 return "kernel enqeue flags";
David Neto47994822015-08-27 13:11:01 -04001599 case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO:
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001600 return "kernel profiling info";
1601 case SPV_OPERAND_TYPE_CAPABILITY:
1602 return "capability";
David Netoee1b3bb2015-09-18 11:19:18 -04001603 case SPV_OPERAND_TYPE_OPTIONAL_IMAGE:
1604 return "image operand";
David Neto78c3b432015-08-27 13:03:52 -04001605 case SPV_OPERAND_TYPE_NONE:
1606 return "NONE";
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001607 default:
1608 assert(0 && "Unhandled operand type!");
1609 break;
1610 }
1611 return "unknown";
1612}
David Neto78c3b432015-08-27 13:03:52 -04001613
1614void spvPrependOperandTypes(const spv_operand_type_t* types,
1615 spv_operand_pattern_t* pattern) {
1616 const spv_operand_type_t* endTypes;
1617 for (endTypes = types ; *endTypes != SPV_OPERAND_TYPE_NONE ; ++endTypes)
1618 ;
1619 pattern->insert(pattern->begin(), types, endTypes);
1620}
1621
David Neto5bf88fc2015-09-17 17:06:10 -04001622void spvPrependOperandTypesForMask(const spv_operand_table operandTable,
1623 const spv_operand_type_t type,
1624 const uint32_t mask,
1625 spv_operand_pattern_t* pattern) {
1626 // Scan from highest bits to lowest bits because we will prepend in LIFO
1627 // fashion, and we need the operands for lower order bits to appear first.
1628 for (uint32_t candidate_bit = (1 << 31); candidate_bit; candidate_bit >>= 1) {
1629 if (candidate_bit & mask) {
1630 spv_operand_desc entry = nullptr;
1631 if (SPV_SUCCESS == spvOperandTableValueLookup(operandTable, type,
1632 candidate_bit, &entry)) {
1633 spvPrependOperandTypes(entry->operandTypes, pattern);
1634 }
1635 }
1636 }
1637}
1638
David Neto78c3b432015-08-27 13:03:52 -04001639bool spvOperandIsOptional(spv_operand_type_t type) {
1640 // Variable means zero or more times.
1641 if (spvOperandIsVariable(type))
1642 return true;
1643
1644 switch (type) {
1645 case SPV_OPERAND_TYPE_OPTIONAL_ID:
1646 case SPV_OPERAND_TYPE_OPTIONAL_IMAGE:
1647 case SPV_OPERAND_TYPE_OPTIONAL_LITERAL:
1648 case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING:
1649 case SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS:
1650 case SPV_OPERAND_TYPE_OPTIONAL_EXECUTION_MODE:
1651 return true;
1652 default:
1653 break;
1654 }
1655 return false;
1656}
1657
1658bool spvOperandIsVariable(spv_operand_type_t type) {
1659 switch (type) {
1660 case SPV_OPERAND_TYPE_VARIABLE_ID:
1661 case SPV_OPERAND_TYPE_VARIABLE_LITERAL:
1662 case SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL:
1663 case SPV_OPERAND_TYPE_VARIABLE_LITERAL_ID:
David Neto78c3b432015-08-27 13:03:52 -04001664 case SPV_OPERAND_TYPE_VARIABLE_EXECUTION_MODE:
1665 return true;
1666 default:
1667 break;
1668 }
1669 return false;
1670}
1671
1672
1673bool spvExpandOperandSequenceOnce(spv_operand_type_t type,
1674 spv_operand_pattern_t* pattern) {
1675 switch (type) {
1676 case SPV_OPERAND_TYPE_VARIABLE_ID:
1677 pattern->insert(pattern->begin(), {SPV_OPERAND_TYPE_OPTIONAL_ID, type});
1678 return true;
1679 case SPV_OPERAND_TYPE_VARIABLE_LITERAL:
1680 pattern->insert(pattern->begin(),
1681 {SPV_OPERAND_TYPE_OPTIONAL_LITERAL, type});
1682 return true;
1683 case SPV_OPERAND_TYPE_VARIABLE_LITERAL_ID:
1684 // Represents Zero or more (Literal, Id) pairs.
1685 pattern->insert(pattern->begin(),
1686 {SPV_OPERAND_TYPE_OPTIONAL_LITERAL,
1687 SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE, type});
1688 return true;
1689 case SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL:
1690 // Represents Zero or more (Id, Literal) pairs.
1691 pattern->insert(pattern->begin(),
1692 {SPV_OPERAND_TYPE_OPTIONAL_ID,
1693 SPV_OPERAND_TYPE_LITERAL_IN_OPTIONAL_TUPLE, type});
1694 return true;
David Neto78c3b432015-08-27 13:03:52 -04001695 case SPV_OPERAND_TYPE_VARIABLE_EXECUTION_MODE:
1696 pattern->insert(pattern->begin(), {SPV_OPERAND_TYPE_OPTIONAL_EXECUTION_MODE, type});
1697 return true;
1698 default:
1699 break;
1700 }
1701 return false;
1702}
1703
1704spv_operand_type_t spvTakeFirstMatchableOperand(spv_operand_pattern_t* pattern) {
1705 assert(!pattern->empty());
1706 spv_operand_type_t result;
1707 do {
1708 result = pattern->front();
1709 pattern->pop_front();
1710 } while(spvExpandOperandSequenceOnce(result, pattern));
1711 return result;
1712}