[clang] [HLSL] Implement codegen for copying cbuffer structs with resources (PR #204232)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 25 13:47:29 PDT 2026


================
@@ -523,8 +536,39 @@ class HLSLBufferCopyEmitter {
     return true;
   }
 
+  // Returns true if the type is either a struct represening a resource record,
+  // or an array of structs that are resource records. This assumes a struct is
+  // a resource record if the first element is a target type (resource handle).
+  // This is the case for all target types used by HLSL except the padding type
+  // ("{dx|spirv.Padding"), but padding will never be the first element of a
+  // struct.
+  bool isResourceOrResourceArray(llvm::Type *Ty) {
+    while (auto *AT = dyn_cast<llvm::ArrayType>(Ty))
+      Ty = AT->getElementType();
+
+    auto *ST = dyn_cast<llvm::StructType>(Ty);
+    if (!ST || ST->getNumElements() < 1)
+      return false;
+
+    auto *TargetTy = dyn_cast<llvm::TargetExtType>(ST->getElementType(0));
----------------
hekota wrote:

It is mentioned in the comment describing the function.

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


More information about the cfe-commits mailing list