summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiang Li <python3kgae@outlook.com>2024-05-01 09:33:58 -0700
committerGitHub <noreply@github.com>2024-05-01 12:33:58 -0400
commita764f49b4ae80daa5ba56cf0892bf0ebce48e2b3 (patch)
tree01eb1de827294543c761d28bde3b239dcf36af98
parent6dfaecf077ade4bf003345501fdcfcebc8409ff7 (diff)
[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
-rw-r--r--llvm/lib/Target/DirectX/DXContainerGlobals.cpp51
-rw-r--r--llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll26
2 files changed, 66 insertions, 11 deletions
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 65cf1dfdb403..67e04c212a69 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -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 *buildSignature(Module &M, Signature &Sig, StringRef Name,
+ StringRef SectionName);
+ void addSignature(Module &M, SmallVector<GlobalValue *> &Globals);
public:
static char ID; // Pass identification, replacement for typeid
@@ -55,7 +62,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
llvm::SmallVector<GlobalValue *> Globals;
Globals.push_back(getFeatureFlags(M));
Globals.push_back(computeShaderHash(M));
-
+ addSignature(M, Globals);
appendToCompilerUsed(M, Globals);
return true;
}
@@ -68,12 +75,7 @@ GlobalVariable *DXContainerGlobals::getFeatureFlags(Module &M) {
Constant *FeatureFlagsConstant =
ConstantInt::get(M.getContext(), APInt(64, FeatureFlags));
- auto *GV = new llvm::GlobalVariable(M, FeatureFlagsConstant->getType(), true,
- GlobalValue::PrivateLinkage,
- FeatureFlagsConstant, "dx.sfi0");
- GV->setSection("SFI0");
- GV->setAlignment(Align(4));
- return GV;
+ return buildContainerGlobal(M, FeatureFlagsConstant, "dx.sfi0", "SFI0");
}
GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
@@ -96,14 +98,41 @@ GlobalVariable *DXContainerGlobals::computeShaderHash(Module &M) {
Constant *ModuleConstant =
ConstantDataArray::get(M.getContext(), arrayRefFromStringRef(Data));
- auto *GV = new llvm::GlobalVariable(M, ModuleConstant->getType(), true,
- GlobalValue::PrivateLinkage,
- ModuleConstant, "dx.hash");
- GV->setSection("HASH");
+ return buildContainerGlobal(M, ModuleConstant, "dx.hash", "HASH");
+}
+
+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::buildSignature(Module &M, Signature &Sig,
+ StringRef Name,
+ StringRef SectionName) {
+ SmallString<256> Data;
+ raw_svector_ostream OS(Data);
+ Sig.write(OS);
+ Constant *Constant =
+ ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
+ return buildContainerGlobal(M, Constant, Name, SectionName);
+}
+
+void DXContainerGlobals::addSignature(Module &M,
+ SmallVector<GlobalValue *> &Globals) {
+ // FIXME: support graphics shader.
+ // see issue https://github.com/llvm/llvm-project/issues/90504.
+
+ Signature InputSig;
+ Globals.emplace_back(buildSignature(M, InputSig, "dx.isg1", "ISG1"));
+
+ Signature OutputSig;
+ Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
+}
+
char DXContainerGlobals::ID = 0;
INITIALIZE_PASS_BEGIN(DXContainerGlobals, "dxil-globals",
"DXContainer Global Emitter", false, true)
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll b/llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
new file mode 100644
index 000000000000..796f7942a80b
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
@@ -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: []