Minor refactoring related to residency task count

Change-Id: I49c9a5b37637e19fa12b7e6d91c352fb78bb117a
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-12-18 13:02:08 +00:00
committed by sys_ocldev
parent 068582445d
commit b138ff5750
4 changed files with 27 additions and 5 deletions

View File

@ -63,11 +63,10 @@ CommandStreamReceiver::~CommandStreamReceiver() {
void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) {
auto submissionTaskCount = this->taskCount + 1;
bool isNotResident = !gfxAllocation.isResident(osContext->getContextId());
if (isNotResident || gfxAllocation.getResidencyTaskCount(osContext->getContextId()) < submissionTaskCount) {
if (gfxAllocation.isResidencyTaskCountBelow(submissionTaskCount, osContext->getContextId())) {
this->getResidencyAllocations().push_back(&gfxAllocation);
gfxAllocation.updateTaskCount(submissionTaskCount, osContext->getContextId());
if (isNotResident) {
if (!gfxAllocation.isResident(osContext->getContextId())) {
this->totalMemoryUsed += gfxAllocation.getUnderlyingBufferSize();
}
}

View File

@ -34,7 +34,7 @@ FlushStamp CommandStreamReceiverWithAUBDump<BaseCSR>::flush(BatchBuffer &batchBu
template <typename BaseCSR>
void CommandStreamReceiverWithAUBDump<BaseCSR>::makeNonResident(GraphicsAllocation &gfxAllocation) {
uint32_t residencyTaskCount = gfxAllocation.getResidencyTaskCount(this->osContext->getContextId());
auto residencyTaskCount = gfxAllocation.getResidencyTaskCount(this->osContext->getContextId());
BaseCSR::makeNonResident(gfxAllocation);
gfxAllocation.updateResidencyTaskCount(residencyTaskCount, this->osContext->getContextId());
if (aubCSR) {

View File

@ -131,6 +131,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
void updateResidencyTaskCount(uint32_t newTaskCount, uint32_t contextId) { usageInfos[contextId].residencyTaskCount = newTaskCount; }
uint32_t getResidencyTaskCount(uint32_t contextId) const { return usageInfos[contextId].residencyTaskCount; }
void resetResidencyTaskCount(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
protected:
constexpr static uint32_t objectNotResident = (uint32_t)-1;

View File

@ -84,9 +84,31 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenUpdatedResidencyTaskCoun
TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenResetResidencyTaskCountThenAllocationIsNotResident) {
MockGraphicsAllocation graphicsAllocation;
graphicsAllocation.updateResidencyTaskCount(1, 0u);
graphicsAllocation.updateResidencyTaskCount(1u, 0u);
EXPECT_TRUE(graphicsAllocation.isResident(0u));
graphicsAllocation.resetResidencyTaskCount(0u);
EXPECT_FALSE(graphicsAllocation.isResident(0u));
}
TEST(GraphicsAllocationTest, givenNonResidentGraphicsAllocationWhenCheckIfResidencyTaskCountIsBelowAnyValueThenReturnTrue) {
MockGraphicsAllocation graphicsAllocation;
EXPECT_FALSE(graphicsAllocation.isResident(0u));
EXPECT_TRUE(graphicsAllocation.isResidencyTaskCountBelow(0u, 0u));
}
TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenCheckIfResidencyTaskCountIsBelowCurrentResidencyTaskCountThenReturnFalse) {
MockGraphicsAllocation graphicsAllocation;
auto currentResidencyTaskCount = 1u;
graphicsAllocation.updateResidencyTaskCount(currentResidencyTaskCount, 0u);
EXPECT_TRUE(graphicsAllocation.isResident(0u));
EXPECT_FALSE(graphicsAllocation.isResidencyTaskCountBelow(currentResidencyTaskCount, 0u));
}
TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenCheckIfResidencyTaskCountIsBelowHigherThanCurrentResidencyTaskCountThenReturnTrue) {
MockGraphicsAllocation graphicsAllocation;
auto currentResidencyTaskCount = 1u;
graphicsAllocation.updateResidencyTaskCount(currentResidencyTaskCount, 0u);
EXPECT_TRUE(graphicsAllocation.isResident(0u));
EXPECT_TRUE(graphicsAllocation.isResidencyTaskCountBelow(currentResidencyTaskCount + 1u, 0u));
}