-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[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
Conversation
Empty ISG1 and OSG1 parts are generated for compute shader since there's no signature for compute shader. Fixes llvm#88778
@llvm/pr-subscribers-backend-directx Author: Xiang Li (python3kgae) ChangesEmpty ISG1 and OSG1 parts are generated for compute shader since there's no signature for compute shader. Fixes #88778 Full diff: https://github.com/llvm/llvm-project/pull/90508.diff 2 Files Affected:
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 65cf1dfdb4031b..4af4c506b630f4 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -28,8 +28,13 @@ using namespace llvm::dxil;
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 *buildInputSingature(Module &M, Constant *Content);
+ GlobalVariable *buildOutputSingature(Module &M, Constant *Content);
+ void addSingature(Module &M, SmallVector<GlobalValue *> &Globals, Triple &TT);
public:
static char ID; // Pass identification, replacement for typeid
@@ -55,7 +60,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;
}
@@ -104,6 +110,50 @@ 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::buildInputSingature(Module &M,
+ Constant *Content) {
+ return buildContainerGlobal(M, Content, "dx.isg1", "ISG1");
+}
+GlobalVariable *DXContainerGlobals::buildOutputSingature(Module &M,
+ Constant *Content) {
+ return buildContainerGlobal(M, Content, "dx.osg1", "OSG1");
+}
+
+void DXContainerGlobals::addSingature(Module &M,
+ SmallVector<GlobalValue *> &Globals,
+ Triple &TT) {
+ dxbc::ProgramSignatureHeader Sig;
+ Sig.ParamCount = 0;
+ Sig.FirstParamOffset = sizeof(dxbc::ProgramSignatureHeader);
+ Type *Int32Ty = Type::getInt32Ty(M.getContext());
+ Constant *InputSig = nullptr;
+ Constant *OutputSig = nullptr;
+ switch (TT.getEnvironment()) {
+ case Triple::EnvironmentType::Compute:
+ InputSig = ConstantStruct::get(
+ StructType::get(Int32Ty, Int32Ty),
+ {ConstantInt::get(M.getContext(), APInt(32, Sig.ParamCount)),
+ ConstantInt::get(M.getContext(), APInt(32, Sig.FirstParamOffset))});
+ OutputSig = InputSig;
+ break;
+ // FIXME: support graphics shader.
+ // see issue https://github.com/llvm/llvm-project/issues/90504.
+ default:
+ return;
+ }
+ Globals.emplace_back(buildInputSingature(M, InputSig));
+ Globals.emplace_back(buildOutputSingature(M, OutputSig));
+}
+
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 00000000000000..bae50606a6b2ac
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/EmptySignature.ll
@@ -0,0 +1,25 @@
+; 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 { i32, i32 } { i32 0, i32 8 }, section "ISG1", align 4
+; CHECK: @dx.osg1 = private constant { i32, i32 } { i32 0, i32 8 }, 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: []
|
|
||
void DXContainerGlobals::addSingature(Module &M, | ||
SmallVector<GlobalValue *> &Globals, | ||
Triple &TT) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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.
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")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
GlobalVariable *buildSingature(Module &M, Signature &Sig, StringRef Name, | ||
StringRef SectionName); | ||
void addSingature(Module &M, SmallVector<GlobalValue *> &Globals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlobalVariable *buildSingature(Module &M, Signature &Sig, StringRef Name, | |
StringRef SectionName); | |
void addSingature(Module &M, SmallVector<GlobalValue *> &Globals); | |
GlobalVariable *buildSignature(Module &M, Signature &Sig, StringRef Name, | |
StringRef SectionName); | |
void addSignature(Module &M, SmallVector<GlobalValue *> &Globals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to get the "singature" typos fixed.
Empty ISG1 and OSG1 parts are generated for compute shader since there's no signature for compute shader.
Fixes #88778