43 "dx-Zss",
cl::desc(
"Compute Shader Hash considering source information"));
46 cl::desc(
"Specify the PDB output file path for DirectX target"),
50 cl::desc(
"Specify the PDB output directory for DirectX target. The file "
51 "name is derived from the shader hash"),
63 void computeShaderHashAndDebugName(
Module &M,
70 void addPipelineStateValidationInfo(
Module &M,
79 StringRef getPassName()
const override {
80 return "DXContainer Global Emitter";
83 bool runOnModule(
Module &M)
override;
85 void getAnalysisUsage(AnalysisUsage &AU)
const override {
97bool DXContainerGlobals::runOnModule(
Module &M) {
100 computeShaderHashAndDebugName(M, Globals);
101 addSignature(M, Globals);
102 addRootSignature(M, Globals);
103 addPipelineStateValidationInfo(M, Globals);
104 addCompilerVersion(M, Globals);
105 addSourceInfo(M, Globals);
110GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
111 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
117 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
118 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
121void DXContainerGlobals::addSection(
Module &M,
123 StringRef SectionData,
124 StringRef MetadataName,
125 StringRef SectionName) {
127 M.getContext(), SectionData,
false);
129 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
132void DXContainerGlobals::computeShaderHashAndDebugName(
134 ConstantDataArray *DXILConstant;
136 dxbc::ShaderHash HashData = {0, {0}};
139 if (
auto *ILDB =
M.getNamedGlobal(
"dx.ildb")) {
141 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
153 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
156 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
161 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
166 if (
M.debug_compile_units().empty())
171 "--dx-pdb-file and --dx-pdb-dir are mutually exclusive options");
173 SmallString<40> DebugNameStr;
175 DebugNameStr +=
".pdb";
177 mcdxbc::DebugName DebugName;
181 DebugNameStr +=
".pdb";
191 SmallString<64> ILDNData;
192 raw_svector_ostream OS(ILDNData);
194 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
198 addSection(M, Globals, AbsoluteDebugName,
"dx.pdb.name",
206GlobalVariable *DXContainerGlobals::buildContainerGlobal(
207 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
208 auto *GV =
new llvm::GlobalVariable(
210 GV->setSection(SectionName);
211 GV->setAlignment(
Align(4));
215GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
217 StringRef SectionName) {
218 SmallString<256>
Data;
219 raw_svector_ostream OS(
Data);
223 return buildContainerGlobal(M, Constant, Name, SectionName);
226void DXContainerGlobals::addSignature(
Module &M,
232 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
235 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
238void DXContainerGlobals::addRootSignature(
Module &M,
241 dxil::ModuleMetadataInfo &MMI =
242 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
248 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
249 const Function *EntryFunction =
nullptr;
256 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
260 SmallString<256>
Data;
261 raw_svector_ostream OS(
Data);
268void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
269 const DXILResourceMap &DRM =
270 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
271 DXILResourceTypeMap &DRTM =
272 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
275 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
277 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
278 dxbc::PSV::v2::ResourceBindInfo BindInfo;
284 "Resource range is too large");
294 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
295 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
297 dxil::ResourceKind::CBuffer));
299 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
300 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
302 dxbc::PSV::ResourceType::Sampler,
303 dxil::ResourceKind::Sampler));
305 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
306 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
308 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
311 ResType = dxbc::PSV::ResourceType::SRVStructured;
313 ResType = dxbc::PSV::ResourceType::SRVTyped;
315 ResType = dxbc::PSV::ResourceType::SRVRaw;
320 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
321 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
323 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
326 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
328 ResType = dxbc::PSV::ResourceType::UAVStructured;
330 ResType = dxbc::PSV::ResourceType::UAVTyped;
332 ResType = dxbc::PSV::ResourceType::UAVRaw;
334 dxbc::PSV::ResourceFlags
Flags;
344void DXContainerGlobals::addPipelineStateValidationInfo(
346 SmallString<256>
Data;
347 raw_svector_ostream OS(
Data);
352 dxil::ModuleMetadataInfo &MMI =
353 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
360 addResourcesForPSV(M, PSV);
393void DXContainerGlobals::addCompilerVersion(
395 if (
M.debug_compile_units().empty())
398 SmallString<256>
Data;
399 raw_svector_ostream OS(
Data);
400 mcdxbc::CompilerVersion CompilerVersion;
401 CompilerVersion.
write(OS);
405void DXContainerGlobals::addSourceInfo(
Module &M,
407 dxil::ModuleMetadataInfo &MMI =
408 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
415 SmallString<256>
Data;
416 raw_svector_ostream OS(
Data);
420 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.srci",
"SRCI"));
423char DXContainerGlobals::ID = 0;
425 "DXContainer Global Emitter",
false,
true)
434 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...
static cl::opt< std::string > PdbFileName("dx-pdb-file", cl::desc("Specify the PDB output file path for DirectX target"), cl::value_desc("filename"))
static cl::opt< std::string > PdbOutputDir("dx-pdb-dir", cl::desc("Specify the PDB output directory for DirectX target. The file " "name is derived from the shader hash"), cl::value_desc("directory"))
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.
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.
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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.
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