This page lists the words and symbols a WGSL file is built from. A keyword has a fixed meaning in the grammar. A reserved word is kept for future use and must not appear in a module at all. A syntactic token is a short run of punctuation used as an operator or separator. A context-dependent name looks like an identifier but only has a meaning in one place, such as inside an attribute. All lists are taken from the W3C specification and are complete.
Keywords
WGSL has 26 keywords (§16.1). Type names such as f32, vec4 and array are not keywords. They are predeclared names, and their constructors are listed on the built-in functions page.
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 words
A reserved word is a token kept for future use. A WGSL module must not contain one (§16.2). There are 146:
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
Syntactic tokens
A syntactic token is a sequence of special code points. It spells an operator or acts as punctuation that groups or separates other parts of the grammar (§16.3). There are 46 tokens with a spelling of their own. Six of them also have a second name used during template list disambiguation, shown in the last column.
| Spelling | Name | Code points | Template form |
|---|---|---|---|
& | and | U+0026 | |
&& | and_and | U+0026 U+0026 | |
-> | arrow | U+002D U+003E | |
@ | attr | U+0040 | |
/ | forward_slash | U+002F | |
! | bang | U+0021 | |
[ | bracket_left | U+005B | |
] | bracket_right | U+005D | |
{ | brace_left | U+007B | |
} | brace_right | U+007D | |
: | colon | U+003A | |
, | comma | U+002C | |
= | equal | U+003D | |
== | equal_equal | U+003D U+003D | |
!= | not_equal | U+0021 U+003D | |
> | greater_than | U+003E | _greater_than |
>= | greater_than_equal | U+003E U+003D | _greater_than_equal |
>> | shift_right | U+003E U+003E | _shift_right |
< | less_than | U+003C | _less_than |
<= | less_than_equal | U+003C U+003D | _less_than_equal |
<< | shift_left | U+003C U+003C | _shift_left |
% | modulo | U+0025 | |
- | minus | U+002D | |
-- | minus_minus | U+002D U+002D | |
. | period | U+002E | |
+ | plus | U+002B | |
++ | plus_plus | U+002B U+002B | |
| | or | U+007C | |
|| | or_or | U+007C U+007C | |
( | paren_left | U+0028 | |
) | paren_right | U+0029 | |
; | semicolon | U+003B | |
* | star | U+002A | |
~ | tilde | U+007E | |
_ | underscore | U+005F | |
^ | xor | U+005E | |
+= | plus_equal | U+002B U+003D | |
-= | minus_equal | U+002D U+003D | |
*= | times_equal | U+002A U+003D | |
/= | division_equal | U+002F U+003D | |
%= | modulo_equal | U+0025 U+003D | |
&= | and_equal | U+0026 U+003D | |
|= | or_equal | U+007C U+003D | |
^= | xor_equal | U+005E U+003D | |
>>= | shift_right_assign | U+003E U+003E U+003D | _shift_right_assign |
<<= | shift_left_assign | U+003C U+003C U+003D | _shift_left_assign |
Three more tokens exist only for template lists such as vec4<f32>. They are produced by template list disambiguation, not typed as separate spellings.
| Name | Text | Meaning |
|---|---|---|
_template_args_start | < (U+003C) | The first token of a template list. Textually the same as less_than. |
_template_args_end | > (U+003E) | The last token of a template list. Textually the same as greater_than. |
_disambiguate_template | None | Matches an empty string. The standard parser ignores it. In the alternative parsing formulation it makes the scanner run template list discovery. |
Context-dependent names
A context-dependent name names a concept, but only in a specific grammatical place (§3.8). It may be spelt like an identifier, but it does not refer to a declared object. It must not be a keyword or reserved word.
| Kind | Names |
|---|---|
| Attribute names (§3.8.1), 18 | align binding builtin compute const diagnostic fragment group id interpolate invariant location blend_src must_use size vertex workgroup_size subgroup_size |
| Built-in value names (§3.8.2), 19 | vertex_index instance_index position front_facing frag_depth sample_index sample_mask local_invocation_id local_invocation_index global_invocation_id global_invocation_index workgroup_id workgroup_index num_workgroups subgroup_invocation_id subgroup_size primitive_index subgroup_id num_subgroups |
| Diagnostic rule names (§3.8.3), 2 | derivative_uniformity subgroup_uniformity |
| Diagnostic severity control names (§3.8.4), 4 | error warning info off |
| Enable-extension names (§3.8.5), 6 | f16 clip_distances dual_source_blending subgroups primitive_index subgroup_size_control |
| Language extension names (§3.8.5), 14 | readonly_and_readwrite_storage_textures packed_4x8_integer_dot_product unrestricted_pointer_parameters pointer_composite_access uniform_buffer_standard_layout subgroup_id subgroup_uniformity texture_and_sampler_let texture_formats_tier1 linear_indexing immediate_address_space fragment_depth buffer_view swizzle_assignment |
| Interpolation type names (§3.8.6), 3 | perspective linear flat |
| Interpolation sampling names (§3.8.7), 5 | center centroid sample first either |
| Swizzle names (§3.8.8) | One to four letters, all from rgba or all from xyzw, such as x, xy, bgr or wzyx. The two sets cannot be mixed in one name. |
| Depth mode names (§3.8.9), 2 | less greater |
The extension tables in §4.1 list one more name than §3.8.5. atomic_vec2u_min_max appears in both the enable-extension table (§4.1.1) and the language extension table (§4.1.2). It makes atomicStoreMin and atomicStoreMax valid on atomic<vec2<u32>>. Depth mode names are used in the frag_depth built-in when the fragment_depth feature is supported.
Operator precedence
Precedence in WGSL comes from the grammar rather than from a numbered table (§8.20, non-normative). The rows below run from strongest to weakest. The Binding column names the strongest kind of expression an operand can be without parentheses. “All above” means any stronger expression may be used. “Unary” means anything weaker than unary, but stronger than this row, must be put in parentheses.
| Name | Operators | Associativity | Binding |
|---|---|---|---|
| Parenthesised | (...) | ||
| Primary | a(), a[], a.b | Left-to-right | |
| Unary | -a, !a, ~a, *a, &a | Right-to-left | All above |
| Multiplicative | a*b, a/b, a%b | Left-to-right | All above |
| Additive | a+b, a-b | Left-to-right | All above |
| Shift | a<<b, a>>b | Requires parentheses | Unary |
| Relational | a<b, a>b, a<=b, a>=b, a==b, a!=b | Requires parentheses | All above |
| Binary AND | a&b | Left-to-right | Unary |
| Binary XOR | a^b | Left-to-right | Unary |
| Binary OR | a|b | Left-to-right | Unary |
| Short-circuit AND | a&&b | Left-to-right | Relational |
| Short-circuit OR | a||b | Left-to-right | Relational |
To keep code readable, the bitwise and short-circuit groups do not associate with other groups, so a & b | c needs parentheses. Shift and relational operators do not associate with themselves, so a < b < c needs parentheses too.
Sources
- WebGPU Shading Language – W3C Candidate Recommendation Draft, 6 November 2026: section 3.8 (context-dependent names), 4.1 (extensions), 8.20 (operator precedence and associativity) and 16 (keyword and token summary).