TS8032
On this page

TS8032

Front-end code UNSIZED_ARRAY_LENGTH

.length, or arrayLength(x), on an array<T> with no N that is not in storage: a uniform<array<T>>, a local, or a parameter.

The registry text and every compiler message on these pages are the compiler's own English.

When it fires

.length, or arrayLength(x), on an array<T> with no N that is not in storage: a uniform<array<T>>, a local, or a parameter. .length once folded to the literal 0, which made gid.x >= xs.length true for every invocation and the kernel a silent no-op in valid WGSL. A runtime-sized storage array now reads its length from the buffer as arrayLength(&x); the shapes that have no runtime length need an explicit size, which is what this says.

Example

example.shade.ts
"use typeshade"
declare const u: uniform<array<f32>>
function count(): f32 {
return f32(u.length)
}
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(uv, count(), 1.)
}

Compiled at build time against the pinned compiler, this program gets:

TS8051 error, line 3: "u" is a list of no fixed length, which a uniform cannot hold: a uniform buffer has one size. Give it a length, array<T, N>, or declare "u" as storage<T>.

TS8032 error, line 6: ".length" on an array with no size is not known at compile time. Give the type a size: array<f32, 3> rather than array<f32>.

How to fix it

The same program, corrected. It compiles with no diagnostic.

example.shade.ts
"use typeshade"
class UData {
items: array<f32, 3>
}
declare const u: uniform<UData>
function count(): f32 {
return f32(u.items.length)
}
@fragment
export function main(@location(0) uv: vec2): vec4 {
return vec4(uv, count(), 1.)
}

See also

TS8051 LAYOUT
A buffer binding's store type breaks one of WGSL's host-shareable rules (§51), which a struct hides from the type map and the backend only meets as emitted text: a bool, alone or in a vector, in a uniform or storage binding, as a field, a runtime array's element or the whole type (type 'bool' cannot be used in address space 'uniform' as it is non-host-shareable, and the same of vec3<bool>), a runtime-sized array<T> that is not its struct's last member, or a runtime-sized array in a uniform, whose type must be constructible.

Source

Where the compiler raises this code at commit 26de7be8, one line per file:

Edit this page Report a problem