Dont unlock/evict wddm allocations during releasing memory

Change-Id: Ib934867886a883a22fde2f0c03e16338dc215e65
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-03-11 10:19:02 +01:00
parent 4386d10e40
commit 3f690e1758
9 changed files with 30 additions and 4 deletions

View File

@ -134,7 +134,7 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) {
return;
}
if (gfxAllocation->isLocked()) {
unlockResource(gfxAllocation);
freeAssociatedResourceImpl(*gfxAllocation);
}
freeGraphicsMemoryImpl(gfxAllocation);
}

View File

@ -263,6 +263,7 @@ class MemoryManager {
virtual void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;
virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0;
virtual void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { return unlockResourceImpl(graphicsAllocation); };
bool force32bitAllocations = false;
bool virtualPaddingAvailable = false;

View File

@ -1002,7 +1002,15 @@ void Wddm::applyBlockingMakeResident(const D3DKMT_HANDLE &handle) {
while (currentPagingFenceValue > *getPagingFenceAddress())
;
}
void Wddm::removeTemporaryResource(const D3DKMT_HANDLE &handle) {
auto lock = acquireLock(temporaryResourcesLock);
auto position = std::find(temporaryResources.begin(), temporaryResources.end(), handle);
if (position == temporaryResources.end()) {
return;
}
*position = temporaryResources.back();
temporaryResources.pop_back();
}
std::unique_lock<SpinLock> Wddm::acquireLock(SpinLock &lock) {
return std::unique_lock<SpinLock>{lock};
}

View File

@ -150,6 +150,7 @@ class Wddm {
MOCKABLE_VIRTUAL EvictionStatus evictTemporaryResource(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL void applyBlockingMakeResident(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock);
MOCKABLE_VIRTUAL void removeTemporaryResource(const D3DKMT_HANDLE &handle);
protected:
bool initialized = false;

View File

@ -286,6 +286,14 @@ void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocatio
DEBUG_BREAK_IF(evictionStatus == EvictionStatus::FAILED);
}
}
void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) {
auto &wddmAllocation = static_cast<WddmAllocation &>(graphicsAllocation);
if (wddmAllocation.needsMakeResidentBeforeLock) {
for (auto i = 0u; i < wddmAllocation.getNumHandles(); i++) {
wddm->removeTemporaryResource(wddmAllocation.getHandles()[i]);
}
}
}
void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) {
WddmAllocation *input = static_cast<WddmAllocation *>(gfxAllocation);

View File

@ -70,6 +70,7 @@ class WddmMemoryManager : public MemoryManager {
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) override;
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;

View File

@ -254,6 +254,11 @@ void WddmMock::applyBlockingMakeResident(const D3DKMT_HANDLE &handle) {
return Wddm::applyBlockingMakeResident(handle);
}
void WddmMock::removeTemporaryResource(const D3DKMT_HANDLE &handle) {
removeTemporaryResourceResult.called++;
return Wddm::removeTemporaryResource(handle);
}
std::unique_lock<SpinLock> WddmMock::acquireLock(SpinLock &lock) {
acquireLockResult.called++;
acquireLockResult.uint64ParamPassed = reinterpret_cast<uint64_t>(&lock);

View File

@ -93,6 +93,7 @@ class WddmMock : public Wddm {
EvictionStatus evictAllTemporaryResources() override;
EvictionStatus evictTemporaryResource(const D3DKMT_HANDLE &handle) override;
void applyBlockingMakeResident(const D3DKMT_HANDLE &handle) override;
void removeTemporaryResource(const D3DKMT_HANDLE &handle) override;
std::unique_lock<SpinLock> acquireLock(SpinLock &lock) override;
bool reserveValidAddressRange(size_t size, void *&reservedMem);
GmmMemory *getGmmMemory() const;
@ -131,6 +132,7 @@ class WddmMock : public Wddm {
WddmMockHelpers::EvictCallResult evictAllTemporaryResourcesResult;
WddmMockHelpers::EvictCallResult evictTemporaryResourceResult;
WddmMockHelpers::CallResult applyBlockingMakeResidentResult;
WddmMockHelpers::CallResult removeTemporaryResourceResult;
WddmMockHelpers::CallResult acquireLockResult;
WddmMockHelpers::CallResult registerTrimCallbackResult;
WddmMockHelpers::CallResult getPagingFenceAddressResult;

View File

@ -1524,12 +1524,12 @@ TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatDoesntN
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(0u, wddm->evictTemporaryResourceResult.called);
}
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingLockedAllocationThatNeedsMakeResidentBeforeLockThenEvictAllocationFromWddmTemporaryResources) {
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingLockedAllocationThatNeedsMakeResidentBeforeLockThenRemoveTemporaryResource) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
allocation->needsMakeResidentBeforeLock = true;
memoryManager->lockResource(allocation);
memoryManager->freeGraphicsMemory(allocation);
EXPECT_EQ(1u, wddm->evictTemporaryResourceResult.called);
EXPECT_EQ(1u, wddm->removeTemporaryResourceResult.called);
}
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatNeedsMakeResidentBeforeLockThenDontEvictAllocationFromWddmTemporaryResources) {
auto allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));