|
| 1 | +//===-------- HLSLRootSignatureDumpTest.cpp - RootSignature dump 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-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "llvm/Frontend/HLSL/HLSLRootSignature.h" |
| 10 | +#include "gtest/gtest.h" |
| 11 | + |
| 12 | +using namespace llvm::hlsl::rootsig; |
| 13 | + |
| 14 | +namespace { |
| 15 | + |
| 16 | +TEST(HLSLRootSignatureTest, DescriptorCBVClauseDump) { |
| 17 | + DescriptorTableClause Clause; |
| 18 | + Clause.Type = ClauseType::CBuffer; |
| 19 | + Clause.Reg = {RegisterType::BReg, 0}; |
| 20 | + Clause.setDefaultFlags(); |
| 21 | + |
| 22 | + std::string Out; |
| 23 | + llvm::raw_string_ostream OS(Out); |
| 24 | + Clause.dump(OS); |
| 25 | + OS.flush(); |
| 26 | + |
| 27 | + std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, " |
| 28 | + "offset = DescriptorTableOffsetAppend, " |
| 29 | + "flags = DataStaticWhileSetAtExecute)"; |
| 30 | + EXPECT_EQ(Out, Expected); |
| 31 | +} |
| 32 | + |
| 33 | +TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) { |
| 34 | + DescriptorTableClause Clause; |
| 35 | + Clause.Type = ClauseType::SRV; |
| 36 | + Clause.Reg = {RegisterType::TReg, 0}; |
| 37 | + Clause.NumDescriptors = 2; |
| 38 | + Clause.Space = 42; |
| 39 | + Clause.Offset = 3; |
| 40 | + Clause.Flags = DescriptorRangeFlags::None; |
| 41 | + |
| 42 | + std::string Out; |
| 43 | + llvm::raw_string_ostream OS(Out); |
| 44 | + Clause.dump(OS); |
| 45 | + OS.flush(); |
| 46 | + |
| 47 | + std::string Expected = |
| 48 | + "SRV(t0, numDescriptors = 2, space = 42, offset = 3, flags = None)"; |
| 49 | + EXPECT_EQ(Out, Expected); |
| 50 | +} |
| 51 | + |
| 52 | +TEST(HLSLRootSignatureTest, DescriptorUAVClauseDump) { |
| 53 | + DescriptorTableClause Clause; |
| 54 | + Clause.Type = ClauseType::UAV; |
| 55 | + Clause.Reg = {RegisterType::UReg, 92374}; |
| 56 | + Clause.NumDescriptors = 3298; |
| 57 | + Clause.Space = 932847; |
| 58 | + Clause.Offset = 1; |
| 59 | + Clause.Flags = DescriptorRangeFlags::ValidFlags; |
| 60 | + |
| 61 | + std::string Out; |
| 62 | + llvm::raw_string_ostream OS(Out); |
| 63 | + Clause.dump(OS); |
| 64 | + OS.flush(); |
| 65 | + |
| 66 | + std::string Expected = |
| 67 | + "UAV(u92374, numDescriptors = 3298, space = 932847, offset = 1, flags = " |
| 68 | + "DescriptorsVolatile | " |
| 69 | + "DataVolatile | " |
| 70 | + "DataStaticWhileSetAtExecute | " |
| 71 | + "DataStatic | " |
| 72 | + "DescriptorsStaticKeepingBufferBoundsChecks)"; |
| 73 | + EXPECT_EQ(Out, Expected); |
| 74 | +} |
| 75 | + |
| 76 | +TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) { |
| 77 | + DescriptorTableClause Clause; |
| 78 | + Clause.Type = ClauseType::Sampler; |
| 79 | + Clause.Reg = {RegisterType::SReg, 0}; |
| 80 | + Clause.NumDescriptors = 2; |
| 81 | + Clause.Space = 42; |
| 82 | + Clause.Offset = DescriptorTableOffsetAppend; |
| 83 | + Clause.Flags = DescriptorRangeFlags::ValidSamplerFlags; |
| 84 | + |
| 85 | + std::string Out; |
| 86 | + llvm::raw_string_ostream OS(Out); |
| 87 | + Clause.dump(OS); |
| 88 | + OS.flush(); |
| 89 | + |
| 90 | + std::string Expected = "Sampler(s0, numDescriptors = 2, space = 42, offset = " |
| 91 | + "DescriptorTableOffsetAppend, " |
| 92 | + "flags = DescriptorsVolatile)"; |
| 93 | + EXPECT_EQ(Out, Expected); |
| 94 | +} |
| 95 | + |
| 96 | +TEST(HLSLRootSignatureTest, DescriptorTableDump) { |
| 97 | + DescriptorTable Table; |
| 98 | + Table.NumClauses = 4; |
| 99 | + Table.Visibility = ShaderVisibility::Geometry; |
| 100 | + |
| 101 | + std::string Out; |
| 102 | + llvm::raw_string_ostream OS(Out); |
| 103 | + Table.dump(OS); |
| 104 | + OS.flush(); |
| 105 | + |
| 106 | + std::string Expected = |
| 107 | + "DescriptorTable(numClauses = 4, visibility = Geometry)"; |
| 108 | + EXPECT_EQ(Out, Expected); |
| 109 | +} |
| 110 | + |
| 111 | +} // namespace |
0 commit comments