[llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)

Finn Plummer via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 15:17:16 PDT 2025


================
@@ -236,11 +323,84 @@ static bool verifyRegisterValue(uint32_t RegisterValue) {
 // This Range is reserverved, therefore invalid, according to the spec
 // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#all-the-values-should-be-legal
 static bool verifyRegisterSpace(uint32_t RegisterSpace) {
-  return !(RegisterSpace >= 0xFFFFFFF0 && RegisterSpace <= 0xFFFFFFFF);
+  return !(RegisterSpace >= 0xFFFFFFF0 && RegisterSpace < 0xFFFFFFFF);
 }
 
 static bool verifyDescriptorFlag(uint32_t Flags) { return (Flags & ~0xE) == 0; }
 
+static bool verifyRangeType(uint32_t Type) {
+  switch (Type) {
+  case llvm::to_underlying(dxbc::DescriptorRangeType::CBV):
+  case llvm::to_underlying(dxbc::DescriptorRangeType::SRV):
+  case llvm::to_underlying(dxbc::DescriptorRangeType::UAV):
+  case llvm::to_underlying(dxbc::DescriptorRangeType::Sampler):
+    return true;
+  };
+
+  return false;
+}
+
+static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
+                                      uint32_t Flags) {
+  if (Version == 1 &&
+      Type == llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+    return Flags == 0;
+
+  if (Version == 2 &&
+      Type == llvm::to_underlying(dxbc::DescriptorRangeType::Sampler)) {
+    switch (Flags) {
+    case 0:
+    case llvm::to_underlying(dxbc::DescriptorRangeFlag::DATA_VOLATILE):
+    case llvm::to_underlying(
+        dxbc::DescriptorRangeFlag::
+            DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS):
+      return true;
+    }
+    return false;
+  }
+
+  if (Version == 1 &&
+      Type != llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+    return Flags ==
+           llvm::to_underlying(dxbc::DescriptorRangeFlag::DESCRIPTORS_VOLATILE);
+
+  if (Version == 2 &&
+      Type != llvm::to_underlying(dxbc::DescriptorRangeType::Sampler)) {
+    switch (Flags) {
----------------
inbelic wrote:

Personally, I find this switch statement really difficult to follow along and verify it is doing what we want.

I am pretty sure it is implementing the logic from [here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#all-the-values-should-be-legal).

Maybe a templated `isFlagSet` function and an if-else chain might help?

Or a comment describing/linking to the docs to help.

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


More information about the llvm-commits mailing list