[llvm] [HLSL][RootSignature] Implement serialized dump of Descriptor Tables (PR #138326)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 10:28:42 PDT 2025


================
@@ -0,0 +1,151 @@
+//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects ---------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helpers for working with HLSL Root Signatures.
+///
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+#include "llvm/ADT/bit.h"
+
+namespace llvm {
+namespace hlsl {
+namespace rootsig {
+
+static raw_ostream &operator<<(raw_ostream &OS, const Register &Reg) {
+  switch (Reg.ViewType) {
+  case RegisterType::BReg:
+    OS << "b";
+    break;
+  case RegisterType::TReg:
+    OS << "t";
+    break;
+  case RegisterType::UReg:
+    OS << "u";
+    break;
+  case RegisterType::SReg:
+    OS << "s";
+    break;
+  }
+  OS << Reg.Number;
+  return OS;
+}
+
+static raw_ostream &operator<<(raw_ostream &OS,
+                               const ShaderVisibility &Visibility) {
+  switch (Visibility) {
+  case ShaderVisibility::All:
+    OS << "All";
+    break;
+  case ShaderVisibility::Vertex:
+    OS << "Vertex";
+    break;
+  case ShaderVisibility::Hull:
+    OS << "Hull";
+    break;
+  case ShaderVisibility::Domain:
+    OS << "Domain";
+    break;
+  case ShaderVisibility::Geometry:
+    OS << "Geometry";
+    break;
+  case ShaderVisibility::Pixel:
+    OS << "Pixel";
+    break;
+  case ShaderVisibility::Amplification:
+    OS << "Amplification";
+    break;
+  case ShaderVisibility::Mesh:
+    OS << "Mesh";
+    break;
+  }
+
+  return OS;
+}
+
+void DescriptorTable::dump(raw_ostream &OS) const {
+  OS << "DescriptorTable(numClauses = " << NumClauses;
+  OS << ", visibility = " << Visibility << ")";
+}
+
+static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) {
+  switch (Type) {
+  case ClauseType::CBuffer:
+    OS << "CBV";
+    break;
+  case ClauseType::SRV:
+    OS << "SRV";
+    break;
+  case ClauseType::UAV:
+    OS << "UAV";
+    break;
+  case ClauseType::Sampler:
+    OS << "Sampler";
+    break;
+  }
+
+  return OS;
+}
+
+static raw_ostream &operator<<(raw_ostream &OS,
+                               const DescriptorRangeFlags &Flags) {
+  bool FlagSet = false;
+  unsigned Remaining = llvm::to_underlying(Flags);
+  while (Remaining) {
+    unsigned Bit = 1u << llvm::countr_zero(Remaining);
+    if (Remaining & Bit) {
+      if (FlagSet)
+        OS << " | ";
+
+      switch (static_cast<DescriptorRangeFlags>(Bit)) {
+      case DescriptorRangeFlags::DescriptorsVolatile:
+        OS << "DescriptorsVolatile";
+        break;
+      case DescriptorRangeFlags::DataVolatile:
+        OS << "DataVolatile";
+        break;
+      case DescriptorRangeFlags::DataStaticWhileSetAtExecute:
+        OS << "DataStaticWhileSetAtExecute";
+        break;
+      case DescriptorRangeFlags::DataStatic:
+        OS << "DataStatic";
+        break;
+      case DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks:
+        OS << "DescriptorsStaticKeepingBufferBoundsChecks";
+        break;
+      default:
+        OS << "invalid: " << Bit;
+        break;
+      }
+
+      FlagSet = true;
+    }
+    Remaining &= ~Bit;
+  }
+
+  if (!FlagSet)
+    OS << "None";
+
+  return OS;
+}
+
+void DescriptorTableClause::dump(raw_ostream &OS) const {
+  OS << Type << "(" << Reg;
+  OS << ", numDescriptors = " << NumDescriptors;
+  OS << ", space = " << Space;
+  OS << ", offset = ";
----------------
bogner wrote:

Same here

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


More information about the llvm-commits mailing list