[llvm] [DirectX] Add Range Overlap validation (PR #152229)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 16:55:51 PDT 2025


================
@@ -24,6 +25,35 @@ using namespace llvm;
 using namespace llvm::dxil;
 
 namespace {
+static ResourceClass RangeToResourceClass(uint32_t RangeType) {
+  using namespace dxbc;
+  switch (static_cast<DescriptorRangeType>(RangeType)) {
+  case DescriptorRangeType::SRV:
+    return ResourceClass::SRV;
+  case DescriptorRangeType::UAV:
+    return ResourceClass::UAV;
+  case DescriptorRangeType::CBV:
+    return ResourceClass::CBuffer;
+  case DescriptorRangeType::Sampler:
+    return ResourceClass::Sampler;
+  }
+}
+
+ResourceClass ParameterToResourceClass(uint32_t Type) {
+  using namespace dxbc;
+  switch (Type) {
+  case llvm::to_underlying(RootParameterType::Constants32Bit):
+    return ResourceClass::CBuffer;
+  case llvm::to_underlying(RootParameterType::SRV):
+    return ResourceClass::SRV;
+  case llvm::to_underlying(RootParameterType::UAV):
+    return ResourceClass::UAV;
+  case llvm::to_underlying(RootParameterType::CBV):
+    return ResourceClass::CBuffer;
+  default:
+    llvm_unreachable("Unknown RootParameterType");
----------------
bogner wrote:

Better to explicitly have the case we're intentionally not handling and no `default` at all. I also think it would be a good idea to have a different messages for that case and for the fall through `llvm_unreachable` - in one case the value should be impossible but in the other we have a misuse of the API if we're passing in `RootParameterType::DescriptorTable`

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


More information about the llvm-commits mailing list