================ @@ -3808,11 +3796,101 @@ void SemaHLSL::createResourceRecordCtorArgs( } bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) { - SmallVector<Expr *> Args; - createResourceRecordCtorArgs(VD->getType().getTypePtr(), VD->getName(), - VD->getAttr<HLSLResourceBindingAttr>(), - VD->getAttr<HLSLVkBindingAttr>(), 0, Args); - return initVarDeclWithCtor(SemaRef, VD, Args); + assert(VD->getType()->isHLSLResourceRecord() && + "expected resource record type"); + + ASTContext &AST = SemaRef.getASTContext(); + uint64_t UIntTySize = AST.getTypeSize(AST.UnsignedIntTy); + uint64_t IntTySize = AST.getTypeSize(AST.IntTy); + + // Gather resource binding information from attributes. + HLSLResourceBindingAttr *RBA = VD->getAttr<HLSLResourceBindingAttr>(); + HLSLVkBindingAttr *VkBinding = VD->getAttr<HLSLVkBindingAttr>(); + std::optional<uint32_t> RegisterSlot; + uint32_t SpaceNo = 0; + if (VkBinding) { + RegisterSlot = VkBinding->getBinding(); + SpaceNo = VkBinding->getSet(); + } else if (RBA) { + if (RBA->hasRegisterSlot()) + RegisterSlot = RBA->getSlotNumber(); + SpaceNo = RBA->getSpaceNumber(); + } + + // Find correct initialization method and create its arguments. + QualType ResourceTy = VD->getType(); + CXXRecordDecl *ResourceDecl = ResourceTy->getAsCXXRecordDecl(); + CXXMethodDecl *CreateMethod = nullptr; + llvm::SmallVector<Expr *> Args; + + if (RegisterSlot.has_value()) { + // The resource has explicit binding. + CreateMethod = lookupMethod(ResourceDecl, "__createFromBinding", SC_Static); + IntegerLiteral *RegSlot = IntegerLiteral::Create( + AST, llvm::APInt(UIntTySize, RegisterSlot.value()), AST.UnsignedIntTy, + SourceLocation()); + Args.push_back(RegSlot); + } else { + // The resource has implicit binding. + CreateMethod = + lookupMethod(ResourceDecl, "__createFromImplicitBinding", SC_Static); + uint32_t OrderID = (RBA && RBA->hasImplicitBindingOrderID()) + ? RBA->getImplicitBindingOrderID() + : getNextImplicitBindingOrderID(); + IntegerLiteral *OrderId = + IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, OrderID), + AST.UnsignedIntTy, SourceLocation()); + Args.push_back(OrderId); + } + + if (!CreateMethod) ---------------- llvm-beanz wrote:
Is it possible for this to fail? I suspect if this fails and we don't generate a diagnostic somewhere this would result in a really weird user experience. Likely a failure without producing an error. https://github.com/llvm/llvm-project/pull/156544 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits