Skip to content

Commit c4b78d8

Browse files
author
joaosaffran
committed
address comments
1 parent cadc296 commit c4b78d8

File tree

5 files changed

+76
-21
lines changed

5 files changed

+76
-21
lines changed

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,50 +47,53 @@ static bool reportValueError(LLVMContext *Ctx, Twine ParamName, uint32_t Value,
4747
return true;
4848
}
4949

50+
static bool extractMdIntValue(uint32_t &Value, MDNode *Node,
51+
unsigned int OpId) {
52+
auto *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(OpId).get());
53+
if (CI == nullptr)
54+
return true;
55+
56+
Value = CI->getZExtValue();
57+
return false;
58+
}
59+
5060
static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
5161
MDNode *RootFlagNode) {
5262

5363
if (RootFlagNode->getNumOperands() != 2)
5464
return reportError(Ctx, "Invalid format for RootFlag Element");
5565

56-
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
57-
RSD.Flags = Flag->getZExtValue();
66+
if (extractMdIntValue(RSD.Flags, RootFlagNode, 1))
67+
return reportError(Ctx, "Invalid value for RootFlag");
5868

5969
return false;
6070
}
6171

62-
static bool extractMdValue(uint32_t &Value, MDNode *Node, unsigned int OpId) {
63-
64-
auto *CI = mdconst::extract<ConstantInt>(Node->getOperand(OpId));
65-
if (CI == nullptr)
66-
return true;
67-
68-
Value = CI->getZExtValue();
69-
return false;
70-
}
71-
7272
static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
73-
MDNode *RootFlagNode) {
73+
MDNode *RootConstantNode) {
7474

75-
if (RootFlagNode->getNumOperands() != 5)
75+
if (RootConstantNode->getNumOperands() != 5)
7676
return reportError(Ctx, "Invalid format for RootConstants Element");
7777

7878
mcdxbc::RootParameter NewParameter;
7979
NewParameter.Header.ParameterType = dxbc::RootParameterType::Constants32Bit;
8080

8181
uint32_t SV;
82-
if (extractMdValue(SV, RootFlagNode, 1))
82+
if (extractMdIntValue(SV, RootConstantNode, 1))
8383
return reportError(Ctx, "Invalid value for ShaderVisibility");
8484

8585
NewParameter.Header.ShaderVisibility = (dxbc::ShaderVisibility)SV;
8686

87-
if (extractMdValue(NewParameter.Constants.ShaderRegister, RootFlagNode, 2))
87+
if (extractMdIntValue(NewParameter.Constants.ShaderRegister, RootConstantNode,
88+
2))
8889
return reportError(Ctx, "Invalid value for ShaderRegister");
8990

90-
if (extractMdValue(NewParameter.Constants.RegisterSpace, RootFlagNode, 3))
91+
if (extractMdIntValue(NewParameter.Constants.RegisterSpace, RootConstantNode,
92+
3))
9193
return reportError(Ctx, "Invalid value for RegisterSpace");
9294

93-
if (extractMdValue(NewParameter.Constants.Num32BitValues, RootFlagNode, 4))
95+
if (extractMdIntValue(NewParameter.Constants.Num32BitValues, RootConstantNode,
96+
4))
9497
return reportError(Ctx, "Invalid value for Num32BitValues");
9598

9699
RSD.Parameters.push_back(NewParameter);
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+
; CHECK: error: Invalid value for Num32BitValues
6+
; CHECK-NOT: Root Signature Definitions
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 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"RootConstants", i32 0, i32 1, i32 2, !"Invalid" }
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+
; CHECK: error: Invalid value for RegisterSpace
6+
; CHECK-NOT: Root Signature Definitions
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 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"RootConstants", i32 0, i32 1, !"Invalid", 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+
; CHECK: error: Invalid value for ShaderRegister
6+
; CHECK-NOT: Root Signature Definitions
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 } ; function, root signature
17+
!3 = !{ !5 } ; list of root signature elements
18+
!5 = !{ !"RootConstants", i32 0, !"Invalid", i32 2, i32 3 }

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
1414

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

2120
; DXC: - Name: RTS0
@@ -33,4 +32,3 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
3332
; DXC-NEXT: Num32BitValues: 3
3433
; DXC-NEXT: RegisterSpace: 2
3534
; DXC-NEXT: ShaderRegister: 1
36-
; DXC-NEXT: AllowInputAssemblerInputLayout: true

0 commit comments

Comments
 (0)