Skip to content

Commit bcf27e9

Browse files
committed
Handle space-only implicit binding
1 parent 8194951 commit bcf27e9

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
536536
BufDecl->addLayoutStruct(LS);
537537
}
538538

539-
void addImplicitBindingAttrToBuffer(Sema &S, HLSLBufferDecl *BufDecl,
539+
static void addImplicitBindingAttrToBuffer(Sema &S, HLSLBufferDecl *BufDecl,
540540
uint32_t ImplicitBindingOrderID) {
541541
RegisterType RT =
542542
BufDecl->isCBuffer() ? RegisterType::CBuffer : RegisterType::SRV;
@@ -558,13 +558,16 @@ void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
558558
// create buffer layout struct
559559
createHostLayoutStructForBuffer(SemaRef, BufDecl);
560560

561-
if (std::none_of(Dcl->attr_begin(), Dcl->attr_end(),
562-
[](Attr *A) { return isa<HLSLResourceBindingAttr>(A); })) {
561+
HLSLResourceBindingAttr *RBA = Dcl->getAttr<HLSLResourceBindingAttr>();
562+
if (!RBA || RBA->isImplicit()) {
563563
SemaRef.Diag(Dcl->getLocation(), diag::warn_hlsl_implicit_binding);
564-
// add implicit HLSLResourceBindingAttr for the buffer
565-
// (used mostly as a way to tranfer ImplicitBindingOrderID to codegen)
566-
addImplicitBindingAttrToBuffer(SemaRef, BufDecl,
567-
getNextImplicitBindingOrderID());
564+
// Use HLSLResourceBindingAttr as a way to transfer implicit binding
565+
// order_ID to codegen. If it does not exist, create an implicit one.
566+
uint32_t OrderID = getNextImplicitBindingOrderID();
567+
if (RBA)
568+
RBA->setImplicitBindingOrderID(OrderID);
569+
else
570+
addImplicitBindingAttrToBuffer(SemaRef, BufDecl, OrderID);
568571
}
569572

570573
SemaRef.PopDeclContext();

clang/test/CodeGenHLSL/cbuffer.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef uint32_t4 uint32_t8[2];
102102
typedef uint4 T1;
103103
typedef T1 T2[2]; // check a double typedef
104104

105-
cbuffer CBTypedefArray {
105+
cbuffer CBTypedefArray : register(space2) {
106106
uint32_t8 t1[2];
107107
T2 t2[2];
108108
}
@@ -287,7 +287,7 @@ cbuffer CB_C {
287287
// CHECK: define internal void @_init_buffer_CBTypedefArray.cb()
288288
// CHECK-NEXT: entry:
289289
// CHECK-NEXT: %CBTypedefArray.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CBTypedefArray, 128, 0, 64))
290-
// CHECK-SAME: @llvm.dx.resource.handlefromimplicitbinding.tdx.CBuffer_tdx.Layout_s___cblayout_CBTypedefArrays_128_0_64tt(i32 1, i32 0, i32 1, i32 0, i1 false)
290+
// CHECK-SAME: @llvm.dx.resource.handlefromimplicitbinding.tdx.CBuffer_tdx.Layout_s___cblayout_CBTypedefArrays_128_0_64tt(i32 1, i32 2, i32 1, i32 0, i1 false)
291291
// CHECK-NEXT: store target("dx.CBuffer", target("dx.Layout", %__cblayout_CBTypedefArray, 128, 0, 64)) %CBTypedefArray.cb_h, ptr @CBTypedefArray.cb, align 4
292292

293293
// CHECK: define internal void @_init_buffer_CBStructs.cb()

0 commit comments

Comments
 (0)