Skip to content

[DXIL][Analysis] Add validator version to info collected by Module Metadata Analysis #104828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ModuleMetadataInfo {
VersionTuple DXILVersion{};
VersionTuple ShaderModelVersion{};
Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment;
VersionTuple ValidatorVersion{};

void print(raw_ostream &OS) const;
};
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Analysis/DXILMetadataAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderStage = TT.getEnvironment();
NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
if (ValidatorVerNode) {
auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
auto *MajorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(0));
auto *MinorMD = mdconst::extract<ConstantInt>(ValVerMD->getOperand(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a check if the tuple isn't well formed, or is there a separate place that's already checked?
AFAIK, there's nothing that guarantees someone couldn't form a bad metadata header, which shouldn't be accidentally evaluated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a check if the tuple isn't well formed, or is there a separate place that's already checked? AFAIK, there's nothing that guarantees someone couldn't form a bad metadata header, which shouldn't be accidentally evaluated.

These checks are not included here as they are expected to be done during Module construction.

MMDAI.ValidatorVersion =
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we report error when dx.valver not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we report error when dx.valver not exist?

Since this is an analysis pass, the thought behind not reporting an error here but just retaining the default value of {}, is to allow for the consumer of the analysis information the option of emitting an error, emitting a warning or may be setting the validator version, depending on the usage context.

return MMDAI;
}

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

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.0.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.0-vertex"
; CHECK: ![[DXVER]] = !{i32 1, i32 0}

; ANALYSIS: Shader Model Version : 6.0
; ANALYSIS: DXIL Version : 1.0
; ANALYSIS: Shader Stage : vertex
; ANALYSIS-NEXT: DXIL Version : 1.0
; ANALYSIS-NEXT: Shader Stage : vertex
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/dxilVer-1.8.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.8-compute"
; CHECK: ![[DXVER]] = !{i32 1, i32 8}

; ANALYSIS: Shader Model Version : 6.8
; ANALYSIS: DXIL Version : 1.8
; ANALYSIS: Shader Stage : compute
; ANALYSIS-NEXT: DXIL Version : 1.8
; ANALYSIS-NEXT: Shader Stage : compute
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/CodeGen/DirectX/Metadata/empty-valver1.8.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; RUN: opt -S -passes="print<dxil-metadata>" -disable-output %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
; Verify correctness of Shader Model version, DXIL version, Shader stage and Validator version
; obtained by Module Metadata Analysis pass from the metadata specified in the source.

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : compute
; ANALYSIS-NEXT: Validator Version : 1.8
; ANALYSIS-EMPTY:

; Function Attrs: nounwind memory(none)
define void @main() local_unnamed_addr #0 {
entry:
ret void
}

attributes #0 = { nounwind memory(none) }

!dx.valver = !{!0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the other test cases stop after attributes #0 Is there something special about the empty case that makes you need lined 19-32? If not please delete or add checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the other test cases stop after attributes #0 Is there something special about the empty case that makes you need lined 19-32? If not please delete or add checks.

Deleted unrelated metadata.

!dx.shaderModel = !{!2}
!dx.version = !{!3}

!0 = !{i32 1, i32 8}
!2 = !{!"cs", i32 6, i32 6}
!3 = !{i32 1, i32 6}
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-as.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6-amplification"
; CHECK: ![[SM]] = !{!"as", i32 6, i32 0}

; ANALYSIS: Shader Model Version : 6
; ANALYSIS: DXIL Version : 1.0
; ANALYSIS: Shader Stage : amplification
; ANALYSIS-NEXT: DXIL Version : 1.0
; ANALYSIS-NEXT: Shader Stage : amplification
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ attributes #0 = { noinline nounwind "exp-shader"="cs" "hlsl.numthreads"="1,2,1"
!0 = !{i32 0, i32 0}

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS: DXIL Version : 1.6
; ANALYSIS: Shader Stage : compute
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : compute
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-cs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ target triple = "dxil-pc-shadermodel6.6-compute"
; CHECK: ![[SM]] = !{!"cs", i32 6, i32 6}

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS: DXIL Version : 1.6
; ANALYSIS: Shader Stage : compute
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : compute
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-gs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-geometry"
; CHECK: ![[SM]] = !{!"gs", i32 6, i32 6}

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS: DXIL Version : 1.6
; ANALYSIS: Shader Stage : geometry
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : geometry
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-hs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-hull"
; CHECK: ![[SM]] = !{!"hs", i32 6, i32 6}

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS: DXIL Version : 1.6
; ANALYSIS: Shader Stage : hull
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : hull
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-lib.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ target triple = "dxil-pc-shadermodel6.3-library"
; CHECK: ![[SM]] = !{!"lib", i32 6, i32 3}

; ANALYSIS: Shader Model Version : 6.3
; ANALYSIS: DXIL Version : 1.3
; ANALYSIS: Shader Stage : library
; ANALYSIS-NEXT: DXIL Version : 1.3
; ANALYSIS-NEXT: Shader Stage : library
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-ms.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel6.6-mesh"
; CHECK: ![[SM]] = !{!"ms", i32 6, i32 6}

; ANALYSIS: Shader Model Version : 6.6
; ANALYSIS: DXIL Version : 1.6
; ANALYSIS: Shader Stage : mesh
; ANALYSIS-NEXT: DXIL Version : 1.6
; ANALYSIS-NEXT: Shader Stage : mesh
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-ps.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel5.0-pixel"
; CHECK: ![[SM]] = !{!"ps", i32 5, i32 0}

; ANALYSIS: Shader Model Version : 5.0
; ANALYSIS: DXIL Version : 1.0
; ANALYSIS: Shader Stage : pixel
; ANALYSIS-NEXT: DXIL Version : 1.0
; ANALYSIS-NEXT: Shader Stage : pixel
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/CodeGen/DirectX/Metadata/shaderModel-vs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ target triple = "dxil-pc-shadermodel-vertex"
; CHECK: ![[SM]] = !{!"vs", i32 0, i32 0}

; ANALYSIS: Shader Model Version : 0
; ANALYSIS: DXIL Version : 1.0
; ANALYSIS: Shader Stage : vertex
; ANALYSIS-NEXT: DXIL Version : 1.0
; ANALYSIS-NEXT: Shader Stage : vertex
; ANALYSIS-NEXT: Validator Version : 0
; ANALYSIS-EMPTY:

define void @entry() #0 {
entry:
Expand Down
Loading