41 GlobalVariable *buildContainerGlobal(
Module &M, Constant *Content,
42 StringRef Name, StringRef SectionName);
43 GlobalVariable *getFeatureFlags(
Module &M);
44 GlobalVariable *computeShaderHash(
Module &M);
45 GlobalVariable *buildSignature(
Module &M, Signature &Sig, StringRef Name,
46 StringRef SectionName);
49 void addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV);
50 void addPipelineStateValidationInfo(
Module &M,
55 DXContainerGlobals() : ModulePass(ID) {}
57 StringRef getPassName()
const override {
58 return "DXContainer Global Emitter";
61 bool runOnModule(
Module &M)
override;
63 void getAnalysisUsage(AnalysisUsage &AU)
const override {
75bool DXContainerGlobals::runOnModule(
Module &M) {
79 addSignature(M, Globals);
80 addRootSignature(M, Globals);
81 addPipelineStateValidationInfo(M, Globals);
86GlobalVariable *DXContainerGlobals::getFeatureFlags(
Module &M) {
87 uint64_t CombinedFeatureFlags = getAnalysis<ShaderFlagsAnalysisWrapper>()
93 ConstantInt::get(
M.getContext(), APInt(64, CombinedFeatureFlags));
94 return buildContainerGlobal(M, FeatureFlagsConstant,
"dx.sfi0",
"SFI0");
97GlobalVariable *DXContainerGlobals::computeShaderHash(
Module &M) {
101 Digest.
update(DXILConstant->getRawDataValues());
104 dxbc::ShaderHash HashData = {0, {0}};
107 if (!
M.debug_compile_units().empty())
108 HashData.
Flags =
static_cast<uint32_t
>(dxbc::HashFlags::IncludesSource);
110 memcpy(
reinterpret_cast<void *
>(&HashData.
Digest),
Result.data(), 16);
113 StringRef
Data(
reinterpret_cast<char *
>(&HashData),
sizeof(dxbc::ShaderHash));
117 return buildContainerGlobal(M, ModuleConstant,
"dx.hash",
"HASH");
120GlobalVariable *DXContainerGlobals::buildContainerGlobal(
121 Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
122 auto *GV =
new llvm::GlobalVariable(
124 GV->setSection(SectionName);
125 GV->setAlignment(
Align(4));
129GlobalVariable *DXContainerGlobals::buildSignature(
Module &M, Signature &Sig,
131 StringRef SectionName) {
132 SmallString<256>
Data;
133 raw_svector_ostream OS(
Data);
137 return buildContainerGlobal(M, Constant, Name, SectionName);
140void DXContainerGlobals::addSignature(
Module &M,
146 Globals.
emplace_back(buildSignature(M, InputSig,
"dx.isg1",
"ISG1"));
149 Globals.
emplace_back(buildSignature(M, OutputSig,
"dx.osg1",
"OSG1"));
152void DXContainerGlobals::addRootSignature(
Module &M,
155 dxil::ModuleMetadataInfo &MMI =
156 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
162 auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
163 const Function *EntryFunction =
nullptr;
170 const mcdxbc::RootSignatureDesc *
RS = RSA.getDescForFunction(EntryFunction);
174 SmallString<256>
Data;
175 raw_svector_ostream OS(
Data);
181 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.rts0",
"RTS0"));
184void DXContainerGlobals::addResourcesForPSV(
Module &M, PSVRuntimeInfo &PSV) {
185 const DXILResourceMap &DRM =
186 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
187 DXILResourceTypeMap &DRTM =
188 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
191 [](
const dxil::ResourceInfo::ResourceBinding &
Binding,
193 const dxbc::PSV::ResourceFlags
Flags = dxbc::PSV::ResourceFlags()) {
194 dxbc::PSV::v2::ResourceBindInfo BindInfo;
199 "Resource range is too large");
209 for (
const dxil::ResourceInfo &RI : DRM.
cbuffers()) {
210 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
212 dxil::ResourceKind::CBuffer));
214 for (
const dxil::ResourceInfo &RI : DRM.
samplers()) {
215 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
217 dxbc::PSV::ResourceType::Sampler,
218 dxil::ResourceKind::Sampler));
220 for (
const dxil::ResourceInfo &RI : DRM.
srvs()) {
221 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
223 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
226 ResType = dxbc::PSV::ResourceType::SRVStructured;
228 ResType = dxbc::PSV::ResourceType::SRVTyped;
230 ResType = dxbc::PSV::ResourceType::SRVRaw;
235 for (
const dxil::ResourceInfo &RI : DRM.
uavs()) {
236 const dxil::ResourceInfo::ResourceBinding &
Binding = RI.getBinding();
238 dxil::ResourceTypeInfo &TypeInfo = DRTM[RI.getHandleTy()];
241 ResType = dxbc::PSV::ResourceType::UAVStructuredWithCounter;
243 ResType = dxbc::PSV::ResourceType::UAVStructured;
245 ResType = dxbc::PSV::ResourceType::UAVTyped;
247 ResType = dxbc::PSV::ResourceType::UAVRaw;
249 dxbc::PSV::ResourceFlags
Flags;
259void DXContainerGlobals::addPipelineStateValidationInfo(
261 SmallString<256>
Data;
262 raw_svector_ostream OS(
Data);
267 dxil::ModuleMetadataInfo &MMI =
268 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
275 addResourcesForPSV(M, PSV);
300 Globals.
emplace_back(buildContainerGlobal(M, Constant,
"dx.psv0",
"PSV0"));
303char DXContainerGlobals::ID = 0;
305 "DXContainer Global Emitter",
false,
true)
314 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.
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 LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
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.
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
dxbc::PSV::v3::RuntimeInfo BaseData
llvm::StringRef EntryName
SmallVector< dxbc::PSV::v2::ResourceBindInfo > Resources
void finalize(Triple::EnvironmentType Stage)
void write(raw_ostream &OS, uint32_t Version=std::numeric_limits< uint32_t >::max()) const