Skip to content

Commit 74f5ee4

Browse files
authored
[DXIL][Analysis] Add validator version to info collected by Module Metadata Analysis (#104828)
Add Validator Version to information collected by Module Metadata Analysis pass. An earlier change (#104040) added a default hardcoded value for validator version to be associated with DXIL module created during HLSL source compilation. Add tests to verify validator version info collected - Updated existing tests - Added a test with validator version specified in DXIL metadata
1 parent 9bb5556 commit 74f5ee4

14 files changed

+79
-22
lines changed

llvm/include/llvm/Analysis/DXILMetadataAnalysis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct ModuleMetadataInfo {
2323
VersionTuple DXILVersion{};
2424
VersionTuple ShaderModelVersion{};
2525
Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
26+
VersionTuple ValidatorVersion{};
2627

2728
void print(raw_ostream &OS) const;
2829
};

llvm/lib/Analysis/DXILMetadataAnalysis.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
2525
MMDAI.DXILVersion = TT.getDXILVersion();
2626
MMDAI.ShaderModelVersion = TT.getOSVersion();
2727
MMDAI.ShaderStage = TT.getEnvironment();
28+
NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
29+
if (ValidatorVerNode) {
30+
auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
31+
auto *MajorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(0));
32+
auto *MinorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(1));
33+
MMDAI.ValidatorVersion =
34+
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
35+
}
2836
return MMDAI;
2937
}
3038

@@ -33,6 +41,7 @@ void ModuleMetadataInfo::print(raw_ostream &OS) const {
3341
OS << "DXIL Version : " << DXILVersion.getAsString() << "\n";
3442
OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage)
3543
<< "\n";
44+
OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n";
3645
}
3746

3847
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.0-vertex"
66
; CHECK: ![[DXVER]] = !{i32 1, i32 0}
77

88
; ANALYSIS: Shader Model Version : 6.0
9-
; ANALYSIS: DXIL Version : 1.0
10-
; ANALYSIS: Shader Stage : vertex
9+
; ANALYSIS-NEXT: DXIL Version : 1.0
10+
; ANALYSIS-NEXT: Shader Stage : vertex
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.8-compute"
66
; CHECK: ![[DXVER]] = !{i32 1, i32 8}
77

88
; ANALYSIS: Shader Model Version : 6.8
9-
; ANALYSIS: DXIL Version : 1.8
10-
; ANALYSIS: Shader Stage : compute
9+
; ANALYSIS-NEXT: DXIL Version : 1.8
10+
; ANALYSIS-NEXT: Shader Stage : compute
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
2+
; Verify correctness of Shader Model version, DXIL version, Shader stage and Validator version
3+
; obtained by Module Metadata Analysis pass from the metadata specified in the source.
4+
5+
; ANALYSIS: Shader Model Version : 6.6
6+
; ANALYSIS-NEXT: DXIL Version : 1.6
7+
; ANALYSIS-NEXT: Shader Stage : compute
8+
; ANALYSIS-NEXT: Validator Version : 1.8
9+
; ANALYSIS-EMPTY:
10+
11+
; Function Attrs: nounwind memory(none)
12+
define void @main() local_unnamed_addr #0 {
13+
entry:
14+
ret void
15+
}
16+
17+
attributes #0 = { nounwind memory(none) }
18+
19+
!dx.valver = !{!0}
20+
!dx.shaderModel = !{!2}
21+
!dx.version = !{!3}
22+
23+
!0 = !{i32 1, i32 8}
24+
!2 = !{!"cs", i32 6, i32 6}
25+
!3 = !{i32 1, i32 6}

llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6-amplification"
66
; CHECK: ![[SM]] = !{!"as", i32 6, i32 0}
77

88
; ANALYSIS: Shader Model Version : 6
9-
; ANALYSIS: DXIL Version : 1.0
10-
; ANALYSIS: Shader Stage : amplification
9+
; ANALYSIS-NEXT: DXIL Version : 1.0
10+
; ANALYSIS-NEXT: Shader Stage : amplification
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs-val-ver-0.0.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1"
1717
!0 = !{i32 0, i32 0}
1818

1919
; ANALYSIS: Shader Model Version : 6.6
20-
; ANALYSIS: DXIL Version : 1.6
21-
; ANALYSIS: Shader Stage : compute
20+
; ANALYSIS-NEXT: DXIL Version : 1.6
21+
; ANALYSIS-NEXT: Shader Stage : compute
22+
; ANALYSIS-NEXT: Validator Version : 0
23+
; ANALYSIS-EMPTY:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ target triple = "dxil-pc-shadermodel6.6-compute"
88
; CHECK: ![[SM]] = !{!"cs", i32 6, i32 6}
99

1010
; ANALYSIS: Shader Model Version : 6.6
11-
; ANALYSIS: DXIL Version : 1.6
12-
; ANALYSIS: Shader Stage : compute
11+
; ANALYSIS-NEXT: DXIL Version : 1.6
12+
; ANALYSIS-NEXT: Shader Stage : compute
13+
; ANALYSIS-NEXT: Validator Version : 0
14+
; ANALYSIS-EMPTY:
1315

1416
define void @entry() #0 {
1517
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-geometry"
66
; CHECK: ![[SM]] = !{!"gs", i32 6, i32 6}
77

88
; ANALYSIS: Shader Model Version : 6.6
9-
; ANALYSIS: DXIL Version : 1.6
10-
; ANALYSIS: Shader Stage : geometry
9+
; ANALYSIS-NEXT: DXIL Version : 1.6
10+
; ANALYSIS-NEXT: Shader Stage : geometry
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-hull"
66
; CHECK: ![[SM]] = !{!"hs", i32 6, i32 6}
77

88
; ANALYSIS: Shader Model Version : 6.6
9-
; ANALYSIS: DXIL Version : 1.6
10-
; ANALYSIS: Shader Stage : hull
9+
; ANALYSIS-NEXT: DXIL Version : 1.6
10+
; ANALYSIS-NEXT: Shader Stage : hull
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ target triple = "dxil-pc-shadermodel6.3-library"
66
; CHECK: ![[SM]] = !{!"lib", i32 6, i32 3}
77

88
; ANALYSIS: Shader Model Version : 6.3
9-
; ANALYSIS: DXIL Version : 1.3
10-
; ANALYSIS: Shader Stage : library
9+
; ANALYSIS-NEXT: DXIL Version : 1.3
10+
; ANALYSIS-NEXT: Shader Stage : library
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-mesh"
66
; CHECK: ![[SM]] = !{!"ms", i32 6, i32 6}
77

88
; ANALYSIS: Shader Model Version : 6.6
9-
; ANALYSIS: DXIL Version : 1.6
10-
; ANALYSIS: Shader Stage : mesh
9+
; ANALYSIS-NEXT: DXIL Version : 1.6
10+
; ANALYSIS-NEXT: Shader Stage : mesh
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel5.0-pixel"
66
; CHECK: ![[SM]] = !{!"ps", i32 5, i32 0}
77

88
; ANALYSIS: Shader Model Version : 5.0
9-
; ANALYSIS: DXIL Version : 1.0
10-
; ANALYSIS: Shader Stage : pixel
9+
; ANALYSIS-NEXT: DXIL Version : 1.0
10+
; ANALYSIS-NEXT: Shader Stage : pixel
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel-vertex"
66
; CHECK: ![[SM]] = !{!"vs", i32 0, i32 0}
77

88
; ANALYSIS: Shader Model Version : 0
9-
; ANALYSIS: DXIL Version : 1.0
10-
; ANALYSIS: Shader Stage : vertex
9+
; ANALYSIS-NEXT: DXIL Version : 1.0
10+
; ANALYSIS-NEXT: Shader Stage : vertex
11+
; ANALYSIS-NEXT: Validator Version : 0
12+
; ANALYSIS-EMPTY:
1113

1214
define void @entry() #0 {
1315
entry:

0 commit comments

Comments
 (0)