43 "dx-Zss",
cl::desc(
"Compute Shader Hash considering source information"));
46 cl::desc(
"Write debug information to the given file, or automatically "
47 "named file in directory when ending in '/'"),
59 void computeShaderHashAndDebugName(
Module &M,
66 void addPipelineStateValidationInfo(
Module &M,
75 StringRef getPassName()
const override {
76 return "DXContainer Global Emitter";
79 bool runOnModule(
Module &M)
override;
81 void getAnalysisUsage(AnalysisUsage &AU)
const override {
93bool DXContainerGlobals::runOnModule(
Module &M) {
96 computeShaderHashAndDebugName(M, Globals);
97 addSignature(M, Globals);
98 addRootSignature(M, Globals);
99 addPipelineStateValidationInfo(M, Globals);
100 addCompilerVersion(M, Globals);
101 addSourceInfo(M, Globals);
106GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
107 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
113 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
114 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
117void DXContainerGlobals::addSection(
Module &M,
119 StringRef SectionData,
120 StringRef MetadataName,
121 StringRef SectionName) {
123 M.getContext(), SectionData,
false);
125 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
128void DXContainerGlobals::computeShaderHashAndDebugName(
130 ConstantDataArray *DXILConstant;
132 dxbc::ShaderHash HashData = {0, {0}};
135 if (
auto *ILDB =
M.getNamedGlobal(
"dx.ildb")) {
137 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
147 MD5::MD5Result
MD5 = Digest.
final();
149 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
MD5.data(), 16);
152 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
157 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
159 if (
M.debug_compile_units().empty())
162 SmallString<40> DebugNameStr;
164 DebugNameStr +=
".pdb";
167 SmallString<256> AbsoluteDebugName;
170 AbsoluteDebugName = DebugFile;
174 DebugNameStr = DebugFile;
175 AbsoluteDebugName = DebugNameStr;
179 addSection(M, Globals, AbsoluteDebugName,
"dx.pdb.name",
188 mcdxbc::DebugName DebugName;
190 SmallString<64> ILDNData;
191 raw_svector_ostream OS(ILDNData);
193 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
196GlobalVariable *DXContainerGlobals::buildContainerGlobal(
197 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
198 auto *GV =
new llvm::GlobalVariable(
200 GV->setSection(SectionName);
201 GV->setAlignment(
Align(4));
205GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
207 StringRef SectionName) {
208 SmallString<256>
Data;
209 raw_svector_ostream OS(
Data);
213 return buildContainerGlobal(M, Constant, Name, SectionName);
216void DXContainerGlobals::addSignature(
Module &M,
222 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
225 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
228void DXContainerGlobals::addRootSignature(
Module &M,
231 dxil::ModuleMetadataInfo &MMI =
232 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
238 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
239 const Function *EntryFunction =
nullptr;
246 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
250 SmallString<256>
Data;
251 raw_svector_ostream OS(
Data);
258void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
259 const DXILResourceMap &DRM =
260 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
261 DXILResourceTypeMap &DRTM =
262 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
265 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
267 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
268 dxbc::PSV::v2::ResourceBindInfo BindInfo;
274 "Resource range is too large");
284 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
285 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
287 dxil::ResourceKind::CBuffer));
289 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
290 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
292 dxbc::PSV::ResourceType::Sampler,
293 dxil::ResourceKind::Sampler));
295 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
296 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
298 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
301 ResType = dxbc::PSV::ResourceType::SRVStructured;
303 ResType = dxbc::PSV::ResourceType::SRVTyped;
305 ResType = dxbc::PSV::ResourceType::SRVRaw;
310 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
311 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
313 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
316 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
318 ResType = dxbc::PSV::ResourceType::UAVStructured;
320 ResType = dxbc::PSV::ResourceType::UAVTyped;
322 ResType = dxbc::PSV::ResourceType::UAVRaw;
324 dxbc::PSV::ResourceFlags
Flags;
334void DXContainerGlobals::addPipelineStateValidationInfo(
336 SmallString<256>
Data;
337 raw_svector_ostream OS(
Data);
342 dxil::ModuleMetadataInfo &MMI =
343 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
350 addResourcesForPSV(M, PSV);
383void DXContainerGlobals::addCompilerVersion(
385 if (
M.debug_compile_units().empty())
388 SmallString<256>
Data;
389 raw_svector_ostream OS(
Data);
390 mcdxbc::CompilerVersion CompilerVersion;
391 CompilerVersion.
write(OS);
395void DXContainerGlobals::addSourceInfo(
Module &M,
397 dxil::ModuleMetadataInfo &MMI =
398 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
405 SmallString<256>
Data;
406 raw_svector_ostream OS(
Data);
411char DXContainerGlobals::ID = 0;
413 "DXContainer Global Emitter",
false,
true)
422 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< std::string > PdbDebugPath("dx-pdb-path", cl::desc("Write debug information to the given file, or automatically " "named file in directory when ending in '/'"), cl::value_desc("filename"))
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