@@ -15,11 +15,9 @@ SPDX-License-Identifier: MIT
15
15
#include " llvmWrapper/IR/IRBuilder.h"
16
16
#include " llvmWrapper/IR/Instructions.h"
17
17
#include " common/LLVMWarningsPop.hpp"
18
- #include " AdaptorCommon/ImplicitArgs.hpp"
19
18
#include " LLVM3DBuilder/BuiltinsFrontend.hpp"
20
19
#include " Probe/Assertion.h"
21
20
#include " IGC/common/StringMacros.hpp"
22
- #include < llvm/Support/Casting.h>
23
21
24
22
using namespace llvm ;
25
23
using namespace IGC ;
@@ -251,7 +249,7 @@ Argument* CImagesBI::CImagesUtils::findImageFromBufferPtr(const MetaDataUtils& M
251
249
return nullptr ;
252
250
}
253
251
254
- static bool isSYCLBindlessImageLoad (Value *v)
252
+ static bool isBindlessImageLoad (Value *v)
255
253
{
256
254
auto *load = dyn_cast<LoadInst>(v);
257
255
if (!load)
@@ -272,7 +270,7 @@ ConstantInt* CImagesBI::CImagesUtils::getImageIndex(
272
270
{
273
271
ConstantInt* imageIndex = nullptr ;
274
272
275
- imageParam = ValueTracker::track (pCallInst, paramIndex, nullptr , nullptr , isSYCLBindlessImageLoad );
273
+ imageParam = ValueTracker::track (pCallInst, paramIndex, nullptr , nullptr , isBindlessImageLoad );
276
274
IGC_ASSERT (imageParam);
277
275
IGC_ASSERT (isa<Argument>(imageParam) || isa<LoadInst>(imageParam));
278
276
int i = (*pParamMap)[imageParam].index ;
@@ -282,7 +280,7 @@ ConstantInt* CImagesBI::CImagesUtils::getImageIndex(
282
280
283
281
BufferType CImagesBI::CImagesUtils::getImageType (ParamMap* pParamMap, CallInst* pCallInst, unsigned int paramIndex)
284
282
{
285
- Value *imageParam = ValueTracker::track (pCallInst, paramIndex, nullptr , nullptr , isSYCLBindlessImageLoad );
283
+ Value *imageParam = ValueTracker::track (pCallInst, paramIndex, nullptr , nullptr , isBindlessImageLoad );
286
284
IGC_ASSERT (imageParam);
287
285
IGC_ASSERT (isa<Argument>(imageParam) || isa<LoadInst>(imageParam));
288
286
return isa<LoadInst>(imageParam) ? BufferType::BINDLESS : (*pParamMap)[imageParam].type ;
@@ -441,104 +439,62 @@ class COCL_sample : public CImagesBI
441
439
}
442
440
return false ;
443
441
};
444
- Value* samplerValue = ValueTracker::track (m_pCallInst, 1 , m_pMdUtils, m_modMD, isBindlessSampler);
445
- if (!samplerValue ) {
442
+ Value* samplerParam = ValueTracker::track (m_pCallInst, 1 , m_pMdUtils, m_modMD, isBindlessSampler);
443
+ if (!samplerParam ) {
446
444
emitError (" There are instructions that use a sampler, but no sampler found in the kernel!" , m_pCallInst);
447
445
return nullptr ;
448
446
}
449
447
450
448
auto modMD = m_pCodeGenContext->getModuleMetaData ();
451
449
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
-
450
+ // If bindless image is preferred, map the bindless pointer
477
451
if (modMD->UseBindlessImage )
478
452
{
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
- }
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);
525
461
return bindlessSampler;
526
462
}
527
463
528
464
// Argument samplers are looked up in the parameter map
529
- if (isa<Argument>(samplerValue ))
465
+ if (isa<Argument>(samplerParam ))
530
466
{
531
- int i = (*m_pParamMap)[samplerValue ].index ;
467
+ int i = (*m_pParamMap)[samplerParam ].index ;
532
468
samplerIndex = ConstantInt::get (m_pIntType, i);
533
469
return samplerIndex;
534
470
}
535
471
536
472
// The sampler is not an argument, make sure it's a constant
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 ());
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
+ }
540
483
541
- return addToInlineSamplersMD (samplerConstantVal);
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;
542
498
}
543
499
544
500
void CreateInlineSamplerAnnotations (InlineSamplersMD& inlineSamplerMD, int samplerValue)
0 commit comments