Skip to content

Commit a383b1a

Browse files
authored
Reland "[HLSL][RootSignature] Implement serialization of RootConstants and RootFlags" (#143019)
This relands #141130. The initial commit uncovered that we are missing the correct linking of FrontendHLSL into clang/lib/Parse and clang/lib/unittests/Parse. This change addreses this by linking them accordingly. It was also checked and ensured that the LexHLSLRootSignature libraries do not depend on FrontendHLSL and so we are not required to link there. Resolves: #138190 and #138192
1 parent 6cbb67f commit a383b1a

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

clang/lib/Parse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(LLVM_LINK_COMPONENTS
2+
FrontendHLSL
23
FrontendOpenMP
34
MC
45
MCParser

clang/unittests/Parse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ add_clang_unittest(ParseTests
1111
LLVMTestingSupport
1212
clangTesting
1313
LLVM_COMPONENTS
14+
FrontendHLSL
1415
Support
1516
)

llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Metadata;
2727
namespace hlsl {
2828
namespace rootsig {
2929

30+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags);
31+
32+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
33+
const RootConstants &Constants);
34+
3035
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
3136
const DescriptorTableClause &Clause);
3237

llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ static raw_ostream &operator<<(raw_ostream &OS,
129129
return OS;
130130
}
131131

132+
static const EnumEntry<RootFlags> RootFlagNames[] = {
133+
{"AllowInputAssemblerInputLayout",
134+
RootFlags::AllowInputAssemblerInputLayout},
135+
{"DenyVertexShaderRootAccess", RootFlags::DenyVertexShaderRootAccess},
136+
{"DenyHullShaderRootAccess", RootFlags::DenyHullShaderRootAccess},
137+
{"DenyDomainShaderRootAccess", RootFlags::DenyDomainShaderRootAccess},
138+
{"DenyGeometryShaderRootAccess", RootFlags::DenyGeometryShaderRootAccess},
139+
{"DenyPixelShaderRootAccess", RootFlags::DenyPixelShaderRootAccess},
140+
{"AllowStreamOutput", RootFlags::AllowStreamOutput},
141+
{"LocalRootSignature", RootFlags::LocalRootSignature},
142+
{"DenyAmplificationShaderRootAccess",
143+
RootFlags::DenyAmplificationShaderRootAccess},
144+
{"DenyMeshShaderRootAccess", RootFlags::DenyMeshShaderRootAccess},
145+
{"CBVSRVUAVHeapDirectlyIndexed", RootFlags::CBVSRVUAVHeapDirectlyIndexed},
146+
{"SamplerHeapDirectlyIndexed", RootFlags::SamplerHeapDirectlyIndexed},
147+
};
148+
149+
raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) {
150+
OS << "RootFlags(";
151+
printFlags(OS, Flags, ArrayRef(RootFlagNames));
152+
OS << ")";
153+
154+
return OS;
155+
}
156+
157+
raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants) {
158+
OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
159+
<< ", " << Constants.Reg << ", space = " << Constants.Space
160+
<< ", visibility = " << Constants.Visibility << ")";
161+
162+
return OS;
163+
}
164+
132165
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table) {
133166
OS << "DescriptorTable(numClauses = " << Table.NumClauses
134167
<< ", visibility = " << Table.Visibility << ")";

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,73 @@ 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+
143+
TEST(HLSLRootSignatureTest, NoneRootFlagsDump) {
144+
RootFlags Flags = RootFlags::None;
145+
146+
std::string Out;
147+
llvm::raw_string_ostream OS(Out);
148+
OS << Flags;
149+
OS.flush();
150+
151+
std::string Expected = "RootFlags(None)";
152+
EXPECT_EQ(Out, Expected);
153+
}
154+
155+
TEST(HLSLRootSignatureTest, AllRootFlagsDump) {
156+
RootFlags Flags = RootFlags::ValidFlags;
157+
158+
std::string Out;
159+
llvm::raw_string_ostream OS(Out);
160+
OS << Flags;
161+
OS.flush();
162+
163+
std::string Expected = "RootFlags("
164+
"AllowInputAssemblerInputLayout | "
165+
"DenyVertexShaderRootAccess | "
166+
"DenyHullShaderRootAccess | "
167+
"DenyDomainShaderRootAccess | "
168+
"DenyGeometryShaderRootAccess | "
169+
"DenyPixelShaderRootAccess | "
170+
"AllowStreamOutput | "
171+
"LocalRootSignature | "
172+
"DenyAmplificationShaderRootAccess | "
173+
"DenyMeshShaderRootAccess | "
174+
"CBVSRVUAVHeapDirectlyIndexed | "
175+
"SamplerHeapDirectlyIndexed)";
176+
177+
EXPECT_EQ(Out, Expected);
178+
}
179+
111180
} // namespace

0 commit comments

Comments
 (0)