Skip to content

Commit a764f49

Browse files
authored
[DirectX backend] generate ISG1, OSG1 part for compute shader (#90508)
Empty ISG1 and OSG1 parts are generated for compute shader since there's no signature for compute shader. Fixes #88778
1 parent 6dfaecf commit a764f49

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

llvm/lib/Target/DirectX/DXContainerGlobals.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@
1818
#include "llvm/CodeGen/Passes.h"
1919
#include "llvm/IR/Constants.h"
2020
#include "llvm/InitializePasses.h"
21+
#include "llvm/MC/DXContainerPSVInfo.h"
2122
#include "llvm/Pass.h"
2223
#include "llvm/Support/MD5.h"
2324
#include "llvm/Transforms/Utils/ModuleUtils.h"
2425

2526
using namespace llvm;
2627
using namespace llvm::dxil;
28+
using namespace llvm::mcdxbc;
2729

2830
namespace {
2931
class DXContainerGlobals : public llvm::ModulePass {
3032

33+
GlobalVariable *buildContainerGlobal(Module &M, Constant *Content,
34+
StringRef Name, StringRef SectionName);
3135
GlobalVariable *getFeatureFlags(Module &M);
3236
GlobalVariable *computeShaderHash(Module &M);
37+
GlobalVariable *buildSignature(Module &M, Signature &Sig, StringRef Name,
38+
StringRef SectionName);
39+
void addSignature(Module &M, SmallVector<GlobalValue *> &Globals);
3340

3441
public:
3542
static char ID; // Pass identification, replacement for typeid
@@ -55,7 +62,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
5562
llvm::SmallVector<GlobalValue *> Globals;
5663
Globals.push_back(getFeatureFlags(M));
5764
Globals.push_back(computeShaderHash(M));
58-
65+
addSignature(M, Globals);
5966
appendToCompilerUsed(M, Globals);
6067
return true;
6168
}
@@ -68,12 +75,7 @@ GlobalVariable *DXContainerGlobals::getFeatureFlags(Module &M) {
6875

6976
Constant *FeatureFlagsConstant =
7077
ConstantInt::get(M.getContext(), APInt(64, FeatureFlags));
71-
auto *GV = new llvm::GlobalVariable(M, FeatureFlagsConstant->getType(), true,
72-
GlobalValue::PrivateLinkage,
73-
FeatureFlagsConstant, "dx.sfi0");
74-
GV->setSection("SFI0");
75-
GV->setAlignment(Align(4));
76-
return GV;
78+
return buildContainerGlobal(M, FeatureFlagsConstant, "dx.sfi0", "SFI0");
7779
}
7880

7981
GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
@@ -96,14 +98,41 @@ GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
9698

9799
Constant *ModuleConstant =
98100
ConstantDataArray::get(M.getContext(), arrayRefFromStringRef(Data));
99-
auto *GV = new llvm::GlobalVariable(M, ModuleConstant->getType(), true,
100-
GlobalValue::PrivateLinkage,
101-
ModuleConstant, "dx.hash");
102-
GV->setSection("HASH");
101+
return buildContainerGlobal(M, ModuleConstant, "dx.hash", "HASH");
102+
}
103+
104+
GlobalVariable *DXContainerGlobals::buildContainerGlobal(
105+
Module &M, Constant *Content, StringRef Name, StringRef SectionName) {
106+
auto *GV = new llvm::GlobalVariable(
107+
M, Content->getType(), true, GlobalValue::PrivateLinkage, Content, Name);
108+
GV->setSection(SectionName);
103109
GV->setAlignment(Align(4));
104110
return GV;
105111
}
106112

113+
GlobalVariable *DXContainerGlobals::buildSignature(Module &M, Signature &Sig,
114+
StringRef Name,
115+
StringRef SectionName) {
116+
SmallString<256> Data;
117+
raw_svector_ostream OS(Data);
118+
Sig.write(OS);
119+
Constant *Constant =
120+
ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
121+
return buildContainerGlobal(M, Constant, Name, SectionName);
122+
}
123+
124+
void DXContainerGlobals::addSignature(Module &M,
125+
SmallVector<GlobalValue *> &Globals) {
126+
// FIXME: support graphics shader.
127+
// see issue https://github.com/llvm/llvm-project/issues/90504.
128+
129+
Signature InputSig;
130+
Globals.emplace_back(buildSignature(M, InputSig, "dx.isg1", "ISG1"));
131+
132+
Signature OutputSig;
133+
Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
134+
}
135+
107136
char DXContainerGlobals::ID = 0;
108137
INITIALIZE_PASS_BEGIN(DXContainerGlobals, "dxil-globals",
109138
"DXContainer Global Emitter", false, true)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
2+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
; CHECK: @dx.isg1 = private constant [8 x i8] c"\00\00\00\00\08\00\00\00", section "ISG1", align 4
6+
; CHECK: @dx.osg1 = private constant [8 x i8] c"\00\00\00\00\08\00\00\00", section "OSG1", align 4
7+
8+
define void @main() #0 {
9+
entry:
10+
ret void
11+
}
12+
13+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
14+
15+
!dx.valver = !{!0}
16+
17+
!0 = !{i32 1, i32 7}
18+
19+
; DXC: - Name: ISG1
20+
; DXC-NEXT: Size: 8
21+
; DXC-NEXT: Signature:
22+
; DXC-NEXT: Parameters: []
23+
; DXC: - Name: OSG1
24+
; DXC-NEXT: Size: 8
25+
; DXC-NEXT: Signature:
26+
; DXC-NEXT: Parameters: []

0 commit comments

Comments
 (0)