[naga spv-out] Loop bounding probably shouldn't use local variables #7116
Labels
area: naga back-end
Outputs of naga shader conversion
kind: refactor
Making existing function faster or nicer
lang: SPIR-V
Vulkan's Shading Language
naga
Shader Translator
(This is a pre-emptive follow-up issue for #7080, not yet landed.)
Because unbounded loops are undefined behavior in SPIR-V, #7080 changes Naga's SPIR-V backend to make all loops bounded by an injected counter that allows only ~2^64 iterations, introducing new
OpVariable
local variables to serve as the counters.However, SPIR-V's SSA form allows us to express such counters using no local variables at all, and this form might be more digestible to optimizers and code generators. Here's a complete SPIR-V module that passes
spirv-val
validation and does a loop from 0 to 1000 without any local variables. The trick is that theOpPhi
instruction selects either the initial value of the counter, when we enter the loop header for the first time, or the incremented value of the counter, when we enter the loop header from a prior iteration.I don't know that this would really make any difference, which is why I'm filing it as a separate issue, prioritized as a "refactor". But it is nice that we can do this without introducing new local variables, and I think the code is a bit shorter.
The text was updated successfully, but these errors were encountered: