41 GlobalVariable *buildContainerGlobal(
Module &M, Constant *Content,
42 StringRef Name, StringRef SectionName);
44 StringRef SectionData, StringRef MetadataName,
45 StringRef SectionName);
46 GlobalVariable *getFeatureFlags(
Module &M);
47 void computeShaderHashAndDebugName(
Module &M,
49 GlobalVariable *buildSignature(
Module &M, Signature &Sig, StringRef Name,
50 StringRef SectionName);
53 void addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV);
54 void addPipelineStateValidationInfo(
Module &M,
60 DXContainerGlobals() : ModulePass(ID) {}
62 StringRef getPassName()
const override {
63 return "DXContainer Global Emitter";
66 bool runOnModule(
Module &M)
override;
68 void getAnalysisUsage(AnalysisUsage &AU)
const override {
80bool DXContainerGlobals::runOnModule(
Module &M) {
83 computeShaderHashAndDebugName(M, Globals);
84 addSignature(M, Globals);
85 addRootSignature(M, Globals);
86 addPipelineStateValidationInfo(M, Globals);
87 addCompilerVersion(M, Globals);
92GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
93 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
99 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
100 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
103void DXContainerGlobals::addSection(
Module &M,
105 StringRef SectionData,
106 StringRef MetadataName,
107 StringRef SectionName) {
109 M.getContext(), SectionData,
false);
111 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
114void DXContainerGlobals::computeShaderHashAndDebugName(
120 Digest.
update(DXILConstant->getRawDataValues());
122 dxbc::ShaderHash HashData = {0, {0}};
124 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
127 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
132 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
137 if (
M.debug_compile_units().empty())
140 SmallString<40> DebugNameStr;
142 DebugNameStr +=
".pdb";
144 mcdxbc::DebugName DebugName;
147 SmallString<64> ILDNData;
148 raw_svector_ostream OS(ILDNData);
150 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
153GlobalVariable *DXContainerGlobals::buildContainerGlobal(
154 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
155 auto *GV =
new llvm::GlobalVariable(
157 GV->setSection(SectionName);
158 GV->setAlignment(
Align(4));
162GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
164 StringRef SectionName) {
165 SmallString<256>
Data;
166 raw_svector_ostream OS(
Data);
170 return buildContainerGlobal(M, Constant, Name, SectionName);
173void DXContainerGlobals::addSignature(
Module &M,
179 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
182 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
185void DXContainerGlobals::addRootSignature(
Module &M,
188 dxil::ModuleMetadataInfo &MMI =
189 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
195 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
196 const Function *EntryFunction =
nullptr;
203 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
207 SmallString<256>
Data;
208 raw_svector_ostream OS(
Data);
215void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
216 const DXILResourceMap &DRM =
217 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
218 DXILResourceTypeMap &DRTM =
219 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
222 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
224 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
225 dxbc::PSV::v2::ResourceBindInfo BindInfo;
231 "Resource range is too large");
241 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
242 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
244 dxil::ResourceKind::CBuffer));
246 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
247 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
249 dxbc::PSV::ResourceType::Sampler,
250 dxil::ResourceKind::Sampler));
252 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
253 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
255 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
258 ResType = dxbc::PSV::ResourceType::SRVStructured;
260 ResType = dxbc::PSV::ResourceType::SRVTyped;
262 ResType = dxbc::PSV::ResourceType::SRVRaw;
267 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
268 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
270 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
273 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
275 ResType = dxbc::PSV::ResourceType::UAVStructured;
277 ResType = dxbc::PSV::ResourceType::UAVTyped;
279 ResType = dxbc::PSV::ResourceType::UAVRaw;
281 dxbc::PSV::ResourceFlags
Flags;
291void DXContainerGlobals::addPipelineStateValidationInfo(
293 SmallString<256>
Data;
294 raw_svector_ostream OS(
Data);
299 dxil::ModuleMetadataInfo &MMI =
300 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
307 addResourcesForPSV(M, PSV);
340void DXContainerGlobals::addCompilerVersion(
342 dxil::ModuleMetadataInfo &MMI =
343 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
345 if (
M.debug_compile_units().empty())
348 SmallString<256>
Data;
349 raw_svector_ostream OS(
Data);
350 mcdxbc::CompilerVersion CompilerVersion;
351 CompilerVersion.
write(OS);
355char DXContainerGlobals::ID = 0;
357 "DXContainer Global Emitter",
false,
true)
366 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.
static Error addSection(const NewSectionInfo &NewSection, Object &Obj)
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 Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, bool ByteString=false)
This method constructs a CDS and initializes it with a text string.
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.
static LLVM_ABI void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
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
void write(raw_ostream &OS) const
void setFilename(StringRef DebugFilename)
void write(raw_ostream &OS) const
dxbc::PSV::v3::RuntimeInfo BaseData
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
void finalize(Triple::EnvironmentType Stage, uint32_t Version=std::numeric_limits< uint32_t >::max())
void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const