Skip to content

[DirectX] Add stub PSV0 section #96712

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

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/include/llvm/MC/DXContainerPSVInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions llvm/lib/Target/DirectX/DXContainerGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Copy link
Contributor

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

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)
Expand Down
41 changes: 41 additions & 0 deletions llvm/test/CodeGen/DirectX/ContainerData/PipelineStateValidation.ll
Original file line number Diff line number Diff line change
@@ -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: - [ ]
Loading