I always knew interactions between different structs with the same fields wasn't looked at till now, but I didn't expect the behavior to be this strange, haha.
it('copies?', () => {
const Boid = d.struct({
pos: d.vec3f,
vel: d.vec3f,
});
// A different struct, but with the same properties
const Bird = d.struct({
pos: d.vec3f,
vel: d.vec3f,
});
function main() {
'use gpu';
const boid = Boid();
const bird = Bird(boid); // doing an explicit copy, works on the type level
return bird;
}
expect(tgpu.resolve([main])).toMatchInlineSnapshot(`
"struct Boid {
pos: vec3f,
vel: vec3f,
}
struct Bird {
pos: vec3f,
vel: vec3f,
}
fn main() -> Bird {
var boid = Boid();
var bird = boid;
return bird;
}"
`);
});
It seems like when we try to explicitly copy the object boid of type Boid as a new object of type Bird that happens to have the same properties, we just don't handle it and emit boid with the type Bird, where in WGSL it's still going to be of type Boid.
I always knew interactions between different structs with the same fields wasn't looked at till now, but I didn't expect the behavior to be this strange, haha.
It seems like when we try to explicitly copy the object
boidof typeBoidas a new object of typeBirdthat happens to have the same properties, we just don't handle it and emitboidwith the typeBird, where in WGSL it's still going to be of typeBoid.