diff --git a/runtime/command_queue/cpu_data_transfer_handler.cpp b/runtime/command_queue/cpu_data_transfer_handler.cpp index 783bd836a5..344cc2da74 100644 --- a/runtime/command_queue/cpu_data_transfer_handler.cpp +++ b/runtime/command_queue/cpu_data_transfer_handler.cpp @@ -85,6 +85,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie // read/write buffers are always blocking if (!blockQueue || transferProperties.blocking) { err.set(Event::waitForEvents(eventsRequest.numEventsInWaitList, eventsRequest.eventWaitList)); + bool modifySimulationFlags = false; if (outEventObj) { outEventObj->setSubmitTimeStamp(); @@ -123,9 +124,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie eventCompleted = true; } if (!unmapInfo.readOnly) { - auto graphicsAllocation = transferProperties.memObj->getGraphicsAllocation(); - graphicsAllocation->setAubWritable(true, GraphicsAllocation::defaultBank); - graphicsAllocation->setTbxWritable(true, GraphicsAllocation::defaultBank); + modifySimulationFlags = true; } break; case CL_COMMAND_READ_BUFFER: @@ -135,6 +134,7 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie case CL_COMMAND_WRITE_BUFFER: memcpy_s(transferProperties.getCpuPtrForReadWrite(), transferProperties.size[0], transferProperties.ptr, transferProperties.size[0]); eventCompleted = true; + modifySimulationFlags = true; break; case CL_COMMAND_MARKER: break; @@ -152,6 +152,11 @@ void *CommandQueue::cpuDataTransferHandler(TransferProperties &transferPropertie outEventObj->updateExecutionStatus(); } } + if (modifySimulationFlags) { + auto graphicsAllocation = transferProperties.memObj->getGraphicsAllocation(); + graphicsAllocation->setAubWritable(true, GraphicsAllocation::defaultBank); + graphicsAllocation->setTbxWritable(true, GraphicsAllocation::defaultBank); + } } if (context->isProvidingPerformanceHints()) { diff --git a/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp b/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp index c5a3a3478f..21f266e6cb 100644 --- a/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp +++ b/unit_tests/command_queue/enqueue_unmap_memobject_tests.cpp @@ -214,6 +214,28 @@ HWTEST_F(EnqueueUnmapMemObjTest, givenEnqueueUnmapMemObjectWhenNonAubWritableBuf EXPECT_TRUE(buffer->getGraphicsAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); } +HWTEST_F(EnqueueUnmapMemObjTest, givenWriteBufferIsServicedOnCPUWhenBufferIsNonAubTbxWriteableThanFlagsChange) { + DebugManagerStateRestore restorer; + DebugManager.flags.DoCpuCopyOnWriteBuffer.set(true); + auto buffer = std::unique_ptr(BufferHelper<>::create()); + ASSERT_NE(nullptr, buffer); + buffer->getGraphicsAllocation()->setAubWritable(false, GraphicsAllocation::defaultBank); + buffer->getGraphicsAllocation()->setTbxWritable(false, GraphicsAllocation::defaultBank); + + EXPECT_FALSE(buffer->getGraphicsAllocation()->isAubWritable(GraphicsAllocation::defaultBank)); + EXPECT_FALSE(buffer->getGraphicsAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); + + auto ptr = allocateAlignedMemory(buffer->getSize(), MemoryConstants::cacheLineSize); + + retVal = pCmdQ->enqueueWriteBuffer(buffer.get(), true, 0u, buffer->getSize(), ptr.get(), nullptr, 0u, nullptr, nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_EQ(0, memcmp(ptr.get(), buffer->getGraphicsAllocation()->getUnderlyingBuffer(), buffer->getSize())); + + EXPECT_TRUE(buffer->getGraphicsAllocation()->isAubWritable(GraphicsAllocation::defaultBank)); + EXPECT_TRUE(buffer->getGraphicsAllocation()->isTbxWritable(GraphicsAllocation::defaultBank)); +} + HWTEST_F(EnqueueUnmapMemObjTest, givenMemObjWhenUnmappingThenSetAubWritableBeforeEnqueueWrite) { DebugManagerStateRestore restore; DebugManager.flags.DisableZeroCopyForBuffers.set(true);