-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[HLSL][RootSignature] Implement serialized dump of Descriptor Tables #138326
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
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6dd49d4
get infra setup
inbelic 51483dd
implement support for dumping descriptor table clauses
inbelic 2bdbbc6
implement support for dumping descriptor table struct
inbelic 81692d6
nfc: change some test values around or something
inbelic 7070ca0
clang-format
inbelic c3bd361
review: change to using static << operator
inbelic 88de1d9
review: use clang-format for OS streaming
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
//===- 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 void dumpRegType(raw_ostream &OS, RegisterType Type) { | ||
switch (Type) { | ||
case RegisterType::BReg: | ||
OS << "b"; | ||
break; | ||
case RegisterType::TReg: | ||
OS << "t"; | ||
break; | ||
case RegisterType::UReg: | ||
OS << "u"; | ||
break; | ||
case RegisterType::SReg: | ||
OS << "s"; | ||
break; | ||
} | ||
} | ||
|
||
void Register::dump(raw_ostream &OS) const { | ||
dumpRegType(OS, ViewType); | ||
OS << Number; | ||
} | ||
|
||
static void dumpVisibility(raw_ostream &OS, 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; | ||
} | ||
} | ||
|
||
void DescriptorTable::dump(raw_ostream &OS) const { | ||
OS << "DescriptorTable(numClauses = " << NumClauses; | ||
OS << ", visibility = "; | ||
dumpVisibility(OS, Visibility); | ||
OS << ")"; | ||
} | ||
|
||
static void dumpClauseType(raw_ostream &OS, 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; | ||
} | ||
} | ||
|
||
static void dumpDescriptorRangeFlag(raw_ostream &OS, unsigned Bit) { | ||
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; | ||
} | ||
} | ||
|
||
static void dumpDescriptorRangeFlags(raw_ostream &OS, | ||
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 << " | "; | ||
dumpDescriptorRangeFlag(OS, Bit); | ||
FlagSet = true; | ||
} | ||
Remaining &= ~Bit; | ||
} | ||
if (!FlagSet) | ||
OS << "None"; | ||
} | ||
|
||
void DescriptorTableClause::dump(raw_ostream &OS) const { | ||
dumpClauseType(OS, Type); | ||
OS << "("; | ||
Reg.dump(OS); | ||
OS << ", numDescriptors = " << NumDescriptors; | ||
OS << ", space = " << Space; | ||
OS << ", offset = "; | ||
if (Offset == DescriptorTableOffsetAppend) | ||
OS << "DescriptorTableOffsetAppend"; | ||
else | ||
OS << Offset; | ||
OS << ", flags = "; | ||
dumpDescriptorRangeFlags(OS, Flags); | ||
OS << ")"; | ||
} | ||
|
||
} // namespace rootsig | ||
} // namespace hlsl | ||
} // namespace llvm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
//===-------- HLSLRootSignatureDumpTest.cpp - RootSignature dump tests ----===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Frontend/HLSL/HLSLRootSignature.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace llvm::hlsl::rootsig; | ||
|
||
namespace { | ||
|
||
TEST(HLSLRootSignatureTest, DescriptorCBVClauseDump) { | ||
DescriptorTableClause Clause; | ||
Clause.Type = ClauseType::CBuffer; | ||
Clause.Reg = {RegisterType::BReg, 0}; | ||
Clause.setDefaultFlags(); | ||
|
||
std::string Out; | ||
llvm::raw_string_ostream OS(Out); | ||
Clause.dump(OS); | ||
OS.flush(); | ||
|
||
std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, " | ||
"offset = DescriptorTableOffsetAppend, " | ||
"flags = DataStaticWhileSetAtExecute)"; | ||
EXPECT_EQ(Out, Expected); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) { | ||
DescriptorTableClause Clause; | ||
Clause.Type = ClauseType::SRV; | ||
Clause.Reg = {RegisterType::TReg, 0}; | ||
Clause.NumDescriptors = 2; | ||
Clause.Space = 42; | ||
Clause.Offset = 3; | ||
Clause.Flags = DescriptorRangeFlags::None; | ||
|
||
std::string Out; | ||
llvm::raw_string_ostream OS(Out); | ||
Clause.dump(OS); | ||
OS.flush(); | ||
|
||
std::string Expected = | ||
"SRV(t0, numDescriptors = 2, space = 42, offset = 3, flags = None)"; | ||
EXPECT_EQ(Out, Expected); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, DescriptorUAVClauseDump) { | ||
DescriptorTableClause Clause; | ||
Clause.Type = ClauseType::UAV; | ||
Clause.Reg = {RegisterType::UReg, 92374}; | ||
Clause.NumDescriptors = 3298; | ||
Clause.Space = 932847; | ||
Clause.Offset = 1; | ||
Clause.Flags = DescriptorRangeFlags::ValidFlags; | ||
|
||
std::string Out; | ||
llvm::raw_string_ostream OS(Out); | ||
Clause.dump(OS); | ||
OS.flush(); | ||
|
||
std::string Expected = | ||
"UAV(u92374, numDescriptors = 3298, space = 932847, offset = 1, flags = " | ||
"DescriptorsVolatile | " | ||
"DataVolatile | " | ||
"DataStaticWhileSetAtExecute | " | ||
"DataStatic | " | ||
"DescriptorsStaticKeepingBufferBoundsChecks)"; | ||
EXPECT_EQ(Out, Expected); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) { | ||
DescriptorTableClause Clause; | ||
Clause.Type = ClauseType::Sampler; | ||
Clause.Reg = {RegisterType::SReg, 0}; | ||
Clause.NumDescriptors = 2; | ||
Clause.Space = 42; | ||
Clause.Offset = DescriptorTableOffsetAppend; | ||
Clause.Flags = DescriptorRangeFlags::ValidSamplerFlags; | ||
|
||
std::string Out; | ||
llvm::raw_string_ostream OS(Out); | ||
Clause.dump(OS); | ||
OS.flush(); | ||
|
||
std::string Expected = "Sampler(s0, numDescriptors = 2, space = 42, offset = " | ||
"DescriptorTableOffsetAppend, " | ||
"flags = DescriptorsVolatile)"; | ||
EXPECT_EQ(Out, Expected); | ||
} | ||
|
||
TEST(HLSLRootSignatureTest, DescriptorTableDump) { | ||
DescriptorTable Table; | ||
Table.NumClauses = 4; | ||
Table.Visibility = ShaderVisibility::Geometry; | ||
|
||
std::string Out; | ||
llvm::raw_string_ostream OS(Out); | ||
Table.dump(OS); | ||
OS.flush(); | ||
|
||
std::string Expected = | ||
"DescriptorTable(numClauses = 4, visibility = Geometry)"; | ||
EXPECT_EQ(Out, Expected); | ||
} | ||
|
||
} // namespace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole file becomes a bit simpler and cleaner if we define a bunch of
operator<<
s instead of dump functions. So here we could haveand similarly for the rest of these static dump functions. Then the publicly visible
dump()
methods can be implemented asOS << "Foo(" << thing1 << "bar = " << thing2 << ")"
etcThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1