Skip to content

Commit ac157e7

Browse files
pguo-igcgfxbot
authored andcommitted
Refactoring push analysis pass, change PushInfo gather metadata
from. map to vector so that we can re-arrange the order of gather constants if. required. Resubmit bc2991ae after fixing functional regression. Change-Id: I8bc935e9228f1bb3f8ba864438636d32cadab363
1 parent 1cf4892 commit ac157e7

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void CShader::AllocateConstants(uint& offset)
409409
{
410410
m_ConstantBufferLength = 0;
411411
for (auto I = pushInfo.constants.begin(), E = pushInfo.constants.end(); I != E; I++) {
412-
CVariable* var = GetSymbol(m_argListCache[I->second]);
412+
CVariable* var = GetSymbol(m_argListCache[I->argIndex]);
413413
AllocateInput(var, offset + m_ConstantBufferLength);
414414
m_ConstantBufferLength += var->GetSize();
415415
}
@@ -453,7 +453,7 @@ void CShader::CreateGatherMap()
453453
gatherMap.reserve(pushInfo.constants.size());
454454
for(auto I = pushInfo.constants.begin(), E = pushInfo.constants.end();I!=E;I++)
455455
{
456-
unsigned int address = (I->first.bufId * 256 * 4) + (I->first.eltId);
456+
unsigned int address = (I->bufId * 256 * 4) + (I->eltId);
457457
unsigned int cstOffset = address / 4;
458458
unsigned int cstChannel = address % 4;
459459
if(cstOffset!=index)

IGC/Compiler/CISACodeGen/PushAnalysis.cpp

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ bool PushAnalysis::CanPushConstants()
519519
{
520520
return false;
521521
}
522-
523522

524523
switch(m_context->type)
525524
{
@@ -796,6 +795,40 @@ PushConstantMode PushAnalysis::GetPushConstantMode()
796795
return pushConstantMode;
797796
}
798797

798+
// if multiple entries fall into cb[].xyzw, we need to insert in order
799+
static void insertGatherEntry(std::vector<ConstantAddress>& constants,
800+
ConstantAddress& address)
801+
{
802+
bool hasSameSlot = false;
803+
bool inserted = false;
804+
805+
for (unsigned i = 0; i < constants.size(); i++)
806+
{
807+
if (constants[i].eltId / 4 == address.eltId / 4)
808+
{
809+
hasSameSlot = true;
810+
if (constants[i].eltId > address.eltId)
811+
{
812+
constants.insert(constants.begin() + i, address);
813+
inserted = true;
814+
break;
815+
}
816+
}
817+
else
818+
if (hasSameSlot)
819+
{
820+
constants.insert(constants.begin() + i, address);
821+
inserted = true;
822+
break;
823+
}
824+
}
825+
826+
if (!inserted)
827+
{
828+
constants.push_back(address);
829+
}
830+
}
831+
799832
// process gather constants, update PushInfo.constants
800833
void PushAnalysis::processGather(Instruction* inst, uint bufId, uint eltId)
801834
{
@@ -838,7 +871,8 @@ void PushAnalysis::processGather(Instruction* inst, uint bufId, uint eltId)
838871
address.bufId = bufId;
839872
address.eltId = eltId + i;
840873

841-
auto it = pushInfo.constants.find(address);
874+
auto it = std::find(pushInfo.constants.begin(),
875+
pushInfo.constants.end(), address);
842876
if (it != pushInfo.constants.end() ||
843877
(pushInfo.constantReg.size() + pushInfo.constants.size() < m_pullConstantHeuristics->getPushConstantThreshold(m_pFunction) * 8))
844878
{
@@ -861,13 +895,14 @@ void PushAnalysis::processGather(Instruction* inst, uint bufId, uint eltId)
861895
if (pTypeToPush != value->getType())
862896
value = CastInst::CreateZExtOrBitCast(value, pTypeToPush, "", inst);
863897

864-
pushInfo.constants[address] = m_argIndex;
898+
address.argIndex = m_argIndex;
899+
insertGatherEntry(pushInfo.constants, address);
865900
}
866901
else
867902
{
868-
assert((it->second <= m_argIndex) &&
903+
assert((it->argIndex <= m_argIndex) &&
869904
"Function arguments list and metadata are out of sync!");
870-
value = m_argList[it->second];
905+
value = m_argList[it->argIndex];
871906
if (pTypeToPush != value->getType())
872907
value = CastInst::CreateZExtOrBitCast(value, pTypeToPush, "", inst);
873908
}

IGC/common/MDFrameWork.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ namespace IGC
6565

6666
return false;
6767
}
68+
69+
bool operator == (const ConstantAddress &a, const ConstantAddress &b)
70+
{
71+
if (a.bufId == b.bufId && a.eltId == b.eltId)
72+
return true;
73+
74+
return false;
75+
}
6876
}
6977

7078
// non-autogen functions implementations below

IGC/common/MDFrameWork.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ namespace IGC
143143
std::map<unsigned int, int> simplePushLoads;
144144
};
145145

146-
struct ConstantAddress
147-
{
148-
unsigned int bufId = 0;
149-
unsigned int eltId = 0;
146+
struct ConstantAddress
147+
{
148+
unsigned int bufId = 0;
149+
unsigned int eltId = 0;
150150
int size = 0;
151-
};
151+
int argIndex = 0;
152+
};
152153

153-
bool operator < (const ConstantAddress &a, const ConstantAddress &b);
154+
bool operator < (const ConstantAddress &a, const ConstantAddress &b);
155+
bool operator == (const ConstantAddress &a, const ConstantAddress &b);
154156

155157
struct StatelessPushInfo
156158
{
@@ -168,7 +170,7 @@ namespace IGC
168170
unsigned int inlineConstantBufferSlot = INVALID_CONSTANT_BUFFER_INVALID_ADDR; // slot of the inlined constant buffer
169171
unsigned int inlineConstantBufferOffset = INVALID_CONSTANT_BUFFER_INVALID_ADDR; // offset of the inlined constant buffer
170172

171-
std::map<ConstantAddress, int> constants;
173+
std::vector<ConstantAddress> constants;
172174
std::map<unsigned int, SInputDesc> inputs;
173175
std::map<unsigned int, int> constantReg;
174176
std::array<SimplePushInfo, g_c_maxNumberOfBufferPushed> simplePushInfoArr;

0 commit comments

Comments
 (0)