From ced6c55caf78d58bd0fe650f8381a36bfd9a56b7 Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Tue, 29 Jul 2025 11:19:35 +0000 Subject: [PATCH] fix: use alignment when allocate by win kmd Signed-off-by: Maciej Plewka --- .../os_interface/windows/wddm_memory_manager.cpp | 2 +- shared/test/common/mocks/mock_wddm.cpp | 2 ++ shared/test/common/mocks/wddm_mock_helpers.h | 1 + .../windows/wddm_memory_manager_tests.cpp | 12 ++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index eca8db841b..1380c55248 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -169,7 +169,7 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData GmmRequirements gmmRequirements{}; gmmRequirements.allowLargePages = true; gmmRequirements.preferCompressed = allocationData.flags.preferCompressed; - auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), allocationData.hostPtr, allocationData.size, 0u, + auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), allocationData.hostPtr, allocationData.size, allocationData.alignment, CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable, productHelper, hwInfo), systemMemoryStorageInfo, gmmRequirements); auto allocation = std::make_unique(allocationData.rootDeviceIndex, 1u, // numGmms diff --git a/shared/test/common/mocks/mock_wddm.cpp b/shared/test/common/mocks/mock_wddm.cpp index d6ff588bdb..f35b3d37f0 100644 --- a/shared/test/common/mocks/mock_wddm.cpp +++ b/shared/test/common/mocks/mock_wddm.cpp @@ -9,6 +9,7 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/aligned_memory.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/os_environment_win.h" @@ -103,6 +104,7 @@ bool WddmMock::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTU mapGpuVirtualAddressResult.called++; mapGpuVirtualAddressResult.cpuPtrPassed = reinterpret_cast(preferredAddress); mapGpuVirtualAddressResult.uint64ParamPassed = preferredAddress; + mapGpuVirtualAddressResult.alignment = gmm->resourceParams.BaseAlignment; if (callBaseMapGpuVa) { return mapGpuVirtualAddressResult.success = Wddm::mapGpuVirtualAddress(gmm, handle, minimumAddress, maximumAddress, preferredAddress, gpuPtr, type); } else { diff --git a/shared/test/common/mocks/wddm_mock_helpers.h b/shared/test/common/mocks/wddm_mock_helpers.h index ba2c78e415..fb8b85bee7 100644 --- a/shared/test/common/mocks/wddm_mock_helpers.h +++ b/shared/test/common/mocks/wddm_mock_helpers.h @@ -18,6 +18,7 @@ namespace WddmMockHelpers { struct CallResult { uint32_t called = 0; uint64_t uint64ParamPassed = -1; + size_t alignment = 0; bool success = false; void *cpuPtrPassed = nullptr; }; 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 e2a64008f0..e91fd4d051 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 @@ -1183,6 +1183,18 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndHugeSizeWhenAskedToC memoryManager->freeGraphicsMemory(allocation); } +TEST_F(WddmMemoryManagerSimpleTest, GivenMemoryManagerWhenAllocateByKmdThenAlignmentIsCorrect) { + memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment)); + AllocationData allocationData; + allocationData.size = 2ULL * MemoryConstants::pageSize64k; + allocationData.flags.shareable = true; + allocationData.alignment = 8388608; + auto allocation = memoryManager->allocateMemoryByKMD(allocationData); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(static_cast(&memoryManager->getWddm(0u))->mapGpuVirtualAddressResult.alignment, allocationData.alignment); + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(WddmMemoryManagerSimpleTest, GivenShareableEnabledAndSmallSizeWhenAskedToCreatePhysicalGraphicsAllocationThenValidAllocationIsReturned) { memoryManager.reset(new MockWddmMemoryManager(false, false, executionEnvironment)); memoryManager->hugeGfxMemoryChunkSize = MemoryConstants::pageSize64k;