1 //
2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2012-2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // Redistributions in binary form must reproduce the above
17 // copyright notice, this list of conditions and the following
18 // disclaimer in the documentation and/or other materials provided
19 // with the distribution.
20 //
21 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
22 // contributors may be used to endorse or promote products derived
23 // from this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
37 //
38
39 #ifndef _BASICTYPES_INCLUDED_
40 #define _BASICTYPES_INCLUDED_
41
42 namespace glslang {
43
44 //
45 // Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
46 //
47 enum TBasicType {
48 EbtVoid,
49 EbtFloat,
50 EbtDouble,
51 EbtFloat16,
52 EbtInt8,
53 EbtUint8,
54 EbtInt16,
55 EbtUint16,
56 EbtInt,
57 EbtUint,
58 EbtInt64,
59 EbtUint64,
60 EbtBool,
61 EbtAtomicUint,
62 EbtSampler,
63 EbtStruct,
64 EbtBlock,
65 EbtAccStruct,
66 EbtReference,
67 EbtRayQuery,
68
69 // HLSL types that live only temporarily.
70 EbtString,
71
72 EbtNumTypes
73 };
74
75 //
76 // Storage qualifiers. Should align with different kinds of storage or
77 // resource or GLSL storage qualifier. Expansion is deprecated.
78 //
79 // N.B.: You probably DON'T want to add anything here, but rather just add it
80 // to the built-in variables. See the comment above TBuiltInVariable.
81 //
82 // A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
83 // DO NOT follow the design pattern of, say EvqInstanceId, etc.
84 //
85 enum TStorageQualifier {
86 EvqTemporary, // For temporaries (within a function), read/write
87 EvqGlobal, // For globals read/write
88 EvqConst, // User-defined constant values, will be semantically constant and constant folded
89 EvqVaryingIn, // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
90 EvqVaryingOut, // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
91 EvqUniform, // read only, shared with app
92 EvqBuffer, // read/write, shared with app
93 EvqShared, // compute shader's read/write 'shared' qualifier
94
95 EvqPayload,
96 EvqPayloadIn,
97 EvqHitAttr,
98 EvqCallableData,
99 EvqCallableDataIn,
100
101 // parameters
102 EvqIn, // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
103 EvqOut, // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
104 EvqInOut,
105 EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
106
107 // built-ins read by vertex shader
108 EvqVertexId,
109 EvqInstanceId,
110
111 // built-ins written by vertex shader
112 EvqPosition,
113 EvqPointSize,
114 EvqClipVertex,
115
116 // built-ins read by fragment shader
117 EvqFace,
118 EvqFragCoord,
119 EvqPointCoord,
120
121 // built-ins written by fragment shader
122 EvqFragColor,
123 EvqFragDepth,
124
125 // end of list
126 EvqLast
127 };
128
129 //
130 // Subcategories of the TStorageQualifier, simply to give a direct mapping
131 // between built-in variable names and an numerical value (the enum).
132 //
133 // For backward compatibility, there is some redundancy between the
134 // TStorageQualifier and these. Existing members should both be maintained accurately.
135 // However, any new built-in variable (and any existing non-redundant one)
136 // must follow the pattern that the specific built-in is here, and only its
137 // general qualifier is in TStorageQualifier.
138 //
139 // Something like gl_Position, which is sometimes 'in' and sometimes 'out'
140 // shows up as two different built-in variables in a single stage, but
141 // only has a single enum in TBuiltInVariable, so both the
142 // TStorageQualifier and the TBuitinVariable are needed to distinguish
143 // between them.
144 //
145 enum TBuiltInVariable {
146 EbvNone,
147 EbvNumWorkGroups,
148 EbvWorkGroupSize,
149 EbvWorkGroupId,
150 EbvLocalInvocationId,
151 EbvGlobalInvocationId,
152 EbvLocalInvocationIndex,
153 EbvNumSubgroups,
154 EbvSubgroupID,
155 EbvSubGroupSize,
156 EbvSubGroupInvocation,
157 EbvSubGroupEqMask,
158 EbvSubGroupGeMask,
159 EbvSubGroupGtMask,
160 EbvSubGroupLeMask,
161 EbvSubGroupLtMask,
162 EbvSubgroupSize2,
163 EbvSubgroupInvocation2,
164 EbvSubgroupEqMask2,
165 EbvSubgroupGeMask2,
166 EbvSubgroupGtMask2,
167 EbvSubgroupLeMask2,
168 EbvSubgroupLtMask2,
169 EbvVertexId,
170 EbvInstanceId,
171 EbvVertexIndex,
172 EbvInstanceIndex,
173 EbvBaseVertex,
174 EbvBaseInstance,
175 EbvDrawId,
176 EbvPosition,
177 EbvPointSize,
178 EbvClipVertex,
179 EbvClipDistance,
180 EbvCullDistance,
181 EbvNormal,
182 EbvVertex,
183 EbvMultiTexCoord0,
184 EbvMultiTexCoord1,
185 EbvMultiTexCoord2,
186 EbvMultiTexCoord3,
187 EbvMultiTexCoord4,
188 EbvMultiTexCoord5,
189 EbvMultiTexCoord6,
190 EbvMultiTexCoord7,
191 EbvFrontColor,
192 EbvBackColor,
193 EbvFrontSecondaryColor,
194 EbvBackSecondaryColor,
195 EbvTexCoord,
196 EbvFogFragCoord,
197 EbvInvocationId,
198 EbvPrimitiveId,
199 EbvLayer,
200 EbvViewportIndex,
201 EbvPatchVertices,
202 EbvTessLevelOuter,
203 EbvTessLevelInner,
204 EbvBoundingBox,
205 EbvTessCoord,
206 EbvColor,
207 EbvSecondaryColor,
208 EbvFace,
209 EbvFragCoord,
210 EbvPointCoord,
211 EbvFragColor,
212 EbvFragData,
213 EbvFragDepth,
214 EbvFragStencilRef,
215 EbvSampleId,
216 EbvSamplePosition,
217 EbvSampleMask,
218 EbvHelperInvocation,
219
220 EbvBaryCoordNoPersp,
221 EbvBaryCoordNoPerspCentroid,
222 EbvBaryCoordNoPerspSample,
223 EbvBaryCoordSmooth,
224 EbvBaryCoordSmoothCentroid,
225 EbvBaryCoordSmoothSample,
226 EbvBaryCoordPullModel,
227
228 EbvViewIndex,
229 EbvDeviceIndex,
230
231 EbvShadingRateKHR,
232 EbvPrimitiveShadingRateKHR,
233
234 EbvFragSizeEXT,
235 EbvFragInvocationCountEXT,
236
237 EbvSecondaryFragDataEXT,
238 EbvSecondaryFragColorEXT,
239
240 EbvViewportMaskNV,
241 EbvSecondaryPositionNV,
242 EbvSecondaryViewportMaskNV,
243 EbvPositionPerViewNV,
244 EbvViewportMaskPerViewNV,
245 EbvFragFullyCoveredNV,
246 EbvFragmentSizeNV,
247 EbvInvocationsPerPixelNV,
248 // ray tracing
249 EbvLaunchId,
250 EbvLaunchSize,
251 EbvInstanceCustomIndex,
252 EbvGeometryIndex,
253 EbvWorldRayOrigin,
254 EbvWorldRayDirection,
255 EbvObjectRayOrigin,
256 EbvObjectRayDirection,
257 EbvRayTmin,
258 EbvRayTmax,
259 EbvHitT,
260 EbvHitKind,
261 EbvObjectToWorld,
262 EbvObjectToWorld3x4,
263 EbvWorldToObject,
264 EbvWorldToObject3x4,
265 EbvIncomingRayFlags,
266 // barycentrics
267 EbvBaryCoordNV,
268 EbvBaryCoordNoPerspNV,
269 // mesh shaders
270 EbvTaskCountNV,
271 EbvPrimitiveCountNV,
272 EbvPrimitiveIndicesNV,
273 EbvClipDistancePerViewNV,
274 EbvCullDistancePerViewNV,
275 EbvLayerPerViewNV,
276 EbvMeshViewCountNV,
277 EbvMeshViewIndicesNV,
278
279 // sm builtins
280 EbvWarpsPerSM,
281 EbvSMCount,
282 EbvWarpID,
283 EbvSMID,
284
285 // HLSL built-ins that live only temporarily, until they get remapped
286 // to one of the above.
287 EbvFragDepthGreater,
288 EbvFragDepthLesser,
289 EbvGsOutputStream,
290 EbvOutputPatch,
291 EbvInputPatch,
292
293 // structbuffer types
294 EbvAppendConsume, // no need to differentiate append and consume
295 EbvRWStructuredBuffer,
296 EbvStructuredBuffer,
297 EbvByteAddressBuffer,
298 EbvRWByteAddressBuffer,
299
300 EbvLast
301 };
302
303 // In this enum, order matters; users can assume higher precision is a bigger value
304 // and EpqNone is 0.
305 enum TPrecisionQualifier {
306 EpqNone = 0,
307 EpqLow,
308 EpqMedium,
309 EpqHigh
310 };
311
312 #ifdef GLSLANG_WEB
GetStorageQualifierString(TStorageQualifier q)313 __inline const char* GetStorageQualifierString(TStorageQualifier q) { return ""; }
GetPrecisionQualifierString(TPrecisionQualifier p)314 __inline const char* GetPrecisionQualifierString(TPrecisionQualifier p) { return ""; }
315 #else
316 // These will show up in error messages
GetStorageQualifierString(TStorageQualifier q)317 __inline const char* GetStorageQualifierString(TStorageQualifier q)
318 {
319 switch (q) {
320 case EvqTemporary: return "temp"; break;
321 case EvqGlobal: return "global"; break;
322 case EvqConst: return "const"; break;
323 case EvqConstReadOnly: return "const (read only)"; break;
324 case EvqVaryingIn: return "in"; break;
325 case EvqVaryingOut: return "out"; break;
326 case EvqUniform: return "uniform"; break;
327 case EvqBuffer: return "buffer"; break;
328 case EvqShared: return "shared"; break;
329 case EvqIn: return "in"; break;
330 case EvqOut: return "out"; break;
331 case EvqInOut: return "inout"; break;
332 case EvqVertexId: return "gl_VertexId"; break;
333 case EvqInstanceId: return "gl_InstanceId"; break;
334 case EvqPosition: return "gl_Position"; break;
335 case EvqPointSize: return "gl_PointSize"; break;
336 case EvqClipVertex: return "gl_ClipVertex"; break;
337 case EvqFace: return "gl_FrontFacing"; break;
338 case EvqFragCoord: return "gl_FragCoord"; break;
339 case EvqPointCoord: return "gl_PointCoord"; break;
340 case EvqFragColor: return "fragColor"; break;
341 case EvqFragDepth: return "gl_FragDepth"; break;
342 case EvqPayload: return "rayPayloadNV"; break;
343 case EvqPayloadIn: return "rayPayloadInNV"; break;
344 case EvqHitAttr: return "hitAttributeNV"; break;
345 case EvqCallableData: return "callableDataNV"; break;
346 case EvqCallableDataIn: return "callableDataInNV"; break;
347 default: return "unknown qualifier";
348 }
349 }
350
GetBuiltInVariableString(TBuiltInVariable v)351 __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
352 {
353 switch (v) {
354 case EbvNone: return "";
355 case EbvNumWorkGroups: return "NumWorkGroups";
356 case EbvWorkGroupSize: return "WorkGroupSize";
357 case EbvWorkGroupId: return "WorkGroupID";
358 case EbvLocalInvocationId: return "LocalInvocationID";
359 case EbvGlobalInvocationId: return "GlobalInvocationID";
360 case EbvLocalInvocationIndex: return "LocalInvocationIndex";
361 case EbvNumSubgroups: return "NumSubgroups";
362 case EbvSubgroupID: return "SubgroupID";
363 case EbvSubGroupSize: return "SubGroupSize";
364 case EbvSubGroupInvocation: return "SubGroupInvocation";
365 case EbvSubGroupEqMask: return "SubGroupEqMask";
366 case EbvSubGroupGeMask: return "SubGroupGeMask";
367 case EbvSubGroupGtMask: return "SubGroupGtMask";
368 case EbvSubGroupLeMask: return "SubGroupLeMask";
369 case EbvSubGroupLtMask: return "SubGroupLtMask";
370 case EbvSubgroupSize2: return "SubgroupSize";
371 case EbvSubgroupInvocation2: return "SubgroupInvocationID";
372 case EbvSubgroupEqMask2: return "SubgroupEqMask";
373 case EbvSubgroupGeMask2: return "SubgroupGeMask";
374 case EbvSubgroupGtMask2: return "SubgroupGtMask";
375 case EbvSubgroupLeMask2: return "SubgroupLeMask";
376 case EbvSubgroupLtMask2: return "SubgroupLtMask";
377 case EbvVertexId: return "VertexId";
378 case EbvInstanceId: return "InstanceId";
379 case EbvVertexIndex: return "VertexIndex";
380 case EbvInstanceIndex: return "InstanceIndex";
381 case EbvBaseVertex: return "BaseVertex";
382 case EbvBaseInstance: return "BaseInstance";
383 case EbvDrawId: return "DrawId";
384 case EbvPosition: return "Position";
385 case EbvPointSize: return "PointSize";
386 case EbvClipVertex: return "ClipVertex";
387 case EbvClipDistance: return "ClipDistance";
388 case EbvCullDistance: return "CullDistance";
389 case EbvNormal: return "Normal";
390 case EbvVertex: return "Vertex";
391 case EbvMultiTexCoord0: return "MultiTexCoord0";
392 case EbvMultiTexCoord1: return "MultiTexCoord1";
393 case EbvMultiTexCoord2: return "MultiTexCoord2";
394 case EbvMultiTexCoord3: return "MultiTexCoord3";
395 case EbvMultiTexCoord4: return "MultiTexCoord4";
396 case EbvMultiTexCoord5: return "MultiTexCoord5";
397 case EbvMultiTexCoord6: return "MultiTexCoord6";
398 case EbvMultiTexCoord7: return "MultiTexCoord7";
399 case EbvFrontColor: return "FrontColor";
400 case EbvBackColor: return "BackColor";
401 case EbvFrontSecondaryColor: return "FrontSecondaryColor";
402 case EbvBackSecondaryColor: return "BackSecondaryColor";
403 case EbvTexCoord: return "TexCoord";
404 case EbvFogFragCoord: return "FogFragCoord";
405 case EbvInvocationId: return "InvocationID";
406 case EbvPrimitiveId: return "PrimitiveID";
407 case EbvLayer: return "Layer";
408 case EbvViewportIndex: return "ViewportIndex";
409 case EbvPatchVertices: return "PatchVertices";
410 case EbvTessLevelOuter: return "TessLevelOuter";
411 case EbvTessLevelInner: return "TessLevelInner";
412 case EbvBoundingBox: return "BoundingBox";
413 case EbvTessCoord: return "TessCoord";
414 case EbvColor: return "Color";
415 case EbvSecondaryColor: return "SecondaryColor";
416 case EbvFace: return "Face";
417 case EbvFragCoord: return "FragCoord";
418 case EbvPointCoord: return "PointCoord";
419 case EbvFragColor: return "FragColor";
420 case EbvFragData: return "FragData";
421 case EbvFragDepth: return "FragDepth";
422 case EbvFragStencilRef: return "FragStencilRef";
423 case EbvSampleId: return "SampleId";
424 case EbvSamplePosition: return "SamplePosition";
425 case EbvSampleMask: return "SampleMaskIn";
426 case EbvHelperInvocation: return "HelperInvocation";
427
428 case EbvBaryCoordNoPersp: return "BaryCoordNoPersp";
429 case EbvBaryCoordNoPerspCentroid: return "BaryCoordNoPerspCentroid";
430 case EbvBaryCoordNoPerspSample: return "BaryCoordNoPerspSample";
431 case EbvBaryCoordSmooth: return "BaryCoordSmooth";
432 case EbvBaryCoordSmoothCentroid: return "BaryCoordSmoothCentroid";
433 case EbvBaryCoordSmoothSample: return "BaryCoordSmoothSample";
434 case EbvBaryCoordPullModel: return "BaryCoordPullModel";
435
436 case EbvViewIndex: return "ViewIndex";
437 case EbvDeviceIndex: return "DeviceIndex";
438
439 case EbvFragSizeEXT: return "FragSizeEXT";
440 case EbvFragInvocationCountEXT: return "FragInvocationCountEXT";
441
442 case EbvSecondaryFragDataEXT: return "SecondaryFragDataEXT";
443 case EbvSecondaryFragColorEXT: return "SecondaryFragColorEXT";
444
445 case EbvViewportMaskNV: return "ViewportMaskNV";
446 case EbvSecondaryPositionNV: return "SecondaryPositionNV";
447 case EbvSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
448 case EbvPositionPerViewNV: return "PositionPerViewNV";
449 case EbvViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
450 case EbvFragFullyCoveredNV: return "FragFullyCoveredNV";
451 case EbvFragmentSizeNV: return "FragmentSizeNV";
452 case EbvInvocationsPerPixelNV: return "InvocationsPerPixelNV";
453 case EbvLaunchId: return "LaunchIdNV";
454 case EbvLaunchSize: return "LaunchSizeNV";
455 case EbvInstanceCustomIndex: return "InstanceCustomIndexNV";
456 case EbvGeometryIndex: return "GeometryIndexEXT";
457 case EbvWorldRayOrigin: return "WorldRayOriginNV";
458 case EbvWorldRayDirection: return "WorldRayDirectionNV";
459 case EbvObjectRayOrigin: return "ObjectRayOriginNV";
460 case EbvObjectRayDirection: return "ObjectRayDirectionNV";
461 case EbvRayTmin: return "ObjectRayTminNV";
462 case EbvRayTmax: return "ObjectRayTmaxNV";
463 case EbvHitT: return "HitTNV";
464 case EbvHitKind: return "HitKindNV";
465 case EbvIncomingRayFlags: return "IncomingRayFlagsNV";
466 case EbvObjectToWorld: return "ObjectToWorldNV";
467 case EbvWorldToObject: return "WorldToObjectNV";
468
469 case EbvBaryCoordNV: return "BaryCoordNV";
470 case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
471
472 case EbvTaskCountNV: return "TaskCountNV";
473 case EbvPrimitiveCountNV: return "PrimitiveCountNV";
474 case EbvPrimitiveIndicesNV: return "PrimitiveIndicesNV";
475 case EbvClipDistancePerViewNV: return "ClipDistancePerViewNV";
476 case EbvCullDistancePerViewNV: return "CullDistancePerViewNV";
477 case EbvLayerPerViewNV: return "LayerPerViewNV";
478 case EbvMeshViewCountNV: return "MeshViewCountNV";
479 case EbvMeshViewIndicesNV: return "MeshViewIndicesNV";
480
481 case EbvWarpsPerSM: return "WarpsPerSMNV";
482 case EbvSMCount: return "SMCountNV";
483 case EbvWarpID: return "WarpIDNV";
484 case EbvSMID: return "SMIDNV";
485
486 case EbvShadingRateKHR: return "ShadingRateKHR";
487 case EbvPrimitiveShadingRateKHR: return "PrimitiveShadingRateKHR";
488
489 default: return "unknown built-in variable";
490 }
491 }
492
GetPrecisionQualifierString(TPrecisionQualifier p)493 __inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
494 {
495 switch (p) {
496 case EpqNone: return ""; break;
497 case EpqLow: return "lowp"; break;
498 case EpqMedium: return "mediump"; break;
499 case EpqHigh: return "highp"; break;
500 default: return "unknown precision qualifier";
501 }
502 }
503 #endif
504
isTypeSignedInt(TBasicType type)505 __inline bool isTypeSignedInt(TBasicType type)
506 {
507 switch (type) {
508 case EbtInt8:
509 case EbtInt16:
510 case EbtInt:
511 case EbtInt64:
512 return true;
513 default:
514 return false;
515 }
516 }
517
isTypeUnsignedInt(TBasicType type)518 __inline bool isTypeUnsignedInt(TBasicType type)
519 {
520 switch (type) {
521 case EbtUint8:
522 case EbtUint16:
523 case EbtUint:
524 case EbtUint64:
525 return true;
526 default:
527 return false;
528 }
529 }
530
isTypeInt(TBasicType type)531 __inline bool isTypeInt(TBasicType type)
532 {
533 return isTypeSignedInt(type) || isTypeUnsignedInt(type);
534 }
535
isTypeFloat(TBasicType type)536 __inline bool isTypeFloat(TBasicType type)
537 {
538 switch (type) {
539 case EbtFloat:
540 case EbtDouble:
541 case EbtFloat16:
542 return true;
543 default:
544 return false;
545 }
546 }
547
getTypeRank(TBasicType type)548 __inline int getTypeRank(TBasicType type)
549 {
550 int res = -1;
551 switch(type) {
552 case EbtInt8:
553 case EbtUint8:
554 res = 0;
555 break;
556 case EbtInt16:
557 case EbtUint16:
558 res = 1;
559 break;
560 case EbtInt:
561 case EbtUint:
562 res = 2;
563 break;
564 case EbtInt64:
565 case EbtUint64:
566 res = 3;
567 break;
568 default:
569 assert(false);
570 break;
571 }
572 return res;
573 }
574
575 } // end namespace glslang
576
577 #endif // _BASICTYPES_INCLUDED_
578