fill
On this page

fill

Function

Fill constructs a fixed-size array by repeating one value.

Compare examples

A scalar fills every element with that scalar. A vector fills every element with that vector.

Example 1fill<f32, 3>(0.)
Result
[0, 0, 0]
Example 2fill<f32, 3>(2.)
Result
[2, 2, 2]
Example 3fill<vec2, 2>(vec2(1., 2.))
Result
[[1, 2], [1, 2]]

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 initializing a short array to a known value.

Inputs and limits

Specify the element type and length. It creates a value, not a storage-buffer allocation or a host-to-GPU upload.

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.

Creates an array<T, N> where every element is the given value; requires type arguments fill<T, N>(value).

Syntax

declare function fill<T, N extends number>(value: T): array<T, N>

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.

Parameters

  • value T

Return value

array<T, N>

See also

Edit this page Report a problem