40 GlobalVariable *buildContainerGlobal(
Module &M, Constant *Content,
41 StringRef Name, StringRef SectionName);
42 GlobalVariable *getFeatureFlags(
Module &M);
43 GlobalVariable *computeShaderHash(
Module &M);
44 GlobalVariable *buildSignature(
Module &M, Signature &Sig, StringRef Name,
45 StringRef SectionName);
48 void addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV);
49 void addPipelineStateValidationInfo(
Module &M,
54 DXContainerGlobals() : ModulePass(ID) {}
56 StringRef getPassName()
const override {
57 return "DXContainer Global Emitter";
60 bool runOnModule(
Module &M)
override;
62 void getAnalysisUsage(AnalysisUsage &AU)
const override {
74bool DXContainerGlobals::runOnModule(
Module &M) {
78 addSignature(M, Globals);
79 addRootSignature(M, Globals);
80 addPipelineStateValidationInfo(M, Globals);
85GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
86 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
92 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
93 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
96GlobalVariable *DXContainerGlobals::computeShaderHash(
Module &M) {
100 Digest.
update(DXILConstant->getRawDataValues());
103 dxbc::ShaderHash HashData = {0, {0}};
106 if (!
M.debug_compile_units().empty())
107 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
109 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
112 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
116 return buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH");
119GlobalVariable *DXContainerGlobals::buildContainerGlobal(
120 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
121 auto *GV =
new llvm::GlobalVariable(
123 GV->setSection(SectionName);
124 GV->setAlignment(
Align(4));
128GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
130 StringRef SectionName) {
131 SmallString<256>
Data;
132 raw_svector_ostream OS(
Data);
136 return buildContainerGlobal(M, Constant, Name, SectionName);
139void DXContainerGlobals::addSignature(
Module &M,
145 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
148 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
151void DXContainerGlobals::addRootSignature(
Module &M,
154 dxil::ModuleMetadataInfo &MMI =
155 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
161 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
162 const Function *EntryFunction =
nullptr;
169 const mcdxbc::RootSignatureDesc *RS = RSA.getDescForFunction(EntryFunction);
173 SmallString<256>
Data;
174 raw_svector_ostream OS(
Data);
180 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.rts0",
"RTS0"));
183void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
184 const DXILResourceMap &DRM =
185 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
186 DXILResourceTypeMap &DRTM =
187 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
190 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
192 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
193 dxbc::PSV::v2::ResourceBindInfo BindInfo;
203 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
204 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
206 dxil::ResourceKind::CBuffer));
208 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
209 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
211 dxbc::PSV::ResourceType::Sampler,
212 dxil::ResourceKind::Sampler));
214 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
215 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
217 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
220 ResType = dxbc::PSV::ResourceType::SRVStructured;
222 ResType = dxbc::PSV::ResourceType::SRVTyped;
224 ResType = dxbc::PSV::ResourceType::SRVRaw;
229 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
230 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
232 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
235 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
237 ResType = dxbc::PSV::ResourceType::UAVStructured;
239 ResType = dxbc::PSV::ResourceType::UAVTyped;
241 ResType = dxbc::PSV::ResourceType::UAVRaw;
243 dxbc::PSV::ResourceFlags
Flags;
253void DXContainerGlobals::addPipelineStateValidationInfo(
255 SmallString<256>
Data;
256 raw_svector_ostream OS(
Data);
261 dxil::ModuleMetadataInfo &MMI =
262 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
269 addResourcesForPSV(M, PSV);
294 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.psv0",
"PSV0"));
297char DXContainerGlobals::ID = 0;
299 "DXContainer Global Emitter",
false,
true)
308 return new DXContainerGlobals();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Resource Implicit Binding
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
iterator_range< iterator > samplers()
iterator_range< iterator > srvs()
iterator_range< iterator > cbuffers()
iterator_range< iterator > uavs()
@ PrivateLinkage
Like Internal, but omit from symbol table.
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI bool isTyped() const
LLVM_ABI bool isStruct() const
dxil::ResourceKind getResourceKind() const
Wrapper pass for the legacy pass manager.
void write(raw_ostream &OS)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
ResourceKind
The kind of resource for an SRV or UAV resource.
constexpr bool IsBigEndianHost
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
ModulePass * createDXContainerGlobalsPass()
Pass for generating DXContainer part globals.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
uint32_t MaximumWaveLaneCount
uint32_t MinimumWaveLaneCount
dxbc::PSV::v3::RuntimeInfo BaseData
llvm::StringRef EntryName
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
void finalize(Triple::EnvironmentType Stage)
void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const
LLVM_ABI void write(raw_ostream &OS) const