42 GlobalVariable *buildContainerGlobal(
Module &M, Constant *Content,
43 StringRef Name, StringRef SectionName);
45 StringRef SectionData, StringRef MetadataName,
46 StringRef SectionName);
47 GlobalVariable *getFeatureFlags(
Module &M);
48 void computeShaderHashAndDebugName(
Module &M,
50 GlobalVariable *buildSignature(
Module &M, Signature &Sig, StringRef Name,
51 StringRef SectionName);
54 void addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV);
55 void addPipelineStateValidationInfo(
Module &M,
62 DXContainerGlobals() : ModulePass(ID) {}
64 StringRef getPassName()
const override {
65 return "DXContainer Global Emitter";
68 bool runOnModule(
Module &M)
override;
70 void getAnalysisUsage(AnalysisUsage &AU)
const override {
82bool DXContainerGlobals::runOnModule(
Module &M) {
85 computeShaderHashAndDebugName(M, Globals);
86 addSignature(M, Globals);
87 addRootSignature(M, Globals);
88 addPipelineStateValidationInfo(M, Globals);
89 addCompilerVersion(M, Globals);
90 addSourceInfo(M, Globals);
95GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
96 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
102 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
103 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
106void DXContainerGlobals::addSection(
Module &M,
108 StringRef SectionData,
109 StringRef MetadataName,
110 StringRef SectionName) {
112 M.getContext(), SectionData,
false);
114 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
117void DXContainerGlobals::computeShaderHashAndDebugName(
123 Digest.
update(DXILConstant->getRawDataValues());
125 dxbc::ShaderHash HashData = {0, {0}};
127 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
130 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
135 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
140 if (
M.debug_compile_units().empty())
143 SmallString<40> DebugNameStr;
145 DebugNameStr +=
".pdb";
147 mcdxbc::DebugName DebugName;
150 SmallString<64> ILDNData;
151 raw_svector_ostream OS(ILDNData);
153 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
156GlobalVariable *DXContainerGlobals::buildContainerGlobal(
157 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
158 auto *GV =
new llvm::GlobalVariable(
160 GV->setSection(SectionName);
161 GV->setAlignment(
Align(4));
165GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
167 StringRef SectionName) {
168 SmallString<256>
Data;
169 raw_svector_ostream OS(
Data);
173 return buildContainerGlobal(M, Constant, Name, SectionName);
176void DXContainerGlobals::addSignature(
Module &M,
182 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
185 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
188void DXContainerGlobals::addRootSignature(
Module &M,
191 dxil::ModuleMetadataInfo &MMI =
192 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
198 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
199 const Function *EntryFunction =
nullptr;
206 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
210 SmallString<256>
Data;
211 raw_svector_ostream OS(
Data);
218void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
219 const DXILResourceMap &DRM =
220 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
221 DXILResourceTypeMap &DRTM =
222 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
225 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
227 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
228 dxbc::PSV::v2::ResourceBindInfo BindInfo;
234 "Resource range is too large");
244 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
245 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
247 dxil::ResourceKind::CBuffer));
249 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
250 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
252 dxbc::PSV::ResourceType::Sampler,
253 dxil::ResourceKind::Sampler));
255 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
256 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
258 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
261 ResType = dxbc::PSV::ResourceType::SRVStructured;
263 ResType = dxbc::PSV::ResourceType::SRVTyped;
265 ResType = dxbc::PSV::ResourceType::SRVRaw;
270 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
271 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
273 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
276 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
278 ResType = dxbc::PSV::ResourceType::UAVStructured;
280 ResType = dxbc::PSV::ResourceType::UAVTyped;
282 ResType = dxbc::PSV::ResourceType::UAVRaw;
284 dxbc::PSV::ResourceFlags
Flags;
294void DXContainerGlobals::addPipelineStateValidationInfo(
296 SmallString<256>
Data;
297 raw_svector_ostream OS(
Data);
302 dxil::ModuleMetadataInfo &MMI =
303 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
310 addResourcesForPSV(M, PSV);
343void DXContainerGlobals::addCompilerVersion(
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);
355void DXContainerGlobals::addSourceInfo(
Module &M,
357 dxil::ModuleMetadataInfo &MMI =
358 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
365 SmallString<256>
Data;
366 raw_svector_ostream OS(
Data);
370 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.srci",
"SRCI"));
373char DXContainerGlobals::ID = 0;
375 "DXContainer Global Emitter",
false,
true)
384 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.
LLVM_ABI 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 an array ref of bytes from a string ref.
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
LLVM_ABI void write(raw_ostream &OS) const
LLVM_ABI void setFilename(StringRef DebugFilename)
LLVM_ABI void write(raw_ostream &OS) const
dxbc::PSV::v3::RuntimeInfo BaseData
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
LLVM_ABI void finalize(Triple::EnvironmentType Stage, uint32_t Version=std::numeric_limits< uint32_t >::max())
LLVM_ABI void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const