Author: Finn Plummer Date: 2025-07-04T09:48:24-07:00 New Revision: 6a948145aa7a55af31e7406842a4f45a86b74eaf
URL: https://github.com/llvm/llvm-project/commit/6a948145aa7a55af31e7406842a4f45a86b74eaf DIFF: https://github.com/llvm/llvm-project/commit/6a948145aa7a55af31e7406842a4f45a86b74eaf.diff LOG: [HLSL][RootSignature] Update `setDefaultFlags` to account for Root Signature Version (#145828) This pr updates `setDefaultFlags` in `HLSLRootSignature.h` to account for which version it should initialize the default flag values for. - Updates `setDefaultFlags` with a `Version` argument and initializes them to be compliant as described [here](https://github.com/llvm/wg-hlsl/pull/297). - Updates `RootSignatureParser` to retain the `Version` and pass this into `setDefaultFlags` - Updates all uses of `setDefaultFlags` in test-cases - Adds some new unit testing to ensure behaviour is as expected and that the Parser correctly passes down the version Resolves https://github.com/llvm/llvm-project/issues/145820. Added: Modified: clang/include/clang/Parse/ParseHLSLRootSignature.h clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseHLSLRootSignature.cpp clang/test/AST/HLSL/RootSignatures-AST.hlsl clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 18cd1f379e62c..66a5a3b7eaad0 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -27,7 +27,8 @@ namespace hlsl { class RootSignatureParser { public: - RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements, + RootSignatureParser(llvm::dxbc::RootSignatureVersion Version, + SmallVector<llvm::hlsl::rootsig::RootElement> &Elements, RootSignatureLexer &Lexer, clang::Preprocessor &PP); /// Consumes tokens from the Lexer and constructs the in-memory @@ -187,6 +188,7 @@ class RootSignatureParser { bool tryConsumeExpectedToken(ArrayRef<RootSignatureToken::Kind> Expected); private: + llvm::dxbc::RootSignatureVersion Version; SmallVector<llvm::hlsl::rootsig::RootElement> &Elements; RootSignatureLexer &Lexer; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index bd5c28b1992c4..6b0564dca6f45 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4956,7 +4956,8 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) { // Invoke the root signature parser to construct the in-memory constructs hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc); SmallVector<llvm::hlsl::rootsig::RootElement> RootElements; - hlsl::RootSignatureParser Parser(RootElements, Lexer, PP); + hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements, + Lexer, PP); if (Parser.parse()) { T.consumeClose(); return; diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 18d3644114eef..96d3999ff2acb 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -17,10 +17,12 @@ namespace hlsl { using TokenKind = RootSignatureToken::Kind; -RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements, - RootSignatureLexer &Lexer, - Preprocessor &PP) - : Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {} +RootSignatureParser::RootSignatureParser( + llvm::dxbc::RootSignatureVersion Version, + SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer, + Preprocessor &PP) + : Version(Version), Elements(Elements), Lexer(Lexer), PP(PP), + CurToken(SourceLocation()) {} bool RootSignatureParser::parse() { // Iterate as many RootElements as possible @@ -199,7 +201,7 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() { ExpectedReg = TokenKind::uReg; break; } - Descriptor.setDefaultFlags(); + Descriptor.setDefaultFlags(Version); auto Params = parseRootDescriptorParams(ExpectedReg); if (!Params.has_value()) @@ -318,7 +320,7 @@ RootSignatureParser::parseDescriptorTableClause() { ExpectedReg = TokenKind::sReg; break; } - Clause.setDefaultFlags(); + Clause.setDefaultFlags(Version); auto Params = parseDescriptorTableClauseParams(ExpectedReg); if (!Params.has_value()) diff --git a/clang/test/AST/HLSL/RootSignatures-AST.hlsl b/clang/test/AST/HLSL/RootSignatures-AST.hlsl index 1e60b9367c145..27c40430c9d0a 100644 --- a/clang/test/AST/HLSL/RootSignatures-AST.hlsl +++ b/clang/test/AST/HLSL/RootSignatures-AST.hlsl @@ -1,11 +1,11 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -ast-dump \ -// RUN: -disable-llvm-passes -o - %s | FileCheck %s +// RUN: -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-V1_1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -ast-dump \ // RUN: -fdx-rootsignature-version=rootsig_1_0 \ -// RUN: -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-V1_0 +// RUN: -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-V1_0 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -ast-dump \ // RUN: -fdx-rootsignature-version=rootsig_1_1 \ -// RUN: -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-V1_1 +// RUN: -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-V1_1 // This test ensures that the sample root signature is parsed without error and // the Attr AST Node is created succesfully. If an invalid root signature was @@ -37,13 +37,17 @@ // CHECK-SAME: space = 1, visibility = All, flags = DataStatic // CHECK-SAME: ), // CHECK-SAME: RootSRV(t0, -// CHECK-SAME: space = 0, visibility = All, flags = DataStaticWhileSetAtExecute +// CHECK-SAME: space = 0, visibility = All, +// CHECK-V1_0-SAME: flags = DataVolatile +// CHECK-V1_1-SAME: flags = DataStaticWhileSetAtExecute // CHECK-SAME: ), // CHECK-SAME: RootUAV( // CHECK-SAME: u0, space = 0, visibility = All, flags = DataVolatile // CHECK-SAME: ), // CHECK-SAME: CBV( -// CHECK-SAME: b1, numDescriptors = 1, space = 0, offset = DescriptorTableOffsetAppend, flags = DataStaticWhileSetAtExecute +// CHECK-SAME: b1, numDescriptors = 1, space = 0, offset = DescriptorTableOffsetAppend, +// CHECK-V1_0-SAME: flags = DescriptorsVolatile | DataVolatile +// CHECK-V1_1-SAME: flags = DataStaticWhileSetAtExecute // CHECK-SAME: ), // CHECK-SAME: SRV( // CHECK-SAME: t1, numDescriptors = 8, space = 0, offset = DescriptorTableOffsetAppend, flags = DescriptorsVolatile @@ -55,7 +59,9 @@ // CHECK-SAME: numClauses = 3, visibility = All // CHECK-SAME: ), // CHECK-SAME: Sampler( -// CHECK-SAME: s0, numDescriptors = 4, space = 1, offset = DescriptorTableOffsetAppend, flags = None +// CHECK-SAME: s0, numDescriptors = 4, space = 1, offset = DescriptorTableOffsetAppend, +// CHECK-V1_0-SAME: flags = DescriptorsVolatile +// CHECK-V1_1-SAME: flags = None // CHECK-SAME: ), // CHECK-SAME: DescriptorTable( // CHECK-SAME: numClauses = 1, visibility = All @@ -112,9 +118,13 @@ void same_rs_string_main() {} // a seperate decl and identifier to reference // CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[DIFF_RS_DECL:__hlsl_rootsig_decl_\d*]] +// CHECK-V1_0: version: 1.0, +// CHECK-V1_1: version: 1.1, // CHECK-SAME: RootElements{ -// CHECK-SAME: Sampler(s0, numDescriptors = 4, space = 1, -// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = None), +// CHECK-SAME: Sampler(s0, numDescriptors = 4, space = 1, offset = DescriptorTableOffsetAppend, +// CHECK-V1_0-SAME: flags = DescriptorsVolatile +// CHECK-V1_1-SAME: flags = None +// CHECK-SAME: ), // CHECK-SAME: DescriptorTable(numClauses = 1, visibility = All) // CHECK-SAME: } diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index 8831198e4b9c2..871f12ef3cce3 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -29,6 +29,8 @@ using namespace llvm::hlsl::rootsig; namespace { +using llvm::dxbc::RootSignatureVersion; + // Diagnostic helper for helper tests class ExpectedDiagConsumer : public DiagnosticConsumer { virtual void anchor() {} @@ -115,7 +117,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -149,7 +152,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -252,7 +256,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -337,7 +342,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -412,7 +418,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -443,7 +450,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -500,7 +508,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -553,7 +562,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -627,7 +637,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -637,6 +648,152 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { ASSERT_TRUE(Consumer->isSatisfied()); } +TEST_F(ParseHLSLRootSignatureTest, ValidVersion10Test) { + // This test checks that the default values are set correctly + // when parsing with root signature version 1.0 + const llvm::StringLiteral Source = R"cc( + CBV(b0), + SRV(t0), + UAV(u0), + DescriptorTable( + CBV(b1), + SRV(t1), + UAV(u1), + Sampler(s1), + ) + )cc"; + + TrivialModuleLoader ModLoader; + auto PP = createPP(Source, ModLoader); + auto TokLoc = SourceLocation(); + + hlsl::RootSignatureLexer Lexer(Source, TokLoc); + SmallVector<RootElement> Elements; + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_0, Elements, Lexer, + *PP); + + // Test no diagnostics produced + Consumer->setNoDiag(); + + ASSERT_FALSE(Parser.parse()); + + auto DefRootDescriptorFlag = llvm::dxbc::RootDescriptorFlags::DataVolatile; + RootElement Elem = Elements[0]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::CBuffer); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag); + + Elem = Elements[1]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::SRV); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag); + + Elem = Elements[2]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::UAV); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag); + + auto ValidNonSamplerFlags = + llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile | + llvm::dxbc::DescriptorRangeFlags::DataVolatile; + Elem = Elements[3]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::CBuffer); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[4]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::SRV); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[5]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::UAV); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[6]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::Sampler); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile); + + ASSERT_TRUE(Consumer->isSatisfied()); +} + +TEST_F(ParseHLSLRootSignatureTest, ValidVersion11Test) { + // This test checks that the default values are set correctly + // when parsing with root signature version 1.1 + const llvm::StringLiteral Source = R"cc( + CBV(b0), + SRV(t0), + UAV(u0), + DescriptorTable( + CBV(b1), + SRV(t1), + UAV(u1), + Sampler(s1), + ) + )cc"; + + TrivialModuleLoader ModLoader; + auto PP = createPP(Source, ModLoader); + auto TokLoc = SourceLocation(); + + hlsl::RootSignatureLexer Lexer(Source, TokLoc); + SmallVector<RootElement> Elements; + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); + + // Test no diagnostics produced + Consumer->setNoDiag(); + + ASSERT_FALSE(Parser.parse()); + + RootElement Elem = Elements[0]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::CBuffer); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[1]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::SRV); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[2]; + ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem)); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, DescriptorType::UAV); + ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataVolatile); + + Elem = Elements[3]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::CBuffer); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[4]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::SRV); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[5]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::UAV); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataVolatile); + + Elem = Elements[6]; + ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem)); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ClauseType::Sampler); + ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::None); + + ASSERT_TRUE(Consumer->isSatisfied()); +} + // Invalid Parser Tests TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { @@ -651,7 +808,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -671,7 +829,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced - invalid token Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -691,7 +850,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced - end of stream Consumer->setExpected(diag::err_expected_after); @@ -716,7 +876,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -738,7 +899,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -760,7 +922,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -784,7 +947,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -806,7 +970,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -830,7 +995,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -856,7 +1022,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -879,7 +1046,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -901,7 +1069,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -922,7 +1091,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -943,7 +1113,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -964,7 +1135,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -985,7 +1157,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_underflow); @@ -1009,7 +1182,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector<RootElement> Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer, + *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag); diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h index e10bd81c73aad..e44612af071bc 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h @@ -51,7 +51,14 @@ struct RootDescriptor { dxbc::ShaderVisibility Visibility = dxbc::ShaderVisibility::All; dxbc::RootDescriptorFlags Flags; - void setDefaultFlags() { + void setDefaultFlags(dxbc::RootSignatureVersion Version) { + if (Version == dxbc::RootSignatureVersion::V1_0) { + Flags = dxbc::RootDescriptorFlags::DataVolatile; + return; + } + + assert(Version == llvm::dxbc::RootSignatureVersion::V1_1 && + "Specified an invalid root signature version"); switch (Type) { case DescriptorType::CBuffer: case DescriptorType::SRV: @@ -84,7 +91,16 @@ struct DescriptorTableClause { uint32_t Offset = DescriptorTableOffsetAppend; dxbc::DescriptorRangeFlags Flags; - void setDefaultFlags() { + void setDefaultFlags(dxbc::RootSignatureVersion Version) { + if (Version == dxbc::RootSignatureVersion::V1_0) { + Flags = dxbc::DescriptorRangeFlags::DescriptorsVolatile; + if (Type != ClauseType::Sampler) + Flags |= dxbc::DescriptorRangeFlags::DataVolatile; + return; + } + + assert(Version == dxbc::RootSignatureVersion::V1_1 && + "Specified an invalid root signature version"); switch (Type) { case ClauseType::CBuffer: case ClauseType::SRV: diff --git a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp index 2a326353d67a4..98b33fdfb8c12 100644 --- a/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp +++ b/llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp @@ -17,7 +17,7 @@ TEST(HLSLRootSignatureTest, DescriptorCBVClauseDump) { DescriptorTableClause Clause; Clause.Type = ClauseType::CBuffer; Clause.Reg = {RegisterType::BReg, 0}; - Clause.setDefaultFlags(); + Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_1); std::string Out; llvm::raw_string_ostream OS(Out); @@ -100,6 +100,40 @@ TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) { EXPECT_EQ(Out, Expected); } +TEST(HLSLRootSignatureTest, DescriptorCBVV10ClauseDump) { + DescriptorTableClause Clause; + Clause.Type = ClauseType::CBuffer; + Clause.Reg = {RegisterType::BReg, 0}; + Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0); + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Clause; + OS.flush(); + + std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, " + "offset = DescriptorTableOffsetAppend, " + "flags = DescriptorsVolatile | DataVolatile)"; + EXPECT_EQ(Out, Expected); +} + +TEST(HLSLRootSignatureTest, DescriptorSamplerV10ClauseDump) { + DescriptorTableClause Clause; + Clause.Type = ClauseType::Sampler; + Clause.Reg = {RegisterType::SReg, 0}; + Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0); + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Clause; + OS.flush(); + + std::string Expected = "Sampler(s0, numDescriptors = 1, space = 0, offset = " + "DescriptorTableOffsetAppend, " + "flags = DescriptorsVolatile)"; + EXPECT_EQ(Out, Expected); +} + TEST(HLSLRootSignatureTest, DescriptorTableDump) { DescriptorTable Table; Table.NumClauses = 4; @@ -119,7 +153,7 @@ TEST(HLSLRootSignatureTest, RootCBVDump) { RootDescriptor Descriptor; Descriptor.Type = DescriptorType::CBuffer; Descriptor.Reg = {RegisterType::BReg, 0}; - Descriptor.setDefaultFlags(); + Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_1); std::string Out; llvm::raw_string_ostream OS(Out); @@ -132,6 +166,40 @@ TEST(HLSLRootSignatureTest, RootCBVDump) { EXPECT_EQ(Out, Expected); } +TEST(HLSLRootSignatureTest, RootSRV10Dump) { + RootDescriptor Descriptor; + Descriptor.Type = DescriptorType::SRV; + Descriptor.Reg = {RegisterType::TReg, 0}; + Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0); + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Descriptor; + OS.flush(); + + std::string Expected = "RootSRV(t0, space = 0, " + "visibility = All, " + "flags = DataVolatile)"; + EXPECT_EQ(Out, Expected); +} + +TEST(HLSLRootSignatureTest, RootUAVV10Dump) { + RootDescriptor Descriptor; + Descriptor.Type = DescriptorType::UAV; + Descriptor.Reg = {RegisterType::UReg, 0}; + Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0); + + std::string Out; + llvm::raw_string_ostream OS(Out); + OS << Descriptor; + OS.flush(); + + std::string Expected = "RootUAV(u0, space = 0, " + "visibility = All, " + "flags = DataVolatile)"; + EXPECT_EQ(Out, Expected); +} + TEST(HLSLRootSignatureTest, RootSRVDump) { RootDescriptor Descriptor; Descriptor.Type = DescriptorType::SRV; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits