Skip to content

Commit 936fe9b

Browse files
joaosaffranjoaosaffran
andauthored
[HLSL] Add more tests to root signature metadata extraction (#127283)
This PR adds a few more tests to validate some error scenarios of root signature metadata representation. Closes: #127280 --------- Co-authored-by: joaosaffran <[email protected]>
1 parent 56e0bf2 commit 936fe9b

File tree

5 files changed

+113
-3
lines changed

5 files changed

+113
-3
lines changed

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,17 @@ analyzeModule(Module &M) {
150150
continue;
151151
}
152152

153-
MDNode *RootElementListNode =
154-
dyn_cast<MDNode>(RSDefNode->getOperand(1).get());
153+
Metadata *RootElementListOperand = RSDefNode->getOperand(1).get();
155154

155+
if (RootElementListOperand == nullptr) {
156+
reportError(Ctx, "Root Element mdnode is null.");
157+
continue;
158+
}
159+
160+
MDNode *RootElementListNode = dyn_cast<MDNode>(RootElementListOperand);
156161
if (RootElementListNode == nullptr) {
157-
reportError(Ctx, "Missing Root Element List Metadata node.");
162+
reportError(Ctx, "Root Element is not a metadata node.");
163+
continue;
158164
}
159165

160166
mcdxbc::RootSignatureDesc RSD;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
; CHECK: error: First element of root signature is not a Function
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
13+
define void @anotherMain() #0 {
14+
entry:
15+
ret void
16+
}
17+
18+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
19+
20+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21+
!2 = !{ ptr @main, !3 } ; function, root signature
22+
!3 = !{ !4 } ; list of root signature elements
23+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24+
!5 = !{ i32 -1, !6 } ; function, root signature
25+
!6 = !{ !7 } ; list of root signature elements
26+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
; CHECK: error: First element of root signature is not a Value
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
13+
define void @anotherMain() #0 {
14+
entry:
15+
ret void
16+
}
17+
18+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
19+
20+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21+
!2 = !{ ptr @main, !3 } ; function, root signature
22+
!3 = !{ !4 } ; list of root signature elements
23+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24+
!5 = !{ !3, !6 } ; function, root signature
25+
!6 = !{ !7 } ; list of root signature elements
26+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
; CHECK: error: Root Element mdnode is null.
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
13+
define void @anotherMain() #0 {
14+
entry:
15+
ret void
16+
}
17+
18+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
19+
20+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21+
!2 = !{ ptr @main, null } ; function, root signature
22+
!3 = !{ !4 } ; list of root signature elements
23+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24+
!5 = !{ i32 -1, !6 } ; function, root signature
25+
!6 = !{ !7 } ; list of root signature elements
26+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
; CHECK: error: Root Element is not a metadata node.
6+
; CHECK-NOT: Root Signature Definitions
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
13+
define void @anotherMain() #0 {
14+
entry:
15+
ret void
16+
}
17+
18+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
19+
20+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21+
!2 = !{ ptr @main, i32 -1 } ; function, root signature
22+
!3 = !{ !4 } ; list of root signature elements
23+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24+
!5 = !{ i32 -1, !6 } ; function, root signature
25+
!6 = !{ !7 } ; list of root signature elements
26+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

0 commit comments

Comments
 (0)