This is equivalent in function to creating a new typed buffer and plugging in an existing GPUBuffer, but we can validate that the size of the schemas matches. Also, it's pretty cool.
const size = 4;
const array2d = <T extends AnyWgslData>(element: T, w: number, h: number) =>
d.arrayOf(d.arrayOf(d.vec2h, w), h);
const displacementBuffer = root.createBuffer(array2d(d.vec2h, size, size)).$usage('storage');
const regularView = noiseBuffer.as('mutable');
const packedView = noiseBuffer.as('mutable', array2d(d.u32, size, size));
We could also go for a .reinterpret API, which would nicely extend to fixed usages:
const size = 4;
const array2d = <T extends AnyWgslData>(element: T, w: number, h: number) =>
d.arrayOf(d.arrayOf(d.vec2h, w), h);
const displacementMutable = root.createMutable(array2d(d.vec2h, size, size));
const displacementPackedMutable = displacementMutable.reinterpret(array2d(d.u32, size, size));
To be discussed before attempting to implement
This is equivalent in function to creating a new typed buffer and plugging in an existing GPUBuffer, but we can validate that the size of the schemas matches. Also, it's pretty cool.
We could also go for a
.reinterpretAPI, which would nicely extend to fixed usages:To be discussed before attempting to implement