================ @@ -459,7 +467,412 @@ void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) { D->addAttr(HLSLResourceClassAttr::Create(getASTContext(), RC, ArgLoc)); } -void SemaHLSL::handleResourceBindingAttr(Decl *D, const ParsedAttr &AL) { +struct RegisterBindingFlags { + bool Resource = false; + bool UDT = false; + bool Other = false; + bool Basic = false; + + bool SRV = false; + bool UAV = false; + bool CBV = false; + bool Sampler = false; + + bool ContainsNumeric = false; + bool DefaultGlobals = false; +}; + +static bool isDeclaredWithinCOrTBuffer(const Decl *TheDecl) { + if (!TheDecl) + return false; + + // Traverse up the parent contexts + const DeclContext *context = TheDecl->getDeclContext(); + if (isa<HLSLBufferDecl>(context)) { + return true; + } + + return false; +} + +// get the record decl from a var decl that we expect +// represents a resource +static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) { + const Type *Ty = VD->getType()->getPointeeOrArrayElementType(); + assert(Ty && "Resource must have an element type."); + + if (const auto *TheBuiltinTy = dyn_cast<BuiltinType>(Ty)) + return nullptr; + + CXXRecordDecl *TheRecordDecl = Ty->getAsCXXRecordDecl(); + assert(TheRecordDecl && "Resource should have a resource type declaration."); + return TheRecordDecl; +} + +static void setResourceClassFlagsFromDeclResourceClass( + RegisterBindingFlags &Flags, llvm::hlsl::ResourceClass DeclResourceClass) { + switch (DeclResourceClass) { + case llvm::hlsl::ResourceClass::SRV: + Flags.SRV = true; + break; + case llvm::hlsl::ResourceClass::UAV: + Flags.UAV = true; + break; + case llvm::hlsl::ResourceClass::CBuffer: + Flags.CBV = true; + break; + case llvm::hlsl::ResourceClass::Sampler: + Flags.Sampler = true; + break; + } +} + +template <typename T> +static const T * +getSpecifiedHLSLAttrFromVarDeclOrRecordDecl(VarDecl *VD, + RecordDecl *TheRecordDecl) { ---------------- hekota wrote:
> 3. It should be ok that the first attribute is all that's detected. We don't > expect users to use user-defined resources that have made use of the > spellable attributes, and have defined more than one resource class for said > attribute. All HLSL resources should have exactly one resource class > attribute, so there will never be a valid case where there are 2 attributes > and we should've picked the second one. I guess that's ok for now. I'll approve to get this PR in to unblock the milestone, but we might want to go revisit this later. https://github.com/llvm/llvm-project/pull/97103 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits