Skip to content

Commit 58e1789

Browse files
author
joaosaffran
committed
clean up and add more tests
1 parent 3eb5e10 commit 58e1789

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//===----------------------------------------------------------------------===//
1313
#include "DXILRootSignature.h"
1414
#include "DirectX.h"
15-
#include "llvm/ADT/STLForwardCompat.h"
1615
#include "llvm/ADT/StringSwitch.h"
1716
#include "llvm/ADT/Twine.h"
1817
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -31,7 +30,6 @@
3130
#include <cstdint>
3231
#include <optional>
3332
#include <utility>
34-
#include <variant>
3533

3634
using namespace llvm;
3735
using namespace llvm::dxil;
@@ -227,10 +225,7 @@ static bool verifyRegisterSpace(uint32_t RegisterSpace) {
227225
return !(RegisterSpace >= 0xFFFFFFF0 && RegisterSpace <= 0xFFFFFFFF);
228226
}
229227

230-
static bool verifyDescriptorFlag(uint32_t Flags) {
231-
return (Flags & ~0xE) == 0;
232-
}
233-
228+
static bool verifyDescriptorFlag(uint32_t Flags) { return (Flags & ~0xE) == 0; }
234229

235230
static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
236231

@@ -249,37 +244,38 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
249244

250245
assert(dxbc::isValidParameterType(Info.Header.ParameterType) &&
251246
"Invalid value for ParameterType");
252-
253-
247+
254248
auto P = RSD.ParametersContainer.getParameter(&Info);
255-
if(!P)
256-
return reportError(Ctx, "Cannot locate parameter from Header Info");
257-
258-
if( std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)){
259-
auto *Descriptor = std::get<const dxbc::RTS0::v1::RootDescriptor *>(P.value());
249+
if (!P)
250+
return reportError(Ctx, "Cannot locate parameter from Header Info");
251+
252+
if (std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)) {
253+
auto *Descriptor =
254+
std::get<const dxbc::RTS0::v1::RootDescriptor *>(P.value());
260255

261-
if(!verifyRegisterValue(Descriptor->ShaderRegister))
256+
if (!verifyRegisterValue(Descriptor->ShaderRegister))
262257
return reportValueError(Ctx, "ShaderRegister",
263258
Descriptor->ShaderRegister);
264-
265-
if(!verifyRegisterSpace(Descriptor->RegisterSpace))
259+
260+
if (!verifyRegisterSpace(Descriptor->RegisterSpace))
266261
return reportValueError(Ctx, "RegisterSpace",
267262
Descriptor->RegisterSpace);
268263

269-
} else if( std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)){
270-
auto *Descriptor = std::get<const dxbc::RTS0::v2::RootDescriptor *>(P.value());
264+
} else if (std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(
265+
*P)) {
266+
auto *Descriptor =
267+
std::get<const dxbc::RTS0::v2::RootDescriptor *>(P.value());
271268

272-
if(!verifyRegisterValue(Descriptor->ShaderRegister))
269+
if (!verifyRegisterValue(Descriptor->ShaderRegister))
273270
return reportValueError(Ctx, "ShaderRegister",
274271
Descriptor->ShaderRegister);
275-
276-
if(!verifyRegisterSpace(Descriptor->RegisterSpace))
272+
273+
if (!verifyRegisterSpace(Descriptor->RegisterSpace))
277274
return reportValueError(Ctx, "RegisterSpace",
278275
Descriptor->RegisterSpace);
279276

280-
if(!verifyDescriptorFlag(Descriptor->Flags))
281-
return reportValueError(Ctx, "DescriptorFlag",
282-
Descriptor->Flags);
277+
if (!verifyDescriptorFlag(Descriptor->Flags))
278+
return reportValueError(Ctx, "DescriptorFlag", Descriptor->Flags);
283279
}
284280
}
285281

@@ -417,20 +413,21 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
417413
<< "Shader Register: " << Constants->ShaderRegister << "\n";
418414
OS << indent(Space + 2)
419415
<< "Num 32 Bit Values: " << Constants->Num32BitValues << "\n";
420-
} else if (std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)) {
416+
} else if (std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(
417+
*P)) {
421418
auto *Constants = std::get<const dxbc::RTS0::v1::RootDescriptor *>(*P);
422419
OS << indent(Space + 2)
423420
<< "Register Space: " << Constants->RegisterSpace << "\n";
424421
OS << indent(Space + 2)
425422
<< "Shader Register: " << Constants->ShaderRegister << "\n";
426-
} else if (std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)) {
423+
} else if (std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(
424+
*P)) {
427425
auto *Constants = std::get<const dxbc::RTS0::v2::RootDescriptor *>(*P);
428426
OS << indent(Space + 2)
429427
<< "Register Space: " << Constants->RegisterSpace << "\n";
430428
OS << indent(Space + 2)
431429
<< "Shader Register: " << Constants->ShaderRegister << "\n";
432-
OS << indent(Space + 2)
433-
<< "Flags: " << Constants->Flags << "\n";
430+
OS << indent(Space + 2) << "Flags: " << Constants->Flags << "\n";
434431
}
435432
}
436433
Space--;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
2+
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
6+
; CHECK: error: Invalid Root Signature Element: Invalid
7+
; CHECK-NOT: Root Signature Definitions
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
13+
14+
15+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16+
!2 = !{ ptr @main, !3 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"Invalid", i32 0, i32 1, i32 2, i32 3 }

0 commit comments

Comments
 (0)