[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


================
@@ -174,6 +174,90 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
   return false;
 }
 
+static bool parseDescriptorRange(LLVMContext *Ctx,
+                                 mcdxbc::RootSignatureDesc &RSD,
+                                 mcdxbc::DescriptorTable &Table,
+                                 MDNode *RangeDescriptorNode) {
+
+  if (RangeDescriptorNode->getNumOperands() != 6)
+    return reportError(Ctx, "Invalid format for Descriptor Range");
+
+  dxbc::RTS0::v2::DescriptorRange Range;
+
+  std::optional<StringRef> ElementText =
+      extractMdStringValue(RangeDescriptorNode, 0);
+
+  if (!ElementText.has_value())
+    return reportError(Ctx, "Descriptor Range, first element is not a string.");
+
+  Range.RangeType =
+      StringSwitch<uint32_t>(*ElementText)
+          .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+          .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+          .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+          .Case("Sampler",
+                llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+          .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+  if (std::optional<uint32_t> Val = extractMdIntValue(RangeDescriptorNode, 1))
+    Range.NumDescriptors = *Val;
+  else
+    return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
----------------
inbelic wrote:

We could probably have a function like `reportInvalidTypeError` for all of these. Similar to `reportValueError` but with a message that will differentiate between the two.

Something like "Parameter: ... expected metadata node of type ... but got ..." I am not sure if you can retrieve the type of an `MDNode`?

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


More information about the llvm-commits mailing list