@@ -205,141 +205,89 @@ Value* ImageFuncResolution::getImageNumSamples(CallInst& CI)
205
205
return arg;
206
206
}
207
207
208
- Value* ImageFuncResolution::getSamplerAddressMode (CallInst& CI)
208
+ template <ImplicitArg::ArgType ArgTy>
209
+ Value* ImageFuncResolution::getSamplerProperty (CallInst& CI)
209
210
{
210
211
MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils ();
211
212
ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData ();
212
-
213
- Value* sampler = ValueTracker::track (&CI, 0 , pMdUtils, modMD);
214
- if (sampler == nullptr )
215
- {
216
- // TODO: For now disable WA if unable to trace sampler argument.
217
- // Will need to rework WA to add support for indirect sampler case.
218
- return ConstantInt::get (CI.getType (), 0 );
219
- }
220
- if (isa<Argument>(sampler))
221
- {
222
- Argument* arg = getImplicitImageArg (CI, ImplicitArg::SAMPLER_ADDRESS);
223
- return arg;
224
- }
225
- else
213
+ if (Value* sampler = ValueTracker::track (&CI, 0 , pMdUtils, modMD))
226
214
{
227
- llvm::Function* pFunc = CI.getParent ()->getParent ();
228
-
229
- IGC_ASSERT_MESSAGE (isa<ConstantInt>(sampler), " Sampler must be a constant integer" );
230
- InlineSamplerState samplerStateAddressMode{ cast<ConstantInt>(sampler)->getZExtValue () };
231
- uint64_t samplerVal = 0 ;
232
- uint samplerValue = int_cast<unsigned int >(cast<ConstantInt>(sampler)->getZExtValue ());
233
- if (modMD->FuncMD .find (pFunc) != modMD->FuncMD .end ())
215
+ if (isa<Argument>(sampler))
234
216
{
235
- FunctionMetaData funcMD = modMD->FuncMD [pFunc];
236
- ResourceAllocMD resAllocMD = funcMD.resAllocMD ;
237
- for (auto i = resAllocMD.inlineSamplersMD .begin (), e = resAllocMD.inlineSamplersMD .end (); i != e; i++)
217
+ if (m_implicitArgs.isImplicitArgExist (ArgTy))
238
218
{
239
- IGC::InlineSamplersMD inlineSamplerMD = *i;
240
- if (samplerValue == inlineSamplerMD.m_Value )
241
- {
242
- InlineSamplerState samplerState{ static_cast <uint64_t >(samplerValue) };
243
- samplerVal = inlineSamplerMD.addressMode ;
244
- }
219
+ Argument* arg = getImplicitImageArg (CI, ArgTy);
220
+ return arg;
245
221
}
246
222
}
247
- return ConstantInt::get (CI.getType (), samplerVal);
248
- }
249
- }
250
-
251
- Value* ImageFuncResolution::getSamplerNormalizedCoords (CallInst& CI)
252
- {
253
- MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils ();
254
- ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData ();
255
- Value* sampler = ValueTracker::track (&CI, 0 , pMdUtils, modMD);
256
- if (sampler == nullptr )
257
- {
258
- // TODO: For now disable WA if unable to trace sampler argument.
259
- // Will need to rework WA to add support for indirect sampler case.
260
- return ConstantInt::get (CI.getType (), 0 );
261
- }
262
- else if (isa<Argument>(sampler))
263
- {
264
- Argument* arg = getImplicitImageArg (CI, ImplicitArg::SAMPLER_NORMALIZED);
265
- return arg;
266
- }
267
- else
268
- {
269
- llvm::Function* pFunc = CI.getParent ()->getParent ();
270
- IGC_ASSERT_MESSAGE (isa<ConstantInt>(sampler), " Sampler must be a constant integer" );
271
-
272
- uint64_t samplerVal = 0 ;
273
- uint samplerValue = int_cast<unsigned int >(cast<ConstantInt>(sampler)->getZExtValue ());
274
-
275
- if (modMD->FuncMD .find (pFunc) != modMD->FuncMD .end ())
223
+ else
276
224
{
277
- FunctionMetaData funcMD = modMD->FuncMD [pFunc];
278
- ResourceAllocMD resAllocMD = funcMD.resAllocMD ;
279
- for (auto i = resAllocMD.inlineSamplersMD .begin (), e = resAllocMD.inlineSamplersMD .end (); i != e; ++i)
225
+ llvm::Function* pFunc = CI.getFunction ();
226
+
227
+ IGC_ASSERT_MESSAGE (isa<ConstantInt>(sampler), " Sampler must be a constant integer" );
228
+ uint64_t samplerVal = 0 ;
229
+ if (modMD->FuncMD .find (pFunc) != modMD->FuncMD .end ())
280
230
{
281
- IGC::InlineSamplersMD inlineSamplerMD = *i;
282
- if (samplerValue == inlineSamplerMD.m_Value )
231
+ FunctionMetaData funcMD = modMD->FuncMD [pFunc];
232
+ ResourceAllocMD resAllocMD = funcMD.resAllocMD ;
233
+ uint samplerValue = int_cast<unsigned int >(cast<ConstantInt>(sampler)->getZExtValue ());
234
+ for (auto i = resAllocMD.inlineSamplersMD .begin (), e = resAllocMD.inlineSamplersMD .end (); i != e; i++)
283
235
{
284
- InlineSamplerState samplerState{ static_cast <uint64_t >(samplerValue) };
285
- samplerVal = inlineSamplerMD.NormalizedCoords ;
236
+ IGC::InlineSamplersMD inlineSamplerMD = *i;
237
+ if (samplerValue == inlineSamplerMD.m_Value )
238
+ {
239
+ InlineSamplerState samplerState{ static_cast <uint64_t >(samplerValue) };
240
+ if constexpr (ArgTy == ImplicitArg::SAMPLER_ADDRESS)
241
+ {
242
+ samplerVal = inlineSamplerMD.addressMode ;
243
+ }
244
+ else if constexpr (ArgTy == ImplicitArg::SAMPLER_NORMALIZED)
245
+ {
246
+ samplerVal = inlineSamplerMD.NormalizedCoords ;
247
+ }
248
+ else if constexpr (ArgTy == ImplicitArg::SAMPLER_SNAP_WA)
249
+ {
250
+ bool anyAddressModeClamp =
251
+ inlineSamplerMD.TCXAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER ||
252
+ inlineSamplerMD.TCYAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER ||
253
+ inlineSamplerMD.TCZAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER;
254
+ bool anyMapFilterModeNearest =
255
+ inlineSamplerMD.MagFilterType == iOpenCL::SAMPLER_MAPFILTER_POINT ||
256
+ inlineSamplerMD.MinFilterType == iOpenCL::SAMPLER_MAPFILTER_POINT;
257
+ bool snapWARequired = anyAddressModeClamp &&
258
+ anyMapFilterModeNearest &&
259
+ !inlineSamplerMD.NormalizedCoords ;
260
+ samplerVal = snapWARequired ? -1 : 0 ;
261
+ }
262
+ else
263
+ {
264
+ llvm_unreachable (" unexpected sampler property" );
265
+ }
266
+ }
286
267
}
287
268
}
269
+ return ConstantInt::get (CI.getType (), samplerVal);
288
270
}
289
- return ConstantInt::get (CI.getType (), samplerVal);
290
271
}
272
+
273
+ // TODO: For now disable WA if unable to trace sampler argument.
274
+ // Will need to rework WA to add support for indirect sampler case.
275
+ return ConstantInt::get (CI.getType (), 0 );
291
276
}
292
277
293
- Value* ImageFuncResolution::getSamplerSnapWARequired (CallInst& CI)
278
+ Value* ImageFuncResolution::getSamplerAddressMode (CallInst& CI)
294
279
{
295
- MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils ();
296
- ModuleMetaData* modMD = getAnalysis<MetaDataUtilsWrapper>().getModuleMetaData ();
297
- Value* sampler = ValueTracker::track (&CI, 0 , pMdUtils, modMD);
298
- if (sampler == nullptr )
299
- {
300
- // TODO: For now disable WA if unable to trace sampler argument.
301
- // Will need to rework WA to add support for indirect sampler case.
302
- return ConstantInt::get (CI.getType (), 0 );
303
- }
304
- else if (isa<Argument>(sampler))
305
- {
306
- Argument* arg = getImplicitImageArg (CI, ImplicitArg::SAMPLER_SNAP_WA);
307
- return arg;
308
- }
309
- else
310
- {
311
- IGC_ASSERT_MESSAGE (isa<ConstantInt>(sampler), " Sampler must be a constant integer" );
312
-
313
- llvm::Function* pFunc = CI.getParent ()->getParent ();
280
+ return getSamplerProperty<ImplicitArg::SAMPLER_ADDRESS>(CI);
281
+ }
314
282
315
- bool snapWARequired = false ;
316
- uint samplerVal = int_cast<unsigned int >(cast<ConstantInt>(sampler)->getZExtValue ());
283
+ Value* ImageFuncResolution::getSamplerNormalizedCoords (CallInst& CI)
284
+ {
285
+ return getSamplerProperty<ImplicitArg::SAMPLER_NORMALIZED>(CI);
286
+ }
317
287
318
- if (modMD->FuncMD .find (pFunc) != modMD->FuncMD .end ())
319
- {
320
- FunctionMetaData funcMD = modMD->FuncMD [pFunc];
321
- ResourceAllocMD resAllocMD = funcMD.resAllocMD ;
322
- for (auto i = resAllocMD.inlineSamplersMD .begin (), e = resAllocMD.inlineSamplersMD .end (); i != e; ++i)
323
- {
324
- InlineSamplersMD inlineSamplerMD = *i;
325
- if (samplerVal == inlineSamplerMD.m_Value )
326
- {
327
- InlineSamplerState samplerState{ static_cast <uint64_t >(samplerVal) };
328
- bool anyAddressModeClamp =
329
- inlineSamplerMD.TCXAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER ||
330
- inlineSamplerMD.TCYAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER ||
331
- inlineSamplerMD.TCZAddressMode == iOpenCL::SAMPLER_TEXTURE_ADDRESS_MODE_BORDER;
332
- bool anyMapFilterModeNearest =
333
- inlineSamplerMD.MagFilterType == iOpenCL::SAMPLER_MAPFILTER_POINT ||
334
- inlineSamplerMD.MinFilterType == iOpenCL::SAMPLER_MAPFILTER_POINT;
335
- snapWARequired = anyAddressModeClamp &&
336
- anyMapFilterModeNearest &&
337
- !inlineSamplerMD.NormalizedCoords ;
338
- }
339
- }
340
- }
341
- return ConstantInt::get (CI.getType (), snapWARequired ? -1 : 0 );
342
- }
288
+ Value* ImageFuncResolution::getSamplerSnapWARequired (CallInst& CI)
289
+ {
290
+ return getSamplerProperty<ImplicitArg::SAMPLER_SNAP_WA>(CI);
343
291
}
344
292
345
293
Argument* ImageFuncResolution::getImplicitImageArg (CallInst& CI, ImplicitArg::ArgType argType) {
0 commit comments