-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[HLSL] Implicit resource binding for cbuffers #139022
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 23 commits
d5685ec
d8a4a3f
d79900c
c718763
9a70f06
bca1bf3
f58e2d5
b65d3bc
075e27e
2f0aba1
79c2e7b
e9747e5
da838a9
dfce6ce
8194951
bcf27e9
1f997d8
8a27708
bc93994
8142713
9eab67d
4a3e4c5
03da2d1
f3d9605
d4a3bcd
fb3d516
2ff496b
e4369aa
cecd1e4
cef2c3e
d82236d
84d710d
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#include "clang/AST/Type.h" | ||
#include "clang/Basic/TargetOptions.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/GlobalVariable.h" | ||
#include "llvm/IR/LLVMContext.h" | ||
|
@@ -42,8 +43,8 @@ using namespace llvm; | |
using llvm::hlsl::CBufferRowSizeInBytes; | ||
|
||
static void initializeBufferFromBinding(CodeGenModule &CGM, | ||
llvm::GlobalVariable *GV, unsigned Slot, | ||
unsigned Space); | ||
llvm::GlobalVariable *GV, | ||
HLSLResourceBindingAttr *RBA); | ||
|
||
namespace { | ||
|
||
|
@@ -257,13 +258,10 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) { | |
emitBufferGlobalsAndMetadata(BufDecl, BufGV); | ||
|
||
// Initialize cbuffer from binding (implicit or explicit) | ||
const HLSLResourceBindingAttr *RBA = | ||
BufDecl->getAttr<HLSLResourceBindingAttr>(); | ||
// FIXME: handle implicit binding if no binding attribute is found | ||
// (llvm/llvm-project#110722) | ||
if (RBA && RBA->hasRegisterSlot()) | ||
initializeBufferFromBinding(CGM, BufGV, RBA->getSlotNumber(), | ||
RBA->getSpaceNumber()); | ||
HLSLResourceBindingAttr *RBA = BufDecl->getAttr<HLSLResourceBindingAttr>(); | ||
assert(RBA && | ||
"cbuffer/tbuffer should always have resource binding attribute"); | ||
initializeBufferFromBinding(CGM, BufGV, RBA); | ||
} | ||
|
||
llvm::TargetExtType * | ||
|
@@ -539,19 +537,27 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV, | |
} | ||
|
||
static void initializeBufferFromBinding(CodeGenModule &CGM, | ||
llvm::GlobalVariable *GV, unsigned Slot, | ||
unsigned Space) { | ||
llvm::GlobalVariable *GV, | ||
HLSLResourceBindingAttr *RBA) { | ||
llvm::Type *Int1Ty = llvm::Type::getInt1Ty(CGM.getLLVMContext()); | ||
llvm::Value *Args[] = { | ||
llvm::ConstantInt::get(CGM.IntTy, Space), /* reg_space */ | ||
llvm::ConstantInt::get(CGM.IntTy, Slot), /* lower_bound */ | ||
llvm::ConstantInt::get(CGM.IntTy, 1), /* range_size */ | ||
llvm::ConstantInt::get(CGM.IntTy, 0), /* index */ | ||
llvm::ConstantInt::get(Int1Ty, false) /* non-uniform */ | ||
}; | ||
initializeBuffer(CGM, GV, | ||
CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic(), | ||
Args); | ||
auto *False = llvm::ConstantInt::get(Int1Ty, false); | ||
auto *Zero = llvm::ConstantInt::get(CGM.IntTy, 0); | ||
auto *One = llvm::ConstantInt::get(CGM.IntTy, 1); | ||
auto *Space = | ||
llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0); | ||
|
||
if (RBA->hasRegisterSlot()) { | ||
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. You are unconditionally dereferencing 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. ping 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. Opened issue here: #145525 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. Thanks @shafik for following up! I was planning to fix this before I left on vacation but didn't get to it. |
||
auto *RegSlot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber()); | ||
Intrinsic::ID Intr = | ||
CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic(); | ||
initializeBuffer(CGM, GV, Intr, {Space, RegSlot, One, Zero, False}); | ||
} else { | ||
auto *OrderID = | ||
llvm::ConstantInt::get(CGM.IntTy, RBA->getImplicitBindingOrderID()); | ||
Intrinsic::ID Intr = | ||
CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic(); | ||
initializeBuffer(CGM, GV, Intr, {OrderID, Space, One, Zero, False}); | ||
} | ||
} | ||
|
||
llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.