1765 lines · cpp
1//=== ParseHLSLRootSignatureTest.cpp - Parse Root Signature tests ---------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "clang/AST/ASTContext.h"10#include "clang/AST/Expr.h"11#include "clang/Basic/Diagnostic.h"12#include "clang/Basic/DiagnosticOptions.h"13#include "clang/Basic/FileManager.h"14#include "clang/Basic/LangOptions.h"15#include "clang/Basic/SourceLocation.h"16#include "clang/Basic/SourceManager.h"17#include "clang/Basic/TargetInfo.h"18#include "clang/Lex/HeaderSearch.h"19#include "clang/Lex/HeaderSearchOptions.h"20#include "clang/Lex/Lexer.h"21#include "clang/Lex/ModuleLoader.h"22#include "clang/Lex/Preprocessor.h"23#include "clang/Lex/PreprocessorOptions.h"24 25#include "clang/Lex/LexHLSLRootSignature.h"26#include "clang/Parse/ParseHLSLRootSignature.h"27#include "gtest/gtest.h"28 29using namespace clang;30using namespace clang::hlsl;31using namespace llvm::hlsl::rootsig;32 33namespace {34 35using llvm::dxbc::RootSignatureVersion;36 37// Diagnostic helper for helper tests38class ExpectedDiagConsumer : public DiagnosticConsumer {39 virtual void anchor() {}40 41 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,42 const Diagnostic &Info) override {43 if (!FirstDiag || !ExpectedDiagID.has_value()) {44 Satisfied = false;45 return;46 }47 FirstDiag = false;48 49 Satisfied = ExpectedDiagID.value() == Info.getID();50 }51 52 bool FirstDiag = true;53 bool Satisfied = false;54 std::optional<unsigned> ExpectedDiagID;55 56public:57 void setNoDiag() {58 Satisfied = true;59 ExpectedDiagID = std::nullopt;60 }61 62 void setExpected(unsigned DiagID) {63 Satisfied = false;64 ExpectedDiagID = DiagID;65 }66 67 bool isSatisfied() { return Satisfied; }68};69 70// The test fixture.71class ParseHLSLRootSignatureTest : public ::testing::Test {72protected:73 ParseHLSLRootSignatureTest()74 : FileMgr(FileMgrOpts), Consumer(new ExpectedDiagConsumer()),75 Diags(DiagnosticIDs::create(), DiagOpts, Consumer),76 SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {77 // This is an arbitrarily chosen target triple to create the target info.78 TargetOpts->Triple = "dxil";79 Target = TargetInfo::CreateTargetInfo(Diags, *TargetOpts);80 }81 82 std::unique_ptr<Preprocessor> createPP(StringRef Source,83 TrivialModuleLoader &ModLoader) {84 std::unique_ptr<llvm::MemoryBuffer> Buf =85 llvm::MemoryBuffer::getMemBuffer(Source);86 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));87 88 HeaderSearchOptions SearchOpts;89 HeaderSearch HeaderInfo(SearchOpts, SourceMgr, Diags, LangOpts,90 Target.get());91 auto PP = std::make_unique<Preprocessor>(92 PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,93 /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false);94 PP->Initialize(*Target);95 PP->EnterMainSourceFile();96 return PP;97 }98 99 std::unique_ptr<ASTContext> createMinimalASTContext() {100 IdentifierTable Idents(LangOpts);101 SelectorTable Selectors;102 Builtin::Context Builtins;103 104 return std::make_unique<ASTContext>(LangOpts, SourceMgr, Idents, Selectors,105 Builtins, TU_Complete);106 }107 108 StringLiteral *wrapSource(std::unique_ptr<ASTContext> &Ctx,109 StringRef Source) {110 SourceLocation Locs[1] = {SourceLocation()};111 return StringLiteral::Create(*Ctx, Source, StringLiteralKind::Unevaluated,112 false, Ctx->VoidTy, Locs);113 }114 115 FileSystemOptions FileMgrOpts;116 FileManager FileMgr;117 DiagnosticOptions DiagOpts;118 ExpectedDiagConsumer *Consumer;119 DiagnosticsEngine Diags;120 SourceManager SourceMgr;121 LangOptions LangOpts;122 PreprocessorOptions PPOpts;123 std::shared_ptr<TargetOptions> TargetOpts;124 IntrusiveRefCntPtr<TargetInfo> Target;125};126 127// Valid Parser Tests128 129TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {130 const llvm::StringLiteral Source = R"cc()cc";131 132 auto Ctx = createMinimalASTContext();133 StringLiteral *Signature = wrapSource(Ctx, Source);134 135 TrivialModuleLoader ModLoader;136 auto PP = createPP(Source, ModLoader);137 138 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);139 140 // Test no diagnostics produced141 Consumer->setNoDiag();142 143 ASSERT_FALSE(Parser.parse());144 ASSERT_EQ((int)Parser.getElements().size(), 0);145 146 ASSERT_TRUE(Consumer->isSatisfied());147}148 149TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {150 using llvm::dxbc::DescriptorRangeFlags;151 const llvm::StringLiteral Source = R"cc(152 DescriptorTable(153 CBV(b0),154 SRV(space = 3, offset = 32, t42, flags = 0, numDescriptors = 4),155 visibility = SHADER_VISIBILITY_PIXEL,156 Sampler(s987, space = +2, offset = DESCRIPTOR_RANGE_OFFSET_APPEND),157 UAV(u4294967294, numDescriptors = unbounded,158 flags = Descriptors_Volatile | Data_Volatile159 | Data_Static_While_Set_At_Execute | Data_Static160 | Descriptors_Static_Keeping_Buffer_Bounds_Checks161 )162 ),163 DescriptorTable()164 )cc";165 166 auto Ctx = createMinimalASTContext();167 StringLiteral *Signature = wrapSource(Ctx, Source);168 169 TrivialModuleLoader ModLoader;170 auto PP = createPP(Source, ModLoader);171 172 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);173 174 // Test no diagnostics produced175 Consumer->setNoDiag();176 177 ASSERT_FALSE(Parser.parse());178 179 auto Elements = Parser.getElements();180 // First Descriptor Table with 4 elements181 RootElement Elem = Elements[0].getElement();182 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));183 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::CBuffer);184 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.ViewType,185 RegisterType::BReg);186 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.Number, 0u);187 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, 1u);188 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, 0u);189 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,190 DescriptorTableOffsetAppend);191 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,192 DescriptorRangeFlags::DataStaticWhileSetAtExecute);193 194 Elem = Elements[1].getElement();195 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));196 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::SRV);197 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.ViewType,198 RegisterType::TReg);199 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.Number, 42u);200 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, 4u);201 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, 3u);202 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset, 32u);203 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,204 DescriptorRangeFlags::None);205 206 Elem = Elements[2].getElement();207 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));208 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::Sampler);209 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.ViewType,210 RegisterType::SReg);211 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.Number, 987u);212 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors, 1u);213 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, 2u);214 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,215 DescriptorTableOffsetAppend);216 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,217 DescriptorRangeFlags::None);218 219 Elem = Elements[3].getElement();220 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));221 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::UAV);222 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.ViewType,223 RegisterType::UReg);224 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Reg.Number, 4294967294u);225 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).NumDescriptors,226 NumDescriptorsUnbounded);227 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Space, 0u);228 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Offset,229 DescriptorTableOffsetAppend);230 auto ValidDescriptorRangeFlags =231 DescriptorRangeFlags::DescriptorsVolatile |232 DescriptorRangeFlags::DataVolatile |233 DescriptorRangeFlags::DataStaticWhileSetAtExecute |234 DescriptorRangeFlags::DataStatic |235 DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks;236 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,237 ValidDescriptorRangeFlags);238 239 Elem = Elements[4].getElement();240 ASSERT_TRUE(std::holds_alternative<DescriptorTable>(Elem));241 ASSERT_EQ(std::get<DescriptorTable>(Elem).NumClauses, (uint32_t)4);242 ASSERT_EQ(std::get<DescriptorTable>(Elem).Visibility,243 llvm::dxbc::ShaderVisibility::Pixel);244 245 // Empty Descriptor Table246 Elem = Elements[5].getElement();247 ASSERT_TRUE(std::holds_alternative<DescriptorTable>(Elem));248 ASSERT_EQ(std::get<DescriptorTable>(Elem).NumClauses, 0u);249 ASSERT_EQ(std::get<DescriptorTable>(Elem).Visibility,250 llvm::dxbc::ShaderVisibility::All);251 252 ASSERT_TRUE(Consumer->isSatisfied());253}254 255TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {256 const llvm::StringLiteral Source = R"cc(257 StaticSampler(s0),258 StaticSampler(s0, maxAnisotropy = 3, space = 4,259 visibility = SHADER_VISIBILITY_DOMAIN,260 minLOD = 4.2f, mipLODBias = 0.23e+3,261 addressW = TEXTURE_ADDRESS_CLAMP,262 addressV = TEXTURE_ADDRESS_BORDER,263 filter = FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT,264 maxLOD = 9000, addressU = TEXTURE_ADDRESS_MIRROR,265 comparisonFunc = COMPARISON_NOT_EQUAL,266 borderColor = STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT,267 flags = 0268 )269 )cc";270 271 auto Ctx = createMinimalASTContext();272 StringLiteral *Signature = wrapSource(Ctx, Source);273 274 TrivialModuleLoader ModLoader;275 auto PP = createPP(Source, ModLoader);276 277 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);278 279 // Test no diagnostics produced280 Consumer->setNoDiag();281 282 ASSERT_FALSE(Parser.parse());283 284 auto Elements = Parser.getElements();285 ASSERT_EQ(Elements.size(), 2u);286 287 // Check default values are as expected288 RootElement Elem = Elements[0].getElement();289 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));290 ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg);291 ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u);292 ASSERT_EQ(std::get<StaticSampler>(Elem).Filter,293 llvm::dxbc::SamplerFilter::Anisotropic);294 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU,295 llvm::dxbc::TextureAddressMode::Wrap);296 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV,297 llvm::dxbc::TextureAddressMode::Wrap);298 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW,299 llvm::dxbc::TextureAddressMode::Wrap);300 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);301 ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 16u);302 ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc,303 llvm::dxbc::ComparisonFunc::LessEqual);304 ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor,305 llvm::dxbc::StaticBorderColor::OpaqueWhite);306 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 0.f);307 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 3.402823466e+38f);308 ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 0u);309 ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility,310 llvm::dxbc::ShaderVisibility::All);311 312 // Check values can be set as expected313 Elem = Elements[1].getElement();314 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));315 ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg);316 ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u);317 ASSERT_EQ(std::get<StaticSampler>(Elem).Filter,318 llvm::dxbc::SamplerFilter::MaximumMinPointMagLinearMipPoint);319 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU,320 llvm::dxbc::TextureAddressMode::Mirror);321 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV,322 llvm::dxbc::TextureAddressMode::Border);323 ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW,324 llvm::dxbc::TextureAddressMode::Clamp);325 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 230.f);326 ASSERT_EQ(std::get<StaticSampler>(Elem).MaxAnisotropy, 3u);327 ASSERT_EQ(std::get<StaticSampler>(Elem).CompFunc,328 llvm::dxbc::ComparisonFunc::NotEqual);329 ASSERT_EQ(std::get<StaticSampler>(Elem).BorderColor,330 llvm::dxbc::StaticBorderColor::OpaqueBlackUint);331 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MinLOD, 4.2f);332 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MaxLOD, 9000.f);333 ASSERT_EQ(std::get<StaticSampler>(Elem).Space, 4u);334 ASSERT_EQ(std::get<StaticSampler>(Elem).Visibility,335 llvm::dxbc::ShaderVisibility::Domain);336 337 ASSERT_TRUE(Consumer->isSatisfied());338}339 340TEST_F(ParseHLSLRootSignatureTest, ValidStaticSamplerFlagsTest) {341 const llvm::StringLiteral Source = R"cc(342 StaticSampler(s0, flags = UINT_BORDER_COLOR | NON_NORMALIZED_COORDINATES)343 )cc";344 345 auto Ctx = createMinimalASTContext();346 StringLiteral *Signature = wrapSource(Ctx, Source);347 348 TrivialModuleLoader ModLoader;349 auto PP = createPP(Source, ModLoader);350 351 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);352 353 // Test no diagnostics produced354 Consumer->setNoDiag();355 356 ASSERT_FALSE(Parser.parse());357 358 auto Elements = Parser.getElements();359 ASSERT_EQ(Elements.size(), 1u);360 361 RootElement Elem = Elements[0].getElement();362 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));363 auto ValidStaticSamplerFlags =364 llvm::dxbc::StaticSamplerFlags::NonNormalizedCoordinates |365 llvm::dxbc::StaticSamplerFlags::UintBorderColor;366 ASSERT_EQ(std::get<StaticSampler>(Elem).Flags, ValidStaticSamplerFlags);367 368 ASSERT_TRUE(Consumer->isSatisfied());369}370 371TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {372 const llvm::StringLiteral Source = R"cc(373 StaticSampler(s0, mipLODBias = 0),374 StaticSampler(s0, mipLODBias = +1),375 StaticSampler(s0, mipLODBias = -1),376 StaticSampler(s0, mipLODBias = 42.),377 StaticSampler(s0, mipLODBias = +4.2),378 StaticSampler(s0, mipLODBias = -.42),379 StaticSampler(s0, mipLODBias = .42e+3),380 StaticSampler(s0, mipLODBias = 42E-12),381 StaticSampler(s0, mipLODBias = 42.f),382 StaticSampler(s0, mipLODBias = 4.2F),383 StaticSampler(s0, mipLODBias = 42.e+10f),384 StaticSampler(s0, mipLODBias = -2147483648),385 StaticSampler(s0, mipLODBias = 2147483648),386 )cc";387 388 auto Ctx = createMinimalASTContext();389 StringLiteral *Signature = wrapSource(Ctx, Source);390 391 TrivialModuleLoader ModLoader;392 auto PP = createPP(Source, ModLoader);393 394 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);395 396 // Test no diagnostics produced397 Consumer->setNoDiag();398 399 ASSERT_FALSE(Parser.parse());400 401 auto Elements = Parser.getElements();402 RootElement Elem = Elements[0].getElement();403 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));404 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.f);405 406 Elem = Elements[1].getElement();407 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));408 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 1.f);409 410 Elem = Elements[2].getElement();411 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));412 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, -1.f);413 414 Elem = Elements[3].getElement();415 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));416 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 42.f);417 418 Elem = Elements[4].getElement();419 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));420 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 4.2f);421 422 Elem = Elements[5].getElement();423 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));424 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, -.42f);425 426 Elem = Elements[6].getElement();427 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));428 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 420.f);429 430 Elem = Elements[7].getElement();431 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));432 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 0.000000000042f);433 434 Elem = Elements[8].getElement();435 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));436 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 42.f);437 438 Elem = Elements[9].getElement();439 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));440 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 4.2f);441 442 Elem = Elements[10].getElement();443 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));444 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 420000000000.f);445 446 Elem = Elements[11].getElement();447 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));448 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, -2147483648.f);449 450 Elem = Elements[12].getElement();451 ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem));452 ASSERT_FLOAT_EQ(std::get<StaticSampler>(Elem).MipLODBias, 2147483648.f);453 454 ASSERT_TRUE(Consumer->isSatisfied());455}456 457TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {458 // This test will checks we can set the valid enum for Sampler descriptor459 // range flags460 const llvm::StringLiteral Source = R"cc(461 DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE))462 )cc";463 464 auto Ctx = createMinimalASTContext();465 StringLiteral *Signature = wrapSource(Ctx, Source);466 467 TrivialModuleLoader ModLoader;468 auto PP = createPP(Source, ModLoader);469 470 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);471 472 // Test no diagnostics produced473 Consumer->setNoDiag();474 475 ASSERT_FALSE(Parser.parse());476 477 auto Elements = Parser.getElements();478 RootElement Elem = Elements[0].getElement();479 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));480 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::Sampler);481 auto ValidSamplerFlags =482 llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile;483 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidSamplerFlags);484 485 ASSERT_TRUE(Consumer->isSatisfied());486}487 488TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {489 const llvm::StringLiteral Source = R"cc(490 RootConstants(num32BitConstants = 1, b0),491 RootConstants(b42, space = 3, num32BitConstants = 4294967295,492 visibility = SHADER_VISIBILITY_HULL493 )494 )cc";495 496 auto Ctx = createMinimalASTContext();497 StringLiteral *Signature = wrapSource(Ctx, Source);498 499 TrivialModuleLoader ModLoader;500 auto PP = createPP(Source, ModLoader);501 502 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);503 504 // Test no diagnostics produced505 Consumer->setNoDiag();506 507 ASSERT_FALSE(Parser.parse());508 509 auto Elements = Parser.getElements();510 ASSERT_EQ(Elements.size(), 2u);511 512 RootElement Elem = Elements[0].getElement();513 ASSERT_TRUE(std::holds_alternative<RootConstants>(Elem));514 ASSERT_EQ(std::get<RootConstants>(Elem).Num32BitConstants, 1u);515 ASSERT_EQ(std::get<RootConstants>(Elem).Reg.ViewType, RegisterType::BReg);516 ASSERT_EQ(std::get<RootConstants>(Elem).Reg.Number, 0u);517 ASSERT_EQ(std::get<RootConstants>(Elem).Space, 0u);518 ASSERT_EQ(std::get<RootConstants>(Elem).Visibility,519 llvm::dxbc::ShaderVisibility::All);520 521 Elem = Elements[1].getElement();522 ASSERT_TRUE(std::holds_alternative<RootConstants>(Elem));523 ASSERT_EQ(std::get<RootConstants>(Elem).Num32BitConstants, 4294967295u);524 ASSERT_EQ(std::get<RootConstants>(Elem).Reg.ViewType, RegisterType::BReg);525 ASSERT_EQ(std::get<RootConstants>(Elem).Reg.Number, 42u);526 ASSERT_EQ(std::get<RootConstants>(Elem).Space, 3u);527 ASSERT_EQ(std::get<RootConstants>(Elem).Visibility,528 llvm::dxbc::ShaderVisibility::Hull);529 530 ASSERT_TRUE(Consumer->isSatisfied());531}532 533TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {534 using llvm::dxbc::RootFlags;535 const llvm::StringLiteral Source = R"cc(536 RootFlags(537 deny_domain_shader_root_access |538 deny_pixel_shader_root_access |539 local_root_signature |540 cbv_srv_uav_heap_directly_indexed |541 deny_amplification_shader_root_access |542 deny_geometry_shader_root_access |543 deny_hull_shader_root_access |544 deny_mesh_shader_root_access |545 allow_stream_output |546 sampler_heap_directly_indexed |547 allow_input_assembler_input_layout |548 deny_vertex_shader_root_access549 )550 )cc";551 552 auto Ctx = createMinimalASTContext();553 StringLiteral *Signature = wrapSource(Ctx, Source);554 555 TrivialModuleLoader ModLoader;556 auto PP = createPP(Source, ModLoader);557 558 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);559 560 // Test no diagnostics produced561 Consumer->setNoDiag();562 563 ASSERT_FALSE(Parser.parse());564 565 auto Elements = Parser.getElements();566 ASSERT_EQ(Elements.size(), 1u);567 568 RootElement Elem = Elements[0].getElement();569 ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));570 auto ValidRootFlags = RootFlags::AllowInputAssemblerInputLayout |571 RootFlags::DenyVertexShaderRootAccess |572 RootFlags::DenyHullShaderRootAccess |573 RootFlags::DenyDomainShaderRootAccess |574 RootFlags::DenyGeometryShaderRootAccess |575 RootFlags::DenyPixelShaderRootAccess |576 RootFlags::AllowStreamOutput |577 RootFlags::LocalRootSignature |578 RootFlags::DenyAmplificationShaderRootAccess |579 RootFlags::DenyMeshShaderRootAccess |580 RootFlags::CBVSRVUAVHeapDirectlyIndexed |581 RootFlags::SamplerHeapDirectlyIndexed;582 ASSERT_EQ(std::get<RootFlags>(Elem), ValidRootFlags);583 584 ASSERT_TRUE(Consumer->isSatisfied());585}586 587TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyRootFlagsTest) {588 using llvm::dxbc::RootFlags;589 const llvm::StringLiteral Source = R"cc(590 RootFlags(),591 )cc";592 593 auto Ctx = createMinimalASTContext();594 StringLiteral *Signature = wrapSource(Ctx, Source);595 596 TrivialModuleLoader ModLoader;597 auto PP = createPP(Source, ModLoader);598 599 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);600 601 // Test no diagnostics produced602 Consumer->setNoDiag();603 604 ASSERT_FALSE(Parser.parse());605 606 auto Elements = Parser.getElements();607 ASSERT_EQ(Elements.size(), 1u);608 609 RootElement Elem = Elements[0].getElement();610 ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));611 ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::None);612 613 ASSERT_TRUE(Consumer->isSatisfied());614}615 616TEST_F(ParseHLSLRootSignatureTest, ValidParseZeroRootFlagsTest) {617 using llvm::dxbc::RootFlags;618 const llvm::StringLiteral Source = R"cc(619 RootFlags(0),620 )cc";621 622 auto Ctx = createMinimalASTContext();623 StringLiteral *Signature = wrapSource(Ctx, Source);624 625 TrivialModuleLoader ModLoader;626 auto PP = createPP(Source, ModLoader);627 628 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);629 630 // Test no diagnostics produced631 Consumer->setNoDiag();632 633 ASSERT_FALSE(Parser.parse());634 635 auto Elements = Parser.getElements();636 ASSERT_EQ(Elements.size(), 1u);637 638 RootElement Elem = Elements[0].getElement();639 ASSERT_TRUE(std::holds_alternative<RootFlags>(Elem));640 ASSERT_EQ(std::get<RootFlags>(Elem), RootFlags::None);641 642 ASSERT_TRUE(Consumer->isSatisfied());643}644 645TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {646 using llvm::dxbc::RootDescriptorFlags;647 const llvm::StringLiteral Source = R"cc(648 CBV(b0),649 SRV(space = 4, t42, visibility = SHADER_VISIBILITY_GEOMETRY,650 flags = DATA_VOLATILE | DATA_STATIC | DATA_STATIC_WHILE_SET_AT_EXECUTE651 ),652 UAV(visibility = SHADER_VISIBILITY_HULL, u34893247),653 CBV(b0, flags = 0),654 )cc";655 656 auto Ctx = createMinimalASTContext();657 StringLiteral *Signature = wrapSource(Ctx, Source);658 659 TrivialModuleLoader ModLoader;660 auto PP = createPP(Source, ModLoader);661 662 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);663 664 // Test no diagnostics produced665 Consumer->setNoDiag();666 667 ASSERT_FALSE(Parser.parse());668 669 auto Elements = Parser.getElements();670 ASSERT_EQ(Elements.size(), 4u);671 672 RootElement Elem = Elements[0].getElement();673 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));674 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::CBuffer);675 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::BReg);676 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 0u);677 ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u);678 ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility,679 llvm::dxbc::ShaderVisibility::All);680 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,681 RootDescriptorFlags::DataStaticWhileSetAtExecute);682 683 Elem = Elements[1].getElement();684 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));685 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::SRV);686 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::TReg);687 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 42u);688 ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 4u);689 ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility,690 llvm::dxbc::ShaderVisibility::Geometry);691 auto ValidRootDescriptorFlags =692 RootDescriptorFlags::DataVolatile |693 RootDescriptorFlags::DataStaticWhileSetAtExecute |694 RootDescriptorFlags::DataStatic;695 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, ValidRootDescriptorFlags);696 697 Elem = Elements[2].getElement();698 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));699 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::UAV);700 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::UReg);701 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 34893247u);702 ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u);703 ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility,704 llvm::dxbc::ShaderVisibility::Hull);705 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,706 RootDescriptorFlags::DataVolatile);707 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,708 RootDescriptorFlags::DataVolatile);709 710 Elem = Elements[3].getElement();711 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::CBuffer);712 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.ViewType, RegisterType::BReg);713 ASSERT_EQ(std::get<RootDescriptor>(Elem).Reg.Number, 0u);714 ASSERT_EQ(std::get<RootDescriptor>(Elem).Space, 0u);715 ASSERT_EQ(std::get<RootDescriptor>(Elem).Visibility,716 llvm::dxbc::ShaderVisibility::All);717 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, RootDescriptorFlags::None);718 719 ASSERT_TRUE(Consumer->isSatisfied());720}721 722TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {723 // This test will checks we can handling trailing commas ','724 const llvm::StringLiteral Source = R"cc(725 DescriptorTable(726 CBV(b0, ),727 SRV(t42),728 )729 )cc";730 731 auto Ctx = createMinimalASTContext();732 StringLiteral *Signature = wrapSource(Ctx, Source);733 734 TrivialModuleLoader ModLoader;735 auto PP = createPP(Source, ModLoader);736 737 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);738 739 // Test no diagnostics produced740 Consumer->setNoDiag();741 742 ASSERT_FALSE(Parser.parse());743 744 ASSERT_TRUE(Consumer->isSatisfied());745}746 747TEST_F(ParseHLSLRootSignatureTest, ValidVersion10Test) {748 // This test checks that the default values are set correctly749 // when parsing with root signature version 1.0750 const llvm::StringLiteral Source = R"cc(751 CBV(b0),752 SRV(t0),753 UAV(u0),754 DescriptorTable(755 CBV(b1),756 SRV(t1),757 UAV(u1),758 Sampler(s1),759 )760 )cc";761 762 auto Ctx = createMinimalASTContext();763 StringLiteral *Signature = wrapSource(Ctx, Source);764 765 TrivialModuleLoader ModLoader;766 auto PP = createPP(Source, ModLoader);767 768 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_0, Signature, *PP);769 770 // Test no diagnostics produced771 Consumer->setNoDiag();772 773 ASSERT_FALSE(Parser.parse());774 775 auto Elements = Parser.getElements();776 auto DefRootDescriptorFlag = llvm::dxbc::RootDescriptorFlags::DataVolatile;777 RootElement Elem = Elements[0].getElement();778 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));779 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::CBuffer);780 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);781 782 Elem = Elements[1].getElement();783 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));784 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::SRV);785 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);786 787 Elem = Elements[2].getElement();788 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));789 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::UAV);790 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags, DefRootDescriptorFlag);791 792 auto ValidNonSamplerFlags =793 llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile |794 llvm::dxbc::DescriptorRangeFlags::DataVolatile;795 Elem = Elements[3].getElement();796 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));797 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::CBuffer);798 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);799 800 Elem = Elements[4].getElement();801 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));802 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::SRV);803 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);804 805 Elem = Elements[5].getElement();806 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));807 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::UAV);808 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags, ValidNonSamplerFlags);809 810 Elem = Elements[6].getElement();811 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));812 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::Sampler);813 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,814 llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile);815 816 ASSERT_TRUE(Consumer->isSatisfied());817}818 819TEST_F(ParseHLSLRootSignatureTest, ValidVersion11Test) {820 // This test checks that the default values are set correctly821 // when parsing with root signature version 1.1822 const llvm::StringLiteral Source = R"cc(823 CBV(b0),824 SRV(t0),825 UAV(u0),826 DescriptorTable(827 CBV(b1),828 SRV(t1),829 UAV(u1),830 Sampler(s1),831 )832 )cc";833 834 auto Ctx = createMinimalASTContext();835 StringLiteral *Signature = wrapSource(Ctx, Source);836 837 TrivialModuleLoader ModLoader;838 auto PP = createPP(Source, ModLoader);839 840 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);841 842 // Test no diagnostics produced843 Consumer->setNoDiag();844 845 ASSERT_FALSE(Parser.parse());846 847 auto Elements = Parser.getElements();848 RootElement Elem = Elements[0].getElement();849 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));850 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::CBuffer);851 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,852 llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute);853 854 Elem = Elements[1].getElement();855 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));856 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::SRV);857 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,858 llvm::dxbc::RootDescriptorFlags::DataStaticWhileSetAtExecute);859 860 Elem = Elements[2].getElement();861 ASSERT_TRUE(std::holds_alternative<RootDescriptor>(Elem));862 ASSERT_EQ(std::get<RootDescriptor>(Elem).Type, ResourceClass::UAV);863 ASSERT_EQ(std::get<RootDescriptor>(Elem).Flags,864 llvm::dxbc::RootDescriptorFlags::DataVolatile);865 866 Elem = Elements[3].getElement();867 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));868 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::CBuffer);869 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,870 llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute);871 872 Elem = Elements[4].getElement();873 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));874 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::SRV);875 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,876 llvm::dxbc::DescriptorRangeFlags::DataStaticWhileSetAtExecute);877 878 Elem = Elements[5].getElement();879 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));880 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::UAV);881 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,882 llvm::dxbc::DescriptorRangeFlags::DataVolatile);883 884 Elem = Elements[6].getElement();885 ASSERT_TRUE(std::holds_alternative<DescriptorTableClause>(Elem));886 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Type, ResourceClass::Sampler);887 ASSERT_EQ(std::get<DescriptorTableClause>(Elem).Flags,888 llvm::dxbc::DescriptorRangeFlags::None);889 890 ASSERT_TRUE(Consumer->isSatisfied());891}892 893// Invalid Parser Tests894 895TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {896 const llvm::StringLiteral Source = R"cc(897 DescriptorTable()898 space899 )cc";900 901 auto Ctx = createMinimalASTContext();902 StringLiteral *Signature = wrapSource(Ctx, Source);903 904 TrivialModuleLoader ModLoader;905 auto PP = createPP(Source, ModLoader);906 907 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);908 909 // Test correct diagnostic produced910 Consumer->setExpected(diag::err_expected_either);911 ASSERT_TRUE(Parser.parse());912 913 ASSERT_TRUE(Consumer->isSatisfied());914}915 916TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {917 const llvm::StringLiteral Source = R"cc(918 notAnIdentifier919 )cc";920 921 auto Ctx = createMinimalASTContext();922 StringLiteral *Signature = wrapSource(Ctx, Source);923 924 TrivialModuleLoader ModLoader;925 auto PP = createPP(Source, ModLoader);926 927 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);928 929 // Test correct diagnostic produced - invalid token930 Consumer->setExpected(diag::err_hlsl_invalid_token);931 ASSERT_TRUE(Parser.parse());932 933 ASSERT_TRUE(Consumer->isSatisfied());934}935 936TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {937 const llvm::StringLiteral Source = R"cc(938 DescriptorTable939 )cc";940 941 auto Ctx = createMinimalASTContext();942 StringLiteral *Signature = wrapSource(Ctx, Source);943 944 TrivialModuleLoader ModLoader;945 auto PP = createPP(Source, ModLoader);946 947 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);948 949 // Test correct diagnostic produced - expected '(' after DescriptorTable950 Consumer->setExpected(diag::err_expected_after);951 952 ASSERT_TRUE(Parser.parse());953 954 ASSERT_TRUE(Consumer->isSatisfied());955}956 957TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {958 // This test will check that the parsing fails due a mandatory959 // parameter (register) not being specified960 const llvm::StringLiteral Source = R"cc(961 DescriptorTable(962 CBV()963 )964 )cc";965 966 auto Ctx = createMinimalASTContext();967 StringLiteral *Signature = wrapSource(Ctx, Source);968 969 TrivialModuleLoader ModLoader;970 auto PP = createPP(Source, ModLoader);971 972 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);973 974 // Test correct diagnostic produced975 Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);976 ASSERT_TRUE(Parser.parse());977 978 ASSERT_TRUE(Consumer->isSatisfied());979}980 981TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {982 // This test will check that the parsing fails due a mandatory983 // parameter (register) not being specified984 const llvm::StringLiteral Source = R"cc(985 SRV()986 )cc";987 988 auto Ctx = createMinimalASTContext();989 StringLiteral *Signature = wrapSource(Ctx, Source);990 991 TrivialModuleLoader ModLoader;992 auto PP = createPP(Source, ModLoader);993 994 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);995 996 // Test correct diagnostic produced997 Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);998 ASSERT_TRUE(Parser.parse());999 1000 ASSERT_TRUE(Consumer->isSatisfied());1001}1002 1003TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {1004 // This test will check that the parsing fails due a mandatory1005 // parameter (num32BitConstants) not being specified1006 const llvm::StringLiteral Source = R"cc(1007 RootConstants(b0)1008 )cc";1009 1010 auto Ctx = createMinimalASTContext();1011 StringLiteral *Signature = wrapSource(Ctx, Source);1012 1013 TrivialModuleLoader ModLoader;1014 auto PP = createPP(Source, ModLoader);1015 1016 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1017 1018 // Test correct diagnostic produced1019 Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);1020 ASSERT_TRUE(Parser.parse());1021 1022 ASSERT_TRUE(Consumer->isSatisfied());1023}1024 1025TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {1026 // This test will check that the parsing fails due the same mandatory1027 // parameter being specified multiple times1028 const llvm::StringLiteral Source = R"cc(1029 DescriptorTable(1030 CBV(b32, b84)1031 )1032 )cc";1033 1034 auto Ctx = createMinimalASTContext();1035 StringLiteral *Signature = wrapSource(Ctx, Source);1036 1037 TrivialModuleLoader ModLoader;1038 auto PP = createPP(Source, ModLoader);1039 1040 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1041 1042 // Test correct diagnostic produced1043 Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);1044 ASSERT_TRUE(Parser.parse());1045 1046 ASSERT_TRUE(Consumer->isSatisfied());1047}1048 1049TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {1050 // This test will check that the parsing fails due the same mandatory1051 // parameter being specified multiple times1052 const llvm::StringLiteral Source = R"cc(1053 RootConstants(num32BitConstants = 32, num32BitConstants = 24)1054 )cc";1055 1056 auto Ctx = createMinimalASTContext();1057 StringLiteral *Signature = wrapSource(Ctx, Source);1058 1059 TrivialModuleLoader ModLoader;1060 auto PP = createPP(Source, ModLoader);1061 1062 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1063 1064 // Test correct diagnostic produced1065 Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);1066 ASSERT_TRUE(Parser.parse());1067 1068 ASSERT_TRUE(Consumer->isSatisfied());1069}1070 1071TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {1072 // This test will check that the parsing fails due the same optional1073 // parameter being specified multiple times1074 const llvm::StringLiteral Source = R"cc(1075 DescriptorTable(1076 CBV(space = 2, space = 0)1077 )1078 )cc";1079 1080 auto Ctx = createMinimalASTContext();1081 StringLiteral *Signature = wrapSource(Ctx, Source);1082 1083 TrivialModuleLoader ModLoader;1084 auto PP = createPP(Source, ModLoader);1085 1086 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1087 1088 // Test correct diagnostic produced1089 Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);1090 ASSERT_TRUE(Parser.parse());1091 1092 ASSERT_TRUE(Consumer->isSatisfied());1093}1094 1095TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {1096 // This test will check that the parsing fails due the same optional1097 // parameter being specified multiple times1098 const llvm::StringLiteral Source = R"cc(1099 RootConstants(1100 visibility = Shader_Visibility_All,1101 b0, num32BitConstants = 1,1102 visibility = Shader_Visibility_Pixel1103 )1104 )cc";1105 1106 auto Ctx = createMinimalASTContext();1107 StringLiteral *Signature = wrapSource(Ctx, Source);1108 1109 TrivialModuleLoader ModLoader;1110 auto PP = createPP(Source, ModLoader);1111 1112 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1113 1114 // Test correct diagnostic produced1115 Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);1116 ASSERT_TRUE(Parser.parse());1117 1118 ASSERT_TRUE(Consumer->isSatisfied());1119}1120 1121TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {1122 // This test will check that the lexing fails due to an integer overflow1123 const llvm::StringLiteral Source = R"cc(1124 DescriptorTable(1125 CBV(b4294967296)1126 )1127 )cc";1128 1129 auto Ctx = createMinimalASTContext();1130 StringLiteral *Signature = wrapSource(Ctx, Source);1131 1132 TrivialModuleLoader ModLoader;1133 auto PP = createPP(Source, ModLoader);1134 1135 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1136 1137 // Test correct diagnostic produced1138 Consumer->setExpected(diag::err_hlsl_number_literal_overflow);1139 ASSERT_TRUE(Parser.parse());1140 1141 ASSERT_TRUE(Consumer->isSatisfied());1142}1143 1144TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {1145 // This test will check that parsing fails due to a unsigned integer having1146 // too large of a magnitude to be interpreted as its negative1147 const llvm::StringLiteral Source = R"cc(1148 StaticSampler(s0, mipLODBias = -4294967295)1149 )cc";1150 1151 auto Ctx = createMinimalASTContext();1152 StringLiteral *Signature = wrapSource(Ctx, Source);1153 1154 TrivialModuleLoader ModLoader;1155 auto PP = createPP(Source, ModLoader);1156 1157 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1158 1159 // Test correct diagnostic produced1160 Consumer->setExpected(diag::err_hlsl_number_literal_overflow);1161 ASSERT_TRUE(Parser.parse());1162 1163 ASSERT_TRUE(Consumer->isSatisfied());1164}1165 1166TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {1167 // This test will check that the lexing fails due to a float overflow1168 const llvm::StringLiteral Source = R"cc(1169 StaticSampler(s0, mipLODBias = 3.402823467e+38F)1170 )cc";1171 1172 auto Ctx = createMinimalASTContext();1173 StringLiteral *Signature = wrapSource(Ctx, Source);1174 1175 TrivialModuleLoader ModLoader;1176 auto PP = createPP(Source, ModLoader);1177 1178 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1179 1180 // Test correct diagnostic produced1181 Consumer->setExpected(diag::err_hlsl_number_literal_overflow);1182 ASSERT_TRUE(Parser.parse());1183 1184 ASSERT_TRUE(Consumer->isSatisfied());1185}1186 1187TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {1188 // This test will check that the lexing fails due to negative float overflow1189 const llvm::StringLiteral Source = R"cc(1190 StaticSampler(s0, mipLODBias = -3.402823467e+38F)1191 )cc";1192 1193 auto Ctx = createMinimalASTContext();1194 StringLiteral *Signature = wrapSource(Ctx, Source);1195 1196 TrivialModuleLoader ModLoader;1197 auto PP = createPP(Source, ModLoader);1198 1199 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1200 1201 // Test correct diagnostic produced1202 Consumer->setExpected(diag::err_hlsl_number_literal_overflow);1203 ASSERT_TRUE(Parser.parse());1204 1205 ASSERT_TRUE(Consumer->isSatisfied());1206}1207 1208TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {1209 // This test will check that the lexing fails due to an overflow of double1210 const llvm::StringLiteral Source = R"cc(1211 StaticSampler(s0, mipLODBias = 1.e+500)1212 )cc";1213 1214 auto Ctx = createMinimalASTContext();1215 StringLiteral *Signature = wrapSource(Ctx, Source);1216 1217 TrivialModuleLoader ModLoader;1218 auto PP = createPP(Source, ModLoader);1219 1220 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1221 1222 // Test correct diagnostic produced1223 Consumer->setExpected(diag::err_hlsl_number_literal_overflow);1224 ASSERT_TRUE(Parser.parse());1225 1226 ASSERT_TRUE(Consumer->isSatisfied());1227}1228 1229TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {1230 // This test will check that the lexing fails due to double underflow1231 const llvm::StringLiteral Source = R"cc(1232 StaticSampler(s0, mipLODBias = 10e-309)1233 )cc";1234 1235 auto Ctx = createMinimalASTContext();1236 StringLiteral *Signature = wrapSource(Ctx, Source);1237 1238 TrivialModuleLoader ModLoader;1239 auto PP = createPP(Source, ModLoader);1240 1241 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1242 1243 // Test correct diagnostic produced1244 Consumer->setExpected(diag::err_hlsl_number_literal_underflow);1245 ASSERT_TRUE(Parser.parse());1246 1247 ASSERT_TRUE(Consumer->isSatisfied());1248}1249 1250TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {1251 // This test will check that parsing fails when a non-zero integer literal1252 // is given to flags1253 const llvm::StringLiteral Source = R"cc(1254 DescriptorTable(1255 CBV(b0, flags = 3)1256 )1257 )cc";1258 1259 auto Ctx = createMinimalASTContext();1260 StringLiteral *Signature = wrapSource(Ctx, Source);1261 1262 TrivialModuleLoader ModLoader;1263 auto PP = createPP(Source, ModLoader);1264 1265 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1266 1267 // Test correct diagnostic produced1268 Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);1269 ASSERT_TRUE(Parser.parse());1270 1271 ASSERT_TRUE(Consumer->isSatisfied());1272}1273 1274TEST_F(ParseHLSLRootSignatureTest, InvalidRootElementMissingCommaTest) {1275 // This test will check that an error is produced when there is a missing1276 // comma between parameters1277 const llvm::StringLiteral Source = R"cc(1278 RootFlags()1279 RootConstants(num32BitConstants = 1, b0)1280 )cc";1281 1282 auto Ctx = createMinimalASTContext();1283 StringLiteral *Signature = wrapSource(Ctx, Source);1284 1285 TrivialModuleLoader ModLoader;1286 auto PP = createPP(Source, ModLoader);1287 1288 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1289 1290 // Test correct diagnostic produced1291 Consumer->setExpected(diag::err_expected_either);1292 ASSERT_TRUE(Parser.parse());1293 1294 ASSERT_TRUE(Consumer->isSatisfied());1295}1296 1297TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorTableMissingCommaTest) {1298 // This test will check that an error is produced when there is a missing1299 // comma between parameters1300 const llvm::StringLiteral Source = R"cc(1301 DescriptorTable(1302 CBV(b0)1303 visibility = SHADER_VISIBILITY_ALL1304 )1305 )cc";1306 1307 auto Ctx = createMinimalASTContext();1308 StringLiteral *Signature = wrapSource(Ctx, Source);1309 1310 TrivialModuleLoader ModLoader;1311 auto PP = createPP(Source, ModLoader);1312 1313 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1314 1315 // Test correct diagnostic produced1316 Consumer->setExpected(diag::err_expected_either);1317 ASSERT_TRUE(Parser.parse());1318 1319 ASSERT_TRUE(Consumer->isSatisfied());1320}1321 1322TEST_F(ParseHLSLRootSignatureTest, InvalidRootConstantParamsCommaTest) {1323 // This test will check that an error is produced when there is a missing1324 // comma between parameters1325 const llvm::StringLiteral Source = R"cc(1326 RootConstants(1327 num32BitConstants = 11328 b01329 )1330 )cc";1331 1332 auto Ctx = createMinimalASTContext();1333 StringLiteral *Signature = wrapSource(Ctx, Source);1334 1335 TrivialModuleLoader ModLoader;1336 auto PP = createPP(Source, ModLoader);1337 1338 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1339 1340 // Test correct diagnostic produced1341 Consumer->setExpected(diag::err_expected_either);1342 ASSERT_TRUE(Parser.parse());1343 1344 ASSERT_TRUE(Consumer->isSatisfied());1345}1346 1347TEST_F(ParseHLSLRootSignatureTest, InvalidRootDescriptorParamsCommaTest) {1348 // This test will check that an error is produced when there is a missing1349 // comma between parameters1350 const llvm::StringLiteral Source = R"cc(1351 CBV(1352 b01353 flags = 01354 )1355 )cc";1356 1357 auto Ctx = createMinimalASTContext();1358 StringLiteral *Signature = wrapSource(Ctx, Source);1359 1360 TrivialModuleLoader ModLoader;1361 auto PP = createPP(Source, ModLoader);1362 1363 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1364 1365 // Test correct diagnostic produced1366 Consumer->setExpected(diag::err_expected_either);1367 ASSERT_TRUE(Parser.parse());1368 1369 ASSERT_TRUE(Consumer->isSatisfied());1370}1371 1372TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorClauseParamsCommaTest) {1373 // This test will check that an error is produced when there is a missing1374 // comma between parameters1375 const llvm::StringLiteral Source = R"cc(1376 DescriptorTable(1377 UAV(1378 u01379 flags = 01380 )1381 )1382 )cc";1383 1384 auto Ctx = createMinimalASTContext();1385 StringLiteral *Signature = wrapSource(Ctx, Source);1386 1387 TrivialModuleLoader ModLoader;1388 auto PP = createPP(Source, ModLoader);1389 1390 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1391 1392 // Test correct diagnostic produced1393 Consumer->setExpected(diag::err_expected_either);1394 ASSERT_TRUE(Parser.parse());1395 1396 ASSERT_TRUE(Consumer->isSatisfied());1397}1398 1399TEST_F(ParseHLSLRootSignatureTest, InvalidStaticSamplerCommaTest) {1400 // This test will check that an error is produced when there is a missing1401 // comma between parameters1402 const llvm::StringLiteral Source = R"cc(1403 StaticSampler(1404 s01405 maxLOD = 31406 )1407 )cc";1408 1409 auto Ctx = createMinimalASTContext();1410 StringLiteral *Signature = wrapSource(Ctx, Source);1411 1412 TrivialModuleLoader ModLoader;1413 auto PP = createPP(Source, ModLoader);1414 1415 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1416 1417 // Test correct diagnostic produced1418 Consumer->setExpected(diag::err_expected_either);1419 ASSERT_TRUE(Parser.parse());1420 1421 ASSERT_TRUE(Consumer->isSatisfied());1422}1423 1424TEST_F(ParseHLSLRootSignatureTest, InvalidRootDescriptorParamTest) {1425 // This test will check that an error is produced when there is a invalid1426 // value of a parameter1427 const llvm::StringLiteral Source = R"cc(1428 SRV(t0, invalid)1429 )cc";1430 1431 auto Ctx = createMinimalASTContext();1432 StringLiteral *Signature = wrapSource(Ctx, Source);1433 1434 TrivialModuleLoader ModLoader;1435 auto PP = createPP(Source, ModLoader);1436 1437 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1438 1439 // Test correct diagnostic produced1440 Consumer->setExpected(diag::err_hlsl_invalid_token);1441 ASSERT_TRUE(Parser.parse());1442 1443 ASSERT_TRUE(Consumer->isSatisfied());1444}1445 1446TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorTableParamTest) {1447 // This test will check that an error is produced when there is a invalid1448 // value of a parameter1449 const llvm::StringLiteral Source = R"cc(1450 DescriptorTable(1451 visibility = SHADER_VISIBILITY_ALL,1452 invalid1453 )1454 )cc";1455 1456 auto Ctx = createMinimalASTContext();1457 StringLiteral *Signature = wrapSource(Ctx, Source);1458 1459 TrivialModuleLoader ModLoader;1460 auto PP = createPP(Source, ModLoader);1461 1462 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1463 1464 // Test correct diagnostic produced1465 Consumer->setExpected(diag::err_hlsl_invalid_token);1466 ASSERT_TRUE(Parser.parse());1467 1468 ASSERT_TRUE(Consumer->isSatisfied());1469}1470 1471TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorTableClauseParamTest) {1472 // This test will check that an error is produced when there is a invalid1473 // value of a parameter1474 const llvm::StringLiteral Source = R"cc(1475 DescriptorTable(1476 CBV(invalid)1477 )1478 )cc";1479 1480 auto Ctx = createMinimalASTContext();1481 StringLiteral *Signature = wrapSource(Ctx, Source);1482 1483 TrivialModuleLoader ModLoader;1484 auto PP = createPP(Source, ModLoader);1485 1486 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1487 1488 // Test correct diagnostic produced1489 Consumer->setExpected(diag::err_hlsl_invalid_token);1490 ASSERT_TRUE(Parser.parse());1491 1492 ASSERT_TRUE(Consumer->isSatisfied());1493}1494 1495TEST_F(ParseHLSLRootSignatureTest, InvalidStaticSamplerParamTest) {1496 // This test will check that an error is produced when there is a invalid1497 // value of a parameter1498 const llvm::StringLiteral Source = R"cc(1499 StaticSampler(1500 s0,1501 filter = FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT,1502 invalid,1503 comparisonFunc = COMPARISON_EQUAL,1504 )1505 )cc";1506 1507 auto Ctx = createMinimalASTContext();1508 StringLiteral *Signature = wrapSource(Ctx, Source);1509 1510 TrivialModuleLoader ModLoader;1511 auto PP = createPP(Source, ModLoader);1512 1513 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1514 1515 // Test correct diagnostic produced1516 Consumer->setExpected(diag::err_hlsl_invalid_token);1517 ASSERT_TRUE(Parser.parse());1518 1519 ASSERT_TRUE(Consumer->isSatisfied());1520}1521 1522TEST_F(ParseHLSLRootSignatureTest, InvalidVisibilityValueTest) {1523 // This test will check that an error is produced when there is a invalid1524 // value of a parameter1525 const llvm::StringLiteral Source = R"cc(1526 UAV(1527 u0,1528 visibility = SHADER_VISIBILITY_TYPO1529 )1530 )cc";1531 1532 auto Ctx = createMinimalASTContext();1533 StringLiteral *Signature = wrapSource(Ctx, Source);1534 1535 TrivialModuleLoader ModLoader;1536 auto PP = createPP(Source, ModLoader);1537 1538 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1539 1540 // Test correct diagnostic produced1541 Consumer->setExpected(diag::err_hlsl_invalid_token);1542 ASSERT_TRUE(Parser.parse());1543 1544 ASSERT_TRUE(Consumer->isSatisfied());1545}1546 1547TEST_F(ParseHLSLRootSignatureTest, InvalidRegisterValueTest) {1548 // This test will check that an error is produced when there is a invalid1549 // value of a parameter1550 const llvm::StringLiteral Source = R"cc(1551 StaticSampler(1552 b01553 )1554 )cc";1555 1556 auto Ctx = createMinimalASTContext();1557 StringLiteral *Signature = wrapSource(Ctx, Source);1558 1559 TrivialModuleLoader ModLoader;1560 auto PP = createPP(Source, ModLoader);1561 1562 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1563 1564 // Test correct diagnostic produced1565 Consumer->setExpected(diag::err_hlsl_invalid_token);1566 ASSERT_TRUE(Parser.parse());1567 1568 ASSERT_TRUE(Consumer->isSatisfied());1569}1570 1571TEST_F(ParseHLSLRootSignatureTest, InvalidFilterValueTest) {1572 // This test will check that an error is produced when there is a invalid1573 // value of a parameter1574 const llvm::StringLiteral Source = R"cc(1575 StaticSampler(1576 s0,1577 filter = FILTER_TYPO1578 )1579 )cc";1580 1581 auto Ctx = createMinimalASTContext();1582 StringLiteral *Signature = wrapSource(Ctx, Source);1583 1584 TrivialModuleLoader ModLoader;1585 auto PP = createPP(Source, ModLoader);1586 1587 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1588 1589 // Test correct diagnostic produced1590 Consumer->setExpected(diag::err_hlsl_invalid_token);1591 ASSERT_TRUE(Parser.parse());1592 1593 ASSERT_TRUE(Consumer->isSatisfied());1594}1595 1596TEST_F(ParseHLSLRootSignatureTest, InvalidTextureAddressModeValueTest) {1597 // This test will check that an error is produced when there is a invalid1598 // value of a parameter1599 const llvm::StringLiteral Source = R"cc(1600 StaticSampler(1601 s0,1602 addressU = TEXTURE_ADDRESS_MODE_TYPO1603 )1604 )cc";1605 1606 auto Ctx = createMinimalASTContext();1607 StringLiteral *Signature = wrapSource(Ctx, Source);1608 1609 TrivialModuleLoader ModLoader;1610 auto PP = createPP(Source, ModLoader);1611 1612 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1613 1614 // Test correct diagnostic produced1615 Consumer->setExpected(diag::err_hlsl_invalid_token);1616 ASSERT_TRUE(Parser.parse());1617 1618 ASSERT_TRUE(Consumer->isSatisfied());1619}1620 1621TEST_F(ParseHLSLRootSignatureTest, InvalidComparisonFuncValueTest) {1622 // This test will check that an error is produced when there is a invalid1623 // value of a parameter1624 const llvm::StringLiteral Source = R"cc(1625 StaticSampler(1626 s0,1627 comparisonFunc = COMPARISON_FUNC_TYPO1628 )1629 )cc";1630 1631 auto Ctx = createMinimalASTContext();1632 StringLiteral *Signature = wrapSource(Ctx, Source);1633 1634 TrivialModuleLoader ModLoader;1635 auto PP = createPP(Source, ModLoader);1636 1637 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1638 1639 // Test correct diagnostic produced1640 Consumer->setExpected(diag::err_hlsl_invalid_token);1641 ASSERT_TRUE(Parser.parse());1642 1643 ASSERT_TRUE(Consumer->isSatisfied());1644}1645 1646TEST_F(ParseHLSLRootSignatureTest, InvalidStaticBorderColorValueTest) {1647 // This test will check that an error is produced when there is a invalid1648 // value of a parameter1649 const llvm::StringLiteral Source = R"cc(1650 StaticSampler(1651 s0,1652 borderColor = STATIC_BORDER_COLOR_TYPO1653 )1654 )cc";1655 1656 auto Ctx = createMinimalASTContext();1657 StringLiteral *Signature = wrapSource(Ctx, Source);1658 1659 TrivialModuleLoader ModLoader;1660 auto PP = createPP(Source, ModLoader);1661 1662 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1663 1664 // Test correct diagnostic produced1665 Consumer->setExpected(diag::err_hlsl_invalid_token);1666 ASSERT_TRUE(Parser.parse());1667 1668 ASSERT_TRUE(Consumer->isSatisfied());1669}1670 1671TEST_F(ParseHLSLRootSignatureTest, InvalidRootFlagsValueTest) {1672 // This test will check that an error is produced when there is a invalid1673 // value of a parameter1674 const llvm::StringLiteral Source = R"cc(1675 RootFlags( ROOT_FLAG_TYPO )1676 )cc";1677 1678 auto Ctx = createMinimalASTContext();1679 StringLiteral *Signature = wrapSource(Ctx, Source);1680 1681 TrivialModuleLoader ModLoader;1682 auto PP = createPP(Source, ModLoader);1683 1684 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1685 1686 // Test correct diagnostic produced1687 Consumer->setExpected(diag::err_hlsl_invalid_token);1688 ASSERT_TRUE(Parser.parse());1689 1690 ASSERT_TRUE(Consumer->isSatisfied());1691}1692 1693TEST_F(ParseHLSLRootSignatureTest, InvalidRootDescriptorFlagsValueTest) {1694 // This test will check that an error is produced when there is a invalid1695 // value of a parameter1696 const llvm::StringLiteral Source = R"cc(1697 CBV( flags = DATA_STATIC | ROOT_DESRIPTOR_FLAG_TYPO )1698 )cc";1699 1700 auto Ctx = createMinimalASTContext();1701 StringLiteral *Signature = wrapSource(Ctx, Source);1702 1703 TrivialModuleLoader ModLoader;1704 auto PP = createPP(Source, ModLoader);1705 1706 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1707 1708 // Test correct diagnostic produced1709 Consumer->setExpected(diag::err_hlsl_invalid_token);1710 ASSERT_TRUE(Parser.parse());1711 1712 ASSERT_TRUE(Consumer->isSatisfied());1713}1714 1715TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorRangeFlagsValueTest) {1716 // This test will check that an error is produced when there is a invalid1717 // value of a parameter1718 const llvm::StringLiteral Source = R"cc(1719 DescriptorTable(1720 CBV(1721 flags = DATA_STATIC | DESRIPTOR_RANGE_FLAG_TYPO | DESCRIPTORS_VOLATILE1722 )1723 )1724 )cc";1725 1726 auto Ctx = createMinimalASTContext();1727 StringLiteral *Signature = wrapSource(Ctx, Source);1728 1729 TrivialModuleLoader ModLoader;1730 auto PP = createPP(Source, ModLoader);1731 1732 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1733 1734 // Test correct diagnostic produced1735 Consumer->setExpected(diag::err_hlsl_invalid_token);1736 ASSERT_TRUE(Parser.parse());1737 1738 ASSERT_TRUE(Consumer->isSatisfied());1739}1740 1741TEST_F(ParseHLSLRootSignatureTest, InvalidMultipleRootFlagsTest) {1742 // This test will check that an error is produced when there are multiple1743 // root flags provided1744 const llvm::StringLiteral Source = R"cc(1745 RootFlags(DENY_VERTEX_SHADER_ROOT_ACCESS),1746 RootFlags(DENY_PIXEL_SHADER_ROOT_ACCESS)1747 )cc";1748 1749 auto Ctx = createMinimalASTContext();1750 StringLiteral *Signature = wrapSource(Ctx, Source);1751 1752 TrivialModuleLoader ModLoader;1753 auto PP = createPP(Source, ModLoader);1754 1755 hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Signature, *PP);1756 1757 // Test correct diagnostic produced1758 Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);1759 ASSERT_TRUE(Parser.parse());1760 1761 ASSERT_TRUE(Consumer->isSatisfied());1762}1763 1764} // anonymous namespace1765