-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DirectX] Add stub PSV0 section #96712
Conversation
@llvm/pr-subscribers-backend-directx Author: Damyan Pepper (damyanp) ChangesDirect3D 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 Full diff: https://github.com/llvm/llvm-project/pull/96712.diff 3 Files Affected:
diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h
index bad2fe78eb8fb..3a2d2949d0223 100644
--- a/llvm/include/llvm/MC/DXContainerPSVInfo.h
+++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h
@@ -47,7 +47,9 @@ struct PSVSignatureElement {
// modifiable format, and can be used to serialize the data back into valid PSV
// RuntimeInfo.
struct PSVRuntimeInfo {
- PSVRuntimeInfo() : DXConStrTabBuilder(StringTableBuilder::DXContainer) {}
+ PSVRuntimeInfo() : DXConStrTabBuilder(StringTableBuilder::DXContainer) {
+ memset((void *)&BaseData, 0, sizeof(dxbc::PSV::v3::RuntimeInfo));
+ }
bool IsFinalized = false;
dxbc::PSV::v3::RuntimeInfo BaseData;
SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources;
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 67e04c212a692..18d1029d66eb0 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.
+ //
+ // 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)
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/PipelineStateValidation.ll b/llvm/test/CodeGen/DirectX/ContainerData/PipelineStateValidation.ll
new file mode 100644
index 0000000000000..9e1720b0b1cac
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/PipelineStateValidation.ll
@@ -0,0 +1,41 @@
+; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
+; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: @dx.psv0 = private constant [76 x i8] c"{{.*}}", section "PSV0", align 4
+
+define void @main() #0 {
+entry:
+ ret void
+}
+
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+!dx.valver = !{!0}
+
+!0 = !{i32 1, i32 7}
+
+; DXC: - Name: PSV0
+; DXC: Size: 76
+; DXC: PSVInfo:
+; DXC: Version: 3
+; DXC: ShaderStage: 5
+; DXC: MinimumWaveLaneCount: 0
+; DXC: MaximumWaveLaneCount: 4294967295
+; DXC: UsesViewID: 0
+; DXC: SigInputVectors: 0
+; DXC: SigOutputVectors: [ 0, 0, 0, 0 ]
+; DXC: NumThreadsX: 1
+; DXC: NumThreadsY: 1
+; DXC: NumThreadsZ: 1
+; DXC: EntryName: main
+; DXC: ResourceStride: 24
+; DXC: Resources: []
+; DXC: SigInputElements: []
+; DXC: SigOutputElements: []
+; DXC: SigPatchOrPrimElements: []
+; DXC: InputOutputMap:
+; DXC: - [ ]
+; DXC: - [ ]
+; DXC: - [ ]
+; DXC: - [ ]
\ No newline at end of file
|
// | ||
// Lots more stuff to do here! | ||
// | ||
// See issue https://github.com/llvm/llvm-project/issues/96674. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd probably good to have "TODO:" somewhere in this comment like we have elsewhere
6a98ce3
to
7b469a7
Compare
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
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
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 llvm/wg-hlsl#7