[PATCH] D141417: [DirectX backend] emit metadata for DXIL version
Xiang Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 10 11:16:02 PST 2023
python3kgae created this revision.
python3kgae added reviewers: beanz, pow2clk, bogner, bob80905.
Herald added a subscriber: hiraditya.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
New named metadata created with name "dx.version".
The content is shader model major - 5 and shader model minor.
sm6.0 will get dxil version 1.0.
sm6.6 will get dxil version 6.6.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141417
Files:
llvm/lib/Target/DirectX/DXILMetadata.cpp
llvm/lib/Target/DirectX/DXILMetadata.h
llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
llvm/test/CodeGen/DirectX/Metadata/dxil_version.ll
Index: llvm/test/CodeGen/DirectX/Metadata/dxil_version.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/DirectX/Metadata/dxil_version.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S --mtriple=dxil-pc-shadermodel6.0-compute -dxil-metadata-emit %s | FileCheck %s --check-prefixes=SM60,CHECK
+; RUN: opt -S --mtriple=dxil-pc-shadermodel6.6-compute -dxil-metadata-emit %s | FileCheck %s --check-prefixes=SM66,CHECK
+
+; CHECK: !dx.shaderModel = !{![[SM:[0-9]+]]}
+; CHECK: !dx.version = !{![[DXIL_VERSION:[0-9]+]]}
+
+; SM60-DAG: ![[SM]] = !{!"cs", i32 6, i32 0}
+; SM60-DAG: ![[DXIL_VERSION]] = !{i32 1, i32 0}
+
+; SM66-DAG: ![[SM]] = !{!"cs", i32 6, i32 6}
+; SM66-DAG: ![[DXIL_VERSION]] = !{i32 1, i32 6}
+
+define void @entry() #0 {
+entry:
+ ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.numthreads"="1,2,1" "hlsl.shader"="compute" }
Index: llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
===================================================================
--- llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
+++ llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
@@ -47,7 +47,7 @@
dxil::ValidatorVersionMD ValVerMD(M);
if (ValVerMD.isEmpty())
ValVerMD.update(VersionTuple(1, 0));
- dxil::createShaderModelMD(M);
+ dxil::createShaderModelAndDXILVersionMD(M);
const dxil::Resources &Res =
getAnalysis<DXILResourceWrapper>().getDXILResource();
Index: llvm/lib/Target/DirectX/DXILMetadata.h
===================================================================
--- llvm/lib/Target/DirectX/DXILMetadata.h
+++ llvm/lib/Target/DirectX/DXILMetadata.h
@@ -32,7 +32,7 @@
bool isEmpty();
};
-void createShaderModelMD(Module &M);
+void createShaderModelAndDXILVersionMD(Module &M);
void createEntryMD(Module &M, const uint64_t ShaderFlags);
} // namespace dxil
Index: llvm/lib/Target/DirectX/DXILMetadata.cpp
===================================================================
--- llvm/lib/Target/DirectX/DXILMetadata.cpp
+++ llvm/lib/Target/DirectX/DXILMetadata.cpp
@@ -67,7 +67,7 @@
return "";
}
-void dxil::createShaderModelMD(Module &M) {
+void dxil::createShaderModelAndDXILVersionMD(Module &M) {
NamedMDNode *Entry = M.getOrInsertNamedMetadata("dx.shaderModel");
Triple TT(M.getTargetTriple());
VersionTuple Ver = TT.getOSVersion();
@@ -79,6 +79,13 @@
Vals[1] = ConstantAsMetadata::get(B.getInt32(Ver.getMajor()));
Vals[2] = ConstantAsMetadata::get(B.getInt32(Ver.getMinor().value_or(0)));
Entry->addOperand(MDNode::get(Ctx, Vals));
+
+ // DXIL Version is just shader model major - 5. sm6.0-> dxil version 1.0.
+ NamedMDNode *DXILVerEntry = M.getOrInsertNamedMetadata("dx.version");
+ Metadata *DXILVerVals[2];
+ DXILVerVals[0] = ConstantAsMetadata::get(B.getInt32(Ver.getMajor() - 5));
+ DXILVerVals[1] = ConstantAsMetadata::get(B.getInt32(Ver.getMinor().value_or(0)));
+ DXILVerEntry->addOperand(MDNode::get(Ctx, DXILVerVals));
}
static uint32_t getShaderStage(Triple::EnvironmentType Env) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141417.487898.patch
Type: text/x-patch
Size: 3020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230110/80d7b96e/attachment.bin>
More information about the llvm-commits
mailing list