Override Stage
Override-expressions are value expressions that are evaluated at pipeline creation time, or earlier.
Formally, every constant-expression is an override-expression.
Override-expressions other than const-expressions are only validated or evaluated during pipeline creation, and only after any API-provided values are substituted for override-declarations. If an override-declaration has its value substituted via the WebGPU API, its initializer expression, if present, is not evaluated.
Example: Pipeline-Overridable Constants & Sizing
The following example is loaded as an active, running playground in the panel on the right.
Try modifying the default value of WORKGROUP_WIDTH in the editor (for example, from 16u to 8u or 32u) and click Run to see the evaluated override-expression results update dynamically in real-time!
How it works:
DEFAULT_MULTIPLIER: This is a compile-time constant (const). Its value is fixed when the shader is translated.WORKGROUP_WIDTH: This is an overridable constant (override). If the host CPU application provides a value for ID101when creating the compute pipeline,WORKGROUP_WIDTHtakes that value; otherwise, it defaults to16u.TOTAL_CACHE_SIZE: The expressionWORKGROUP_WIDTH * DEFAULT_MULTIPLIERis an override-expression. It cannot be fully resolved at compile-time since it depends on the overridableWORKGROUP_WIDTH. Instead, it is evaluated during pipeline creation time, after any host-provided overrides are substituted.
Syntax Reference: override Declarations & JS APIs
For detailed reference on how to declare overridable constants in WGSL shaders and supply their overridden values dynamically inside the WebGPU JavaScript host application, refer to the override Declarations guide.
/*
* Copyright ©2026 Michael R. Bernstein. Licensed under Apache 2.0.
* See root README.md for global project-wide upstream attributions.
*/
// A compile-time constant expression (evaluated at shader module creation)
const DEFAULT_MULTIPLIER = 2u;
// A pipeline-overridable constant (evaluated at pipeline creation)
// Feel free to edit this default value and click "Run" to see the output update!
@id(101) override WORKGROUP_WIDTH: u32 = 16u;
// This override-expression uses both a const-expression and an override variable.
// It is evaluated during pipeline creation, once WORKGROUP_WIDTH is finalized.
override TOTAL_CACHE_SIZE: u32 = WORKGROUP_WIDTH * DEFAULT_MULTIPLIER;
// Sizing workgroup variables is the primary use-case for override-expressions.
// The array length is resolved at pipeline creation time.
var<workgroup> shared_cache: array<f32, TOTAL_CACHE_SIZE>;
@compute @workgroup_size(16)
fn compute_main(
@builtin(local_invocation_id) local_id: vec3<u32>
) {
// We can use the override constants inside our shader code as well
if (local_id.x < TOTAL_CACHE_SIZE) {
shared_cache[local_id.x] = 0.0;
}
}