uniform
On this page

uniform

Function

A uniform declaration describes data supplied by the host and shared by shader invocations during a draw or dispatch.

Compare examples

The shader reads the parameter value supplied by the host. Declaring a uniform does not upload the value.

Model assumptionsclass Params { scale: f32; } declare const u: uniform<Params>;

Example 1host: u.scale = 1; shader: u.scale
Result
1
Example 2host: u.scale = 2; shader: u.scale
Result
2
Example 3host: u.scale = 0; shader: u.scale
Result
0

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

When to use it

Use it for passing camera settings, dimensions, and other small parameters.

Inputs and limits

The declaration does not upload data. The host must allocate, bind, and populate a buffer with the reflected layout. Shaders cannot write a uniform binding.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Declares a uniform binding of type T; use declare const name: uniform<T> or const name = uniform<T>().

Syntax

declare function uniform<T>(slot?: number | { group?: number; binding?: number }, binding?: number): ReadView<T>

A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

type f32 = number & { readonly [f32Tag]?: true }

A number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.

A signature may name a type the ambient file declares for its own use. These are those declarations.

ReadView
type ReadView<T> = T extends number | boolean ? T : T extends (...args: never[]) => unknown ? T : { readonly [K in keyof T]: K extends string | number ? ReadView<T[K]> : T[K] }

Parameters

  • slot optional number | { group?: number; binding?: number }
  • binding optional number

Return value

ReadView<T>

Examples

See also

Edit this page Report a problem