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