From 4d80f21dac9a39c2e64f921de586a4790d9c0e57 Mon Sep 17 00:00:00 2001 From: Pawel Wilma Date: Thu, 2 Apr 2020 10:52:36 +0200 Subject: [PATCH] Reuse mapAllocation for memory transfer during buffer creation Change-Id: Idcdabb4a9c61b5cbf69164c51ca1690a64665a26 Signed-off-by: Pawel Wilma --- opencl/source/mem_obj/buffer.cpp | 2 +- opencl/test/unit_test/mem_obj/buffer_tests.cpp | 10 ++++++++++ opencl/test/unit_test/mocks/mock_command_queue.h | 2 ++ opencl/test/unit_test/mocks/mock_memory_manager.cpp | 2 +- opencl/test/unit_test/mocks/mock_memory_manager.h | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index dcd91a999a..b4bc2c17fd 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -304,7 +304,7 @@ Buffer *Buffer::create(Context *context, if (blitMemoryToAllocationResult != BlitOperationResult::Success) { auto cmdQ = context->getSpecialQueue(); - if (CL_SUCCESS != cmdQ->enqueueWriteBuffer(pBuffer, CL_TRUE, 0, size, hostPtr, nullptr, 0, nullptr, nullptr)) { + if (CL_SUCCESS != cmdQ->enqueueWriteBuffer(pBuffer, CL_TRUE, 0, size, hostPtr, mapAllocation, 0, nullptr, nullptr)) { errcodeRet = CL_OUT_OF_RESOURCES; } } diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 3d13b5eecb..987d29a3e6 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -655,6 +655,16 @@ TEST_F(RenderCompressedBuffersCopyHostMemoryTests, givenRenderCompressedBufferWh EXPECT_EQ(CL_SUCCESS, retVal); } +TEST_F(RenderCompressedBuffersCopyHostMemoryTests, givenBufferCreateWhenMemoryTransferWithEnqueueWriteBufferThenMapAllocationIsReused) { + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR; + auto &capabilityTable = device->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable; + capabilityTable.blitterOperationsSupported = false; + static_cast(context->memoryManager)->forceRenderCompressed = true; + std::unique_ptr buffer(Buffer::create(context.get(), flags, bufferSize, hostPtr, retVal)); + EXPECT_NE(nullptr, mockCmdQ->writeMapAllocation); + EXPECT_EQ(buffer->getMapAllocation(), mockCmdQ->writeMapAllocation); +} + struct BcsBufferTests : public ::testing::Test { class BcsMockContext : public MockContext { public: diff --git a/opencl/test/unit_test/mocks/mock_command_queue.h b/opencl/test/unit_test/mocks/mock_command_queue.h index 9f6df29afe..9fd599920d 100644 --- a/opencl/test/unit_test/mocks/mock_command_queue.h +++ b/opencl/test/unit_test/mocks/mock_command_queue.h @@ -56,6 +56,7 @@ class MockCommandQueue : public CommandQueue { writeBufferOffset = offset; writeBufferSize = size; writeBufferPtr = const_cast(ptr); + writeMapAllocation = mapAllocation; return writeBufferRetValue; } @@ -178,6 +179,7 @@ class MockCommandQueue : public CommandQueue { size_t writeBufferSize = 0; void *writeBufferPtr = nullptr; size_t requestedCmdStreamSize = 0; + GraphicsAllocation *writeMapAllocation = nullptr; std::atomic latestTaskCountWaited{std::numeric_limits::max()}; }; diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.cpp b/opencl/test/unit_test/mocks/mock_memory_manager.cpp index 23043cae5f..6885768c9c 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.cpp +++ b/opencl/test/unit_test/mocks/mock_memory_manager.cpp @@ -58,7 +58,7 @@ GraphicsAllocation *MockMemoryManager::allocateShareableMemory(const AllocationD GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(const AllocationData &allocationData) { allocation64kbPageCreated = true; - preferRenderCompressedFlagPassed = allocationData.flags.preferRenderCompressed; + preferRenderCompressedFlagPassed = forceRenderCompressed ? true : allocationData.flags.preferRenderCompressed; auto allocation = OsAgnosticMemoryManager::allocateGraphicsMemory64kb(allocationData); if (allocation) { diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.h b/opencl/test/unit_test/mocks/mock_memory_manager.h index d56fe13fc4..8fb20e65c9 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.h +++ b/opencl/test/unit_test/mocks/mock_memory_manager.h @@ -129,6 +129,7 @@ class MockMemoryManager : public MemoryManagerCreate { bool failAllocateSystemMemory = false; bool failAllocate32Bit = false; bool cpuCopyRequired = false; + bool forceRenderCompressed = false; std::unique_ptr mockExecutionEnvironment; };