43 "dx-Zss",
cl::desc(
"Compute Shader Hash considering source information"));
47 cl::desc(
"Store PDB in private user data"));
58 void computeShaderHashAndDebugName(
Module &M,
65 void addPipelineStateValidationInfo(
Module &M,
74 StringRef getPassName()
const override {
75 return "DXContainer Global Emitter";
78 bool runOnModule(
Module &M)
override;
80 void getAnalysisUsage(AnalysisUsage &AU)
const override {
92bool DXContainerGlobals::runOnModule(
Module &M) {
95 computeShaderHashAndDebugName(M, Globals);
96 addSignature(M, Globals);
97 addRootSignature(M, Globals);
98 addPipelineStateValidationInfo(M, Globals);
99 addCompilerVersion(M, Globals);
100 addSourceInfo(M, Globals);
105GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
106 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
112 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
113 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
116void DXContainerGlobals::addSection(
Module &M,
118 StringRef SectionData,
119 StringRef MetadataName,
120 StringRef SectionName) {
122 M.getContext(), SectionData,
false);
124 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
127void DXContainerGlobals::computeShaderHashAndDebugName(
129 ConstantDataArray *DXILConstant;
131 dxbc::ShaderHash HashData = {0, {0}};
134 if (
auto *ILDB =
M.getNamedGlobal(
"dx.ildb")) {
136 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
146 MD5::MD5Result
MD5 = Digest.
final();
148 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
MD5.data(), 16);
151 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
156 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
158 if (
M.debug_compile_units().empty())
161 SmallString<40> DebugNameStr;
163 DebugNameStr +=
".pdb";
167 SmallString<256> AbsoluteDebugName;
171 AbsoluteDebugName = DebugFile;
175 DebugNameStr = DebugFile;
176 AbsoluteDebugName = DebugNameStr;
180 addSection(M, Globals, AbsoluteDebugName,
"dx.pdb.name",
191 mcdxbc::DebugName DebugName;
193 SmallString<64> ILDNData;
194 raw_svector_ostream OS(ILDNData);
196 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
199GlobalVariable *DXContainerGlobals::buildContainerGlobal(
200 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
201 auto *GV =
new llvm::GlobalVariable(
203 GV->setSection(SectionName);
204 GV->setAlignment(
Align(4));
208GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
210 StringRef SectionName) {
211 SmallString<256>
Data;
212 raw_svector_ostream OS(
Data);
216 return buildContainerGlobal(M, Constant, Name, SectionName);
219void DXContainerGlobals::addSignature(
Module &M,
225 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
228 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
231void DXContainerGlobals::addRootSignature(
Module &M,
234 dxil::ModuleMetadataInfo &MMI =
235 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
241 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
242 const Function *EntryFunction =
nullptr;
249 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
253 SmallString<256>
Data;
254 raw_svector_ostream OS(
Data);
261void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
262 const DXILResourceMap &DRM =
263 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
264 DXILResourceTypeMap &DRTM =
265 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
268 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
270 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
271 dxbc::PSV::v2::ResourceBindInfo BindInfo;
277 "Resource range is too large");
287 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
288 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
290 dxil::ResourceKind::CBuffer));
292 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
293 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
295 dxbc::PSV::ResourceType::Sampler,
296 dxil::ResourceKind::Sampler));
298 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
299 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
301 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
304 ResType = dxbc::PSV::ResourceType::SRVStructured;
306 ResType = dxbc::PSV::ResourceType::SRVTyped;
308 ResType = dxbc::PSV::ResourceType::SRVRaw;
313 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
314 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
316 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
319 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
321 ResType = dxbc::PSV::ResourceType::UAVStructured;
323 ResType = dxbc::PSV::ResourceType::UAVTyped;
325 ResType = dxbc::PSV::ResourceType::UAVRaw;
327 dxbc::PSV::ResourceFlags
Flags;
337void DXContainerGlobals::addPipelineStateValidationInfo(
339 SmallString<256>
Data;
340 raw_svector_ostream OS(
Data);
345 dxil::ModuleMetadataInfo &MMI =
346 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
353 addResourcesForPSV(M, PSV);
386void DXContainerGlobals::addCompilerVersion(
388 if (
M.debug_compile_units().empty())
391 SmallString<256>
Data;
392 raw_svector_ostream OS(
Data);
393 mcdxbc::CompilerVersion CompilerVersion;
394 CompilerVersion.
write(OS);
398void DXContainerGlobals::addSourceInfo(
Module &M,
400 dxil::ModuleMetadataInfo &MMI =
401 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
408 SmallString<256>
Data;
409 raw_svector_ostream OS(
Data);
414char DXContainerGlobals::ID = 0;
416 "DXContainer Global Emitter",
false,
true)
425 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...
cl::opt< bool > PdbInPrivate("dx-pdb-in-private", cl::desc("Store PDB in private user data"))
cl::opt< std::string > PdbDebugPath
cl::opt< bool > SourceInDebugModule
static cl::opt< bool > ShaderHashDependsOnSource("dx-Zss", cl::desc("Compute Shader Hash considering source information"))
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.
LLVM_ABI StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
This is an important base class in LLVM.
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)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
char back() const
Get the last character in the string.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
ResourceKind
The kind of resource for an SRV or UAV resource.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI bool is_separator(char value, Style style=Style::native)
Check whether the given char is a path separator on the host OS.
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.
static constexpr StringLiteral ModuleHashSectionName
Contains module hash.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
static constexpr StringLiteral PdbFileNameSectionName
Contains PDB output file name.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
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