[llvm] [DirectX] Set shader feature flags MinimumPrecision and NativeLowPrecision (PR #139623)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 23:56:15 PDT 2025


bogner wrote:

I think we need to refactor / clean up the handling of the MinimumPrecision/NativeLowPrecision and LowPrecisionPresent/UseNativeLowPrecision flags. This code is starting to become very hard to follow.

1. I'm not 100% convinced we really need all four, and if we do we should probably do some renaming as it's very confusing to have "NativeLowPrecision" and "UseNativeLowPrecision" be so subtly different.
2. It's really awkward how setting these is spread out across three different places.

For (1), it does look like we need MinimumPrecision, NativeLowPrecision, and LowPrecisionPresent. LowPrecisionPresent seems to be set in the container regardless of whether 16 bit types are enabled so I don't think it can be folded in to the other two. UseNativeLowPrecision on the other hand feels redundant to me. The one place that's tricky here is related to a comment in [use-native-low-precision-1.ll](https://github.com/llvm/llvm-project/blob/ad66e5495d598c9f64cfafba92ba48f2a24b8278/llvm/test/CodeGen/DirectX/ShaderFlags/use-native-low-precision-1.ll#L21-L23) - if we set the function flag purely based on the compiler flag but the container flag depends on actual use, then they do need to be separate. Is this done by dxc intentionally or is it a bug? It seems weird to have a flag that says there are 16 bit types when there aren't any present.

For (2), I think we should move the logic that reads the module metadata out of the loop and precalculate a bool to look it up rather than calculate it every time, and then put all of the logic to set these correctly where we handle LowPrecisionPresent today. IIUC The module flags aren't involved in the function flag calculation, so it should be fine to set those here, and that way we can have one place that has all of this logic and can be commented appropriately to explain what's happening.

https://github.com/llvm/llvm-project/pull/139623


More information about the llvm-commits mailing list