Skip to content

Commit 3eb5e10

Browse files
author
joaosaffran
committed
adding tests
1 parent 4f7f998 commit 3eb5e10

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed

llvm/include/llvm/BinaryFormat/DXContainerConstants.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
7878
// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name).
7979
#ifdef ROOT_DESCRIPTOR_FLAG
8080

81+
ROOT_DESCRIPTOR_FLAG(0, NONE)
8182
ROOT_DESCRIPTOR_FLAG(1, DATA_VOLATILE)
8283
ROOT_DESCRIPTOR_FLAG(2, DATA_STATIC_WHILE_SET_AT_EXECUTE)
8384
ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313
#include "DXILRootSignature.h"
1414
#include "DirectX.h"
15+
#include "llvm/ADT/STLForwardCompat.h"
1516
#include "llvm/ADT/StringSwitch.h"
1617
#include "llvm/ADT/Twine.h"
1718
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -30,6 +31,7 @@
3031
#include <cstdint>
3132
#include <optional>
3233
#include <utility>
34+
#include <variant>
3335

3436
using namespace llvm;
3537
using namespace llvm::dxil;
@@ -217,6 +219,19 @@ static bool verifyVersion(uint32_t Version) {
217219
return (Version == 1 || Version == 2);
218220
}
219221

222+
static bool verifyRegisterValue(uint32_t RegisterValue) {
223+
return !(RegisterValue == 0xFFFFFFFF);
224+
}
225+
226+
static bool verifyRegisterSpace(uint32_t RegisterSpace) {
227+
return !(RegisterSpace >= 0xFFFFFFF0 && RegisterSpace <= 0xFFFFFFFF);
228+
}
229+
230+
static bool verifyDescriptorFlag(uint32_t Flags) {
231+
return (Flags & ~0xE) == 0;
232+
}
233+
234+
220235
static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
221236

222237
if (!verifyVersion(RSD.Version)) {
@@ -234,6 +249,38 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
234249

235250
assert(dxbc::isValidParameterType(Info.Header.ParameterType) &&
236251
"Invalid value for ParameterType");
252+
253+
254+
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());
260+
261+
if(!verifyRegisterValue(Descriptor->ShaderRegister))
262+
return reportValueError(Ctx, "ShaderRegister",
263+
Descriptor->ShaderRegister);
264+
265+
if(!verifyRegisterSpace(Descriptor->RegisterSpace))
266+
return reportValueError(Ctx, "RegisterSpace",
267+
Descriptor->RegisterSpace);
268+
269+
} else if( std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)){
270+
auto *Descriptor = std::get<const dxbc::RTS0::v2::RootDescriptor *>(P.value());
271+
272+
if(!verifyRegisterValue(Descriptor->ShaderRegister))
273+
return reportValueError(Ctx, "ShaderRegister",
274+
Descriptor->ShaderRegister);
275+
276+
if(!verifyRegisterSpace(Descriptor->RegisterSpace))
277+
return reportValueError(Ctx, "RegisterSpace",
278+
Descriptor->RegisterSpace);
279+
280+
if(!verifyDescriptorFlag(Descriptor->Flags))
281+
return reportValueError(Ctx, "DescriptorFlag",
282+
Descriptor->Flags);
283+
}
237284
}
238285

239286
return false;
@@ -370,6 +417,20 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
370417
<< "Shader Register: " << Constants->ShaderRegister << "\n";
371418
OS << indent(Space + 2)
372419
<< "Num 32 Bit Values: " << Constants->Num32BitValues << "\n";
420+
} else if (std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)) {
421+
auto *Constants = std::get<const dxbc::RTS0::v1::RootDescriptor *>(*P);
422+
OS << indent(Space + 2)
423+
<< "Register Space: " << Constants->RegisterSpace << "\n";
424+
OS << indent(Space + 2)
425+
<< "Shader Register: " << Constants->ShaderRegister << "\n";
426+
} else if (std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)) {
427+
auto *Constants = std::get<const dxbc::RTS0::v2::RootDescriptor *>(*P);
428+
OS << indent(Space + 2)
429+
<< "Register Space: " << Constants->RegisterSpace << "\n";
430+
OS << indent(Space + 2)
431+
<< "Shader Register: " << Constants->ShaderRegister << "\n";
432+
OS << indent(Space + 2)
433+
<< "Flags: " << Constants->Flags << "\n";
373434
}
374435
}
375436
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 value for DescriptorFlag: 3
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 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 3 }
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 value for RegisterSpace: 4294967280
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 = !{ !"RootCBV", i32 0, i32 1, i32 4294967280, i32 0 }
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 value for ShaderRegister: 4294967295
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 = !{ !"RootCBV", i32 0, i32 4294967295, i32 2, i32 3 }

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootDescriptor.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
1616
!2 = !{ ptr @main, !3 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
18-
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 3 }
18+
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 8 }
1919

2020
; DXC: - Name: RTS0
2121
; DXC-NEXT: Size: 48
@@ -31,4 +31,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
3131
; DXC-NEXT: Descriptor:
3232
; DXC-NEXT: RegisterSpace: 2
3333
; DXC-NEXT: ShaderRegister: 1
34-
; DXC-NEXT: DATA_VOLATILE: true
34+
; DXC-NEXT: DATA_STATIC: true

0 commit comments

Comments
 (0)