diff options
author | Finn Plummer <finn.c.plum@gmail.com> | 2025-06-25 14:06:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-25 14:06:46 -0700 |
commit | a8ef75e758982d8e66790ffe26fcc6f1d9648e88 (patch) | |
tree | 8e56c373d8b760e71d8cc473ba5282b35a2a134f | |
parent | ce1c1a0e6d6b8dcae19a2b51e01246dd8850691f (diff) | |
download | llvm-a8ef75e758982d8e66790ffe26fcc6f1d9648e88.zip llvm-a8ef75e758982d8e66790ffe26fcc6f1d9648e88.tar.gz llvm-a8ef75e758982d8e66790ffe26fcc6f1d9648e88.tar.bz2 |
[DirectX] Strip `dx.rootsignatures` metadata during `dxil-prepare` (#145746)
The `dx.rootsignatures` metadata is not recognized in DXIL, so failure
to remove this will cause validation errors.
This metadata is parsed (within `RootSignatureAnalysisWrapper`) into its
binary format. As such, once it has been used to construct the binary
form, it can be safely discarded without loss of information.
This pr ensures that the dxil prepare pass will depend and preserve on
the root signature analysis so that it runs before the metadata is
removed.
- Update `DXILPrepare.cpp` to preserve and depend on
`RootSignatureAnalysisWrapper`
- Update test to demonstrate order is correct
- Provide test-case to demonstrate the metadata is removed
Resolves https://github.com/llvm/llvm-project/issues/145437.
----------
Co-authored-by: Justin Bogner <mail@justinbogner.com>
-rw-r--r-- | llvm/lib/Target/DirectX/DXILPrepare.cpp | 11 | ||||
-rw-r--r-- | llvm/test/CodeGen/DirectX/llc-pipeline.ll | 2 | ||||
-rw-r--r-- | llvm/test/CodeGen/DirectX/strip-rootsignatures.ll | 18 |
3 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp index cb58f48..c8866bf 100644 --- a/llvm/lib/Target/DirectX/DXILPrepare.cpp +++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp @@ -11,6 +11,7 @@ /// Language (DXIL). //===----------------------------------------------------------------------===// +#include "DXILRootSignature.h" #include "DXILShaderFlags.h" #include "DirectX.h" #include "DirectXIRPasses/PointerTypeAnalysis.h" @@ -286,12 +287,21 @@ public: } // Remove flags not for DXIL. cleanModuleFlags(M); + + // dx.rootsignatures will have been parsed from its metadata form as its + // binary form as part of the RootSignatureAnalysisWrapper, so safely + // remove it as it is not recognized in DXIL + if (NamedMDNode *RootSignature = M.getNamedMetadata("dx.rootsignatures")) + RootSignature->eraseFromParent(); + return true; } DXILPrepareModule() : ModulePass(ID) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<DXILMetadataAnalysisWrapperPass>(); + AU.addRequired<RootSignatureAnalysisWrapper>(); + AU.addPreserved<RootSignatureAnalysisWrapper>(); AU.addPreserved<ShaderFlagsAnalysisWrapper>(); AU.addPreserved<DXILMetadataAnalysisWrapperPass>(); AU.addPreserved<DXILResourceWrapperPass>(); @@ -305,6 +315,7 @@ char DXILPrepareModule::ID = 0; INITIALIZE_PASS_BEGIN(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module", false, false) INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass) +INITIALIZE_PASS_DEPENDENCY(RootSignatureAnalysisWrapper) INITIALIZE_PASS_END(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module", false, false) diff --git a/llvm/test/CodeGen/DirectX/llc-pipeline.ll b/llvm/test/CodeGen/DirectX/llc-pipeline.ll index 2b29fd3..36fed88 100644 --- a/llvm/test/CodeGen/DirectX/llc-pipeline.ll +++ b/llvm/test/CodeGen/DirectX/llc-pipeline.ll @@ -33,13 +33,13 @@ ; CHECK-NEXT: DXIL Translate Metadata ; CHECK-NEXT: DXIL Post Optimization Validation ; CHECK-NEXT: DXIL Op Lowering +; CHECK-NEXT: DXIL Root Signature Analysis ; CHECK-NEXT: DXIL Prepare Module ; CHECK-ASM-NEXT: DXIL Metadata Pretty Printer ; CHECK-ASM-NEXT: Print Module IR ; CHECK-OBJ-NEXT: DXIL Embedder -; CHECK-OBJ-NEXT: DXIL Root Signature Analysis ; CHECK-OBJ-NEXT: DXContainer Global Emitter ; CHECK-OBJ-NEXT: FunctionPass Manager ; CHECK-OBJ-NEXT: Lazy Machine Block Frequency Analysis diff --git a/llvm/test/CodeGen/DirectX/strip-rootsignatures.ll b/llvm/test/CodeGen/DirectX/strip-rootsignatures.ll new file mode 100644 index 0000000..3ac617a --- /dev/null +++ b/llvm/test/CodeGen/DirectX/strip-rootsignatures.ll @@ -0,0 +1,18 @@ +; RUN: opt -S -dxil-prepare < %s | FileCheck %s + +; Ensures that dxil-prepare will remove the dx.rootsignatures metadata + +target triple = "dxil-unknown-shadermodel6.0-compute" + +define void @main() { +entry: + ret void +} + +; CHECK-NOT: !dx.rootsignatures +; CHECK-NOT: {{^!}} + +!dx.rootsignatures = !{!2} ; list of function/root signature pairs +!2 = !{ ptr @main, !3, i32 2 } ; function, root signature +!3 = !{ !4 } ; list of root signature elements +!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout |