Skip to content

Commit a18baec

Browse files
DianaChenigcbot
authored andcommitted
vISA: support paired surface
Add paired surface argument to message APIs
1 parent 6f6b47a commit a18baec

28 files changed

+401
-86
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,22 @@ namespace IGC
21572157
return srcOpnd;
21582158
}
21592159

2160+
VISA_RawOpnd* CEncoder::GetPairedResourceOperand(const ResourceDescriptor& pairedResource)
2161+
{
2162+
VISA_RawOpnd* pairedResourceBSSOOpnd = nullptr;
2163+
if (m_program->m_Platform->hasSamplerFeedbackSurface() &&
2164+
pairedResource.m_surfaceType == ESURFACE_BINDLESS &&
2165+
IGC_IS_FLAG_ENABLED(EnableInsertingPairedResourcePointer))
2166+
{
2167+
pairedResourceBSSOOpnd = GetRawSource(pairedResource.m_resource);
2168+
}
2169+
else
2170+
{
2171+
V(vKernel->CreateVISANullRawOperand(pairedResourceBSSOOpnd, false));
2172+
}
2173+
return pairedResourceBSSOOpnd;
2174+
}
2175+
21602176
VISA_RawOpnd* CEncoder::GetRawDestination(CVariable* var, unsigned offset)
21612177
{
21622178
VISA_RawOpnd* dstOpnd = nullptr;
@@ -2469,6 +2485,7 @@ namespace IGC
24692485
uint writeMask,
24702486
CVariable* offset,
24712487
const ResourceDescriptor& resource,
2488+
const ResourceDescriptor& pairedResource,
24722489
const SamplerDescriptor& sampler,
24732490
uint numSources,
24742491
CVariable* dst,
@@ -2491,6 +2508,7 @@ namespace IGC
24912508
bool isIdxLT16;
24922509
VISA_StateOpndHandle* samplerOpnd = GetSamplerOperand(sampler, isIdxLT16);
24932510
VISA_StateOpndHandle* btiOpnd = GetVISASurfaceOpnd(resource);
2511+
VISA_RawOpnd* pairedResourceBSSOOpnd = GetPairedResourceOperand(pairedResource);
24942512
VISA_RawOpnd* dstVar = GetRawDestination(dst);
24952513
VISA_RawOpnd* opndArray[11];
24962514
for (int i = 0; i < numMsgSpecificOpnds; i++)
@@ -2522,6 +2540,7 @@ namespace IGC
25222540
aoffimmi,
25232541
samplerOpnd,
25242542
btiOpnd,
2543+
pairedResourceBSSOOpnd,
25252544
dstVar,
25262545
numSources,
25272546
opndArray);
@@ -2535,6 +2554,7 @@ namespace IGC
25352554
uint writeMask,
25362555
CVariable* offset,
25372556
const ResourceDescriptor& resource,
2557+
const ResourceDescriptor& pairedResource,
25382558
uint numSources,
25392559
CVariable* dst,
25402560
SmallVector<CVariable*, 4>& payload,
@@ -2550,6 +2570,7 @@ namespace IGC
25502570

25512571
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
25522572
VISA_StateOpndHandle* surfOpnd = GetVISASurfaceOpnd(resource);
2573+
VISA_RawOpnd* pairedResourceBSSOOpnd = GetPairedResourceOperand(pairedResource);
25532574
VISA_RawOpnd* dstVar = GetRawDestination(dst);
25542575

25552576
VISA_RawOpnd* opndArray[11];
@@ -2572,6 +2593,7 @@ namespace IGC
25722593
ConvertChannelMaskToVisaType(writeMask),
25732594
aoffimmi,
25742595
surfOpnd,
2596+
pairedResourceBSSOOpnd,
25752597
dstVar,
25762598
numSources,
25772599
opndArray);
@@ -2649,6 +2671,7 @@ namespace IGC
26492671
EOPCODE subOpcode,
26502672
CVariable* offset,
26512673
const ResourceDescriptor& resource,
2674+
const ResourceDescriptor& pairedResource,
26522675
const SamplerDescriptor& sampler,
26532676
uint numSources,
26542677
CVariable* dst,
@@ -2670,6 +2693,7 @@ namespace IGC
26702693
VISA_StateOpndHandle* surfOpnd = GetVISASurfaceOpnd(resource);
26712694
uint32_t samplerImmIndex = 0;
26722695
uint32_t surfaceImmIndex = 0;
2696+
VISA_RawOpnd* pairedResourceBSSOOpnd = GetPairedResourceOperand(pairedResource);
26732697
VISA_RawOpnd* dstVar = GetRawDestination(dst);
26742698
VISA_RawOpnd* opndArray[11];
26752699
for (unsigned int i = 0; i < numSources; i++)
@@ -2697,6 +2721,7 @@ namespace IGC
26972721
samplerImmIndex,
26982722
surfOpnd,
26992723
surfaceImmIndex,
2724+
pairedResourceBSSOOpnd,
27002725
dstVar,
27012726
numSources,
27022727
opndArray);

IGC/Compiler/CISACodeGen/CISABuilder.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ namespace IGC
191191
uint writeMask,
192192
CVariable* offset,
193193
const ResourceDescriptor& bindingTableIndex,
194+
const ResourceDescriptor& pairedesource,
194195
const SamplerDescriptor& SamplerIdx,
195196
uint numSources,
196197
CVariable* dst,
@@ -204,6 +205,7 @@ namespace IGC
204205
uint writeMask,
205206
CVariable* offset,
206207
const ResourceDescriptor& resource,
208+
const ResourceDescriptor& pairedesource,
207209
uint numSources,
208210
CVariable* dst,
209211
llvm::SmallVector<CVariable*, 4> & payload,
@@ -216,6 +218,7 @@ namespace IGC
216218
EOPCODE subOpcode,
217219
CVariable* offset,
218220
const ResourceDescriptor& resource,
221+
const ResourceDescriptor& pairedesource,
219222
const SamplerDescriptor& sampler,
220223
uint numSources,
221224
CVariable* dst,
@@ -524,6 +527,7 @@ namespace IGC
524527
VISA_VectorOpnd* GetSourceOperandNoModifier(CVariable* var);
525528
VISA_VectorOpnd* GetDestinationOperand(CVariable* var, const SModifier& mod);
526529
VISA_RawOpnd* GetRawSource(CVariable* var, uint offset = 0);
530+
VISA_RawOpnd* GetPairedResourceOperand(const ResourceDescriptor& pairedResource);
527531
VISA_RawOpnd* GetRawDestination(CVariable* var, unsigned offset = 0);
528532
VISA_PredOpnd* GetFlagOperand(const SFlag& flag);
529533
VISA_StateOpndHandle* GetVISASurfaceOpnd(e_predefSurface surfaceType, CVariable* bti);
@@ -1088,11 +1092,13 @@ namespace IGC
10881092
const ResourceDescriptor& resource, uint numSources, CVariable* dst,
10891093
llvm::SmallVector<CVariable*, 4> & payload, bool feedbackEnable)
10901094
{
1095+
ResourceDescriptor pairedResource{};
10911096
Load(
10921097
subOpcode,
10931098
writeMask,
10941099
offset,
10951100
resource,
1101+
pairedResource,
10961102
numSources,
10971103
dst,
10981104
payload,

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,15 +4915,15 @@ void EmitPass::emitLdInstruction(llvm::Instruction* inst)
49154915
{
49164916
uint numOperands = inst->getNumOperands();
49174917
IGC_ASSERT_MESSAGE(7 < numOperands, "Wrong number of operands");
4918-
IGC_ASSERT_MESSAGE(numOperands < 10, "Wrong number of operands");
4918+
IGC_ASSERT_MESSAGE(numOperands < 11, "Wrong number of operands");
49194919

49204920
EOPCODE opCode = GetOpCode(inst);
49214921
//Subtract the offsets, resource sources to get
49224922
//the number of texture coordinates and index to texture source
4923-
uint numSources = numOperands - 5;
4923+
uint numSources = numOperands - 6;
49244924
uint textureArgIdx = numOperands - 5;
49254925

4926-
uint offsetSourceIndex = numSources + 1;
4926+
uint offsetSourceIndex = numSources + 2;
49274927

49284928
SmallVector<CVariable*, 4> payload;
49294929

@@ -5027,6 +5027,11 @@ void EmitPass::emitLdInstruction(llvm::Instruction* inst)
50275027
m_encoder->SetUniformSIMDSize(m_currShader->m_Platform->getMinDispatchMode());
50285028
}
50295029

5030+
SamplerLoadIntrinsic* samplerLoadIntrinsic = llvm::cast<llvm::SamplerLoadIntrinsic>(inst);
5031+
ResourceDescriptor pairedResource = samplerLoadIntrinsic->hasPairedTextureArg() &&
5032+
llvm::isa<llvm::UndefValue>(samplerLoadIntrinsic->getPairedTextureValue()) == false ?
5033+
GetResourceVariable(samplerLoadIntrinsic->getPairedTextureValue()) :
5034+
ResourceDescriptor();
50305035

50315036
CVariable* offset = ComputeSampleIntOffset(inst, offsetSourceIndex);
50325037

@@ -5035,6 +5040,7 @@ void EmitPass::emitLdInstruction(llvm::Instruction* inst)
50355040
writeMask.getEM(),
50365041
offset,
50375042
resource,
5043+
pairedResource,
50385044
numSources,
50395045
dst,
50405046
payload,
@@ -7492,6 +7498,10 @@ void EmitPass::emitSampleInstruction(SampleIntrinsic* inst)
74927498

74937499
m_currShader->SetHasSample();
74947500
ResourceDescriptor resource = GetSampleResourceHelper(inst);
7501+
bool isEval = isUsedOnlyByEval(inst);
7502+
ResourceDescriptor pairedResource = inst->hasPairedTextureArg() && llvm::isa<llvm::UndefValue>(inst->getPairedTextureValue()) == false ?
7503+
GetResourceVariable(inst->getPairedTextureValue()) :
7504+
ResourceDescriptor();
74957505

74967506

74977507
//Get sampler index in the array of operands
@@ -7598,6 +7608,7 @@ void EmitPass::emitSampleInstruction(SampleIntrinsic* inst)
75987608
writeMask.getEM(),
75997609
immOffset,
76007610
resource,
7611+
pairedResource,
76017612
sampler,
76027613
numSources,
76037614
dst,
@@ -7909,6 +7920,10 @@ void EmitPass::emitGather4Instruction(SamplerGatherIntrinsic* inst)
79097920
ResourceDescriptor resource = GetResourceVariable(textureValue);
79107921

79117922
bool isEval = isUsedOnlyByEval(inst);
7923+
ResourceDescriptor pairedResource = llvm::isa<llvm::UndefValue>(inst->getPairedTextureValue()) == false ?
7924+
GetResourceVariable(inst->getPairedTextureValue()) :
7925+
ResourceDescriptor();
7926+
79127927
SamplerDescriptor sampler;
79137928
Value* samplerValue = inst->getSamplerValue();
79147929

@@ -7974,6 +7989,7 @@ void EmitPass::emitGather4Instruction(SamplerGatherIntrinsic* inst)
79747989
opCode,
79757990
offset,
79767991
resource,
7992+
pairedResource,
79777993
sampler,
79787994
numSources,
79797995
dst,

IGC/Compiler/CISACodeGen/UniformAssumptions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ namespace IGC {
8686
}
8787
}
8888
// Figure out the intrinsic operands for texture & sampler
89+
// & paired texture
90+
llvm::Value* pPairedTextureValue = nullptr;
8991
llvm::Value* pTextureValue = nullptr;
9092
llvm::Value*pSamplerValue = nullptr;
9193
IGC::getTextureAndSamplerOperands(
9294
pIntr,
95+
pPairedTextureValue,
9396
pTextureValue,
9497
pSamplerValue);
9598

@@ -103,6 +106,16 @@ namespace IGC {
103106
}
104107
}
105108

