Skip to content

Commit 9764ebf

Browse files
committed
[HLSL][RootSignature] Add serialization for RootConstants
1 parent 5d76555 commit 9764ebf

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct RootConstants {
8585
ShaderVisibility Visibility = ShaderVisibility::All;
8686
};
8787

88+
raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants);
89+
8890
using DescriptorType = llvm::dxil::ResourceClass;
8991
// Models RootDescriptor : CBV | SRV | UAV, by collecting like parameters
9092
struct RootDescriptor {

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ static raw_ostream &operator<<(raw_ostream &OS,
132132
return OS;
133133
}
134134

135+
raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants) {
136+
OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
137+
<< ", " << Constants.Reg << ", space = " << Constants.Space
138+
<< ", visibility = " << Constants.Visibility << ")";
139+
140+
return OS;
141+
}
142+
135143
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table) {
136144
OS << "DescriptorTable(numClauses = " << Table.NumClauses
137145
<< ", visibility = " << Table.Visibility << ")";

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,36 @@ TEST(HLSLRootSignatureTest, DescriptorTableDump) {
108108
EXPECT_EQ(Out, Expected);
109109
}
110110

111+
TEST(HLSLRootSignatureTest, DefaultRootConstantsDump) {
112+
RootConstants Constants;
113+
Constants.Num32BitConstants = 1;
114+
Constants.Reg = {RegisterType::BReg, 3};
115+
116+
std::string Out;
117+
llvm::raw_string_ostream OS(Out);
118+
OS << Constants;
119+
OS.flush();
120+
121+
std::string Expected = "RootConstants(num32BitConstants = 1, b3, space = 0, "
122+
"visibility = All)";
123+
EXPECT_EQ(Out, Expected);
124+
}
125+
126+
TEST(HLSLRootSignatureTest, SetRootConstantsDump) {
127+
RootConstants Constants;
128+
Constants.Num32BitConstants = 983;
129+
Constants.Reg = {RegisterType::BReg, 34593};
130+
Constants.Space = 7;
131+
Constants.Visibility = ShaderVisibility::Pixel;
132+
133+
std::string Out;
134+
llvm::raw_string_ostream OS(Out);
135+
OS << Constants;
136+
OS.flush();
137+
138+
std::string Expected = "RootConstants(num32BitConstants = 983, b34593, "
139+
"space = 7, visibility = Pixel)";
140+
EXPECT_EQ(Out, Expected);
141+
}
142+
111143
} // namespace

0 commit comments

Comments
 (0)