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 &Elements, + RootSignatureParser(llvm::dxbc::RootSignatureVersion Version, + SmallVector &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 Expected); private: + llvm::dxbc::RootSignatureVersion Version; SmallVector &Elements; RootSignatureLexer &Lexer; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index c1493a5bfd3b3..f5bf9549c7830 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -4957,7 +4957,8 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) { // Invoke the root signature parser to construct the in-memory constructs hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc); SmallVector 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 &Elements, - RootSignatureLexer &Lexer, - Preprocessor &PP) - : Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {} +RootSignatureParser::RootSignatureParser( + llvm::dxbc::RootSignatureVersion Version, + SmallVector &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 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..b8767a18ec719 100644 --- a/clang/test/AST/HLSL/RootSignatures-AST.hlsl +++ b/clang/test/AST/HLSL/RootSignatures-AST.hlsl @@ -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_1-SAME: flags = DescriptorsVolatile +// CHECK-V1_1-SAME: flags = None // CHECK-SAME: ), // CHECK-SAME: DescriptorTable( // CHECK-SAME: numClauses = 1, visibility = All diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index ba42895afce6c..861089c4790b0 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -29,6 +29,9 @@ using namespace llvm::hlsl::rootsig; namespace { +static const llvm::dxbc::RootSignatureVersion DefVersion = + llvm::dxbc::RootSignatureVersion::V1_1; + // Diagnostic helper for helper tests class ExpectedDiagConsumer : public DiagnosticConsumer { virtual void anchor() {} @@ -115,7 +118,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -148,7 +151,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -246,7 +249,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -331,7 +334,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -406,7 +409,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -436,7 +439,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -492,7 +495,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -533,7 +536,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); @@ -605,13 +608,159 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); + + // Test no diagnostics produced + Consumer->setNoDiag(); + + ASSERT_FALSE(Parser.parse()); + + 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 Elements; + auto Version = llvm::dxbc::RootSignatureVersion::V1_0; + hlsl::RootSignatureParser Parser(Version, 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(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::CBuffer); + ASSERT_EQ(std::get(Elem).Flags, DefRootDescriptorFlag); + + Elem = Elements[1]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::SRV); + ASSERT_EQ(std::get(Elem).Flags, DefRootDescriptorFlag); + + Elem = Elements[2]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::UAV); + ASSERT_EQ(std::get(Elem).Flags, DefRootDescriptorFlag); + + auto ValidNonSamplerFlags = + llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile | + llvm::dxbc::DescriptorRangeFlags::DataVolatile; + Elem = Elements[3]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::CBuffer); + ASSERT_EQ(std::get(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[4]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::SRV); + ASSERT_EQ(std::get(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[5]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::UAV); + ASSERT_EQ(std::get(Elem).Flags, ValidNonSamplerFlags); + + Elem = Elements[6]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::Sampler); + ASSERT_EQ(std::get(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 Elements; + auto Version = llvm::dxbc::RootSignatureVersion::V1_1; + hlsl::RootSignatureParser Parser(Version, Elements, Lexer, *PP); // Test no diagnostics produced Consumer->setNoDiag(); ASSERT_FALSE(Parser.parse()); + RootElement Elem = Elements[0]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::CBuffer); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[1]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::SRV); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[2]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, DescriptorType::UAV); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::RootDescriptorFlags::DataVolatile); + + Elem = Elements[3]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::CBuffer); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[4]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::SRV); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute); + + Elem = Elements[5]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::UAV); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::DataVolatile); + + Elem = Elements[6]; + ASSERT_TRUE(std::holds_alternative(Elem)); + ASSERT_EQ(std::get(Elem).Type, ClauseType::Sampler); + ASSERT_EQ(std::get(Elem).Flags, + llvm::dxbc::DescriptorRangeFlags::None); + ASSERT_TRUE(Consumer->isSatisfied()); } @@ -629,7 +778,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -649,7 +798,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced - invalid token Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params); @@ -669,7 +818,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced - end of stream Consumer->setExpected(diag::err_expected_after); @@ -694,7 +843,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -716,7 +865,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -738,7 +887,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_missing_param); @@ -762,7 +911,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -784,7 +933,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -808,7 +957,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -834,7 +983,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param); @@ -857,7 +1006,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -879,7 +1028,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -900,7 +1049,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -921,7 +1070,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -942,7 +1091,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_overflow); @@ -963,7 +1112,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, Elements, Lexer, *PP); // Test correct diagnostic produced Consumer->setExpected(diag::err_hlsl_number_literal_underflow); @@ -987,7 +1136,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) { hlsl::RootSignatureLexer Lexer(Source, TokLoc); SmallVector Elements; - hlsl::RootSignatureParser Parser(Elements, Lexer, *PP); + hlsl::RootSignatureParser Parser(DefVersion, 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 f552040ab31cc..0579c1b5f9c25 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h @@ -50,7 +50,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: @@ -83,7 +90,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 e090f6bae470f..76ac285735d05 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); @@ -93,6 +93,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; @@ -112,7 +146,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); @@ -125,6 +159,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;