[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:08 PDT 2024


================
@@ -4593,6 +4593,44 @@ def HLSLResourceBinding: InheritableAttr {
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
+  let AdditionalMembers = [{
+      enum class RegisterType : unsigned { SRV, UAV, CBuffer, Sampler, C, I, Invalid };
+
+      RegisterType RegType;
+      unsigned SlotNumber;
+      unsigned SpaceNumber;
+      
+      // Size of the binding
+      // 0 == not set
+      //-1 == unbounded
+      int Size;
+
+      void setBinding(RegisterType RT, unsigned SlotNum, unsigned SpaceNum, int Size = 0) {
+        RegType = RT;
+        SlotNumber = SlotNum;
+        SpaceNumber = SpaceNum;
+      }
+      RegisterType getRegisterType() {
+        return RegType;
+      }
+      unsigned getSlotNumber() {
+        return SlotNumber;
+      }
+      unsigned getSpaceNumber() {
+        return SpaceNumber;
+      }
+      unsigned getSize() {
+        assert(Size == -1 || Size > 0 && "size not set");
+        return Size;
+      }
+      void setSize(int N) {
+        assert(N == -1 || N > 0 && "unexpected size value");
+        Size = N;
+      }
+      bool isSizeUnbounded() {
+        return Size == -1;
----------------
damyanp wrote:

Presumably this should have the same assert as on line 4623.  Or could be written as `return getSize() == -1;`

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


More information about the cfe-commits mailing list