41 GlobalVariable *buildContainerGlobal(
Module &M, Constant *Content,
42 StringRef Name, StringRef SectionName);
44 StringRef SectionData, StringRef MetadataName,
45 StringRef SectionName);
46 GlobalVariable *getFeatureFlags(
Module &M);
47 void computeShaderHashAndDebugName(
Module &M,
49 GlobalVariable *buildSignature(
Module &M, Signature &Sig, StringRef Name,
50 StringRef SectionName);
53 void addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV);
54 void addPipelineStateValidationInfo(
Module &M,
59 DXContainerGlobals() : ModulePass(ID) {}
61 StringRef getPassName()
const override {
62 return "DXContainer Global Emitter";
65 bool runOnModule(
Module &M)
override;
67 void getAnalysisUsage(AnalysisUsage &AU)
const override {
79bool DXContainerGlobals::runOnModule(
Module &M) {
82 computeShaderHashAndDebugName(M, Globals);
83 addSignature(M, Globals);
84 addRootSignature(M, Globals);
85 addPipelineStateValidationInfo(M, Globals);
90GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
91 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
97 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
98 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
101void DXContainerGlobals::addSection(
Module &M,
103 StringRef SectionData,
104 StringRef MetadataName,
105 StringRef SectionName) {
107 M.getContext(), SectionData,
false);
109 buildContainerGlobal(M, SectionConstant, MetadataName, SectionName));
112void DXContainerGlobals::computeShaderHashAndDebugName(
117 Digest.
update(DXILConstant->getRawDataValues());
120 dxbc::ShaderHash HashData = {0, {0}};
123 if (!
M.debug_compile_units().empty())
124 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
126 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
129 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
134 buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH"));
139 if (
M.debug_compile_units().empty())
142 SmallString<40> DebugNameStr;
144 DebugNameStr +=
".pdb";
146 mcdxbc::DebugName DebugName;
149 SmallString<64> ILDNData;
150 raw_svector_ostream OS(ILDNData);
152 addSection(M, Globals, ILDNData,
"dx.ildn",
"ILDN");
155GlobalVariable *DXContainerGlobals::buildContainerGlobal(
156 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
157 auto *GV =
new llvm::GlobalVariable(
159 GV->setSection(SectionName);
160 GV->setAlignment(
Align(4));
164GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
166 StringRef SectionName) {
167 SmallString<256>
Data;
168 raw_svector_ostream OS(
Data);
172 return buildContainerGlobal(M, Constant, Name, SectionName);
175void DXContainerGlobals::addSignature(
Module &M,
181 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
184 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
187void DXContainerGlobals::addRootSignature(
Module &M,
190 dxil::ModuleMetadataInfo &MMI =
191 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
197 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
198 const Function *EntryFunction =
nullptr;
205 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
209 SmallString<256>
Data;
210 raw_svector_ostream OS(
Data);
217void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
218 const DXILResourceMap &DRM =
219 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
220 DXILResourceTypeMap &DRTM =
221 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
224 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
226 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
227 dxbc::PSV::v2::ResourceBindInfo BindInfo;
233 "Resource range is too large");
243 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
244 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
246 dxil::ResourceKind::CBuffer));
248 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
249 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
251 dxbc::PSV::ResourceType::Sampler,
252 dxil::ResourceKind::Sampler));
254 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
255 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
257 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
260 ResType = dxbc::PSV::ResourceType::SRVStructured;
262 ResType = dxbc::PSV::ResourceType::SRVTyped;
264 ResType = dxbc::PSV::ResourceType::SRVRaw;
269 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
270 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
272 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
275 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
277 ResType = dxbc::PSV::ResourceType::UAVStructured;
279 ResType = dxbc::PSV::ResourceType::UAVTyped;
281 ResType = dxbc::PSV::ResourceType::UAVRaw;
283 dxbc::PSV::ResourceFlags
Flags;
293void DXContainerGlobals::addPipelineStateValidationInfo(
295 SmallString<256>
Data;
296 raw_svector_ostream OS(
Data);
301 dxil::ModuleMetadataInfo &MMI =
302 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
309 addResourcesForPSV(M, PSV);
342char DXContainerGlobals::ID = 0;
344 "DXContainer Global Emitter",
false,
true)
353 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.
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 a string ref from an array ref of unsigned chars.
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
void setFilename(StringRef DebugFilename)
void write(raw_ostream &OS) const
dxbc::PSV::v3::RuntimeInfo BaseData
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
void finalize(Triple::EnvironmentType Stage, uint32_t Version=std::numeric_limits< uint32_t >::max())
void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const