diff --git a/IGC/AdaptorCommon/ImplicitArgs.cpp b/IGC/AdaptorCommon/ImplicitArgs.cpp index 9b2f1b71fea1..2b983a42394a 100644 --- a/IGC/AdaptorCommon/ImplicitArgs.cpp +++ b/IGC/AdaptorCommon/ImplicitArgs.cpp @@ -394,6 +394,20 @@ bool ImplicitArgs::isImplicitArgExist( return isImplicitArgExist(pMdUtils->getFunctionsInfoItem(&F), argType); } +bool ImplicitArgs::isImplicitArgExistForNumberedArg(ImplicitArg::ArgType argType, int argNum) const { + IGC_ASSERT_MESSAGE((argNum >= 0), "objectNum cannot be less than 0"); + + for (int i = 0, e = m_funcInfoMD->size_ImplicitArgInfoList(); i < e; ++i) + { + ArgInfoMetaDataHandle argInfo = m_funcInfoMD->getImplicitArgInfoListItem(i); + if (argInfo->getArgId() == argType && argInfo->getExplicitArgNum() == argNum) + { + return true; + } + } + return false; +} + unsigned int ImplicitArgs::getImageArgIndex(ImplicitArg::ArgType argType, const Argument* image) const { IGC_ASSERT_MESSAGE(isImplicitImage(argType), "Non image/sampler implicit arg!"); return getNumberedArgIndex(argType, image->getArgNo()); diff --git a/IGC/AdaptorCommon/ImplicitArgs.hpp b/IGC/AdaptorCommon/ImplicitArgs.hpp index 650cf509b3ce..6d797ccb35e6 100644 --- a/IGC/AdaptorCommon/ImplicitArgs.hpp +++ b/IGC/AdaptorCommon/ImplicitArgs.hpp @@ -248,6 +248,13 @@ namespace IGC /// @return The implicit argument's index for a given argument type unsigned int getNumberedArgIndex(ImplicitArg::ArgType argType, int argNum) const; + /// @brief Returns if an implicit arg exists for the given explicit argument + /// based on the argument type and argument number + /// @param argType The implicit argument type + /// (height/width/depth for images, normalized/address/snapwa for samplers) + /// @param argNum The explicit argument number of the type + bool isImplicitArgExistForNumberedArg(ImplicitArg::ArgType argType, int argNum) const; + /// @brief Returns the argument type of the argument at the given index /// @param i The implicit argument index /// @return The argument type of the argument at the given index diff --git a/IGC/Compiler/PromoteStatelessToBindless.cpp b/IGC/Compiler/PromoteStatelessToBindless.cpp index 43294d625c5c..eb8fc6a81c88 100644 --- a/IGC/Compiler/PromoteStatelessToBindless.cpp +++ b/IGC/Compiler/PromoteStatelessToBindless.cpp @@ -195,9 +195,17 @@ void PromoteStatelessToBindless::PromoteStatelessToBindlessBuffers(Function& F) // Do this only for legacy mode, since the resource type of the original // kernel arg needs to be bindless for it to be reinterpreted as a bindless offset. // In advanced mode, always keep the original kernel arg as stateless, and use the - // IMPLICIT_BUFFER_OFFSET arg for bindless access. + // BINDLESS_OFFSET arg for bindless access. argInfo->type = ResourceTypeEnum::BindlessUAVResourceType; } + else + { + // In advanced mode, there must be a corresponding implicit arg BINDLESS_OFFSET for every + // explicit buffer arg for it to be promoted to bindless. Check if this implcit arg exists, + // and skip promotion if we can't find it. + if (!implicitArgs.isImplicitArgExistForNumberedArg(ImplicitArg::BINDLESS_OFFSET, srcPtr->getArgNo())) + continue; + } if (supportDynamicBTIsAllocation) {