Skip to content

compute.ndarray#wgslElementType

Summary

compute.ndarray#wgslElementType identifies a direct WGSL element type for the ndarray's dtype, when one is available. Check the strides and offsets separately before binding a view as a packed shader array.

Syntax

get wgslElementType(): "i32" | "u32" | "f32" | "vec2<f32>" | null
const elementType = a.wgslElementType;

Returns

"i32" | "u32" | "f32" | "vec2<f32>" | null - The matching scalar type for i32, u32 and f32, or vec2<f32> for the real and imaginary components of c64. All other dtypes return null.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const a = wgpu.compute.ndarray.empty("c64", { shape: [16] }, { residency: "gpu" });
console.log(a.wgslElementType); // vec2<f32>
a.destroy();

See Also