Enhance ResidencyData to work with multiple OsContext

- Add new method updateCompletionData to register completion fence and context
- remove obsolete methods and fields
- for trimming choose default 0 OsContext

Change-Id: I0f6c7af9499a454a70ad1c5b0fa2766416eba297
This commit is contained in:
Mrozek, Michal
2018-09-07 07:18:38 +02:00
committed by sys_ocldev
parent b11e7b961a
commit ac2a2de3be
6 changed files with 115 additions and 107 deletions

View File

@@ -1,4 +1,3 @@
#include "residency.h"
/*
* Copyright (c) 2017 - 2018, Intel Corporation
*
@@ -26,9 +25,19 @@
using namespace OCLRT;
void ResidencyData::addOsContext(OsContext *osContext) {
if (!this->osContext) {
this->osContext = osContext;
void ResidencyData::updateCompletionData(uint64_t newFenceValue, OsContext *context) {
auto contextId = context->getContextId();
if (contextId + 1 > completionData.size()) {
completionData.resize(contextId + 1);
}
DEBUG_BREAK_IF(this->osContext != osContext);
completionData[contextId].lastFence = newFenceValue;
completionData[contextId].osContext = context;
}
uint64_t ResidencyData::getFenceValueForContextId(uint32_t contextId) {
return completionData[contextId].lastFence;
}
OsContext *ResidencyData::getOsContextFromId(uint32_t contextId) {
return completionData[contextId].osContext;
}

View File

@@ -22,15 +22,25 @@
#pragma once
#include <cinttypes>
#include <vector>
namespace OCLRT {
class OsContext;
struct ResidencyData {
ResidencyData() = default;
void addOsContext(OsContext *osContext);
~ResidencyData() = default;
bool resident = false;
struct FenceData {
uint64_t lastFence = 0;
OsContext *osContext = nullptr;
};
struct ResidencyData {
ResidencyData() = default;
~ResidencyData() = default;
bool resident = false;
void updateCompletionData(uint64_t newFenceValue, OsContext *context);
uint64_t getFenceValueForContextId(uint32_t contextId);
OsContext *getOsContextFromId(uint32_t contextId);
protected:
std::vector<FenceData> completionData;
};
} // namespace OCLRT

View File

@@ -346,10 +346,6 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
unlockResource(input);
input->setLocked(false);
}
OsContextWin *osContextWin = nullptr;
if (input->getResidencyData().osContext) {
osContextWin = input->getResidencyData().osContext->get();
}
auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle);
DEBUG_BREAK_IF(!status);
alignedFreeWrapper(cpuPtr);
@@ -410,23 +406,14 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
D3DKMT_HANDLE handles[max_fragments_count] = {0};
auto allocationCount = 0;
uint64_t lastFenceValue = 0;
OsContext *osContext = nullptr;
for (unsigned int i = 0; i < max_fragments_count; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) {
handles[allocationCount] = handleStorage.fragmentStorageData[i].osHandleStorage->handle;
handleStorage.fragmentStorageData[i].residency->resident = false;
allocationCount++;
lastFenceValue = std::max(handleStorage.fragmentStorageData[i].residency->lastFence, lastFenceValue);
osContext = handleStorage.fragmentStorageData[i].residency->osContext;
}
}
OsContextWin *osContextWin = nullptr;
if (osContext) {
osContextWin = osContext->get();
}
bool success = tryDeferDeletions(handles, allocationCount, 0);
for (unsigned int i = 0; i < max_fragments_count; i++) {
@@ -543,16 +530,15 @@ bool WddmMemoryManager::makeResidentResidencyAllocations(ResidencyContainer *all
for (uint32_t i = 0; i < residencyCount; i++) {
WddmAllocation *allocation = reinterpret_cast<WddmAllocation *>(residencyAllocations[i]);
// Update fence value not to early destroy / evict allocation
allocation->getResidencyData().addOsContext(&osContext);
allocation->getResidencyData().lastFence = osContext.get()->getMonitoredFence().currentFenceValue;
auto currentFence = osContext.get()->getMonitoredFence().currentFenceValue;
allocation->getResidencyData().updateCompletionData(currentFence, &osContext);
allocation->getResidencyData().resident = true;
for (uint32_t allocationId = 0; allocationId < allocation->fragmentsStorage.fragmentCount; allocationId++) {
auto residencyData = allocation->fragmentsStorage.fragmentStorageData[allocationId].residency;
residencyData->addOsContext(&osContext);
residencyData->resident = allocation->getResidencyData().resident;
// Update fence value not to remove the fragment referenced by different GA in trimming callback
residencyData->lastFence = allocation->getResidencyData().lastFence;
residencyData->updateCompletionData(currentFence, &osContext);
residencyData->resident = true;
}
}
}
@@ -684,21 +670,21 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", lastPeriodicTrimFenceValue);
// allocation was not used from last periodic trim
if (wddmAllocation->getResidencyData().lastFence <= lastPeriodicTrimFenceValue) {
if (wddmAllocation->getResidencyData().getFenceValueForContextId(0) <= lastPeriodicTrimFenceValue) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().lastFence);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().getFenceValueForContextId(0));
uint32_t fragmentsToEvict = 0;
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().lastFence);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().getFenceValueForContextId(0));
wddm->evict(&wddmAllocation->handle, 1, sizeToTrim);
}
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->lastFence <= lastPeriodicTrimFenceValue) {
if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(0) <= lastPeriodicTrimFenceValue) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict fragment: handle =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle, "lastFence =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->lastFence);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict fragment: handle =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle, "lastFence =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(0));
fragmentEvictHandles[fragmentsToEvict++] = wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle;
wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->resident = false;
@@ -710,7 +696,7 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
}
wddmAllocation->getResidencyData().resident = false;
osContext = wddmAllocation->getResidencyData().osContext;
osContext = wddmAllocation->getResidencyData().getOsContextFromId(0);
removeFromTrimCandidateList(wddmAllocation);
} else {
periodicTrimDone = true;
@@ -778,8 +764,8 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) {
break;
}
lastFence = wddmAllocation->getResidencyData().lastFence;
auto osContext = wddmAllocation->getResidencyData().osContext;
lastFence = wddmAllocation->getResidencyData().getFenceValueForContextId(0);
auto osContext = wddmAllocation->getResidencyData().getOsContextFromId(0);
if (!osContext) {
removeFromTrimCandidateList(wddmAllocation);
continue;
@@ -802,7 +788,7 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) {
} else {
auto &fragmentStorageData = wddmAllocation->fragmentsStorage.fragmentStorageData;
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
if (fragmentStorageData[allocationId].residency->lastFence <= monitoredFence.lastSubmittedFence) {
if (fragmentStorageData[allocationId].residency->getFenceValueForContextId(0) <= monitoredFence.lastSubmittedFence) {
fragmentEvictHandles[fragmentsToEvict++] = fragmentStorageData[allocationId].osHandleStorage->handle;
}
}
@@ -811,7 +797,7 @@ bool WddmMemoryManager::trimResidencyToBudget(uint64_t bytes) {
wddm->evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim);
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
if (fragmentStorageData[allocationId].residency->lastFence <= monitoredFence.lastSubmittedFence) {
if (fragmentStorageData[allocationId].residency->getFenceValueForContextId(0) <= monitoredFence.lastSubmittedFence) {
fragmentStorageData[allocationId].residency->resident = false;
sizeEvicted += fragmentStorageData[allocationId].fragmentSize;
}

View File

@@ -1810,13 +1810,40 @@ TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCo
EXPECT_EQ(1, osContext->getRefInternalCount());
}
TEST(ResidencyDataTest, givenOsContextWhenItIsAddedToResidencyThenItCantBeOverwritten) {
ResidencyData residency;
TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) {
struct mockResidencyData : public ResidencyData {
using ResidencyData::completionData;
};
mockResidencyData residency;
OsContext osContext(nullptr);
OsContext osContext2(nullptr);
EXPECT_EQ(nullptr, residency.osContext);
residency.addOsContext(&osContext);
EXPECT_EQ(&osContext, residency.osContext);
residency.addOsContext(&osContext2);
EXPECT_EQ(&osContext, residency.osContext);
osContext2.setContextId(1u);
auto lastFenceValue = 45llu;
auto lastFenceValue2 = 23llu;
auto lastFenceValue3 = 373llu;
EXPECT_EQ(0u, residency.completionData.size());
residency.updateCompletionData(lastFenceValue, &osContext);
EXPECT_EQ(1u, residency.completionData.size());
EXPECT_EQ(&osContext, residency.completionData[0].osContext);
EXPECT_EQ(lastFenceValue, residency.completionData[0].lastFence);
EXPECT_EQ(lastFenceValue, residency.getFenceValueForContextId(osContext.getContextId()));
EXPECT_EQ(&osContext, residency.getOsContextFromId(0u));
residency.updateCompletionData(lastFenceValue2, &osContext2);
EXPECT_EQ(2u, residency.completionData.size());
EXPECT_EQ(&osContext2, residency.completionData[1].osContext);
EXPECT_EQ(lastFenceValue2, residency.completionData[1].lastFence);
EXPECT_EQ(lastFenceValue2, residency.getFenceValueForContextId(osContext2.getContextId()));
EXPECT_EQ(&osContext2, residency.getOsContextFromId(1u));
residency.updateCompletionData(lastFenceValue3, &osContext2);
EXPECT_EQ(lastFenceValue3, residency.completionData[1].lastFence);
EXPECT_EQ(lastFenceValue3, residency.getFenceValueForContextId(osContext2.getContextId()));
EXPECT_EQ(&osContext2, residency.getOsContextFromId(1u));
}

View File

@@ -642,7 +642,7 @@ TEST_F(Wddm20Tests, makeNonResidentCallsEvict) {
TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedToDestroyAllocation) {
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull);
allocation.getResidencyData().lastFence = 10;
allocation.getResidencyData().updateCompletionData(10, osContext.get());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getMonitoredFence().cpuAddress = 10;
@@ -670,7 +670,7 @@ TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedTo
TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) {
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull);
allocation.getResidencyData().lastFence = 10;
allocation.getResidencyData().updateCompletionData(10, osContext.get());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getMonitoredFence().cpuAddress = 10;
@@ -693,7 +693,7 @@ TEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalle
TEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) {
WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull);
allocation.getResidencyData().lastFence = 10;
allocation.getResidencyData().updateCompletionData(10, osContext.get());
allocation.handle = ALLOCATION_HANDLE;
*osContextWin->getMonitoredFence().cpuAddress = 10;

View File

@@ -1068,10 +1068,10 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdatesLa
memoryManager->makeResidentResidencyAllocations(nullptr, *osContext);
EXPECT_EQ(20u, allocation1.getResidencyData().lastFence);
EXPECT_EQ(20u, allocation2.getResidencyData().lastFence);
EXPECT_EQ(20u, allocation3.getResidencyData().lastFence);
EXPECT_EQ(20u, allocation4.getResidencyData().lastFence);
EXPECT_EQ(20u, allocation1.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
EXPECT_EQ(20u, allocation2.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
EXPECT_EQ(20u, allocation3.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
EXPECT_EQ(20u, allocation4.getResidencyData().getFenceValueForContextId(osContext->getContextId()));
}
TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTripleAllocationsResident) {
@@ -1109,7 +1109,7 @@ TEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastF
memoryManager->makeResidentResidencyAllocations(nullptr, *osContext);
for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) {
EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->lastFence);
EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->getFenceValueForContextId(0));
}
memoryManager->freeGraphicsMemory(allocationTriple);
@@ -1129,8 +1129,9 @@ TEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeriod
// allocations have fence value == 0 by default
MockWddmAllocation allocation1, allocation2;
allocation1.getResidencyData().addOsContext(osContext);
allocation2.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().updateCompletionData(0, osContext);
allocation1.getResidencyData().resident = true;
allocation2.getResidencyData().resident = true;
@@ -1166,12 +1167,10 @@ TEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPeriodi
MockWddmAllocation allocation1, allocation2;
allocation1.getResidencyData().resident = true;
// mark allocation used from last periodic trim
allocation2.getResidencyData().lastFence = 11;
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().updateCompletionData(11, osContext);
allocation2.getResidencyData().resident = true;
allocation1.getResidencyData().addOsContext(osContext);
allocation2.getResidencyData().addOsContext(osContext);
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
// Set current fence value to greater value
@@ -1205,22 +1204,18 @@ TEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFra
// 3-fragment Allocation
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
// whole allocation unused since previous trim
allocationTriple->getResidencyData().lastFence = 0;
allocationTriple->getResidencyData().addOsContext(osContext);
allocationTriple->getResidencyData().updateCompletionData(0, osContext);
EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount);
allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->lastFence = 0;
allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->updateCompletionData(0, osContext);
allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true;
allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->addOsContext(osContext);
// this fragment was used
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->lastFence = 11;
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident = true;
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->addOsContext(osContext);
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(11, osContext);
allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident = true;
allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->lastFence = 0;
allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->updateCompletionData(0, osContext);
allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true;
allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->addOsContext(osContext);
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
@@ -1292,16 +1287,13 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) {
MockWddmAllocation allocation1, allocation2, allocation3;
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().lastFence = 1;
allocation2.getResidencyData().updateCompletionData(1, osContext);
allocation2.getResidencyData().resident = true;
allocation2.getResidencyData().addOsContext(osContext);
allocation3.getResidencyData().lastFence = 2;
allocation3.getResidencyData().updateCompletionData(2, osContext);
allocation3.getResidencyData().resident = true;
allocation3.getResidencyData().addOsContext(osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 1;
@@ -1334,8 +1326,7 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToTri
MockWddmAllocation allocation1;
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 1;
@@ -1359,16 +1350,13 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesToTr
allocation3(reinterpret_cast<void *>(0x1000), 0x1000, reinterpret_cast<void *>(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().lastFence = 1;
allocation2.getResidencyData().updateCompletionData(1, osContext);
allocation2.getResidencyData().resident = true;
allocation2.getResidencyData().addOsContext(osContext);
allocation3.getResidencyData().lastFence = 2;
allocation3.getResidencyData().updateCompletionData(2, osContext);
allocation3.getResidencyData().resident = true;
allocation3.getResidencyData().addOsContext(osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 1;
@@ -1399,16 +1387,13 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonResi
MockWddmAllocation allocation1, allocation2, allocation3;
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().lastFence = 1;
allocation2.getResidencyData().updateCompletionData(1, osContext);
allocation2.getResidencyData().resident = true;
allocation2.getResidencyData().addOsContext(osContext);
allocation3.getResidencyData().lastFence = 2;
allocation3.getResidencyData().updateCompletionData(2, osContext);
allocation3.getResidencyData().resident = true;
allocation3.getResidencyData().addOsContext(osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 1;
@@ -1435,8 +1420,7 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIsGr
MockWddmAllocation allocation1;
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 2;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(2, osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 2;
@@ -1466,30 +1450,26 @@ TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) {
WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().lastFence = 1;
allocation2.getResidencyData().updateCompletionData(1, osContext);
allocation2.getResidencyData().resident = true;
allocation2.getResidencyData().addOsContext(osContext);
void *ptrTriple = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + 0x500);
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(8196, ptrTriple));
allocationTriple->getResidencyData().lastFence = 1;
allocationTriple->getResidencyData().updateCompletionData(1, osContext);
allocationTriple->getResidencyData().resident = true;
allocationTriple->getResidencyData().addOsContext(osContext);
EXPECT_EQ(3u, allocationTriple->fragmentsStorage.fragmentCount);
for (uint32_t i = 0; i < 3; i++) {
allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->lastFence = 1;
allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->updateCompletionData(1, osContext);
allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident = true;
allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->addOsContext(osContext);
}
// This should not be evicted
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->lastFence = 2;
allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->updateCompletionData(2, osContext);
memoryManager->trimCandidateList.resize(0);
@@ -1555,16 +1535,13 @@ TEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerTha
WddmAllocation allocation3(ptr3, underlyingSize, ptr3, alignedSize, nullptr, MemoryPool::MemoryNull);
allocation1.getResidencyData().resident = true;
allocation1.getResidencyData().lastFence = 0;
allocation1.getResidencyData().addOsContext(osContext);
allocation1.getResidencyData().updateCompletionData(0, osContext);
allocation2.getResidencyData().lastFence = 1;
allocation2.getResidencyData().updateCompletionData(1, osContext);
allocation2.getResidencyData().resident = true;
allocation2.getResidencyData().addOsContext(osContext);
allocation3.getResidencyData().lastFence = 1;
allocation3.getResidencyData().updateCompletionData(1, osContext);
allocation3.getResidencyData().resident = true;
allocation3.getResidencyData().addOsContext(osContext);
*osContext->get()->getMonitoredFence().cpuAddress = 1;
osContext->get()->getMonitoredFence().lastSubmittedFence = 1;
@@ -1866,8 +1843,7 @@ TEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeR
size_t allocationSize = 0x1000;
WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr, MemoryPool::MemoryNull);
allocationToTrim.getResidencyData().lastFence = osContext->get()->getMonitoredFence().lastSubmittedFence;
allocationToTrim.getResidencyData().addOsContext(osContext);
allocationToTrim.getResidencyData().updateCompletionData(osContext->get()->getMonitoredFence().lastSubmittedFence, osContext);
auto makeResidentWithOutBytesToTrim = [allocationSize](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = allocationSize; return false; };