[clang] [llvm] [HLSL] Implement the `faceforward` intrinsic (PR #135878)

Finn Plummer via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 10:45:42 PDT 2025


================
@@ -137,6 +137,42 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID,
     TheCall->setType(RetTy);
     break;
   }
+  case SPIRV::BI__builtin_spirv_faceforward: {
+    if (SemaRef.checkArgCount(TheCall, 3))
+      return true;
+
+    // check if all arguments have floating representation
+    for (unsigned i = 0; i < TheCall->getNumArgs(); ++i) {
+      ExprResult Arg = TheCall->getArg(i);
+      QualType ArgTy = Arg.get()->getType();
+      if (!ArgTy->hasFloatingRepresentation()) {
+        SemaRef.Diag(Arg.get()->getBeginLoc(),
+                     diag::err_builtin_invalid_arg_type)
+            << i + 1 << /* scalar or vector */ 5 << /* no int */ 0 << /* fp */ 1
----------------
inbelic wrote:

```suggestion
            << /* ordinal */ i + 1 << /* scalar or vector */ 5 << /* no int */ 0 << /* fp */ 1
```

I think this for loop is the exact same as the smoothstep function? We could probably move it to a common function then. 

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


More information about the llvm-commits mailing list