diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 3fc363a87c..5a4445af51 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -152,6 +152,10 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(size_t size, const voi return graphicsAllocation; } +GraphicsAllocation *MemoryManager::createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) { + return allocate32BitGraphicsMemory(allocationSize, const_cast(ptr), MemoryType::INTERNAL_ALLOCATION); +} + void MemoryManager::cleanGraphicsMemoryCreatedFromHostPtr(GraphicsAllocation *graphicsAllocation) { hostPtrManager.releaseHandleStorage(graphicsAllocation->fragmentsStorage); cleanOsHandles(graphicsAllocation->fragmentsStorage); diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index ed7940349f..bc188079c0 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -56,6 +56,11 @@ enum allocationType { REUSABLE_ALLOCATION }; +enum MemoryType { + EXTERNAL_ALLOCATION, + INTERNAL_ALLOCATION +}; + struct AlignedMallocRestrictions { uintptr_t minAddress; }; @@ -97,7 +102,7 @@ class MemoryManager { } virtual GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin); - virtual GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) = 0; + virtual GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) = 0; virtual GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) = 0; @@ -111,6 +116,8 @@ class MemoryManager { virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) = 0; + virtual GraphicsAllocation *createInternalGraphicsAllocation(const void *ptr, size_t allocationSize); + virtual bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) { return false; }; virtual void *lockResource(GraphicsAllocation *graphicsAllocation) = 0; @@ -172,7 +179,7 @@ class MemoryManager { GraphicsAllocation *createGraphicsAllocationWithRequiredBitness(size_t size, void *ptr, bool forcePin) { if (force32bitAllocations && is64bit) { - return allocate32BitGraphicsMemory(size, ptr); + return allocate32BitGraphicsMemory(size, ptr, MemoryType::EXTERNAL_ALLOCATION); } else { if (ptr) { return allocateGraphicsMemory(size, ptr, forcePin); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 0203ae1296..500e514e1f 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -69,7 +69,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(size_t s return allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false); } -GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr) { +GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) { if (ptr) { auto allocationSize = alignSizeWholePage(reinterpret_cast(ptr), size); auto gpuVirtualAddress = allocator32Bit->allocate(allocationSize); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index f10f29eded..474e28b5db 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -63,7 +63,7 @@ class OsAgnosticMemoryManager : public MemoryManager { ~OsAgnosticMemoryManager() override; GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) override; - GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) override; + GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; } GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index c0575eb344..94921282d4 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -246,7 +246,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo & return allocation; } -DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr) { +DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) { if (ptr) { uintptr_t inputPtr = (uintptr_t)ptr; auto allocationSize = alignSizeWholePage((void *)ptr, size); diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index 0864502c1e..2b94fa9689 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -52,7 +52,7 @@ class DrmMemoryManager : public MemoryManager { } DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) override; GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; - DrmAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) override; + DrmAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override; GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; } diff --git a/runtime/os_interface/windows/wddm.cpp b/runtime/os_interface/windows/wddm.cpp index eecfd1282a..c4c24d609f 100644 --- a/runtime/os_interface/windows/wddm.cpp +++ b/runtime/os_interface/windows/wddm.cpp @@ -329,9 +329,9 @@ bool Wddm::makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFur return success; } -bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages) { +bool Wddm::mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages, bool useHeap1) { void *mapPtr = allocation->getReservedAddress() != nullptr ? allocation->getReservedAddress() : cpuPtr; - return mapGpuVirtualAddressImpl(allocation->gmm, allocation->handle, mapPtr, size, allocation->gpuPtr, allocation32bit, use64kbPages); + return mapGpuVirtualAddressImpl(allocation->gmm, allocation->handle, mapPtr, size, allocation->gpuPtr, allocation32bit, use64kbPages, useHeap1); } bool Wddm::mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages) { @@ -340,10 +340,10 @@ bool Wddm::mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bo const_cast(allocationStorageData->cpuPtr), allocationStorageData->fragmentSize, allocationStorageData->osHandleStorage->gpuPtr, - allocation32bit, use64kbPages); + allocation32bit, use64kbPages, false); } -bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages) { +bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1) { NTSTATUS status = STATUS_SUCCESS; D3DDDI_MAPGPUVIRTUALADDRESS MapGPUVA = {0}; D3DDDIGPUVIRTUALADDRESS_PROTECTION_TYPE protectionType = {{{0}}}; @@ -355,7 +355,11 @@ bool Wddm::mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr MapGPUVA.SizeInPages = size / MemoryConstants::pageSize; MapGPUVA.OffsetInPages = 0; - if (use64kbPages) { + if (useHeap1) { + MapGPUVA.MinimumAddress = adapterInfo->GfxPartition.Heap32[1].Base; + MapGPUVA.MaximumAddress = adapterInfo->GfxPartition.Heap32[1].Limit; + MapGPUVA.BaseAddress = 0; + } else if (use64kbPages) { MapGPUVA.MinimumAddress = adapterInfo->GfxPartition.Standard64KB.Base; MapGPUVA.MaximumAddress = adapterInfo->GfxPartition.Standard64KB.Limit; } else { diff --git a/runtime/os_interface/windows/wddm.h b/runtime/os_interface/windows/wddm.h index ad432a63d6..3fe1fc9541 100644 --- a/runtime/os_interface/windows/wddm.h +++ b/runtime/os_interface/windows/wddm.h @@ -75,7 +75,7 @@ class Wddm { MOCKABLE_VIRTUAL bool evict(D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim); MOCKABLE_VIRTUAL bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim); - bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages); + bool mapGpuVirtualAddress(WddmAllocation *allocation, void *cpuPtr, uint64_t size, bool allocation32bit, bool use64kbPages, bool useHeap1); bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData, bool allocation32bit, bool use64kbPages); MOCKABLE_VIRTUAL D3DKMT_HANDLE createContext(); MOCKABLE_VIRTUAL bool freeGpuVirtualAddres(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size); @@ -228,7 +228,7 @@ class Wddm { std::unique_ptr gmmMemory; uintptr_t minAddress; - MOCKABLE_VIRTUAL bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages); + MOCKABLE_VIRTUAL bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1); MOCKABLE_VIRTUAL bool openAdapter(); bool createDevice(); bool createPagingQueue(); diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 828451c741..c2245b922d 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -72,7 +72,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo } WddmAllocation allocation(nullptr, imgInfo.size, nullptr); allocation.gmm = gmm; - auto status = WddmMemoryManager::createWddmAllocation(&allocation); + auto status = WddmMemoryManager::createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); if (status) { auto *wddmAllocation = new WddmAllocation(allocation); return wddmAllocation; @@ -103,7 +103,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s wddmAllocation->setAlignedCpuPtr(cpuPtr); // 64kb map is not needed - auto status = wddm->mapGpuVirtualAddress(wddmAllocation, cpuPtr, sizeAligned, false, false); + auto status = wddm->mapGpuVirtualAddress(wddmAllocation, cpuPtr, sizeAligned, false, false, false); DEBUG_BREAK_IF(!status); wddmAllocation->setCpuPtrAndGpuAddress(cpuPtr, (uint64_t)wddmAllocation->gpuPtr); @@ -133,7 +133,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_ while (success) { allocation.gmm = gmm; - bool success = createWddmAllocation(&allocation); + bool success = createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); if (!success) break; @@ -169,7 +169,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const Gmm *gmm = Gmm::create(ptrAligned, sizeAligned, false); allocation->gmm = gmm; - if (createWddmAllocation(allocation)) { + if (createWddmAllocation(allocation, MemoryType::EXTERNAL_ALLOCATION)) { return allocation; } freeGraphicsMemory(allocation); @@ -179,7 +179,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const return MemoryManager::allocateGraphicsMemory(size, ptr); } -GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr) { +GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) { GraphicsAllocation *graphicsAllocation = nullptr; bool success = true; Gmm *gmm = nullptr; @@ -213,14 +213,15 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, while (success) { allocation.gmm = gmm; - success = createWddmAllocation(&allocation); + success = createWddmAllocation(&allocation, memoryType); if (!success) break; auto *wddmAllocation = new WddmAllocation(allocation); graphicsAllocation = wddmAllocation; graphicsAllocation->is32BitAllocation = true; - graphicsAllocation->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase()); + auto baseAddress = memoryType == MemoryType::EXTERNAL_ALLOCATION ? allocator32Bit->getBase() : this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base; + graphicsAllocation->gpuBaseAddress = Gmm::canonize(baseAddress); return graphicsAllocation; } @@ -257,7 +258,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl allocation.is32BitAllocation = true; allocation.gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase()); } - auto status = wddm->mapGpuVirtualAddress(&allocation, ptr, size, is32BitAllocation, false); + auto status = wddm->mapGpuVirtualAddress(&allocation, ptr, size, is32BitAllocation, false, false); DEBUG_BREAK_IF(!status); allocation.setGpuAddress(allocation.gpuPtr); @@ -272,6 +273,10 @@ GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromNTHandle(void return createAllocationFromHandle((osHandle)((UINT_PTR)handle), false, true); } +GraphicsAllocation *WddmMemoryManager::createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) { + return allocate32BitGraphicsMemory(allocationSize, const_cast(ptr), MemoryType::INTERNAL_ALLOCATION); +} + void *WddmMemoryManager::lockResource(GraphicsAllocation *graphicsAllocation) { return wddm->lockResource(static_cast(graphicsAllocation)); }; @@ -768,17 +773,18 @@ AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() { return &mallocRestrictions; } -bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation) { +bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, MemoryType memoryType) { + bool useHeap1 = (memoryType == MemoryType::INTERNAL_ALLOCATION); auto wddmSuccess = wddm->createAllocation(allocation); if (wddmSuccess == STATUS_GRAPHICS_NO_VIDEO_MEMORY && deferredDeleter) { deferredDeleter->drain(true); wddmSuccess = wddm->createAllocation(allocation); } if (wddmSuccess == STATUS_SUCCESS) { - bool mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->getAlignedSize(), allocation->is32BitAllocation, false); + bool mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->getAlignedSize(), allocation->is32BitAllocation, false, useHeap1); if (!mapSuccess && deferredDeleter) { deferredDeleter->drain(true); - mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->getAlignedSize(), allocation->is32BitAllocation, false); + mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->getAlignedSize(), allocation->is32BitAllocation, false, useHeap1); } if (!mapSuccess) { wddm->destroyAllocations(&allocation->handle, 1, 0, allocation->resourceHandle); diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index dacde0c24f..0528e87eb8 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -46,9 +46,10 @@ class WddmMemoryManager : public MemoryManager { GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) override; GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override; GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override; - GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) override; + GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override; + GraphicsAllocation *createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) override; GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; void *lockResource(GraphicsAllocation *graphicsAllocation) override; void unlockResource(GraphicsAllocation *graphicsAllocation) override; @@ -109,7 +110,7 @@ class WddmMemoryManager : public MemoryManager { static bool validateAllocation(WddmAllocation *alloc); bool checkTrimCandidateListCompaction(); void checkTrimCandidateCount(); - bool createWddmAllocation(WddmAllocation *allocation); + bool createWddmAllocation(WddmAllocation *allocation, MemoryType memoryType); ResidencyContainer trimCandidateList; std::mutex trimCandidateListMutex; std::atomic residencyLock; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 73325f462c..0c223dc4af 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -530,7 +530,7 @@ TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenTagPerfCountAllocatorIsCreated TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32bitGraphicsAllocationIsReturned) { size_t size = 10; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_EQ(size, allocation->getUnderlyingBufferSize()); @@ -540,8 +540,8 @@ TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32b TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAllocationNullptrIsReturned) { size_t size = 0xfffff000; - auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr); + auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, MemoryType::EXTERNAL_ALLOCATION); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ(nullptr, allocation); if (allocation) memoryManager->freeGraphicsMemory(allocation); @@ -551,8 +551,8 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAllocationWithHostPtrThenNullptrIsReturned) { size_t size = 0xfffff000; void *ptr = (void *)0x10000; - auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr); - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr); + auto allocationFirst = memoryManager->allocate32BitGraphicsMemory(0x5000, nullptr, MemoryType::EXTERNAL_ALLOCATION); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ(nullptr, allocation); if (allocation) memoryManager->freeGraphicsMemory(allocation); @@ -562,7 +562,7 @@ TEST_F(MemoryAllocatorTest, givenNotEnoughSpaceInAllocatorWhenAskedFor32bitAlloc TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationWithPtrThen32bitGraphicsAllocationWithGpuAddressIsReturned) { size_t size = 10; void *ptr = (void *)0x1000; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_EQ(size, allocation->getUnderlyingBufferSize()); @@ -1103,6 +1103,16 @@ TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryM memoryManager.freeGraphicsMemory(graphicsAllocation1); } +TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsCalledThenGraphicsAllocationIsReturned) { + OsAgnosticMemoryManager memoryManager; + auto ptr = (void *)0x100000; + size_t allocationSize = 4096; + auto graphicsAllocation = memoryManager.createInternalGraphicsAllocation(ptr, allocationSize); + EXPECT_EQ(ptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(allocationSize, graphicsAllocation->getUnderlyingBufferSize()); + memoryManager.freeGraphicsMemory(graphicsAllocation); +} + TEST_F(MemoryAllocatorTest, GivenSizeWhenGmmIsCreatedThenSuccess) { Gmm *gmm = Gmm::create(nullptr, 65536, false); EXPECT_NE(nullptr, gmm); diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 67ce464173..ecade49884 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -125,7 +125,7 @@ class FailMemoryManager : public MockMemoryManager { GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override { return nullptr; }; - GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) override { + GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr, MemoryType memoryType) override { return nullptr; }; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override { diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index e640373a12..31af273d5a 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -591,7 +591,7 @@ TEST_F(DrmMemoryManagerTest, testProfilingAllocatorCleanup) { TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32BitDrmAllocationIsBeingReturned) { mock->ioctl_expected = 3; auto size = 10u; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_GE(allocation->getUnderlyingBufferSize(), size); @@ -789,7 +789,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWithHo auto size = 10u; void *host_ptr = (void *)0x1000; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, host_ptr); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, host_ptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ(nullptr, allocation); } @@ -801,7 +801,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationAndAll mock->ioctl_res_ext = &ioctlResExt; auto size = 10u; - auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr); + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ(nullptr, allocation); } @@ -1394,7 +1394,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragm size_t pages3size = 3 * MemoryConstants::pageSize; void *host_ptr = (void *)0x1000; - DrmAllocation *graphicsAlloaction = memoryManager->allocate32BitGraphicsMemory(pages3size, host_ptr); + DrmAllocation *graphicsAlloaction = memoryManager->allocate32BitGraphicsMemory(pages3size, host_ptr, MemoryType::EXTERNAL_ALLOCATION); auto bo = graphicsAlloaction->getBO(); EXPECT_EQ(allocationSize, bo->peekUnmapSize()); diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index ab24bc73ef..490253b121 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -124,11 +124,11 @@ class WddmMock : public Wddm { makeNonResidentResult.called++; return makeNonResidentResult.success = Wddm::evict(handles, num, sizeToTrim); } - bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32Bit, bool use64kbPages) override { + bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32Bit, bool use64kbPages, bool useHeap1) override { mapGpuVirtualAddressResult.called++; mapGpuVirtualAddressResult.cpuPtrPassed = cpuPtr; if (callBaseMapGpuVa) { - return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, size, gpuPtr, allocation32Bit, use64kbPages); + return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, size, gpuPtr, allocation32Bit, use64kbPages, useHeap1); } else { gpuPtr = reinterpret_cast(cpuPtr); return mapGpuVaStatus; 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 6eb18c7d56..fae2bb1228 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -41,8 +41,8 @@ class WddmWithKmDafMock : public Wddm { return featureTable.get(); } - bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages) override { - return Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, size, gpuPtr, allocation32bit, use64kbPages); + bool mapGpuVirtualAddressImpl(Gmm *gmm, D3DKMT_HANDLE handle, void *cpuPtr, uint64_t size, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, bool allocation32bit, bool use64kbPages, bool useHeap1) override { + return Wddm::mapGpuVirtualAddressImpl(gmm, handle, cpuPtr, size, gpuPtr, allocation32bit, use64kbPages, useHeap1); }; }; @@ -95,7 +95,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmD auto gmm = std::unique_ptr(Gmm::create(nullptr, 1, false)); allocation.gmm = gmm.get(); - wddmWithKmDafMock->mapGpuVirtualAddressImpl(allocation.gmm, allocation.handle, allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), allocation.gpuPtr, false, false); + wddmWithKmDafMock->mapGpuVirtualAddressImpl(allocation.gmm, allocation.handle, allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), allocation.gpuPtr, false, false, false); EXPECT_EQ(wddmWithKmDafMock->getFeatureTable()->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 8c7da415c5..8431d346d0 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -49,11 +49,11 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase uint64_t size = 0x9000; wddm->setHeap32(base, size); - std::unique_ptr mm = std::unique_ptr(new WddmMemoryManager(false, wddm)); + std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(false, wddm)); - ASSERT_NE(nullptr, mm->allocator32Bit.get()); + ASSERT_NE(nullptr, memoryManager->allocator32Bit.get()); - EXPECT_EQ(base, mm->allocator32Bit->getBase()); + EXPECT_EQ(base, memoryManager->allocator32Bit->getBase()); } TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) { @@ -69,14 +69,14 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled HWTEST_F(WddmMemoryManagerTest, AllocateAndFree) { SetUpMm(); - auto *ptr = mm->allocateGraphicsMemory(0x1000); + auto *ptr = memoryManager->allocateGraphicsMemory(0x1000); EXPECT_NE(nullptr, ptr); - mm->freeGraphicsMemory(ptr); + memoryManager->freeGraphicsMemory(ptr); } HWTEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPaddingSupportThenFalseIsReturned) { SetUpMm(); - EXPECT_FALSE(mm->peekVirtualPaddingSupport()); + EXPECT_FALSE(memoryManager->peekVirtualPaddingSupport()); } HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) { @@ -85,23 +85,23 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) { void *ptr = alignedMalloc(3 * 4096, 4096); ASSERT_NE(nullptr, ptr); - auto *gpuAllocation = mm->allocateGraphicsMemory(0x1000, ptr); + auto *gpuAllocation = memoryManager->allocateGraphicsMemory(0x1000, ptr); // Should be same cpu ptr and gpu ptr EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer()); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); alignedFree(ptr); } HWTEST_F(WddmMemoryManagerTest, givenDefaultMemoryManagerWhenAllocateWithSizeIsCalledThenResourceHandleIsZero) { SetUpMm(); - auto *gpuAllocation = mm->allocateGraphicsMemory(0x1000, MemoryConstants::pageSize); + auto *gpuAllocation = memoryManager->allocateGraphicsMemory(0x1000, MemoryConstants::pageSize); auto wddmAllocation = static_cast(gpuAllocation); EXPECT_EQ(0u, wddmAllocation->resourceHandle); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleIsCalledThenNonNullGraphicsAllocationIsReturned) { @@ -113,13 +113,13 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle std::unique_ptr gmm(Gmm::create(pSysMem, 4096u, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(RESOURCE_HANDLE, wddmAlloc->resourceHandle); EXPECT_EQ(ALLOCATION_HANDLE, wddmAlloc->handle); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCalledThenNonNullGraphicsAllocationIsReturned) { @@ -130,29 +130,29 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromNTHandleIsCa std::unique_ptr gmm(Gmm::create(pSysMem, 4096u, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = mm->createGraphicsAllocationFromNTHandle((void *)1); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromNTHandle((void *)1); auto wddmAlloc = static_cast(gpuAllocation); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(NT_RESOURCE_HANDLE, wddmAlloc->resourceHandle); EXPECT_EQ(NT_ALLOCATION_HANDLE, wddmAlloc->handle); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenLockUnlockIsCalledThenReturnPtr) { SetUpMm(); - auto alloc = mm->allocateGraphicsMemory(1); + auto alloc = memoryManager->allocateGraphicsMemory(1); - auto ptr = mm->lockResource(alloc); + auto ptr = memoryManager->lockResource(alloc); EXPECT_NE(nullptr, ptr); EXPECT_EQ(1u, mockWddm->lockResult.called); EXPECT_TRUE(mockWddm->lockResult.success); - mm->unlockResource(alloc); + memoryManager->unlockResource(alloc); EXPECT_EQ(1u, mockWddm->unlockResult.called); EXPECT_TRUE(mockWddm->unlockResult.success); - mm->freeGraphicsMemory(alloc); + memoryManager->freeGraphicsMemory(alloc); } HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllocWhenForce32bitAddressingIsSetAndRequireSpecificBitnessIsTrue) { @@ -164,18 +164,18 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllo std::unique_ptr gmm(Gmm::create(pSysMem, 4096u, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - mm->setForce32BitAllocations(true); + memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, true); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, true); ASSERT_NE(nullptr, gpuAllocation); if (is64bit) { EXPECT_TRUE(gpuAllocation->is32BitAllocation); - uint64_t base = mm->allocator32Bit->getBase(); + uint64_t base = memoryManager->allocator32Bit->getBase(); EXPECT_EQ(Gmm::canonize(base), gpuAllocation->gpuBaseAddress); } - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32BitAllocWhenForce32bitAddressingIsSetAndRequireSpecificBitnessIsFalse) { @@ -187,9 +187,9 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B std::unique_ptr gmm(Gmm::create(pSysMem, 4096u, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - mm->setForce32BitAllocations(true); + memoryManager->setForce32BitAllocations(true); - auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_FALSE(gpuAllocation->is32BitAllocation); @@ -198,7 +198,7 @@ HWTEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleDoesNotReturn32B EXPECT_EQ(base, gpuAllocation->gpuBaseAddress); } - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHandleIsCalledThenDestroyResourceHandle) { @@ -210,7 +210,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan std::unique_ptr gmm(Gmm::create(pSysMem, 4096u, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto gpuAllocation = (WddmAllocation *)mm->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto gpuAllocation = (WddmAllocation *)memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); EXPECT_NE(nullptr, gpuAllocation); auto expectedDestroyHandle = gpuAllocation->resourceHandle; EXPECT_NE(0u, expectedDestroyHandle); @@ -218,7 +218,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenFreeAllocFromSharedHan auto lastDestroyed = getMockLastDestroyedResHandleFcn(); EXPECT_EQ(0u, lastDestroyed); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); lastDestroyed = getMockLastDestroyedResHandleFcn(); EXPECT_EQ(lastDestroyed, expectedDestroyHandle); } @@ -232,10 +232,10 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar std::unique_ptr gmm(Gmm::create(pSysMem, size, false)); auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); - auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(size, gpuAllocation->getUnderlyingBufferSize()); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFailsThenReturnNull) { @@ -249,14 +249,14 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandle mockWddm->failOpenSharedHandle = true; - auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, false); + auto *gpuAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); EXPECT_EQ(nullptr, gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { SetUpMm(); MockContext context; - context.setMemoryManager(mm); + context.setMemoryManager(memoryManager); cl_image_format imageFormat; imageFormat.image_channel_data_type = CL_UNORM_INT8; @@ -284,7 +284,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { SetUpMm(); MockContext context; - context.setMemoryManager(mm); + context.setMemoryManager(memoryManager); cl_image_format imageFormat; imageFormat.image_channel_data_type = CL_UNORM_INT8; @@ -315,7 +315,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreat HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { SetUpMm(); MockContext context; - context.setMemoryManager(mm); + context.setMemoryManager(memoryManager); cl_image_format imageFormat; imageFormat.image_channel_data_type = CL_UNORM_INT8; @@ -351,11 +351,11 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { size_t baseOffset = 1024; // misalligned buffer spanning accross 3 pages - auto *gpuAllocation = mm->allocateGraphicsMemory(2 * 4096, (char *)ptr + baseOffset); + auto *gpuAllocation = memoryManager->allocateGraphicsMemory(2 * 4096, (char *)ptr + baseOffset); // Should be same cpu ptr and gpu ptr EXPECT_EQ((char *)ptr + baseOffset, gpuAllocation->getUnderlyingBuffer()); - auto &hostPtrManager = mm->hostPtrManager; + auto &hostPtrManager = memoryManager->hostPtrManager; auto fragment = hostPtrManager.getFragment(ptr); ASSERT_NE(nullptr, fragment); @@ -369,7 +369,7 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { // offseted by one page, still in boundary void *offsetedPtr = reinterpret_cast(reinterpret_cast(ptr) + 4096); - auto *gpuAllocation2 = mm->allocateGraphicsMemory(0x1000, offsetedPtr); + auto *gpuAllocation2 = memoryManager->allocateGraphicsMemory(0x1000, offsetedPtr); // Should be same cpu ptr and gpu ptr EXPECT_EQ(offsetedPtr, gpuAllocation2->getUnderlyingBuffer()); @@ -381,14 +381,14 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { EXPECT_EQ(alloc.getUnderlyingBufferSize(), allocOffseted.getUnderlyingBufferSize()); EXPECT_EQ(alloc.getAlignedCpuPtr(), allocOffseted.getAlignedCpuPtr()); - mm->freeGraphicsMemory(gpuAllocation2); + memoryManager->freeGraphicsMemory(gpuAllocation2); auto fragment4 = hostPtrManager.getFragment(ptr); ASSERT_NE(nullptr, fragment4); EXPECT_TRUE(fragment4->refCount == 1); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); fragment4 = hostPtrManager.getFragment(ptr); EXPECT_EQ(nullptr, fragment4); @@ -402,19 +402,19 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemCheckGmm) { bool success = false; // three pages void *ptr = alignedMalloc(3 * 4096, 4096); - auto *gpuAllocation = mm->allocateGraphicsMemory(3 * 4096, ptr); + auto *gpuAllocation = memoryManager->allocateGraphicsMemory(3 * 4096, ptr); // Should be same cpu ptr and gpu ptr ASSERT_NE(nullptr, gpuAllocation); EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer()); - auto &hostPtrManager = mm->hostPtrManager; + auto &hostPtrManager = memoryManager->hostPtrManager; auto fragment = hostPtrManager.getFragment(ptr); ASSERT_NE(nullptr, fragment); EXPECT_TRUE(fragment->refCount == 1); EXPECT_NE(fragment->osInternalStorage->handle, 0); EXPECT_NE(fragment->osInternalStorage->gmm, nullptr); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); alignedFree(ptr); } @@ -424,10 +424,10 @@ HWTEST_F(WddmMemoryManagerTest, GivenAlignedPointerWhenAllocate32BitMemoryThenGm bool success = false; uint32_t size = 4096; void *ptr = (void *)4096; - auto *gpuAllocation = mm->allocate32BitGraphicsMemory(size, ptr); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ(ptr, (void *)gpuAllocation->gmm->resourceParams.pExistingSysMem); EXPECT_EQ(size, gpuAllocation->gmm->resourceParams.ExistingSysMemSize); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, GivenUnAlignedPointerAndSizeWhenAllocate32BitMemoryThenGmmCalledWithCorrectPointerAndSize) { @@ -436,21 +436,21 @@ HWTEST_F(WddmMemoryManagerTest, GivenUnAlignedPointerAndSizeWhenAllocate32BitMem bool success = false; uint32_t size = 0x1001; void *ptr = (void *)0x1001; - auto *gpuAllocation = mm->allocate32BitGraphicsMemory(size, ptr); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, MemoryType::EXTERNAL_ALLOCATION); EXPECT_EQ((void *)0x1000, (void *)gpuAllocation->gmm->resourceParams.pExistingSysMem); EXPECT_EQ(0x2000, gpuAllocation->gmm->resourceParams.ExistingSysMemSize); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, getSystemSharedMemory) { SetUpMm(); - int64_t mem = mm->getSystemSharedMemory(); + int64_t mem = memoryManager->getSystemSharedMemory(); EXPECT_EQ(mem, 4249540608); } HWTEST_F(WddmMemoryManagerTest, getMaxApplicationAddress) { SetUpMm(); - uint64_t maxAddr = mm->getMaxApplicationAddress(); + uint64_t maxAddr = memoryManager->getMaxApplicationAddress(); if (is32bit) { EXPECT_EQ(maxAddr, MemoryConstants::max32BitAppAddress); } else { @@ -460,14 +460,14 @@ HWTEST_F(WddmMemoryManagerTest, getMaxApplicationAddress) { HWTEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithNullptr) { SetUpMm(); - auto *gpuAllocation = mm->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, MemoryType::EXTERNAL_ALLOCATION); ASSERT_NE(nullptr, gpuAllocation); EXPECT_LE(Gmm::canonize(wddm->getHeap32Base()), gpuAllocation->getGpuAddress()); EXPECT_GT(Gmm::canonize(wddm->getHeap32Base()) + wddm->getHeap32Size() - 1, gpuAllocation->getGpuAddress()); EXPECT_EQ(0u, gpuAllocation->fragmentsStorage.fragmentCount); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotDoTripleAlloc) { @@ -475,7 +475,7 @@ HWTEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotD size_t misalignedSize = 0x2500; void *misalignedPtr = (void *)0x12500; - auto *gpuAllocation = mm->allocate32BitGraphicsMemory(misalignedSize, misalignedPtr); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(misalignedSize, misalignedPtr, MemoryType::EXTERNAL_ALLOCATION); ASSERT_NE(nullptr, gpuAllocation); @@ -490,19 +490,19 @@ HWTEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotD uint64_t offset = ptrDiff(misalignedPtr, alignedPtr); EXPECT_EQ(offset, gpuAllocation->allocationOffset); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, Allocate32BitMemorySetsCannonizedGpuBaseAddress) { SetUpMm(); - auto *gpuAllocation = mm->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr); + auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, MemoryType::EXTERNAL_ALLOCATION); ASSERT_NE(nullptr, gpuAllocation); uint64_t cannonizedAddress = Gmm::canonize(wddm->getHeap32Base()); EXPECT_EQ(cannonizedAddress, gpuAllocation->gpuBaseAddress); - mm->freeGraphicsMemory(gpuAllocation); + memoryManager->freeGraphicsMemory(gpuAllocation); } HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) { @@ -529,7 +529,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation storage.fragmentStorageData[2].osHandleStorage->gmm = Gmm::create(pSysMem, 4096u, false); storage.fragmentStorageData[2].residency = new ResidencyData; - mm->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage); auto destroyWithResourceHandleCalled = 0u; D3DKMT_DESTROYALLOCATION2 *ptrToDestroyAlloc2 = nullptr; @@ -547,12 +547,12 @@ HWTEST_F(WddmMemoryManagerTest, GivenThreeOsHandlesWhenAskedForDestroyAllocation HWTEST_F(WddmMemoryManagerTest, freeNullAllocationNoCrash) { SetUpMm(); - mm->freeGraphicsMemory(nullptr); + memoryManager->freeGraphicsMemory(nullptr); } HWTEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForAlignedMallocRestrictionsThenValueIsReturned) { SetUpMm(); - AlignedMallocRestrictions *mallocRestrictions = mm->getAlignedMallocRestrictions(); + AlignedMallocRestrictions *mallocRestrictions = memoryManager->getAlignedMallocRestrictions(); ASSERT_NE(nullptr, mallocRestrictions); EXPECT_EQ(OCLRT::windowsMinAddress, mallocRestrictions->minAddress); } @@ -564,11 +564,11 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestricti size_t size = 0x1000; void *expectReserve = reinterpret_cast(mockWddm->virtualAllocAddress); - WddmAllocation *allocation = static_cast(mm->allocateGraphicsMemory(size, cpuPtr)); + WddmAllocation *allocation = static_cast(memoryManager->allocateGraphicsMemory(size, cpuPtr)); ASSERT_NE(nullptr, allocation); EXPECT_EQ(expectReserve, allocation->getReservedAddress()); EXPECT_EQ(expectReserve, reinterpret_cast(allocation->gpuPtr)); - mm->freeGraphicsMemory(allocation); + memoryManager->freeGraphicsMemory(allocation); } HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGpuVaFailThenFailToCreateAllocation) { @@ -587,7 +587,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGp WddmAllocation allocation(ptr, size, nullptr); allocation.gmm = gmm.get(); - bool ret = mockMemoryManager.createWddmAllocation(&allocation); + bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); EXPECT_FALSE(ret); } @@ -608,7 +608,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstM WddmAllocation allocation(ptr, size, nullptr); allocation.gmm = gmm.get(); - bool ret = mockMemoryManager.createWddmAllocation(&allocation); + bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); EXPECT_TRUE(ret); EXPECT_EQ(reinterpret_cast(ptr), allocation.getGpuAddress()); } @@ -630,44 +630,83 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstA WddmAllocation allocation(ptr, size, nullptr); allocation.gmm = gmm.get(); - bool ret = mockMemoryManager.createWddmAllocation(&allocation); + bool ret = mockMemoryManager.createWddmAllocation(&allocation, MemoryType::EXTERNAL_ALLOCATION); EXPECT_FALSE(ret); } +HWTEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeap1) { + SetUpMm(); + auto wddmAllocation = (WddmAllocation *)memoryManager->createInternalGraphicsAllocation(nullptr, 4096u); + ASSERT_NE(nullptr, wddmAllocation); + EXPECT_EQ(wddmAllocation->gpuBaseAddress, Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base)); + EXPECT_NE(nullptr, wddmAllocation->getUnderlyingBuffer()); + EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); + EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress()); + auto cannonizedHeapBase = Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base); + auto cannonizedHeapEnd = Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Limit); + + EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase); + EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd); + + EXPECT_TRUE(wddmAllocation->cpuPtrAllocated); + EXPECT_TRUE(wddmAllocation->is32BitAllocation); + memoryManager->freeGraphicsMemory(wddmAllocation); +} + +HWTEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhenCallIsMadeThenAllocationIsCreatedIn32BitHeap1) { + SetUpMm(); + auto ptr = (void *)0x1000000; + auto wddmAllocation = (WddmAllocation *)memoryManager->createInternalGraphicsAllocation(ptr, 4096u); + ASSERT_NE(nullptr, wddmAllocation); + EXPECT_EQ(wddmAllocation->gpuBaseAddress, Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base)); + EXPECT_EQ(ptr, wddmAllocation->getUnderlyingBuffer()); + EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize()); + EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress()); + auto cannonizedHeapBase = Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Base); + auto cannonizedHeapEnd = Gmm::canonize(this->wddm->getAdapterInfo()->GfxPartition.Heap32[1].Limit); + + EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase); + EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd); + + EXPECT_FALSE(wddmAllocation->cpuPtrAllocated); + EXPECT_TRUE(wddmAllocation->is32BitAllocation); + memoryManager->freeGraphicsMemory(wddmAllocation); +} + HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListPlacesAllocationInContainerAndAssignsPosition) { SetUpMm(); WddmAllocation allocation; - mm->addToTrimCandidateList(&allocation); + memoryManager->addToTrimCandidateList(&allocation); - EXPECT_NE(0u, mm->trimCandidateList.size()); + EXPECT_NE(0u, memoryManager->trimCandidateList.size()); EXPECT_NE(trimListUnusedPosition, allocation.getTrimCandidateListPosition()); size_t position = allocation.getTrimCandidateListPosition(); - ASSERT_LT(position, mm->trimCandidateList.size()); + ASSERT_LT(position, memoryManager->trimCandidateList.size()); - EXPECT_EQ(&allocation, mm->trimCandidateList[position]); + EXPECT_EQ(&allocation, memoryManager->trimCandidateList[position]); } HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListDoesNotInsertAllocationAlreadyOnTheList) { SetUpMm(); WddmAllocation allocation; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation); + memoryManager->addToTrimCandidateList(&allocation); EXPECT_NE(trimListUnusedPosition, allocation.getTrimCandidateListPosition()); size_t position = allocation.getTrimCandidateListPosition(); - ASSERT_LT(position, mm->trimCandidateList.size()); + ASSERT_LT(position, memoryManager->trimCandidateList.size()); - EXPECT_EQ(&allocation, mm->trimCandidateList[position]); + EXPECT_EQ(&allocation, memoryManager->trimCandidateList[position]); - size_t previousSize = mm->trimCandidateList.size(); - mm->addToTrimCandidateList(&allocation); + size_t previousSize = memoryManager->trimCandidateList.size(); + memoryManager->addToTrimCandidateList(&allocation); - EXPECT_EQ(previousSize, mm->trimCandidateList.size()); + EXPECT_EQ(previousSize, memoryManager->trimCandidateList.size()); EXPECT_EQ(position, allocation.getTrimCandidateListPosition()); } @@ -675,8 +714,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListAssignsUnuse SetUpMm(); WddmAllocation allocation; - mm->addToTrimCandidateList(&allocation); - mm->removeFromTrimCandidateList(&allocation); + memoryManager->addToTrimCandidateList(&allocation); + memoryManager->removeFromTrimCandidateList(&allocation); EXPECT_EQ(trimListUnusedPosition, allocation.getTrimCandidateListPosition()); } @@ -685,13 +724,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesAlloc SetUpMm(); WddmAllocation allocation; - mm->addToTrimCandidateList(&allocation); + memoryManager->addToTrimCandidateList(&allocation); size_t position = allocation.getTrimCandidateListPosition(); - mm->removeFromTrimCandidateList(&allocation); + memoryManager->removeFromTrimCandidateList(&allocation); - if (mm->trimCandidateList.size() > position) { - EXPECT_NE(&allocation, mm->trimCandidateList[position]); + if (memoryManager->trimCandidateList.size() > position) { + EXPECT_NE(&allocation, memoryManager->trimCandidateList[position]); } } @@ -699,45 +738,45 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastA SetUpMm(); WddmAllocation allocation; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation); + memoryManager->addToTrimCandidateList(&allocation); - mm->removeFromTrimCandidateList(&allocation); + memoryManager->removeFromTrimCandidateList(&allocation); - EXPECT_EQ(0u, mm->trimCandidateList.size()); + EXPECT_EQ(0u, memoryManager->trimCandidateList.size()); } HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastAllocationAndAllPreviousEmptyEntries) { SetUpMm(); WddmAllocation allocation1, allocation2; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation1); - mm->trimCandidateList.push_back(nullptr); - mm->trimCandidateList.push_back(nullptr); - mm->trimCandidateList.push_back(nullptr); + memoryManager->trimCandidateList.push_back(nullptr); + memoryManager->trimCandidateList.push_back(nullptr); + memoryManager->trimCandidateList.push_back(nullptr); - mm->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation2); - EXPECT_EQ(5u, mm->trimCandidateList.size()); + EXPECT_EQ(5u, memoryManager->trimCandidateList.size()); - mm->removeFromTrimCandidateList(&allocation2); + memoryManager->removeFromTrimCandidateList(&allocation2); - EXPECT_EQ(1u, mm->trimCandidateList.size()); + EXPECT_EQ(1u, memoryManager->trimCandidateList.size()); } HWTEST_F(WddmMemoryManagerResidencyTest, successiveAddingToTrimCandidateListAssignsNewPositions) { SetUpMm(); WddmAllocation allocation1, allocation2, allocation3; - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - EXPECT_EQ(3u, mm->trimCandidateList.size()); + EXPECT_EQ(3u, memoryManager->trimCandidateList.size()); EXPECT_NE(allocation1.getTrimCandidateListPosition(), allocation2.getTrimCandidateListPosition()); EXPECT_NE(allocation2.getTrimCandidateListPosition(), allocation3.getTrimCandidateListPosition()); } @@ -746,13 +785,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, DISABLED_removingNotLastAllocationFromT SetUpMm(); WddmAllocation allocation1, allocation2, allocation3; - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - mm->removeFromTrimCandidateList(&allocation2); + memoryManager->removeFromTrimCandidateList(&allocation2); - EXPECT_EQ(2u, mm->trimCandidateList.size()); + EXPECT_EQ(2u, memoryManager->trimCandidateList.size()); EXPECT_EQ(2u, allocation3.getTrimCandidateListPosition()); EXPECT_NE(allocation2.getTrimCandidateListPosition(), allocation3.getTrimCandidateListPosition()); @@ -762,44 +801,44 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removingNotLastAllocationFromTrimCandid SetUpMm(); WddmAllocation allocation1, allocation2, allocation3; - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); size_t position2 = allocation2.getTrimCandidateListPosition(); size_t position3 = allocation3.getTrimCandidateListPosition(); - mm->removeFromTrimCandidateList(&allocation2); + memoryManager->removeFromTrimCandidateList(&allocation2); - EXPECT_EQ(3u, mm->trimCandidateList.size()); + EXPECT_EQ(3u, memoryManager->trimCandidateList.size()); EXPECT_EQ(2u, position3); - EXPECT_EQ(nullptr, mm->trimCandidateList[position2]); + EXPECT_EQ(nullptr, memoryManager->trimCandidateList[position2]); } HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListRemovesInitialNullEntriesAndUpdatesPositions) { SetUpMm(); WddmAllocation allocation1, allocation2, allocation3, allocation4; - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); - mm->addToTrimCandidateList(&allocation4); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation4); size_t position3 = allocation3.getTrimCandidateListPosition(); size_t position4 = allocation4.getTrimCandidateListPosition(); - mm->removeFromTrimCandidateList(&allocation2); - mm->removeFromTrimCandidateList(&allocation1); + memoryManager->removeFromTrimCandidateList(&allocation2); + memoryManager->removeFromTrimCandidateList(&allocation1); - EXPECT_EQ(4u, mm->trimCandidateList.size()); + EXPECT_EQ(4u, memoryManager->trimCandidateList.size()); - mm->compactTrimCandidateList(); + memoryManager->compactTrimCandidateList(); - EXPECT_EQ(2u, mm->trimCandidateList.size()); + EXPECT_EQ(2u, memoryManager->trimCandidateList.size()); - EXPECT_EQ(mm->trimCandidateList[0], &allocation3); + EXPECT_EQ(memoryManager->trimCandidateList[0], &allocation3); EXPECT_EQ(0u, allocation3.getTrimCandidateListPosition()); - EXPECT_EQ(mm->trimCandidateList[1], &allocation4); + EXPECT_EQ(memoryManager->trimCandidateList[1], &allocation4); EXPECT_EQ(1u, allocation4.getTrimCandidateListPosition()); } @@ -807,28 +846,28 @@ HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListWithNonNullEntr SetUpMm(); WddmAllocation allocation1, allocation2, allocation3, allocation4; - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); - mm->addToTrimCandidateList(&allocation4); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation4); - EXPECT_EQ(4u, mm->trimCandidateList.size()); + EXPECT_EQ(4u, memoryManager->trimCandidateList.size()); - mm->compactTrimCandidateList(); + memoryManager->compactTrimCandidateList(); - EXPECT_EQ(4u, mm->trimCandidateList.size()); + EXPECT_EQ(4u, memoryManager->trimCandidateList.size()); } HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllocationsResident) { SetUpMm(); WddmAllocation allocation1, allocation2, allocation3, allocation4; - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(&allocation2); - mm->pushAllocationForResidency(&allocation3); - mm->pushAllocationForResidency(&allocation4); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation3); + memoryManager->pushAllocationForResidency(&allocation4); - mm->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_TRUE(allocation1.getResidencyData().resident); EXPECT_TRUE(allocation2.getResidencyData().resident); @@ -840,14 +879,14 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdates SetUpMm(); WddmAllocation allocation1, allocation2, allocation3, allocation4; - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(&allocation2); - mm->pushAllocationForResidency(&allocation3); - mm->pushAllocationForResidency(&allocation4); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation3); + memoryManager->pushAllocationForResidency(&allocation4); wddm->getMonitoredFence().currentFenceValue = 20; - mm->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_EQ(20u, allocation1.getResidencyData().lastFence); EXPECT_EQ(20u, allocation2.getResidencyData().lastFence); @@ -861,13 +900,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTr WddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(mockWddm->virtualAllocAddress + 0x1500); - WddmAllocation *allocationTriple = (WddmAllocation *)mm->allocateGraphicsMemory(8196, ptr); + WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(allocationTriple); - mm->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(allocationTriple); + memoryManager->pushAllocationForResidency(&allocation2); - mm->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); @@ -875,34 +914,34 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTr EXPECT_EQ(5u, gdi.getMakeResidentArg().NumAllocations); - mm->freeGraphicsMemory(allocationTriple); + memoryManager->freeGraphicsMemory(allocationTriple); } HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastFencePLusOneForTripleAllocations) { SetUpMm(); WddmAllocation allocation1, allocation2; - WddmAllocation *allocationTriple = (WddmAllocation *)mm->allocateGraphicsMemory(8196, (void *)0x1500); + WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, (void *)0x1500); wddm->getMonitoredFence().currentFenceValue = 20; - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(allocationTriple); - mm->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(allocationTriple); + memoryManager->pushAllocationForResidency(&allocation2); - mm->makeResidentResidencyAllocations(nullptr); + memoryManager->makeResidentResidencyAllocations(nullptr); for (uint32_t i = 0; i < allocationTriple->fragmentsStorage.fragmentCount; i++) { EXPECT_EQ(20u, allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->lastFence); } - mm->freeGraphicsMemory(allocationTriple); + memoryManager->freeGraphicsMemory(allocationTriple); } HWTEST_F(WddmMemoryManagerResidencyTest, trimCallbackIsRegisteredInWddmMemoryManagerCtor) { SetUpMm(); - EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)mm->trimCallback, gdi.getRegisterTrimNotificationArg().Callback); - EXPECT_EQ((void *)mm, gdi.getRegisterTrimNotificationArg().Context); + EXPECT_EQ((PFND3DKMT_TRIMNOTIFICATIONCALLBACK)memoryManager->trimCallback, gdi.getRegisterTrimNotificationArg().Callback); + EXPECT_EQ((void *)memoryManager, gdi.getRegisterTrimNotificationArg().Context); EXPECT_EQ(wddm->getDevice(), gdi.getRegisterTrimNotificationArg().hDevice); } @@ -918,23 +957,23 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri allocation2.getResidencyData().resident = true; // Set last periodic fence value - mm->lastPeriodicTrimFenceValue = 10; + memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value wddm->getMonitoredFence().currentFenceValue = 20; mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); - mm->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); // 2 allocations evicted EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); // removed from trim candidate list - EXPECT_EQ(0u, mm->trimCandidateList.size()); + EXPECT_EQ(0u, memoryManager->trimCandidateList.size()); // marked nonresident EXPECT_FALSE(allocation1.getResidencyData().resident); EXPECT_FALSE(allocation2.getResidencyData().resident); @@ -954,18 +993,18 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio allocation2.getResidencyData().resident = true; // Set last periodic fence value - mm->lastPeriodicTrimFenceValue = 10; + memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value wddm->getMonitoredFence().currentFenceValue = 20; mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); - mm->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); // 1 allocation evicted EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); @@ -986,7 +1025,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF trimNotification.NumBytesToTrim = 0; void *ptr = reinterpret_cast(mockWddm->virtualAllocAddress + 0x1500); // 3-fragment Allocation - WddmAllocation *allocationTriple = (WddmAllocation *)mm->allocateGraphicsMemory(8196, ptr); + WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); // whole allocation unused since previous trim allocationTriple->getResidencyData().lastFence = 0; @@ -1001,17 +1040,17 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true; // Set last periodic fence value - mm->lastPeriodicTrimFenceValue = 10; + memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value wddm->getMonitoredFence().currentFenceValue = 20; mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(allocationTriple); + memoryManager->addToTrimCandidateList(allocationTriple); - mm->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); // 2 fragments evicted with one call EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); @@ -1019,7 +1058,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedF EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident); EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident); - mm->freeGraphicsMemory(allocationTriple); + memoryManager->freeGraphicsMemory(allocationTriple); } HWTEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) { @@ -1029,14 +1068,14 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalled trimNotification.NumBytesToTrim = 0; // Set last periodic fence value - mm->lastPeriodicTrimFenceValue = 10; + memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value *wddm->getMonitoredFence().cpuAddress = 20; - mm->trimCandidateList.resize(0); - mm->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + memoryManager->trimCandidateList.resize(0); + memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); - EXPECT_EQ(20u, mm->lastPeriodicTrimFenceValue); + EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValue); } HWTEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) { @@ -1046,19 +1085,19 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbac trimNotification.NumBytesToTrim = 0; // Set last periodic fence value - mm->lastPeriodicTrimFenceValue = 10; + memoryManager->lastPeriodicTrimFenceValue = 10; // Set current fence value to greater value *wddm->getMonitoredFence().cpuAddress = 20; - mm->trimCandidateList.resize(0); - mm->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); + memoryManager->trimCandidateList.resize(0); + memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim); - EXPECT_EQ(20u, mm->lastPeriodicTrimFenceValue); + EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValue); } HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWithZeroSizeReturnsTrue) { SetUpMm(); - bool status = mm->trimResidencyToBudget(0); + bool status = memoryManager->trimResidencyToBudget(0); EXPECT_TRUE(status); } @@ -1083,19 +1122,19 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) { mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - mm->trimResidencyToBudget(3 * 4096); + memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); - EXPECT_EQ(1u, mm->trimCandidatesCount); - mm->compactTrimCandidateList(); - EXPECT_EQ(1u, mm->trimCandidateList.size()); + EXPECT_EQ(1u, memoryManager->trimCandidatesCount); + memoryManager->compactTrimCandidateList(); + EXPECT_EQ(1u, memoryManager->trimCandidateList.size()); EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition()); EXPECT_EQ(trimListUnusedPosition, allocation2.getTrimCandidateListPosition()); @@ -1114,14 +1153,14 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToT wddm->getMonitoredFence().lastSubmittedFence = 1; mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation1); - bool status = mm->trimResidencyToBudget(3 * 4096); + bool status = memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); - EXPECT_EQ(0u, mm->trimCandidateList.size()); + EXPECT_EQ(0u, memoryManager->trimCandidateList.size()); EXPECT_FALSE(status); } @@ -1147,17 +1186,17 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesTo mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - bool status = mm->trimResidencyToBudget(3 * 4096); + bool status = memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_TRUE(status); EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); - EXPECT_EQ(1u, mm->trimCandidateList.size()); + EXPECT_EQ(1u, memoryManager->trimCandidateList.size()); EXPECT_EQ(trimListUnusedPosition, allocation1.getTrimCandidateListPosition()); EXPECT_EQ(trimListUnusedPosition, allocation2.getTrimCandidateListPosition()); @@ -1184,13 +1223,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonRe mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - bool status = mm->trimResidencyToBudget(3 * 4096); + bool status = memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_FALSE(allocation1.getResidencyData().resident); EXPECT_FALSE(allocation2.getResidencyData().resident); @@ -1212,13 +1251,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs mockWddm->makeNonResidentResult.called = 0; mockWddm->waitFromCpuResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation1); gdi.getWaitFromCpuArg().hDevice = (D3DKMT_HANDLE)0; - bool status = mm->trimResidencyToBudget(3 * 4096); + bool status = memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_EQ(1u, mockWddm->makeNonResidentResult.called); EXPECT_FALSE(allocation1.getResidencyData().resident); @@ -1240,7 +1279,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { allocation2.getResidencyData().resident = true; void *ptrTriple = reinterpret_cast(reinterpret_cast(ptr) + 0x500); - WddmAllocation *allocationTriple = static_cast(mm->allocateGraphicsMemory(8196, ptrTriple)); + WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptrTriple)); allocationTriple->getResidencyData().lastFence = 1; allocationTriple->getResidencyData().resident = true; @@ -1255,11 +1294,11 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { // This should not be evicted allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->lastFence = 2; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(allocationTriple); - mm->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(allocationTriple); + memoryManager->addToTrimCandidateList(&allocation2); *wddm->getMonitoredFence().cpuAddress = 1; wddm->getMonitoredFence().lastSubmittedFence = 1; @@ -1267,7 +1306,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { mockWddm->makeNonResidentResult.called = 0; - bool status = mm->trimResidencyToBudget(3 * 4096); + bool status = memoryManager->trimResidencyToBudget(3 * 4096); EXPECT_EQ(2u, mockWddm->makeNonResidentResult.called); @@ -1275,29 +1314,29 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident); EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident); - mm->freeGraphicsMemory(allocationTriple); + memoryManager->freeGraphicsMemory(allocationTriple); } HWTEST_F(WddmMemoryManagerResidencyTest, checkTrimCandidateListCompaction) { SetUpMm(); - mm->trimCandidatesCount = 10; - mm->trimCandidateList.resize(20); + memoryManager->trimCandidatesCount = 10; + memoryManager->trimCandidateList.resize(20); - bool comapctionRequired = mm->checkTrimCandidateListCompaction(); + bool comapctionRequired = memoryManager->checkTrimCandidateListCompaction(); EXPECT_TRUE(comapctionRequired); - mm->trimCandidatesCount = 5; - mm->trimCandidateList.resize(20); + memoryManager->trimCandidatesCount = 5; + memoryManager->trimCandidateList.resize(20); - comapctionRequired = mm->checkTrimCandidateListCompaction(); + comapctionRequired = memoryManager->checkTrimCandidateListCompaction(); EXPECT_TRUE(comapctionRequired); - mm->trimCandidatesCount = 18; - mm->trimCandidateList.resize(20); + memoryManager->trimCandidatesCount = 18; + memoryManager->trimCandidateList.resize(20); - comapctionRequired = mm->checkTrimCandidateListCompaction(); + comapctionRequired = memoryManager->checkTrimCandidateListCompaction(); EXPECT_FALSE(comapctionRequired); } @@ -1336,13 +1375,13 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerT mockWddm->makeNonResidentResult.called = 0; - mm->trimCandidateList.resize(0); + memoryManager->trimCandidateList.resize(0); - mm->addToTrimCandidateList(&allocation1); - mm->addToTrimCandidateList(&allocation2); - mm->addToTrimCandidateList(&allocation3); + memoryManager->addToTrimCandidateList(&allocation1); + memoryManager->addToTrimCandidateList(&allocation2); + memoryManager->addToTrimCandidateList(&allocation3); - bool status = mm->trimResidencyToBudget(budget); + bool status = memoryManager->trimResidencyToBudget(budget); EXPECT_TRUE(status); EXPECT_FALSE(allocation1.getResidencyData().resident); @@ -1380,13 +1419,13 @@ HWTEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFille OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = (void *)0x1000; storage.fragmentStorageData[0].fragmentSize = MemoryConstants::pageSize; - mm->populateOsHandles(storage); + memoryManager->populateOsHandles(storage); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage); EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage->gmm); EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage); EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage); storage.fragmentStorageData[0].freeTheFragment = true; - mm->cleanOsHandles(storage); + memoryManager->cleanOsHandles(storage); } HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) { @@ -1394,9 +1433,9 @@ HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsk WddmMock *mockWddm = static_cast(wddm); auto ptr = reinterpret_cast(mockWddm->virtualAllocAddress + 0x1001); auto size = MemoryConstants::pageSize * 10; - auto graphicsAllocation = mm->allocateGraphicsMemory(size, ptr); + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr); - auto &hostPtrManager = mm->hostPtrManager; + auto &hostPtrManager = memoryManager->hostPtrManager; ASSERT_EQ(3u, hostPtrManager.getFragmentCount()); @@ -1415,7 +1454,7 @@ HWTEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsk EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->gmm->resourceParams.BaseWidth); } - mm->freeGraphicsMemory(graphicsAllocation); + memoryManager->freeGraphicsMemory(graphicsAllocation); EXPECT_EQ(0u, hostPtrManager.getFragmentCount()); } @@ -1436,7 +1475,7 @@ HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAlloca handleStorage.fragmentStorageData[1].fragmentSize = size * 2; handleStorage.fragmentStorageData[2].fragmentSize = size * 3; - auto allocation = mm->createGraphicsAllocation(handleStorage, size, ptr); + auto allocation = memoryManager->createGraphicsAllocation(handleStorage, size, ptr); EXPECT_EQ(ptr, allocation->getUnderlyingBuffer()); EXPECT_EQ(size, allocation->getUnderlyingBufferSize()); @@ -1450,7 +1489,7 @@ HWTEST_F(BufferWithWddmMemory, GivenPointerAndSizeWhenAskedToCreateGrahicsAlloca EXPECT_EQ(size * 3, allocation->fragmentsStorage.fragmentStorageData[2].fragmentSize); EXPECT_NE(&allocation->fragmentsStorage, &handleStorage); - mm->freeGraphicsMemory(allocation); + memoryManager->freeGraphicsMemory(allocation); } HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllocationsResidentWhenMakeResidentFails) { @@ -1462,12 +1501,12 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllo ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(&allocation2); - mm->pushAllocationForResidency(&allocation3); - mm->pushAllocationForResidency(&allocation4); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation3); + memoryManager->pushAllocationForResidency(&allocation4); - bool result = mm->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_FALSE(result); @@ -1481,7 +1520,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTrip SetUpMm(); WddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(wddm->getWddmMinAddress() + 0x1500); - WddmAllocation *allocationTriple = static_cast(mm->allocateGraphicsMemory(8196, ptr)); + WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptr)); ASSERT_NE(nullptr, allocationTriple); auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; }; @@ -1489,11 +1528,11 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTrip ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(allocationTriple); - mm->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(allocationTriple); + memoryManager->pushAllocationForResidency(&allocation2); - bool result = mm->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_FALSE(result); @@ -1501,7 +1540,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTrip EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[i].residency->resident); } - mm->freeGraphicsMemory(allocationTriple); + memoryManager->freeGraphicsMemory(allocationTriple); } HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeResidentFailsAndCantTrimFurther) { @@ -1513,12 +1552,12 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeRe ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2); - mm->pushAllocationForResidency(&allocation1); - mm->pushAllocationForResidency(&allocation2); - mm->pushAllocationForResidency(&allocation3); - mm->pushAllocationForResidency(&allocation4); + memoryManager->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation2); + memoryManager->pushAllocationForResidency(&allocation3); + memoryManager->pushAllocationForResidency(&allocation4); - bool result = mm->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_FALSE(result); @@ -1538,9 +1577,9 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeReside EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, false, ::testing::_)).Times(1); EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, true, ::testing::_)).Times(1); - mm->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation1); - bool result = mm->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_FALSE(result); } @@ -1566,8 +1605,8 @@ HWTEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResid ON_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(makeResidentWithOutBytesToTrim)); EXPECT_CALL(*wddm, makeResident(::testing::_, 2, false, ::testing::_)).Times(1); - mm->pushAllocationForResidency(&allocation3); - bool result = mm->makeResidentResidencyAllocations(&residencyPack); + memoryManager->pushAllocationForResidency(&allocation3); + bool result = memoryManager->makeResidentResidencyAllocations(&residencyPack); EXPECT_TRUE(result); } @@ -1584,11 +1623,11 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMak EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(makeResidentWithOutBytesToTrim)).WillOnce(::testing::Return(true)); - mm->addToTrimCandidateList(&allocationToTrim); + memoryManager->addToTrimCandidateList(&allocationToTrim); - mm->pushAllocationForResidency(&allocation1); + memoryManager->pushAllocationForResidency(&allocation1); - bool result = mm->makeResidentResidencyAllocations(nullptr); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); EXPECT_TRUE(result); @@ -1604,9 +1643,9 @@ HWTEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemo EXPECT_CALL(*wddm, makeResident(::testing::_, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(makeResidentThatFails)).WillOnce(::testing::Invoke(makeResidentThatSucceds)); - mm->pushAllocationForResidency(&allocation1); - bool result = mm->makeResidentResidencyAllocations(nullptr); - EXPECT_TRUE(mm->isMemoryBudgetExhausted()); + memoryManager->pushAllocationForResidency(&allocation1); + bool result = memoryManager->makeResidentResidencyAllocations(nullptr); + EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted()); } TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { @@ -1843,7 +1882,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpu EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(1).WillOnce(Invoke([&](const GMM_DDI_UPDATEAUXTABLE *arg) {givenDdiUpdateAuxTable = *arg; return GMM_SUCCESS; })); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false); + auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false, false); ASSERT_TRUE(result); EXPECT_EQ(Gmm::canonize(wddm.getAdapterInfo()->GfxPartition.Standard.Base), gpuVa); @@ -1904,7 +1943,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenMapped EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false); + auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false, false); ASSERT_TRUE(result); } @@ -1915,7 +1954,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRet WddmMock wddm; EXPECT_TRUE(wddm.init()); - auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), 0, nullptr, 3, gpuVa, false, false); + auto result = wddm.mapGpuVirtualAddressImpl(gmm.get(), 0, nullptr, 3, gpuVa, false, false, false); ASSERT_FALSE(result); } @@ -1938,7 +1977,7 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUn EXPECT_CALL(*mockMngr, updateAuxTable(_)).Times(0); - auto result = wddm->mapGpuVirtualAddressImpl(myGmm, ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false); + auto result = wddm->mapGpuVirtualAddressImpl(myGmm, ALLOCATION_HANDLE, nullptr, 3, gpuVa, false, false, false); EXPECT_TRUE(result); memoryManager.freeGraphicsMemory(wddmAlloc); } diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 0ec8e530d1..a1c0767f49 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -39,7 +39,7 @@ using namespace ::testing; class WddmMemoryManagerFixture : public MemoryManagementFixture, public WddmFixture { public: - WddmMemoryManager *mm = nullptr; + WddmMemoryManager *memoryManager = nullptr; virtual void SetUp(); @@ -52,15 +52,15 @@ class WddmMemoryManagerFixture : public MemoryManagementFixture, public WddmFixt heap32Base = 0x1000; } mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - mm = new (std::nothrow) WddmMemoryManager(false, wddm); + memoryManager = new (std::nothrow) WddmMemoryManager(false, wddm); //assert we have memory manager - ASSERT_NE(nullptr, mm); + ASSERT_NE(nullptr, memoryManager); } virtual void TearDown() { WddmMock *mockWddm = static_cast(this->wddm); EXPECT_EQ(0, mockWddm->reservedAddresses.size()); - delete mm; + delete memoryManager; this->wddm = nullptr; WddmFixture::TearDown(); MemoryManagementFixture::TearDown(); @@ -71,7 +71,7 @@ typedef ::Test WddmMemoryManagerTest; class MockWddmMemoryManagerFixture : public WddmFixture { public: - MockWddmMemoryManager *mm = nullptr; + MockWddmMemoryManager *memoryManager = nullptr; virtual void SetUp() { WddmFixture::SetUp(&gdi); @@ -87,15 +87,15 @@ class MockWddmMemoryManagerFixture : public WddmFixture { heap32Base = 0x1000; } mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - mm = new (std::nothrow) MockWddmMemoryManager(wddm); + memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm); //assert we have memory manager - ASSERT_NE(nullptr, mm); + ASSERT_NE(nullptr, memoryManager); } virtual void TearDown() { WddmMock *mockWddm = static_cast(this->wddm); EXPECT_EQ(0, mockWddm->reservedAddresses.size()); - delete mm; + delete memoryManager; this->wddm = nullptr; WddmFixture::TearDown(); } @@ -131,7 +131,7 @@ class GmockWddm : public Wddm { class WddmMemoryManagerFixtureWithGmockWddm { public: - MockWddmMemoryManager *mm = nullptr; + MockWddmMemoryManager *memoryManager = nullptr; void SetUp() { // wddm is deleted by memory manager @@ -142,12 +142,12 @@ class WddmMemoryManagerFixtureWithGmockWddm { template void SetUpMm() { wddm->init(); - mm = new (std::nothrow) MockWddmMemoryManager(wddm); + memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm); //assert we have memory manager - ASSERT_NE(nullptr, mm); + ASSERT_NE(nullptr, memoryManager); } void TearDown() { - delete mm; + delete memoryManager; wddm = nullptr; } @@ -174,10 +174,10 @@ class BufferWithWddmMemory : public ::testing::Test, heap32Base = 0x1000; } mockWddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - mm = new (std::nothrow) WddmMemoryManager(false, wddm); + memoryManager = new (std::nothrow) WddmMemoryManager(false, wddm); //assert we have memory manager - ASSERT_NE(nullptr, mm); - context.setMemoryManager(mm); + ASSERT_NE(nullptr, memoryManager); + context.setMemoryManager(memoryManager); flags = 0; } diff --git a/unit_tests/os_interface/windows/wddm_tests.cpp b/unit_tests/os_interface/windows/wddm_tests.cpp index 09f13e034c..aa7dc03f1a 100644 --- a/unit_tests/os_interface/windows/wddm_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_tests.cpp @@ -162,7 +162,7 @@ HWTEST_F(WddmTest, givenAllocationSmallerUnderlyingThanAlignedSizeWhenCreatedThe EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_NE(0, allocation.handle); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false); + bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false, false); EXPECT_TRUE(ret); EXPECT_EQ(alignedPages, getLastCallMapGpuVaArgFcn()->SizeInPages); @@ -201,7 +201,7 @@ HWTEST_F(WddmTest, createAllocation32bit) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.handle != 0); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false); + bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false, false); EXPECT_TRUE(ret); EXPECT_EQ(1u, wddmMock->mapGpuVirtualAddressResult.called); @@ -265,7 +265,7 @@ HWTEST_F(WddmTest, mapAndFreeGpuVa) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.handle != 0); - auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false); + auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false, false); EXPECT_TRUE(error); EXPECT_TRUE(allocation.gpuPtr != 0); @@ -294,7 +294,7 @@ HWTEST_F(WddmTest, givenNullAllocationWhenCreateThenAllocateAndMap) { auto status = wddm->createAllocation(&allocation); EXPECT_EQ(STATUS_SUCCESS, status); - bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false); + bool ret = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getAlignedSize(), allocation.is32BitAllocation, false, false); EXPECT_TRUE(ret); EXPECT_NE(0u, allocation.gpuPtr); @@ -321,7 +321,7 @@ HWTEST_F(WddmTest, makeResidentNonResident) { EXPECT_EQ(STATUS_SUCCESS, status); EXPECT_TRUE(allocation.handle != 0); - auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false); + auto error = wddm->mapGpuVirtualAddress(&allocation, allocation.getAlignedCpuPtr(), allocation.getUnderlyingBufferSize(), false, false, false); EXPECT_TRUE(error); EXPECT_TRUE(allocation.gpuPtr != 0);