TS8032
On this page

TS8032

Front-end code UNSIZED_ARRAY_LENGTH

.length on an array<T> with no size that is not in storage: a uniform<array<T>>, a local or a parameter. A runtime-sized storage array reads its length from the buffer. Any other array needs an explicit size.

The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.

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

Example

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

See also

TS8051 LAYOUT
A buffer binding's store type that breaks one of WGSL's host-shareable rules: a bool, alone or in a vector, in a uniform or storage binding; a runtime-sized array<T> that is not the last member of its struct; a runtime-sized array in a uniform; or a two-row matrix (mat2x2, mat3x2, mat4x2) in a uniform, which WGSL and std140 lay out at different offsets (Rule 4.8).

Source

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

Edit this page Report a problem