Skip to content

Commit f623e3d

Browse files
davidjwoogfxbot
authored andcommitted
Misc. sampler-related changes.
Expanded gather4 workaround to cover gather4_po as well.. Changed ld_mcs definition to allow for different-sized coordinate types. Change-Id: I8bb5da3b131ca4e27d060514e84f7fc24846c5d6
1 parent a2fba48 commit f623e3d

File tree

8 files changed

+64
-46
lines changed

8 files changed

+64
-46
lines changed

IGC/AdaptorCommon/IRUpgrader/UpgraderResourceAccess.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,21 @@ void UpgradeResourceAccess::ChangeIntrinsic(CallInst& C, GenISAIntrinsic::ID ID)
143143
}
144144
break;
145145
case GenISAIntrinsic::GenISA_ldmsptr:
146-
case GenISAIntrinsic::GenISA_ldmcsptr:
147146
case GenISAIntrinsic::GenISA_ldptr: {
148147
types.push_back(C.getType());
149148
unsigned int resIndex = C.getNumOperands() - 5;
150149
args[resIndex] = GetResource(m, builder, args[resIndex]);
151150
types.push_back(args[resIndex]->getType());
152151
}
153152
break;
153+
case GenISAIntrinsic::GenISA_ldmcsptr: {
154+
types.push_back(C.getType());
155+
types.push_back(C.getArgOperand(0)->getType());
156+
unsigned int resIndex = C.getNumOperands() - 5;
157+
args[resIndex] = GetResource(m, builder, args[resIndex]);
158+
types.push_back(args[resIndex]->getType());
159+
}
160+
break;
154161
default:
155162
assert("unhandled intrinsic upgrade" && 0);
156163
break;

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,13 @@ void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst *&pIntr, llvm::Value* oldPt
527527
GenISAIntrinsic::ID id = pIntr->getIntrinsicID();
528528
switch(id)
529529
{
530+
case llvm::GenISAIntrinsic::GenISA_ldmcsptr:
531+
overloadedTys.push_back(pCalledFunc->getReturnType());
532+
overloadedTys.push_back(args[0]->getType());
533+
overloadedTys.push_back(newPtr->getType());
534+
break;
530535
case llvm::GenISAIntrinsic::GenISA_ldptr:
531536
case llvm::GenISAIntrinsic::GenISA_ldmsptr:
532-
case llvm::GenISAIntrinsic::GenISA_ldmcsptr:
533537
overloadedTys.push_back(pCalledFunc->getReturnType());
534538
overloadedTys.push_back(newPtr->getType());
535539
break;

IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,30 @@ void ConvertMSAAPayloadTo16Bit::visitCallInst(CallInst &I)
8181

8282

8383
assert(ldmcs!=NULL);
84-
84+
Type* coordType = m_builder->getInt32Ty();
8585
Type* types_ldmcs[] = {
8686
VectorType::get(m_builder->getInt16Ty(), 4),
87+
coordType,
8788
ldmcs->getOperand(4)->getType() };
8889

8990
Function *func_ldmcs =
9091
GenISAIntrinsic::getDeclaration(
9192
I.getParent()->getParent()->getParent(),
9293
GenISAIntrinsic::GenISA_ldmcsptr,
93-
llvm::ArrayRef<Type*>(types_ldmcs, 2));
94+
llvm::ArrayRef<Type*>(types_ldmcs, 3));
9495

96+
m_builder->SetInsertPoint(ldmcs);
9597
Value * packed_tex_params_ldmcs[] = {
96-
ldmcs->getOperand(0),
97-
ldmcs->getOperand(1),
98-
ldmcs->getOperand(2),
99-
ldmcs->getOperand(3),
98+
m_builder->CreateTrunc(ldmcs->getOperand(0), coordType),
99+
m_builder->CreateTrunc(ldmcs->getOperand(1), coordType),
100+
m_builder->CreateTrunc(ldmcs->getOperand(2), coordType),
101+
m_builder->CreateTrunc(ldmcs->getOperand(3), coordType),
100102
ldmcs->getOperand(4),
101103
ldmcs->getOperand(5),
102104
ldmcs->getOperand(6),
103105
ldmcs->getOperand(7)
104106
};
105107

106-
m_builder->SetInsertPoint(ldmcs);
107108
llvm::CallInst* new_mcs_call = m_builder->CreateCall(func_ldmcs, packed_tex_params_ldmcs);
108109

109110
llvm::Value* mcs0 = m_builder->CreateExtractElement(new_mcs_call, m_builder->getInt32(0));

IGC/Compiler/Optimizer/OCLBIUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ class COCL_ldmcs : public CImagesBI
10911091
m_args.push_back(m_pIntZero); // LOD
10921092
prepareImageBTI();
10931093
prepareZeroOffsets();
1094-
Type* types[] = { llvm::VectorType::get(m_pFloatType, 4), m_args[7]->getType() };
1094+
Type* types[] = { llvm::VectorType::get(m_pFloatType, 4), m_pIntType, m_args[7]->getType() };
10951095
replaceGenISACallInst(GenISAIntrinsic::GenISA_ldmcsptr, types);
10961096
}
10971097
};

