Skip to content

Commit fa76460

Browse files
joaosaffranjoaosaffran
andauthored
[DirectX] Add Root Signature Version Support and Update Test IR Format (#144957)
Updates the Root Signature metadata parser to extract version information. This requirement was added after the initial parser implementation. --------- Co-authored-by: joaosaffran <[email protected]>
1 parent efd42b9 commit fa76460

24 files changed

+70
-30
lines changed

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ analyzeModule(Module &M) {
309309
return RSDMap;
310310

311311
for (const auto &RSDefNode : RootSignatureNode->operands()) {
312-
if (RSDefNode->getNumOperands() != 2) {
312+
if (RSDefNode->getNumOperands() != 3) {
313313
reportError(Ctx, "Invalid format for Root Signature Definition. Pairs "
314314
"of function, root signature expected.");
315315
continue;
@@ -348,8 +348,14 @@ analyzeModule(Module &M) {
348348
reportError(Ctx, "Root Element is not a metadata node.");
349349
continue;
350350
}
351-
352351
mcdxbc::RootSignatureDesc RSD;
352+
if (std::optional<uint32_t> Version = extractMdIntValue(RSDefNode, 2))
353+
RSD.Version = *Version;
354+
else {
355+
reportError(Ctx, "Invalid RSDefNode value, expected constant int");
356+
continue;
357+
}
358+
353359
// Clang emits the root signature data in dxcontainer following a specific
354360
// sequence. First the header, then the root parameters. So the header
355361
// offset will always equal to the header size.

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ entry:
1818
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1919

2020
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21-
!2 = !{ ptr @main, !3 } ; function, root signature
21+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
2222
!3 = !{ !4 } ; list of root signature elements
2323
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24-
!5 = !{ i32 -1, !6 } ; function, root signature
24+
!5 = !{ i32 -1, !6, i32 2 } ; function, root signature
2525
!6 = !{ !7 } ; list of root signature elements
2626
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ entry:
1818
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1919

2020
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21-
!2 = !{ ptr @main, !3 } ; function, root signature
21+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
2222
!3 = !{ !4 } ; list of root signature elements
2323
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24-
!5 = !{ !3, !6 } ; function, root signature
24+
!5 = !{ !3, !6, i32 2 } ; function, root signature
2525
!6 = !{ !7 } ; list of root signature elements
2626
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-no-root-element-list.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ entry:
1818
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1919

2020
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21-
!2 = !{ ptr @main, null } ; function, root signature
21+
!2 = !{ ptr @main, null, i32 2 } ; function, root signature
2222
!3 = !{ !4 } ; list of root signature elements
2323
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24-
!5 = !{ i32 -1, !6 } ; function, root signature
24+
!5 = !{ i32 -1, !6, i32 2 } ; function, root signature
2525
!6 = !{ !7 } ; list of root signature elements
2626
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-root-element-not-mdnode.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ entry:
1818
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1919

2020
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21-
!2 = !{ ptr @main, i32 -1 } ; function, root signature
21+
!2 = !{ ptr @main, i32 -1, i32 2 } ; function, root signature
2222
!3 = !{ !4 } ; list of root signature elements
2323
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24-
!5 = !{ i32 -1, !6 } ; function, root signature
24+
!5 = !{ i32 -1, !6, i32 2 } ; function, root signature
2525
!6 = !{ !7 } ; list of root signature elements
2626
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515

1616

1717
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
18-
!2 = !{ ptr @main, !3 } ; function, root signature
18+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1919
!3 = !{ !4 } ; list of root signature elements
2020
!4 = !{ !"NOTRootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !4 } ; list of root signature elements
1818
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
1919

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ entry:
1616
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1717

1818
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
19-
!2 = !{ ptr @main, !3 } ; function, root signature
19+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
2020
!3 = !{ !4 } ; list of root signature elements
2121
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
22-
!5 = !{ ptr @anotherMain, !6 } ; function, root signature
22+
!5 = !{ ptr @anotherMain, !6, i32 2 } ; function, root signature
2323
!6 = !{ !7 } ; list of root signature elements
2424
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
2525

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ entry:
1313
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1414

1515
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !4 } ; list of root signature elements
1818
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
19-
!5 = !{ null, !6 } ; function, root signature
19+
!5 = !{ null, !6, i32 2 } ; function, root signature
2020
!6 = !{ !7 } ; list of root signature elements
2121
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters-Invalid-ParameterIsNotString.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ entry:
1414
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515

1616
!dx.rootsignatures = !{!0}
17-
!0 = !{ ptr @main, !1 }
17+
!0 = !{ ptr @main, !1, i32 2 }
1818
!1 = !{ !2 }
1919
!2 = !{ i32 0 }

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters-Validation-Error.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515

1616

1717
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
18-
!2 = !{ ptr @main, !3 } ; function, root signature
18+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1919
!3 = !{ !5 } ; list of root signature elements
2020
!5 = !{ !"RootConstants", i32 255, i32 1, i32 2, i32 3 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ entry:
1111
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1212

1313
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
14-
!2 = !{ ptr @main, !3 } ; function, root signature
14+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1515
!3 = !{ !4, !5, !6 } ; list of root signature elements
1616
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
1717
!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, i32 3 }

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants-Invalid-Num32BitValues.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ entry:
1111
}
1212

1313
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
14-
!2 = !{ ptr @main, !3 } ; function, root signature
14+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1515
!3 = !{ !5 } ; list of root signature elements
1616
!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, !"Invalid" }

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants-Invalid-RegisterSpace.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootConstants", i32 0, i32 1, !"Invalid", i32 3 }

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootConstants-Invalid-ShaderRegister.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootConstants", i32 0, !"Invalid", i32 2, i32 3 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, i32 3 }
1919

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 3 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"Invalid", i32 0, i32 1, i32 2, i32 3 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootCBV", i32 0, i32 1, i32 4294967280, i32 0 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootCBV", i32 0, i32 4294967295, i32 2, i32 3 }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1313

1414

1515
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16-
!2 = !{ ptr @main, !3 } ; function, root signature
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1717
!3 = !{ !5 } ; list of root signature elements
1818
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 8 }
1919

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
2+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
3+
4+
target triple = "dxil-unknown-shadermodel6.0-compute"
5+
6+
; CHECK: @dx.rts0 = private constant [44 x i8] c"{{.*}}", section "RTS0", align 4
7+
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, i32 1 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 8 }
19+
20+
; DXC: - Name: RTS0
21+
; DXC-NEXT: Size: 44
22+
; DXC-NEXT: RootSignature:
23+
; DXC-NEXT: Version: 1
24+
; DXC-NEXT: NumRootParameters: 1
25+
; DXC-NEXT: RootParametersOffset: 24
26+
; DXC-NEXT: NumStaticSamplers: 0
27+
; DXC-NEXT: StaticSamplersOffset: 0
28+
; DXC-NEXT: Parameters:
29+
; DXC-NEXT: - ParameterType: 2
30+
; DXC-NEXT: ShaderVisibility: 0
31+
; DXC-NEXT: Descriptor:
32+
; DXC-NEXT: RegisterSpace: 2
33+
; DXC-NEXT: ShaderRegister: 1
34+
; DXC-NOT: DATA_STATIC: true

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515

1616

1717
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
18-
!2 = !{ ptr @main, !3 } ; function, root signature
18+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1919
!3 = !{ !"NOTRootElements" } ; list of root signature elements

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootFlags-VisibilityValidationError.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1515

1616

1717
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
18-
!2 = !{ ptr @main, !3 } ; function, root signature
18+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
1919
!3 = !{ !4 } ; list of root signature elements
2020
!4 = !{ !"RootFlags", i32 2147487744 } ; 1 = allow_input_assembler_input_layout

0 commit comments

Comments
 (0)