43 "dx-Zss",
cl::desc(
"Compute Shader Hash considering source information"));
56 void computeShaderHashAndDebugName(
Module &M,
63 void addPipelineStateValidationInfo(
Module &M,
72 StringRef getPassName()
const override {
73 return "DXContainer Global Emitter";
76 bool runOnModule(
Module &M)
override;
78 void getAnalysisUsage(AnalysisUsage &AU)
const override {
90bool DXContainerGlobals::runOnModule(
Module &M) {
93 computeShaderHashAndDebugName(M, Globals);
94 addSignature(M, Globals);
95 addRootSignature(M, Globals);
96 addPipelineStateValidationInfo(M, Globals);
97 addCompilerVersion(M, Globals);
98 addSourceInfo(M, Globals);
103GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
104 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
110 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
111 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
114void DXContainerGlobals::addSection(
Module &M,
116 StringRef SectionData,
117 StringRef MetadataName,
118 StringRef SectionName) {
120 M.getContext(), SectionData,
false);
122 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
125void DXContainerGlobals::computeShaderHashAndDebugName(
127 ConstantDataArray *DXILConstant;
129 dxbc::ShaderHash HashData = {0, {0}};
132 if (
auto *ILDB =
M.getNamedGlobal(
"dx.ildb")) {
134 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
144 MD5::MD5Result
MD5 = Digest.
final();
146 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
MD5.data(), 16);
149 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
154 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
156 if (
M.debug_compile_units().empty())
159 SmallString<40> DebugNameStr;
161 DebugNameStr +=
".pdb";
164 SmallString<256> AbsoluteDebugName;
167 AbsoluteDebugName = DebugFile;
171 DebugNameStr = DebugFile;
172 AbsoluteDebugName = DebugNameStr;
176 addSection(M, Globals, AbsoluteDebugName,
"dx.pdb.name",
185 mcdxbc::DebugName DebugName;
187 SmallString<64> ILDNData;
188 raw_svector_ostream OS(ILDNData);
190 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
193GlobalVariable *DXContainerGlobals::buildContainerGlobal(
194 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
195 auto *GV =
new llvm::GlobalVariable(
197 GV->setSection(SectionName);
198 GV->setAlignment(
Align(4));
202GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
204 StringRef SectionName) {
205 SmallString<256>
Data;
206 raw_svector_ostream OS(
Data);
210 return buildContainerGlobal(M, Constant, Name, SectionName);
213void DXContainerGlobals::addSignature(
Module &M,
219 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
222 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
225void DXContainerGlobals::addRootSignature(
Module &M,
228 dxil::ModuleMetadataInfo &MMI =
229 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
235 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
236 const Function *EntryFunction =
nullptr;
243 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
247 SmallString<256>
Data;
248 raw_svector_ostream OS(
Data);
255void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
256 const DXILResourceMap &DRM =
257 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
258 DXILResourceTypeMap &DRTM =
259 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
262 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
264 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
265 dxbc::PSV::v2::ResourceBindInfo BindInfo;
271 "Resource range is too large");
281 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
282 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
284 dxil::ResourceKind::CBuffer));
286 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
287 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
289 dxbc::PSV::ResourceType::Sampler,
290 dxil::ResourceKind::Sampler));
292 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
293 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
295 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
298 ResType = dxbc::PSV::ResourceType::SRVStructured;
300 ResType = dxbc::PSV::ResourceType::SRVTyped;
302 ResType = dxbc::PSV::ResourceType::SRVRaw;
307 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
308 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
310 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
313 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
315 ResType = dxbc::PSV::ResourceType::UAVStructured;
317 ResType = dxbc::PSV::ResourceType::UAVTyped;
319 ResType = dxbc::PSV::ResourceType::UAVRaw;
321 dxbc::PSV::ResourceFlags
Flags;
331void DXContainerGlobals::addPipelineStateValidationInfo(
333 SmallString<256>
Data;
334 raw_svector_ostream OS(
Data);
339 dxil::ModuleMetadataInfo &MMI =
340 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
347 addResourcesForPSV(M, PSV);
380void DXContainerGlobals::addCompilerVersion(
382 if (
M.debug_compile_units().empty())
385 SmallString<256>
Data;
386 raw_svector_ostream OS(
Data);
387 mcdxbc::CompilerVersion CompilerVersion;
388 CompilerVersion.
write(OS);
392void DXContainerGlobals::addSourceInfo(
Module &M,
394 dxil::ModuleMetadataInfo &MMI =
395 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
402 SmallString<256>
Data;
403 raw_svector_ostream OS(
Data);
408char DXContainerGlobals::ID = 0;
410 "DXContainer Global Emitter",
false,
true)
419 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
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