fix: Move evict after unlock to wddm layer

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2025-05-27 07:41:23 +00:00 committed by Compute-Runtime-Automation
parent 0306b77297
commit a0f683e42b
8 changed files with 18 additions and 16 deletions

View File

@ -979,13 +979,18 @@ void *Wddm::lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPrio
return lock2.pData;
}
void Wddm::unlockResource(const D3DKMT_HANDLE &handle) {
void Wddm::unlockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock) {
D3DKMT_UNLOCK2 unlock2 = {};
unlock2.hAllocation = handle;
unlock2.hDevice = this->device;
NTSTATUS status = getGdi()->unlock2(&unlock2);
if (applyMakeResidentPriorToLock) {
this->temporaryResources->evictResource(handle);
}
if (status != STATUS_SUCCESS) {
return;
}

View File

@ -82,7 +82,7 @@ class Wddm : public DriverModel {
MOCKABLE_VIRTUAL bool verifyNTHandle(HANDLE handle);
bool openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc);
MOCKABLE_VIRTUAL void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size);
MOCKABLE_VIRTUAL void unlockResource(const D3DKMT_HANDLE &handle);
MOCKABLE_VIRTUAL void unlockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock);
MOCKABLE_VIRTUAL void kmDafLock(D3DKMT_HANDLE handle);
MOCKABLE_VIRTUAL bool isKmDafEnabled() const;

View File

@ -689,11 +689,7 @@ void *WddmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation
}
void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation) {
auto &wddmAllocation = static_cast<WddmAllocation &>(graphicsAllocation);
getWddm(graphicsAllocation.getRootDeviceIndex()).unlockResource(wddmAllocation.getDefaultHandle());
if (wddmAllocation.needsMakeResidentBeforeLock()) {
[[maybe_unused]] auto evictionStatus = getWddm(graphicsAllocation.getRootDeviceIndex()).getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle());
DEBUG_BREAK_IF(evictionStatus == MemoryOperationsStatus::failed);
}
getWddm(graphicsAllocation.getRootDeviceIndex()).unlockResource(wddmAllocation.getDefaultHandle(), wddmAllocation.needsMakeResidentBeforeLock());
}
void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) {
auto &wddmAllocation = static_cast<WddmAllocation &>(graphicsAllocation);
@ -1243,7 +1239,7 @@ bool WddmMemoryManager::copyMemoryToAllocationBanks(GraphicsAllocation *graphics
return false;
}
memcpy_s(ptrOffset(ptr, destinationOffset), graphicsAllocation->getUnderlyingBufferSize() - destinationOffset, memoryToCopy, sizeToCopy);
wddm.unlockResource(wddmAllocation->getHandles()[handleId]);
wddm.unlockResource(wddmAllocation->getHandles()[handleId], wddmAllocation->needsMakeResidentBeforeLock());
}
wddmAllocation->setExplicitlyMadeResident(wddmAllocation->needsMakeResidentBeforeLock());
return true;

View File

@ -226,10 +226,10 @@ void *WddmMock::lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResident
return ptr;
}
void WddmMock::unlockResource(const D3DKMT_HANDLE &handle) {
void WddmMock::unlockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock) {
unlockResult.called++;
unlockResult.success = true;
Wddm::unlockResource(handle);
Wddm::unlockResource(handle, applyMakeResidentPriorToLock);
}
void WddmMock::kmDafLock(D3DKMT_HANDLE handle) {

View File

@ -94,7 +94,7 @@ class WddmMock : public Wddm {
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments) override;
bool waitOnGPU(D3DKMT_HANDLE context) override;
void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size) override;
void unlockResource(const D3DKMT_HANDLE &handle) override;
void unlockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock) override;
void kmDafLock(D3DKMT_HANDLE handle) override;
bool isKmDafEnabled() const override;
void setKmDafEnabled(bool state);

View File

@ -1136,7 +1136,7 @@ TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatDoesntNeedMakeResidentB
wddm->lockResource(ALLOCATION_HANDLE, false, 0x1000);
EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty());
EXPECT_EQ(0u, wddm->makeResidentResult.called);
wddm->unlockResource(ALLOCATION_HANDLE);
wddm->unlockResource(ALLOCATION_HANDLE, false);
}
TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatNeedsMakeResidentBeforeLockWhenLockThenCallBlockingMakeResident) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -93,7 +93,7 @@ TEST_F(WddmKmDafListenerTest, givenInvalidAllocationWhenLockResourceFailsThenKmD
}
TEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafListenerNotifyUnlockIsFedWithCorrectParams) {
wddmWithKmDafMock->unlockResource(ALLOCATION_HANDLE);
wddmWithKmDafMock->unlockResource(ALLOCATION_HANDLE, false);
EXPECT_EQ(wddmWithKmDafMock->featureTable->flags.ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.hAdapter);
@ -103,7 +103,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafListen
EXPECT_EQ(wddmWithKmDafMock->getGdi()->escape.mFunc, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.pfnEscape);
}
TEST_F(WddmKmDafListenerTest, givenInvalidAllocationWhenUnlockResourceIsCalledThenKmDafListenerIsNotNotified) {
wddmWithKmDafMock->unlockResource(0);
wddmWithKmDafMock->unlockResource(0, false);
EXPECT_FALSE(wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.ftrKmdDaf);
EXPECT_EQ(0u, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.hAdapter);

View File

@ -1454,10 +1454,11 @@ TEST_F(WddmMemoryManagerSimpleTest, givenLocalMemoryKernelIsaWithMemoryCopiedWhe
memoryManager->freeGraphicsMemory(allocation);
if (makeResidentPriorToLockRequired) {
EXPECT_EQ(1u, mockTemporaryResources->removeResourceResult.called);
EXPECT_EQ(1u, mockTemporaryResources->evictResourceResult.called);
} else {
EXPECT_EQ(0u, mockTemporaryResources->removeResourceResult.called);
EXPECT_EQ(0u, mockTemporaryResources->evictResourceResult.called);
}
EXPECT_EQ(0u, mockTemporaryResources->evictResourceResult.called);
}
TEST_F(WddmMemoryManagerSimpleTest, whenDestroyingNotLockedAllocationThatDoesntNeedMakeResidentBeforeLockThenDontEvictAllocationFromWddmTemporaryResources) {
DebugManagerStateRestore restorer;