diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 547a4e319b..fb3663bae2 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -187,14 +187,11 @@ Buffer *Buffer::create(Context *context, auto hwInfo = (&memoryManager->peekExecutionEnvironment())->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); - allocationInfo[rootDeviceIndex].allocationType = getGraphicsAllocationType( - memoryProperties, - *context, - HwHelper::renderCompressedBuffersSupported(*hwInfo), - memoryManager->isLocalMemorySupported(rootDeviceIndex), - HwHelper::get(hwInfo->platform.eRenderCoreFamily).isBufferSizeSuitableForRenderCompression(size, *hwInfo)); + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(HwHelper::renderCompressedBuffersSupported(*hwInfo), memoryProperties, *context, + HwHelper::get(hwInfo->platform.eRenderCoreFamily).isBufferSizeSuitableForRenderCompression(size, *hwInfo)); - bool preferCompressed = (allocationInfo[rootDeviceIndex].allocationType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); + allocationInfo[rootDeviceIndex].allocationType = getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, *context, compressionEnabled, + memoryManager->isLocalMemorySupported(rootDeviceIndex)); if (ptr) { if (!memoryProperties.flags.useHostPtr) { @@ -212,7 +209,7 @@ Buffer *Buffer::create(Context *context, return nullptr; } - if (preferCompressed) { + if (compressionEnabled) { allocationInfo[rootDeviceIndex].zeroCopyAllowed = false; allocationInfo[rootDeviceIndex].allocateMemory = true; } @@ -279,14 +276,14 @@ Buffer *Buffer::create(Context *context, allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(), *hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex), context->isSingleDeviceContext()); allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1; - allocProperties.flags.preferCompressed = preferCompressed; + allocProperties.flags.preferCompressed = compressionEnabled; allocationInfo[rootDeviceIndex].memory = memoryManager->createGraphicsAllocationFromExistingStorage(allocProperties, ptr, multiGraphicsAllocation); } else { AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(), *hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex), context->isSingleDeviceContext()); allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1; - allocProperties.flags.preferCompressed = preferCompressed; + allocProperties.flags.preferCompressed = compressionEnabled; allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); if (allocationInfo[rootDeviceIndex].memory) { ptr = reinterpret_cast(allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer()); @@ -326,6 +323,7 @@ Buffer *Buffer::create(Context *context, } } } else if (allocationInfo[rootDeviceIndex].allocationType == GraphicsAllocation::AllocationType::BUFFER) { + UNRECOVERABLE_IF(compressionEnabled); allocationInfo[rootDeviceIndex].allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } @@ -497,18 +495,19 @@ void Buffer::checkMemory(MemoryProperties memoryProperties, return; } -GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryProperties &properties, Context &context, - bool renderCompressedBuffers, bool isLocalMemoryEnabled, - bool preferCompression) { +GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationTypeAndCompressionPreference(const MemoryProperties &properties, Context &context, + bool &compressionEnabled, bool isLocalMemoryEnabled) { if (context.isSharedContext || properties.flags.forceHostMemory) { + compressionEnabled = false; return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } if (properties.flags.useHostPtr && !isLocalMemoryEnabled) { + compressionEnabled = false; return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } - if (MemObjHelper::isSuitableForRenderCompression(renderCompressedBuffers, properties, context, preferCompression)) { + if (compressionEnabled) { return GraphicsAllocation::AllocationType::BUFFER_COMPRESSED; } diff --git a/opencl/source/mem_obj/buffer.h b/opencl/source/mem_obj/buffer.h index 816f33d954..c8c3af3476 100644 --- a/opencl/source/mem_obj/buffer.h +++ b/opencl/source/mem_obj/buffer.h @@ -188,9 +188,8 @@ class Buffer : public MemObj { MemoryManager *memMngr, uint32_t rootDeviceIndex, bool forceCopyHostPtr); - static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryProperties &properties, Context &context, - bool renderCompressedBuffers, bool localMemoryEnabled, - bool preferCompression); + static GraphicsAllocation::AllocationType getGraphicsAllocationTypeAndCompressionPreference(const MemoryProperties &properties, Context &context, + bool &compressionEnabled, bool localMemoryEnabled); static bool isReadOnlyMemoryPermittedByFlags(const MemoryProperties &properties); void transferData(void *dst, void *src, size_t copySize, size_t copyOffset); diff --git a/opencl/source/memory_manager/compression_selector_ocl.cpp b/opencl/source/memory_manager/compression_selector_ocl.cpp index 904b09d8f7..fb7be0954b 100644 --- a/opencl/source/memory_manager/compression_selector_ocl.cpp +++ b/opencl/source/memory_manager/compression_selector_ocl.cpp @@ -11,8 +11,6 @@ namespace NEO { bool CompressionSelector::preferRenderCompressedBuffer(const AllocationProperties &properties, const HardwareInfo &hwInfo) { switch (properties.allocationType) { - case GraphicsAllocation::AllocationType::BUFFER_COMPRESSED: - return true; case GraphicsAllocation::AllocationType::GLOBAL_SURFACE: case GraphicsAllocation::AllocationType::CONSTANT_SURFACE: case GraphicsAllocation::AllocationType::SVM_GPU: diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 269728b464..5bc73ef794 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -22,6 +22,7 @@ #include "opencl/extensions/public/cl_ext_private.h" #include "opencl/source/command_queue/command_queue_hw.h" +#include "opencl/source/mem_obj/mem_obj_helper.h" #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" #include "opencl/test/unit_test/mocks/mock_buffer.h" @@ -426,7 +427,12 @@ TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenB MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_TRUE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } @@ -435,7 +441,12 @@ TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocatio MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, true, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, true); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } @@ -444,7 +455,12 @@ TEST(Buffer, givenSharedContextWhenAllocationTypeIsQueriedThenBufferHostMemoryTy MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = true; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } @@ -453,7 +469,12 @@ TEST(Buffer, givenSharedContextAndRenderCompressedBuffersEnabledWhenAllocationTy MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = true; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } @@ -463,7 +484,12 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQuerie MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } @@ -473,7 +499,12 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, true, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, true); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } @@ -483,7 +514,12 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } @@ -493,7 +529,12 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndRenderCompressedBuffers MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } @@ -503,7 +544,12 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersE MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, true, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, true); + EXPECT_TRUE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } @@ -513,7 +559,12 @@ TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemory MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, true, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, true); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } @@ -523,7 +574,12 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, true, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(true, memoryProperties, context, true); + EXPECT_TRUE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_TRUE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } @@ -532,7 +588,12 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhen MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.isSharedContext = false; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, context, false, false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(false, memoryProperties, context, true); + EXPECT_FALSE(compressionEnabled); + + auto type = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, context, compressionEnabled, false); + EXPECT_FALSE(compressionEnabled); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } diff --git a/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp index 9aee95e472..80863ca3be 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp @@ -346,8 +346,11 @@ TEST(MemObjHelper, givenDifferentCapabilityAndDebugFlagValuesWhenCheckingBufferC MockSpecializedContext context; auto &device = context.getDevice(0)->getDevice(); MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &device); - auto allocationType = MockPublicAccessBuffer::getGraphicsAllocationType( - memoryProperties, context, HwHelper::renderCompressedBuffersSupported(*defaultHwInfo), false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(HwHelper::renderCompressedBuffersSupported(*defaultHwInfo), memoryProperties, context, true); + + auto allocationType = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference( + memoryProperties, context, compressionEnabled, false); bool expectBufferCompressed = ftrRenderCompressedBuffers && (enableMultiTileCompressionValue == 1); if (expectBufferCompressed && clHwHelper.allowRenderCompressionForContext(*context.getDevice(0), context)) { @@ -405,8 +408,10 @@ TEST(MemObjHelper, givenDifferentValuesWhenCheckingBufferCompressionSupportThenC auto &device = context.getDevice(0)->getDevice(); MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, 0, &device); - auto allocationType = MockPublicAccessBuffer::getGraphicsAllocationType( - memoryProperties, context, HwHelper::renderCompressedBuffersSupported(*defaultHwInfo), false, true); + + bool compressionEnabled = MemObjHelper::isSuitableForRenderCompression(HwHelper::renderCompressedBuffersSupported(*defaultHwInfo), memoryProperties, context, true); + auto allocationType = MockPublicAccessBuffer::getGraphicsAllocationTypeAndCompressionPreference( + memoryProperties, context, compressionEnabled, false); bool isCompressionDisabled = isValueSet(flags, CL_MEM_UNCOMPRESSED_HINT_INTEL) || isValueSet(flagsIntel, CL_MEM_UNCOMPRESSED_HINT_INTEL); diff --git a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index 46fc9ebe66..bfe309b452 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -308,6 +308,7 @@ TEST(BaseMemoryManagerTest, givenDebugVariableSetWhenCompressedBufferIsCreatedTh AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, GraphicsAllocation::AllocationType::BUFFER, mockDeviceBitfield); AllocationProperties allocPropertiesBufferCompressed(mockRootDeviceIndex, 1, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield); + allocPropertiesBufferCompressed.flags.preferCompressed = true; DebugManager.flags.RenderCompressedBuffersEnabled.set(1); auto allocationBuffer = memoryManager.allocateGraphicsMemoryInPreferredPool(allocPropertiesBuffer, nullptr); diff --git a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp index b5b40b8ab3..d815ad3dbb 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp @@ -247,10 +247,13 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllow AllocationData allocData; AllocationProperties properties(mockRootDeviceIndex, 10, allocType, mockDeviceBitfield); + bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); + + properties.flags.preferCompressed = bufferCompressedType; + MockMemoryManager mockMemoryManager(true, false); mockMemoryManager.mockExecutionEnvironment->initGmm(); mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); - bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); EXPECT_TRUE(allocData.flags.allow64kbPages); auto allocation = mockMemoryManager.allocateGraphicsMemory(allocData); diff --git a/opencl/test/unit_test/mocks/mock_buffer.h b/opencl/test/unit_test/mocks/mock_buffer.h index efdf96392d..abfcb4c28f 100644 --- a/opencl/test/unit_test/mocks/mock_buffer.h +++ b/opencl/test/unit_test/mocks/mock_buffer.h @@ -138,5 +138,5 @@ class UnalignedBuffer : public MockBufferStorage, public Buffer { class MockPublicAccessBuffer : public Buffer { public: - using Buffer::getGraphicsAllocationType; + using Buffer::getGraphicsAllocationTypeAndCompressionPreference; }; diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 6c12129103..5f61ea3d43 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -758,7 +758,11 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemory } rootDeviceEnvironment->executionEnvironment.initializeMemoryManager(); memoryManager->allocateGraphicsMemoryInNonDevicePool = true; - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield}, ptr); + + MockAllocationProperties properties = {mockRootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, mockDeviceBitfield}; + properties.flags.preferCompressed = true; + + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, ptr); auto gfxPartition = memoryManager->getGfxPartition(mockRootDeviceIndex); D3DGPU_VIRTUAL_ADDRESS standard64kbRangeMinimumAddress = gfxPartition->getHeapMinimalAddress(HeapIndex::HEAP_STANDARD64KB); diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index 4e6d06405f..a15a921350 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -127,7 +127,8 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties) { size_t alignedSize = alignUp(size, MemoryConstants::pageSize64k); - GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(memoryProperties); + bool compressionEnabled = false; + GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled); std::vector rootDeviceIndicesVector(memoryProperties.rootDeviceIndices.begin(), memoryProperties.rootDeviceIndices.end()); @@ -141,6 +142,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size, false, (deviceBitfield.count() > 1) && multiOsContextSupport, deviceBitfield}; + unifiedMemoryProperties.flags.preferCompressed = compressionEnabled; unifiedMemoryProperties.flags.shareable = memoryProperties.allocationFlags.flags.shareable; unifiedMemoryProperties.flags.isUSMHostAllocation = true; unifiedMemoryProperties.flags.isUSMDeviceAllocation = false; @@ -176,7 +178,8 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size, size_t alignedSize = alignUp(size, MemoryConstants::pageSize64k); - GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(memoryProperties); + bool compressionEnabled = false; + GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationTypeAndCompressionPreference(memoryProperties, compressionEnabled); bool multiStorageAllocation = (deviceBitfield.count() > 1) && multiOsContextSupport; if ((deviceBitfield.count() > 1) && !multiOsContextSupport) { @@ -200,6 +203,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size, unifiedMemoryProperties.flags.shareable = memoryProperties.allocationFlags.flags.shareable; unifiedMemoryProperties.cacheRegion = MemoryPropertiesHelper::getCacheRegion(memoryProperties.allocationFlags); unifiedMemoryProperties.flags.uncacheable = memoryProperties.allocationFlags.flags.locallyUncachedResource; + unifiedMemoryProperties.flags.preferCompressed = compressionEnabled; if (memoryProperties.memoryType == InternalMemoryType::DEVICE_UNIFIED_MEMORY) { unifiedMemoryProperties.flags.isUSMDeviceAllocation = true; @@ -502,7 +506,9 @@ void SVMAllocsManager::removeSvmMapOperation(const void *regionSvmPtr) { svmMapOperations.remove(regionSvmPtr); } -GraphicsAllocation::AllocationType SVMAllocsManager::getGraphicsAllocationType(const UnifiedMemoryProperties &unifiedMemoryProperties) const { +GraphicsAllocation::AllocationType SVMAllocsManager::getGraphicsAllocationTypeAndCompressionPreference(const UnifiedMemoryProperties &unifiedMemoryProperties, bool &compressionEnabled) const { + compressionEnabled = false; + GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; if (unifiedMemoryProperties.memoryType == InternalMemoryType::DEVICE_UNIFIED_MEMORY) { if (unifiedMemoryProperties.allocationFlags.allocFlags.allocWriteCombined) { @@ -511,6 +517,7 @@ GraphicsAllocation::AllocationType SVMAllocsManager::getGraphicsAllocationType(c UNRECOVERABLE_IF(nullptr == unifiedMemoryProperties.device); const auto &hwInfoConfig = *HwInfoConfig::get(unifiedMemoryProperties.device->getHardwareInfo().platform.eProductFamily); if (hwInfoConfig.allowStatelessCompression(unifiedMemoryProperties.device->getHardwareInfo())) { + compressionEnabled = true; allocationType = GraphicsAllocation::AllocationType::BUFFER_COMPRESSED; } else { allocationType = GraphicsAllocation::AllocationType::BUFFER; diff --git a/shared/source/memory_manager/unified_memory_manager.h b/shared/source/memory_manager/unified_memory_manager.h index 381dc95f6e..304ba2499b 100644 --- a/shared/source/memory_manager/unified_memory_manager.h +++ b/shared/source/memory_manager/unified_memory_manager.h @@ -154,7 +154,7 @@ class SVMAllocsManager { void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties, const std::set &rootDeviceIndices, const std::map &subdeviceBitfields); - GraphicsAllocation::AllocationType getGraphicsAllocationType(const UnifiedMemoryProperties &unifiedMemoryProperties) const; + GraphicsAllocation::AllocationType getGraphicsAllocationTypeAndCompressionPreference(const UnifiedMemoryProperties &unifiedMemoryProperties, bool &compressionEnabled) const; void freeZeroCopySvmAllocation(SvmAllocationData *svmData);