-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Changes from 2 commits
d745a77
bca032c
de055b1
4a4f392
25c2541
b216910
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||||||||||||||||||||||
|
@@ -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; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
@@ -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); | ||||||||||||||||||||||||||||||
llvm-beanz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
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) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||||||||||||||||||||||||
|
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: [] |
Uh oh!
There was an error while loading. Please reload this page.