aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorDamyan Pepper <damyanp@microsoft.com>2024-06-26 11:15:34 -0700
committerGitHub <noreply@github.com>2024-06-26 11:15:34 -0700
commit141bea8c3cad62b381aef3c216cf7f78b812f580 (patch)
treef73abfe6255b48f5fca05ad68ed41b5528808e16 /llvm/lib
parent868fae1f2ecb54604231c1334ce9aa5b4c0b1288 (diff)
downloadllvm-141bea8c3cad62b381aef3c216cf7f78b812f580.zip
llvm-141bea8c3cad62b381aef3c216cf7f78b812f580.tar.gz
llvm-141bea8c3cad62b381aef3c216cf7f78b812f580.tar.bz2
[DirectX] Add stub PSV0 section (#96712)
Direct3D requires a PSV0 section to be present in the DXContainer in order to be able to load and use the shader. This change adds a minimal stub PSV0, with some hard-coded values, that are just enough to unblock loading into Direct3D. Contributes to #90129
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/DirectX/DXContainerGlobals.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 67e04c2..f49ccfe 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -37,6 +37,8 @@ class DXContainerGlobals : public llvm::ModulePass {
GlobalVariable *buildSignature(Module &M, Signature &Sig, StringRef Name,
StringRef SectionName);
void addSignature(Module &M, SmallVector<GlobalValue *> &Globals);
+ void addPipelineStateValidationInfo(Module &M,
+ SmallVector<GlobalValue *> &Globals);
public:
static char ID; // Pass identification, replacement for typeid
@@ -63,6 +65,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
Globals.push_back(getFeatureFlags(M));
Globals.push_back(computeShaderHash(M));
addSignature(M, Globals);
+ addPipelineStateValidationInfo(M, Globals);
appendToCompilerUsed(M, Globals);
return true;
}
@@ -133,6 +136,34 @@ void DXContainerGlobals::addSignature(Module &M,
Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
}
+void DXContainerGlobals::addPipelineStateValidationInfo(
+ Module &M, SmallVector<GlobalValue *> &Globals) {
+ SmallString<256> Data;
+ raw_svector_ostream OS(Data);
+ PSVRuntimeInfo PSV;
+ Triple TT(M.getTargetTriple());
+ PSV.BaseData.MinimumWaveLaneCount = 0;
+ PSV.BaseData.MaximumWaveLaneCount = std::numeric_limits<uint32_t>::max();
+ PSV.BaseData.ShaderStage =
+ static_cast<uint8_t>(TT.getEnvironment() - Triple::Pixel);
+
+ // Hardcoded values here to unblock loading the shader into D3D.
+ //
+ // TODO: Lots more stuff to do here!
+ //
+ // See issue https://github.com/llvm/llvm-project/issues/96674.
+ PSV.BaseData.NumThreadsX = 1;
+ PSV.BaseData.NumThreadsY = 1;
+ PSV.BaseData.NumThreadsZ = 1;
+ PSV.EntryName = "main";
+
+ PSV.finalize(TT.getEnvironment());
+ PSV.write(OS);
+ Constant *Constant =
+ ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
+ Globals.emplace_back(buildContainerGlobal(M, Constant, "dx.psv0", "PSV0"));
+}
+
char DXContainerGlobals::ID = 0;
INITIALIZE_PASS_BEGIN(DXContainerGlobals, "dxil-globals",
"DXContainer Global Emitter", false, true)