naga/back/glsl/
keywords.rs

1use crate::racy_lock::RacyLock;
2
3use hashbrown::HashSet;
4
5pub const RESERVED_KEYWORDS: &[&str] = &[
6    //
7    // GLSL 4.6 keywords, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L2004-L2322
8    // GLSL ES 3.2 keywords, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/es/3.2/GLSL_ES_Specification_3.20.html#L2166-L2478
9    //
10    // Note: The GLSL ES 3.2 keywords are the same as GLSL 4.6 keywords with some residing in the reserved section.
11    // The only exception are the missing Vulkan keywords which I think is an oversight (see https://github.com/KhronosGroup/OpenGL-Registry/issues/585).
12    //
13    "const",
14    "uniform",
15    "buffer",
16    "shared",
17    "attribute",
18    "varying",
19    "coherent",
20    "volatile",
21    "restrict",
22    "readonly",
23    "writeonly",
24    "atomic_uint",
25    "layout",
26    "centroid",
27    "flat",
28    "smooth",
29    "noperspective",
30    "patch",
31    "sample",
32    "invariant",
33    "precise",
34    "break",
35    "continue",
36    "do",
37    "for",
38    "while",
39    "switch",
40    "case",
41    "default",
42    "if",
43    "else",
44    "subroutine",
45    "in",
46    "out",
47    "inout",
48    "int",
49    "void",
50    "bool",
51    "true",
52    "false",
53    "float",
54    "double",
55    "discard",
56    "return",
57    "vec2",
58    "vec3",
59    "vec4",
60    "ivec2",
61    "ivec3",
62    "ivec4",
63    "bvec2",
64    "bvec3",
65    "bvec4",
66    "uint",
67    "uvec2",
68    "uvec3",
69    "uvec4",
70    "dvec2",
71    "dvec3",
72    "dvec4",
73    "mat2",
74    "mat3",
75    "mat4",
76    "mat2x2",
77    "mat2x3",
78    "mat2x4",
79    "mat3x2",
80    "mat3x3",
81    "mat3x4",
82    "mat4x2",
83    "mat4x3",
84    "mat4x4",
85    "dmat2",
86    "dmat3",
87    "dmat4",
88    "dmat2x2",
89    "dmat2x3",
90    "dmat2x4",
91    "dmat3x2",
92    "dmat3x3",
93    "dmat3x4",
94    "dmat4x2",
95    "dmat4x3",
96    "dmat4x4",
97    "lowp",
98    "mediump",
99    "highp",
100    "precision",
101    "sampler1D",
102    "sampler1DShadow",
103    "sampler1DArray",
104    "sampler1DArrayShadow",
105    "isampler1D",
106    "isampler1DArray",
107    "usampler1D",
108    "usampler1DArray",
109    "sampler2D",
110    "sampler2DShadow",
111    "sampler2DArray",
112    "sampler2DArrayShadow",
113    "isampler2D",
114    "isampler2DArray",
115    "usampler2D",
116    "usampler2DArray",
117    "sampler2DRect",
118    "sampler2DRectShadow",
119    "isampler2DRect",
120    "usampler2DRect",
121    "sampler2DMS",
122    "isampler2DMS",
123    "usampler2DMS",
124    "sampler2DMSArray",
125    "isampler2DMSArray",
126    "usampler2DMSArray",
127    "sampler3D",
128    "isampler3D",
129    "usampler3D",
130    "samplerCube",
131    "samplerCubeShadow",
132    "isamplerCube",
133    "usamplerCube",
134    "samplerCubeArray",
135    "samplerCubeArrayShadow",
136    "isamplerCubeArray",
137    "usamplerCubeArray",
138    "samplerBuffer",
139    "isamplerBuffer",
140    "usamplerBuffer",
141    "image1D",
142    "iimage1D",
143    "uimage1D",
144    "image1DArray",
145    "iimage1DArray",
146    "uimage1DArray",
147    "image2D",
148    "iimage2D",
149    "uimage2D",
150    "image2DArray",
151    "iimage2DArray",
152    "uimage2DArray",
153    "image2DRect",
154    "iimage2DRect",
155    "uimage2DRect",
156    "image2DMS",
157    "iimage2DMS",
158    "uimage2DMS",
159    "image2DMSArray",
160    "iimage2DMSArray",
161    "uimage2DMSArray",
162    "image3D",
163    "iimage3D",
164    "uimage3D",
165    "imageCube",
166    "iimageCube",
167    "uimageCube",
168    "imageCubeArray",
169    "iimageCubeArray",
170    "uimageCubeArray",
171    "imageBuffer",
172    "iimageBuffer",
173    "uimageBuffer",
174    "struct",
175    // Vulkan keywords
176    "texture1D",
177    "texture1DArray",
178    "itexture1D",
179    "itexture1DArray",
180    "utexture1D",
181    "utexture1DArray",
182    "texture2D",
183    "texture2DArray",
184    "itexture2D",
185    "itexture2DArray",
186    "utexture2D",
187    "utexture2DArray",
188    "texture2DRect",
189    "itexture2DRect",
190    "utexture2DRect",
191    "texture2DMS",
192    "itexture2DMS",
193    "utexture2DMS",
194    "texture2DMSArray",
195    "itexture2DMSArray",
196    "utexture2DMSArray",
197    "texture3D",
198    "itexture3D",
199    "utexture3D",
200    "textureCube",
201    "itextureCube",
202    "utextureCube",
203    "textureCubeArray",
204    "itextureCubeArray",
205    "utextureCubeArray",
206    "textureBuffer",
207    "itextureBuffer",
208    "utextureBuffer",
209    "sampler",
210    "samplerShadow",
211    "subpassInput",
212    "isubpassInput",
213    "usubpassInput",
214    "subpassInputMS",
215    "isubpassInputMS",
216    "usubpassInputMS",
217    // Reserved keywords
218    "common",
219    "partition",
220    "active",
221    "asm",
222    "class",
223    "union",
224    "enum",
225    "typedef",
226    "template",
227    "this",
228    "resource",
229    "goto",
230    "inline",
231    "noinline",
232    "public",
233    "static",
234    "extern",
235    "external",
236    "interface",
237    "long",
238    "short",
239    "half",
240    "fixed",
241    "unsigned",
242    "superp",
243    "input",
244    "output",
245    "hvec2",
246    "hvec3",
247    "hvec4",
248    "fvec2",
249    "fvec3",
250    "fvec4",
251    "filter",
252    "sizeof",
253    "cast",
254    "namespace",
255    "using",
256    "sampler3DRect",
257    // Reserved keywords that were unreserved in GLSL 4.2
258    "image1DArrayShadow",
259    "image1DShadow",
260    "image2DArrayShadow",
261    "image2DShadow",
262    // Reserved keywords that were unreserved in GLSL 4.4
263    "packed",
264    "row_major",
265    //
266    // GLSL 4.6 Built-In Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L13314
267    //
268    // Angle and Trigonometry Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L13469-L13561C5
269    "radians",
270    "degrees",
271    "sin",
272    "cos",
273    "tan",
274    "asin",
275    "acos",
276    "atan",
277    "sinh",
278    "cosh",
279    "tanh",
280    "asinh",
281    "acosh",
282    "atanh",
283    // Exponential Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L13569-L13620
284    "pow",
285    "exp",
286    "log",
287    "exp2",
288    "log2",
289    "sqrt",
290    "inversesqrt",
291    // Common Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L13628-L13908
292    "abs",
293    "sign",
294    "floor",
295    "trunc",
296    "round",
297    "roundEven",
298    "ceil",
299    "fract",
300    "mod",
301    "modf",
302    "min",
303    "max",
304    "clamp",
305    "mix",
306    "step",
307    "smoothstep",
308    "isnan",
309    "isinf",
310    "floatBitsToInt",
311    "floatBitsToUint",
312    "intBitsToFloat",
313    "uintBitsToFloat",
314    "fma",
315    "frexp",
316    "ldexp",
317    // Floating-Point Pack and Unpack Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L13916-L14007
318    "packUnorm2x16",
319    "packSnorm2x16",
320    "packUnorm4x8",
321    "packSnorm4x8",
322    "unpackUnorm2x16",
323    "unpackSnorm2x16",
324    "unpackUnorm4x8",
325    "unpackSnorm4x8",
326    "packHalf2x16",
327    "unpackHalf2x16",
328    "packDouble2x32",
329    "unpackDouble2x32",
330    // Geometric Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14014-L14121
331    "length",
332    "distance",
333    "dot",
334    "cross",
335    "normalize",
336    "ftransform",
337    "faceforward",
338    "reflect",
339    "refract",
340    // Matrix Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14151-L14215
341    "matrixCompMult",
342    "outerProduct",
343    "transpose",
344    "determinant",
345    "inverse",
346    // Vector Relational Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14259-L14322
347    "lessThan",
348    "lessThanEqual",
349    "greaterThan",
350    "greaterThanEqual",
351    "equal",
352    "notEqual",
353    "any",
354    "all",
355    "not",
356    // Integer Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14335-L14432
357    "uaddCarry",
358    "usubBorrow",
359    "umulExtended",
360    "imulExtended",
361    "bitfieldExtract",
362    "bitfieldInsert",
363    "bitfieldReverse",
364    "bitCount",
365    "findLSB",
366    "findMSB",
367    // Texture Query Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14645-L14732
368    "textureSize",
369    "textureQueryLod",
370    "textureQueryLevels",
371    "textureSamples",
372    // Texel Lookup Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L14736-L14997
373    "texture",
374    "textureProj",
375    "textureLod",
376    "textureOffset",
377    "texelFetch",
378    "texelFetchOffset",
379    "textureProjOffset",
380    "textureLodOffset",
381    "textureProjLod",
382    "textureProjLodOffset",
383    "textureGrad",
384    "textureGradOffset",
385    "textureProjGrad",
386    "textureProjGradOffset",
387    // Texture Gather Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15077-L15154
388    "textureGather",
389    "textureGatherOffset",
390    "textureGatherOffsets",
391    // Compatibility Profile Texture Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15161-L15220
392    "texture1D",
393    "texture1DProj",
394    "texture1DLod",
395    "texture1DProjLod",
396    "texture2D",
397    "texture2DProj",
398    "texture2DLod",
399    "texture2DProjLod",
400    "texture3D",
401    "texture3DProj",
402    "texture3DLod",
403    "texture3DProjLod",
404    "textureCube",
405    "textureCubeLod",
406    "shadow1D",
407    "shadow2D",
408    "shadow1DProj",
409    "shadow2DProj",
410    "shadow1DLod",
411    "shadow2DLod",
412    "shadow1DProjLod",
413    "shadow2DProjLod",
414    // Atomic Counter Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15241-L15531
415    "atomicCounterIncrement",
416    "atomicCounterDecrement",
417    "atomicCounter",
418    "atomicCounterAdd",
419    "atomicCounterSubtract",
420    "atomicCounterMin",
421    "atomicCounterMax",
422    "atomicCounterAnd",
423    "atomicCounterOr",
424    "atomicCounterXor",
425    "atomicCounterExchange",
426    "atomicCounterCompSwap",
427    // Atomic Memory Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15563-L15624
428    "atomicAdd",
429    "atomicMin",
430    "atomicMax",
431    "atomicAnd",
432    "atomicOr",
433    "atomicXor",
434    "atomicExchange",
435    "atomicCompSwap",
436    // Image Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15763-L15878
437    "imageSize",
438    "imageSamples",
439    "imageLoad",
440    "imageStore",
441    "imageAtomicAdd",
442    "imageAtomicMin",
443    "imageAtomicMax",
444    "imageAtomicAnd",
445    "imageAtomicOr",
446    "imageAtomicXor",
447    "imageAtomicExchange",
448    "imageAtomicCompSwap",
449    // Geometry Shader Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L15886-L15932
450    "EmitStreamVertex",
451    "EndStreamPrimitive",
452    "EmitVertex",
453    "EndPrimitive",
454    // Fragment Processing Functions, Derivative Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16041-L16114
455    "dFdx",
456    "dFdy",
457    "dFdxFine",
458    "dFdyFine",
459    "dFdxCoarse",
460    "dFdyCoarse",
461    "fwidth",
462    "fwidthFine",
463    "fwidthCoarse",
464    // Fragment Processing Functions, Interpolation Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16150-L16198
465    "interpolateAtCentroid",
466    "interpolateAtSample",
467    "interpolateAtOffset",
468    // Noise Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16214-L16243
469    "noise1",
470    "noise2",
471    "noise3",
472    "noise4",
473    // Shader Invocation Control Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16255-L16276
474    "barrier",
475    // Shader Memory Control Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16336-L16382
476    "memoryBarrier",
477    "memoryBarrierAtomicCounter",
478    "memoryBarrierBuffer",
479    "memoryBarrierShared",
480    "memoryBarrierImage",
481    "groupMemoryBarrier",
482    // Subpass-Input Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16451-L16470
483    "subpassLoad",
484    // Shader Invocation Group Functions, from https://github.com/KhronosGroup/OpenGL-Registry/blob/d00e11dc1a1ffba581d633f21f70202051248d5c/specs/gl/GLSLangSpec.4.60.html#L16483-L16511
485    "anyInvocation",
486    "allInvocations",
487    "allInvocationsEqual",
488    //
489    // entry point name (should not be shadowed)
490    //
491    "main",
492    // Naga utilities:
493    super::MODF_FUNCTION,
494    super::FREXP_FUNCTION,
495    super::FIRST_INSTANCE_BINDING,
496];
497
498/// The above set of reserved keywords, turned into a cached HashSet. This saves
499/// significant time during [`Namer::reset`](crate::proc::Namer::reset).
500///
501/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks.
502pub static RESERVED_KEYWORD_SET: RacyLock<HashSet<&'static str>> = RacyLock::new(|| {
503    let mut set = HashSet::default();
504    set.reserve(RESERVED_KEYWORDS.len());
505    for &word in RESERVED_KEYWORDS {
506        set.insert(word);
507    }
508    set
509});