Re:Don't "optimize" conditional moves in shaders with mix()+...
by justsid on Sunday February 09, 2025 @04:19PM
(#42994105)
It depends. If the code flow is uniform for the warp, only side of the branch needs to be evaluated. But you could still end up with pessimistic register allocation because the compiler can’t know it is uniform. It’s sometimes weirdly hard to reason about how exactly code will end up executing on the GPU.
Re:Don't "optimize" conditional moves in shaders with mix()+...
by danybittel on Monday February 10, 2025 @12:09AM
(#42997143)
f or g may have side effects too. Like writing to memory.
Now a conditional has a different meaning.
You could also have some fun stuff, where f and g return a boolean, because thanks to short circuit evaluation && || are actually also conditionals in disguise.
The GPU will almost always execute f and g due to GPU differences vs CPU.
You can avoid the f vs g if you can ensure a scalar Boolean / if statement that is consistent across the warp. So it's not 'always' but requires incredibly specific coding patterns to 'force' the optimizer + GPU compiler into making the branch.