Skip to main content

wgsl_types/
idents.rs

1//! Static strings of all WGSL predeclared identifiers.
2
3/// Built-in types identifiers.
4/// Does not contain type-generators, see [`BUILTIN_TYPE_GENERATOR_NAMES`].
5///
6/// Reference: <https://www.w3.org/TR/WGSL/#predeclared-types>
7pub const BUILTIN_TYPE_NAMES: &[&str] = &[
8    // types that cannot be spelled in user code.
9    // they are prefixed with `__`, which is not a valid WGSL identifier prefix.
10    "__AbstractInt",
11    "__AbstractFloat",
12    "__ref",
13    "__unknown",
14    // plain types
15    "bool",
16    "f16",
17    "f32",
18    "i32",
19    "sampler",
20    "sampler_comparison",
21    "texture_depth_2d",
22    "texture_depth_2d_array",
23    "texture_depth_cube",
24    "texture_depth_cube_array",
25    "texture_depth_multisampled_2d",
26    "texture_external",
27    "u32",
28    // naga extensions
29    #[cfg(feature = "naga-ext")]
30    "i64",
31    #[cfg(feature = "naga-ext")]
32    "u64",
33    #[cfg(feature = "naga-ext")]
34    "f64",
35];
36
37/// Built-in type-generators identifiers.
38///
39/// Reference: <https://www.w3.org/TR/WGSL/#predeclared-types>
40pub const BUILTIN_TYPE_GENERATOR_NAMES: &[&str] = &[
41    "array",
42    "atomic",
43    "mat2x2",
44    "mat2x3",
45    "mat2x4",
46    "mat3x2",
47    "mat3x3",
48    "mat3x4",
49    "mat4x2",
50    "mat4x3",
51    "mat4x4",
52    "ptr",
53    "texture_1d",
54    "texture_2d",
55    "texture_2d_array",
56    "texture_3d",
57    "texture_cube",
58    "texture_cube_array",
59    "texture_multisampled_2d",
60    "texture_storage_1d",
61    "texture_storage_2d",
62    "texture_storage_2d_array",
63    "texture_storage_3d",
64    "vec2",
65    "vec3",
66    "vec4",
67    #[cfg(feature = "naga-ext")]
68    "binding_array",
69    #[cfg(feature = "naga-ext")]
70    "texture_1d_array",
71    #[cfg(feature = "naga-ext")]
72    "texture_storage_1d_array",
73    #[cfg(feature = "naga-ext")]
74    "texture_multisampled_2d_array",
75    #[cfg(feature = "naga-ext")]
76    "ray_query",
77    #[cfg(feature = "naga-ext")]
78    "acceleration_structure",
79];
80
81/// Built-in `struct` identifiers.
82pub const BUILTIN_STRUCT_NAMES: &[&str] = &[
83    // function return types cannot be spelled in user code.
84    // they are prefixed with `__`, which is not a valid WGSL identifier prefix.
85    "__frexp_result_f32",
86    "__frexp_result_f16",
87    "__frexp_result_abstract",
88    "__frexp_result_vec2_f32",
89    "__frexp_result_vec3_f32",
90    "__frexp_result_vec4_f32",
91    "__frexp_result_vec2_f16",
92    "__frexp_result_vec3_f16",
93    "__frexp_result_vec4_f16",
94    "__frexp_result_vec2_abstract",
95    "__frexp_result_vec3_abstract",
96    "__frexp_result_vec4_abstract",
97    "__modf_result_f32",
98    "__modf_result_f16",
99    "__modf_result_abstract",
100    "__modf_result_vec2_f32",
101    "__modf_result_vec3_f32",
102    "__modf_result_vec4_f32",
103    "__modf_result_vec2_f16",
104    "__modf_result_vec3_f16",
105    "__modf_result_vec4_f16",
106    "__modf_result_vec2_abstract",
107    "__modf_result_vec3_abstract",
108    "__modf_result_vec4_abstract",
109    "__atomic_compare_exchange_result",
110    #[cfg(feature = "naga-ext")]
111    "RayDesc",
112    #[cfg(feature = "naga-ext")]
113    "RayIntersection",
114];
115
116/// Built-in variable and value declarations identifiers.
117///
118/// There are none currently in WGSL.
119pub const BUILTIN_DECLARATION_NAMES: &[&str] = &[
120    // ray queries (naga extension). These are const declarations.
121    #[cfg(feature = "naga-ext")]
122    "RAY_FLAG_NONE", // value: 0x0
123    #[cfg(feature = "naga-ext")]
124    "RAY_FLAG_FORCE_OPAQUE", // value: 0x1
125    #[cfg(feature = "naga-ext")]
126    "RAY_FLAG_FORCE_NO_OPAQUE", // value: 0x2
127    #[cfg(feature = "naga-ext")]
128    "RAY_FLAG_TERMINATE_ON_FIRST_HIT", // value: 0x4
129    #[cfg(feature = "naga-ext")]
130    "RAY_FLAG_SKIP_CLOSEST_HIT_SHADER", // value: 0x8
131    #[cfg(feature = "naga-ext")]
132    "RAY_FLAG_CULL_BACK_FACING", // value: 0x10
133    #[cfg(feature = "naga-ext")]
134    "RAY_FLAG_CULL_FRONT_FACING", // value: 0x20
135    #[cfg(feature = "naga-ext")]
136    "RAY_FLAG_CULL_OPAQUE", // value: 0x40
137    #[cfg(feature = "naga-ext")]
138    "RAY_FLAG_CULL_NO_OPAQUE", // value: 0x80
139    #[cfg(feature = "naga-ext")]
140    "RAY_FLAG_SKIP_TRIANGLES", // value: 0x100
141    #[cfg(feature = "naga-ext")]
142    "RAY_FLAG_SKIP_AABBS", // value: 0x200
143    #[cfg(feature = "naga-ext")]
144    "RAY_QUERY_INTERSECTION_NONE", // value: 0
145    #[cfg(feature = "naga-ext")]
146    "RAY_QUERY_INTERSECTION_TRIANGLE", // value: 1
147    #[cfg(feature = "naga-ext")]
148    "RAY_QUERY_INTERSECTION_GENERATED", // value: 2
149    #[cfg(feature = "naga-ext")]
150    "RAY_QUERY_INTERSECTION_AABB", // value: 3
151];
152
153/// Predeclared type aliases names.
154pub const BUILTIN_ALIAS_NAMES: &[&str] = &[
155    "vec2i", "vec3i", "vec4i", "vec2u", "vec3u", "vec4u", "vec2f", "vec3f", "vec4f", "vec2h",
156    "vec3h", "vec4h", "mat2x2f", "mat2x3f", "mat2x4f", "mat3x2f", "mat3x3f", "mat3x4f", "mat4x2f",
157    "mat4x3f", "mat4x4f", "mat2x2h", "mat2x3h", "mat2x4h", "mat3x2h", "mat3x3h", "mat3x4h",
158    "mat4x2h", "mat4x3h", "mat4x4h",
159];
160
161/// Built-in enumerants identifiers.
162///
163/// These enumerants are not context-dependent names, and can therefore be shadowed.
164///
165/// Reference: <https://www.w3.org/TR/WGSL/#predeclared-enumerants>
166pub const BUILTIN_ENUMERANT_NAMES: &[&str] = &[
167    // : access mode
168    "read",
169    "write",
170    "read_write",
171    // : address space (enumerant)
172    "function",
173    "private",
174    "workgroup",
175    "uniform",
176    "storage",
177    "immediate",
178    #[cfg(feature = "naga-ext")]
179    "task_payload",
180    #[cfg(feature = "naga-ext")]
181    "ray_payload",
182    #[cfg(feature = "naga-ext")]
183    "incoming_ray_payload",
184    // : texel format
185    "rgba8unorm",
186    "rgba8snorm",
187    "rgba8uint",
188    "rgba8sint",
189    "rgba16uint",
190    "rgba16sint",
191    "rgba16float",
192    "r32uint",
193    "r32sint",
194    "r32float",
195    "rg32uint",
196    "rg32sint",
197    "rg32float",
198    "rgba32uint",
199    "rgba32sint",
200    "rgba32float",
201    "bgra8unorm",
202    #[cfg(feature = "naga-ext")]
203    "r8unorm",
204    #[cfg(feature = "naga-ext")]
205    "r8snorm",
206    #[cfg(feature = "naga-ext")]
207    "r8uint",
208    #[cfg(feature = "naga-ext")]
209    "r8sint",
210    #[cfg(feature = "naga-ext")]
211    "r16unorm",
212    #[cfg(feature = "naga-ext")]
213    "r16snorm",
214    #[cfg(feature = "naga-ext")]
215    "r16uint",
216    #[cfg(feature = "naga-ext")]
217    "r16sint",
218    #[cfg(feature = "naga-ext")]
219    "r16float",
220    #[cfg(feature = "naga-ext")]
221    "rg8unorm",
222    #[cfg(feature = "naga-ext")]
223    "rg8snorm",
224    #[cfg(feature = "naga-ext")]
225    "rg8uint",
226    #[cfg(feature = "naga-ext")]
227    "rg8sint",
228    #[cfg(feature = "naga-ext")]
229    "rg16unorm",
230    #[cfg(feature = "naga-ext")]
231    "rg16snorm",
232    #[cfg(feature = "naga-ext")]
233    "rg16uint",
234    #[cfg(feature = "naga-ext")]
235    "rg16sint",
236    #[cfg(feature = "naga-ext")]
237    "rg16float",
238    #[cfg(feature = "naga-ext")]
239    "rgb10a2uint",
240    #[cfg(feature = "naga-ext")]
241    "rgb10a2unorm",
242    #[cfg(feature = "naga-ext")]
243    "rg11b10ufloat",
244    #[cfg(feature = "naga-ext")]
245    "r64uint",
246    #[cfg(feature = "naga-ext")]
247    "rgba16unorm",
248    #[cfg(feature = "naga-ext")]
249    "rgba16snorm",
250    #[cfg(feature = "naga-ext")]
251    "vertex_return", // for ray_query and acceleration_structure
252];
253
254/// Built-in functions identifiers, excluding built-in constructors.
255///
256/// Reference: <https://www.w3.org/TR/WGSL/#builtin-functions>
257pub const BUILTIN_FUNCTION_NAMES: &[&str] = &[
258    // : bitcast
259    "bitcast",
260    // : logical
261    "all",
262    "any",
263    "select",
264    "arrayLength",
265    "abs",
266    "acos",
267    "acosh",
268    "asin",
269    "asinh",
270    "atan",
271    "atanh",
272    "atan2",
273    "ceil",
274    "clamp",
275    "cos",
276    "cosh",
277    "countLeadingZeros",
278    "countOneBits",
279    "countTrailingZeros",
280    "cross",
281    "degrees",
282    "determinant",
283    "distance",
284    "dot",
285    "dot4I8Packed",
286    "dot4U8Packed",
287    "exp",
288    "exp2",
289    "extractBits",
290    "faceForward",
291    "firstLeadingBit",
292    "firstTrailingBit",
293    "floor",
294    "fma",
295    "fract",
296    "frexp",
297    "insertBits",
298    "inverseSqrt",
299    "ldexp",
300    "length",
301    "log",
302    "log2",
303    "max",
304    "min",
305    "mix",
306    "modf",
307    "normalize",
308    "pow",
309    "quantizeToF16",
310    "radians",
311    "reflect",
312    "refract",
313    "reverseBits",
314    "round",
315    "saturate",
316    "sign",
317    "sin",
318    "sinh",
319    "smoothstep",
320    "sqrt",
321    "step",
322    "tan",
323    "tanh",
324    "transpose",
325    "trunc",
326    // : derivative
327    "dpdx",
328    "dpdxCoarse",
329    "dpdxFine",
330    "dpdy",
331    "dpdyCoarse",
332    "dpdyFine",
333    "fwidth",
334    "fwidthCoarse",
335    "fwidthFine",
336    // : texture
337    "textureDimensions",
338    "textureGather",
339    "textureGatherCompare",
340    "textureLoad",
341    "textureNumLayers",
342    "textureNumLevels",
343    "textureNumSamples",
344    "textureSample",
345    "textureSampleBias",
346    "textureSampleCompare",
347    "textureSampleCompareLevel",
348    "textureSampleGrad",
349    "textureSampleLevel",
350    "textureSampleBaseClampToEdge",
351    "textureStore",
352    // : atomic
353    "atomicLoad",
354    "atomicStore",
355    "atomicAdd",
356    "atomicSub",
357    "atomicMax",
358    "atomicMin",
359    "atomicAnd",
360    "atomicOr",
361    "atomicXor",
362    "atomicExchange",
363    "atomicCompareExchangeWeak",
364    // : packing
365    "pack4x8snorm",
366    "pack4x8unorm",
367    "pack4xI8",
368    "pack4xU8",
369    "pack4xI8Clamp",
370    "pack4xU8Clamp",
371    "pack2x16snorm",
372    "pack2x16unorm",
373    "pack2x16float",
374    "unpack4x8snorm",
375    "unpack4x8unorm",
376    "unpack4xI8",
377    "unpack4xU8",
378    "unpack2x16snorm",
379    "unpack2x16unorm",
380    "unpack2x16float",
381    // : synchronization
382    "storageBarrier",
383    "textureBarrier",
384    "workgroupBarrier",
385    "workgroupUniformLoad",
386    // : subgroup
387    "subgroupAdd",
388    "subgroupExclusiveAdd",
389    "subgroupInclusiveAdd",
390    "subgroupAll",
391    "subgroupAnd",
392    "subgroupAny",
393    "subgroupBallot",
394    "subgroupBroadcast",
395    "subgroupBroadcastFirst",
396    "subgroupElect",
397    "subgroupMax",
398    "subgroupMin",
399    "subgroupMul",
400    "subgroupExclusiveMul",
401    "subgroupInclusiveMul",
402    "subgroupOr",
403    "subgroupShuffle",
404    "subgroupShuffleDown",
405    "subgroupShuffleUp",
406    "subgroupShuffleXor",
407    "subgroupXor",
408    // : quad
409    "quadBroadcast",
410    "quadSwapDiagonal",
411    "quadSwapX",
412    "quadSwapY",
413    // : ray queries (naga extension)
414    #[cfg(feature = "naga-ext")]
415    "rayQueryInitialize",
416    #[cfg(feature = "naga-ext")]
417    "rayQueryProceed",
418    #[cfg(feature = "naga-ext")]
419    "rayQueryGenerateIntersection",
420    #[cfg(feature = "naga-ext")]
421    "rayQueryConfirmIntersection",
422    #[cfg(feature = "naga-ext")]
423    "rayQueryTerminate",
424    #[cfg(feature = "naga-ext")]
425    "rayQueryGetCommittedIntersection",
426    #[cfg(feature = "naga-ext")]
427    "rayQueryGetCandidateIntersection",
428    #[cfg(feature = "naga-ext")]
429    "getCommittedHitVertexPositions",
430    #[cfg(feature = "naga-ext")]
431    "getCandidateHitVertexPositions",
432    // : ray tracing pipelines (naga extension)
433    #[cfg(feature = "naga-ext")]
434    "traceRay",
435];
436
437/// Built-in constructor identifiers (zero-value and value-constructors).
438///
439/// Reference: <https://www.w3.org/TR/WGSL/#constructor-builtin-function>
440pub const BUILTIN_CONSTRUCTOR_NAMES: &[&str] = &[
441    // constructor built-in functions
442    "bool",
443    "f16",
444    "f32",
445    "i32",
446    "u32",
447    #[cfg(feature = "naga-ext")]
448    "i64",
449    #[cfg(feature = "naga-ext")]
450    "u64",
451    #[cfg(feature = "naga-ext")]
452    "f64",
453    // type-generators
454    "array",
455    "mat2x2",
456    "mat2x3",
457    "mat2x4",
458    "mat3x2",
459    "mat3x3",
460    "mat3x4",
461    "mat4x2",
462    "mat4x3",
463    "mat4x4",
464    "vec2",
465    "vec3",
466    "vec4",
467    // predeclared aliases
468    "vec2i",
469    "vec3i",
470    "vec4i",
471    "vec2u",
472    "vec3u",
473    "vec4u",
474    "vec2f",
475    "vec3f",
476    "vec4f",
477    "vec2h",
478    "vec3h",
479    "vec4h",
480    "mat2x2f",
481    "mat2x3f",
482    "mat2x4f",
483    "mat3x2f",
484    "mat3x3f",
485    "mat3x4f",
486    "mat4x2f",
487    "mat4x3f",
488    "mat4x4f",
489    "mat2x2h",
490    "mat2x3h",
491    "mat2x4h",
492    "mat3x2h",
493    "mat3x3h",
494    "mat3x4h",
495    "mat4x2h",
496    "mat4x3h",
497    "mat4x4h",
498    // ray queries (naga extension)
499    #[cfg(feature = "naga-ext")]
500    "RayDesc",
501    #[cfg(feature = "naga-ext")]
502    "RayIntersection",
503];
504
505/// All built-in identifiers.
506pub fn iter_builtin_idents() -> impl Iterator<Item = &'static str> {
507    itertools::chain!(
508        BUILTIN_TYPE_NAMES.iter(),
509        BUILTIN_TYPE_GENERATOR_NAMES.iter(),
510        BUILTIN_STRUCT_NAMES.iter(),
511        BUILTIN_DECLARATION_NAMES.iter(),
512        BUILTIN_ALIAS_NAMES.iter(),
513        BUILTIN_ENUMERANT_NAMES.iter(),
514        BUILTIN_FUNCTION_NAMES.iter(),
515        BUILTIN_CONSTRUCTOR_NAMES.iter(),
516    )
517    .map(|s| *s)
518}
519
520/// Reserved WGSL identifiers.
521///
522/// * WESL keywords (`as`, `import`, `super`, `self`) are included.
523/// * `binding_array` is not included if feature `naga-ext` is set.
524///
525/// Reference: <https://www.w3.org/TR/WGSL/#reserved-words>
526pub const RESERVED_WORDS: &[&str] = &[
527    "NULL",
528    "Self",
529    "abstract",
530    "active",
531    "alignas",
532    "alignof",
533    "as",
534    "asm",
535    "asm_fragment",
536    "async",
537    "attribute",
538    "auto",
539    "await",
540    "become",
541    #[cfg(not(feature = "naga-ext"))]
542    "binding_array",
543    "cast",
544    "catch",
545    "class",
546    "co_await",
547    "co_return",
548    "co_yield",
549    "coherent",
550    "column_major",
551    "common",
552    "compile",
553    "compile_fragment",
554    "concept",
555    "const_cast",
556    "consteval",
557    "constexpr",
558    "constinit",
559    "crate",
560    "debugger",
561    "decltype",
562    "delete",
563    "demote",
564    "demote_to_helper",
565    "do",
566    "dynamic_cast",
567    "enum",
568    "explicit",
569    "export",
570    "extends",
571    "extern",
572    "external",
573    "fallthrough",
574    "filter",
575    "final",
576    "finally",
577    "friend",
578    "from",
579    "fxgroup",
580    "get",
581    "goto",
582    "groupshared",
583    "highp",
584    "impl",
585    "implements",
586    "import",
587    "inline",
588    "instanceof",
589    "interface",
590    "layout",
591    "lowp",
592    "macro",
593    "macro_rules",
594    "match",
595    "mediump",
596    "meta",
597    "mod",
598    "module",
599    "move",
600    "mut",
601    "mutable",
602    "namespace",
603    "new",
604    "nil",
605    "noexcept",
606    "noinline",
607    "nointerpolation",
608    "non_coherent",
609    "noncoherent",
610    "noperspective",
611    "null",
612    "nullptr",
613    "of",
614    "operator",
615    "package",
616    "packoffset",
617    "partition",
618    "pass",
619    "patch",
620    "pixelfragment",
621    "precise",
622    "precision",
623    "premerge",
624    "priv",
625    "protected",
626    "pub",
627    "public",
628    "readonly",
629    "ref",
630    "regardless",
631    "register",
632    "reinterpret_cast",
633    "require",
634    "resource",
635    "restrict",
636    "self",
637    "set",
638    "shared",
639    "sizeof",
640    "smooth",
641    "snorm",
642    "static",
643    "static_assert",
644    "static_cast",
645    "std",
646    "subroutine",
647    "super",
648    "target",
649    "template",
650    "this",
651    "thread_local",
652    "throw",
653    "trait",
654    "try",
655    "type",
656    "typedef",
657    "typeid",
658    "typename",
659    "typeof",
660    "union",
661    "unless",
662    "unorm",
663    "unsafe",
664    "unsized",
665    "use",
666    "using",
667    "varying",
668    "virtual",
669    "volatile",
670    "wgsl",
671    "where",
672    "with",
673    "writeonly",
674    "yield",
675];