Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ enum class RootFlags : uint32_t {
ValidFlags = 0x00000fff
};

raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags);

enum class DescriptorRangeFlags : unsigned {
None = 0,
DescriptorsVolatile = 0x1,
Expand Down Expand Up @@ -85,6 +87,8 @@ struct RootConstants {
ShaderVisibility Visibility = ShaderVisibility::All;
};

raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants);

using DescriptorType = llvm::dxil::ResourceClass;
// Models RootDescriptor : CBV | SRV | UAV, by collecting like parameters
struct RootDescriptor {
Expand Down
73 changes: 73 additions & 0 deletions llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,79 @@ static raw_ostream &operator<<(raw_ostream &OS,
return OS;
}

raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) {
OS << "RootFlags(";
bool FlagSet = false;
unsigned Remaining = llvm::to_underlying(Flags);
while (Remaining) {
unsigned Bit = 1u << llvm::countr_zero(Remaining);
if (Remaining & Bit) {
if (FlagSet)
OS << " | ";

switch (static_cast<RootFlags>(Bit)) {
case RootFlags::AllowInputAssemblerInputLayout:
OS << "AllowInputAssemblerInputLayout";
break;
case RootFlags::DenyVertexShaderRootAccess:
OS << "DenyVertexShaderRootAccess";
break;
case RootFlags::DenyHullShaderRootAccess:
OS << "DenyHullShaderRootAccess";
break;
case RootFlags::DenyDomainShaderRootAccess:
OS << "DenyDomainShaderRootAccess";
break;
case RootFlags::DenyGeometryShaderRootAccess:
OS << "DenyGeometryShaderRootAccess";
break;
case RootFlags::DenyPixelShaderRootAccess:
OS << "DenyPixelShaderRootAccess";
break;
case RootFlags::AllowStreamOutput:
OS << "AllowStreamOutput";
break;
case RootFlags::LocalRootSignature:
OS << "LocalRootSignature";
break;
case RootFlags::DenyAmplificationShaderRootAccess:
OS << "DenyAmplificationShaderRootAccess";
break;
case RootFlags::DenyMeshShaderRootAccess:
OS << "DenyMeshShaderRootAccess";
break;
case RootFlags::CBVSRVUAVHeapDirectlyIndexed:
OS << "CBVSRVUAVHeapDirectlyIndexed";
break;
case RootFlags::SamplerHeapDirectlyIndexed:
OS << "SamplerHeapDirectlyIndexed";
break;
default:
OS << "invalid: " << Bit;
break;
}

FlagSet = true;
}
Remaining &= ~Bit;
}

if (!FlagSet)
OS << "None";

OS << ")";

return OS;
}

raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants) {
OS << "RootConstants(num32BitConstants = " << Constants.Num32BitConstants
<< ", " << Constants.Reg << ", space = " << Constants.Space
<< ", visibility = " << Constants.Visibility << ")";

return OS;
}

raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table) {
OS << "DescriptorTable(numClauses = " << Table.NumClauses
<< ", visibility = " << Table.Visibility << ")";
Expand Down
69 changes: 69 additions & 0 deletions llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,73 @@ TEST(HLSLRootSignatureTest, DescriptorTableDump) {
EXPECT_EQ(Out, Expected);
}

TEST(HLSLRootSignatureTest, DefaultRootConstantsDump) {
RootConstants Constants;
Constants.Num32BitConstants = 1;
Constants.Reg = {RegisterType::BReg, 3};

std::string Out;
llvm::raw_string_ostream OS(Out);
OS << Constants;
OS.flush();

std::string Expected = "RootConstants(num32BitConstants = 1, b3, space = 0, "
"visibility = All)";
EXPECT_EQ(Out, Expected);
}

TEST(HLSLRootSignatureTest, SetRootConstantsDump) {
RootConstants Constants;
Constants.Num32BitConstants = 983;
Constants.Reg = {RegisterType::BReg, 34593};
Constants.Space = 7;
Constants.Visibility = ShaderVisibility::Pixel;

std::string Out;
llvm::raw_string_ostream OS(Out);
OS << Constants;
OS.flush();

std::string Expected = "RootConstants(num32BitConstants = 983, b34593, "
"space = 7, visibility = Pixel)";
EXPECT_EQ(Out, Expected);
}

TEST(HLSLRootSignatureTest, NoneRootFlagsDump) {
RootFlags Flags = RootFlags::None;

std::string Out;
llvm::raw_string_ostream OS(Out);
OS << Flags;
OS.flush();

std::string Expected = "RootFlags(None)";
EXPECT_EQ(Out, Expected);
}

TEST(HLSLRootSignatureTest, AllRootFlagsDump) {
RootFlags Flags = RootFlags::ValidFlags;

std::string Out;
llvm::raw_string_ostream OS(Out);
OS << Flags;
OS.flush();

std::string Expected = "RootFlags("
"AllowInputAssemblerInputLayout | "
"DenyVertexShaderRootAccess | "
"DenyHullShaderRootAccess | "
"DenyDomainShaderRootAccess | "
"DenyGeometryShaderRootAccess | "
"DenyPixelShaderRootAccess | "
"AllowStreamOutput | "
"LocalRootSignature | "
"DenyAmplificationShaderRootAccess | "
"DenyMeshShaderRootAccess | "
"CBVSRVUAVHeapDirectlyIndexed | "
"SamplerHeapDirectlyIndexed)";

EXPECT_EQ(Out, Expected);
}

} // namespace