10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " DXILRootSignature.h"
13
14
#include " DXILShaderFlags.h"
14
15
#include " DirectX.h"
15
16
#include " llvm/ADT/SmallVector.h"
25
26
#include " llvm/MC/DXContainerPSVInfo.h"
26
27
#include " llvm/Pass.h"
27
28
#include " llvm/Support/MD5.h"
29
+ #include " llvm/TargetParser/Triple.h"
28
30
#include " llvm/Transforms/Utils/ModuleUtils.h"
31
+ #include < optional>
29
32
30
33
using namespace llvm ;
31
34
using namespace llvm ::dxil;
@@ -41,6 +44,7 @@ class DXContainerGlobals : public llvm::ModulePass {
41
44
GlobalVariable *buildSignature (Module &M, Signature &Sig, StringRef Name,
42
45
StringRef SectionName);
43
46
void addSignature (Module &M, SmallVector<GlobalValue *> &Globals);
47
+ void addRootSignature (Module &M, SmallVector<GlobalValue *> &Globals);
44
48
void addResourcesForPSV (Module &M, PSVRuntimeInfo &PSV);
45
49
void addPipelineStateValidationInfo (Module &M,
46
50
SmallVector<GlobalValue *> &Globals);
@@ -60,6 +64,7 @@ class DXContainerGlobals : public llvm::ModulePass {
60
64
void getAnalysisUsage (AnalysisUsage &AU) const override {
61
65
AU.setPreservesAll ();
62
66
AU.addRequired <ShaderFlagsAnalysisWrapper>();
67
+ AU.addRequired <RootSignatureAnalysisWrapper>();
63
68
AU.addRequired <DXILMetadataAnalysisWrapperPass>();
64
69
AU.addRequired <DXILResourceTypeWrapperPass>();
65
70
AU.addRequired <DXILResourceBindingWrapperPass>();
@@ -73,6 +78,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
73
78
Globals.push_back (getFeatureFlags (M));
74
79
Globals.push_back (computeShaderHash (M));
75
80
addSignature (M, Globals);
81
+ addRootSignature (M, Globals);
76
82
addPipelineStateValidationInfo (M, Globals);
77
83
appendToCompilerUsed (M, Globals);
78
84
return true ;
@@ -144,6 +150,36 @@ void DXContainerGlobals::addSignature(Module &M,
144
150
Globals.emplace_back (buildSignature (M, OutputSig, " dx.osg1" , " OSG1" ));
145
151
}
146
152
153
+ void DXContainerGlobals::addRootSignature (Module &M,
154
+ SmallVector<GlobalValue *> &Globals) {
155
+
156
+ dxil::ModuleMetadataInfo &MMI =
157
+ getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
158
+
159
+ // Root Signature in Library don't compile to DXContainer.
160
+ if (MMI.ShaderProfile == llvm::Triple::Library)
161
+ return ;
162
+
163
+ assert (MMI.EntryPropertyVec .size () == 1 );
164
+
165
+ auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>();
166
+ const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
167
+ const auto &FuncRs = RSA.find (EntryFunction);
168
+
169
+ if (FuncRs == RSA.end ())
170
+ return ;
171
+
172
+ const RootSignatureDesc &RS = FuncRs->second ;
173
+ SmallString<256 > Data;
174
+ raw_svector_ostream OS (Data);
175
+
176
+ RS.write (OS);
177
+
178
+ Constant *Constant =
179
+ ConstantDataArray::getString (M.getContext (), Data, /* AddNull*/ false );
180
+ Globals.emplace_back (buildContainerGlobal (M, Constant, " dx.rts0" , " RTS0" ));
181
+ }
182
+
147
183
void DXContainerGlobals::addResourcesForPSV (Module &M, PSVRuntimeInfo &PSV) {
148
184
const DXILBindingMap &DBM =
149
185
getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap ();
0 commit comments