================
@@ -3334,7 +3366,60 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
 
     break;
   }
+  case Builtin::BI__builtin_hlsl_resource_sample: {
+    if (SemaRef.checkArgCountRange(TheCall, 3, 5))
+      return true;
+
+    if (CheckResourceHandle(
+            &SemaRef, TheCall, 0,
+            [](const HLSLAttributedResourceType *ResType) {
+              return ResType->getAttrs().ResourceDimension ==
+                     llvm::dxil::ResourceDimension::DimensionUnknown;
+            }))
+      return true;
+
+    if (CheckResourceHandle(&SemaRef, TheCall, 1,
+                            [](const HLSLAttributedResourceType *ResType) {
+                              return ResType->getAttrs().ResourceClass !=
+                                     llvm::hlsl::ResourceClass::Sampler;
+                            }))
+      return true;
 
+    auto *ResourceTy =
+        TheCall->getArg(0)->getType()->castAs<HLSLAttributedResourceType>();
+
+    unsigned ExpectedDim =
+        getResourceDimensions(ResourceTy->getAttrs().ResourceDimension);
+    if (CheckVectorElementCount(&SemaRef, TheCall->getArg(2)->getType(),
+                                SemaRef.Context.FloatTy, ExpectedDim,
+                                TheCall->getArg(2)->getBeginLoc()))
+      return true;
+
+    if (TheCall->getNumArgs() > 3) {
+      if (CheckVectorElementCount(&SemaRef, TheCall->getArg(3)->getType(),
+                                  SemaRef.Context.IntTy, ExpectedDim,
+                                  TheCall->getArg(3)->getBeginLoc()))
+        return true;
+    }
+
+    if (TheCall->getNumArgs() > 4) {
+      QualType ClampTy = TheCall->getArg(4)->getType();
+      if (!ClampTy->isFloatingType() || ClampTy->isVectorType()) {
+        SemaRef.Diag(TheCall->getArg(4)->getBeginLoc(),
+                     diag::err_typecheck_convert_incompatible)
+            << ClampTy << SemaRef.Context.FloatTy << 1 << 0 << 0;
+        return true;
+      }
+    }
+
+    assert(ResourceTy->hasContainedType() &&
+           "Expecting a contained type for resource with a the dimension "
+           "attribute.");
----------------
hekota wrote:

```suggestion
           "Expecting a contained type for resource with a dimension "
           "attribute.");
```

https://github.com/llvm/llvm-project/pull/177240
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to