gpuweb icon indicating copy to clipboard operation
gpuweb copied to clipboard

[buffer-view] Extent of reinterpretation permitted

Open alan-baker opened this issue 2 months ago • 1 comments

Proposal currently limits reinterpretation to always from the base variable and only once.

Would more extensive reinterpretation be better? This seems it would imply taking any pointer type and reinterpreting it. That would mean implementations would have to track through more expressions. For example:

var<storage, read_write> buf : buffer;

struct T {
  u : vec4,
  v : vec2i,
}

struct S {
  a : array<T, 4>,
  b : f32
}

fn foo() {
  let p1 : ptr<storage, S, read_write> = bufferView<S>(&buf, offset1);
  let p2 : ptr<storage, f32, read_write> = &(p1.a[2].u[1]);
  let p3 : ptr<storage, vec4u, read_write> = bufferView<vec4u>(p2, offset2); // real potential for unaligned memory access
}

The current restrictions avoid some footguns like unaligned memory access.

alan-baker avatar Oct 22 '25 15:10 alan-baker

Additionally, the proposal currently limits the return type as host-shareable. This is a restriction on workgroup variables since it may be desirable to reinterpret them as an override-sized array. Related to #5486.

alan-baker avatar Dec 12 '25 21:12 alan-baker