gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.62k stars 925 forks source link

[naga] [glsl-in] Crashes when we go over a certain nested stack depth (including if/else chains) #5652

Open magcius opened 6 months ago

magcius commented 6 months ago

Description It seems that glsl-in crashes after a certain recursion limit; the call stack is blown.

Repro steps https://gist.github.com/magcius/b53f33c9135355fe7fed542a748c60b3

Expected vs observed behavior I'd expect a successful parse, or at least an error, rather than a crash.

Extra materials This was found when trying to translate this shader to WGSL for noclip.website, which uses Naga to transform GLSL to WGSL for the WebGPU backend. https://github.com/magcius/noclip.website/blob/fe8dd8f74d93579296e7d087147de0b3a1bfcebd/src/MarioKart8Deluxe/Render.ts#L534-L597

Platform wgpu commit bdf30fa45aa86b827749f7ee45ed342ce27b0fbb. This was found with a version of Naga compiled to WebAssembly, but it crashes anywhere.

ErichDonGubler commented 6 months ago

Some relevant Naga community chat about solutions: https://matrix.to/#/!fjjkgHFcwtkREywzfk:matrix.org/$hfLitnms2hGFLbFiwC6t2ZJ6Yd-51HHj9WEmKol7RoI?via=matrix.org&via=mozilla.org&via=ralith.com