[clang] [HLSL] Collect explicit resource binding information (PR #111203)

Damyan Pepper via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 14 14:28:10 PDT 2024


================
@@ -83,6 +81,49 @@ static RegisterType getRegisterType(StringRef Slot) {
   }
 }
 
+static ResourceClass getResourceClass(RegisterType RT) {
+  switch (RT) {
+  case RegisterType::SRV:
+    return ResourceClass::SRV;
+  case RegisterType::UAV:
+    return ResourceClass::UAV;
+  case RegisterType::CBuffer:
+    return ResourceClass::CBuffer;
+  case RegisterType::Sampler:
+    return ResourceClass::Sampler;
+  default:
+    llvm_unreachable("unexpected RegisterType value");
+  }
+}
+
+DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,
+                                                      ResourceClass ResClass,
+                                                      int Size) {
+  assert(getDeclBindingInfo(VD, ResClass) == nullptr &&
+         "DeclBindingInfo already added");
+  if (DeclToBindingListIndex.find(VD) == DeclToBindingListIndex.end())
+    DeclToBindingListIndex[VD] = BindingsList.size();
+  return &BindingsList.emplace_back(DeclBindingInfo(VD, ResClass, Size));
----------------
damyanp wrote:

```suggestion
  return &BindingsList.emplace_back(VD, ResClass, Size);
```

Or

```suggestion
  return &BindingsList.push_back(DeclBindingInfo(VD, ResClass, Size));
```


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


More information about the cfe-commits mailing list