[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 << ")";
----------------
bogner wrote:

Style nit (though it really doesn't matter much) - we typically just do all of this as a single expression, and clang-format does a pretty good job of handling streaming operators:
```suggestion
  OS << "DescriptorTable(numClauses = " << NumClauses
     << ", visibility = " << Visibility << ")";
```

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


More information about the llvm-commits mailing list