From 296634f5b8c7fee34217310fcce8bc90ed48b717 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 12 May 2021 13:58:40 +0000 Subject: [PATCH] Fallback to CPU copy when blit copy fails Related-To: NEO-5733 Signed-off-by: Mateusz Jablonski --- .../memory_manager/memory_manager_tests.cpp | 22 +++++++++++++++++++ .../source/memory_manager/memory_manager.cpp | 7 +++--- 2 files changed, 26 insertions(+), 3 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 04e82f3f10..97631ee688 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -2600,3 +2600,25 @@ TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivat EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(GraphicsAllocation::AllocationType::SCRATCH_SURFACE)); EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(GraphicsAllocation::AllocationType::PRIVATE_SURFACE)); } + +TEST(MemoryTransferHelperTest, WhenBlitterIsSelectedButBlitCopyFailsThenFallbackToCopyOnCPU) { + constexpr uint32_t dataSize = 16; + uint8_t destData[dataSize] = {}; + uint8_t srcData[dataSize] = {}; + for (uint8_t i = 0u; i < dataSize; i++) { + srcData[i] = i; + } + MockGraphicsAllocation graphicsAllocation{destData, sizeof(destData)}; + graphicsAllocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); + + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = false; + + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + + EXPECT_EQ(BlitOperationResult::Unsupported, BlitHelperFunctions::blitMemoryToAllocation(*device, &graphicsAllocation, 0, srcData, {dataSize, 1, 1})); + + auto result = MemoryTransferHelper::transferMemoryToAllocation(true, *device, &graphicsAllocation, 0u, srcData, dataSize); + EXPECT_TRUE(result); + EXPECT_EQ(0, memcmp(destData, srcData, dataSize)); +} \ No newline at end of file diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 9cf6ce4cbc..f5b884b146 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -776,9 +776,10 @@ bool MemoryManager::isAllocationTypeToCapture(GraphicsAllocation::AllocationType bool MemoryTransferHelper::transferMemoryToAllocation(bool useBlitter, const Device &device, GraphicsAllocation *dstAllocation, size_t dstOffset, const void *srcMemory, size_t srcSize) { if (useBlitter) { - return (BlitHelperFunctions::blitMemoryToAllocation(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}) == BlitOperationResult::Success); - } else { - return device.getMemoryManager()->copyMemoryToAllocation(dstAllocation, dstOffset, srcMemory, srcSize); + if (BlitHelperFunctions::blitMemoryToAllocation(device, dstAllocation, dstOffset, srcMemory, {srcSize, 1, 1}) == BlitOperationResult::Success) { + return true; + } } + return device.getMemoryManager()->copyMemoryToAllocation(dstAllocation, dstOffset, srcMemory, srcSize); } } // namespace NEO