@@ -164,15 +164,29 @@ static void createResourceCtorArgs(CodeGenModule &CGM, CXXConstructorDecl *CD,
164
164
llvm::Value *ThisPtr, llvm::Value *Range,
165
165
llvm::Value *Index, StringRef Name,
166
166
HLSLResourceBindingAttr *RBA,
167
+ HLSLVkBindingAttr *VkBinding,
167
168
CallArgList &Args) {
169
+ assert ((VkBinding || RBA) && " at least one a binding attribute expected" );
170
+
171
+ std::optional<uint32_t > RegisterSlot;
172
+ uint32_t SpaceNo = 0 ;
173
+ if (VkBinding) {
174
+ RegisterSlot = VkBinding->getBinding ();
175
+ SpaceNo = VkBinding->getSet ();
176
+ } else if (RBA) {
177
+ if (RBA->hasRegisterSlot ())
178
+ RegisterSlot = RBA->getSlotNumber ();
179
+ SpaceNo = RBA->getSpaceNumber ();
180
+ }
181
+
168
182
ASTContext &AST = CD->getASTContext ();
169
183
Value *NameStr = buildNameForResource (Name, CGM);
170
- Value *Space = llvm::ConstantInt::get (CGM.IntTy , RBA-> getSpaceNumber () );
184
+ Value *Space = llvm::ConstantInt::get (CGM.IntTy , SpaceNo );
171
185
172
186
Args.add (RValue::get (ThisPtr), CD->getThisType ());
173
- if (RBA-> hasRegisterSlot ()) {
187
+ if (RegisterSlot. has_value ()) {
174
188
// explicit binding
175
- auto *RegSlot = llvm::ConstantInt::get (CGM.IntTy , RBA-> getSlotNumber ());
189
+ auto *RegSlot = llvm::ConstantInt::get (CGM.IntTy , RegisterSlot. value ());
176
190
Args.add (RValue::get (RegSlot), AST.UnsignedIntTy );
177
191
Args.add (RValue::get (Space), AST.UnsignedIntTy );
178
192
Args.add (RValue::get (Range), AST.IntTy );
@@ -696,13 +710,6 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
696
710
CGM.AddCXXGlobalInit (InitResFunc);
697
711
}
698
712
699
- static Value *buildNameForResource (llvm::StringRef BaseName,
700
- CodeGenModule &CGM) {
701
- std::string Str (BaseName);
702
- std::string GlobalName (Str + " .str" );
703
- return CGM.GetAddrOfConstantCString (Str, GlobalName.c_str ()).getPointer ();
704
- }
705
-
706
713
void CGHLSLRuntime::initializeBufferFromBinding (const HLSLBufferDecl *BufDecl,
707
714
llvm::GlobalVariable *GV,
708
715
HLSLVkBindingAttr *VkBinding) {
@@ -730,17 +737,13 @@ void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
730
737
auto *Index = llvm::ConstantInt::get (CGM.IntTy , 0 );
731
738
auto *RangeSize = llvm::ConstantInt::get (CGM.IntTy , 1 );
732
739
auto *Space = llvm::ConstantInt::get (CGM.IntTy , RBA->getSpaceNumber ());
733
- Value *Name = nullptr ;
740
+ Value *Name = buildNameForResource (BufDecl-> getName (), CGM) ;
734
741
735
742
llvm::Intrinsic::ID IntrinsicID =
736
743
RBA->hasRegisterSlot ()
737
744
? CGM.getHLSLRuntime ().getCreateHandleFromBindingIntrinsic ()
738
745
: CGM.getHLSLRuntime ().getCreateHandleFromImplicitBindingIntrinsic ();
739
746
740
- std::string Str (BufDecl->getName ());
741
- std::string GlobalName (Str + " .str" );
742
- Name = CGM.GetAddrOfConstantCString (Str, GlobalName.c_str ()).getPointer ();
743
-
744
747
// buffer with explicit binding
745
748
if (RBA->hasRegisterSlot ()) {
746
749
auto *RegSlot = llvm::ConstantInt::get (CGM.IntTy , RBA->getSlotNumber ());
@@ -854,15 +857,16 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
854
857
}
855
858
856
859
// find binding info for the resource array
857
- // (for implicit binding it should have been by SemaHLSL)
860
+ // (for implicit binding an HLSLResourceBindingAttr should have been added by SemaHLSL)
858
861
QualType ResourceTy = ArraySubsExpr->getType ();
862
+ HLSLVkBindingAttr *VkBinding = ArrayDecl->getAttr <HLSLVkBindingAttr>();
859
863
HLSLResourceBindingAttr *RBA = ArrayDecl->getAttr <HLSLResourceBindingAttr>();
860
- assert (RBA && " resource array is missing HLSLResourceBindingAttr attribute" );
864
+ assert ((VkBinding || RBA) && " resource array must have a binding attribute" );
861
865
862
866
// lookup the resource class constructor based on the resource type and
863
867
// binding
864
868
CXXConstructorDecl *CD = findResourceConstructorDecl (
865
- ArrayDecl->getASTContext (), ResourceTy, RBA->hasRegisterSlot ());
869
+ ArrayDecl->getASTContext (), ResourceTy, VkBinding || RBA->hasRegisterSlot ());
866
870
867
871
// create a temporary variable for the resource class instance (we need to
868
872
// return an LValue)
@@ -885,7 +889,7 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
885
889
// assemble the constructor parameters
886
890
CallArgList Args;
887
891
createResourceCtorArgs (CGM, CD, ThisPtr, Range, Index, ArrayDecl->getName (),
888
- RBA, Args);
892
+ RBA, VkBinding, Args);
889
893
890
894
// call the constructor
891
895
CGF.EmitCXXConstructorCall (CD, Ctor_Complete, false , false , ThisAddress, Args,
0 commit comments