From 4605a48170808b4457f456ad99e257048c6d0fab Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 5 Mar 2019 15:00:45 +0100 Subject: [PATCH] Cleanup Wddm interface 2/n don't pass the entire WddmAllocation to createAllocation methods Change-Id: Ibd4c684a362edbe3b2c520b73b71246fed5a9399 Signed-off-by: Mateusz Jablonski --- runtime/os_interface/windows/wddm/wddm.cpp | 26 ++++++++----------- runtime/os_interface/windows/wddm/wddm.h | 4 +-- .../windows/wddm_memory_manager.cpp | 6 ++--- unit_tests/mocks/mock_wddm.cpp | 23 +++++++++++----- unit_tests/mocks/mock_wddm.h | 7 +++-- .../windows/wddm_kmdaf_listener_tests.cpp | 4 +-- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index e57c2c47ff..64f7344968 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -402,20 +402,16 @@ bool Wddm::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) return status == STATUS_SUCCESS; } -NTSTATUS Wddm::createAllocation(WddmAllocation *alloc) { +NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle) { NTSTATUS status = STATUS_UNSUCCESSFUL; D3DDDI_ALLOCATIONINFO AllocationInfo = {0}; D3DKMT_CREATEALLOCATION CreateAllocation = {0}; - size_t size; - if (alloc == nullptr) - return false; - size = alloc->getAlignedSize(); - if (size == 0) + if (gmm == nullptr) return false; - AllocationInfo.pSystemMem = alloc->getAlignedCpuPtr(); - AllocationInfo.pPrivateDriverData = alloc->gmm->gmmResourceInfo->peekHandle(); + AllocationInfo.pSystemMem = alignedCpuPtr; + AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); AllocationInfo.PrivateDriverDataSize = static_cast(sizeof(GMM_RESOURCE_INFO)); AllocationInfo.Flags.Primary = 0; @@ -429,7 +425,7 @@ NTSTATUS Wddm::createAllocation(WddmAllocation *alloc) { CreateAllocation.Flags.NonSecure = FALSE; CreateAllocation.Flags.CreateShared = FALSE; CreateAllocation.Flags.RestrictSharedAccess = FALSE; - CreateAllocation.Flags.CreateResource = alloc->getAlignedCpuPtr() == 0 ? TRUE : FALSE; + CreateAllocation.Flags.CreateResource = alignedCpuPtr ? TRUE : FALSE; CreateAllocation.pAllocationInfo = &AllocationInfo; CreateAllocation.hDevice = device; @@ -439,19 +435,19 @@ NTSTATUS Wddm::createAllocation(WddmAllocation *alloc) { return status; } - alloc->handle = AllocationInfo.hAllocation; - kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, alloc->handle, gdi->escape); + outHandle = AllocationInfo.hAllocation; + kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, outHandle, gdi->escape); return status; } -bool Wddm::createAllocation64k(WddmAllocation *alloc) { +bool Wddm::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { NTSTATUS status = STATUS_SUCCESS; D3DDDI_ALLOCATIONINFO AllocationInfo = {0}; D3DKMT_CREATEALLOCATION CreateAllocation = {0}; AllocationInfo.pSystemMem = 0; - AllocationInfo.pPrivateDriverData = alloc->gmm->gmmResourceInfo->peekHandle(); + AllocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); AllocationInfo.PrivateDriverDataSize = static_cast(sizeof(GMM_RESOURCE_INFO)); AllocationInfo.Flags.Primary = 0; @@ -469,9 +465,9 @@ bool Wddm::createAllocation64k(WddmAllocation *alloc) { return false; } - alloc->handle = AllocationInfo.hAllocation; + outHandle = AllocationInfo.hAllocation; - kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, alloc->handle, gdi->escape); + kmDafListener->notifyWriteTarget(featureTable->ftrKmdDaf, adapter, device, outHandle, gdi->escape); return true; } diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index fcec759e91..4ccb7d2636 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -63,8 +63,8 @@ class Wddm { MOCKABLE_VIRTUAL bool createContext(OsContextWin &osContext); MOCKABLE_VIRTUAL void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext); MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); - MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc); - MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc); + MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle); + MOCKABLE_VIRTUAL bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle); MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles); MOCKABLE_VIRTUAL bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle); MOCKABLE_VIRTUAL bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc); diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 36eec2f05d..091a4fb348 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -67,7 +67,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(const Allocati auto gmm = new Gmm(nullptr, sizeAligned, false, allocationData.flags.preferRenderCompressed, true, {}); wddmAllocation->gmm = gmm; - if (!wddm->createAllocation64k(wddmAllocation.get())) { + if (!wddm->createAllocation64k(gmm, wddmAllocation->handle)) { delete gmm; return nullptr; } @@ -459,10 +459,10 @@ AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() { } bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation) { - auto wddmSuccess = wddm->createAllocation(allocation); + auto wddmSuccess = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->gmm, allocation->handle); if (wddmSuccess == STATUS_GRAPHICS_NO_VIDEO_MEMORY && deferredDeleter) { deferredDeleter->drain(true); - wddmSuccess = wddm->createAllocation(allocation); + wddmSuccess = wddm->createAllocation(allocation->getAlignedCpuPtr(), allocation->gmm, allocation->handle); } if (wddmSuccess == STATUS_SUCCESS) { diff --git a/unit_tests/mocks/mock_wddm.cpp b/unit_tests/mocks/mock_wddm.cpp index 1513c48406..e46c8ec802 100644 --- a/unit_tests/mocks/mock_wddm.cpp +++ b/unit_tests/mocks/mock_wddm.cpp @@ -50,23 +50,34 @@ bool WddmMock::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t si freeGpuVirtualAddressResult.called++; return freeGpuVirtualAddressResult.success = Wddm::freeGpuVirtualAddress(gpuPtr, size); } - -NTSTATUS WddmMock::createAllocation(WddmAllocation *alloc) { +NTSTATUS WddmMock::createAllocation(WddmAllocation *wddmAllocation) { + if (wddmAllocation) { + return createAllocation(wddmAllocation->getAlignedCpuPtr(), wddmAllocation->gmm, wddmAllocation->handle); + } + return false; +} +NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle) { createAllocationResult.called++; if (callBaseDestroyAllocations) { - createAllocationStatus = Wddm::createAllocation(alloc); + createAllocationStatus = Wddm::createAllocation(alignedCpuPtr, gmm, outHandle); createAllocationResult.success = createAllocationStatus == STATUS_SUCCESS; } else { createAllocationResult.success = true; - alloc->handle = ALLOCATION_HANDLE; + outHandle = ALLOCATION_HANDLE; return createAllocationStatus; } return createAllocationStatus; } -bool WddmMock::createAllocation64k(WddmAllocation *alloc) { +bool WddmMock::createAllocation64k(WddmAllocation *wddmAllocation) { + if (wddmAllocation) { + return createAllocation64k(wddmAllocation->gmm, wddmAllocation->handle); + } + return false; +} +bool WddmMock::createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) { createAllocationResult.called++; - return createAllocationResult.success = Wddm::createAllocation64k(alloc); + return createAllocationResult.success = Wddm::createAllocation64k(gmm, outHandle); } bool WddmMock::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) { diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index 94e0cbf114..55aab2ce09 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -62,9 +62,12 @@ class WddmMock : public Wddm { bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override; bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex) override; bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override; - NTSTATUS createAllocation(WddmAllocation *alloc) override; - bool createAllocation64k(WddmAllocation *alloc) override; + NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; + bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) override; + + NTSTATUS createAllocation(WddmAllocation *wddmAllocation); + bool createAllocation64k(WddmAllocation *wddmAllocation); bool destroyAllocation(WddmAllocation *alloc, OsContextWin *osContext); bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) override; bool createContext(OsContextWin &osContext) override; diff --git a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 961c94f791..dcad0e2a1d 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -142,7 +142,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafList auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); - wddmWithKmDafMock->createAllocation(&allocation); + wddmWithKmDafMock->createAllocation(allocation.getAlignedCpuPtr(), gmm.get(), allocation.handle); EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.ftrKmdDaf); EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.hAdapter); @@ -156,7 +156,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDafLi auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); - wddmWithKmDafMock->createAllocation64k(&allocation); + wddmWithKmDafMock->createAllocation64k(gmm.get(), allocation.handle); EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.ftrKmdDaf); EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.hAdapter);