109+
if (pPairedTextureValue && pPairedTextureValue->getType()->isPointerTy() &&
110+
!m_WIAnalysis->isUniform(pPairedTextureValue))
111+
{
112+
// Check assumptions for texture:
113+
if (m_forceUniformTexture || IsAssumedUniform(pPairedTextureValue))
114+
{
115+
MakeUniformResourceOperand(pPairedTextureValue, &CI);
116+
}
117+
}
118+
106119
if (pSamplerValue && pSamplerValue->getType()->isPointerTy() &&
107120
!m_WIAnalysis->isUniform(pSamplerValue))
108121
{

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,12 @@ namespace IGC
979979
case llvm::GenISAIntrinsic::GenISA_ldmsptr:
980980
{
981981
llvm::Value* pTextureValue = cast<SamplerLoadIntrinsic>(pIntr)->getTextureValue();
982+
llvm::Value* pPairedTextureValue = cast<SamplerLoadIntrinsic>(pIntr)->getPairedTextureValue();
982983
overloadedTys.push_back(pCalledFunc->getReturnType());
984+
if (pPairedTextureValue != nullptr)
985+
{
986+
overloadedTys.push_back(pPairedTextureValue == oldPtr ? newPtr->getType() : pPairedTextureValue->getType());
987+
}
983988
overloadedTys.push_back(pTextureValue == oldPtr ? newPtr->getType() : pTextureValue->getType());
984989
break;
985990
}
@@ -1003,15 +1008,22 @@ namespace IGC
10031008
case llvm::GenISAIntrinsic::GenISA_lodptr:
10041009
{
10051010
// Figure out the intrinsic operands for texture & sampler
1011+
// & paired texture
1012+
llvm::Value* pPairedTextureValue = nullptr;
10061013
llvm::Value* pTextureValue = nullptr;
10071014
llvm::Value* pSamplerValue = nullptr;
10081015
IGC::getTextureAndSamplerOperands(
10091016
pIntr,
1017+
pPairedTextureValue,
10101018
pTextureValue,
10111019
pSamplerValue);
10121020

10131021
overloadedTys.push_back(pCalledFunc->getReturnType());
10141022
overloadedTys.push_back(pIntr->getOperand(0)->getType());
1023+
if (pPairedTextureValue != nullptr)
1024+
{
1025+
overloadedTys.push_back(pPairedTextureValue == oldPtr ? newPtr->getType() : pPairedTextureValue->getType());
1026+
}
10151027
overloadedTys.push_back(pTextureValue == oldPtr ? newPtr->getType() : pTextureValue->getType());
10161028
if (pSamplerValue != nullptr)
10171029
{
@@ -1118,24 +1130,41 @@ namespace IGC
11181130
llvm::GenIntrinsicInst* pIntr,
11191131
llvm::Value*& pTextureValue,
11201132
llvm::Value*& pSamplerValue)
1133+
{
1134+
llvm::Value* pUnusedPairedTextureValue;
1135+
getTextureAndSamplerOperands(pIntr, pUnusedPairedTextureValue, pTextureValue, pSamplerValue);
1136+
}
1137+
1138+
///
1139+
/// Returns the sampler/texture/paired texture pointers for resource access intrinsics
1140+
///
1141+
void getTextureAndSamplerOperands(
1142+
llvm::GenIntrinsicInst* pIntr,
1143+
llvm::Value*& pPairedTextureValue,
1144+
llvm::Value*& pTextureValue,
1145+
llvm::Value*& pSamplerValue)
11211146
{
11221147
if (llvm::SamplerLoadIntrinsic * pSamplerLoadInst = llvm::dyn_cast<llvm::SamplerLoadIntrinsic>(pIntr))
11231148
{
1149+
pPairedTextureValue = pSamplerLoadInst->getPairedTextureValue();
11241150
pTextureValue = pSamplerLoadInst->getTextureValue();
11251151
pSamplerValue = nullptr;
11261152
}
11271153
else if (llvm::SampleIntrinsic * pSampleInst = llvm::dyn_cast<llvm::SampleIntrinsic>(pIntr))
11281154
{
1155+
pPairedTextureValue = pSampleInst->getPairedTextureValue();
11291156
pTextureValue = pSampleInst->getTextureValue();
11301157
pSamplerValue = pSampleInst->getSamplerValue();
11311158
}
11321159
else if (llvm::SamplerGatherIntrinsic * pGatherInst = llvm::dyn_cast<llvm::SamplerGatherIntrinsic>(pIntr))
11331160
{
1161+
pPairedTextureValue = pGatherInst->getPairedTextureValue();
11341162
pTextureValue = pGatherInst->getTextureValue();
11351163
pSamplerValue = pGatherInst->getSamplerValue();
11361164
}
11371165
else
11381166
{
1167+
pPairedTextureValue = nullptr;
11391168
pTextureValue = nullptr;
11401169
pSamplerValue = nullptr;
11411170
switch (pIntr->getIntrinsicID())

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace IGC
157157
llvm::StoreRawIntrinsic* CreateStoreRawIntrinsic(llvm::StoreInst* inst, llvm::Value* bufPtr, llvm::Value* offsetVal);
158158

159159
void getTextureAndSamplerOperands(llvm::GenIntrinsicInst* pIntr, llvm::Value*& pTextureValue, llvm::Value*& pSamplerValue);
160+
void getTextureAndSamplerOperands(llvm::GenIntrinsicInst* pIntr, llvm::Value*& pPairedTextureValue, llvm::Value*& pTextureValue, llvm::Value*& pSamplerValue);
160161
void ChangePtrTypeInIntrinsic(llvm::GenIntrinsicInst*& pIntr, llvm::Value* oldPtr, llvm::Value* newPtr);
161162

162163
llvm::Value* TracePointerSource(llvm::Value* resourcePtr);

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,12 @@ void IGC::CustomSafeOptPass::visitLdptr(llvm::SamplerLoadIntrinsic* inst)
18091809
return;
18101810
}
18111811

1812+
// Sampler feedback (GenISA_evaluateSampler) supports GenISA_ldptr and not GenISA_typedread
1813+
llvm::Value* pairedTexture = inst->getPairedTextureValue();
1814+
if (pairedTexture != nullptr && !isa<UndefValue>(pairedTexture))
1815+
{
1816+
return;
1817+
}
18121818
// change
18131819
// % 10 = call fast <4 x float> @llvm.genx.GenISA.ldptr.v4f32.p196608v4f32(i32 %_s1.i, i32 %_s14.i, i32 0, i32 0, <4 x float> addrspace(196608)* null, i32 0, i32 0, i32 0), !dbg !123
18141820
// to
@@ -1944,6 +1950,7 @@ void IGC::CustomSafeOptPass::visitSampleBptr(llvm::SampleIntrinsic* sampleInst)
19441950
llvm::SmallVector<llvm::Type*, 4> overloadedTys;
19451951
overloadedTys.push_back(sampleInst->getCalledFunction()->getReturnType());
19461952
overloadedTys.push_back(sampleInst->getOperand(0)->getType());
1953+
overloadedTys.push_back(sampleInst->getPairedTextureValue()->getType());
19471954
overloadedTys.push_back(sampleInst->getTextureValue()->getType());
19481955
overloadedTys.push_back(sampleInst->getSamplerValue()->getType());
19491956

IGC/Compiler/LegalizationPass.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,20 +2273,31 @@ void Legalization::PromoteFp16ToFp32OnGenSampleCall(llvm::CallInst& I)
22732273

22742274
llvm::SmallVector<Type*, 5> types;
22752275

2276+
llvm::Value* pairedTexture = nullptr;
22762277
llvm::Value* texture = nullptr;
22772278
llvm::Value* sampler = nullptr;
22782279

22792280
if (SampleIntrinsic * inst = llvm::dyn_cast<SampleIntrinsic>(&I))
22802281
{
2282+
pairedTexture = inst->getPairedTextureValue();
22812283
texture = inst->getTextureValue();
22822284
sampler = inst->getSamplerValue();
22832285
}
22842286
else if (SamplerGatherIntrinsic * inst = llvm::dyn_cast<SamplerGatherIntrinsic>(&I))
22852287
{
2288+
pairedTexture = inst->getPairedTextureValue();
22862289
texture = inst->getTextureValue();
22872290
sampler = inst->getSamplerValue();
22882291
}
2289-
if (texture && texture->getType()->isPointerTy())
2292+
if (pairedTexture && pairedTexture->getType()->isPointerTy() &&
2293+
texture && texture->getType()->isPointerTy())
2294+
{
2295+
types.resize(5);
2296+
types[2] = pairedTexture->getType();
2297+
types[3] = texture->getType();
2298+
types[4] = sampler->getType();
2299+
}
2300+
else if (texture && texture->getType()->isPointerTy())
22902301
{
22912302
types.resize(4);
22922303
types[2] = texture->getType();

0 commit comments

Comments
 (0)