gfx-rs/wgpu-rs

Division not working as intended in the Boids example

baptistemanson opened this issue · 4 comments

This line:

 cMass = cMass * (1.0 / f32(cMassCount)) - vPos;

https://github.com/gfx-rs/wgpu-rs/blob/master/examples/boids/compute.wgsl#L80

should be simplifiable to:

 cMass = cMass / f32(cMassCount) - vPos;

but it crashes with an access violation on the vulkan backend. The problem comes from the division.
GL doesnt run at all, with this change or not, DX11 either, but DX12 runs smoothly.

kvark commented

Doing cMass / f32(cMassCount) is actually not valid in WGSL. See the "Binary arithmetic expressions with mixed scalar, vector, and matrix operands" section of the spec at https://gpuweb.github.io/gpuweb/wgsl.html .
We could do cMass / vec2<f32>(f32(cMassCount), f32(cMassCount)) though, and that would probably be better than what we have now.

Thanks, I'll keep it in mind for the validation layer!

Fwiw, DX11 seems to runs boids fine now. I don't know if the source has been changed since then.

Closing due to wgpu-rs -> wgpu migration and due to this being old. Please refile if this is still an issue.