diff --git a/runtime/built_ins/builtins_dispatch_builder.h b/runtime/built_ins/builtins_dispatch_builder.h index e8599d962a..c2a8f43d61 100644 --- a/runtime/built_ins/builtins_dispatch_builder.h +++ b/runtime/built_ins/builtins_dispatch_builder.h @@ -38,6 +38,7 @@ struct BuiltinOpParams { GraphicsAllocation *srcSvmAlloc = nullptr; GraphicsAllocation *dstSvmAlloc = nullptr; GraphicsAllocation *mapAllocation = nullptr; + GraphicsAllocation *hostPtrAllocation = nullptr; const MemObjsForAuxTranslation *memObjsForAuxTranslation = nullptr; AuxTranslationDirection auxTranslationDirection = AuxTranslationDirection::None; bool unifiedMemoryArgsRequireMemSync = true; diff --git a/runtime/command_queue/enqueue_read_buffer.h b/runtime/command_queue/enqueue_read_buffer.h index 5f83db1183..9958151597 100644 --- a/runtime/command_queue/enqueue_read_buffer.h +++ b/runtime/command_queue/enqueue_read_buffer.h @@ -93,6 +93,7 @@ cl_int CommandQueueHw::enqueueReadBuffer( dc.srcOffset = {offset, 0, 0}; dc.size = {size, 0, 0}; dc.mapAllocation = mapAllocation; + dc.hostPtrAllocation = hostPtrSurf.getAllocation(); builder.buildDispatchInfos(dispatchInfo, dc); if (context->isProvidingPerformanceHints()) { diff --git a/runtime/command_queue/enqueue_write_buffer.h b/runtime/command_queue/enqueue_write_buffer.h index abd66ec8ea..fdfa831b29 100644 --- a/runtime/command_queue/enqueue_write_buffer.h +++ b/runtime/command_queue/enqueue_write_buffer.h @@ -89,6 +89,7 @@ cl_int CommandQueueHw::enqueueWriteBuffer( dc.dstOffset = {offset, 0, 0}; dc.size = {size, 0, 0}; dc.mapAllocation = mapAllocation; + dc.hostPtrAllocation = hostPtrSurf.getAllocation(); builder.buildDispatchInfos(dispatchInfo, dc); enqueueHandler( diff --git a/runtime/helpers/blit_commands_helper.cpp b/runtime/helpers/blit_commands_helper.cpp index 46b1bdf7bb..83804b8eed 100644 --- a/runtime/helpers/blit_commands_helper.cpp +++ b/runtime/helpers/blit_commands_helper.cpp @@ -46,7 +46,6 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons CommandStreamReceiver &commandStreamReceiver, const BuiltinOpParams &builtinOpParams, bool blocking) { - GraphicsAllocation *hostAllocation = builtinOpParams.mapAllocation; GraphicsAllocation *gpuAllocation = nullptr; size_t copyOffset = 0; size_t memObjOffset = 0; @@ -54,6 +53,11 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons void *hostPtr = nullptr; size_t hostPtrOffset = 0; + GraphicsAllocation *hostAllocation = builtinOpParams.hostPtrAllocation; + if (builtinOpParams.mapAllocation) { + hostAllocation = builtinOpParams.mapAllocation; + } + if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) { // write buffer if (builtinOpParams.dstSvmAlloc) { diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index d76f753220..cf85cce0c0 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -1168,7 +1168,18 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBlockingEnqueueWhenUsingBcsThenCallWait) cmdQ->enqueueWriteBuffer(buffer.get(), false, 0, 1, hostPtr, nullptr, 0, nullptr, nullptr); EXPECT_EQ(0u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled); EXPECT_FALSE(gpgpuCsr.getTemporaryAllocations().peekIsEmpty()); - EXPECT_FALSE(myMockCsr->getTemporaryAllocations().peekIsEmpty()); + EXPECT_TRUE(myMockCsr->getTemporaryAllocations().peekIsEmpty()); + + bool tempAllocationFound = false; + auto tempAllocation = gpgpuCsr.getTemporaryAllocations().peekHead(); + while (tempAllocation) { + if (tempAllocation->getUnderlyingBuffer() == hostPtr) { + tempAllocationFound = true; + break; + } + tempAllocation = tempAllocation->next; + } + EXPECT_TRUE(tempAllocationFound); cmdQ->enqueueWriteBuffer(buffer.get(), true, 0, 1, hostPtr, nullptr, 0, nullptr, nullptr); EXPECT_EQ(1u, myMockCsr->waitForTaskCountAndCleanAllocationListCalled);