Author: Finn Plummer Date: 2025-07-03T14:44:11-07:00 New Revision: 0ceb0c377a3e67b70965c32e7f21fe8b33f555d2
URL: https://github.com/llvm/llvm-project/commit/0ceb0c377a3e67b70965c32e7f21fe8b33f555d2 DIFF: https://github.com/llvm/llvm-project/commit/0ceb0c377a3e67b70965c32e7f21fe8b33f555d2.diff LOG: [NFC][HLSL][DirectX] Let `HLSLRootSignature` reuse the `dxbc` defined enums (#145986) This pr removes the redundancy of having the same enums defined in both the front-end and back-end of handling root signatures. Since there are many more uses of the enum in the front-end of the code, we will adhere to the naming conventions used in the front-end, to minimize the diff. The macros in `DXContainerConstants.def` are also touched-up to be consistent and to have each macro name follow its respective definition in d3d12.h and searchable by name [here](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/). Additionally, the many `getEnumNames` are moved to `DXContainer` from `HLSLRootSignatureUtils` as they we will want them to be exposed publicly anyways. Changes for each enum follow the pattern of a commit that will make the enum definition in `DXContainer` adhere to above listed naming conventions, followed by a commit to actually use that enum in the front-end. Resolves https://github.com/llvm/llvm-project/issues/145815 Added: Modified: clang/include/clang/Parse/ParseHLSLRootSignature.h clang/lib/Parse/ParseHLSLRootSignature.cpp clang/lib/Sema/SemaHLSL.cpp clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp llvm/include/llvm/BinaryFormat/DXContainer.h llvm/include/llvm/BinaryFormat/DXContainerConstants.def llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h llvm/include/llvm/ObjectYAML/DXContainerYAML.h llvm/lib/BinaryFormat/DXContainer.cpp llvm/lib/Frontend/HLSL/CMakeLists.txt llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp llvm/lib/ObjectYAML/DXContainerYAML.cpp llvm/lib/Target/DirectX/DXILRootSignature.cpp llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index afa2c4d8cfe50..18cd1f379e62c 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -71,7 +71,7 @@ class RootSignatureParser { // expected, or, there is a lexing error /// Root Element parse methods: - std::optional<llvm::hlsl::rootsig::RootFlags> parseRootFlags(); + std::optional<llvm::dxbc::RootFlags> parseRootFlags(); std::optional<llvm::hlsl::rootsig::RootConstants> parseRootConstants(); std::optional<llvm::hlsl::rootsig::RootDescriptor> parseRootDescriptor(); std::optional<llvm::hlsl::rootsig::DescriptorTable> parseDescriptorTable(); @@ -86,15 +86,15 @@ class RootSignatureParser { std::optional<llvm::hlsl::rootsig::Register> Reg; std::optional<uint32_t> Num32BitConstants; std::optional<uint32_t> Space; - std::optional<llvm::hlsl::rootsig::ShaderVisibility> Visibility; + std::optional<llvm::dxbc::ShaderVisibility> Visibility; }; std::optional<ParsedConstantParams> parseRootConstantParams(); struct ParsedRootDescriptorParams { std::optional<llvm::hlsl::rootsig::Register> Reg; std::optional<uint32_t> Space; - std::optional<llvm::hlsl::rootsig::ShaderVisibility> Visibility; - std::optional<llvm::hlsl::rootsig::RootDescriptorFlags> Flags; + std::optional<llvm::dxbc::ShaderVisibility> Visibility; + std::optional<llvm::dxbc::RootDescriptorFlags> Flags; }; std::optional<ParsedRootDescriptorParams> parseRootDescriptorParams(RootSignatureToken::Kind RegType); @@ -104,25 +104,25 @@ class RootSignatureParser { std::optional<uint32_t> NumDescriptors; std::optional<uint32_t> Space; std::optional<uint32_t> Offset; - std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags> Flags; + std::optional<llvm::dxbc::DescriptorRangeFlags> Flags; }; std::optional<ParsedClauseParams> parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType); struct ParsedStaticSamplerParams { std::optional<llvm::hlsl::rootsig::Register> Reg; - std::optional<llvm::hlsl::rootsig::SamplerFilter> Filter; - std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressU; - std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressV; - std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressW; + std::optional<llvm::dxbc::SamplerFilter> Filter; + std::optional<llvm::dxbc::TextureAddressMode> AddressU; + std::optional<llvm::dxbc::TextureAddressMode> AddressV; + std::optional<llvm::dxbc::TextureAddressMode> AddressW; std::optional<float> MipLODBias; std::optional<uint32_t> MaxAnisotropy; - std::optional<llvm::hlsl::rootsig::ComparisonFunc> CompFunc; - std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor; + std::optional<llvm::dxbc::ComparisonFunc> CompFunc; + std::optional<llvm::dxbc::StaticBorderColor> BorderColor; std::optional<float> MinLOD; std::optional<float> MaxLOD; std::optional<uint32_t> Space; - std::optional<llvm::hlsl::rootsig::ShaderVisibility> Visibility; + std::optional<llvm::dxbc::ShaderVisibility> Visibility; }; std::optional<ParsedStaticSamplerParams> parseStaticSamplerParams(); @@ -132,17 +132,13 @@ class RootSignatureParser { std::optional<float> parseFloatParam(); /// Parsing methods of various enums - std::optional<llvm::hlsl::rootsig::ShaderVisibility> parseShaderVisibility(); - std::optional<llvm::hlsl::rootsig::SamplerFilter> parseSamplerFilter(); - std::optional<llvm::hlsl::rootsig::TextureAddressMode> - parseTextureAddressMode(); - std::optional<llvm::hlsl::rootsig::ComparisonFunc> parseComparisonFunc(); - std::optional<llvm::hlsl::rootsig::StaticBorderColor> - parseStaticBorderColor(); - std::optional<llvm::hlsl::rootsig::RootDescriptorFlags> - parseRootDescriptorFlags(); - std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags> - parseDescriptorRangeFlags(); + std::optional<llvm::dxbc::ShaderVisibility> parseShaderVisibility(); + std::optional<llvm::dxbc::SamplerFilter> parseSamplerFilter(); + std::optional<llvm::dxbc::TextureAddressMode> parseTextureAddressMode(); + std::optional<llvm::dxbc::ComparisonFunc> parseComparisonFunc(); + std::optional<llvm::dxbc::StaticBorderColor> parseStaticBorderColor(); + std::optional<llvm::dxbc::RootDescriptorFlags> parseRootDescriptorFlags(); + std::optional<llvm::dxbc::DescriptorRangeFlags> parseDescriptorRangeFlags(); /// Use NumericLiteralParser to convert CurToken.NumSpelling into a unsigned /// 32-bit integer diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index e510302c3aae0..18d3644114eef 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -76,7 +76,7 @@ static FlagType maybeOrFlag(std::optional<FlagType> Flags, FlagType Flag) { llvm::to_underlying(Flag)); } -std::optional<RootFlags> RootSignatureParser::parseRootFlags() { +std::optional<llvm::dxbc::RootFlags> RootSignatureParser::parseRootFlags() { assert(CurToken.TokKind == TokenKind::kw_RootFlags && "Expects to only be invoked starting at given keyword"); @@ -84,7 +84,7 @@ std::optional<RootFlags> RootSignatureParser::parseRootFlags() { CurToken.TokKind)) return std::nullopt; - std::optional<RootFlags> Flags = RootFlags::None; + std::optional<llvm::dxbc::RootFlags> Flags = llvm::dxbc::RootFlags::None; // Handle the edge-case of '0' to specify no flags set if (tryConsumeExpectedToken(TokenKind::int_literal)) { @@ -104,7 +104,8 @@ std::optional<RootFlags> RootSignatureParser::parseRootFlags() { switch (CurToken.TokKind) { #define ROOT_FLAG_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - Flags = maybeOrFlag<RootFlags>(Flags, RootFlags::NAME); \ + Flags = maybeOrFlag<llvm::dxbc::RootFlags>(Flags, \ + llvm::dxbc::RootFlags::NAME); \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -240,7 +241,7 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() { return std::nullopt; DescriptorTable Table; - std::optional<ShaderVisibility> Visibility; + std::optional<llvm::dxbc::ShaderVisibility> Visibility; // Iterate as many Clauses as possible do { @@ -983,7 +984,7 @@ std::optional<float> RootSignatureParser::parseFloatParam() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::ShaderVisibility> +std::optional<llvm::dxbc::ShaderVisibility> RootSignatureParser::parseShaderVisibility() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -999,7 +1000,7 @@ RootSignatureParser::parseShaderVisibility() { switch (CurToken.TokKind) { #define SHADER_VISIBILITY_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - return ShaderVisibility::NAME; \ + return llvm::dxbc::ShaderVisibility::NAME; \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1009,7 +1010,7 @@ RootSignatureParser::parseShaderVisibility() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::SamplerFilter> +std::optional<llvm::dxbc::SamplerFilter> RootSignatureParser::parseSamplerFilter() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1025,7 +1026,7 @@ RootSignatureParser::parseSamplerFilter() { switch (CurToken.TokKind) { #define FILTER_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - return SamplerFilter::NAME; \ + return llvm::dxbc::SamplerFilter::NAME; \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1035,7 +1036,7 @@ RootSignatureParser::parseSamplerFilter() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::TextureAddressMode> +std::optional<llvm::dxbc::TextureAddressMode> RootSignatureParser::parseTextureAddressMode() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1051,7 +1052,7 @@ RootSignatureParser::parseTextureAddressMode() { switch (CurToken.TokKind) { #define TEXTURE_ADDRESS_MODE_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - return TextureAddressMode::NAME; \ + return llvm::dxbc::TextureAddressMode::NAME; \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1061,7 +1062,7 @@ RootSignatureParser::parseTextureAddressMode() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::ComparisonFunc> +std::optional<llvm::dxbc::ComparisonFunc> RootSignatureParser::parseComparisonFunc() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1077,7 +1078,7 @@ RootSignatureParser::parseComparisonFunc() { switch (CurToken.TokKind) { #define COMPARISON_FUNC_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - return ComparisonFunc::NAME; \ + return llvm::dxbc::ComparisonFunc::NAME; \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1087,7 +1088,7 @@ RootSignatureParser::parseComparisonFunc() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::StaticBorderColor> +std::optional<llvm::dxbc::StaticBorderColor> RootSignatureParser::parseStaticBorderColor() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1103,7 +1104,7 @@ RootSignatureParser::parseStaticBorderColor() { switch (CurToken.TokKind) { #define STATIC_BORDER_COLOR_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - return StaticBorderColor::NAME; \ + return llvm::dxbc::StaticBorderColor::NAME; \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1113,7 +1114,7 @@ RootSignatureParser::parseStaticBorderColor() { return std::nullopt; } -std::optional<llvm::hlsl::rootsig::RootDescriptorFlags> +std::optional<llvm::dxbc::RootDescriptorFlags> RootSignatureParser::parseRootDescriptorFlags() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1124,7 +1125,7 @@ RootSignatureParser::parseRootDescriptorFlags() { getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } - return RootDescriptorFlags::None; + return llvm::dxbc::RootDescriptorFlags::None; } TokenKind Expected[] = { @@ -1132,15 +1133,15 @@ RootSignatureParser::parseRootDescriptorFlags() { #include "clang/Lex/HLSLRootSignatureTokenKinds.def" }; - std::optional<RootDescriptorFlags> Flags; + std::optional<llvm::dxbc::RootDescriptorFlags> Flags; do { if (tryConsumeExpectedToken(Expected)) { switch (CurToken.TokKind) { #define ROOT_DESCRIPTOR_FLAG_ENUM(NAME, LIT) \ case TokenKind::en_##NAME: \ - Flags = \ - maybeOrFlag<RootDescriptorFlags>(Flags, RootDescriptorFlags::NAME); \ + Flags = maybeOrFlag<llvm::dxbc::RootDescriptorFlags>( \ + Flags, llvm::dxbc::RootDescriptorFlags::NAME); \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: @@ -1152,7 +1153,7 @@ RootSignatureParser::parseRootDescriptorFlags() { return Flags; } -std::optional<llvm::hlsl::rootsig::DescriptorRangeFlags> +std::optional<llvm::dxbc::DescriptorRangeFlags> RootSignatureParser::parseDescriptorRangeFlags() { assert(CurToken.TokKind == TokenKind::pu_equal && "Expects to only be invoked starting at given keyword"); @@ -1163,7 +1164,7 @@ RootSignatureParser::parseDescriptorRangeFlags() { getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag); return std::nullopt; } - return DescriptorRangeFlags::None; + return llvm::dxbc::DescriptorRangeFlags::None; } TokenKind Expected[] = { @@ -1171,15 +1172,15 @@ RootSignatureParser::parseDescriptorRangeFlags() { #include "clang/Lex/HLSLRootSignatureTokenKinds.def" }; - std::optional<DescriptorRangeFlags> Flags; + std::optional<llvm::dxbc::DescriptorRangeFlags> Flags; do { if (tryConsumeExpectedToken(Expected)) { switch (CurToken.TokKind) { #define DESCRIPTOR_RANGE_FLAG_ENUM(NAME, LIT, ON) \ case TokenKind::en_##NAME: \ - Flags = \ - maybeOrFlag<DescriptorRangeFlags>(Flags, DescriptorRangeFlags::NAME); \ + Flags = maybeOrFlag<llvm::dxbc::DescriptorRangeFlags>( \ + Flags, llvm::dxbc::DescriptorRangeFlags::NAME); \ break; #include "clang/Lex/HLSLRootSignatureTokenKinds.def" default: diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index bad357b50929b..6061b0015a56b 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1200,10 +1200,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, auto ReportOverlap = [this, Loc, &HadOverlap](const RangeInfo *Info, const RangeInfo *OInfo) { HadOverlap = true; - auto CommonVis = - Info->Visibility == llvm::hlsl::rootsig::ShaderVisibility::All - ? OInfo->Visibility - : Info->Visibility; + auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All + ? OInfo->Visibility + : Info->Visibility; this->Diag(Loc, diag::err_hlsl_resource_range_overlap) << llvm::to_underlying(Info->Class) << Info->LowerBound << /*unbounded=*/(Info->UpperBound == RangeInfo::Unbounded) @@ -1238,7 +1237,7 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, // ResourceRanges in the former case and it will be an ArrayRef to just the // all visiblity ResourceRange in the latter case. ArrayRef<ResourceRange> OverlapRanges = - Info.Visibility == llvm::hlsl::rootsig::ShaderVisibility::All + Info.Visibility == llvm::dxbc::ShaderVisibility::All ? ArrayRef<ResourceRange>{Ranges}.drop_front() : ArrayRef<ResourceRange>{Ranges}.take_front(); diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index 1e46ee35d5d49..8831198e4b9c2 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -127,6 +127,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { } TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { + using llvm::dxbc::DescriptorRangeFlags; const llvm::StringLiteral Source = R"cc( DescriptorTable( CBV(b0), @@ -205,20 +206,27 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, 0u); ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset, DescriptorTableOffsetAppend); + auto ValidDescriptorRangeFlags = + DescriptorRangeFlags::DescriptorsVolatile | + DescriptorRangeFlags::DataVolatile | + DescriptorRangeFlags::DataStaticWhileSetAtExecute | + DescriptorRangeFlags::DataStatic | + DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks; ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, - DescriptorRangeFlags::ValidFlags); + ValidDescriptorRangeFlags); Elem = Elements[4]; ASSERT_TRUE(std::holds_alternative<DescriptorTable>(Elem)); ASSERT_EQ(std::get<DescriptorTable>(Elem).NumClauses, (uint32_t)4); ASSERT_EQ(std::get<DescriptorTable>(Elem).Visibility, - ShaderVisibility::Pixel); + llvm::dxbc::ShaderVisibility::Pixel); // Empty Descriptor Table Elem = Elements[5]; ASSERT_TRUE(std::holds_alternative<DescriptorTable>(Elem)); ASSERT_EQ(std::get<DescriptorTable>(Elem).NumClauses, 0u); - ASSERT_EQ(std::get<DescriptorTable>(Elem).Visibility, ShaderVisibility::All); + ASSERT_EQ(std::get<DescriptorTable>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::All); ASSERT_TRUE(Consumer->isSatisfied()); } @@ -258,19 +266,25 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem)); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u); - ASSERT_EQ(std::get<StaticSampler>(Elem).Filter, SamplerFilter::Anisotropic); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, TextureAddressMode::Wrap); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, TextureAddressMode::Wrap); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, TextureAddressMode::Wrap); + ASSERT_EQ(std::get<StaticSampler>(Elem).Filter, + llvm::dxbc::SamplerFilter::Anisotropic); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, + llvm::dxbc::TextureAddressMode::Wrap); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, + llvm::dxbc::TextureAddressMode::Wrap); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, + llvm::dxbc::TextureAddressMode::Wrap); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f); ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u); - ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc, ComparisonFunc::LessEqual); + ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc, + llvm::dxbc::ComparisonFunc::LessEqual); ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, - StaticBorderColor::OpaqueWhite); + llvm::dxbc::StaticBorderColor::OpaqueWhite); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f); ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 0u); - ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::All); + ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::All); // Check values can be set as expected Elem = Elements[1]; @@ -278,19 +292,24 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u); ASSERT_EQ(std::get<StaticSampler>(Elem).Filter, - SamplerFilter::MaximumMinPointMagLinearMipPoint); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, TextureAddressMode::Mirror); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, TextureAddressMode::Border); - ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, TextureAddressMode::Clamp); + llvm::dxbc::SamplerFilter::MaximumMinPointMagLinearMipPoint); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, + llvm::dxbc::TextureAddressMode::Mirror); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, + llvm::dxbc::TextureAddressMode::Border); + ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, + llvm::dxbc::TextureAddressMode::Clamp); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 230.f); ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u); - ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc, ComparisonFunc::NotEqual); + ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc, + llvm::dxbc::ComparisonFunc::NotEqual); ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor, - StaticBorderColor::OpaqueBlackUint); + llvm::dxbc::StaticBorderColor::OpaqueBlackUint); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f); ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f); ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 4u); - ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, ShaderVisibility::Domain); + ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::Domain); ASSERT_TRUE(Consumer->isSatisfied()); } @@ -403,8 +422,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { RootElement Elem = Elements[0]; ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::Sampler); - ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, - DescriptorRangeFlags::ValidSamplerFlags); + auto ValidSamplerFlags = + llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile; + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidSamplerFlags); ASSERT_TRUE(Consumer->isSatisfied()); } @@ -438,7 +458,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { ASSERT_EQ(std::get<RootConstants>(Elem).Reg.ViewType, RegisterType::BReg); ASSERT_EQ(std::get<RootConstants>(Elem).Reg.Number, 0u); ASSERT_EQ(std::get<RootConstants>(Elem).Space, 0u); - ASSERT_EQ(std::get<RootConstants>(Elem).Visibility, ShaderVisibility::All); + ASSERT_EQ(std::get<RootConstants>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::All); Elem = Elements[1]; ASSERT_TRUE(std::holds_alternative<RootConstants>(Elem)); @@ -446,12 +467,14 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { ASSERT_EQ(std::get<RootConstants>(Elem).Reg.ViewType, RegisterType::BReg); ASSERT_EQ(std::get<RootConstants>(Elem).Reg.Number, 42u); ASSERT_EQ(std::get<RootConstants>(Elem).Space, 3u); - ASSERT_EQ(std::get<RootConstants>(Elem).Visibility, ShaderVisibility::Hull); + ASSERT_EQ(std::get<RootConstants>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::Hull); ASSERT_TRUE(Consumer->isSatisfied()); } TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { + using llvm::dxbc::RootFlags; const llvm::StringLiteral Source = R"cc( RootFlags(), RootFlags(0), @@ -496,12 +519,25 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { Elem = Elements[2]; ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem)); - ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::ValidFlags); + auto ValidRootFlags = RootFlags::AllowInputAssemblerInputLayout | + RootFlags::DenyVertexShaderRootAccess | + RootFlags::DenyHullShaderRootAccess | + RootFlags::DenyDomainShaderRootAccess | + RootFlags::DenyGeometryShaderRootAccess | + RootFlags::DenyPixelShaderRootAccess | + RootFlags::AllowStreamOutput | + RootFlags::LocalRootSignature | + RootFlags::DenyAmplificationShaderRootAccess | + RootFlags::DenyMeshShaderRootAccess | + RootFlags::CBVSRVUAVHeapDirectlyIndexed | + RootFlags::SamplerHeapDirectlyIndexed; + ASSERT_EQ(std::get<RootFlags>(Elem), ValidRootFlags); ASSERT_TRUE(Consumer->isSatisfied()); } TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { + using llvm::dxbc::RootDescriptorFlags; const llvm::StringLiteral Source = R"cc( CBV(b0), SRV(space = 4, t42, visibility = SHADER_VISIBILITY_GEOMETRY, @@ -532,7 +568,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::BReg); ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 0u); ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u); - ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, ShaderVisibility::All); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::All); ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, RootDescriptorFlags::DataStaticWhileSetAtExecute); @@ -543,9 +580,12 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 42u); ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 4u); ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, - ShaderVisibility::Geometry); - ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, - RootDescriptorFlags::ValidFlags); + llvm::dxbc::ShaderVisibility::Geometry); + auto ValidRootDescriptorFlags = + RootDescriptorFlags::DataVolatile | + RootDescriptorFlags::DataStaticWhileSetAtExecute | + RootDescriptorFlags::DataStatic; + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, ValidRootDescriptorFlags); Elem = Elements[2]; ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); @@ -553,7 +593,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::UReg); ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 34893247u); ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u); - ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, ShaderVisibility::Hull); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::Hull); ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, RootDescriptorFlags::DataVolatile); ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, @@ -564,7 +605,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::BReg); ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 0u); ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u); - ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, ShaderVisibility::All); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility, + llvm::dxbc::ShaderVisibility::All); ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, RootDescriptorFlags::None); ASSERT_TRUE(Consumer->isSatisfied()); diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h index 45170f550faf1..89abca02efefa 100644 --- a/llvm/include/llvm/BinaryFormat/DXContainer.h +++ b/llvm/include/llvm/BinaryFormat/DXContainer.h @@ -157,23 +157,33 @@ enum class FeatureFlags : uint64_t { static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63, "Shader flag bits exceed enum size."); -#define ROOT_ELEMENT_FLAG(Num, Val) Val = Num, -enum class RootElementFlag : uint32_t { +#define ROOT_SIGNATURE_FLAG(Num, Val) Val = Num, +enum class RootFlags : uint32_t { #include "DXContainerConstants.def" + + LLVM_MARK_AS_BITMASK_ENUM(SamplerHeapDirectlyIndexed) }; -#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = Num, -enum class RootDescriptorFlag : uint32_t { +LLVM_ABI ArrayRef<EnumEntry<RootFlags>> getRootFlags(); + +#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) Enum = Num, +enum class RootDescriptorFlags : uint32_t { #include "DXContainerConstants.def" + + LLVM_MARK_AS_BITMASK_ENUM(DataStatic) }; -#define DESCRIPTOR_RANGE_FLAG(Num, Val) Val = Num, -enum class DescriptorRangeFlag : uint32_t { +LLVM_ABI ArrayRef<EnumEntry<RootDescriptorFlags>> getRootDescriptorFlags(); + +#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) Enum = Num, +enum class DescriptorRangeFlags : uint32_t { #include "DXContainerConstants.def" - LLVM_MARK_AS_BITMASK_ENUM(DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS) + LLVM_MARK_AS_BITMASK_ENUM(DescriptorsStaticKeepingBufferBoundsChecks) }; +LLVM_ABI ArrayRef<EnumEntry<DescriptorRangeFlags>> getDescriptorRangeFlags(); + #define ROOT_PARAMETER(Val, Enum) Enum = Val, enum class RootParameterType : uint32_t { #include "DXContainerConstants.def" @@ -215,26 +225,34 @@ inline bool isValidShaderVisibility(uint32_t V) { return false; } -#define STATIC_SAMPLER_FILTER(Val, Enum) Enum = Val, -enum class StaticSamplerFilter : uint32_t { +#define FILTER(Val, Enum) Enum = Val, +enum class SamplerFilter : uint32_t { #include "DXContainerConstants.def" }; +LLVM_ABI ArrayRef<EnumEntry<SamplerFilter>> getSamplerFilters(); + #define TEXTURE_ADDRESS_MODE(Val, Enum) Enum = Val, enum class TextureAddressMode : uint32_t { #include "DXContainerConstants.def" }; -#define COMPARISON_FUNCTION(Val, Enum) Enum = Val, -enum class SamplersComparisonFunction : uint32_t { +LLVM_ABI ArrayRef<EnumEntry<TextureAddressMode>> getTextureAddressModes(); + +#define COMPARISON_FUNC(Val, Enum) Enum = Val, +enum class ComparisonFunc : uint32_t { #include "DXContainerConstants.def" }; +LLVM_ABI ArrayRef<EnumEntry<ComparisonFunc>> getComparisonFuncs(); + #define STATIC_BORDER_COLOR(Val, Enum) Enum = Val, -enum class SamplersBorderColor : uint32_t { +enum class StaticBorderColor : uint32_t { #include "DXContainerConstants.def" }; +LLVM_ABI ArrayRef<EnumEntry<StaticBorderColor>> getStaticBorderColors(); + LLVM_ABI PartType parsePartType(StringRef S); struct VertexPSVInfo { diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def index a281256a44ae0..8730820dd8b06 100644 --- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def +++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def @@ -55,47 +55,52 @@ SHADER_FEATURE_FLAG(33, 39, NextUnusedBit, "Next reserved shader flag bit (not a #undef SHADER_FEATURE_FLAG #endif // SHADER_FEATURE_FLAG - -// ROOT_ELEMENT_FLAG(bit offset for the flag, name). -#ifdef ROOT_ELEMENT_FLAG - -ROOT_ELEMENT_FLAG(0, NONE) -ROOT_ELEMENT_FLAG(0x1, AllowInputAssemblerInputLayout) -ROOT_ELEMENT_FLAG(0x2, DenyVertexShaderRootAccess) -ROOT_ELEMENT_FLAG(0x4, DenyHullShaderRootAccess) -ROOT_ELEMENT_FLAG(0x8, DenyDomainShaderRootAccess) -ROOT_ELEMENT_FLAG(0x10, DenyGeometryShaderRootAccess) -ROOT_ELEMENT_FLAG(0x20, DenyPixelShaderRootAccess) -ROOT_ELEMENT_FLAG(0x40, AllowStreamOutput) -ROOT_ELEMENT_FLAG(0x80, LocalRootSignature) -ROOT_ELEMENT_FLAG(0x100, DenyAmplificationShaderRootAccess) -ROOT_ELEMENT_FLAG(0x200, DenyMeshShaderRootAccess) -ROOT_ELEMENT_FLAG(0x400, CBVSRVUAVHeapDirectlyIndexed) -ROOT_ELEMENT_FLAG(0x800, SamplerHeapDirectlyIndexed) -#undef ROOT_ELEMENT_FLAG -#endif // ROOT_ELEMENT_FLAG - +// Below is the definition of root signature enumerations and flags. The +// definitions of all values here correspond to their description in the +// d3d12.h header and are carried over from their values in DXC. For reference: +// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ + +// ROOT_SIGNATURE_FLAG(flag value, name). +#ifdef ROOT_SIGNATURE_FLAG + +ROOT_SIGNATURE_FLAG(0, None) +ROOT_SIGNATURE_FLAG(0x1, AllowInputAssemblerInputLayout) +ROOT_SIGNATURE_FLAG(0x2, DenyVertexShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x4, DenyHullShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x8, DenyDomainShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x10, DenyGeometryShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x20, DenyPixelShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x40, AllowStreamOutput) +ROOT_SIGNATURE_FLAG(0x80, LocalRootSignature) +ROOT_SIGNATURE_FLAG(0x100, DenyAmplificationShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x200, DenyMeshShaderRootAccess) +ROOT_SIGNATURE_FLAG(0x400, CBVSRVUAVHeapDirectlyIndexed) +ROOT_SIGNATURE_FLAG(0x800, SamplerHeapDirectlyIndexed) + +#undef ROOT_SIGNATURE_FLAG +#endif // ROOT_SIGNATURE_FLAG -// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name). +// ROOT_DESCRIPTOR_FLAG(flag value, name, flag). #ifdef ROOT_DESCRIPTOR_FLAG -ROOT_DESCRIPTOR_FLAG(0, NONE) -ROOT_DESCRIPTOR_FLAG(0x2, DATA_VOLATILE) -ROOT_DESCRIPTOR_FLAG(0x4, DATA_STATIC_WHILE_SET_AT_EXECUTE) -ROOT_DESCRIPTOR_FLAG(0x8, DATA_STATIC) +ROOT_DESCRIPTOR_FLAG(0, None, NONE) +ROOT_DESCRIPTOR_FLAG(0x2, DataVolatile, DATA_VOLATILE) +ROOT_DESCRIPTOR_FLAG(0x4, DataStaticWhileSetAtExecute, DATA_STATIC_WHILE_SET_AT_EXECUTE) +ROOT_DESCRIPTOR_FLAG(0x8, DataStatic, DATA_STATIC) + #undef ROOT_DESCRIPTOR_FLAG #endif // ROOT_DESCRIPTOR_FLAG - -// DESCRIPTOR_RANGE_FLAG(bit offset for the flag, name). +// DESCRIPTOR_RANGE_FLAG(flag value, name, flag). #ifdef DESCRIPTOR_RANGE_FLAG -DESCRIPTOR_RANGE_FLAG(0, NONE) -DESCRIPTOR_RANGE_FLAG(0x1, DESCRIPTORS_VOLATILE) -DESCRIPTOR_RANGE_FLAG(0x2, DATA_VOLATILE) -DESCRIPTOR_RANGE_FLAG(0x4, DATA_STATIC_WHILE_SET_AT_EXECUTE) -DESCRIPTOR_RANGE_FLAG(0x8, DATA_STATIC) -DESCRIPTOR_RANGE_FLAG(0x10000, DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS) +DESCRIPTOR_RANGE_FLAG(0, None, NONE) +DESCRIPTOR_RANGE_FLAG(0x1, DescriptorsVolatile, DESCRIPTORS_VOLATILE) +DESCRIPTOR_RANGE_FLAG(0x2, DataVolatile, DATA_VOLATILE) +DESCRIPTOR_RANGE_FLAG(0x4, DataStaticWhileSetAtExecute, DATA_STATIC_WHILE_SET_AT_EXECUTE) +DESCRIPTOR_RANGE_FLAG(0x8, DataStatic, DATA_STATIC) +DESCRIPTOR_RANGE_FLAG(0x10000, DescriptorsStaticKeepingBufferBoundsChecks, DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS) + #undef DESCRIPTOR_RANGE_FLAG #endif // DESCRIPTOR_RANGE_FLAG @@ -119,6 +124,7 @@ ROOT_PARAMETER(4, UAV) #undef ROOT_PARAMETER #endif // ROOT_PARAMETER +// SHADER_VISIBILITY(value, enum). #ifdef SHADER_VISIBILITY SHADER_VISIBILITY(0, All) @@ -129,79 +135,89 @@ SHADER_VISIBILITY(4, Geometry) SHADER_VISIBILITY(5, Pixel) SHADER_VISIBILITY(6, Amplification) SHADER_VISIBILITY(7, Mesh) + #undef SHADER_VISIBILITY #endif // SHADER_VISIBILITY -#ifdef STATIC_SAMPLER_FILTER - -STATIC_SAMPLER_FILTER(0, MIN_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x1, MIN_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x4, MIN_POINT_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x5, MIN_POINT_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x10, MIN_LINEAR_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x11, MIN_LINEAR_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x14, MIN_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x15, MIN_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x55, ANISOTROPIC) -STATIC_SAMPLER_FILTER(0x80, COMPARISON_MIN_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x81, COMPARISON_MIN_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x84, COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x85, COMPARISON_MIN_POINT_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x90, COMPARISON_MIN_LINEAR_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x91, COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x94, COMPARISON_MIN_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x95, COMPARISON_MIN_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0xd5, COMPARISON_ANISOTROPIC) -STATIC_SAMPLER_FILTER(0x100, MINIMUM_MIN_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x101, MINIMUM_MIN_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x104, MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x105, MINIMUM_MIN_POINT_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x110, MINIMUM_MIN_LINEAR_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x111, MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x114, MINIMUM_MIN_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x115, MINIMUM_MIN_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x155, MINIMUM_ANISOTROPIC) -STATIC_SAMPLER_FILTER(0x180, MAXIMUM_MIN_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x181, MAXIMUM_MIN_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x184, MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x185, MAXIMUM_MIN_POINT_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x190, MAXIMUM_MIN_LINEAR_MAG_MIP_POINT) -STATIC_SAMPLER_FILTER(0x191, MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x194, MAXIMUM_MIN_MAG_LINEAR_MIP_POINT) -STATIC_SAMPLER_FILTER(0x195, MAXIMUM_MIN_MAG_MIP_LINEAR) -STATIC_SAMPLER_FILTER(0x1d5, MAXIMUM_ANISOTROPIC) -#undef STATIC_SAMPLER_FILTER -#endif // STATIC_SAMPLER_FILTER - +// FILTER(value, enum). +#ifdef FILTER + +FILTER(0, MinMagMipPoint) +FILTER(0x1, MinMagPointMipLinear) +FILTER(0x4, MinPointMagLinearMipPoint) +FILTER(0x5, MinPointMagMipLinear) +FILTER(0x10, MinLinearMagMipPoint) +FILTER(0x11, MinLinearMagPointMipLinear) +FILTER(0x14, MinMagLinearMipPoint) +FILTER(0x15, MinMagMipLinear) +FILTER(0x55, Anisotropic) +FILTER(0x80, ComparisonMinMagMipPoint) +FILTER(0x81, ComparisonMinMagPointMipLinear) +FILTER(0x84, ComparisonMinPointMagLinearMipPoint) +FILTER(0x85, ComparisonMinPointMagMipLinear) +FILTER(0x90, ComparisonMinLinearMagMipPoint) +FILTER(0x91, ComparisonMinLinearMagPointMipLinear) +FILTER(0x94, ComparisonMinMagLinearMipPoint) +FILTER(0x95, ComparisonMinMagMipLinear) +FILTER(0xd5, ComparisonAnisotropic) +FILTER(0x100, MinimumMinMagMipPoint) +FILTER(0x101, MinimumMinMagPointMipLinear) +FILTER(0x104, MinimumMinPointMagLinearMipPoint) +FILTER(0x105, MinimumMinPointMagMipLinear) +FILTER(0x110, MinimumMinLinearMagMipPoint) +FILTER(0x111, MinimumMinLinearMagPointMipLinear) +FILTER(0x114, MinimumMinMagLinearMipPoint) +FILTER(0x115, MinimumMinMagMipLinear) +FILTER(0x155, MinimumAnisotropic) +FILTER(0x180, MaximumMinMagMipPoint) +FILTER(0x181, MaximumMinMagPointMipLinear) +FILTER(0x184, MaximumMinPointMagLinearMipPoint) +FILTER(0x185, MaximumMinPointMagMipLinear) +FILTER(0x190, MaximumMinLinearMagMipPoint) +FILTER(0x191, MaximumMinLinearMagPointMipLinear) +FILTER(0x194, MaximumMinMagLinearMipPoint) +FILTER(0x195, MaximumMinMagMipLinear) +FILTER(0x1d5, MaximumAnisotropic) + +#undef FILTER +#endif // FILTER + +// TEXTURE_ADDRESS_MODE(value, enum). #ifdef TEXTURE_ADDRESS_MODE -TEXTURE_ADDRESS_MODE( 1, Wrap) -TEXTURE_ADDRESS_MODE( 2, Mirror) -TEXTURE_ADDRESS_MODE( 3, Clamp) -TEXTURE_ADDRESS_MODE( 4, Border) -TEXTURE_ADDRESS_MODE( 5, MirrorOnce) +TEXTURE_ADDRESS_MODE(1, Wrap) +TEXTURE_ADDRESS_MODE(2, Mirror) +TEXTURE_ADDRESS_MODE(3, Clamp) +TEXTURE_ADDRESS_MODE(4, Border) +TEXTURE_ADDRESS_MODE(5, MirrorOnce) + #undef TEXTURE_ADDRESS_MODE #endif // TEXTURE_ADDRESS_MODE -#ifdef COMPARISON_FUNCTION +// COMPARISON_FUNC(value, enum). +#ifdef COMPARISON_FUNC + +COMPARISON_FUNC(1, Never) +COMPARISON_FUNC(2, Less) +COMPARISON_FUNC(3, Equal) +COMPARISON_FUNC(4, LessEqual) +COMPARISON_FUNC(5, Greater) +COMPARISON_FUNC(6, NotEqual) +COMPARISON_FUNC(7, GreaterEqual) +COMPARISON_FUNC(8, Always) -COMPARISON_FUNCTION( 1, Never) -COMPARISON_FUNCTION( 2, Less) -COMPARISON_FUNCTION( 3, Equal) -COMPARISON_FUNCTION( 4, LessEqual) -COMPARISON_FUNCTION( 5, Greater) -COMPARISON_FUNCTION( 6, NotEqual) -COMPARISON_FUNCTION( 7, GreaterEqual) -COMPARISON_FUNCTION( 8, Always) -#undef COMPARISON_FUNCTION -#endif // COMPARISON_FUNCTION +#undef COMPARISON_FUNC +#endif // COMPARISON_FUNC +// STATIC_BORDER_COLOR(value, enum). #ifdef STATIC_BORDER_COLOR -STATIC_BORDER_COLOR( 0, TransparentBlack) -STATIC_BORDER_COLOR( 1, OpaqueBlack) -STATIC_BORDER_COLOR( 2, OpaqueWhite) -STATIC_BORDER_COLOR( 3, OpaqueBlackUint) -STATIC_BORDER_COLOR( 4, OpaqueWhiteUint) + +STATIC_BORDER_COLOR(0, TransparentBlack) +STATIC_BORDER_COLOR(1, OpaqueBlack) +STATIC_BORDER_COLOR(2, OpaqueWhite) +STATIC_BORDER_COLOR(3, OpaqueBlackUint) +STATIC_BORDER_COLOR(4, OpaqueWhiteUint) + #undef STATIC_BORDER_COLOR #endif // STATIC_BORDER_COLOR diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h index 9dfbd3cb68928..3e959829a20bf 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h @@ -14,6 +14,7 @@ #ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H #define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H +#include "llvm/BinaryFormat/DXContainer.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DXILABI.h" #include <limits> @@ -23,126 +24,6 @@ namespace llvm { namespace hlsl { namespace rootsig { -// Definition of the various enumerations and flags. The definitions of all -// values here correspond to their description in the d3d12.h header and are -// carried over from their values in DXC. For reference: -// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ - -enum class RootFlags : uint32_t { - None = 0, - AllowInputAssemblerInputLayout = 0x1, - DenyVertexShaderRootAccess = 0x2, - DenyHullShaderRootAccess = 0x4, - DenyDomainShaderRootAccess = 0x8, - DenyGeometryShaderRootAccess = 0x10, - DenyPixelShaderRootAccess = 0x20, - AllowStreamOutput = 0x40, - LocalRootSignature = 0x80, - DenyAmplificationShaderRootAccess = 0x100, - DenyMeshShaderRootAccess = 0x200, - CBVSRVUAVHeapDirectlyIndexed = 0x400, - SamplerHeapDirectlyIndexed = 0x800, - ValidFlags = 0x00000fff -}; - -enum class RootDescriptorFlags : unsigned { - None = 0, - DataVolatile = 0x2, - DataStaticWhileSetAtExecute = 0x4, - DataStatic = 0x8, - ValidFlags = 0xe, -}; - -enum class DescriptorRangeFlags : unsigned { - None = 0, - DescriptorsVolatile = 0x1, - DataVolatile = 0x2, - DataStaticWhileSetAtExecute = 0x4, - DataStatic = 0x8, - DescriptorsStaticKeepingBufferBoundsChecks = 0x10000, - ValidFlags = 0x1000f, - ValidSamplerFlags = DescriptorsVolatile, -}; - -enum class ShaderVisibility { - All = 0, - Vertex = 1, - Hull = 2, - Domain = 3, - Geometry = 4, - Pixel = 5, - Amplification = 6, - Mesh = 7, -}; - -// D3D12_FILTER enumeration: -// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter -enum class SamplerFilter { - MinMagMipPoint = 0, - MinMagPointMipLinear = 0x1, - MinPointMagLinearMipPoint = 0x4, - MinPointMagMipLinear = 0x5, - MinLinearMagMipPoint = 0x10, - MinLinearMagPointMipLinear = 0x11, - MinMagLinearMipPoint = 0x14, - MinMagMipLinear = 0x15, - Anisotropic = 0x55, - ComparisonMinMagMipPoint = 0x80, - ComparisonMinMagPointMipLinear = 0x81, - ComparisonMinPointMagLinearMipPoint = 0x84, - ComparisonMinPointMagMipLinear = 0x85, - ComparisonMinLinearMagMipPoint = 0x90, - ComparisonMinLinearMagPointMipLinear = 0x91, - ComparisonMinMagLinearMipPoint = 0x94, - ComparisonMinMagMipLinear = 0x95, - ComparisonAnisotropic = 0xd5, - MinimumMinMagMipPoint = 0x100, - MinimumMinMagPointMipLinear = 0x101, - MinimumMinPointMagLinearMipPoint = 0x104, - MinimumMinPointMagMipLinear = 0x105, - MinimumMinLinearMagMipPoint = 0x110, - MinimumMinLinearMagPointMipLinear = 0x111, - MinimumMinMagLinearMipPoint = 0x114, - MinimumMinMagMipLinear = 0x115, - MinimumAnisotropic = 0x155, - MaximumMinMagMipPoint = 0x180, - MaximumMinMagPointMipLinear = 0x181, - MaximumMinPointMagLinearMipPoint = 0x184, - MaximumMinPointMagMipLinear = 0x185, - MaximumMinLinearMagMipPoint = 0x190, - MaximumMinLinearMagPointMipLinear = 0x191, - MaximumMinMagLinearMipPoint = 0x194, - MaximumMinMagMipLinear = 0x195, - MaximumAnisotropic = 0x1d5 -}; - -enum class TextureAddressMode { - Wrap = 1, - Mirror = 2, - Clamp = 3, - Border = 4, - MirrorOnce = 5 -}; - -enum class ComparisonFunc : unsigned { - Never = 1, - Less = 2, - Equal = 3, - LessEqual = 4, - Greater = 5, - NotEqual = 6, - GreaterEqual = 7, - Always = 8 -}; - -enum class StaticBorderColor { - TransparentBlack = 0, - OpaqueBlack = 1, - OpaqueWhite = 2, - OpaqueBlackUint = 3, - OpaqueWhiteUint = 4 -}; - // Definitions of the in-memory data layout structures // Models the diff erent registers: bReg | tReg | uReg | sReg @@ -157,7 +38,7 @@ struct RootConstants { uint32_t Num32BitConstants; Register Reg; uint32_t Space = 0; - ShaderVisibility Visibility = ShaderVisibility::All; + dxbc::ShaderVisibility Visibility = dxbc::ShaderVisibility::All; }; enum class DescriptorType : uint8_t { SRV = 0, UAV, CBuffer }; @@ -166,17 +47,17 @@ struct RootDescriptor { DescriptorType Type; Register Reg; uint32_t Space = 0; - ShaderVisibility Visibility = ShaderVisibility::All; - RootDescriptorFlags Flags; + dxbc::ShaderVisibility Visibility = dxbc::ShaderVisibility::All; + dxbc::RootDescriptorFlags Flags; void setDefaultFlags() { switch (Type) { case DescriptorType::CBuffer: case DescriptorType::SRV: - Flags = RootDescriptorFlags::DataStaticWhileSetAtExecute; + Flags = dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute; break; case DescriptorType::UAV: - Flags = RootDescriptorFlags::DataVolatile; + Flags = dxbc::RootDescriptorFlags::DataVolatile; break; } } @@ -184,7 +65,7 @@ struct RootDescriptor { // Models the end of a descriptor table and stores its visibility struct DescriptorTable { - ShaderVisibility Visibility = ShaderVisibility::All; + dxbc::ShaderVisibility Visibility = dxbc::ShaderVisibility::All; // Denotes that the previous NumClauses in the RootElement array // are the clauses in the table. uint32_t NumClauses = 0; @@ -200,19 +81,19 @@ struct DescriptorTableClause { uint32_t NumDescriptors = 1; uint32_t Space = 0; uint32_t Offset = DescriptorTableOffsetAppend; - DescriptorRangeFlags Flags; + dxbc::DescriptorRangeFlags Flags; void setDefaultFlags() { switch (Type) { case ClauseType::CBuffer: case ClauseType::SRV: - Flags = DescriptorRangeFlags::DataStaticWhileSetAtExecute; + Flags = dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute; break; case ClauseType::UAV: - Flags = DescriptorRangeFlags::DataVolatile; + Flags = dxbc::DescriptorRangeFlags::DataVolatile; break; case ClauseType::Sampler: - Flags = DescriptorRangeFlags::None; + Flags = dxbc::DescriptorRangeFlags::None; break; } } @@ -220,18 +101,18 @@ struct DescriptorTableClause { struct StaticSampler { Register Reg; - SamplerFilter Filter = SamplerFilter::Anisotropic; - TextureAddressMode AddressU = TextureAddressMode::Wrap; - TextureAddressMode AddressV = TextureAddressMode::Wrap; - TextureAddressMode AddressW = TextureAddressMode::Wrap; + dxbc::SamplerFilter Filter = dxbc::SamplerFilter::Anisotropic; + dxbc::TextureAddressMode AddressU = dxbc::TextureAddressMode::Wrap; + dxbc::TextureAddressMode AddressV = dxbc::TextureAddressMode::Wrap; + dxbc::TextureAddressMode AddressW = dxbc::TextureAddressMode::Wrap; float MipLODBias = 0.f; uint32_t MaxAnisotropy = 16; - ComparisonFunc CompFunc = ComparisonFunc::LessEqual; - StaticBorderColor BorderColor = StaticBorderColor::OpaqueWhite; + dxbc::ComparisonFunc CompFunc = dxbc::ComparisonFunc::LessEqual; + dxbc::StaticBorderColor BorderColor = dxbc::StaticBorderColor::OpaqueWhite; float MinLOD = 0.f; float MaxLOD = std::numeric_limits<float>::max(); uint32_t Space = 0; - ShaderVisibility Visibility = ShaderVisibility::All; + dxbc::ShaderVisibility Visibility = dxbc::ShaderVisibility::All; }; /// Models RootElement : RootFlags | RootConstants | RootParam @@ -251,8 +132,8 @@ struct StaticSampler { /// RootElements in the array, and it holds a data member for the Visibility /// parameter. using RootElement = - std::variant<RootFlags, RootConstants, RootDescriptor, DescriptorTable, - DescriptorTableClause, StaticSampler>; + std::variant<dxbc::RootFlags, RootConstants, RootDescriptor, + DescriptorTable, DescriptorTableClause, StaticSampler>; } // namespace rootsig } // namespace hlsl diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h index 43c8805ce06b6..ed6e5e5447a61 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignatureUtils.h @@ -28,7 +28,7 @@ class Metadata; namespace hlsl { namespace rootsig { -LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags); +LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags); LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootConstants &Constants); @@ -61,7 +61,7 @@ class MetadataBuilder { private: /// Define the various builders for the diff erent metadata types - MDNode *BuildRootFlags(const RootFlags &Flags); + MDNode *BuildRootFlags(const dxbc::RootFlags &Flags); MDNode *BuildRootConstants(const RootConstants &Constants); MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor); MDNode *BuildDescriptorTable(const DescriptorTable &Table); @@ -83,7 +83,7 @@ struct RangeInfo { // Information retained for diagnostics llvm::dxil::ResourceClass Class; uint32_t Space; - ShaderVisibility Visibility; + dxbc::ShaderVisibility Visibility; }; class ResourceRange { diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h index c235112dacf7c..7e0a4c6b07039 100644 --- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h +++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h @@ -87,7 +87,7 @@ struct RootDescriptorYaml { LLVM_ABI uint32_t getEncodedFlags() const; -#define ROOT_DESCRIPTOR_FLAG(Num, Val) bool Val = false; +#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) bool Enum = false; #include "llvm/BinaryFormat/DXContainerConstants.def" }; @@ -100,7 +100,7 @@ struct DescriptorRangeYaml { LLVM_ABI uint32_t getEncodedFlags() const; -#define DESCRIPTOR_RANGE_FLAG(Num, Val) bool Val = false; +#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) bool Enum = false; #include "llvm/BinaryFormat/DXContainerConstants.def" }; @@ -165,16 +165,16 @@ struct RootParameterYamlDesc { }; struct StaticSamplerYamlDesc { - uint32_t Filter = llvm::to_underlying(dxbc::StaticSamplerFilter::ANISOTROPIC); + uint32_t Filter = llvm::to_underlying(dxbc::SamplerFilter::Anisotropic); uint32_t AddressU = llvm::to_underlying(dxbc::TextureAddressMode::Wrap); uint32_t AddressV = llvm::to_underlying(dxbc::TextureAddressMode::Wrap); uint32_t AddressW = llvm::to_underlying(dxbc::TextureAddressMode::Wrap); float MipLODBias = 0.f; uint32_t MaxAnisotropy = 16u; uint32_t ComparisonFunc = - llvm::to_underlying(dxbc::SamplersComparisonFunction::LessEqual); + llvm::to_underlying(dxbc::ComparisonFunc::LessEqual); uint32_t BorderColor = - llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueWhite); + llvm::to_underlying(dxbc::StaticBorderColor::OpaqueWhite); float MinLOD = 0.f; float MaxLOD = std::numeric_limits<float>::max(); uint32_t ShaderRegister; @@ -203,7 +203,7 @@ struct RootSignatureYamlDesc { LLVM_ABI static llvm::Expected<DXContainerYAML::RootSignatureYamlDesc> create(const object::DirectX::RootSignature &Data); -#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false; +#define ROOT_SIGNATURE_FLAG(Num, Val) bool Val = false; #include "llvm/BinaryFormat/DXContainerConstants.def" }; diff --git a/llvm/lib/BinaryFormat/DXContainer.cpp b/llvm/lib/BinaryFormat/DXContainer.cpp index 8e7b7d313706a..36d10d0b63078 100644 --- a/llvm/lib/BinaryFormat/DXContainer.cpp +++ b/llvm/lib/BinaryFormat/DXContainer.cpp @@ -60,6 +60,35 @@ ArrayRef<EnumEntry<SigComponentType>> dxbc::getSigComponentTypes() { return ArrayRef(SigComponentTypes); } +static const EnumEntry<RootFlags> RootFlagNames[] = { +#define ROOT_SIGNATURE_FLAG(Val, Enum) {#Enum, RootFlags::Enum}, +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<RootFlags>> dxbc::getRootFlags() { + return ArrayRef(RootFlagNames); +} + +static const EnumEntry<RootDescriptorFlags> RootDescriptorFlagNames[] = { +#define ROOT_DESCRIPTOR_FLAG(Val, Enum, Flag) \ + {#Enum, RootDescriptorFlags::Enum}, +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<RootDescriptorFlags>> dxbc::getRootDescriptorFlags() { + return ArrayRef(RootDescriptorFlagNames); +} + +static const EnumEntry<DescriptorRangeFlags> DescriptorRangeFlagNames[] = { +#define DESCRIPTOR_RANGE_FLAG(Val, Enum, Flag) \ + {#Enum, DescriptorRangeFlags::Enum}, +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<DescriptorRangeFlags>> dxbc::getDescriptorRangeFlags() { + return ArrayRef(DescriptorRangeFlagNames); +} + #define SHADER_VISIBILITY(Val, Enum) {#Enum, ShaderVisibility::Enum}, static const EnumEntry<ShaderVisibility> ShaderVisibilityValues[] = { @@ -70,6 +99,46 @@ ArrayRef<EnumEntry<ShaderVisibility>> dxbc::getShaderVisibility() { return ArrayRef(ShaderVisibilityValues); } +#define FILTER(Val, Enum) {#Enum, SamplerFilter::Enum}, + +static const EnumEntry<SamplerFilter> SamplerFilterNames[] = { +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<SamplerFilter>> dxbc::getSamplerFilters() { + return ArrayRef(SamplerFilterNames); +} + +#define TEXTURE_ADDRESS_MODE(Val, Enum) {#Enum, TextureAddressMode::Enum}, + +static const EnumEntry<TextureAddressMode> TextureAddressModeNames[] = { +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<TextureAddressMode>> dxbc::getTextureAddressModes() { + return ArrayRef(TextureAddressModeNames); +} + +#define COMPARISON_FUNC(Val, Enum) {#Enum, ComparisonFunc::Enum}, + +static const EnumEntry<ComparisonFunc> ComparisonFuncNames[] = { +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<ComparisonFunc>> dxbc::getComparisonFuncs() { + return ArrayRef(ComparisonFuncNames); +} + +#define STATIC_BORDER_COLOR(Val, Enum) {#Enum, StaticBorderColor::Enum}, + +static const EnumEntry<StaticBorderColor> StaticBorderColorValues[] = { +#include "llvm/BinaryFormat/DXContainerConstants.def" +}; + +ArrayRef<EnumEntry<StaticBorderColor>> dxbc::getStaticBorderColors() { + return ArrayRef(StaticBorderColorValues); +} + #define ROOT_PARAMETER(Val, Enum) {#Enum, RootParameterType::Enum}, static const EnumEntry<RootParameterType> RootParameterTypes[] = { diff --git a/llvm/lib/Frontend/HLSL/CMakeLists.txt b/llvm/lib/Frontend/HLSL/CMakeLists.txt index dfebe354807bf..8928144730477 100644 --- a/llvm/lib/Frontend/HLSL/CMakeLists.txt +++ b/llvm/lib/Frontend/HLSL/CMakeLists.txt @@ -11,6 +11,7 @@ add_llvm_component_library(LLVMFrontendHLSL intrinsics_gen LINK_COMPONENTS + BinaryFormat Core Support ) diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp index 22a761ba3b135..67f512008b069 100644 --- a/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp +++ b/llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp @@ -80,123 +80,37 @@ static raw_ostream &operator<<(raw_ostream &OS, const Register &Reg) { return OS; } -static const EnumEntry<ShaderVisibility> VisibilityNames[] = { - {"All", ShaderVisibility::All}, - {"Vertex", ShaderVisibility::Vertex}, - {"Hull", ShaderVisibility::Hull}, - {"Domain", ShaderVisibility::Domain}, - {"Geometry", ShaderVisibility::Geometry}, - {"Pixel", ShaderVisibility::Pixel}, - {"Amplification", ShaderVisibility::Amplification}, - {"Mesh", ShaderVisibility::Mesh}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const ShaderVisibility &Visibility) { - printEnum(OS, Visibility, ArrayRef(VisibilityNames)); + const llvm::dxbc::ShaderVisibility &Visibility) { + printEnum(OS, Visibility, dxbc::getShaderVisibility()); return OS; } -static const EnumEntry<SamplerFilter> SamplerFilterNames[] = { - {"MinMagMipPoint", SamplerFilter::MinMagMipPoint}, - {"MinMagPointMipLinear", SamplerFilter::MinMagPointMipLinear}, - {"MinPointMagLinearMipPoint", SamplerFilter::MinPointMagLinearMipPoint}, - {"MinPointMagMipLinear", SamplerFilter::MinPointMagMipLinear}, - {"MinLinearMagMipPoint", SamplerFilter::MinLinearMagMipPoint}, - {"MinLinearMagPointMipLinear", SamplerFilter::MinLinearMagPointMipLinear}, - {"MinMagLinearMipPoint", SamplerFilter::MinMagLinearMipPoint}, - {"MinMagMipLinear", SamplerFilter::MinMagMipLinear}, - {"Anisotropic", SamplerFilter::Anisotropic}, - {"ComparisonMinMagMipPoint", SamplerFilter::ComparisonMinMagMipPoint}, - {"ComparisonMinMagPointMipLinear", - SamplerFilter::ComparisonMinMagPointMipLinear}, - {"ComparisonMinPointMagLinearMipPoint", - SamplerFilter::ComparisonMinPointMagLinearMipPoint}, - {"ComparisonMinPointMagMipLinear", - SamplerFilter::ComparisonMinPointMagMipLinear}, - {"ComparisonMinLinearMagMipPoint", - SamplerFilter::ComparisonMinLinearMagMipPoint}, - {"ComparisonMinLinearMagPointMipLinear", - SamplerFilter::ComparisonMinLinearMagPointMipLinear}, - {"ComparisonMinMagLinearMipPoint", - SamplerFilter::ComparisonMinMagLinearMipPoint}, - {"ComparisonMinMagMipLinear", SamplerFilter::ComparisonMinMagMipLinear}, - {"ComparisonAnisotropic", SamplerFilter::ComparisonAnisotropic}, - {"MinimumMinMagMipPoint", SamplerFilter::MinimumMinMagMipPoint}, - {"MinimumMinMagPointMipLinear", SamplerFilter::MinimumMinMagPointMipLinear}, - {"MinimumMinPointMagLinearMipPoint", - SamplerFilter::MinimumMinPointMagLinearMipPoint}, - {"MinimumMinPointMagMipLinear", SamplerFilter::MinimumMinPointMagMipLinear}, - {"MinimumMinLinearMagMipPoint", SamplerFilter::MinimumMinLinearMagMipPoint}, - {"MinimumMinLinearMagPointMipLinear", - SamplerFilter::MinimumMinLinearMagPointMipLinear}, - {"MinimumMinMagLinearMipPoint", SamplerFilter::MinimumMinMagLinearMipPoint}, - {"MinimumMinMagMipLinear", SamplerFilter::MinimumMinMagMipLinear}, - {"MinimumAnisotropic", SamplerFilter::MinimumAnisotropic}, - {"MaximumMinMagMipPoint", SamplerFilter::MaximumMinMagMipPoint}, - {"MaximumMinMagPointMipLinear", SamplerFilter::MaximumMinMagPointMipLinear}, - {"MaximumMinPointMagLinearMipPoint", - SamplerFilter::MaximumMinPointMagLinearMipPoint}, - {"MaximumMinPointMagMipLinear", SamplerFilter::MaximumMinPointMagMipLinear}, - {"MaximumMinLinearMagMipPoint", SamplerFilter::MaximumMinLinearMagMipPoint}, - {"MaximumMinLinearMagPointMipLinear", - SamplerFilter::MaximumMinLinearMagPointMipLinear}, - {"MaximumMinMagLinearMipPoint", SamplerFilter::MaximumMinMagLinearMipPoint}, - {"MaximumMinMagMipLinear", SamplerFilter::MaximumMinMagMipLinear}, - {"MaximumAnisotropic", SamplerFilter::MaximumAnisotropic}, -}; - -static raw_ostream &operator<<(raw_ostream &OS, const SamplerFilter &Filter) { - printEnum(OS, Filter, ArrayRef(SamplerFilterNames)); +static raw_ostream &operator<<(raw_ostream &OS, + const llvm::dxbc::SamplerFilter &Filter) { + printEnum(OS, Filter, dxbc::getSamplerFilters()); return OS; } -static const EnumEntry<TextureAddressMode> TextureAddressModeNames[] = { - {"Wrap", TextureAddressMode::Wrap}, - {"Mirror", TextureAddressMode::Mirror}, - {"Clamp", TextureAddressMode::Clamp}, - {"Border", TextureAddressMode::Border}, - {"MirrorOnce", TextureAddressMode::MirrorOnce}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const TextureAddressMode &Address) { - printEnum(OS, Address, ArrayRef(TextureAddressModeNames)); + const dxbc::TextureAddressMode &Address) { + printEnum(OS, Address, dxbc::getTextureAddressModes()); return OS; } -static const EnumEntry<ComparisonFunc> ComparisonFuncNames[] = { - {"Never", ComparisonFunc::Never}, - {"Less", ComparisonFunc::Less}, - {"Equal", ComparisonFunc::Equal}, - {"LessEqual", ComparisonFunc::LessEqual}, - {"Greater", ComparisonFunc::Greater}, - {"NotEqual", ComparisonFunc::NotEqual}, - {"GreaterEqual", ComparisonFunc::GreaterEqual}, - {"Always", ComparisonFunc::Always}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const ComparisonFunc &CompFunc) { - printEnum(OS, CompFunc, ArrayRef(ComparisonFuncNames)); + const dxbc::ComparisonFunc &CompFunc) { + printEnum(OS, CompFunc, dxbc::getComparisonFuncs()); return OS; } -static const EnumEntry<StaticBorderColor> StaticBorderColorNames[] = { - {"TransparentBlack", StaticBorderColor::TransparentBlack}, - {"OpaqueBlack", StaticBorderColor::OpaqueBlack}, - {"OpaqueWhite", StaticBorderColor::OpaqueWhite}, - {"OpaqueBlackUint", StaticBorderColor::OpaqueBlackUint}, - {"OpaqueWhiteUint", StaticBorderColor::OpaqueWhiteUint}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const StaticBorderColor &BorderColor) { - printEnum(OS, BorderColor, ArrayRef(StaticBorderColorNames)); + const dxbc::StaticBorderColor &BorderColor) { + printEnum(OS, BorderColor, dxbc::getStaticBorderColors()); return OS; } @@ -215,57 +129,23 @@ static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) { return OS; } -static const EnumEntry<RootDescriptorFlags> RootDescriptorFlagNames[] = { - {"DataVolatile", RootDescriptorFlags::DataVolatile}, - {"DataStaticWhileSetAtExecute", - RootDescriptorFlags::DataStaticWhileSetAtExecute}, - {"DataStatic", RootDescriptorFlags::DataStatic}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const RootDescriptorFlags &Flags) { - printFlags(OS, Flags, ArrayRef(RootDescriptorFlagNames)); + const dxbc::RootDescriptorFlags &Flags) { + printFlags(OS, Flags, dxbc::getRootDescriptorFlags()); return OS; } -static const EnumEntry<DescriptorRangeFlags> DescriptorRangeFlagNames[] = { - {"DescriptorsVolatile", DescriptorRangeFlags::DescriptorsVolatile}, - {"DataVolatile", DescriptorRangeFlags::DataVolatile}, - {"DataStaticWhileSetAtExecute", - DescriptorRangeFlags::DataStaticWhileSetAtExecute}, - {"DataStatic", DescriptorRangeFlags::DataStatic}, - {"DescriptorsStaticKeepingBufferBoundsChecks", - DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks}, -}; - static raw_ostream &operator<<(raw_ostream &OS, - const DescriptorRangeFlags &Flags) { - printFlags(OS, Flags, ArrayRef(DescriptorRangeFlagNames)); + const llvm::dxbc::DescriptorRangeFlags &Flags) { + printFlags(OS, Flags, dxbc::getDescriptorRangeFlags()); return OS; } -static const EnumEntry<RootFlags> RootFlagNames[] = { - {"AllowInputAssemblerInputLayout", - RootFlags::AllowInputAssemblerInputLayout}, - {"DenyVertexShaderRootAccess", RootFlags::DenyVertexShaderRootAccess}, - {"DenyHullShaderRootAccess", RootFlags::DenyHullShaderRootAccess}, - {"DenyDomainShaderRootAccess", RootFlags::DenyDomainShaderRootAccess}, - {"DenyGeometryShaderRootAccess", RootFlags::DenyGeometryShaderRootAccess}, - {"DenyPixelShaderRootAccess", RootFlags::DenyPixelShaderRootAccess}, - {"AllowStreamOutput", RootFlags::AllowStreamOutput}, - {"LocalRootSignature", RootFlags::LocalRootSignature}, - {"DenyAmplificationShaderRootAccess", - RootFlags::DenyAmplificationShaderRootAccess}, - {"DenyMeshShaderRootAccess", RootFlags::DenyMeshShaderRootAccess}, - {"CBVSRVUAVHeapDirectlyIndexed", RootFlags::CBVSRVUAVHeapDirectlyIndexed}, - {"SamplerHeapDirectlyIndexed", RootFlags::SamplerHeapDirectlyIndexed}, -}; - -raw_ostream &operator<<(raw_ostream &OS, const RootFlags &Flags) { +raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags) { OS << "RootFlags("; - printFlags(OS, Flags, ArrayRef(RootFlagNames)); + printFlags(OS, Flags, dxbc::getRootFlags()); OS << ")"; return OS; @@ -341,7 +221,7 @@ template <class... Ts> OverloadedVisit(Ts...) -> OverloadedVisit<Ts...>; raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element) { const auto Visitor = OverloadedVisit{ - [&OS](const RootFlags &Flags) { OS << Flags; }, + [&OS](const dxbc::RootFlags &Flags) { OS << Flags; }, [&OS](const RootConstants &Constants) { OS << Constants; }, [&OS](const RootDescriptor &Descriptor) { OS << Descriptor; }, [&OS](const DescriptorTableClause &Clause) { OS << Clause; }, @@ -366,7 +246,7 @@ void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) { MDNode *MetadataBuilder::BuildRootSignature() { const auto Visitor = OverloadedVisit{ - [this](const RootFlags &Flags) -> MDNode * { + [this](const dxbc::RootFlags &Flags) -> MDNode * { return BuildRootFlags(Flags); }, [this](const RootConstants &Constants) -> MDNode * { @@ -396,7 +276,7 @@ MDNode *MetadataBuilder::BuildRootSignature() { return MDNode::get(Ctx, GeneratedMetadata); } -MDNode *MetadataBuilder::BuildRootFlags(const RootFlags &Flags) { +MDNode *MetadataBuilder::BuildRootFlags(const dxbc::RootFlags &Flags) { IRBuilder<> Builder(Ctx); Metadata *Operands[] = { MDString::get(Ctx, "RootFlags"), diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp index f6d0e5227e64a..263f7bdf37bca 100644 --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -63,9 +63,9 @@ readDescriptorRanges(DXContainerYAML::RootParameterHeaderYaml &Header, NewR.RangeType = R.RangeType; if constexpr (std::is_same_v<T, dxbc::RTS0::v2::DescriptorRange>) { // Set all flag fields for v2 -#define DESCRIPTOR_RANGE_FLAG(Num, Val) \ - NewR.Val = \ - (R.Flags & llvm::to_underlying(dxbc::DescriptorRangeFlag::Val)) != 0; +#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \ + NewR.Enum = \ + (R.Flags & llvm::to_underlying(dxbc::DescriptorRangeFlags::Enum)) != 0; #include "llvm/BinaryFormat/DXContainerConstants.def" } TableYaml.Ranges.push_back(NewR); @@ -140,10 +140,10 @@ DXContainerYAML::RootSignatureYamlDesc::create( YamlDescriptor.ShaderRegister = Descriptor.ShaderRegister; YamlDescriptor.RegisterSpace = Descriptor.RegisterSpace; if (Version > 1) { -#define ROOT_DESCRIPTOR_FLAG(Num, Val) \ - YamlDescriptor.Val = \ +#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \ + YamlDescriptor.Enum = \ (Descriptor.Flags & \ - llvm::to_underlying(dxbc::RootDescriptorFlag::Val)) > 0; + llvm::to_underlying(dxbc::RootDescriptorFlags::Enum)) > 0; #include "llvm/BinaryFormat/DXContainerConstants.def" } } else if (auto *DTV = @@ -180,38 +180,37 @@ DXContainerYAML::RootSignatureYamlDesc::create( RootSigDesc.StaticSamplers.push_back(NewS); } -#define ROOT_ELEMENT_FLAG(Num, Val) \ - RootSigDesc.Val = \ - (Flags & llvm::to_underlying(dxbc::RootElementFlag::Val)) > 0; +#define ROOT_SIGNATURE_FLAG(Num, Val) \ + RootSigDesc.Val = (Flags & llvm::to_underlying(dxbc::RootFlags::Val)) > 0; #include "llvm/BinaryFormat/DXContainerConstants.def" return RootSigDesc; } uint32_t DXContainerYAML::RootDescriptorYaml::getEncodedFlags() const { - uint64_t Flag = 0; -#define ROOT_DESCRIPTOR_FLAG(Num, Val) \ - if (Val) \ - Flag |= (uint32_t)dxbc::RootDescriptorFlag::Val; + uint64_t Flags = 0; +#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \ + if (Enum) \ + Flags |= (uint32_t)dxbc::RootDescriptorFlags::Enum; #include "llvm/BinaryFormat/DXContainerConstants.def" - return Flag; + return Flags; } uint32_t DXContainerYAML::RootSignatureYamlDesc::getEncodedFlags() { uint64_t Flag = 0; -#define ROOT_ELEMENT_FLAG(Num, Val) \ +#define ROOT_SIGNATURE_FLAG(Num, Val) \ if (Val) \ - Flag |= (uint32_t)dxbc::RootElementFlag::Val; + Flag |= (uint32_t)dxbc::RootFlags::Val; #include "llvm/BinaryFormat/DXContainerConstants.def" return Flag; } uint32_t DXContainerYAML::DescriptorRangeYaml::getEncodedFlags() const { - uint64_t Flag = 0; -#define DESCRIPTOR_RANGE_FLAG(Num, Val) \ - if (Val) \ - Flag |= (uint32_t)dxbc::DescriptorRangeFlag::Val; + uint64_t Flags = 0; +#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \ + if (Enum) \ + Flags |= (uint32_t)dxbc::DescriptorRangeFlags::Enum; #include "llvm/BinaryFormat/DXContainerConstants.def" - return Flag; + return Flags; } uint64_t DXContainerYAML::ShaderFeatureFlags::getEncodedFlags() { @@ -382,7 +381,7 @@ void MappingTraits<DXContainerYAML::RootSignatureYamlDesc>::mapping( IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset); IO.mapRequired("Parameters", S.Parameters.Locations, S); IO.mapOptional("Samplers", S.StaticSamplers); -#define ROOT_ELEMENT_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false); +#define ROOT_SIGNATURE_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false); #include "llvm/BinaryFormat/DXContainerConstants.def" } @@ -406,7 +405,8 @@ void MappingTraits<llvm::DXContainerYAML::DescriptorRangeYaml>::mapping( IO.mapRequired("RegisterSpace", R.RegisterSpace); IO.mapRequired("OffsetInDescriptorsFromTableStart", R.OffsetInDescriptorsFromTableStart); -#define DESCRIPTOR_RANGE_FLAG(Num, Val) IO.mapOptional(#Val, R.Val, false); +#define DESCRIPTOR_RANGE_FLAG(Num, Enum, Flag) \ + IO.mapOptional(#Flag, R.Enum, false); #include "llvm/BinaryFormat/DXContainerConstants.def" } @@ -459,7 +459,8 @@ void MappingTraits<llvm::DXContainerYAML::RootDescriptorYaml>::mapping( IO &IO, llvm::DXContainerYAML::RootDescriptorYaml &D) { IO.mapRequired("RegisterSpace", D.RegisterSpace); IO.mapRequired("ShaderRegister", D.ShaderRegister); -#define ROOT_DESCRIPTOR_FLAG(Num, Val) IO.mapOptional(#Val, D.Val, false); +#define ROOT_DESCRIPTOR_FLAG(Num, Enum, Flag) \ + IO.mapOptional(#Flag, D.Enum, false); #include "llvm/BinaryFormat/DXContainerConstants.def" } diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 2dccc0d5b2b3e..5e0975736f90d 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -431,7 +431,7 @@ static bool verifyRangeType(uint32_t Type) { static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type, uint32_t FlagsVal) { - using FlagT = dxbc::DescriptorRangeFlag; + using FlagT = dxbc::DescriptorRangeFlags; FlagT Flags = FlagT(FlagsVal); const bool IsSampler = @@ -441,61 +441,59 @@ static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type, // Since the metadata is unversioned, we expect to explicitly see the values // that map to the version 1 behaviour here. if (IsSampler) - return Flags == FlagT::DESCRIPTORS_VOLATILE; - return Flags == (FlagT::DATA_VOLATILE | FlagT::DESCRIPTORS_VOLATILE); + return Flags == FlagT::DescriptorsVolatile; + return Flags == (FlagT::DataVolatile | FlagT::DescriptorsVolatile); } // The data-specific flags are mutually exclusive. - FlagT DataFlags = FlagT::DATA_VOLATILE | FlagT::DATA_STATIC | - FlagT::DATA_STATIC_WHILE_SET_AT_EXECUTE; + FlagT DataFlags = FlagT::DataVolatile | FlagT::DataStatic | + FlagT::DataStaticWhileSetAtExecute; if (popcount(llvm::to_underlying(Flags & DataFlags)) > 1) return false; // The descriptor-specific flags are mutually exclusive. - FlagT DescriptorFlags = - FlagT::DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS | - FlagT::DESCRIPTORS_VOLATILE; + FlagT DescriptorFlags = FlagT::DescriptorsStaticKeepingBufferBoundsChecks | + FlagT::DescriptorsVolatile; if (popcount(llvm::to_underlying(Flags & DescriptorFlags)) > 1) return false; // For volatile descriptors, DATA_STATIC is never valid. - if ((Flags & FlagT::DESCRIPTORS_VOLATILE) == FlagT::DESCRIPTORS_VOLATILE) { - FlagT Mask = FlagT::DESCRIPTORS_VOLATILE; + if ((Flags & FlagT::DescriptorsVolatile) == FlagT::DescriptorsVolatile) { + FlagT Mask = FlagT::DescriptorsVolatile; if (!IsSampler) { - Mask |= FlagT::DATA_VOLATILE; - Mask |= FlagT::DATA_STATIC_WHILE_SET_AT_EXECUTE; + Mask |= FlagT::DataVolatile; + Mask |= FlagT::DataStaticWhileSetAtExecute; } - return (Flags & ~Mask) == FlagT::NONE; + return (Flags & ~Mask) == FlagT::None; } // For "STATIC_KEEPING_BUFFER_BOUNDS_CHECKS" descriptors, // the other data-specific flags may all be set. - if ((Flags & FlagT::DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS) == - FlagT::DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS) { - FlagT Mask = FlagT::DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS; + if ((Flags & FlagT::DescriptorsStaticKeepingBufferBoundsChecks) == + FlagT::DescriptorsStaticKeepingBufferBoundsChecks) { + FlagT Mask = FlagT::DescriptorsStaticKeepingBufferBoundsChecks; if (!IsSampler) { - Mask |= FlagT::DATA_VOLATILE; - Mask |= FlagT::DATA_STATIC; - Mask |= FlagT::DATA_STATIC_WHILE_SET_AT_EXECUTE; + Mask |= FlagT::DataVolatile; + Mask |= FlagT::DataStatic; + Mask |= FlagT::DataStaticWhileSetAtExecute; } - return (Flags & ~Mask) == FlagT::NONE; + return (Flags & ~Mask) == FlagT::None; } // When no descriptor flag is set, any data flag is allowed. - FlagT Mask = FlagT::NONE; + FlagT Mask = FlagT::None; if (!IsSampler) { - Mask |= FlagT::DATA_VOLATILE; - Mask |= FlagT::DATA_STATIC; - Mask |= FlagT::DATA_STATIC_WHILE_SET_AT_EXECUTE; + Mask |= FlagT::DataVolatile; + Mask |= FlagT::DataStaticWhileSetAtExecute; + Mask |= FlagT::DataStatic; } - return (Flags & ~Mask) == FlagT::NONE; + return (Flags & ~Mask) == FlagT::None; } static bool verifySamplerFilter(uint32_t Value) { switch (Value) { -#define STATIC_SAMPLER_FILTER(Num, Val) \ - case llvm::to_underlying(dxbc::StaticSamplerFilter::Val): +#define FILTER(Num, Val) case llvm::to_underlying(dxbc::SamplerFilter::Val): #include "llvm/BinaryFormat/DXContainerConstants.def" return true; } @@ -524,8 +522,8 @@ static bool verifyMaxAnisotropy(uint32_t MaxAnisotropy) { static bool verifyComparisonFunc(uint32_t ComparisonFunc) { switch (ComparisonFunc) { -#define COMPARISON_FUNCTION(Num, Val) \ - case llvm::to_underlying(dxbc::SamplersComparisonFunction::Val): +#define COMPARISON_FUNC(Num, Val) \ + case llvm::to_underlying(dxbc::ComparisonFunc::Val): #include "llvm/BinaryFormat/DXContainerConstants.def" return true; } @@ -535,7 +533,7 @@ static bool verifyComparisonFunc(uint32_t ComparisonFunc) { static bool verifyBorderColor(uint32_t BorderColor) { switch (BorderColor) { #define STATIC_BORDER_COLOR(Num, Val) \ - case llvm::to_underlying(dxbc::SamplersBorderColor::Val): + case llvm::to_underlying(dxbc::StaticBorderColor::Val): #include "llvm/BinaryFormat/DXContainerConstants.def" return true; } diff --git a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp index dde82ac34ea28..ca2c296efc99b 100644 --- a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp +++ b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp @@ -37,7 +37,7 @@ TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) { Clause.NumDescriptors = NumDescriptorsUnbounded; Clause.Space = 42; Clause.Offset = 3; - Clause.Flags = DescriptorRangeFlags::None; + Clause.Flags = llvm::dxbc::DescriptorRangeFlags::None; std::string Out; llvm::raw_string_ostream OS(Out); @@ -50,13 +50,20 @@ TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) { } TEST(HLSLRootSignatureTest, DescriptorUAVClauseDump) { + using llvm::dxbc::DescriptorRangeFlags; DescriptorTableClause Clause; Clause.Type = ClauseType::UAV; Clause.Reg = {RegisterType::UReg, 92374}; Clause.NumDescriptors = 3298; Clause.Space = 932847; Clause.Offset = 1; - Clause.Flags = DescriptorRangeFlags::ValidFlags; + auto ValidDescriptorRangeFlags = + DescriptorRangeFlags::DescriptorsVolatile | + DescriptorRangeFlags::DataVolatile | + DescriptorRangeFlags::DataStaticWhileSetAtExecute | + DescriptorRangeFlags::DataStatic | + DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks; + Clause.Flags = ValidDescriptorRangeFlags; std::string Out; llvm::raw_string_ostream OS(Out); @@ -80,7 +87,7 @@ TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) { Clause.NumDescriptors = 2; Clause.Space = 42; Clause.Offset = DescriptorTableOffsetAppend; - Clause.Flags = DescriptorRangeFlags::ValidSamplerFlags; + Clause.Flags = llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile; std::string Out; llvm::raw_string_ostream OS(Out); @@ -96,7 +103,7 @@ TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) { TEST(HLSLRootSignatureTest, DescriptorTableDump) { DescriptorTable Table; Table.NumClauses = 4; - Table.Visibility = ShaderVisibility::Geometry; + Table.Visibility = llvm::dxbc::ShaderVisibility::Geometry; std::string Out; llvm::raw_string_ostream OS(Out); @@ -130,8 +137,8 @@ TEST(HLSLRootSignatureTest, RootSRVDump) { Descriptor.Type = DescriptorType::SRV; Descriptor.Reg = {RegisterType::TReg, 0}; Descriptor.Space = 42; - Descriptor.Visibility = ShaderVisibility::Geometry; - Descriptor.Flags = RootDescriptorFlags::None; + Descriptor.Visibility = llvm::dxbc::ShaderVisibility::Geometry; + Descriptor.Flags = llvm::dxbc::RootDescriptorFlags::None; std::string Out; llvm::raw_string_ostream OS(Out); @@ -144,12 +151,17 @@ TEST(HLSLRootSignatureTest, RootSRVDump) { } TEST(HLSLRootSignatureTest, RootUAVDump) { + using llvm::dxbc::RootDescriptorFlags; RootDescriptor Descriptor; Descriptor.Type = DescriptorType::UAV; Descriptor.Reg = {RegisterType::UReg, 92374}; Descriptor.Space = 932847; - Descriptor.Visibility = ShaderVisibility::Hull; - Descriptor.Flags = RootDescriptorFlags::ValidFlags; + Descriptor.Visibility = llvm::dxbc::ShaderVisibility::Hull; + auto ValidRootDescriptorFlags = + RootDescriptorFlags::DataVolatile | + RootDescriptorFlags::DataStaticWhileSetAtExecute | + RootDescriptorFlags::DataStatic; + Descriptor.Flags = ValidRootDescriptorFlags; std::string Out; llvm::raw_string_ostream OS(Out); @@ -194,18 +206,18 @@ TEST(HLSLRootSignatureTest, DefinedStaticSamplerDump) { StaticSampler Sampler; Sampler.Reg = {RegisterType::SReg, 0}; - Sampler.Filter = SamplerFilter::ComparisonMinMagLinearMipPoint; - Sampler.AddressU = TextureAddressMode::Mirror; - Sampler.AddressV = TextureAddressMode::Border; - Sampler.AddressW = TextureAddressMode::Clamp; + Sampler.Filter = llvm::dxbc::SamplerFilter::ComparisonMinMagLinearMipPoint; + Sampler.AddressU = llvm::dxbc::TextureAddressMode::Mirror; + Sampler.AddressV = llvm::dxbc::TextureAddressMode::Border; + Sampler.AddressW = llvm::dxbc::TextureAddressMode::Clamp; Sampler.MipLODBias = 4.8f; Sampler.MaxAnisotropy = 32; - Sampler.CompFunc = ComparisonFunc::NotEqual; - Sampler.BorderColor = StaticBorderColor::OpaqueBlack; + Sampler.CompFunc = llvm::dxbc::ComparisonFunc::NotEqual; + Sampler.BorderColor = llvm::dxbc::StaticBorderColor::OpaqueBlack; Sampler.MinLOD = 1.0f; Sampler.MaxLOD = 32.0f; Sampler.Space = 7; - Sampler.Visibility = ShaderVisibility::Domain; + Sampler.Visibility = llvm::dxbc::ShaderVisibility::Domain; std::string Out; llvm::raw_string_ostream OS(Out); @@ -249,7 +261,7 @@ TEST(HLSLRootSignatureTest, SetRootConstantsDump) { Constants.Num32BitConstants = 983; Constants.Reg = {RegisterType::BReg, 34593}; Constants.Space = 7; - Constants.Visibility = ShaderVisibility::Pixel; + Constants.Visibility = llvm::dxbc::ShaderVisibility::Pixel; std::string Out; llvm::raw_string_ostream OS(Out); @@ -262,7 +274,7 @@ TEST(HLSLRootSignatureTest, SetRootConstantsDump) { } TEST(HLSLRootSignatureTest, NoneRootFlagsDump) { - RootFlags Flags = RootFlags::None; + llvm::dxbc::RootFlags Flags = llvm::dxbc::RootFlags::None; std::string Out; llvm::raw_string_ostream OS(Out); @@ -274,11 +286,23 @@ TEST(HLSLRootSignatureTest, NoneRootFlagsDump) { } TEST(HLSLRootSignatureTest, AllRootFlagsDump) { - RootFlags Flags = RootFlags::ValidFlags; + using llvm::dxbc::RootFlags; + auto ValidRootFlags = RootFlags::AllowInputAssemblerInputLayout | + RootFlags::DenyVertexShaderRootAccess | + RootFlags::DenyHullShaderRootAccess | + RootFlags::DenyDomainShaderRootAccess | + RootFlags::DenyGeometryShaderRootAccess | + RootFlags::DenyPixelShaderRootAccess | + RootFlags::AllowStreamOutput | + RootFlags::LocalRootSignature | + RootFlags::DenyAmplificationShaderRootAccess | + RootFlags::DenyMeshShaderRootAccess | + RootFlags::CBVSRVUAVHeapDirectlyIndexed | + RootFlags::SamplerHeapDirectlyIndexed; std::string Out; llvm::raw_string_ostream OS(Out); - OS << Flags; + OS << ValidRootFlags; OS.flush(); std::string Expected = "RootFlags(" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits