#4560·wgpu

Naga should map `break if` 1:1 to the backend (i.e. `do`-`while` for GLSL/HLSL/MSL).

Author: eddybCreated Jun 21, 2023Updated Sep 18, 2026
Labelstype: enhancementarea: naga back-endnagalang: GLSLlang: Metallang: HLSL

Quoting myself from https://github.com/gfx-rs/wgpu/issues/4558:

I do not understand why break if turns into that kind of conditional break.

AIUI it was only added to WGSL to represent SPIR-V conditional backedges. And SPIR-V itself only has conditional backedges to encode do-while loops. So that's the natural translation.

That is, loop { ... continuing { ... break if !(select(false, true, _e23)); } } should turn into do { ... } while(!!(_e23 ? true : false)); - without any overcomplicated propagation across the backedge.

I believe Naga already maps break if 1:1 to WGSL (as expected) and to SPIR-V (as conditional backedges).

So only the C-like backends (GLSL/HLSL/MSL) remain, and they should all allow a 1:1 mapping via do-while.