From 56c05a2f080ce7faff25c898239ee87cec20afc2 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Wed, 3 Nov 2021 19:27:47 +0000 Subject: [PATCH] Update allocateGraphicsMemoryWithAlignment Allocate Gmm object when the allocation uses compression. Signed-off-by: Filip Hazubski --- .../memory_manager/memory_manager_tests.cpp | 38 +++++++++++++++++++ .../os_agnostic_memory_manager.cpp | 34 ++++++++++++----- .../xe_hp_core/test_traits_xe_hp_core.h | 3 +- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 35be2f5d1b..fb8662b0e1 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -996,15 +996,53 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall memoryManager.freeGraphicsMemory(allocation); } +TEST(OsAgnosticMemoryManager, givenCompressionEnabledWhenAllocateGraphicsMemoryWithAlignmentIsCalledThenGmmIsAllocated) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.RenderCompressedBuffersEnabled.set(true); + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); + MockMemoryManager memoryManager(true, false, executionEnvironment); + AllocationData allocationData; + allocationData.size = 4096u; + allocationData.alignment = MemoryConstants::pageSize; + allocationData.flags.preferRenderCompressed = true; + auto allocation = memoryManager.allocateGraphicsMemoryWithAlignment(allocationData); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + EXPECT_NE(nullptr, allocation->getDefaultGmm()); + EXPECT_EQ(true, allocation->getDefaultGmm()->isCompressionEnabled); + EXPECT_EQ(MemoryConstants::pageSize, allocation->getDefaultGmm()->resourceParams.BaseAlignment); + memoryManager.freeGraphicsMemory(allocation); +} + TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.initGmm(); MockMemoryManager memoryManager(true, false, executionEnvironment); AllocationData allocationData; allocationData.size = 4096u; + allocationData.alignment = MemoryConstants::pageSize; auto allocation = memoryManager.allocateGraphicsMemory64kb(allocationData); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); + EXPECT_EQ(MemoryConstants::pageSize64k, allocation->getDefaultGmm()->resourceParams.BaseAlignment); + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledAndCompressionEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.RenderCompressedBuffersEnabled.set(true); + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.initGmm(); + MockMemoryManager memoryManager(true, false, executionEnvironment); + AllocationData allocationData; + allocationData.size = 4096u; + allocationData.alignment = MemoryConstants::pageSize; + allocationData.flags.preferRenderCompressed = true; + auto allocation = memoryManager.allocateGraphicsMemory64kb(allocationData); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); + EXPECT_GT(allocation->getDefaultGmm()->resourceParams.BaseAlignment, MemoryConstants::pageSize); memoryManager.freeGraphicsMemory(allocation); } diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.cpp b/shared/source/memory_manager/os_agnostic_memory_manager.cpp index 2fc94aa38a..07b1d281a5 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/shared/source/memory_manager/os_agnostic_memory_manager.cpp @@ -102,6 +102,20 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment if (allocationData.type == GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA) { memoryAllocation->storageInfo = allocationData.storageInfo; } + + auto pHwInfo = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHardwareInfo(); + if (HwHelper::get(pHwInfo->platform.eRenderCoreFamily).renderCompressedBuffersSupported(*pHwInfo) && + allocationData.flags.preferRenderCompressed) { + auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), + allocationData.hostPtr, + sizeAligned, + alignment, + allocationData.flags.uncacheable, + true, + allocationData.flags.useSystemMemory, + allocationData.storageInfo); + memoryAllocation->setDefaultGmm(gmm.release()); + } } counter++; return memoryAllocation; @@ -142,15 +156,17 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al auto memoryAllocation = allocateGraphicsMemoryWithAlignment(allocationDataAlign); if (memoryAllocation) { static_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); - auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), - allocationData.hostPtr, - allocationDataAlign.size, - allocationDataAlign.alignment, - allocationData.flags.uncacheable, - allocationData.flags.preferRenderCompressed, - allocationData.flags.useSystemMemory, - allocationData.storageInfo); - memoryAllocation->setDefaultGmm(gmm.release()); + if (memoryAllocation->getDefaultGmm() == nullptr) { + auto gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), + allocationData.hostPtr, + allocationDataAlign.size, + allocationDataAlign.alignment, + allocationData.flags.uncacheable, + allocationData.flags.preferRenderCompressed, + allocationData.flags.useSystemMemory, + allocationData.storageInfo); + memoryAllocation->setDefaultGmm(gmm.release()); + } } return memoryAllocation; } diff --git a/shared/test/common/xe_hp_core/test_traits_xe_hp_core.h b/shared/test/common/xe_hp_core/test_traits_xe_hp_core.h index 773552844d..d00a43638e 100644 --- a/shared/test/common/xe_hp_core/test_traits_xe_hp_core.h +++ b/shared/test/common/xe_hp_core/test_traits_xe_hp_core.h @@ -13,7 +13,8 @@ struct TestTraits { static constexpr bool surfaceStateCompressionParamsSupported = true; static constexpr bool clearColorAddressMatcher = true; static constexpr bool auxBuiltinsSupported = true; - static constexpr bool compressionAubsSupported = true; + static constexpr bool localMemCompressionAubsSupported = true; + static constexpr bool systemMemCompressionAubsSupported = false; static constexpr bool l3ControlSupported = true; static constexpr bool forceNonCoherentSupported = true; static constexpr bool threadPreemptionDisableBitMatcher = true;