Skip to content

Commit a8ef75e

Browse files
inbelicbogner
andauthored
[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 #145437. ---------- Co-authored-by: Justin Bogner <[email protected]>
1 parent ce1c1a0 commit a8ef75e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/// Language (DXIL).
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "DXILRootSignature.h"
1415
#include "DXILShaderFlags.h"
1516
#include "DirectX.h"
1617
#include "DirectXIRPasses/PointerTypeAnalysis.h"
@@ -286,12 +287,21 @@ class DXILPrepareModule : public ModulePass {
286287
}
287288
// Remove flags not for DXIL.
288289
cleanModuleFlags(M);
290+
291+
// dx.rootsignatures will have been parsed from its metadata form as its
292+
// binary form as part of the RootSignatureAnalysisWrapper, so safely
293+
// remove it as it is not recognized in DXIL
294+
if (NamedMDNode *RootSignature = M.getNamedMetadata("dx.rootsignatures"))
295+
RootSignature->eraseFromParent();
296+
289297
return true;
290298
}
291299

292300
DXILPrepareModule() : ModulePass(ID) {}
293301
void getAnalysisUsage(AnalysisUsage &AU) const override {
294302
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
303+
AU.addRequired<RootSignatureAnalysisWrapper>();
304+
AU.addPreserved<RootSignatureAnalysisWrapper>();
295305
AU.addPreserved<ShaderFlagsAnalysisWrapper>();
296306
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
297307
AU.addPreserved<DXILResourceWrapperPass>();
@@ -305,6 +315,7 @@ char DXILPrepareModule::ID = 0;
305315
INITIALIZE_PASS_BEGIN(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module",
306316
false, false)
307317
INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
318+
INITIALIZE_PASS_DEPENDENCY(RootSignatureAnalysisWrapper)
308319
INITIALIZE_PASS_END(DXILPrepareModule, DEBUG_TYPE, "DXIL Prepare Module", false,
309320
false)
310321

llvm/test/CodeGen/DirectX/llc-pipeline.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
; CHECK-NEXT: DXIL Translate Metadata
3434
; CHECK-NEXT: DXIL Post Optimization Validation
3535
; CHECK-NEXT: DXIL Op Lowering
36+
; CHECK-NEXT: DXIL Root Signature Analysis
3637
; CHECK-NEXT: DXIL Prepare Module
3738

3839
; CHECK-ASM-NEXT: DXIL Metadata Pretty Printer
3940
; CHECK-ASM-NEXT: Print Module IR
4041

4142
; CHECK-OBJ-NEXT: DXIL Embedder
42-
; CHECK-OBJ-NEXT: DXIL Root Signature Analysis
4343
; CHECK-OBJ-NEXT: DXContainer Global Emitter
4444
; CHECK-OBJ-NEXT: FunctionPass Manager
4545
; CHECK-OBJ-NEXT: Lazy Machine Block Frequency Analysis
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -S -dxil-prepare < %s | FileCheck %s
2+
3+
; Ensures that dxil-prepare will remove the dx.rootsignatures metadata
4+
5+
target triple = "dxil-unknown-shadermodel6.0-compute"
6+
7+
define void @main() {
8+
entry:
9+
ret void
10+
}
11+
12+
; CHECK-NOT: !dx.rootsignatures
13+
; CHECK-NOT: {{^!}}
14+
15+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
16+
!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
17+
!3 = !{ !4 } ; list of root signature elements
18+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout

0 commit comments

Comments
 (0)