Source code
Revision control
Copy as Markdown
Other Tools
/*!
Keywords for [WGSL][wgsl] (WebGPU Shading Language).
*/
use crate::proc::KeywordSet;
use crate::racy_lock::RacyLock;
pub const RESERVED: &[&str] = &[
// Keywords
"alias",
"break",
"case",
"const",
"const_assert",
"continue",
"continuing",
"default",
"diagnostic",
"discard",
"else",
"enable",
"false",
"fn",
"for",
"if",
"let",
"loop",
"override",
"requires",
"return",
"struct",
"switch",
"true",
"var",
"while",
// Reserved
"NULL",
"Self",
"abstract",
"active",
"alignas",
"alignof",
"as",
"asm",
"asm_fragment",
"async",
"attribute",
"auto",
"await",
"become",
"cast",
"catch",
"class",
"co_await",
"co_return",
"co_yield",
"coherent",
"column_major",
"common",
"compile",
"compile_fragment",
"concept",
"const_cast",
"consteval",
"constexpr",
"constinit",
"crate",
"debugger",
"decltype",
"delete",
"demote",
"demote_to_helper",
"do",
"dynamic_cast",
"enum",
"explicit",
"export",
"extends",
"extern",
"external",
"fallthrough",
"filter",
"final",
"finally",
"friend",
"from",
"fxgroup",
"get",
"goto",
"groupshared",
"highp",
"impl",
"implements",
"import",
"inline",
"instanceof",
"interface",
"layout",
"lowp",
"macro",
"macro_rules",
"match",
"mediump",
"meta",
"mod",
"module",
"move",
"mut",
"mutable",
"namespace",
"new",
"nil",
"noexcept",
"noinline",
"nointerpolation",
"non_coherent",
"noncoherent",
"noperspective",
"null",
"nullptr",
"of",
"operator",
"package",
"packoffset",
"partition",
"pass",
"patch",
"pixelfragment",
"precise",
"precision",
"premerge",
"priv",
"protected",
"pub",
"public",
"readonly",
"ref",
"regardless",
"register",
"reinterpret_cast",
"require",
"resource",
"restrict",
"self",
"set",
"shared",
"sizeof",
"smooth",
"snorm",
"static",
"static_assert",
"static_cast",
"std",
"subroutine",
"super",
"target",
"template",
"this",
"thread_local",
"throw",
"trait",
"try",
"type",
"typedef",
"typeid",
"typename",
"typeof",
"union",
"unless",
"unorm",
"unsafe",
"unsized",
"use",
"using",
"varying",
"virtual",
"volatile",
"wgsl",
"where",
"with",
"writeonly",
"yield",
];
/// The above set of reserved keywords, turned into a cached HashSet. This saves
/// significant time during [`Namer::reset`](crate::proc::Namer::reset).
///
/// See <https://github.com/gfx-rs/wgpu/pull/7338> for benchmarks.
pub static RESERVED_SET: RacyLock<KeywordSet> = RacyLock::new(|| KeywordSet::from_iter(RESERVED));
/// Shadowable words that the WGSL backend should avoid using for declarations.
///
/// Includes:
/// - [6.9. Predeclared Types and Type-Generators]
/// - [6.3.1. Predeclared enumerants]
/// - [17. Built-in Functions]
///
/// This set must be separate from the [`RESERVED`] set above since the
/// [`Namer`](crate::proc::Namer) must ignore these identifiers if they appear
/// as struct member names. This is because this set contains `fract` and `exp`
/// which are also names used by return types of the `frexp` and `modf` built-in functions.
///
/// [6.9. Predeclared Types and Type-Generators]: https://www.w3.org/TR/WGSL/#predeclared-types
/// [6.3.1. Predeclared enumerants]: https://www.w3.org/TR/WGSL/#predeclared-enumerants
/// [17. Built-in Functions]: https://www.w3.org/TR/WGSL/#builtin-functions
pub const BUILTIN_IDENTIFIERS: &[&str] = &[
// types
"bool",
"i32",
"u32",
"f32",
"f16",
"array",
"atomic",
"vec2",
"vec3",
"vec4",
"mat2x2",
"mat2x3",
"mat2x4",
"mat3x2",
"mat3x3",
"mat3x4",
"mat4x2",
"mat4x3",
"mat4x4",
"ptr",
"sampler",
"sampler_comparison",
"texture_1d",
"texture_2d",
"texture_2d_array",
"texture_3d",
"texture_cube",
"texture_cube_array",
"texture_multisampled_2d",
"texture_depth_multisampled_2d",
"texture_external",
"texture_storage_1d",
"texture_storage_2d",
"texture_storage_2d_array",
"texture_storage_3d",
"texture_depth_2d",
"texture_depth_2d_array",
"texture_depth_cube",
"texture_depth_cube_array",
// enumerants
"read",
"write",
"read_write",
"function",
"private",
"workgroup",
"uniform",
"storage",
"rgba8unorm",
"rgba8snorm",
"rgba8uint",
"rgba8sint",
"rgba16unorm",
"rgba16snorm",
"rgba16uint",
"rgba16sint",
"rgba16float",
"rg8unorm",
"rg8snorm",
"rg8uint",
"rg8sint",
"rg16unorm",
"rg16snorm",
"rg16uint",
"rg16sint",
"rg16float",
"r32uint",
"r32sint",
"r32float",
"rg32uint",
"rg32sint",
"rg32float",
"rgba32uint",
"rgba32sint",
"rgba32float",
"bgra8unorm",
"r8unorm",
"r8snorm",
"r8uint",
"r8sint",
"r16unorm",
"r16snorm",
"r16uint",
"r16sint",
"r16float",
"rgb10a2unorm",
"rgb10a2uint",
"rg11b10ufloat",
// functions
"bitcast",
"all",
"any",
"select",
"arrayLength",
"abs",
"acos",
"acosh",
"asin",
"asinh",
"atan",
"atanh",
"atan2",
"ceil",
"clamp",
"cos",
"cosh",
"countLeadingZeros",
"countOneBits",
"countTrailingZeros",
"cross",
"degrees",
"determinant",
"distance",
"dot",
"dot4U8Packed",
"dot4I8Packed",
"exp",
"exp2",
"extractBits",
"faceForward",
"firstLeadingBit",
"firstTrailingBit",
"floor",
"fma",
"fract",
"frexp",
"insertBits",
"inverseSqrt",
"ldexp",
"length",
"log",
"log2",
"max",
"min",
"mix",
"modf",
"normalize",
"pow",
"quantizeToF16",
"radians",
"reflect",
"refract",
"reverseBits",
"round",
"saturate",
"sign",
"sin",
"sinh",
"smoothstep",
"sqrt",
"step",
"tan",
"tanh",
"transpose",
"trunc",
"dpdx",
"dpdxCoarse",
"dpdxFine",
"dpdy",
"dpdyCoarse",
"dpdyFine",
"fwidth",
"fwidthCoarse",
"fwidthFine",
"textureDimensions",
"textureGather",
"textureGatherCompare",
"textureLoad",
"textureNumLayers",
"textureNumLevels",
"textureNumSamples",
"textureSample",
"textureSampleBias",
"textureSampleCompare",
"textureSampleCompareLevel",
"textureSampleGrad",
"textureSampleLevel",
"textureSampleBaseClampToEdge",
"textureStore",
"atomicLoad",
"atomicStore",
"atomicAdd",
"atomicSub",
"atomicMax",
"atomicMin",
"atomicAnd",
"atomicOr",
"atomicXor",
"atomicExchange",
"atomicCompareExchangeWeak",
"pack4x8snorm",
"pack4x8unorm",
"pack4xI8",
"pack4xU8",
"pack4xI8Clamp",
"pack4xU8Clamp",
"pack2x16snorm",
"pack2x16unorm",
"pack2x16float",
"unpack4x8snorm",
"unpack4x8unorm",
"unpack4xI8",
"unpack4xU8",
"unpack2x16snorm",
"unpack2x16unorm",
"unpack2x16float",
"storageBarrier",
"textureBarrier",
"workgroupBarrier",
"workgroupUniformLoad",
"subgroupAdd",
"subgroupExclusiveAdd",
"subgroupInclusiveAdd",
"subgroupAll",
"subgroupAnd",
"subgroupAny",
"subgroupBallot",
"subgroupBroadcast",
"subgroupBroadcastFirst",
"subgroupElect",
"subgroupMax",
"subgroupMin",
"subgroupMul",
"subgroupExclusiveMul",
"subgroupInclusiveMul",
"subgroupOr",
"subgroupShuffle",
"subgroupShuffleDown",
"subgroupShuffleUp",
"subgroupShuffleXor",
"subgroupXor",
"quadBroadcast",
"quadSwapDiagonal",
"quadSwapX",
"quadSwapY",
// not in the WGSL spec
"i64",
"u64",
"f64",
"push_constant",
"r64uint",
];
pub static BUILTIN_IDENTIFIER_SET: RacyLock<KeywordSet> =
RacyLock::new(|| KeywordSet::from_iter(BUILTIN_IDENTIFIERS));