@@ -273,10 +273,14 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
273273 emitBufferGlobalsAndMetadata (BufDecl, BufGV);
274274
275275 // Initialize cbuffer from binding (implicit or explicit)
276- HLSLResourceBindingAttr *RBA = BufDecl->getAttr <HLSLResourceBindingAttr>();
277- assert (RBA &&
278- " cbuffer/tbuffer should always have resource binding attribute" );
279- initializeBufferFromBinding (BufDecl, BufGV, RBA);
276+ if (HLSLVkBindingAttr *VkBinding = BufDecl->getAttr <HLSLVkBindingAttr>()) {
277+ initializeBufferFromBinding (BufDecl, BufGV, VkBinding);
278+ } else {
279+ HLSLResourceBindingAttr *RBA = BufDecl->getAttr <HLSLResourceBindingAttr>();
280+ assert (RBA &&
281+ " cbuffer/tbuffer should always have resource binding attribute" );
282+ initializeBufferFromBinding (BufDecl, BufGV, RBA);
283+ }
280284}
281285
282286llvm::TargetExtType *
@@ -593,6 +597,31 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
593597 CGM.AddCXXGlobalInit (InitResFunc);
594598}
595599
600+ static Value *buildNameForResource (llvm::StringRef BaseName,
601+ CodeGenModule &CGM) {
602+ std::string Str (BaseName);
603+ std::string GlobalName (Str + " .str" );
604+ return CGM.GetAddrOfConstantCString (Str, GlobalName.c_str ()).getPointer ();
605+ }
606+
607+ void CGHLSLRuntime::initializeBufferFromBinding (const HLSLBufferDecl *BufDecl,
608+ llvm::GlobalVariable *GV,
609+ HLSLVkBindingAttr *VkBinding) {
610+ assert (VkBinding && " expect a nonnull binding attribute" );
611+ llvm::Type *Int1Ty = llvm::Type::getInt1Ty (CGM.getLLVMContext ());
612+ auto *NonUniform = llvm::ConstantInt::get (Int1Ty, false );
613+ auto *Index = llvm::ConstantInt::get (CGM.IntTy , 0 );
614+ auto *RangeSize = llvm::ConstantInt::get (CGM.IntTy , 1 );
615+ auto *Set = llvm::ConstantInt::get (CGM.IntTy , VkBinding->getSet ());
616+ auto *Binding = llvm::ConstantInt::get (CGM.IntTy , VkBinding->getBinding ());
617+ Value *Name = buildNameForResource (BufDecl->getName (), CGM);
618+ llvm::Intrinsic::ID IntrinsicID =
619+ CGM.getHLSLRuntime ().getCreateHandleFromBindingIntrinsic ();
620+
621+ SmallVector<Value *> Args{Set, Binding, RangeSize, Index, NonUniform, Name};
622+ initializeBuffer (CGM, GV, IntrinsicID, Args);
623+ }
624+
596625void CGHLSLRuntime::initializeBufferFromBinding (const HLSLBufferDecl *BufDecl,
597626 llvm::GlobalVariable *GV,
598627 HLSLResourceBindingAttr *RBA) {
0 commit comments