Skip to content

Commit 30388bf

Browse files
committed
[HLSL][RootSignature] Add serialization for RootFlags
1 parent 9764ebf commit 30388bf

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum class RootFlags : uint32_t {
4646
ValidFlags = 0x00000fff
4747
};
4848

49+
raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags);
50+
4951
enum class DescriptorRangeFlags : unsigned {
5052
None = 0,
5153
DescriptorsVolatile = 0x1,

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

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

135+
raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) {
136+
OS << "RootFlags(";
137+
bool FlagSet = false;
138+
unsigned Remaining = llvm::to_underlying(Flags);
139+
while (Remaining) {
140+
unsigned Bit = 1u << llvm::countr_zero(Remaining);
141+
if (Remaining & Bit) {
142+
if (FlagSet)
143+
OS << " | ";
144+
145+
switch (static_cast<RootFlags>(Bit)) {
146+
case RootFlags::AllowInputAssemblerInputLayout:
147+
OS << "AllowInputAssemblerInputLayout";
148+
break;
149+
case RootFlags::DenyVertexShaderRootAccess:
150+
OS << "DenyVertexShaderRootAccess";
151+
break;
152+
case RootFlags::DenyHullShaderRootAccess:
153+
OS << "DenyHullShaderRootAccess";
154+
break;
155+
case RootFlags::DenyDomainShaderRootAccess:
156+
OS << "DenyDomainShaderRootAccess";
157+
break;
158+
case RootFlags::DenyGeometryShaderRootAccess:
159+
OS << "DenyGeometryShaderRootAccess";
160+
break;
161+
case RootFlags::DenyPixelShaderRootAccess:
162+
OS << "DenyPixelShaderRootAccess";
163+
break;
164+
case RootFlags::AllowStreamOutput:
165+
OS << "AllowStreamOutput";
166+
break;
167+
case RootFlags::LocalRootSignature:
168+
OS << "LocalRootSignature";
169+
break;
170+
case RootFlags::DenyAmplificationShaderRootAccess:
171+
OS << "DenyAmplificationShaderRootAccess";
172+
break;
173+
case RootFlags::DenyMeshShaderRootAccess:
174+
OS << "DenyMeshShaderRootAccess";
175+
break;
176+
case RootFlags::CBVSRVUAVHeapDirectlyIndexed:
177+
OS << "CBVSRVUAVHeapDirectlyIndexed";
178+
break;
179+
case RootFlags::SamplerHeapDirectlyIndexed:
180+
OS << "SamplerHeapDirectlyIndexed";
181+
break;
182+
default:
183+
OS << "invalid: " << Bit;
184+
break;
185+
}
186+
187+
FlagSet = true;
188+
}
189+
Remaining &= ~Bit;
190+
}
191+
192+
if (!FlagSet)
193+
OS << "None";
194+
195+
OS << ")";
196+
197+
return OS;
198+
}
199+
135200
raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants) {
136201
OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
137202
<< ", " << Constants.Reg << ", space = " << Constants.Space

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,41 @@ TEST(HLSLRootSignatureTest, SetRootConstantsDump) {
140140
EXPECT_EQ(Out, Expected);
141141
}
142142

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+
143180
} // namespace

0 commit comments

Comments
 (0)