From 5367440fab12a622e9759384e79f6ccee748aefe Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 18 Mar 2019 10:06:01 +0100 Subject: [PATCH] Refactor Wddm map gpu address method Change-Id: I9d3d8675bf80af4079e25b84ba6e09b7883c9e28 Signed-off-by: Mateusz Jablonski --- runtime/memory_manager/gfx_partition.h | 3 + runtime/memory_manager/memory_constants.h | 1 + runtime/memory_manager/memory_manager.cpp | 6 +- runtime/memory_manager/memory_manager.h | 2 +- runtime/os_interface/windows/wddm/wddm.cpp | 52 +++------------ runtime/os_interface/windows/wddm/wddm.h | 3 +- .../windows/wddm_memory_manager.cpp | 16 +++-- .../windows/wddm_memory_manager.h | 3 - .../memory_manager/gfx_partition_tests.cpp | 3 +- .../memory_manager/memory_manager_tests.cpp | 35 +++------- unit_tests/mock_gdi/mock_gdi.cpp | 4 +- .../mock_gdi/mock_gdi_gfx_partition.cpp | 4 +- unit_tests/mocks/mock_wddm.cpp | 21 ++++-- unit_tests/mocks/mock_wddm.h | 4 +- .../os_interface/windows/wddm20_tests.cpp | 64 +++++-------------- .../windows/wddm_kmdaf_listener_tests.cpp | 5 +- .../windows/wddm_memory_manager_tests.cpp | 38 ++++++----- .../wddm_residency_controller_tests.cpp | 4 +- 18 files changed, 105 insertions(+), 163 deletions(-) diff --git a/runtime/memory_manager/gfx_partition.h b/runtime/memory_manager/gfx_partition.h index 6f62480e17..2eee9595f5 100644 --- a/runtime/memory_manager/gfx_partition.h +++ b/runtime/memory_manager/gfx_partition.h @@ -49,6 +49,9 @@ class GfxPartition { uint64_t getHeapBase(HeapIndex heapIndex) { return getHeap(heapIndex).getBase(); } + uint64_t getHeapLimit(HeapIndex heapIndex) { + return getHeap(heapIndex).getBase() + getHeap(heapIndex).getSize() - 1; + } static const std::array heap32Names; diff --git a/runtime/memory_manager/memory_constants.h b/runtime/memory_manager/memory_constants.h index 9a4f067fbb..dfd7ed911e 100644 --- a/runtime/memory_manager/memory_constants.h +++ b/runtime/memory_manager/memory_constants.h @@ -43,4 +43,5 @@ static const uint64_t max48BitAddress = maxNBitValue<48>; static const uintptr_t page4kEntryMask = std::numeric_limits::max() & ~MemoryConstants::pageMask; static const uintptr_t page64kEntryMask = std::numeric_limits::max() & ~MemoryConstants::page64kMask; static const int GfxAddressBits = is64bit ? 48 : 32; +static const uint64_t maxSvmAddress = is64bit ? maxNBitValue<47> : maxNBitValue<32>; } // namespace MemoryConstants diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 138b708336..cfe2ce44ea 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -393,7 +393,7 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) { graphicsAllocation->unlock(); } -HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, const void *ptr, const HardwareInfo &hwInfo) { +HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM) { if (allocation) { if (useInternal32BitAllocator(allocation->getAllocationType())) { return internalHeapIndex; @@ -401,8 +401,8 @@ HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, const return HeapIndex::HEAP_EXTERNAL; } } - if (hwInfo.capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) { - if (ptr) { + if (isFullRangeSVM) { + if (hasPointer) { return HeapIndex::HEAP_SVM; } if (allocation && allocation->getDefaultGmm()->gmmResourceInfo->is64KBPageSuitable()) { diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index bbd907badf..f711612ae7 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -183,7 +183,7 @@ class MemoryManager { HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); } void setDefaultEngineIndex(uint32_t index) { defaultEngineIndex = index; } virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const; - static HeapIndex selectHeap(const GraphicsAllocation *allocation, const void *ptr, const HardwareInfo &hwInfo); + static HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM); static std::unique_ptr createMemoryManager(bool enable64KBpages, bool enableLocalMemory, ExecutionEnvironment &exeEnv); virtual void *reserveCpuAddressRange(size_t size) = 0; virtual void releaseReservedCpuAddressRange(void *reserved, size_t size) = 0; diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index de602e0c0b..a95c1d10d4 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -288,20 +288,14 @@ bool Wddm::makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantT return success; } -bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *requiredGpuPtr) { - return mapGpuVirtualAddressImpl(allocation->getDefaultGmm(), allocation->getDefaultHandle(), requiredGpuPtr, allocation->getGpuAddressToModify(), - MemoryManager::selectHeap(allocation, requiredGpuPtr, *hardwareInfoTable[gfxPlatform->eProductFamily])); -} - bool Wddm::mapGpuVirtualAddress(AllocationStorageData *allocationStorageData) { - return mapGpuVirtualAddressImpl(allocationStorageData->osHandleStorage->gmm, - allocationStorageData->osHandleStorage->handle, - const_cast(allocationStorageData->cpuPtr), - allocationStorageData->osHandleStorage->gpuPtr, - MemoryManager::selectHeap(nullptr, allocationStorageData->cpuPtr, *hardwareInfoTable[gfxPlatform->eProductFamily])); + return mapGpuVirtualAddress(allocationStorageData->osHandleStorage->gmm, + allocationStorageData->osHandleStorage->handle, + 0u, MemoryConstants::maxSvmAddress, reinterpret_cast(allocationStorageData->cpuPtr), + allocationStorageData->osHandleStorage->gpuPtr); } -bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex) { +bool Wddm::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) { D3DDDI_MAPGPUVIRTUALADDRESS MapGPUVA = {0}; D3DDDIGPUVIRTUALADDRESS_PROTECTION_TYPE protectionType = {{{0}}}; protectionType.Write = TRUE; @@ -314,35 +308,9 @@ bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr MapGPUVA.SizeInPages = size / MemoryConstants::pageSize; MapGPUVA.OffsetInPages = 0; - auto productFamily = gfxPlatform->eProductFamily; - UNRECOVERABLE_IF(!hardwareInfoTable[productFamily]); - - MapGPUVA.BaseAddress = 0; - MapGPUVA.MinimumAddress = 0; - switch (heapIndex) { - case HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY: - case HeapIndex::HEAP_INTERNAL: - case HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY: - case HeapIndex::HEAP_EXTERNAL: - MapGPUVA.MinimumAddress = gfxPartition.Heap32[static_cast(heapIndex)].Base + MemoryConstants::pageSize; - MapGPUVA.MaximumAddress = gfxPartition.Heap32[static_cast(heapIndex)].Limit; - break; - case HeapIndex::HEAP_STANDARD: - MapGPUVA.MinimumAddress = gfxPartition.Standard.Base; - MapGPUVA.MaximumAddress = gfxPartition.Standard.Limit; - break; - case HeapIndex::HEAP_STANDARD64KB: - UNRECOVERABLE_IF(hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress); - MapGPUVA.MinimumAddress = gfxPartition.Standard64KB.Base; - MapGPUVA.MaximumAddress = gfxPartition.Standard64KB.Limit; - break; - case HeapIndex::HEAP_SVM: - UNRECOVERABLE_IF(hardwareInfoTable[productFamily]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress); - UNRECOVERABLE_IF(!cpuPtr); - MapGPUVA.BaseAddress = reinterpret_cast(cpuPtr); - MapGPUVA.MaximumAddress = is64bit ? maxNBitValue<47> : maxNBitValue<32>; - break; - } + MapGPUVA.BaseAddress = preferredAddress; + MapGPUVA.MinimumAddress = minimumAddress; + MapGPUVA.MaximumAddress = maximumAddress; NTSTATUS status = gdi->mapGpuVirtualAddress(&MapGPUVA); gpuPtr = GmmHelper::canonize(MapGPUVA.VirtualAddress); @@ -801,7 +769,7 @@ void Wddm::initGfxPartition(GfxPartition &outGfxPartition) const { outGfxPartition.heapInit(HeapIndex::HEAP_STANDARD64KB, gfxPartition.Standard64KB.Base, gfxPartition.Standard64KB.Limit - gfxPartition.Standard64KB.Base + 1); for (auto heap : GfxPartition::heap32Names) { - outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast(heap)].Base, + outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast(heap)].Base + MemoryConstants::pageSize, gfxPartition.Heap32[static_cast(heap)].Limit - gfxPartition.Heap32[static_cast(heap)].Base + 1); } } @@ -828,7 +796,7 @@ uint64_t Wddm::getExternalHeapBase() const { } uint64_t Wddm::getExternalHeapSize() const { - return alignDown(gfxPartition.Heap32[static_cast(HeapIndex::HEAP_EXTERNAL)].Limit, MemoryConstants::pageSize); + return alignDown(gfxPartition.Heap32[static_cast(HeapIndex::HEAP_EXTERNAL)].Limit - gfxPartition.Heap32[static_cast(HeapIndex::HEAP_EXTERNAL)].Base, MemoryConstants::pageSize); } VOID *Wddm::registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmResidencyController &residencyController) { diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index a15fa27c36..2e464bb812 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -58,7 +58,7 @@ class Wddm { MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim); MOCKABLE_VIRTUAL bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim); - bool mapGpuVirtualAddress(WddmAllocation *allocation, void *requiredGpuPtr); + MOCKABLE_VIRTUAL bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr); bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData); D3DGPU_VIRTUAL_ADDRESS reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_SIZE_T size); MOCKABLE_VIRTUAL bool createContext(OsContextWin &osContext); @@ -184,7 +184,6 @@ class Wddm { uintptr_t minAddress = 0; Wddm(); - MOCKABLE_VIRTUAL bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex); MOCKABLE_VIRTUAL bool openAdapter(); MOCKABLE_VIRTUAL bool waitOnGPU(D3DKMT_HANDLE context); bool createDevice(PreemptionMode preemptionMode); diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 71444fdbf0..b23fb84c63 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -198,7 +198,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All gmm = new Gmm(ptrAligned, sizeAligned, false); wddmAllocation->setDefaultGmm(gmm); - if (!createWddmAllocation(wddmAllocation.get(), wddmAllocation->getAlignedCpuPtr())) { + if (!createWddmAllocation(wddmAllocation.get(), nullptr)) { delete gmm; freeSystemMemory(pSysMem); return nullptr; @@ -513,10 +513,18 @@ bool WddmMemoryManager::mapGpuVirtualAddressWithRetry(WddmAllocation *graphicsAl } return numMappedAllocations == graphicsAllocation->getNumHandles(); } + uint32_t WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *preferredGpuVirtualAddress, uint32_t startingIndex) { - auto numMappedAllocations = 0; - for (auto i = startingIndex; i < graphicsAllocation->getNumHandles(); i++) { - if (!wddm->mapGpuVirtualAddress(graphicsAllocation, const_cast(preferredGpuVirtualAddress))) { + auto numMappedAllocations = 0u; + auto heapIndex = selectHeap(graphicsAllocation, preferredGpuVirtualAddress != nullptr, executionEnvironment.isFullRangeSvm()); + if (!executionEnvironment.isFullRangeSvm()) { + preferredGpuVirtualAddress = nullptr; + } + for (auto handleId = startingIndex; handleId < graphicsAllocation->getNumHandles(); handleId++) { + + if (!wddm->mapGpuVirtualAddress(graphicsAllocation->getGmm(handleId), graphicsAllocation->getHandles()[handleId], + gfxPartition.getHeapBase(heapIndex), gfxPartition.getHeapLimit(heapIndex), + reinterpret_cast(preferredGpuVirtualAddress), graphicsAllocation->getGpuAddressToModify())) { return numMappedAllocations; } numMappedAllocations++; diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index e4ff575f4c..8341b11929 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -48,9 +48,6 @@ class WddmMemoryManager : public MemoryManager { void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage); - static const D3DGPU_VIRTUAL_ADDRESS minimumAddress = static_cast(0x0); - static const D3DGPU_VIRTUAL_ADDRESS maximumAddress = static_cast((sizeof(size_t) == 8) ? 0x7ffffffffff : (D3DGPU_VIRTUAL_ADDRESS)0xffffffff); - uint64_t getSystemSharedMemory() override; uint64_t getMaxApplicationAddress() override; uint64_t getInternalHeapBaseAddress() override; diff --git a/unit_tests/memory_manager/gfx_partition_tests.cpp b/unit_tests/memory_manager/gfx_partition_tests.cpp index 62f2a0398f..c4fa4d30da 100644 --- a/unit_tests/memory_manager/gfx_partition_tests.cpp +++ b/unit_tests/memory_manager/gfx_partition_tests.cpp @@ -18,7 +18,7 @@ void testGfxPartition(uint64_t gpuAddressSpace) { gfxPartition.init(gpuAddressSpace); uint64_t gfxTop = gpuAddressSpace + 1; - uint64_t gfxBase = is64bit ? MemoryConstants::max64BitAppAddress + 1 : MemoryConstants::max32BitAddress + 1; + uint64_t gfxBase = MemoryConstants::maxSvmAddress + 1; const uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte; const uint64_t gfxGranularity = 2 * MemoryConstants::megaByte; @@ -27,6 +27,7 @@ void testGfxPartition(uint64_t gpuAddressSpace) { EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), gfxGranularity); EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), gfxBase - gfxGranularity); + EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress); } else { // Limited range EXPECT_FALSE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 2ff966d063..37141c8b67 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1656,35 +1656,29 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenAllocationWasNotUnlockedThenItIsUn TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.set32BitAllocation(true); - EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, false, false)); } TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.set32BitAllocation(false); - EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, false, false)); } TEST(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) { GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; allocation.set32BitAllocation(true); - EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, false, false)); } TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenStandardHeapIsUsed) { GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; - if (platformDevices[0]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) { - return; - } - EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, true, false)); } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) { GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false}; - if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { - return; - } - EXPECT_EQ(HeapIndex::HEAP_SVM, MemoryManager::selectHeap(&allocation, &allocation, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_SVM, MemoryManager::selectHeap(&allocation, true, true)); } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) { @@ -1693,10 +1687,7 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); resourceInfo->is64KBPageSuitableValue = true; allocation.setDefaultGmm(gmm.get()); - if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { - return; - } - EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_STANDARD64KB, MemoryManager::selectHeap(&allocation, false, true)); } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) { @@ -1705,23 +1696,15 @@ TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocati auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); resourceInfo->is64KBPageSuitableValue = false; allocation.setDefaultGmm(gmm.get()); - if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { - return; - } - EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, false, true)); } TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) { - if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { - return; - } - EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, nullptr, *platformDevices[0])); + EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, true)); } TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) { - auto hwInfo = *platformDevices[0]; - hwInfo.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress; - EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, nullptr, hwInfo)); + EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, false, false)); } TEST(MemoryAllocationTest, givenAllocationTypeWhenPassedToMemoryAllocationConstructorThenAllocationTypeIsStored) { diff --git a/unit_tests/mock_gdi/mock_gdi.cpp b/unit_tests/mock_gdi/mock_gdi.cpp index d506b54a61..f0eba925bc 100644 --- a/unit_tests/mock_gdi/mock_gdi.cpp +++ b/unit_tests/mock_gdi/mock_gdi.cpp @@ -19,7 +19,6 @@ uint64_t gGpuAddressSpace = 0ull; #ifdef __cplusplus // If used by C++ code, extern "C" { // we need to export the C interface #endif - BOOLEAN WINAPI DllMain(IN HINSTANCE hDllHandle, IN DWORD nReason, IN LPVOID Reserved) { @@ -194,7 +193,6 @@ NTSTATUS __stdcall D3DKMTDestroyAllocation2(IN CONST D3DKMT_DESTROYALLOCATION2 * } NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS *mapGpuVA) { - uint64_t maxSvmAddress = sizeof(size_t) == 8 ? 0x7fffffffffff : 0xffffffff; if (mapGpuVA == nullptr) { memset(&gLastCallMapGpuVaArg, 0, sizeof(gLastCallMapGpuVaArg)); return STATUS_INVALID_PARAMETER; @@ -225,7 +223,7 @@ NTSTATUS __stdcall D3DKMTMapGpuVirtualAddress(IN OUT D3DDDI_MAPGPUVIRTUALADDRESS mapGpuVA->VirtualAddress = MemoryConstants::pageSize64k; } } else { - if (maxSvmAddress != mapGpuVA->MaximumAddress) { + if (MemoryConstants::maxSvmAddress != mapGpuVA->MaximumAddress) { return STATUS_INVALID_PARAMETER; } mapGpuVA->VirtualAddress = mapGpuVA->BaseAddress; diff --git a/unit_tests/mock_gdi/mock_gdi_gfx_partition.cpp b/unit_tests/mock_gdi/mock_gdi_gfx_partition.cpp index e06525df4c..f1e3676eb0 100644 --- a/unit_tests/mock_gdi/mock_gdi_gfx_partition.cpp +++ b/unit_tests/mock_gdi/mock_gdi_gfx_partition.cpp @@ -5,6 +5,8 @@ * */ +#include "runtime/memory_manager/memory_constants.h" + #include "mock_gdi.h" extern ADAPTER_INFO gAdapterInfo; @@ -15,7 +17,7 @@ void InitGfxPartition() { gAdapterInfo.GfxPartition.Standard64KB.Base = 0x0000b80200000000; gAdapterInfo.GfxPartition.Standard64KB.Limit = 0x0000efffffffffff; gAdapterInfo.GfxPartition.SVM.Base = 0; - gAdapterInfo.GfxPartition.SVM.Limit = 0x00007fffffffffff; + gAdapterInfo.GfxPartition.SVM.Limit = MemoryConstants::maxSvmAddress; gAdapterInfo.GfxPartition.Heap32[0].Base = 0x0000800000000000; gAdapterInfo.GfxPartition.Heap32[0].Limit = 0x00008000ffffefff; gAdapterInfo.GfxPartition.Heap32[1].Base = 0x0000800100000000; diff --git a/unit_tests/mocks/mock_wddm.cpp b/unit_tests/mocks/mock_wddm.cpp index 47cf920ade..83b141b5e4 100644 --- a/unit_tests/mocks/mock_wddm.cpp +++ b/unit_tests/mocks/mock_wddm.cpp @@ -34,14 +34,23 @@ bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeT makeNonResidentResult.called++; return makeNonResidentResult.success = Wddm::evict(handles, num, sizeToTrim); } - -bool WddmMock::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, HeapIndex heapIndex) { +bool WddmMock::mapGpuVirtualAddress(WddmAllocation *allocation) { + D3DGPU_VIRTUAL_ADDRESS minimumAddress = gfxPartition.Standard.Base; + D3DGPU_VIRTUAL_ADDRESS maximumAddress = gfxPartition.Standard.Limit; + if (allocation->getAlignedCpuPtr()) { + minimumAddress = 0u; + maximumAddress = MemoryConstants::maxSvmAddress; + } + return mapGpuVirtualAddress(allocation->getDefaultGmm(), allocation->getDefaultHandle(), minimumAddress, maximumAddress, + reinterpret_cast(allocation->getAlignedCpuPtr()), allocation->getGpuAddressToModify()); +} +bool WddmMock::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) { mapGpuVirtualAddressResult.called++; - mapGpuVirtualAddressResult.cpuPtrPassed = cpuPtr; + mapGpuVirtualAddressResult.cpuPtrPassed = reinterpret_cast(preferredAddress); if (callBaseMapGpuVa) { - return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, gpuPtr, heapIndex); + return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddress(gmm, handle, minimumAddress, maximumAddress, preferredAddress, gpuPtr); } else { - gpuPtr = reinterpret_cast(cpuPtr); + gpuPtr = preferredAddress; return mapGpuVaStatus; } } @@ -186,7 +195,7 @@ bool WddmMock::openAdapter() { void WddmMock::setHeap32(uint64_t base, uint64_t size) { gfxPartition.Heap32[3].Base = base; - gfxPartition.Heap32[3].Limit = size; + gfxPartition.Heap32[3].Limit = base + size; } GMM_GFX_PARTITIONING *WddmMock::getGfxPartitionPtr() { diff --git a/unit_tests/mocks/mock_wddm.h b/unit_tests/mocks/mock_wddm.h index f5dd895bb2..8dcd4bbf09 100644 --- a/unit_tests/mocks/mock_wddm.h +++ b/unit_tests/mocks/mock_wddm.h @@ -52,6 +52,7 @@ class WddmMock : public Wddm { using Wddm::gdi; using Wddm::getSystemInfo; using Wddm::gmmMemory; + using Wddm::mapGpuVirtualAddress; using Wddm::pagingFenceAddress; using Wddm::pagingQueue; using Wddm::temporaryResources; @@ -63,7 +64,8 @@ class WddmMock : public Wddm { bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) override; 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 mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) override; + bool mapGpuVirtualAddress(WddmAllocation *allocation); bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override; NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override; diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 85dfeb80ab..e69a4c85fd 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -82,7 +82,7 @@ TEST_F(Wddm20Tests, givenNullPageTableManagerAndRenderCompressedResourceWhenMapp allocation.setDefaultGmm(gmm.get()); allocation.getHandleToModify(0u) = ALLOCATION_HANDLE; - EXPECT_TRUE(wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr())); + EXPECT_TRUE(wddm->mapGpuVirtualAddress(&allocation)); } TEST(Wddm20EnumAdaptersTest, expectTrue) { @@ -205,7 +205,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedSiz EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_NE(0, allocation.getDefaultHandle()); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + bool ret = wddm->mapGpuVirtualAddress(&allocation); EXPECT_TRUE(ret); EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages); @@ -247,59 +247,27 @@ TEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGmmS auto mockResourceInfo = static_cast(gmm->gmmResourceInfo.get()); mockResourceInfo->overrideReturnedSize(allocation.getAlignedSize() + (2 * MemoryConstants::pageSize)); - wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + wddm->mapGpuVirtualAddress(&allocation); uint64_t expectedSizeInPages = static_cast(mockResourceInfo->getSizeAllocation() / MemoryConstants::pageSize); EXPECT_EQ(expectedSizeInPages, getLastCallMapGpuVaArgFcn()->SizeInPages); } -TEST_F(Wddm20Tests, createAllocation32bit) { - uint64_t heap32baseAddress = 0x40000; - uint64_t heap32Size = 0x40000; - wddm->setHeap32(heap32baseAddress, heap32Size); - - MockWddmAllocation allocation; - Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); - - allocation.setDefaultGmm(gmm); - allocation.set32BitAllocation(true); // mark 32 bit allocation - - auto status = wddm->createAllocation(&allocation); - - EXPECT_EQ(STATUS_SUCCESS, status); - EXPECT_TRUE(allocation.handle != 0); - - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); - EXPECT_TRUE(ret); - - EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called); - - EXPECT_LE(heap32baseAddress, allocation.getGpuAddress()); - EXPECT_GT(heap32baseAddress + heap32Size, allocation.getGpuAddress()); - - auto success = wddm->destroyAllocation(&allocation, osContext.get()); - EXPECT_TRUE(success); - - delete gmm; -} - TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddressWithinHeapInternalLimits) { void *alignedPtr = (void *)0x12000; size_t alignedSize = 0x2000; - WddmAllocation allocation(GraphicsAllocation::AllocationType::KERNEL_ISA, alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull, false); + std::unique_ptr gmm(GmmHelperFunctions::getGmm(alignedPtr, alignedSize)); + uint64_t gpuAddress = 0u; + auto heapBase = wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Base; + auto heapLimit = wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Limit; - allocation.getHandleToModify(0u) = ALLOCATION_HANDLE; - allocation.setDefaultGmm(GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize())); - EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, allocation.getAlignedCpuPtr(), *hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily])); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + bool ret = wddm->mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, heapBase, heapLimit, 0u, gpuAddress); EXPECT_TRUE(ret); + auto cannonizedHeapBase = GmmHelper::canonize(heapBase); + auto cannonizedHeapEnd = GmmHelper::canonize(heapLimit); - auto cannonizedHeapBase = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Base); - auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Limit); - - EXPECT_GE(allocation.getGpuAddress(), cannonizedHeapBase); - EXPECT_LE(allocation.getGpuAddress(), cannonizedHeapEnd); - delete allocation.getDefaultGmm(); + EXPECT_GE(gpuAddress, cannonizedHeapBase); + EXPECT_LE(gpuAddress, cannonizedHeapEnd); } TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) { @@ -345,7 +313,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.getDefaultHandle() != 0); - auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + auto error = wddm->mapGpuVirtualAddress(&allocation); EXPECT_TRUE(error); EXPECT_TRUE(allocation.getGpuAddress() != 0); @@ -369,7 +337,7 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { auto status = wddm->createAllocation(&allocation); EXPECT_EQ(STATUS_SUCCESS, status); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + bool ret = wddm->mapGpuVirtualAddress(&allocation); EXPECT_TRUE(ret); EXPECT_NE(0u, allocation.getGpuAddress()); @@ -390,7 +358,7 @@ TEST_F(Wddm20Tests, makeResidentNonResident) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.getDefaultHandle() != 0); - auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr()); + auto error = wddm->mapGpuVirtualAddress(&allocation); EXPECT_TRUE(error); EXPECT_TRUE(allocation.getGpuAddress() != 0); @@ -461,7 +429,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto wddmAllocation = (WddmAllocation *)graphicsAllocation; ASSERT_NE(nullptr, wddmAllocation); - if (is32bit) { + if (is32bit && executionEnvironment->isFullRangeSvm()) { EXPECT_NE(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); } else { EXPECT_EQ(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); 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 afca3ae25d..0edf3fe6ef 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -24,7 +24,7 @@ class WddmWithKmDafMock : public Wddm { public: using Wddm::featureTable; using Wddm::gdi; - using Wddm::mapGpuVirtualAddressImpl; + using Wddm::mapGpuVirtualAddress; WddmWithKmDafMock() : Wddm() { kmDafListener.reset(new KmDafListenerMock); @@ -79,8 +79,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmDaf auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.setDefaultGmm(gmm.get()); - auto heapIndex = MemoryManager::selectHeap(&allocation, allocation.getUnderlyingBuffer(), *platformDevices[0]); - wddmWithKmDafMock->mapGpuVirtualAddressImpl(allocation.getDefaultGmm(), allocation.getDefaultHandle(), allocation.getUnderlyingBuffer(), allocation.getGpuAddressToModify(), heapIndex); + wddmWithKmDafMock->mapGpuVirtualAddress(allocation.getDefaultGmm(), allocation.getDefaultHandle(), wddmWithKmDafMock->getGfxPartition().Standard.Base, wddmWithKmDafMock->getGfxPartition().Standard.Limit, 0u, allocation.getGpuAddressToModify()); EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyMapGpuVAParametrization.ftrKmdDaf); EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyMapGpuVAParametrization.hAdapter); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index cfb39690a0..2275bd7f37 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -819,6 +819,8 @@ TEST_F(WddmMemoryManagerTest, given32BitAllocationWhenItIsCreatedThenItHasNonZer ASSERT_NE(nullptr, gpuAllocation); EXPECT_NE(0llu, gpuAllocation->getGpuAddressToPatch()); + EXPECT_LE(GmmHelper::canonize(wddm->getExternalHeapBase()), gpuAllocation->getGpuAddress()); + EXPECT_GT(GmmHelper::canonize(wddm->getExternalHeapBase()) + wddm->getExternalHeapSize() - 1, gpuAllocation->getGpuAddress()); memoryManager->freeGraphicsMemory(gpuAllocation); } @@ -1173,18 +1175,19 @@ TEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocati struct WddmMemoryManagerWithAsyncDeleterTest : ::testing::Test { void SetUp() { + executionEnvironment = platform()->peekExecutionEnvironment(); wddm = std::make_unique(); wddm->gdi.reset(new MockGdi()); wddm->callBaseDestroyAllocations = false; wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); deleter = new MockDeferredDeleter; - memoryManager = std::make_unique(wddm.get(), executionEnvironment); + memoryManager = std::make_unique(wddm.get(), *executionEnvironment); memoryManager->setDeferredDeleter(deleter); } MockDeferredDeleter *deleter = nullptr; std::unique_ptr wddm; std::unique_ptr memoryManager; - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; }; TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { @@ -1254,19 +1257,19 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele } TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeapInternalBaseIsReturned) { - ExecutionEnvironment executionEnvironment; + auto executionEnvironment = platform()->peekExecutionEnvironment(); auto wddm = std::make_unique(); wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); - MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment); + MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment); auto heapBase = wddm->getGfxPartition().Heap32[static_cast(internalHeapIndex)].Base; EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress()); } TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) { - ExecutionEnvironment executionEnvironment; + auto executionEnvironment = platform()->peekExecutionEnvironment(); auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment); + MockWddmMemoryManager memoryManager(wddm.get(), *executionEnvironment); auto wddmAlloc = static_cast(memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, MemoryConstants::pageSize}, reinterpret_cast(0x1000))); @@ -1313,12 +1316,12 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation } TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) { - ExecutionEnvironment executionEnvironment; + auto executionEnvironment = platform()->peekExecutionEnvironment(); DebugManagerStateRestore dbgRestore; DebugManager.flags.Enable64kbpages.set(true); auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - MockWddmMemoryManager memoryManager64k(wddm.get(), executionEnvironment); + MockWddmMemoryManager memoryManager64k(wddm.get(), *executionEnvironment); uint32_t lockCount = wddm->lockResult.called; uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called; AllocationData allocationData; @@ -1326,7 +1329,11 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemory64kb(allocationData); EXPECT_EQ(lockCount + 1, wddm->lockResult.called); EXPECT_EQ(mapGpuVirtualAddressResult + 1, wddm->mapGpuVirtualAddressResult.called); - EXPECT_NE(wddm->mapGpuVirtualAddressResult.cpuPtrPassed, nullptr); + if (executionEnvironment->isFullRangeSvm()) { + EXPECT_NE(nullptr, wddm->mapGpuVirtualAddressResult.cpuPtrPassed); + } else { + EXPECT_EQ(nullptr, wddm->mapGpuVirtualAddressResult.cpuPtrPassed); + } memoryManager64k.freeGraphicsMemory(galloc); } @@ -1423,7 +1430,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa auto hwInfo = hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily]; ASSERT_NE(nullptr, hwInfo); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, gpuVa, MemoryManager::selectHeap(nullptr, nullptr, *hwInfo)); + auto result = wddm.mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, wddm.getGfxPartition().Standard.Base, wddm.getGfxPartition().Standard.Limit, 0u, gpuVa); ASSERT_TRUE(result); EXPECT_EQ(GmmHelper::canonize(wddm.getGfxPartition().Standard.Base), gpuVa); @@ -1484,8 +1491,7 @@ TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMappedGp EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); - auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily]); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, gpuVa, heapIndex); + auto result = wddm.mapGpuVirtualAddress(gmm.get(), ALLOCATION_HANDLE, wddm.getGfxPartition().Standard.Base, wddm.getGfxPartition().Standard.Limit, 0u, gpuVa); ASSERT_TRUE(result); } @@ -1496,8 +1502,7 @@ TEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRetur WddmMock wddm; EXPECT_TRUE(wddm.init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm.getGfxPlatform()->eProductFamily]); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), 0, nullptr, gpuVa, heapIndex); + auto result = wddm.mapGpuVirtualAddress(gmm.get(), 0, 0, 0, 0, gpuVa); ASSERT_FALSE(result); } @@ -1520,8 +1525,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); - auto heapIndex = MemoryManager::selectHeap(nullptr, nullptr, *hardwareInfoTable[wddm->getGfxPlatform()->eProductFamily]); - auto result = wddm->mapGpuVirtualAddressImpl(myGmm, ALLOCATION_HANDLE, nullptr, gpuVa, heapIndex); + auto result = wddm->mapGpuVirtualAddress(myGmm, ALLOCATION_HANDLE, wddm->getGfxPartition().Standard.Base, wddm->getGfxPartition().Standard.Limit, 0u, gpuVa); EXPECT_TRUE(result); memoryManager.freeGraphicsMemory(wddmAlloc); } @@ -1568,7 +1572,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC } TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) { - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment &executionEnvironment = *platform()->peekExecutionEnvironment(); auto csr = createCommandStream(*platformDevices, executionEnvironment); auto wddm = new WddmMock(); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index 2579408b30..4ee981861d 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -118,7 +118,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { gdi = new MockGdi(); wddm->gdi.reset(gdi); - executionEnvironment = std::make_unique(); + executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); @@ -135,7 +135,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { osContext->decRefInternal(); } - std::unique_ptr executionEnvironment; + ExecutionEnvironment *executionEnvironment; std::unique_ptr memoryManager; WddmMock *wddm = nullptr;