Skip to content

[DirectX] Strip dx.rootsignatures metadata during dxil-prepare #145746

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 5 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions llvm/lib/Target/DirectX/DXILPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/// Language (DXIL).
//===----------------------------------------------------------------------===//

#include "DXILRootSignature.h"
#include "DXILShaderFlags.h"
#include "DirectX.h"
#include "DirectXIRPasses/PointerTypeAnalysis.h"
Expand Down Expand Up @@ -286,12 +287,21 @@ class DXILPrepareModule : public ModulePass {
}
// 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>();
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/DirectX/llc-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/CodeGen/DirectX/strip-rootsignatures.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; 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.rootsignature
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo here (though it would still catch the problem). Should we also do a CHECK-NOT: {{^!}} or so to make sure the elements are cleaned up too?

Suggested change
; CHECK-NOT: !dx.rootsignature
; 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
Loading