Skip to content

Revert "[DirectX][objdump] Add support for printing signatures" #153313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions llvm/include/llvm/Object/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,6 @@ class LLVM_ABI DXContainerObjectFile : public ObjectFile {
}

public:
const DXContainer &getDXContainer() const { return Container; }

static bool classof(const Binary *v) { return v->isDXContainer(); }

Expected<StringRef> getSymbolName(DataRefImpl) const override;
Expand Down
167 changes: 0 additions & 167 deletions llvm/test/tools/llvm-objdump/DXContainer/input-output-signatures.yaml

This file was deleted.

129 changes: 2 additions & 127 deletions llvm/tools/llvm-objdump/DXContainerDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,141 +12,16 @@
//===----------------------------------------------------------------------===//

#include "llvm-objdump.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"

using namespace llvm;
using namespace llvm::object;

static llvm::SmallString<4> maskToString(uint8_t Mask) {
llvm::SmallString<4> Result(" ");
if (Mask & 1)
Result[0] = 'x';
if (Mask & 2)
Result[1] = 'y';
if (Mask & 4)
Result[2] = 'z';
if (Mask & 8)
Result[3] = 'w';
return Result;
}

static void printColumnHeader(raw_ostream &OS, size_t Length) {
for (size_t I = 0; I < Length; ++I)
OS << "-";
}

static void printColumnHeaders(raw_ostream &OS, ArrayRef<size_t> Lengths) {
for (auto L : Lengths) {
printColumnHeader(OS, L);
OS << " ";
}
OS << "\n";
}

static size_t digitsForNumber(size_t N) {
return static_cast<size_t>(log10(static_cast<double>(N))) + 1;
}

namespace {
class DXContainerDumper : public objdump::Dumper {
const DXContainerObjectFile &Obj;

public:
DXContainerDumper(const DXContainerObjectFile &O)
: objdump::Dumper(O), Obj(O) {}

void printPrivateHeaders() override;
void printSignature(const DirectX::Signature &S);
DXContainerDumper(const object::DXContainerObjectFile &Obj)
: objdump::Dumper(Obj) {}
};

void DXContainerDumper::printSignature(const DirectX::Signature &S) {
// DXC prints a table like this as part of the shader disassembly:
//; Name Index Mask Register SysValue Format Used
//; -------------------- ----- ------ -------- -------- ------- ------
//; NORMAL 0 xyz 0 NONE float xyz
//; TEXCOORD 0 xy 1 NONE float xy

// DXC's implementation doesn't scale columns entirely completely for the
// provided input, so this implementation is a bit more complicated in
// formatting logic to scale with the size of the printed text.

// DXC gives names 21 characters for some unknown reason, I arbitrarily chose
// to start at 24 so that we're not going shorter but are using a round
// number.
size_t LongestName = 24;
size_t LongestSV = 10;
size_t LongestIndex = strlen("Index");
size_t LongestRegister = strlen("Register");
size_t LongestFormat = strlen("Format");
const size_t MaskWidth = 5;
// Compute the column widths. Skip calculating the "Mask" and "Used" columns
// since they both have widths of 4.
for (auto El : S) {
LongestName = std::max(LongestName, S.getName(El.NameOffset).size());
LongestSV = std::max(
LongestSV,
enumToStringRef(El.SystemValue, dxbc::getD3DSystemValues()).size());
LongestIndex = std::max(LongestIndex, digitsForNumber(El.Index));
LongestRegister = std::max(LongestRegister, digitsForNumber(El.Register));
LongestFormat = std::max(
LongestFormat,
enumToStringRef(El.CompType, dxbc::getSigComponentTypes()).size());
}

// Print Column headers.
OS << "; ";
OS << left_justify("Name", LongestName) << " ";
OS << right_justify("Index", LongestIndex) << " ";
OS << right_justify("Mask", MaskWidth) << " ";
OS << right_justify("Register", LongestRegister) << " ";
OS << right_justify("SysValue", LongestSV) << " ";
OS << right_justify("Format", LongestFormat) << " ";
OS << right_justify("Used", MaskWidth) << "\n";
OS << "; ";
printColumnHeaders(OS, {LongestName, LongestIndex, MaskWidth, LongestRegister,
LongestSV, LongestFormat, MaskWidth});

for (auto El : S) {
OS << "; " << left_justify(S.getName(El.NameOffset), LongestName) << " ";
OS << right_justify(std::to_string(El.Index), LongestIndex) << " ";
OS << right_justify(maskToString(El.Mask), MaskWidth) << " ";
OS << right_justify(std::to_string(El.Register), LongestRegister) << " ";
OS << right_justify(
enumToStringRef(El.SystemValue, dxbc::getD3DSystemValues()),
LongestSV)
<< " ";
OS << right_justify(
enumToStringRef(El.CompType, dxbc::getSigComponentTypes()),
LongestFormat)
<< " ";
OS << right_justify(maskToString(El.ExclusiveMask), MaskWidth) << "\n";
}
}

void DXContainerDumper::printPrivateHeaders() {
const DXContainer &C =
cast<object::DXContainerObjectFile>(Obj).getDXContainer();

if (!C.getInputSignature().isEmpty()) {
OS << "; Input signature:\n;\n";
printSignature(C.getInputSignature());
OS << ";\n";
}

if (!C.getOutputSignature().isEmpty()) {
OS << "; Output signature:\n;\n";
printSignature(C.getOutputSignature());
OS << ";\n";
}

if (!C.getPatchConstantSignature().isEmpty()) {
OS << "; Patch Constant signature:\n;\n";
printSignature(C.getPatchConstantSignature());
OS << ";\n";
}
}
} // namespace

std::unique_ptr<objdump::Dumper> llvm::objdump::createDXContainerDumper(
Expand Down
Loading