[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

Deric C. via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 3 15:37:20 PDT 2025


================
@@ -280,6 +280,22 @@ constexpr bool4 isinf(double4 V) { return isinf((float4)V); }
 _DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
 _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
 
+//===----------------------------------------------------------------------===//
+// lit builtins overloads
+//===----------------------------------------------------------------------===//
+
+template <typename T>
+constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
+                                    (__detail::is_same<double, T>::value ||
----------------
Icohedron wrote:

> ^ Since bool is arithmetic, both of these options would allow bool inputs to pass. I checked the DXC implementation on [godbolt](https://godbolt.org/z/Eb3vTdvvG) and I guess it technically accepts bool types and casts them down to float. But is that something we want to be mimicking?
> 
> As for checking just `__detail::is_arithmetic<T>`, this produces a `call to 'lit' is ambiguous` error. So if we want to do this I think it would have to be checking not half or float too.

We should mimic DXC.

Would the ambiguous error still appear if you didn't use templates? Just like as Farzon suggested:
```c++
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half4 lit(half A, half B, half M) { ...}
const inline float4 lit(float A, float B, float M) { ...}
```

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


More information about the cfe-commits mailing list