diff --git a/runtime/helpers/blit_commands_helper.cpp b/runtime/helpers/blit_commands_helper.cpp index d5b3aa2a11..48797202e2 100644 --- a/runtime/helpers/blit_commands_helper.cpp +++ b/runtime/helpers/blit_commands_helper.cpp @@ -17,8 +17,8 @@ namespace NEO { BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection, CommandStreamReceiver &commandStreamReceiver, - GraphicsAllocation *memObjAllocation, void *hostPtr, bool blocking, - size_t offset, uint64_t copySize) { + GraphicsAllocation *memObjAllocation, void *hostPtr, size_t hostPtrOffset, + bool blocking, size_t offset, uint64_t copySize) { HostPtrSurface hostPtrSurface(hostPtr, static_cast(copySize), true); bool success = commandStreamReceiver.createAllocationForHostSurface(hostPtrSurface, false); @@ -26,9 +26,9 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons auto hostPtrAllocation = hostPtrSurface.getAllocation(); if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) { - return {nullptr, blitDirection, {}, AuxTranslationDirection::None, memObjAllocation, hostPtrAllocation, hostPtr, blocking, offset, 0, copySize}; + return {nullptr, blitDirection, {}, AuxTranslationDirection::None, memObjAllocation, hostPtrAllocation, hostPtr, blocking, offset, hostPtrOffset, copySize}; } else { - return {nullptr, blitDirection, {}, AuxTranslationDirection::None, hostPtrAllocation, memObjAllocation, hostPtr, blocking, 0, offset, copySize}; + return {nullptr, blitDirection, {}, AuxTranslationDirection::None, hostPtrAllocation, memObjAllocation, hostPtr, blocking, hostPtrOffset, offset, copySize}; } } @@ -38,11 +38,11 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons bool blocking) { if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) { return constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, builtinOpParams.dstMemObj->getGraphicsAllocation(), - builtinOpParams.srcPtr, blocking, builtinOpParams.dstOffset.x, + builtinOpParams.srcPtr, builtinOpParams.srcOffset.x, blocking, builtinOpParams.dstOffset.x, builtinOpParams.size.x); } else { return constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, builtinOpParams.srcMemObj->getGraphicsAllocation(), - builtinOpParams.dstPtr, blocking, builtinOpParams.srcOffset.x, + builtinOpParams.dstPtr, builtinOpParams.dstOffset.x, blocking, builtinOpParams.srcOffset.x, builtinOpParams.size.x); } } diff --git a/runtime/helpers/blit_commands_helper.h b/runtime/helpers/blit_commands_helper.h index 14ee842389..3c5e0306a2 100644 --- a/runtime/helpers/blit_commands_helper.h +++ b/runtime/helpers/blit_commands_helper.h @@ -23,8 +23,8 @@ class TimestampPacketContainer; struct BlitProperties { static BlitProperties constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection, CommandStreamReceiver &commandStreamReceiver, - GraphicsAllocation *memObjAllocation, void *hostPtr, bool blocking, - size_t offset, uint64_t copySize); + GraphicsAllocation *memObjAllocation, void *hostPtr, size_t hostPtrOffset, + bool blocking, size_t offset, uint64_t copySize); static BlitProperties constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection blitDirection, CommandStreamReceiver &commandStreamReceiver, diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index dc56475ea1..9f13007cc1 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -384,7 +384,8 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC csr.taskCount = newTaskCount - 1; EXPECT_EQ(0u, csr.recursiveLockCounter.load()); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer->getGraphicsAllocation(), hostPtr, true, 0, bltSize); + csr, buffer->getGraphicsAllocation(), hostPtr, 0, true, + 0, bltSize); csr.blitBuffer(blitProperties); EXPECT_EQ(newTaskCount, csr.taskCount); @@ -443,7 +444,8 @@ HWTEST_F(BcsTests, givenCsrDependenciesWhenProgrammingCommandStreamThenAddSemaph size_t numberNodesPerContainer = 5; auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer->getGraphicsAllocation(), hostPtr, true, 0, 1); + csr, buffer->getGraphicsAllocation(), hostPtr, 0, true, + 0, 1); MockTimestampPacketContainer timestamp0(*csr.getTimestampPacketAllocator(), numberNodesPerContainer); MockTimestampPacketContainer timestamp1(*csr.getTimestampPacketAllocator(), numberNodesPerContainer); @@ -491,7 +493,8 @@ HWTEST_F(BcsTests, givenInputAllocationsWhenBlitDispatchedThenMakeAllAllocations EXPECT_EQ(0u, csr.makeSurfacePackNonResidentCalled); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer->getGraphicsAllocation(), hostPtr, true, 0, 1); + csr, buffer->getGraphicsAllocation(), hostPtr, 0, true, + 0, 1); csr.blitBuffer(blitProperties); @@ -519,7 +522,8 @@ HWTEST_F(BcsTests, givenBufferWhenBlitCalledThenFlushCommandBuffer) { csr.taskCount = newTaskCount - 1; auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer->getGraphicsAllocation(), hostPtr, true, 0, 1); + csr, buffer->getGraphicsAllocation(), hostPtr, 0, true, + 0, 1); csr.blitBuffer(blitProperties); @@ -567,7 +571,8 @@ HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCallWaitWithKmdFallback) { void *hostPtr = reinterpret_cast(0x12340000); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - *myMockCsr, buffer->getGraphicsAllocation(), hostPtr, false, 0, 1); + *myMockCsr, buffer->getGraphicsAllocation(), hostPtr, 0, + false, 0, 1); myMockCsr->blitBuffer(blitProperties); @@ -597,7 +602,8 @@ HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCleanTemporaryAllocations) { EXPECT_EQ(0u, mockInternalAllocationsStorage->cleanAllocationsCalled); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - bcsCsr, buffer->getGraphicsAllocation(), hostPtr, false, 0, 1); + bcsCsr, buffer->getGraphicsAllocation(), hostPtr, 0, + false, 0, 1); bcsCsr.blitBuffer(blitProperties); @@ -618,12 +624,14 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres auto buffer1 = clUniquePtr(Buffer::create(context.get(), CL_MEM_READ_WRITE, 1, nullptr, retVal)); auto buffer2 = clUniquePtr(Buffer::create(context.get(), CL_MEM_READ_WRITE, 1, nullptr, retVal)); void *hostPtr = reinterpret_cast(0x12340000); + size_t hostPtrOffset = 0x1234; { // from hostPtr HardwareParse hwParser; auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer1->getGraphicsAllocation(), hostPtr, true, 0, 1); + csr, buffer1->getGraphicsAllocation(), hostPtr, hostPtrOffset, + true, 0, 1); csr.blitBuffer(blitProperties); @@ -632,7 +640,7 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); if (pDevice->isFullRangeSvm()) { - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getSourceBaseAddress()); + EXPECT_EQ(reinterpret_cast(ptrOffset(hostPtr, hostPtrOffset)), bltCmd->getSourceBaseAddress()); } EXPECT_EQ(buffer1->getGraphicsAllocation()->getGpuAddress(), bltCmd->getDestinationBaseAddress()); } @@ -641,7 +649,8 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres HardwareParse hwParser; auto offset = csr.commandStream.getUsed(); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::BufferToHostPtr, - csr, buffer1->getGraphicsAllocation(), hostPtr, true, 0, 1); + csr, buffer1->getGraphicsAllocation(), hostPtr, hostPtrOffset, + true, 0, 1); csr.blitBuffer(blitProperties); @@ -650,7 +659,7 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); if (pDevice->isFullRangeSvm()) { - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getDestinationBaseAddress()); + EXPECT_EQ(reinterpret_cast(ptrOffset(hostPtr, hostPtrOffset)), bltCmd->getDestinationBaseAddress()); } EXPECT_EQ(buffer1->getGraphicsAllocation()->getGpuAddress(), bltCmd->getSourceBaseAddress()); } @@ -689,7 +698,8 @@ HWTEST_F(BcsTests, givenBufferWithOffsetWhenBlitOperationCalledThenProgramCorrec HardwareParse hwParser; auto offset = csr.commandStream.getUsed(); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, - csr, buffer1->getGraphicsAllocation(), hostPtr, true, buffer1Offset, 1); + csr, buffer1->getGraphicsAllocation(), hostPtr, + 0, true, buffer1Offset, 1); csr.blitBuffer(blitProperties); @@ -707,7 +717,8 @@ HWTEST_F(BcsTests, givenBufferWithOffsetWhenBlitOperationCalledThenProgramCorrec HardwareParse hwParser; auto offset = csr.commandStream.getUsed(); auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::BufferToHostPtr, - csr, buffer1->getGraphicsAllocation(), hostPtr, true, buffer1Offset, 1); + csr, buffer1->getGraphicsAllocation(), hostPtr, + 0, true, buffer1Offset, 1); csr.blitBuffer(blitProperties); diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 36a84bb02f..7530fe7f2a 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -674,7 +674,7 @@ struct BcsBufferTests : public ::testing::Test { BlitOperationResult blitMemoryToAllocation(MemObj &memObj, GraphicsAllocation *memory, void *hostPtr, size_t size) const override { auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, *bcsCsr, memory, - hostPtr, true, 0, size); + hostPtr, 0, true, 0, size); bcsCsr->blitBuffer(blitProperties); return BlitOperationResult::Success; }