@@ -28,8 +28,13 @@ using namespace llvm::dxil;
28
28
namespace {
29
29
class DXContainerGlobals : public llvm ::ModulePass {
30
30
31
+ GlobalVariable *buildContainerGlobal (Module &M, Constant *Content,
32
+ StringRef Name, StringRef SectionName);
31
33
GlobalVariable *getFeatureFlags (Module &M);
32
34
GlobalVariable *computeShaderHash (Module &M);
35
+ GlobalVariable *buildInputSingature (Module &M, Constant *Content);
36
+ GlobalVariable *buildOutputSingature (Module &M, Constant *Content);
37
+ void addSingature (Module &M, SmallVector<GlobalValue *> &Globals, Triple &TT);
33
38
34
39
public:
35
40
static char ID; // Pass identification, replacement for typeid
@@ -55,7 +60,8 @@ bool DXContainerGlobals::runOnModule(Module &M) {
55
60
llvm::SmallVector<GlobalValue *> Globals;
56
61
Globals.push_back (getFeatureFlags (M));
57
62
Globals.push_back (computeShaderHash (M));
58
-
63
+ Triple TT (M.getTargetTriple ());
64
+ addSingature (M, Globals, TT);
59
65
appendToCompilerUsed (M, Globals);
60
66
return true ;
61
67
}
@@ -104,6 +110,50 @@ GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
104
110
return GV;
105
111
}
106
112
113
+ GlobalVariable *DXContainerGlobals::buildContainerGlobal (
114
+ Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
115
+ auto *GV = new llvm::GlobalVariable (
116
+ M, Content->getType (), true , GlobalValue::PrivateLinkage, Content, Name);
117
+ GV->setSection (SectionName);
118
+ GV->setAlignment (Align (4 ));
119
+ return GV;
120
+ }
121
+
122
+ GlobalVariable *DXContainerGlobals::buildInputSingature (Module &M,
123
+ Constant *Content) {
124
+ return buildContainerGlobal (M, Content, " dx.isg1" , " ISG1" );
125
+ }
126
+ GlobalVariable *DXContainerGlobals::buildOutputSingature (Module &M,
127
+ Constant *Content) {
128
+ return buildContainerGlobal (M, Content, " dx.osg1" , " OSG1" );
129
+ }
130
+
131
+ void DXContainerGlobals::addSingature (Module &M,
132
+ SmallVector<GlobalValue *> &Globals,
133
+ Triple &TT) {
134
+ dxbc::ProgramSignatureHeader Sig;
135
+ Sig.ParamCount = 0 ;
136
+ Sig.FirstParamOffset = sizeof (dxbc::ProgramSignatureHeader);
137
+ Type *Int32Ty = Type::getInt32Ty (M.getContext ());
138
+ Constant *InputSig = nullptr ;
139
+ Constant *OutputSig = nullptr ;
140
+ switch (TT.getEnvironment ()) {
141
+ case Triple::EnvironmentType::Compute:
142
+ InputSig = ConstantStruct::get (
143
+ StructType::get (Int32Ty, Int32Ty),
144
+ {ConstantInt::get (M.getContext (), APInt (32 , Sig.ParamCount )),
145
+ ConstantInt::get (M.getContext (), APInt (32 , Sig.FirstParamOffset ))});
146
+ OutputSig = InputSig;
147
+ break ;
148
+ // FIXME: support graphics shader.
149
+ // see issue https://github.com/llvm/llvm-project/issues/90504.
150
+ default :
151
+ return ;
152
+ }
153
+ Globals.emplace_back (buildInputSingature (M, InputSig));
154
+ Globals.emplace_back (buildOutputSingature (M, OutputSig));
155
+ }
156
+
107
157
char DXContainerGlobals::ID = 0 ;
108
158
INITIALIZE_PASS_BEGIN (DXContainerGlobals, " dxil-globals" ,
109
159
" DXContainer Global Emitter" , false , true )
0 commit comments