diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index d5980f9b0c..6fdaab6a86 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -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; } diff --git a/shared/source/os_interface/windows/wddm/wddm.h b/shared/source/os_interface/windows/wddm/wddm.h index 42381e74ca..b947565ed9 100644 --- a/shared/source/os_interface/windows/wddm/wddm.h +++ b/shared/source/os_interface/windows/wddm/wddm.h @@ -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; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index ab103907a0..aa761c3fa6 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -689,11 +689,7 @@ void *WddmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation } void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation) { auto &wddmAllocation = static_cast(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(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; diff --git a/shared/test/common/mocks/mock_wddm.cpp b/shared/test/common/mocks/mock_wddm.cpp index 7e89991826..d6ff588bdb 100644 --- a/shared/test/common/mocks/mock_wddm.cpp +++ b/shared/test/common/mocks/mock_wddm.cpp @@ -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) { diff --git a/shared/test/common/mocks/mock_wddm.h b/shared/test/common/mocks/mock_wddm.h index 2c26bbbf23..826a82d5b1 100644 --- a/shared/test/common/mocks/mock_wddm.h +++ b/shared/test/common/mocks/mock_wddm.h @@ -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); diff --git a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp index 26cd2e144c..13d10ae7a4 100644 --- a/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -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) { diff --git a/shared/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp index f46200d1fd..32ca12c57c 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -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); diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 8b943dc225..fa77bd3f71 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -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;