IGC/Compiler/WorkaroundAnalysisPass.cpp

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void WorkaroundAnalysis::visitCallInst(llvm::CallInst &I)
264264
switch (intr->getIntrinsicID())
265265
{
266266
case llvm::GenISAIntrinsic::GenISA_gather4POCptr:
267+
case llvm::GenISAIntrinsic::GenISA_gather4POptr:
267268
GatherOffsetWorkaround(cast<SamplerGatherIntrinsic>(&I));
268269
break;
269270
case GenISAIntrinsic::GenISA_ldmsptr:
@@ -383,45 +384,48 @@ void WorkaroundAnalysis::ldmsOffsetWorkaournd(LdMSIntrinsic* ldms)
383384
}
384385
}
385386

386-
/// transform gather4poc into gather4
387-
void WorkaroundAnalysis::GatherOffsetWorkaround(SamplerGatherIntrinsic* gatherpoc)
387+
/// transform gather4poc and gatherpo into gather4c/gather4
388+
void WorkaroundAnalysis::GatherOffsetWorkaround(SamplerGatherIntrinsic* gatherpo)
388389
{
389390
if(IGC_IS_FLAG_DISABLED(EnableGather4cpoWA))
390391
{
391392
return;
392393
}
393394
Value* zero = m_builder->getInt32(0);
394-
if(gatherpoc->getOperand(8) != zero ||
395-
gatherpoc->getOperand(9) != zero ||
396-
gatherpoc->getOperand(10) != zero)
395+
bool hasRef = gatherpo->getIntrinsicID() == llvm::GenISAIntrinsic::GenISA_gather4POCptr;
396+
if(gatherpo->getOperand(hasRef ? 8 : 7) != zero ||
397+
gatherpo->getOperand(hasRef ? 9 : 8) != zero ||
398+
gatherpo->getOperand(hasRef ? 10 : 9) != zero)
397399
{
398400
// only apply the WA if all the immediate offsets are zero
399401
return;
400402
}
401-
Value* resource = gatherpoc->getTextureValue();
402-
Value* sampler = gatherpoc->getSamplerValue();
403+
Value* resource = gatherpo->getTextureValue();
404+
Value* sampler = gatherpo->getSamplerValue();
403405
Function* resInfo =
404406
GenISAIntrinsic::getDeclaration(m_pModule, GenISAIntrinsic::GenISA_resinfoptr, resource->getType());
405-
m_builder->SetInsertPoint(gatherpoc);
407+
m_builder->SetInsertPoint(gatherpo);
406408
Value* info = m_builder->CreateCall2(resInfo, resource, m_builder->getInt32(0));
407-
Value* arg[] =
408-
{
409-
gatherpoc->getOperand(0), // ref
410-
nullptr, // u
411-
nullptr, // v
412-
gatherpoc->getOperand(5), // r
413-
ConstantFP::get(gatherpoc->getOperand(0)->getType(), 0.0), // ai
414-
resource,
415-
sampler,
416-
zero,
417-
zero,
418-
zero,
419-
gatherpoc->getOperand(11),
420-
};
409+
std::vector<Value*> arg;
410+
if (hasRef)
411+
{
412+
arg.push_back(gatherpo->getOperand(0)); // ref
413+
}
414+
arg.push_back(nullptr); // u
415+
arg.push_back(nullptr); // v
416+
arg.push_back(gatherpo->getOperand(hasRef ? 5 : 4)); // r
417+
arg.push_back(ConstantFP::get(gatherpo->getOperand(0)->getType(), 0.0)); // ai
418+
arg.push_back(resource);
419+
arg.push_back(sampler);
420+
arg.push_back(zero);
421+
arg.push_back(zero);
422+
arg.push_back(zero);
423+
arg.push_back(gatherpo->getOperand(hasRef ? 11 : 10));
424+
421425
for(unsigned int i = 0; i < 2; i++)
422426
{
423-
Value* coord = gatherpoc->getOperand(i + 1);
424-
Value* offset = gatherpoc->getOperand(i + 3);
427+
Value* coord = gatherpo->getOperand(i + (hasRef ? 1 : 0));
428+
Value* offset = gatherpo->getOperand(i + (hasRef ? 3 : 2));
425429

426430
Value* size = m_builder->CreateExtractElement(info, m_builder->getInt32(i));
427431
size = m_builder->CreateUIToFP(size, coord->getType());
@@ -434,20 +438,22 @@ void WorkaroundAnalysis::GatherOffsetWorkaround(SamplerGatherIntrinsic* gatherpo
434438
//
435439
Value* newCoord = m_builder->CreateFMul(offset, invSize);
436440
newCoord = m_builder->CreateFAdd(newCoord, coord);
437-
arg[i + 1] = newCoord;
441+
arg[i + (hasRef ? 1 : 0)] = newCoord;
438442
}
439443
Type* types[] =
440444
{
441-
gatherpoc->getType(),
442-
gatherpoc->getOperand(0)->getType(),
445+
gatherpo->getType(),
446+
gatherpo->getOperand(0)->getType(),
443447
resource->getType(),
444448
sampler->getType(),
445449
};
446-
Function* gather4cFunc =
447-
GenISAIntrinsic::getDeclaration(m_pModule, GenISAIntrinsic::GenISA_gather4Cptr, types);
448-
Value* gather4c = m_builder->CreateCall(gather4cFunc, arg);
449-
gatherpoc->replaceAllUsesWith(gather4c);
450-
gatherpoc->eraseFromParent();
450+
Function* gather4Func = GenISAIntrinsic::getDeclaration(
451+
m_pModule,
452+
hasRef ? GenISAIntrinsic::GenISA_gather4Cptr : GenISAIntrinsic::GenISA_gather4ptr,
453+
types);
454+
Value* gather4c = m_builder->CreateCall(gather4Func, arg);
455+
gatherpo->replaceAllUsesWith(gather4c);
456+
gatherpo->eraseFromParent();
451457
}
452458

453459

IGC/GenISAIntrinsics/Intrinsic_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"GenISA_evaluateSampler": ["void",["anyvector"],"None"],
120120
"GenISA_ldmsptr16bit": ["anyvector",["short","short","short","short","short","short","short","short","short","anyptr","int","int","int"],"NoMem"],
121121
"GenISA_ldmsptr": ["anyvector",["int","int","int","int","int","int","int","anyptr","int","int","int"],"NoMem"],
122-
"GenISA_ldmcsptr": ["anyvector",["int","int","int","int","anyptr","int","int","int"],"NoMem"],
122+
"GenISA_ldmcsptr": ["anyvector",["anyint",1,1,1,"anyptr","int","int","int"],"NoMem"],
123123
"GenISA_lodptr": ["anyvector",["anyfloat",1,1,1,"anyptr","anyptr"],"NoMem"],
124124
"GenISA_sampleptr": ["anyvector",["anyfloat",1,1,1,1,"anyptr","anyptr","int","int","int"],"NoMem"],
125125
"GenISA_sampleBptr": ["anyvector",["anyfloat",1,1,1,1,1,"anyptr","anyptr","int","int","int"],"NoMem"],

IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,9 +1761,9 @@ inline llvm::CallInst* LLVM3DBuilder<preserveNames, T, Inserter>::Create_ldms(
17611761

17621762
llvm::Module* module = this->GetInsertBlock()->getParent()->getParent();
17631763

1764-
llvm::Type* types[] = { llvm::VectorType::get(this->getInt32Ty(), 2), int32_textureIdx->getType() };
1764+
llvm::Type* types[] = { llvm::VectorType::get(this->getInt32Ty(), 2), this->getInt32Ty(), int32_textureIdx->getType() };
17651765
llvm::Function* func_llvm_GenISA_ldmcsptr_v4f32_f32 = llvm::GenISAIntrinsic::getDeclaration
1766-
(module, llvm::GenISAIntrinsic::GenISA_ldmcsptr, llvm::ArrayRef<llvm::Type*>(types, 2));
1766+
(module, llvm::GenISAIntrinsic::GenISA_ldmcsptr, llvm::ArrayRef<llvm::Type*>(types, 3));
17671767
llvm::CallInst* packed_mcs_call = this->CreateCall(func_llvm_GenISA_ldmcsptr_v4f32_f32, packed_mcs_params);
17681768

17691769

IGC/common/igc_flags.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ DECLARE_IGC_REGKEY(bool, EnableVariableReuse, true, "Enable local vari
258258
DECLARE_IGC_REGKEY(bool, EnableVariableAlias, true, "Enable variable aliases (part of VariableReuse Pass, but separate functionality)")
259259
DECLARE_IGC_REGKEY(DWORD, EnableVATemp, 0, "[temp]Enable variable aliases sub-optimization, once it is stable, remove this key")
260260
DECLARE_IGC_REGKEY(DWORD, VariableReuseByteSize, 64, "The byte size threshold for variable reuse")
261-
DECLARE_IGC_REGKEY(bool, EnableGather4cpoWA, true, "Enable WA transforming gather4cpo into gather4c")
261+
DECLARE_IGC_REGKEY(bool, EnableGather4cpoWA, true, "Enable WA transforming gather4cpo/gather4po into gather4c/gather4")
262262
DECLARE_IGC_REGKEY(bool, EnableIntelFast, false, "Enable intel fast, experimental flag.")
263263
DECLARE_IGC_REGKEY(bool, disableUnormTypedReadWA, false, "disable software conversion for UNORM surface")
264264
DECLARE_IGC_REGKEY(bool, forceGlobalRA, false, "force global register allocator")

0 commit comments

Comments
 (0)