@@ -113,15 +113,16 @@ static int getTotalArraySize(const clang::Type *Ty) {
113
113
if (Ty->isIncompleteArrayType ())
114
114
return -1 ;
115
115
int Size = 1 ;
116
- while (const auto *CAT = dyn_cast<ConstantArrayType>(Ty)) {
116
+ while (const auto *CAT =
117
+ dyn_cast<ConstantArrayType>(Ty->getUnqualifiedDesugaredType ())) {
117
118
Size *= CAT->getSExtSize ();
118
119
Ty = CAT->getArrayElementTypeNoTypeQual ();
119
120
}
120
121
return Size;
121
122
}
122
123
123
124
// Find constructor decl for a specific resource record type and binding
124
- // (implicit vs. explicit). The constructor has 6 parameters.
125
+ // (implicit vs. explicit). The constructor has 5 parameters.
125
126
// For explicit binding the signature is:
126
127
// void(unsigned, unsigned, int, unsigned, const char *).
127
128
// For implicit binding the signature is:
@@ -171,7 +172,7 @@ static void createResourceCtorArgs(CodeGenModule &CGM, CXXConstructorDecl *CD,
171
172
if (VkBinding) {
172
173
RegisterSlot = VkBinding->getBinding ();
173
174
SpaceNo = VkBinding->getSet ();
174
- } else if (RBA) {
175
+ } else {
175
176
if (RBA->hasRegisterSlot ())
176
177
RegisterSlot = RBA->getSlotNumber ();
177
178
SpaceNo = RBA->getSpaceNumber ();
@@ -815,7 +816,7 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
815
816
ArraySubsExpr->getType ()->isHLSLResourceRecordArray () &&
816
817
" expected resource array subscript expression" );
817
818
818
- // let clang codegen handle local resource array subscrips
819
+ // let clang codegen handle local resource array subscripts
819
820
const VarDecl *ArrayDecl = dyn_cast<VarDecl>(getArrayDecl (ArraySubsExpr));
820
821
if (!ArrayDecl || !ArrayDecl->hasGlobalStorage ())
821
822
return std::nullopt;
@@ -824,12 +825,10 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
824
825
assert (!ArraySubsExpr->getType ()->isArrayType () &&
825
826
" indexing of array subsets it not supported yet" );
826
827
827
- // get total array size (= range size)
828
+ // get the resource array type
828
829
const Type *ResArrayTy = ArrayDecl->getType ().getTypePtr ();
829
830
assert (ResArrayTy->isHLSLResourceRecordArray () &&
830
831
" expected array of resource classes" );
831
- llvm::Value *Range =
832
- llvm::ConstantInt::get (CGM.IntTy , getTotalArraySize (ResArrayTy));
833
832
834
833
// Iterate through all nested array subscript expressions to calculate
835
834
// the index in the flattened resource array (if this is a multi-
@@ -886,6 +885,10 @@ std::optional<LValue> CGHLSLRuntime::emitResourceArraySubscriptExpr(
886
885
llvm::Value *ThisPtr = CGF.getAsNaturalPointerTo (
887
886
ThisAddress, CD->getThisType ()->getPointeeType ());
888
887
888
+ // get total array size (= range size)
889
+ llvm::Value *Range =
890
+ llvm::ConstantInt::get (CGM.IntTy , getTotalArraySize (ResArrayTy));
891
+
889
892
// assemble the constructor parameters
890
893
CallArgList Args;
891
894
createResourceCtorArgs (CGM, CD, ThisPtr, Range, Index, ArrayDecl->getName (),
0 commit comments