gfx-rs / wgpu

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

[hlsl-out] Output is not HLSL 2021 compatible #4498

Open fornwall opened 1 year ago

fornwall commented 1 year ago

Naga currently generates hlsl that is not valid HLSL 2021, as there binary logic operators can only be used with scalars, so we need to change generation:

-  doit = vec && (ShouldIDoIt(vec) || !ShouldINotDoIt(vec));
+  doit = and(vec, or(ShouldIDoIt(vec), !ShouldINotDoIt(vec)));

While possible (changing countLeadingZeros() and select() writing is enough to pass CI), fxc does not support HLSL 2021 (and the and(), or() and select() intrinsics are only available in HLSL 2021).

In gfx-rs/naga#2447 we worked around the DX Compiler release for August 2023 making HLSL 2021 the default by specifying -HV 2018 in CI, but:

Ideally we should be forward compatible. [..] I think we are running into this issue only for the select implementation; we can either take the language version as a parameter or inject a polyfill for vector conditions regardless of version.

This issue is tracking that.

teoxoy commented 1 year ago

Note that this is only an issue with the select built-in as that's the only one getting translated to the ternary op ?: with a vecN<bool> condition.