397 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/Frontend/HLSL/HLSLRootSignature.h"10#include "gtest/gtest.h"11 12using namespace llvm::hlsl::rootsig;13using llvm::dxil::ResourceClass;14 15namespace {16 17TEST(HLSLRootSignatureTest, DescriptorCBVClauseDump) {18 DescriptorTableClause Clause;19 Clause.Type = ResourceClass::CBuffer;20 Clause.Reg = {RegisterType::BReg, 0};21 Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_1);22 23 std::string Out;24 llvm::raw_string_ostream OS(Out);25 OS << Clause;26 OS.flush();27 28 std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, "29 "offset = DescriptorTableOffsetAppend, "30 "flags = DataStaticWhileSetAtExecute)";31 EXPECT_EQ(Out, Expected);32}33 34TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) {35 DescriptorTableClause Clause;36 Clause.Type = ResourceClass::SRV;37 Clause.Reg = {RegisterType::TReg, 0};38 Clause.NumDescriptors = NumDescriptorsUnbounded;39 Clause.Space = 42;40 Clause.Offset = 3;41 Clause.Flags = llvm::dxbc::DescriptorRangeFlags::None;42 43 std::string Out;44 llvm::raw_string_ostream OS(Out);45 OS << Clause;46 OS.flush();47 48 std::string Expected = "SRV(t0, numDescriptors = unbounded, space = 42, "49 "offset = 3, flags = None)";50 EXPECT_EQ(Out, Expected);51}52 53TEST(HLSLRootSignatureTest, DescriptorUAVClauseDump) {54 using llvm::dxbc::DescriptorRangeFlags;55 DescriptorTableClause Clause;56 Clause.Type = ResourceClass::UAV;57 Clause.Reg = {RegisterType::UReg, 92374};58 Clause.NumDescriptors = 3298;59 Clause.Space = 932847;60 Clause.Offset = 1;61 auto ValidDescriptorRangeFlags =62 DescriptorRangeFlags::DescriptorsVolatile |63 DescriptorRangeFlags::DataVolatile |64 DescriptorRangeFlags::DataStaticWhileSetAtExecute |65 DescriptorRangeFlags::DataStatic |66 DescriptorRangeFlags::DescriptorsStaticKeepingBufferBoundsChecks;67 Clause.Flags = ValidDescriptorRangeFlags;68 69 std::string Out;70 llvm::raw_string_ostream OS(Out);71 OS << Clause;72 OS.flush();73 74 std::string Expected =75 "UAV(u92374, numDescriptors = 3298, space = 932847, offset = 1, flags = "76 "DescriptorsVolatile | "77 "DataVolatile | "78 "DataStaticWhileSetAtExecute | "79 "DataStatic | "80 "DescriptorsStaticKeepingBufferBoundsChecks)";81 EXPECT_EQ(Out, Expected);82}83 84TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) {85 DescriptorTableClause Clause;86 Clause.Type = ResourceClass::Sampler;87 Clause.Reg = {RegisterType::SReg, 0};88 Clause.NumDescriptors = 2;89 Clause.Space = 42;90 Clause.Offset = DescriptorTableOffsetAppend;91 Clause.Flags = llvm::dxbc::DescriptorRangeFlags::DescriptorsVolatile;92 93 std::string Out;94 llvm::raw_string_ostream OS(Out);95 OS << Clause;96 OS.flush();97 98 std::string Expected = "Sampler(s0, numDescriptors = 2, space = 42, offset = "99 "DescriptorTableOffsetAppend, "100 "flags = DescriptorsVolatile)";101 EXPECT_EQ(Out, Expected);102}103 104TEST(HLSLRootSignatureTest, DescriptorCBVV10ClauseDump) {105 DescriptorTableClause Clause;106 Clause.Type = ResourceClass::CBuffer;107 Clause.Reg = {RegisterType::BReg, 0};108 Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0);109 110 std::string Out;111 llvm::raw_string_ostream OS(Out);112 OS << Clause;113 OS.flush();114 115 std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, "116 "offset = DescriptorTableOffsetAppend, "117 "flags = DescriptorsVolatile | DataVolatile)";118 EXPECT_EQ(Out, Expected);119}120 121TEST(HLSLRootSignatureTest, DescriptorSamplerV10ClauseDump) {122 DescriptorTableClause Clause;123 Clause.Type = ResourceClass::Sampler;124 Clause.Reg = {RegisterType::SReg, 0};125 Clause.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0);126 127 std::string Out;128 llvm::raw_string_ostream OS(Out);129 OS << Clause;130 OS.flush();131 132 std::string Expected = "Sampler(s0, numDescriptors = 1, space = 0, offset = "133 "DescriptorTableOffsetAppend, "134 "flags = DescriptorsVolatile)";135 EXPECT_EQ(Out, Expected);136}137 138TEST(HLSLRootSignatureTest, DescriptorTableDump) {139 DescriptorTable Table;140 Table.NumClauses = 4;141 Table.Visibility = llvm::dxbc::ShaderVisibility::Geometry;142 143 std::string Out;144 llvm::raw_string_ostream OS(Out);145 OS << Table;146 OS.flush();147 148 std::string Expected =149 "DescriptorTable(numClauses = 4, visibility = Geometry)";150 EXPECT_EQ(Out, Expected);151}152 153TEST(HLSLRootSignatureTest, RootCBVDump) {154 RootDescriptor Descriptor;155 Descriptor.Type = ResourceClass::CBuffer;156 Descriptor.Reg = {RegisterType::BReg, 0};157 Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_1);158 159 std::string Out;160 llvm::raw_string_ostream OS(Out);161 OS << Descriptor;162 OS.flush();163 164 std::string Expected = "RootCBV(b0, space = 0, "165 "visibility = All, "166 "flags = DataStaticWhileSetAtExecute)";167 EXPECT_EQ(Out, Expected);168}169 170TEST(HLSLRootSignatureTest, RootSRV10Dump) {171 RootDescriptor Descriptor;172 Descriptor.Type = ResourceClass::SRV;173 Descriptor.Reg = {RegisterType::TReg, 0};174 Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0);175 176 std::string Out;177 llvm::raw_string_ostream OS(Out);178 OS << Descriptor;179 OS.flush();180 181 std::string Expected = "RootSRV(t0, space = 0, "182 "visibility = All, "183 "flags = DataVolatile)";184 EXPECT_EQ(Out, Expected);185}186 187TEST(HLSLRootSignatureTest, RootUAVV10Dump) {188 RootDescriptor Descriptor;189 Descriptor.Type = ResourceClass::UAV;190 Descriptor.Reg = {RegisterType::UReg, 0};191 Descriptor.setDefaultFlags(llvm::dxbc::RootSignatureVersion::V1_0);192 193 std::string Out;194 llvm::raw_string_ostream OS(Out);195 OS << Descriptor;196 OS.flush();197 198 std::string Expected = "RootUAV(u0, space = 0, "199 "visibility = All, "200 "flags = DataVolatile)";201 EXPECT_EQ(Out, Expected);202}203 204TEST(HLSLRootSignatureTest, RootSRVDump) {205 RootDescriptor Descriptor;206 Descriptor.Type = ResourceClass::SRV;207 Descriptor.Reg = {RegisterType::TReg, 0};208 Descriptor.Space = 42;209 Descriptor.Visibility = llvm::dxbc::ShaderVisibility::Geometry;210 Descriptor.Flags = llvm::dxbc::RootDescriptorFlags::None;211 212 std::string Out;213 llvm::raw_string_ostream OS(Out);214 OS << Descriptor;215 OS.flush();216 217 std::string Expected =218 "RootSRV(t0, space = 42, visibility = Geometry, flags = None)";219 EXPECT_EQ(Out, Expected);220}221 222TEST(HLSLRootSignatureTest, RootUAVDump) {223 using llvm::dxbc::RootDescriptorFlags;224 RootDescriptor Descriptor;225 Descriptor.Type = ResourceClass::UAV;226 Descriptor.Reg = {RegisterType::UReg, 92374};227 Descriptor.Space = 932847;228 Descriptor.Visibility = llvm::dxbc::ShaderVisibility::Hull;229 auto ValidRootDescriptorFlags =230 RootDescriptorFlags::DataVolatile |231 RootDescriptorFlags::DataStaticWhileSetAtExecute |232 RootDescriptorFlags::DataStatic;233 Descriptor.Flags = ValidRootDescriptorFlags;234 235 std::string Out;236 llvm::raw_string_ostream OS(Out);237 OS << Descriptor;238 OS.flush();239 240 std::string Expected =241 "RootUAV(u92374, space = 932847, visibility = Hull, flags = "242 "DataVolatile | "243 "DataStaticWhileSetAtExecute | "244 "DataStatic)";245 EXPECT_EQ(Out, Expected);246}247 248TEST(HLSLRootSignatureTest, DefaultStaticSamplerDump) {249 StaticSampler Sampler;250 Sampler.Reg = {RegisterType::SReg, 0};251 252 std::string Out;253 llvm::raw_string_ostream OS(Out);254 OS << Sampler;255 OS.flush();256 257 std::string Expected = "StaticSampler(s0, "258 "filter = Anisotropic, "259 "addressU = Wrap, "260 "addressV = Wrap, "261 "addressW = Wrap, "262 "mipLODBias = 0.000000e+00, "263 "maxAnisotropy = 16, "264 "comparisonFunc = LessEqual, "265 "borderColor = OpaqueWhite, "266 "minLOD = 0.000000e+00, "267 "maxLOD = 3.402823e+38, "268 "space = 0, "269 "visibility = All, "270 "flags = None"271 ")";272 EXPECT_EQ(Out, Expected);273}274 275TEST(HLSLRootSignatureTest, DefinedStaticSamplerDump) {276 StaticSampler Sampler;277 Sampler.Reg = {RegisterType::SReg, 0};278 279 Sampler.Filter = llvm::dxbc::SamplerFilter::ComparisonMinMagLinearMipPoint;280 Sampler.AddressU = llvm::dxbc::TextureAddressMode::Mirror;281 Sampler.AddressV = llvm::dxbc::TextureAddressMode::Border;282 Sampler.AddressW = llvm::dxbc::TextureAddressMode::Clamp;283 Sampler.MipLODBias = 4.8f;284 Sampler.MaxAnisotropy = 32;285 Sampler.CompFunc = llvm::dxbc::ComparisonFunc::NotEqual;286 Sampler.BorderColor = llvm::dxbc::StaticBorderColor::OpaqueBlack;287 Sampler.MinLOD = 1.0f;288 Sampler.MaxLOD = 32.0f;289 Sampler.Space = 7;290 Sampler.Visibility = llvm::dxbc::ShaderVisibility::Domain;291 Sampler.Flags = llvm::dxbc::StaticSamplerFlags::NonNormalizedCoordinates;292 293 std::string Out;294 llvm::raw_string_ostream OS(Out);295 OS << Sampler;296 OS.flush();297 298 std::string Expected = "StaticSampler(s0, "299 "filter = ComparisonMinMagLinearMipPoint, "300 "addressU = Mirror, "301 "addressV = Border, "302 "addressW = Clamp, "303 "mipLODBias = 4.800000e+00, "304 "maxAnisotropy = 32, "305 "comparisonFunc = NotEqual, "306 "borderColor = OpaqueBlack, "307 "minLOD = 1.000000e+00, "308 "maxLOD = 3.200000e+01, "309 "space = 7, "310 "visibility = Domain, "311 "flags = NonNormalizedCoordinates"312 ")";313 EXPECT_EQ(Out, Expected);314}315 316TEST(HLSLRootSignatureTest, DefaultRootConstantsDump) {317 RootConstants Constants;318 Constants.Num32BitConstants = 1;319 Constants.Reg = {RegisterType::BReg, 3};320 321 std::string Out;322 llvm::raw_string_ostream OS(Out);323 OS << Constants;324 OS.flush();325 326 std::string Expected = "RootConstants(num32BitConstants = 1, b3, space = 0, "327 "visibility = All)";328 EXPECT_EQ(Out, Expected);329}330 331TEST(HLSLRootSignatureTest, SetRootConstantsDump) {332 RootConstants Constants;333 Constants.Num32BitConstants = 983;334 Constants.Reg = {RegisterType::BReg, 34593};335 Constants.Space = 7;336 Constants.Visibility = llvm::dxbc::ShaderVisibility::Pixel;337 338 std::string Out;339 llvm::raw_string_ostream OS(Out);340 OS << Constants;341 OS.flush();342 343 std::string Expected = "RootConstants(num32BitConstants = 983, b34593, "344 "space = 7, visibility = Pixel)";345 EXPECT_EQ(Out, Expected);346}347 348TEST(HLSLRootSignatureTest, NoneRootFlagsDump) {349 llvm::dxbc::RootFlags Flags = llvm::dxbc::RootFlags::None;350 351 std::string Out;352 llvm::raw_string_ostream OS(Out);353 OS << Flags;354 OS.flush();355 356 std::string Expected = "RootFlags(None)";357 EXPECT_EQ(Out, Expected);358}359 360TEST(HLSLRootSignatureTest, AllRootFlagsDump) {361 using llvm::dxbc::RootFlags;362 auto ValidRootFlags = RootFlags::AllowInputAssemblerInputLayout |363 RootFlags::DenyVertexShaderRootAccess |364 RootFlags::DenyHullShaderRootAccess |365 RootFlags::DenyDomainShaderRootAccess |366 RootFlags::DenyGeometryShaderRootAccess |367 RootFlags::DenyPixelShaderRootAccess |368 RootFlags::AllowStreamOutput |369 RootFlags::LocalRootSignature |370 RootFlags::DenyAmplificationShaderRootAccess |371 RootFlags::DenyMeshShaderRootAccess |372 RootFlags::CBVSRVUAVHeapDirectlyIndexed |373 RootFlags::SamplerHeapDirectlyIndexed;374 375 std::string Out;376 llvm::raw_string_ostream OS(Out);377 OS << ValidRootFlags;378 OS.flush();379 380 std::string Expected = "RootFlags("381 "AllowInputAssemblerInputLayout | "382 "DenyVertexShaderRootAccess | "383 "DenyHullShaderRootAccess | "384 "DenyDomainShaderRootAccess | "385 "DenyGeometryShaderRootAccess | "386 "DenyPixelShaderRootAccess | "387 "AllowStreamOutput | "388 "LocalRootSignature | "389 "DenyAmplificationShaderRootAccess | "390 "DenyMeshShaderRootAccess | "391 "CBVSRVUAVHeapDirectlyIndexed | "392 "SamplerHeapDirectlyIndexed)";393 EXPECT_EQ(Out, Expected);394}395 396} // namespace397