[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)
Deric C. via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 3 14:54:07 PDT 2025
================
@@ -253,6 +253,37 @@ const inline float length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
return __detail::length_vec_impl(X);
}
+//===----------------------------------------------------------------------===//
+// lit builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn vector<T, 4> lit(T NDotL, T NDotH, T M)
+/// \brief Returns a lighting coefficient vector.
+/// \param NDotL The dot product of the normalized surface normal and the
+/// light vector.
+/// \param NDotH The dot product of the half-angle vector and the surface
+/// normal.
+/// \param M A specular exponent.
+///
+/// This function returns a lighting coefficient vector (ambient, diffuse,
+/// specular, 1).
+
+template <typename T>
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
----------------
Icohedron wrote:
> > I believe you should not worry about implicit truncation here.
>
> Hm ok, curious what other people's thoughts are on this. I was just trying to match the behavior of DXC since it doesn't compile when called with vector inputs. I still think `_DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lit)` doesn't work regardless because the return type of `lit` is always a vector of 4.
Oh, right
https://github.com/llvm/llvm-project/pull/134171
More information about the cfe-commits
mailing list