diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index b98d291e6d..665ef9a1be 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -969,9 +969,10 @@ AddressRange WddmMemoryManager::reserveGpuAddressOnHeap(const uint64_t requiredS *reservedOnRootDeviceIndex = 0; size_t reservedSize = 0; NTSTATUS status = STATUS_UNSUCCESSFUL; + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[*reservedOnRootDeviceIndex]->getGmmHelper(); for (auto rootDeviceIndex : rootDeviceIndices) { auto gfxPartition = getGfxPartition(rootDeviceIndex); - status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(requiredStartAddress, gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa); + status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(gmmHelper->decanonize(requiredStartAddress), gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa); if (requiredStartAddress != 0ull && status != STATUS_SUCCESS) { status = getWddm(rootDeviceIndex).reserveGpuVirtualAddress(0ull, gfxPartition->getHeapMinimalAddress(heap), gfxPartition->getHeapLimit(heap), size, &gpuVa); } @@ -984,7 +985,6 @@ AddressRange WddmMemoryManager::reserveGpuAddressOnHeap(const uint64_t requiredS if (status != STATUS_SUCCESS) { return AddressRange{0u, 0}; } - auto gmmHelper = executionEnvironment.rootDeviceEnvironments[*reservedOnRootDeviceIndex]->getGmmHelper(); gpuVa = gmmHelper->canonize(gpuVa); return AddressRange{gpuVa, reservedSize}; } diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index f0520f00d2..ce1f2c619a 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1245,6 +1245,31 @@ TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReserv memoryManager->freeGpuAddress(addressRange, 0); } +TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenGpuAddressIsReservedAndFreedThenRequestingTheSameAddressButCanonizedReturnedRequestedAddress) { + RootDeviceIndicesContainer rootDeviceIndices; + rootDeviceIndices.pushUnique(0); + uint32_t rootDeviceIndexReserved = 1; + HeapIndex heap = HeapIndex::heapStandard; + auto alignment = memoryManager->selectAlignmentAndHeap(MemoryConstants::pageSize64k, &heap); + EXPECT_EQ(heap, HeapIndex::heapStandard64KB); + EXPECT_EQ(MemoryConstants::pageSize64k, alignment); + auto addressRange = memoryManager->reserveGpuAddressOnHeap(0ull, MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved, heap, alignment); + auto gmmHelper = memoryManager->getGmmHelper(0); + EXPECT_EQ(0u, rootDeviceIndexReserved); + EXPECT_NE(0u, gmmHelper->decanonize(addressRange.address)); + EXPECT_EQ(MemoryConstants::pageSize64k, addressRange.size); + + const auto addressRangeOriginal = addressRange; + memoryManager->freeGpuAddress(addressRange, 0); + + addressRange = memoryManager->reserveGpuAddressOnHeap(gmmHelper->canonize(addressRangeOriginal.address), MemoryConstants::pageSize64k, rootDeviceIndices, &rootDeviceIndexReserved, heap, alignment); + EXPECT_EQ(0u, rootDeviceIndexReserved); + EXPECT_EQ(addressRangeOriginal.address, addressRange.address); + EXPECT_EQ(MemoryConstants::pageSize64k, addressRange.size); + + memoryManager->freeGpuAddress(addressRange, 0); +} + TEST_F(WddmMemoryManagerSimpleTest, givenWddmMemoryManagerWhenAllocatingWithGpuVaThenNullptrIsReturned) { AllocationData allocationData;