[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
This commit is contained in:
parent
6dfaecf077
commit
a764f49b4a
@ -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)
|
||||
|
||||
26
llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
Normal file
26
llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
Normal file
@ -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…
x
Reference in New Issue
Block a user