Skip to content

[DirectX backend] generate ISG1, OSG1 part for compute shader #90508

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 6 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
43 changes: 42 additions & 1 deletion llvm/lib/Target/DirectX/DXContainerGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/Constants.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/DXContainerPSVInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"

using namespace llvm;
using namespace llvm::dxil;
using namespace llvm::mcdxbc;

namespace {
class DXContainerGlobals : public llvm::ModulePass {

GlobalVariable *buildContainerGlobal(Module &M, Constant *Content,
StringRef Name, StringRef SectionName);
GlobalVariable *getFeatureFlags(Module &M);
GlobalVariable *computeShaderHash(Module &M);
GlobalVariable *buildSingature(Module &M, Signature &Sig, StringRef Name,
StringRef SectionName);
void addSingature(Module &M, SmallVector<GlobalValue *> &Globals, Triple &TT);

public:
static char ID; // Pass identification, replacement for typeid
Expand All @@ -55,7 +62,8 @@ bool DXContainerGlobals::runOnModule(Module &M) {
llvm::SmallVector<GlobalValue *> Globals;
Globals.push_back(getFeatureFlags(M));
Globals.push_back(computeShaderHash(M));

Triple TT(M.getTargetTriple());
addSingature(M, Globals, TT);
appendToCompilerUsed(M, Globals);
return true;
}
Expand Down Expand Up @@ -104,6 +112,39 @@ GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
return GV;
}

GlobalVariable *DXContainerGlobals::buildContainerGlobal(
Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
auto *GV = new llvm::GlobalVariable(
M, Content->getType(), true, GlobalValue::PrivateLinkage, Content, Name);
GV->setSection(SectionName);
GV->setAlignment(Align(4));
return GV;
}

GlobalVariable *DXContainerGlobals::buildSingature(Module &M, Signature &Sig,
StringRef Name,
StringRef SectionName) {
std::string Data;
raw_string_ostream OS(Data);
Sig.write(OS);
OS.flush();
Constant *Constant =
ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
return buildContainerGlobal(M, Constant, Name, SectionName);
}

void DXContainerGlobals::addSingature(Module &M,
SmallVector<GlobalValue *> &Globals,
Triple &TT) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TT is unused (and also reachable from the module)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Signature InputSig;
Signature OutputSig;
// FIXME: support graphics shader.
// see issue https://github.com/llvm/llvm-project/issues/90504.

Globals.emplace_back(buildSingature(M, InputSig, "dx.isg1", "ISG1"));
Globals.emplace_back(buildSingature(M, OutputSig, "dx.osg1", "OSG1"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It's clearer to read what is going on here if we group creating the signature with emitting it.

Suggested change
Signature InputSig;
Signature OutputSig;
// FIXME: support graphics shader.
// see issue https://github.com/llvm/llvm-project/issues/90504.
Globals.emplace_back(buildSingature(M, InputSig, "dx.isg1", "ISG1"));
Globals.emplace_back(buildSingature(M, OutputSig, "dx.osg1", "OSG1"));
// FIXME: support graphics shader.
// see issue https://github.com/llvm/llvm-project/issues/90504.
Signature InputSig;
Globals.emplace_back(buildSingature(M, InputSig, "dx.isg1", "ISG1"));
Signature OutputSig;
Globals.emplace_back(buildSingature(M, OutputSig, "dx.osg1", "OSG1"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}

char DXContainerGlobals::ID = 0;
INITIALIZE_PASS_BEGIN(DXContainerGlobals, "dxil-globals",
"DXContainer Global Emitter", false, true)
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; 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.isg1 = private constant [8 x i8] c"\00\00\00\00\08\00\00\00", section "ISG1", align 4
; CHECK: @dx.osg1 = private constant [8 x i8] c"\00\00\00\00\08\00\00\00", section "OSG1", 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: ISG1
; DXC-NEXT: Size: 8
; DXC-NEXT: Signature:
; DXC-NEXT: Parameters: []
; DXC: - Name: OSG1
; DXC-NEXT: Size: 8
; DXC-NEXT: Signature:
; DXC-NEXT: Parameters: []
Loading