Skip to content

Commit 0e8aba1

Browse files
wenju-heigcbot
authored andcommitted
Add new implicit arg for OpenCL inline sampler in bindless mode
To support OpenCL inline sampler in bindless mode, a new implicit arg `inlineSampler` is added for each unique inline sampler. The arg passes bindless offset of its sampler state into the kernel. Therefore, a new zeinfo payload argument `inline_sampler` is added for the implicit arg. The payload argument has an entry `sampler_index` that is used for looking up inline sampler entry in `inline_samplers` section of zeinfo. For example, payload_arguments: - arg_type: inline_sampler offset: 60 size: 4 addrmode: bindless addrspace: sampler sampler_index: 1 inline_samplers: - sampler_index: 1 addrmode: none filtermode: nearest
1 parent ef12a59 commit 0e8aba1

File tree

31 files changed

+470
-120
lines changed

31 files changed

+470
-120
lines changed

IGC/AdaptorCommon/AddImplicitArgs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace IGC
5353
/// @brief Provides name of pass
5454
virtual llvm::StringRef getPassName() const override
5555
{
56-
return "AddImplictArgs";
56+
return "AddImplicitArgs";
5757
}
5858

5959
virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override

IGC/AdaptorCommon/ImplicitArgs.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static const std::vector<ImplicitArg> IMPLICIT_ARGS = {
6262
ImplicitArg(ImplicitArg::SAMPLER_ADDRESS, "smpAddress", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
6363
ImplicitArg(ImplicitArg::SAMPLER_NORMALIZED, "smpNormalized", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
6464
ImplicitArg(ImplicitArg::SAMPLER_SNAP_WA, "smpSnapWA", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
65+
ImplicitArg(ImplicitArg::INLINE_SAMPLER, "inlineSampler", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
6566
ImplicitArg(ImplicitArg::FLAT_IMAGE_BASEOFFSET, "flatImageBaseoffset", ImplicitArg::LONG, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_QWORD, true),
6667
ImplicitArg(ImplicitArg::FLAT_IMAGE_HEIGHT, "flatImageHeight", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
6768
ImplicitArg(ImplicitArg::FLAT_IMAGE_WIDTH, "flatImageWidth", ImplicitArg::INT, WIAnalysis::UNIFORM_GLOBAL, 1, ImplicitArg::ALIGN_DWORD, true),
@@ -648,6 +649,27 @@ bool ImplicitArgs::isImplicitStruct(ImplicitArg::ArgType argType)
648649
return (argType >= ImplicitArg::STRUCT_START) && (argType <= ImplicitArg::STRUCT_END);
649650
}
650651

652+
bool ImplicitArgs::isImplicitArg(Argument *arg) const
653+
{
654+
unsigned argSize = arg->getParent()->arg_size();
655+
unsigned numImplicitArgs = size();
656+
IGC_ASSERT_MESSAGE(argSize >= numImplicitArgs, "Function arg size does not match meta data args.");
657+
unsigned argNo = arg->getArgNo();
658+
return argNo >= (argSize - numImplicitArgs);
659+
}
660+
661+
int ImplicitArgs::getExplicitArgNumForArg(Argument *implicitArg) const
662+
{
663+
unsigned argSize = implicitArg->getParent()->arg_size();
664+
unsigned numImplicitArgs = size();
665+
IGC_ASSERT_MESSAGE(argSize >= numImplicitArgs, "Function arg size does not match meta data args.");
666+
unsigned argNo = implicitArg->getArgNo();
667+
IGC_ASSERT_MESSAGE(argNo >= (argSize - numImplicitArgs), "The arg should be implicit arg");
668+
unsigned implicitArgIndex = argNo - (argSize - numImplicitArgs);
669+
ArgInfoMetaDataHandle argInfo = m_funcInfoMD->getImplicitArgInfoListItem(implicitArgIndex);
670+
return argInfo->getExplicitArgNum();
671+
}
672+
651673
ImplicitArg::ArgType ImplicitArgs::getArgType(unsigned int index) const {
652674
IGC_ASSERT_MESSAGE((index < size()), "Index out of range");
653675
ArgInfoMetaDataHandle argInfo = m_funcInfoMD->getImplicitArgInfoListItem(index);

IGC/AdaptorCommon/ImplicitArgs.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace IGC
8181
SAMPLER_ADDRESS,
8282
SAMPLER_NORMALIZED,
8383
SAMPLER_SNAP_WA,
84+
INLINE_SAMPLER,
8485
FLAT_IMAGE_BASEOFFSET,
8586
FLAT_IMAGE_HEIGHT,
8687
FLAT_IMAGE_WIDTH,
@@ -362,6 +363,14 @@ namespace IGC
362363
/// @param argType The argument type to check.
363364
static bool isImplicitStruct(ImplicitArg::ArgType argType);
364365

366+
/// @brief Returns true if the given argument is an implicit argument.
367+
/// @param arg The argument to check.
368+
bool isImplicitArg(llvm::Argument *arg) const;
369+
370+
/// @brief Returns explicit argument number associated with the given implicit argument.
371+
/// @param implicitArg The associated implicit argument.
372+
int getExplicitArgNumForArg(llvm::Argument *implicitArg) const;
373+
365374
llvm::Value* getImplicitArgValue(llvm::Function& F, ImplicitArg::ArgType argType, const IGCMD::MetaDataUtils* pMdUtils);
366375

367376
private:

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,19 @@ namespace IGC
13071307
break;
13081308
}
13091309

1310+
case KernelArg::ArgType::IMPLICIT_INLINE_SAMPLER: {
1311+
uint32_t arg_idx = kernelArg->getAssociatedArgNo();
1312+
ResourceAllocMD& resAllocMD = GetContext()->getModuleMetaData()->FuncMD[entry].resAllocMD;
1313+
auto it = llvm::find_if(resAllocMD.inlineSamplersMD, [&](auto &inlineSamplerMD) {
1314+
return inlineSamplerMD.m_Value == arg_idx;
1315+
});
1316+
IGC_ASSERT_MESSAGE(it != resAllocMD.inlineSamplersMD.end(), "Inline sampler isn't found in metadata.");
1317+
zebin::ZEInfoBuilder::addPayloadArgumentImplicitInlineSampler(
1318+
m_kernelInfo.m_zePayloadArgs, zebin::PreDefinedAttrGetter::ArgType::inline_sampler, payloadPosition,
1319+
kernelArg->getAllocateSize(), it->index);
1320+
break;
1321+
}
1322+
13101323
case KernelArg::ArgType::IMPLICIT_BUFFER_OFFSET: {
13111324
zebin::zeInfoPayloadArgument& arg = zebin::ZEInfoBuilder::addPayloadArgumentImplicit(m_kernelInfo.m_zePayloadArgs,
13121325
zebin::PreDefinedAttrGetter::ArgType::buffer_offset,

IGC/Compiler/Optimizer/OCLBIUtils.cpp

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ SPDX-License-Identifier: MIT
1515
#include "llvmWrapper/IR/IRBuilder.h"
1616
#include "llvmWrapper/IR/Instructions.h"
1717
#include "common/LLVMWarningsPop.hpp"
18+
#include "AdaptorCommon/ImplicitArgs.hpp"
1819
#include "LLVM3DBuilder/BuiltinsFrontend.hpp"
1920
#include "Probe/Assertion.h"
2021
#include "IGC/common/StringMacros.hpp"
22+
#include <llvm/Support/Casting.h>
2123

2224
using namespace llvm;
2325
using namespace IGC;
@@ -249,7 +251,7 @@ Argument* CImagesBI::CImagesUtils::findImageFromBufferPtr(const MetaDataUtils& M
249251
return nullptr;
250252
}
251253

252-
static bool isBindlessImageLoad(Value *v)
254+
static bool isSYCLBindlessImageLoad(Value *v)
253255
{
254256
auto *load = dyn_cast<LoadInst>(v);
255257
if (!load)
@@ -270,7 +272,7 @@ ConstantInt* CImagesBI::CImagesUtils::getImageIndex(
270272
{
271273
ConstantInt* imageIndex = nullptr;
272274

273-
imageParam = ValueTracker::track(pCallInst, paramIndex, nullptr, nullptr, isBindlessImageLoad);
275+
imageParam = ValueTracker::track(pCallInst, paramIndex, nullptr, nullptr, isSYCLBindlessImageLoad);
274276
IGC_ASSERT(imageParam);
275277
IGC_ASSERT(isa<Argument>(imageParam) || isa<LoadInst>(imageParam));
276278
int i = (*pParamMap)[imageParam].index;
@@ -280,7 +282,7 @@ ConstantInt* CImagesBI::CImagesUtils::getImageIndex(
280282

281283
BufferType CImagesBI::CImagesUtils::getImageType(ParamMap* pParamMap, CallInst* pCallInst, unsigned int paramIndex)
282284
{
283-
Value *imageParam = ValueTracker::track(pCallInst, paramIndex, nullptr, nullptr, isBindlessImageLoad);
285+
Value *imageParam = ValueTracker::track(pCallInst, paramIndex, nullptr, nullptr, isSYCLBindlessImageLoad);
284286
IGC_ASSERT(imageParam);
285287
IGC_ASSERT(isa<Argument>(imageParam) || isa<LoadInst>(imageParam));
286288
return isa<LoadInst>(imageParam) ? BufferType::BINDLESS : (*pParamMap)[imageParam].type;
@@ -439,62 +441,104 @@ class COCL_sample : public CImagesBI
439441
}
440442
return false;
441443
};
442-
Value* samplerParam = ValueTracker::track(m_pCallInst, 1, m_pMdUtils, m_modMD, isBindlessSampler);
443-
if (!samplerParam) {
444+
Value* samplerValue = ValueTracker::track(m_pCallInst, 1, m_pMdUtils, m_modMD, isBindlessSampler);
445+
if (!samplerValue) {
444446
emitError("There are instructions that use a sampler, but no sampler found in the kernel!", m_pCallInst);
445447
return nullptr;
446448
}
447449

448450
auto modMD = m_pCodeGenContext->getModuleMetaData();
449451

450-
// If bindless image is preferred, map the bindless pointer
452+
auto addToInlineSamplersMD = [&](int samplerConstantVal)
453+
{
454+
// Is this sampler already allocated?
455+
auto iter = m_pInlineMap->find(samplerConstantVal);
456+
if (iter != m_pInlineMap->end())
457+
{
458+
return ConstantInt::get(m_pIntType, iter->second);
459+
}
460+
461+
// No, allocate it.
462+
int currSamplerIdx = (*m_pNextSampler)++;
463+
(*m_pInlineMap)[samplerConstantVal] = currSamplerIdx;
464+
samplerIndex = ConstantInt::get(m_pIntType, currSamplerIdx);
465+
466+
// Push this information into the metadata, for the state processor's benefit
467+
FunctionMetaData& funcMD = m_modMD->FuncMD[m_pFunc];
468+
ResourceAllocMD& resAllocMD = funcMD.resAllocMD;
469+
InlineSamplersMD inlineSamplerMD;
470+
CreateInlineSamplerAnnotations(inlineSamplerMD, samplerConstantVal);
471+
inlineSamplerMD.index = currSamplerIdx;
472+
resAllocMD.inlineSamplersMD.push_back(inlineSamplerMD);
473+
m_pMdUtils->save(*m_pCtx);
474+
return samplerIndex;
475+
};
476+
451477
if (modMD->UseBindlessImage)
452478
{
453-
// If sampler is argument, look up index in the parameter map.
454-
int i = isa<Argument>(samplerParam) ? (*m_pParamMap)[samplerParam].index : 0;
455-
samplerIndex = ConstantInt::get(m_pIntType, i);
456-
unsigned int addressSpace = IGC::EncodeAS4GFXResource(*samplerIndex, BufferType::BINDLESS_SAMPLER);
457-
Type* ptrTy = llvm::PointerType::get(m_pFloatType, addressSpace);
458-
Value* bindlessSampler = isa<IntegerType>(samplerParam->getType()) ?
459-
BitCastInst::CreateBitOrPointerCast(samplerParam, ptrTy, "bindless_sampler", m_pCallInst) :
460-
BitCastInst::CreatePointerCast(samplerParam, ptrTy, "bindless_sampler", m_pCallInst);
479+
// In bindless mode, samplerValue is BinaryOperator::Or computed in ResolveSampledImageBuiltins pass.
480+
// Continue to track back the sampler's origin value, which could be one of following values:
481+
// * a constant, e.g. inline sampler.
482+
// * kernel argument, e.g. sampler that is kernel argument.
483+
// * load inst, e.g. sampler in SYCL bindless sampled image.
484+
Value *samplerValueOrigin = ValueTracker::track(samplerValue, m_pFunc, m_pMdUtils, m_modMD, isSYCLBindlessImageLoad);
485+
if (!samplerValueOrigin) {
486+
emitError("There are instructions that use a sampler, but no sampler found in the kernel!", m_pCallInst);
487+
return nullptr;
488+
}
489+
// Map the bindless pointer.
490+
Value *bindlessSampler = nullptr;
491+
if (auto *samplerConstant = dyn_cast<ConstantInt>(samplerValueOrigin))
492+
{
493+
// Sampler is constant, e.g. inline sampler.
494+
int samplerConstantVal = int_cast<int>(samplerConstant->getZExtValue());
495+
samplerIndex = addToInlineSamplersMD(samplerConstantVal);
496+
497+
// Bindless inline sampler is passed via implicit kernel argument.
498+
ImplicitArgs implicitArgs(*m_pFunc, m_pMdUtils);
499+
500+
Argument *arg = implicitArgs.getNumberedImplicitArg(*m_pFunc, ImplicitArg::INLINE_SAMPLER, samplerConstantVal);
501+
if (!arg) {
502+
emitError("Implicit arg isn't found for inline sampler!", m_pCallInst);
503+
return nullptr;
504+
}
505+
auto *binOp = cast<BinaryOperator>(samplerValue);
506+
auto *argExt = new ZExtInst(arg, Type::getInt64Ty(*m_pCtx), "", binOp);
507+
binOp->setOperand(0, argExt);
508+
509+
unsigned addressSpace = IGC::EncodeAS4GFXResource(*samplerIndex, BufferType::BINDLESS_SAMPLER);
510+
Type *ptrTy = PointerType::get(m_pFloatType, addressSpace);
511+
bindlessSampler = BitCastInst::CreateBitOrPointerCast(m_pCallInst->getOperand(1), ptrTy, "bindless_sampler", m_pCallInst);
512+
}
513+
else
514+
{
515+
// Sampler is either sampler that is kernel argument, or sampler in SYCL bindless sampled image.
516+
// If sampler is argument, look up index in the parameter map.
517+
int i = isa<Argument>(samplerValueOrigin) ? (*m_pParamMap)[samplerValueOrigin].index : 0;
518+
samplerIndex = ConstantInt::get(m_pIntType, i);
519+
unsigned int addressSpace = IGC::EncodeAS4GFXResource(*samplerIndex, BufferType::BINDLESS_SAMPLER);
520+
Type* ptrTy = llvm::PointerType::get(m_pFloatType, addressSpace);
521+
bindlessSampler = isa<IntegerType>(samplerValue->getType()) ?
522+
BitCastInst::CreateBitOrPointerCast(samplerValue, ptrTy, "bindless_sampler", m_pCallInst) :
523+
BitCastInst::CreatePointerCast(samplerValue, ptrTy, "bindless_sampler", m_pCallInst);
524+
}
461525
return bindlessSampler;
462526
}
463527

464528
// Argument samplers are looked up in the parameter map
465-
if (isa<Argument>(samplerParam))
529+
if (isa<Argument>(samplerValue))
466530
{
467-
int i = (*m_pParamMap)[samplerParam].index;
531+
int i = (*m_pParamMap)[samplerValue].index;
468532
samplerIndex = ConstantInt::get(m_pIntType, i);
469533
return samplerIndex;
470534
}
471535

472536
// The sampler is not an argument, make sure it's a constant
473-
IGC_ASSERT_MESSAGE(isa<ConstantInt>(samplerParam), "Sampler must be a global variable or a constant");
474-
ConstantInt* constSampler = cast<ConstantInt>(samplerParam);
475-
int samplerValue = int_cast<int>(constSampler->getZExtValue());
476-
477-
// Is this sampler already allocated?
478-
auto iter = m_pInlineMap->find(samplerValue);
479-
if (iter != m_pInlineMap->end())
480-
{
481-
return ConstantInt::get(m_pIntType, iter->second);
482-
}
537+
IGC_ASSERT_MESSAGE(isa<ConstantInt>(samplerValue), "Sampler must be a global variable or a constant");
538+
auto *samplerConstant = cast<ConstantInt>(samplerValue);
539+
int samplerConstantVal = int_cast<int>(samplerConstant->getZExtValue());
483540

484-
// No, allocate it.
485-
int currSamplerIdx = (*m_pNextSampler)++;
486-
(*m_pInlineMap)[samplerValue] = currSamplerIdx;
487-
samplerIndex = ConstantInt::get(m_pIntType, currSamplerIdx);
488-
489-
// Push this information into the metadata, for the state processor's benefit
490-
FunctionMetaData& funcMD = m_modMD->FuncMD[m_pFunc];
491-
ResourceAllocMD& resAllocMD = funcMD.resAllocMD;
492-
InlineSamplersMD inlineSamplerMD;
493-
CreateInlineSamplerAnnotations(inlineSamplerMD, samplerValue);
494-
inlineSamplerMD.index = currSamplerIdx;
495-
resAllocMD.inlineSamplersMD.push_back(inlineSamplerMD);
496-
m_pMdUtils->save(*m_pCtx);
497-
return samplerIndex;
541+
return addToInlineSamplersMD(samplerConstantVal);
498542
}
499543

500544
void CreateInlineSamplerAnnotations(InlineSamplersMD& inlineSamplerMD, int samplerValue)

IGC/Compiler/Optimizer/OpenCLPasses/ImageFuncs/ImageFuncResolution.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ Value* ImageFuncResolution::getSamplerProperty(CallInst& CI)
212212
ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData();
213213
if (Value* sampler = ValueTracker::track(&CI, 0, pMdUtils, modMD))
214214
{
215-
if (isa<Argument>(sampler))
215+
auto *arg = dyn_cast<Argument>(sampler);
216+
bool isImplicitInlineSamplerArg = arg ? m_implicitArgs.isImplicitArg(arg) : false;
217+
if (arg && !isImplicitInlineSamplerArg)
216218
{
217219
if (m_implicitArgs.isImplicitArgExist(ArgTy))
218220
{
@@ -224,13 +226,22 @@ Value* ImageFuncResolution::getSamplerProperty(CallInst& CI)
224226
{
225227
llvm::Function* pFunc = CI.getFunction();
226228

227-
IGC_ASSERT_MESSAGE(isa<ConstantInt>(sampler), "Sampler must be a constant integer");
228229
uint64_t samplerVal = 0;
229230
if (modMD->FuncMD.find(pFunc) != modMD->FuncMD.end())
230231
{
231232
FunctionMetaData funcMD = modMD->FuncMD[pFunc];
232233
ResourceAllocMD resAllocMD = funcMD.resAllocMD;
233-
uint samplerValue = int_cast<unsigned int>(cast<ConstantInt>(sampler)->getZExtValue());
234+
unsigned samplerValue;
235+
if (isImplicitInlineSamplerArg)
236+
{
237+
// Inline sampler value is stored as explicit argument number in ImageFuncsAnalysis pass.
238+
samplerValue = m_implicitArgs.getExplicitArgNumForArg(arg);
239+
}
240+
else
241+
{
242+
IGC_ASSERT_MESSAGE(isa<ConstantInt>(sampler), "Sampler must be a constant integer");
243+
samplerValue = int_cast<unsigned int>(cast<ConstantInt>(sampler)->getZExtValue());
244+
}
234245
for (auto i = resAllocMD.inlineSamplersMD.begin(), e = resAllocMD.inlineSamplersMD.end(); i != e; i++)
235246
{
236247
IGC::InlineSamplersMD inlineSamplerMD = *i;

IGC/Compiler/Optimizer/OpenCLPasses/ImageFuncs/ImageFuncsAnalysis.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ bool ImageFuncsAnalysis::runOnModule(Module& M) {
5656
m_pMDUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
5757
CodeGenContext* ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
5858

59-
m_addImplicitImageArgs = !ctx->getModuleMetaData()->compOpt.UseBindlessMode ||
60-
ctx->getModuleMetaData()->compOpt.UseLegacyBindlessMode;
59+
m_useAdvancedBindlessMode = ctx->getModuleMetaData()->compOpt.UseBindlessMode &&
60+
!ctx->getModuleMetaData()->compOpt.UseLegacyBindlessMode;
6161

6262
// Run on all functions defined in this module
6363
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
@@ -81,7 +81,7 @@ bool ImageFuncsAnalysis::runOnFunction(Function& F) {
8181
// Visit the function
8282
visit(F);
8383

84-
ImplicitArgs::addImageArgs(F, m_argMap, getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils());
84+
ImplicitArgs::addImageArgs(F, m_argMap, m_pMDUtils);
8585

8686
m_argMap.clear();
8787

@@ -100,15 +100,15 @@ void ImageFuncsAnalysis::visitCallInst(CallInst& CI)
100100
// Check for OpenCL image dimension function calls
101101
std::set<int>* imageFunc = nullptr;
102102

103-
if (funcName == GET_IMAGE_HEIGHT && m_addImplicitImageArgs)
103+
if (funcName == GET_IMAGE_HEIGHT && !m_useAdvancedBindlessMode)
104104
{
105105
imageFunc = &m_argMap[ImplicitArg::IMAGE_HEIGHT];
106106
}
107-
else if (funcName == GET_IMAGE_WIDTH && m_addImplicitImageArgs)
107+
else if (funcName == GET_IMAGE_WIDTH && !m_useAdvancedBindlessMode)
108108
{
109109
imageFunc = &m_argMap[ImplicitArg::IMAGE_WIDTH];
110110
}
111-
else if (funcName == GET_IMAGE_DEPTH && m_addImplicitImageArgs)
111+
else if (funcName == GET_IMAGE_DEPTH && !m_useAdvancedBindlessMode)
112112
{
113113
imageFunc = &m_argMap[ImplicitArg::IMAGE_DEPTH];
114114
}
@@ -128,7 +128,7 @@ void ImageFuncsAnalysis::visitCallInst(CallInst& CI)
128128
{
129129
imageFunc = &m_argMap[ImplicitArg::IMAGE_SRGB_CHANNEL_ORDER];
130130
}
131-
else if ((funcName == GET_IMAGE1D_ARRAY_SIZE || funcName == GET_IMAGE2D_ARRAY_SIZE) && m_addImplicitImageArgs)
131+
else if ((funcName == GET_IMAGE1D_ARRAY_SIZE || funcName == GET_IMAGE2D_ARRAY_SIZE) && !m_useAdvancedBindlessMode)
132132
{
133133
imageFunc = &m_argMap[ImplicitArg::IMAGE_ARRAY_SIZE];
134134
}
@@ -197,9 +197,21 @@ void ImageFuncsAnalysis::visitCallInst(CallInst& CI)
197197
// These WAs need to be reworked to support indirect case in the future.
198198
if (callArg)
199199
{
200-
if (Argument * arg = dyn_cast<Argument>(callArg); arg && isSamplerArgument(arg))
200+
if (Argument * arg = dyn_cast<Argument>(callArg))
201201
{
202-
imageFunc->insert(arg->getArgNo());
202+
if (isSamplerArgument(arg))
203+
{
204+
imageFunc->insert(arg->getArgNo());
205+
return;
206+
}
207+
}
208+
else if (m_useAdvancedBindlessMode)
209+
{
210+
IGC_ASSERT_MESSAGE(isa<ConstantInt>(callArg), "Expect inline sampler");
211+
auto *inlineSampler = cast<ConstantInt>(callArg);
212+
// Inline sampler doesn't associate with an explicit argument.
213+
// To avoid adding a new metadata entry, inline sampler value is stored as explicit argument number.
214+
m_argMap[ImplicitArg::INLINE_SAMPLER].insert(int_cast<int>(inlineSampler->getZExtValue()));
203215
return;
204216
}
205217
}

IGC/Compiler/Optimizer/OpenCLPasses/ImageFuncs/ImageFuncsAnalysis.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ namespace IGC
103103
/// @brief MetaData utils used to generate LLVM metadata
104104
IGCMD::MetaDataUtils* m_pMDUtils = nullptr;
105105

106-
/// @brief If true, implicit image args for information like width, height, etc.
106+
/// @brief Indicate whether advanced bindless mode is used.
107+
/// If false, implicit image args for information like width, height, etc.
107108
/// will be added to m_argMap
108-
bool m_addImplicitImageArgs{};
109+
bool m_useAdvancedBindlessMode{};
109110
};
110111

111112
} // namespace IGC

0 commit comments

Comments
 (0)