From 914ace6165bcc434fec587e19401a01575a633ba Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Tue, 20 Oct 2020 15:27:49 +0200 Subject: [PATCH] Add blitter support for read/write images OpenCL Change-Id: I5a74bcbdc5a5d7c20f55ee3c59839077649778c4 Signed-off-by: Kamil Kopryk Related-To: NEO-4692 --- .../sources/cmdlist/test_cmdlist_2.cpp | 3 + opencl/source/command_queue/command_queue.cpp | 25 +- .../source/command_queue/enqueue_read_image.h | 28 +- .../command_queue/enqueue_write_image.h | 25 +- opencl/source/helpers/cl_blit_properties.h | 89 ++++-- .../command_queue/command_queue_tests.cpp | 18 ++ .../command_stream_receiver_hw_1_tests.cpp | 28 ++ .../command_stream_receiver_hw_2_tests.cpp | 266 ++++++++++++++++++ .../command_stream_receiver_hw_gen12lp.cpp | 82 ++---- .../source/helpers/blit_commands_helper.cpp | 11 +- shared/source/helpers/blit_commands_helper.h | 6 +- .../helpers/blit_commands_helper_base.inl | 24 +- .../helpers/blit_commands_helper_bdw_plus.inl | 6 +- shared/source/helpers/constants.h | 4 +- .../helpers/blit_commands_helper_tests.cpp | 3 +- .../blit_commands_helper_tests_gen12lp.cpp | 223 ++++----------- 16 files changed, 530 insertions(+), 311 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 3b9f41d034..12bffefe27 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -804,6 +804,7 @@ using BlitBlockCopyPlatforms = IsWithinProducts HWTEST2_F(CommandListCreate, givenCopyCommandListWhenCopyRegionWithinMaxBlitSizeThenOneBlitCommandHasBeenSpown, BlitBlockCopyPlatforms) { using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; using XY_COPY_BLT = typename GfxFamily::XY_COPY_BLT; + using MI_ARB_CHECK = typename GfxFamily::MI_ARB_CHECK; auto commandList = std::make_unique>>(); commandList->initialize(device, NEO::EngineGroupType::Copy); @@ -829,6 +830,8 @@ HWTEST2_F(CommandListCreate, givenCopyCommandListWhenCopyRegionWithinMaxBlitSize cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); auto itor = find(cmdList.begin(), cmdList.end()); EXPECT_NE(cmdList.end(), itor); + itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); itor++; EXPECT_EQ(cmdList.end(), itor); } diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index 0d57d957b4..862afbb78d 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -637,18 +637,27 @@ bool CommandQueue::queueDependenciesClearRequired() const { } bool CommandQueue::blitEnqueueAllowed(cl_command_type cmdType) const { - bool blitAllowed = device->getHardwareInfo().capabilityTable.blitterOperationsSupported || this->isCopyOnly; + auto blitAllowed = device->getHardwareInfo().capabilityTable.blitterOperationsSupported || this->isCopyOnly; if (DebugManager.flags.EnableBlitterOperationsForReadWriteBuffers.get() != -1) { - blitAllowed &= !!DebugManager.flags.EnableBlitterOperationsForReadWriteBuffers.get(); + + blitAllowed &= static_cast(DebugManager.flags.EnableBlitterOperationsForReadWriteBuffers.get()); } - bool commandAllowed = (CL_COMMAND_READ_BUFFER == cmdType) || (CL_COMMAND_WRITE_BUFFER == cmdType) || - (CL_COMMAND_COPY_BUFFER == cmdType) || (CL_COMMAND_READ_BUFFER_RECT == cmdType) || - (CL_COMMAND_WRITE_BUFFER_RECT == cmdType) || (CL_COMMAND_COPY_BUFFER_RECT == cmdType) || - (CL_COMMAND_SVM_MEMCPY == cmdType); - - return commandAllowed && blitAllowed; + switch (cmdType) { + case CL_COMMAND_READ_BUFFER: + case CL_COMMAND_WRITE_BUFFER: + case CL_COMMAND_COPY_BUFFER: + case CL_COMMAND_READ_BUFFER_RECT: + case CL_COMMAND_WRITE_BUFFER_RECT: + case CL_COMMAND_COPY_BUFFER_RECT: + case CL_COMMAND_SVM_MEMCPY: + case CL_COMMAND_READ_IMAGE: + case CL_COMMAND_WRITE_IMAGE: + return blitAllowed; + default: + return false; + } } bool CommandQueue::isBlockedCommandStreamRequired(uint32_t commandType, const EventsRequest &eventsRequest, bool blockedQueue) const { diff --git a/opencl/source/command_queue/enqueue_read_image.h b/opencl/source/command_queue/enqueue_read_image.h index 5390c91746..b426079a43 100644 --- a/opencl/source/command_queue/enqueue_read_image.h +++ b/opencl/source/command_queue/enqueue_read_image.h @@ -41,27 +41,23 @@ cl_int CommandQueueHw::enqueueReadImage( const cl_event *eventWaitList, cl_event *event) { - auto &csr = getGpgpuCommandStreamReceiver(); + auto cmdType = CL_COMMAND_READ_IMAGE; + auto &csr = getCommandStreamReceiverByCommandType(cmdType); if (nullptr == mapAllocation) { - notifyEnqueueReadImage(srcImage, !!blockingRead, EngineHelpers::isBcs(csr.getOsContext().getEngineType())); + notifyEnqueueReadImage(srcImage, static_cast(blockingRead), EngineHelpers::isBcs(csr.getOsContext().getEngineType())); } auto isMemTransferNeeded = true; if (srcImage->isMemObjZeroCopy()) { size_t hostOffset; Image::calculateHostPtrOffset(&hostOffset, origin, region, inputRowPitch, inputSlicePitch, srcImage->getImageDesc().image_type, srcImage->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes); - isMemTransferNeeded = srcImage->checkIfMemoryTransferIsRequired(hostOffset, 0, ptr, CL_COMMAND_READ_IMAGE); + isMemTransferNeeded = srcImage->checkIfMemoryTransferIsRequired(hostOffset, 0, ptr, cmdType); } if (!isMemTransferNeeded) { - return enqueueMarkerForReadWriteOperation(srcImage, ptr, CL_COMMAND_READ_IMAGE, blockingRead, + return enqueueMarkerForReadWriteOperation(srcImage, ptr, cmdType, blockingRead, numEventsInWaitList, eventWaitList, event); } - auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyImage3dToBuffer, - this->getDevice()); - - BuiltInOwnershipWrapper builtInLock(builder, this->context); - size_t hostPtrSize = calculateHostPtrSizeForImage(region, inputRowPitch, inputSlicePitch, srcImage); void *dstPtr = ptr; @@ -103,18 +99,12 @@ cl_int CommandQueueHw::enqueueReadImage( if (srcImage->getImageDesc().num_mip_levels > 0) { dc.srcMipLevel = findMipLevel(srcImage->getImageDesc().image_type, origin); } + dc.transferAllocation = mapAllocation ? mapAllocation : hostPtrSurf.getAllocation(); - MultiDispatchInfo di(dc); + auto eBuiltInOps = EBuiltInOps::CopyImage3dToBuffer; + MultiDispatchInfo dispatchInfo(dc); - builder.buildDispatchInfos(di); - - enqueueHandler( - surfaces, - blockingRead == CL_TRUE, - di, - numEventsInWaitList, - eventWaitList, - event); + dispatchBcsOrGpgpuEnqueue(dispatchInfo, surfaces, eBuiltInOps, numEventsInWaitList, eventWaitList, event, blockingRead == CL_TRUE); if (context->isProvidingPerformanceHints()) { if (!isL3Capable(ptr, hostPtrSize)) { diff --git a/opencl/source/command_queue/enqueue_write_image.h b/opencl/source/command_queue/enqueue_write_image.h index 90af48dff3..e34578f0b2 100644 --- a/opencl/source/command_queue/enqueue_write_image.h +++ b/opencl/source/command_queue/enqueue_write_image.h @@ -35,20 +35,17 @@ cl_int CommandQueueHw::enqueueWriteImage( const cl_event *eventWaitList, cl_event *event) { + auto cmdType = CL_COMMAND_WRITE_IMAGE; auto isMemTransferNeeded = true; if (dstImage->isMemObjZeroCopy()) { size_t hostOffset; Image::calculateHostPtrOffset(&hostOffset, origin, region, inputRowPitch, inputSlicePitch, dstImage->getImageDesc().image_type, dstImage->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes); - isMemTransferNeeded = dstImage->checkIfMemoryTransferIsRequired(hostOffset, 0, ptr, CL_COMMAND_WRITE_IMAGE); + isMemTransferNeeded = dstImage->checkIfMemoryTransferIsRequired(hostOffset, 0, ptr, cmdType); } if (!isMemTransferNeeded) { - return enqueueMarkerForReadWriteOperation(dstImage, const_cast(ptr), CL_COMMAND_WRITE_IMAGE, blockingWrite, + return enqueueMarkerForReadWriteOperation(dstImage, const_cast(ptr), cmdType, blockingWrite, numEventsInWaitList, eventWaitList, event); } - auto &builder = BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::CopyBufferToImage3d, - this->getDevice()); - - BuiltInOwnershipWrapper lock(builder, this->context); size_t hostPtrSize = calculateHostPtrSizeForImage(region, inputRowPitch, inputSlicePitch, dstImage); void *srcPtr = const_cast(ptr); @@ -69,7 +66,8 @@ cl_int CommandQueueHw::enqueueWriteImage( if (region[0] != 0 && region[1] != 0 && region[2] != 0) { - bool status = getGpgpuCommandStreamReceiver().createAllocationForHostSurface(hostPtrSurf, false); + auto &csr = getCommandStreamReceiverByCommandType(cmdType); + bool status = csr.createAllocationForHostSurface(hostPtrSurf, false); if (!status) { return CL_OUT_OF_RESOURCES; } @@ -91,17 +89,12 @@ cl_int CommandQueueHw::enqueueWriteImage( if (dstImage->getImageDesc().num_mip_levels > 0) { dc.dstMipLevel = findMipLevel(dstImage->getImageDesc().image_type, origin); } + dc.transferAllocation = mapAllocation ? mapAllocation : hostPtrSurf.getAllocation(); - MultiDispatchInfo di(dc); - builder.buildDispatchInfos(di); + auto eBuiltInOps = EBuiltInOps::CopyBufferToImage3d; + MultiDispatchInfo dispatchInfo(dc); - enqueueHandler( - surfaces, - blockingWrite == CL_TRUE, - di, - numEventsInWaitList, - eventWaitList, - event); + dispatchBcsOrGpgpuEnqueue(dispatchInfo, surfaces, eBuiltInOps, numEventsInWaitList, eventWaitList, event, blockingWrite == CL_TRUE); if (context->isProvidingPerformanceHints()) { context->providePerformanceHint(CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL, CL_ENQUEUE_WRITE_IMAGE_REQUIRES_COPY_DATA, static_cast(dstImage)); diff --git a/opencl/source/helpers/cl_blit_properties.h b/opencl/source/helpers/cl_blit_properties.h index d5845b9523..b3542c2c9e 100644 --- a/opencl/source/helpers/cl_blit_properties.h +++ b/opencl/source/helpers/cl_blit_properties.h @@ -9,6 +9,7 @@ #include "shared/source/helpers/blit_commands_helper.h" #include "opencl/source/built_ins/builtins_dispatch_builder.h" +#include "opencl/source/mem_obj/image.h" #include "CL/cl.h" @@ -47,6 +48,7 @@ struct ClBlitProperties { builtinOpParams.dstRowPitch, builtinOpParams.dstSlicePitch); } + BlitProperties blitProperties{}; GraphicsAllocation *gpuAllocation = nullptr; Vec3 copyOffset = 0; @@ -64,8 +66,9 @@ struct ClBlitProperties { size_t gpuRowPitch = 0; size_t gpuSlicePitch = 0; - if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) { - // write buffer + if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection || + BlitterConstants::BlitDirection::HostPtrToImage == blitDirection) { + // write buffer/image hostPtr = builtinOpParams.srcPtr; hostPtrOffset = builtinOpParams.srcOffset; copyOffset = builtinOpParams.dstOffset; @@ -88,10 +91,10 @@ struct ClBlitProperties { copySize = builtinOpParams.size; } - if (BlitterConstants::BlitDirection::BufferToHostPtr == blitDirection) { - // read buffer + if (BlitterConstants::BlitDirection::BufferToHostPtr == blitDirection || + BlitterConstants::BlitDirection::ImageToHostPtr == blitDirection) { + // read buffer/image hostPtr = builtinOpParams.dstPtr; - hostPtrOffset = builtinOpParams.dstOffset; copyOffset = builtinOpParams.srcOffset; @@ -114,27 +117,79 @@ struct ClBlitProperties { } UNRECOVERABLE_IF(BlitterConstants::BlitDirection::HostPtrToBuffer != blitDirection && - BlitterConstants::BlitDirection::BufferToHostPtr != blitDirection); + BlitterConstants::BlitDirection::BufferToHostPtr != blitDirection && + BlitterConstants::BlitDirection::HostPtrToImage != blitDirection && + BlitterConstants::BlitDirection::ImageToHostPtr != blitDirection); - return BlitProperties::constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, gpuAllocation, - hostAllocation, hostPtr, memObjGpuVa, hostAllocGpuVa, - hostPtrOffset, copyOffset, copySize, - hostRowPitch, hostSlicePitch, - gpuRowPitch, gpuSlicePitch); + blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(blitDirection, commandStreamReceiver, gpuAllocation, + hostAllocation, hostPtr, memObjGpuVa, hostAllocGpuVa, + hostPtrOffset, copyOffset, copySize, + hostRowPitch, hostSlicePitch, + gpuRowPitch, gpuSlicePitch); + + if (BlitterConstants::BlitDirection::HostPtrToImage == blitDirection || + BlitterConstants::BlitDirection::ImageToHostPtr == blitDirection) { + adjustBlitPropertiesForImage(blitProperties, builtinOpParams); + } + + return blitProperties; } static BlitterConstants::BlitDirection obtainBlitDirection(uint32_t commandType) { - if (CL_COMMAND_WRITE_BUFFER == commandType || CL_COMMAND_WRITE_BUFFER_RECT == commandType) { + + switch (commandType) { + case CL_COMMAND_WRITE_BUFFER: + case CL_COMMAND_WRITE_BUFFER_RECT: return BlitterConstants::BlitDirection::HostPtrToBuffer; - } else if (CL_COMMAND_READ_BUFFER == commandType || CL_COMMAND_READ_BUFFER_RECT == commandType) { + case CL_COMMAND_READ_BUFFER: + case CL_COMMAND_READ_BUFFER_RECT: return BlitterConstants::BlitDirection::BufferToHostPtr; - } else if (CL_COMMAND_COPY_BUFFER_RECT == commandType || CL_COMMAND_SVM_MEMCPY == commandType) { - return BlitterConstants::BlitDirection::BufferToBuffer; - } else { - UNRECOVERABLE_IF(CL_COMMAND_COPY_BUFFER != commandType); + case CL_COMMAND_COPY_BUFFER: + case CL_COMMAND_COPY_BUFFER_RECT: + case CL_COMMAND_SVM_MEMCPY: return BlitterConstants::BlitDirection::BufferToBuffer; + case CL_COMMAND_WRITE_IMAGE: + return BlitterConstants::BlitDirection::HostPtrToImage; + case CL_COMMAND_READ_IMAGE: + return BlitterConstants::BlitDirection::ImageToHostPtr; + default: + UNRECOVERABLE_IF(true); } } + + static void adjustBlitPropertiesForImage(BlitProperties &blitProperties, const BuiltinOpParams &builtinOpParams) { + + Image *srcImage = nullptr; + Image *dstImage = nullptr; + + blitProperties.srcSize = {static_cast(builtinOpParams.size.x), + static_cast(builtinOpParams.size.y), + static_cast(builtinOpParams.size.z)}; + + blitProperties.dstSize = {static_cast(builtinOpParams.size.x), + static_cast(builtinOpParams.size.y), + static_cast(builtinOpParams.size.z)}; + + if (blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr) { + srcImage = castToObject(builtinOpParams.srcMemObj); + blitProperties.bytesPerPixel = srcImage->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + blitProperties.srcSize.x = static_cast(srcImage->getImageDesc().image_width); + blitProperties.srcSize.y = static_cast(srcImage->getImageDesc().image_height); + blitProperties.srcSize.z = static_cast(srcImage->getImageDesc().image_depth); + + } else { + dstImage = castToObject(builtinOpParams.dstMemObj); + blitProperties.bytesPerPixel = dstImage->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + blitProperties.dstSize.x = static_cast(dstImage->getImageDesc().image_width); + blitProperties.dstSize.y = static_cast(dstImage->getImageDesc().image_height); + blitProperties.dstSize.z = static_cast(dstImage->getImageDesc().image_depth); + } + + blitProperties.srcRowPitch = builtinOpParams.dstRowPitch ? builtinOpParams.dstRowPitch : blitProperties.srcSize.x * blitProperties.bytesPerPixel; + blitProperties.dstRowPitch = builtinOpParams.srcRowPitch ? builtinOpParams.srcRowPitch : blitProperties.dstSize.x * blitProperties.bytesPerPixel; + blitProperties.srcSlicePitch = builtinOpParams.dstSlicePitch ? builtinOpParams.dstSlicePitch : blitProperties.srcSize.y * blitProperties.srcRowPitch; + blitProperties.dstSlicePitch = builtinOpParams.srcSlicePitch ? builtinOpParams.srcSlicePitch : blitProperties.dstSize.y * blitProperties.dstRowPitch; + } }; } // namespace NEO diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index 82e918b506..5130f6642e 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -1150,3 +1150,21 @@ TEST(CommandQueue, givenCopyOnlyQueueWhenCallingBlitEnqueueAllowedThenReturnTrue queue.isCopyOnly = true; EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER)); } + +TEST(CommandQueue, giveClCommandWhenCallingBlitEnqueueAllowedThenReturnCorrectValue) { + MockContext context{}; + HardwareInfo *hwInfo = context.getDevice(0)->getRootDeviceEnvironment().getMutableHardwareInfo(); + MockCommandQueue queue(&context, context.getDevice(0), 0); + hwInfo->capabilityTable.blitterOperationsSupported = true; + + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_BUFFER_RECT)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_SVM_MEMCPY)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_READ_IMAGE)); + EXPECT_TRUE(queue.blitEnqueueAllowed(CL_COMMAND_WRITE_IMAGE)); + EXPECT_FALSE(queue.blitEnqueueAllowed(CL_COMMAND_COPY_IMAGE)); +} diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp index 9a08b0fa64..0ce16c0869 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp @@ -10,6 +10,7 @@ #include "shared/test/unit_test/utilities/base_object_utils.h" #include "opencl/source/event/user_event.h" +#include "opencl/source/helpers/cl_blit_properties.h" #include "opencl/test/unit_test/command_stream/command_stream_receiver_hw_fixture.h" #include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" @@ -873,6 +874,33 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC EXPECT_NE(nullptr, genCmdCast(*(cmdIterator++))); } } +HWTEST_F(BcsTests, givenCommandTypeWhenObtainBlitDirectionIsCalledThenReturnCorrectBlitDirection) { + + std::array, 9> testParams{ + std::make_pair(CL_COMMAND_WRITE_BUFFER, BlitterConstants::BlitDirection::HostPtrToBuffer), + std::make_pair(CL_COMMAND_WRITE_BUFFER_RECT, BlitterConstants::BlitDirection::HostPtrToBuffer), + std::make_pair(CL_COMMAND_READ_BUFFER, BlitterConstants::BlitDirection::BufferToHostPtr), + std::make_pair(CL_COMMAND_READ_BUFFER_RECT, BlitterConstants::BlitDirection::BufferToHostPtr), + std::make_pair(CL_COMMAND_COPY_BUFFER_RECT, BlitterConstants::BlitDirection::BufferToBuffer), + std::make_pair(CL_COMMAND_SVM_MEMCPY, BlitterConstants::BlitDirection::BufferToBuffer), + std::make_pair(CL_COMMAND_WRITE_IMAGE, BlitterConstants::BlitDirection::HostPtrToImage), + std::make_pair(CL_COMMAND_READ_IMAGE, BlitterConstants::BlitDirection::ImageToHostPtr), + std::make_pair(CL_COMMAND_COPY_BUFFER, BlitterConstants::BlitDirection::BufferToBuffer)}; + + for (const auto ¶ms : testParams) { + uint32_t commandType; + BlitterConstants::BlitDirection expectedBlitDirection; + std::tie(commandType, expectedBlitDirection) = params; + + auto blitDirection = ClBlitProperties::obtainBlitDirection(commandType); + EXPECT_EQ(expectedBlitDirection, blitDirection); + } +} + +HWTEST_F(BcsTests, givenWrongCommandTypeWhenObtainBlitDirectionIsCalledThenExpectThrow) { + uint32_t wrongCommandType = CL_COMMAND_COPY_IMAGE; + EXPECT_THROW(ClBlitProperties::obtainBlitDirection(wrongCommandType), std::exception); +} struct BcsTestParam { Vec3 copySize; diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp index abe61913e8..63ed5baf76 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp @@ -15,10 +15,12 @@ #include "opencl/source/helpers/cl_blit_properties.h" #include "opencl/source/mem_obj/mem_obj_helper.h" #include "opencl/test/unit_test/command_stream/command_stream_receiver_hw_fixture.h" +#include "opencl/test/unit_test/fixtures/image_fixture.h" #include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h" #include "opencl/test/unit_test/helpers/raii_hw_helper.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" #include "opencl/test/unit_test/mocks/mock_hw_helper.h" +#include "opencl/test/unit_test/mocks/mock_image.h" #include "opencl/test/unit_test/mocks/mock_internal_allocation_storage.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" #include "opencl/test/unit_test/mocks/mock_memory_manager.h" @@ -1213,6 +1215,270 @@ HWTEST_F(BcsTests, givenBlitterDirectSubmissionEnabledWhenProgrammingBlitterThen EXPECT_EQ(0ull, bbStart->getBatchBufferStartAddressGraphicsaddress472()); } +HWTEST_F(BcsTests, givenHostPtrToImageWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) { + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + imgDesc.image_width = 10u; + imgDesc.image_height = 12u; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.srcPtr = hostPtr; + builtinOpParams.srcMemObj = nullptr; + builtinOpParams.dstMemObj = image.get(); + builtinOpParams.size = {2, 3, 1}; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto expectedDstPtr = image.get()->getGraphicsAllocation(csr.getRootDeviceIndex())->getGpuAddress(); + auto expectedBytesPerPixel = image.get()->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + auto srcRowPitchExpected = expectedBytesPerPixel * builtinOpParams.size.x; + auto dstRowPitchExpected = expectedBytesPerPixel * image.get()->getImageDesc().image_width; + auto srcSlicePitchExpected = srcRowPitchExpected * builtinOpParams.size.y; + auto dstSlicePitchExpected = dstRowPitchExpected * image.get()->getImageDesc().image_height; + + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToImage, + csr, + builtinOpParams); + + EXPECT_EQ(builtinOpParams.size, blitProperties.copySize); + EXPECT_EQ(expectedDstPtr, blitProperties.dstGpuAddress); + EXPECT_EQ(builtinOpParams.srcOffset, blitProperties.srcOffset); + EXPECT_EQ(builtinOpParams.dstOffset, blitProperties.dstOffset); + EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel); + EXPECT_EQ(srcRowPitchExpected, blitProperties.srcRowPitch); + EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch); + EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch); + EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch); +} + +HWTEST_F(BcsTests, givenImageToHostPtrWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) { + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + imgDesc.image_width = 10u; + imgDesc.image_height = 12u; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.dstPtr = hostPtr; + builtinOpParams.srcMemObj = image.get(); + builtinOpParams.dstMemObj = nullptr; + builtinOpParams.size = {2, 3, 1}; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto expectedSrcPtr = image.get()->getGraphicsAllocation(csr.getRootDeviceIndex())->getGpuAddress(); + auto expectedBytesPerPixel = image.get()->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + auto srcRowPitchExpected = expectedBytesPerPixel * image.get()->getImageDesc().image_width; + auto dstRowPitchExpected = expectedBytesPerPixel * builtinOpParams.size.x; + auto srcSlicePitchExpected = srcRowPitchExpected * image.get()->getImageDesc().image_height; + auto dstSlicePitchExpected = dstRowPitchExpected * builtinOpParams.size.y; + + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::ImageToHostPtr, + csr, + builtinOpParams); + + EXPECT_EQ(builtinOpParams.size, blitProperties.copySize); + EXPECT_EQ(expectedSrcPtr, blitProperties.srcGpuAddress); + EXPECT_EQ(builtinOpParams.srcOffset, blitProperties.srcOffset); + EXPECT_EQ(builtinOpParams.dstOffset, blitProperties.dstOffset); + EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel); + EXPECT_EQ(srcRowPitchExpected, blitProperties.srcRowPitch); + EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch); + EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch); + EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch); +} + +HWTEST_F(BcsTests, givenHostPtrToImageWithInputRowSlicePitchesWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) { + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.srcPtr = hostPtr; + builtinOpParams.srcMemObj = nullptr; + builtinOpParams.dstMemObj = image.get(); + builtinOpParams.size = {2, 3, 1}; + auto inputRowPitch = 0x20u; + auto inputSlicePitch = 0x400u; + builtinOpParams.dstRowPitch = inputRowPitch; + builtinOpParams.dstSlicePitch = inputSlicePitch; + + auto expectedBytesPerPixel = image.get()->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + auto dstRowPitchExpected = expectedBytesPerPixel * image.get()->getImageDesc().image_width; + auto dstSlicePitchExpected = dstRowPitchExpected * image.get()->getImageDesc().image_height; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToImage, + csr, + builtinOpParams); + + EXPECT_EQ(inputRowPitch, blitProperties.srcRowPitch); + EXPECT_EQ(dstRowPitchExpected, blitProperties.dstRowPitch); + EXPECT_EQ(inputSlicePitch, blitProperties.srcSlicePitch); + EXPECT_EQ(dstSlicePitchExpected, blitProperties.dstSlicePitch); +} + +HWTEST_F(BcsTests, givenImageToHostPtrWithInputRowSlicePitchesWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) { + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.dstPtr = hostPtr; + builtinOpParams.srcMemObj = image.get(); + builtinOpParams.dstMemObj = nullptr; + builtinOpParams.size = {2, 3, 1}; + auto inputRowPitch = 0x20u; + auto inputSlicePitch = 0x400u; + builtinOpParams.srcRowPitch = inputRowPitch; + builtinOpParams.srcSlicePitch = inputSlicePitch; + + auto expectedBytesPerPixel = image.get()->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; + auto srcRowPitchExpected = expectedBytesPerPixel * image.get()->getImageDesc().image_width; + auto srcSlicePitchExpected = srcRowPitchExpected * image.get()->getImageDesc().image_height; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::ImageToHostPtr, + csr, + builtinOpParams); + + EXPECT_EQ(srcRowPitchExpected, blitProperties.srcRowPitch); + EXPECT_EQ(inputRowPitch, blitProperties.dstRowPitch); + EXPECT_EQ(srcSlicePitchExpected, blitProperties.srcSlicePitch); + EXPECT_EQ(inputSlicePitch, blitProperties.dstSlicePitch); +} + +HWTEST_F(BcsTests, givenHostPtrToImageWhenBlitBufferIsCalledThenBlitCmdIsFound) { + if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) { + GTEST_SKIP(); + } + void *hostPtr = reinterpret_cast(0x12340000); + std::unique_ptr image(Image2dHelper<>::create(context.get())); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.srcPtr = hostPtr; + builtinOpParams.dstMemObj = image.get(); + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToImage, + csr, + builtinOpParams); + blitBuffer(&csr, blitProperties, true); + + HardwareParse hwParser; + hwParser.parseCommands(csr.commandStream, 0); + auto cmdIterator = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + EXPECT_NE(hwParser.cmdList.end(), cmdIterator); +} + +HWTEST_F(BcsTests, given3dImageWhenBlitBufferIsCalledThenBlitCmdIsFoundZtimes) { + if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) { + GTEST_SKIP(); + } + void *hostPtr = reinterpret_cast(0x12340000); + std::unique_ptr image(Image3dHelper<>::create(context.get())); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.srcPtr = hostPtr; + builtinOpParams.dstMemObj = image.get(); + builtinOpParams.size = {1, 1, 10}; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToImage, + csr, + builtinOpParams); + blitBuffer(&csr, blitProperties, true); + HardwareParse hwParser; + hwParser.parseCommands(csr.commandStream, 0); + uint32_t xyCopyBltCmdFound = 0; + + for (auto &cmd : hwParser.cmdList) { + if (auto bltCmd = genCmdCast(cmd)) { + ++xyCopyBltCmdFound; + } + } + EXPECT_EQ(static_cast(builtinOpParams.size.z), xyCopyBltCmdFound); +} + +HWTEST_F(BcsTests, givenImageToHostPtrWhenBlitBufferIsCalledThenBlitCmdIsFound) { + if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) { + GTEST_SKIP(); + } + void *hostPtr = reinterpret_cast(0x12340000); + std::unique_ptr image(Image2dHelper<>::create(context.get())); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.dstPtr = hostPtr; + builtinOpParams.srcMemObj = image.get(); + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::ImageToHostPtr, + csr, + builtinOpParams); + blitBuffer(&csr, blitProperties, true); + + HardwareParse hwParser; + hwParser.parseCommands(csr.commandStream, 0); + auto cmdIterator = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + EXPECT_NE(hwParser.cmdList.end(), cmdIterator); +} + +HWTEST_F(BcsTests, givenHostPtrToImageWhenBlitBufferIsCalledThenBlitCmdIsCorrectlyProgrammed) { + if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) { + GTEST_SKIP(); + } + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + imgDesc.image_width = 10; + imgDesc.image_height = 12; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.srcPtr = hostPtr; + builtinOpParams.srcMemObj = nullptr; + builtinOpParams.dstMemObj = image.get(); + builtinOpParams.size = {6, 8, 1}; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::HostPtrToImage, + csr, + builtinOpParams); + blitBuffer(&csr, blitProperties, true); + + HardwareParse hwParser; + hwParser.parseCommands(csr.commandStream, 0); + auto cmdIterator = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + ASSERT_NE(hwParser.cmdList.end(), cmdIterator); + auto bltCmd = genCmdCast(*cmdIterator); + + auto dstPtr = builtinOpParams.dstMemObj->getGraphicsAllocation(csr.getRootDeviceIndex())->getGpuAddress(); + EXPECT_EQ(blitProperties.srcGpuAddress, bltCmd->getSourceBaseAddress()); + EXPECT_EQ(dstPtr, bltCmd->getDestinationBaseAddress()); +} + +HWTEST_F(BcsTests, givenImageToHostPtrWhenBlitBufferIsCalledThenBlitCmdIsCorrectlyProgrammed) { + if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) { + GTEST_SKIP(); + } + void *hostPtr = reinterpret_cast(0x12340000); + cl_image_desc imgDesc = Image2dDefaults::imageDesc; + imgDesc.image_width = 10u; + imgDesc.image_height = 12u; + std::unique_ptr image(Image2dHelper<>::create(context.get(), &imgDesc)); + BuiltinOpParams builtinOpParams{}; + builtinOpParams.dstPtr = hostPtr; + builtinOpParams.srcMemObj = image.get(); + builtinOpParams.dstMemObj = nullptr; + builtinOpParams.size = {2, 3, 1}; + + auto &csr = pDevice->getUltCommandStreamReceiver(); + auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::ImageToHostPtr, + csr, + builtinOpParams); + blitBuffer(&csr, blitProperties, true); + + HardwareParse hwParser; + hwParser.parseCommands(csr.commandStream, 0); + auto cmdIterator = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + ASSERT_NE(hwParser.cmdList.end(), cmdIterator); + auto bltCmd = genCmdCast(*cmdIterator); + + auto srcPtr = builtinOpParams.srcMemObj->getGraphicsAllocation(csr.getRootDeviceIndex())->getGpuAddress(); + EXPECT_EQ(srcPtr, bltCmd->getSourceBaseAddress()); + EXPECT_EQ(blitProperties.dstGpuAddress, bltCmd->getDestinationBaseAddress()); +} + struct MockScratchSpaceController : ScratchSpaceControllerBase { using ScratchSpaceControllerBase::privateScratchAllocation; using ScratchSpaceControllerBase::ScratchSpaceControllerBase; diff --git a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp index 8d71285821..7286581363 100644 --- a/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp +++ b/shared/source/gen12lp/command_stream_receiver_hw_gen12lp.cpp @@ -85,86 +85,46 @@ void BlitCommandsHelper::appendColorDepth(const BlitProperties &blitProp } template <> -void BlitCommandsHelper::appendTilingType(const GMM_TILE_TYPE srcTilingType, const GMM_TILE_TYPE dstTilingType, typename Family::XY_COPY_BLT &blitCmd) { - using XY_COPY_BLT = typename Family::XY_COPY_BLT; - if (srcTilingType == GMM_TILED_Y) { - blitCmd.setSourceTiling(XY_COPY_BLT::SOURCE_TILING::SOURCE_TILING_YMAJOR); - } - if (dstTilingType == GMM_TILED_Y) { - blitCmd.setDestinationTiling(XY_COPY_BLT::DESTINATION_TILING::DESTINATION_TILING_YMAJOR); - } -} - -template <> -void BlitCommandsHelper::appendSurfaceType(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd) { -} - -template <> -void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod) { - constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; - constexpr uint32_t NON_TILED_PITCH_ALIGNMENT = 16; - +void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod, uint32_t &compressionDetails, const RootDeviceEnvironment &rootDeviceEnvironment) { if (allocation.getDefaultGmm()) { - auto gmmResInfo = allocation.getDefaultGmm()->gmmResourceInfo.get(); - auto resInfo = gmmResInfo->getResourceFlags()->Info; - if (resInfo.TiledY) { - tileType = GMM_TILED_Y; - pitch = static_cast(gmmResInfo->getRenderPitch()); - pitch = alignUp(pitch, TILED_Y_PITCH_ALIGNMENT); - qPitch = static_cast(gmmResInfo->getQPitch()); - } else { - pitch = alignUp(pitch, NON_TILED_PITCH_ALIGNMENT); + auto gmmResourceInfo = allocation.getDefaultGmm()->gmmResourceInfo.get(); + if (!gmmResourceInfo->getResourceFlags()->Info.Linear) { + qPitch = gmmResourceInfo->getQPitch() ? static_cast(gmmResourceInfo->getQPitch()) : qPitch; + pitch = gmmResourceInfo->getRenderPitch() ? static_cast(gmmResourceInfo->getRenderPitch()) : pitch; } } } template <> -void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, uint32_t sliceIndex) { +void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch) { using XY_COPY_BLT = typename Family::XY_COPY_BLT; - auto srcAllocation = blitProperties.srcAllocation; - auto dstAllocation = blitProperties.dstAllocation; - auto srcQPitch = blitProperties.srcSize.y; - auto dstQPitch = blitProperties.dstSize.y; - auto srcPitch = static_cast(blitProperties.srcRowPitch); - auto dstPitch = static_cast(blitProperties.dstRowPitch); - auto tileType = GMM_NOT_TILED; - uint32_t mipTailLod = 0; + auto srcAddress = blitProperties.srcGpuAddress; + auto dstAddress = blitProperties.dstGpuAddress; - getBlitAllocationProperties(*srcAllocation, srcPitch, srcQPitch, tileType, mipTailLod); - getBlitAllocationProperties(*dstAllocation, dstPitch, dstQPitch, tileType, mipTailLod); - - auto srcSlicePitch = srcPitch * srcQPitch; - auto dstSlicePitch = dstPitch * dstQPitch; - - size_t srcOffset = srcSlicePitch * (sliceIndex + blitProperties.srcOffset.z); - size_t dstOffset = dstSlicePitch * (sliceIndex + blitProperties.dstOffset.z); - - blitCmd.setSourceBaseAddress(ptrOffset(srcAllocation->getGpuAddress(), srcOffset)); - blitCmd.setDestinationBaseAddress(ptrOffset(dstAllocation->getGpuAddress(), dstOffset)); + blitCmd.setSourceBaseAddress(ptrOffset(srcAddress, srcSlicePitch * (sliceIndex + blitProperties.srcOffset.z))); + blitCmd.setDestinationBaseAddress(ptrOffset(dstAddress, dstSlicePitch * (sliceIndex + blitProperties.dstOffset.z))); } template <> -void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd) { - auto srcTileType = GMM_NOT_TILED; - auto dstTileType = GMM_NOT_TILED; +void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename Family::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t &srcSlicePitch, uint32_t &dstSlicePitch) { + auto tileType = GMM_NOT_TILED; auto srcAllocation = blitProperties.srcAllocation; auto dstAllocation = blitProperties.dstAllocation; auto srcQPitch = blitProperties.srcSize.y; auto dstQPitch = blitProperties.dstSize.y; - auto srcPitch = static_cast(blitProperties.srcRowPitch); - auto dstPitch = static_cast(blitProperties.dstRowPitch); + auto srcRowPitch = static_cast(blitProperties.srcRowPitch); + auto dstRowPitch = static_cast(blitProperties.dstRowPitch); uint32_t mipTailLod = 0; + auto compressionDetails = 0u; - getBlitAllocationProperties(*srcAllocation, srcPitch, srcQPitch, srcTileType, mipTailLod); - getBlitAllocationProperties(*dstAllocation, dstPitch, dstQPitch, dstTileType, mipTailLod); + getBlitAllocationProperties(*srcAllocation, srcRowPitch, srcQPitch, tileType, mipTailLod, compressionDetails, rootDeviceEnvironment); + getBlitAllocationProperties(*dstAllocation, dstRowPitch, dstQPitch, tileType, mipTailLod, compressionDetails, rootDeviceEnvironment); - srcPitch = (srcTileType == GMM_NOT_TILED) ? srcPitch : srcPitch / 4; - dstPitch = (dstTileType == GMM_NOT_TILED) ? dstPitch : dstPitch / 4; + blitCmd.setSourcePitch(srcRowPitch); + blitCmd.setDestinationPitch(dstRowPitch); - blitCmd.setSourcePitch(srcPitch); - blitCmd.setDestinationPitch(dstPitch); - - appendTilingType(srcTileType, dstTileType, blitCmd); + srcSlicePitch = std::max(srcSlicePitch, srcRowPitch * srcQPitch); + dstSlicePitch = std::max(dstSlicePitch, dstRowPitch * dstQPitch); } template <> diff --git a/shared/source/helpers/blit_commands_helper.cpp b/shared/source/helpers/blit_commands_helper.cpp index 452b4e96c1..a9de2669ff 100644 --- a/shared/source/helpers/blit_commands_helper.cpp +++ b/shared/source/helpers/blit_commands_helper.cpp @@ -41,7 +41,8 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons copySize.y = copySize.y ? copySize.y : 1; copySize.z = copySize.z ? copySize.z : 1; - if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection) { + if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection || + BlitterConstants::BlitDirection::HostPtrToImage == blitDirection) { return { nullptr, // outputTimestampPacket blitDirection, // blitDirection @@ -54,10 +55,10 @@ BlitProperties BlitProperties::constructPropertiesForReadWriteBuffer(BlitterCons copySize, // copySize copyOffset, // dstOffset hostPtrOffset, // srcOffset - gpuRowPitch, //dstRowPitch - gpuSlicePitch, //dstSlicePitch - hostRowPitch, //srcRowPitch - hostSlicePitch}; //srcSlicePitch + gpuRowPitch, // dstRowPitch + gpuSlicePitch, // dstSlicePitch + hostRowPitch, // srcRowPitch + hostSlicePitch}; // srcSlicePitch } else { return { diff --git a/shared/source/helpers/blit_commands_helper.h b/shared/source/helpers/blit_commands_helper.h index 813e49eb33..10a91d85e4 100644 --- a/shared/source/helpers/blit_commands_helper.h +++ b/shared/source/helpers/blit_commands_helper.h @@ -129,14 +129,14 @@ struct BlitCommandsHelper { template static void dispatchBlitMemoryFill(NEO::GraphicsAllocation *dstAlloc, uint32_t *pattern, LinearStream &linearStream, size_t size, const RootDeviceEnvironment &rootDeviceEnvironment, COLOR_DEPTH depth); static void appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); - static void appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); + static void appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t &srcSlicePitch, uint32_t &dstSlicePitch); static void appendColorDepth(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendBlitCommandsForFillBuffer(NEO::GraphicsAllocation *dstAlloc, typename GfxFamily::XY_COLOR_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment); static void appendSurfaceType(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd); static void appendTilingEnable(typename GfxFamily::XY_COLOR_BLT &blitCmd); static void appendTilingType(const GMM_TILE_TYPE srcTilingType, const GMM_TILE_TYPE dstTilingType, typename GfxFamily::XY_COPY_BLT &blitCmd); - static void appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex); - static void getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod); + static void appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch); + static void getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod, uint32_t &compressionDetails, const RootDeviceEnvironment &rootDeviceEnvironment); static void dispatchDebugPauseCommands(LinearStream &commandStream, uint64_t debugPauseStateGPUAddress, DebugPauseState confirmationTrigger, DebugPauseState waitCondition); static size_t getSizeForDebugPauseCommands(); static bool useOneBlitCopyCommand(Vec3 copySize, uint32_t bytesPerPixel); diff --git a/shared/source/helpers/blit_commands_helper_base.inl b/shared/source/helpers/blit_commands_helper_base.inl index 59a2cb8d60..0c59c56f43 100644 --- a/shared/source/helpers/blit_commands_helper_base.inl +++ b/shared/source/helpers/blit_commands_helper_base.inl @@ -226,14 +226,14 @@ void BlitCommandsHelper::dispatchBlitMemoryFill(NEO::GraphicsAllocati template void BlitCommandsHelper::dispatchBlitCommandsRegion(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) { - auto dstAllocation = blitProperties.dstAllocation; - auto srcAllocation = blitProperties.srcAllocation; + auto srcSlicePitch = static_cast(blitProperties.srcSlicePitch); + auto dstSlicePitch = static_cast(blitProperties.dstSlicePitch); UNRECOVERABLE_IF(blitProperties.copySize.x > BlitterConstants::maxBlitWidth || blitProperties.copySize.y > BlitterConstants::maxBlitWidth); auto bltCmd = GfxFamily::cmdInitXyCopyBlt; - bltCmd.setSourceBaseAddress(srcAllocation->getGpuAddress()); - bltCmd.setDestinationBaseAddress(dstAllocation->getGpuAddress()); + bltCmd.setSourceBaseAddress(blitProperties.srcAllocation->getGpuAddress()); + bltCmd.setDestinationBaseAddress(blitProperties.dstAllocation->getGpuAddress()); bltCmd.setDestinationX1CoordinateLeft(static_cast(blitProperties.dstOffset.x)); bltCmd.setDestinationY1CoordinateTop(static_cast(blitProperties.dstOffset.y)); @@ -244,13 +244,14 @@ void BlitCommandsHelper::dispatchBlitCommandsRegion(const BlitPropert bltCmd.setSourceY1CoordinateTop(static_cast(blitProperties.srcOffset.y)); appendBlitCommandsForBuffer(blitProperties, bltCmd, rootDeviceEnvironment); - appendBlitCommandsForImages(blitProperties, bltCmd); + appendBlitCommandsForImages(blitProperties, bltCmd, rootDeviceEnvironment, srcSlicePitch, dstSlicePitch); appendColorDepth(blitProperties, bltCmd); appendSurfaceType(blitProperties, bltCmd); for (uint32_t i = 0; i < blitProperties.copySize.z; i++) { - appendSliceOffsets(blitProperties, bltCmd, i); + appendSliceOffsets(blitProperties, bltCmd, i, rootDeviceEnvironment, srcSlicePitch, dstSlicePitch); auto cmd = linearStream.getSpaceForCmd(); *cmd = bltCmd; + dispatchPostBlitCommand(linearStream); } } @@ -289,10 +290,15 @@ uint32_t BlitCommandsHelper::getAvailableBytesPerPixel(size_t copySiz template void BlitCommandsHelper::dispatchBlitCommands(const BlitProperties &blitProperties, LinearStream &linearStream, const RootDeviceEnvironment &rootDeviceEnvironment) { - bool preferCopyRegion = isCopyRegionPreferred(blitProperties.copySize, rootDeviceEnvironment); - preferCopyRegion ? dispatchBlitCommandsForBufferRegion(blitProperties, linearStream, rootDeviceEnvironment) - : dispatchBlitCommandsForBufferPerRow(blitProperties, linearStream, rootDeviceEnvironment); + if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage || + blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr) { + return dispatchBlitCommandsRegion(blitProperties, linearStream, rootDeviceEnvironment); + } + + bool preferCopyBufferRegion = isCopyRegionPreferred(blitProperties.copySize, rootDeviceEnvironment); + preferCopyBufferRegion ? dispatchBlitCommandsForBufferRegion(blitProperties, linearStream, rootDeviceEnvironment) + : dispatchBlitCommandsForBufferPerRow(blitProperties, linearStream, rootDeviceEnvironment); } template diff --git a/shared/source/helpers/blit_commands_helper_bdw_plus.inl b/shared/source/helpers/blit_commands_helper_bdw_plus.inl index eb7b5f8791..090cf512dd 100644 --- a/shared/source/helpers/blit_commands_helper_bdw_plus.inl +++ b/shared/source/helpers/blit_commands_helper_bdw_plus.inl @@ -23,7 +23,7 @@ template void BlitCommandsHelper::appendBlitCommandsForBuffer(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment) {} template -void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd) { +void BlitCommandsHelper::appendBlitCommandsForImages(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t &srcSlicePitch, uint32_t &dstSlicePitch) { appendTilingType(GMM_NOT_TILED, GMM_NOT_TILED, blitCmd); } @@ -66,11 +66,11 @@ void BlitCommandsHelper::appendColorDepth(const BlitProperties &blitP } template -void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex) { +void BlitCommandsHelper::appendSliceOffsets(const BlitProperties &blitProperties, typename GfxFamily::XY_COPY_BLT &blitCmd, uint32_t sliceIndex, const RootDeviceEnvironment &rootDeviceEnvironment, uint32_t srcSlicePitch, uint32_t dstSlicePitch) { } template -void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod) { +void BlitCommandsHelper::getBlitAllocationProperties(const GraphicsAllocation &allocation, uint32_t &pitch, uint32_t &qPitch, GMM_TILE_TYPE &tileType, uint32_t &mipTailLod, uint32_t &compressionDetails, const RootDeviceEnvironment &rootDeviceEnvironment) { } template diff --git a/shared/source/helpers/constants.h b/shared/source/helpers/constants.h index 221e829baa..631eca529b 100644 --- a/shared/source/helpers/constants.h +++ b/shared/source/helpers/constants.h @@ -67,7 +67,9 @@ constexpr uint64_t maxBytesPerPixel = 0x10; enum class BlitDirection : uint32_t { BufferToHostPtr, HostPtrToBuffer, - BufferToBuffer + BufferToBuffer, + HostPtrToImage, + ImageToHostPtr }; } // namespace BlitterConstants diff --git a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp index c12cbb96f8..90b5fd6ce8 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests.cpp @@ -380,8 +380,9 @@ HWTEST2_F(BlitTests, givenGen9AndGetBlitAllocationPropertiesThenCorrectValuesAre auto expectedQPitch = qPitch; auto expectedtileType = tileType; auto expectedMipTailLod = mipTailLod; + auto compressionDetails = 0u; - NEO::BlitCommandsHelper::getBlitAllocationProperties(alloc, pitch, qPitch, tileType, mipTailLod); + NEO::BlitCommandsHelper::getBlitAllocationProperties(alloc, pitch, qPitch, tileType, mipTailLod, compressionDetails, pDevice->getRootDeviceEnvironment()); EXPECT_EQ(expectedPitch, pitch); EXPECT_EQ(expectedQPitch, qPitch); diff --git a/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp b/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp index 70f139962e..551c788d02 100644 --- a/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp +++ b/shared/test/unit_test/helpers/blit_commands_helper_tests_gen12lp.cpp @@ -72,72 +72,9 @@ HWTEST2_F(BlitTests, givenIncorrectBytePerPixelWhenAppendColorDepthThenAbortIsTh EXPECT_THROW(BlitCommandsHelper::appendColorDepth(properties, bltCmd), std::exception); } -HWTEST2_F(BlitTests, givenNotTiledSrcAndDestinationWhenAppendTilingTypeThenCorrectTilingIsSet, IsGen12LP) { - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - BlitCommandsHelper::appendTilingType(GMM_NOT_TILED, GMM_NOT_TILED, bltCmd); - EXPECT_EQ(bltCmd.getSourceTiling(), XY_COPY_BLT::SOURCE_TILING::SOURCE_TILING_LINEAR); - EXPECT_EQ(bltCmd.getDestinationTiling(), XY_COPY_BLT::DESTINATION_TILING::DESTINATION_TILING_LINEAR); -} -HWTEST2_F(BlitTests, givenTiledSrcAndDestinationAppendTilingTypeThenCorrectTilingIsSet, IsGen12LP) { - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - BlitCommandsHelper::appendTilingType(GMM_TILED_Y, GMM_TILED_Y, bltCmd); - EXPECT_EQ(bltCmd.getSourceTiling(), XY_COPY_BLT::SOURCE_TILING::SOURCE_TILING_YMAJOR); - EXPECT_EQ(bltCmd.getDestinationTiling(), XY_COPY_BLT::DESTINATION_TILING::DESTINATION_TILING_YMAJOR); -} - -HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenAppendImageCommandsThenCorrectTiledIsSet, IsGen12LP) { - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto gmm = std::make_unique(); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = true; - MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - mockAllocationSrc.setGmm(gmm.get(), 0); - mockAllocationDst.setGmm(gmm.get(), 0); - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - properties.srcAllocation = &mockAllocationSrc; - properties.dstAllocation = &mockAllocationDst; - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getSourceTiling(), XY_COPY_BLT::SOURCE_TILING::SOURCE_TILING_YMAJOR); - EXPECT_EQ(bltCmd.getDestinationTiling(), XY_COPY_BLT::DESTINATION_TILING::DESTINATION_TILING_YMAJOR); -} - -HWTEST2_F(BlitTests, givenNotTiledSrcAndDestinationWhenAppendImageCommandsThenCorrectTiledIsSet, IsGen12LP) { - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto gmm = std::make_unique(); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = false; - MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - mockAllocationSrc.setGmm(gmm.get(), 0); - mockAllocationDst.setGmm(gmm.get(), 0); - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - properties.srcAllocation = &mockAllocationSrc; - properties.dstAllocation = &mockAllocationDst; - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getSourceTiling(), XY_COPY_BLT::SOURCE_TILING::SOURCE_TILING_LINEAR); - EXPECT_EQ(bltCmd.getDestinationTiling(), XY_COPY_BLT::DESTINATION_TILING::DESTINATION_TILING_LINEAR); -} - HWTEST2_F(BlitTests, givenSrcAndDestinationImagesWhenAppendSliceOffsetsThenAdressAreCorectOffseted, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = false; MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); @@ -150,19 +87,22 @@ HWTEST2_F(BlitTests, givenSrcAndDestinationImagesWhenAppendSliceOffsetsThenAdres BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; + properties.srcGpuAddress = mockAllocationSrc.getGpuAddress(); + properties.dstGpuAddress = mockAllocationDst.getGpuAddress(); properties.srcSize.y = 0x10; properties.srcRowPitch = 0x10; - auto srcSlicePitch = properties.srcSize.y * properties.srcRowPitch; + auto srcSlicePitch = static_cast(properties.srcSize.y * properties.srcRowPitch); properties.dstSize.y = 0x20; properties.dstRowPitch = 0x20; - auto dstSlicePitch = properties.dstSize.y * properties.dstRowPitch; + auto dstSlicePitch = static_cast(properties.dstSize.y * properties.dstRowPitch); properties.srcOffset = {0x10, 0x10, 0x10}; properties.dstOffset = {0x20, 0x20, 0x20}; uint32_t index = 7; - BlitCommandsHelper::appendSliceOffsets(properties, bltCmd, index); + + BlitCommandsHelper::appendSliceOffsets(properties, bltCmd, index, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); auto expectesSrcOffset = (index + properties.srcOffset.z) * srcSlicePitch; auto expectesDstOffset = (index + properties.dstOffset.z) * dstSlicePitch; @@ -170,28 +110,43 @@ HWTEST2_F(BlitTests, givenSrcAndDestinationImagesWhenAppendSliceOffsetsThenAdres EXPECT_EQ(bltCmd.getDestinationBaseAddress(), ptrOffset(mockAllocationDst.getGpuAddress(), expectesDstOffset)); } -HWTEST2_F(BlitTests, givenNotTiledSrcAndDestinationWhenAppendImageCommandsThenPitchIsValueFromProperties, IsGen12LP) { +HWTEST2_F(BlitTests, givenInputAndDefaultSlicePitchWhenAppendBlitCommandsForImagesThenSlicePitchesAreCorrect, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto gmm = std::make_unique(); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = false; + MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); - mockAllocationSrc.setGmm(gmm.get(), 0); - mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; - properties.srcRowPitch = 0x1000; - properties.dstRowPitch = 0x4000; - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getDestinationPitch(), properties.dstRowPitch); - EXPECT_EQ(bltCmd.getSourcePitch(), properties.srcRowPitch); + properties.srcSize = {10, 10, 1}; + properties.dstSize = {8, 12, 1}; + properties.srcRowPitch = 0x10; + properties.dstRowPitch = 0x40; + + { + uint32_t inputSlicePitch = 0; + auto srcSlicePitch = inputSlicePitch; + auto dstSlicePitch = inputSlicePitch; + BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + + EXPECT_EQ(srcSlicePitch, static_cast(properties.srcRowPitch * properties.srcSize.y)); + EXPECT_EQ(dstSlicePitch, static_cast(properties.dstRowPitch * properties.dstSize.y)); + } + + { + uint32_t inputSlicePitch = 0x40000; + auto srcSlicePitch = inputSlicePitch; + auto dstSlicePitch = inputSlicePitch; + BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + + EXPECT_EQ(srcSlicePitch, inputSlicePitch); + EXPECT_EQ(dstSlicePitch, inputSlicePitch); + } } struct MyMockResourecInfo : public GmmResourceInfo { using GmmResourceInfo::resourceInfo; @@ -214,15 +169,14 @@ struct MyMockResourecInfo : public GmmResourceInfo { GMM_RESOURCE_FLAG flags = {}; }; -HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenAppendImageCommandsThenPitchIsValueFromGmm, IsGen12LP) { +HWTEST2_F(BlitTests, givenTiledSrcAndDestinationImagesWhenAppendImageCommandsThenPitchIsValueFromGmm, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(); GMM_RESCREATE_PARAMS gmmParams = {}; auto myResourecInfo = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); myResourecInfo->pitch = 0x100; + myResourecInfo->flags.Info.TiledY = 1; gmm->gmmResourceInfo.reset(myResourecInfo.release()); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = true; MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); @@ -233,26 +187,27 @@ HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenAppendImageCommandsThenPitch mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; - properties.dstRowPitch = 0x1000; - properties.srcRowPitch = 0x1000; - properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getDestinationPitch(), gmm->gmmResourceInfo->getRenderPitch() / sizeof(uint32_t)); - EXPECT_EQ(bltCmd.getSourcePitch(), gmm->gmmResourceInfo->getRenderPitch() / sizeof(uint32_t)); + properties.srcRowPitch = 0x1000; + properties.dstRowPitch = 0x4000; + auto srcSlicePitch = static_cast(properties.srcSlicePitch); + auto dstSlicePitch = static_cast(properties.dstSlicePitch); + BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + EXPECT_EQ(bltCmd.getDestinationPitch(), gmm->gmmResourceInfo->getRenderPitch()); + EXPECT_EQ(bltCmd.getSourcePitch(), gmm->gmmResourceInfo->getRenderPitch()); + EXPECT_NE(bltCmd.getDestinationPitch(), static_cast(properties.dstRowPitch)); + EXPECT_NE(bltCmd.getSourcePitch(), static_cast(properties.srcRowPitch)); } -HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenGmmReturnsNotAlignedPitchThenValuesInCommandAreAligned, IsGen12LP) { - constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; +HWTEST2_F(BlitTests, givenLinearSrcAndDestinationImagesWhenAppendImageCommandsThenPitchIsValueFromProperties, IsGen12LP) { using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; auto gmm = std::make_unique(); GMM_RESCREATE_PARAMS gmmParams = {}; auto myResourecInfo = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); - myResourecInfo->pitch = 0xFC; + myResourecInfo->pitch = 0x100; + myResourecInfo->flags.Info.Linear = 1; gmm->gmmResourceInfo.reset(myResourecInfo.release()); - auto flags = gmm->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = true; MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), MemoryPool::System4KBPages); @@ -263,83 +218,15 @@ HWTEST2_F(BlitTests, givenTiledSrcAndDestinationWhenGmmReturnsNotAlignedPitchThe mockAllocationDst.setGmm(gmm.get(), 0); auto bltCmd = FamilyType::cmdInitXyCopyBlt; BlitProperties properties = {}; - properties.dstRowPitch = 0x1000; - properties.srcRowPitch = 0x1000; - properties.srcAllocation = &mockAllocationSrc; properties.dstAllocation = &mockAllocationDst; - auto expectedPitch = alignUp(static_cast(gmm->gmmResourceInfo->getRenderPitch()), TILED_Y_PITCH_ALIGNMENT); - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getDestinationPitch(), expectedPitch / sizeof(uint32_t)); - EXPECT_EQ(bltCmd.getSourcePitch(), expectedPitch / sizeof(uint32_t)); + properties.srcRowPitch = 0x1000; + properties.dstRowPitch = 0x4000; + auto srcSlicePitch = static_cast(properties.srcSlicePitch); + auto dstSlicePitch = static_cast(properties.dstSlicePitch); + BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd, pDevice->getRootDeviceEnvironment(), srcSlicePitch, dstSlicePitch); + EXPECT_NE(bltCmd.getDestinationPitch(), gmm->gmmResourceInfo->getRenderPitch()); + EXPECT_NE(bltCmd.getSourcePitch(), gmm->gmmResourceInfo->getRenderPitch()); + EXPECT_EQ(bltCmd.getDestinationPitch(), static_cast(properties.dstRowPitch)); + EXPECT_EQ(bltCmd.getSourcePitch(), static_cast(properties.srcRowPitch)); } - -HWTEST2_F(BlitTests, givenDstTiledImageAndNotTiledSourceWhenAppendBlitCommandsForImagesThenPitchIsValueInDwords, IsGen12LP) { - constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto gmmSrc = std::make_unique(); - auto gmmDst = std::make_unique(); - GMM_RESCREATE_PARAMS gmmParams = {}; - auto myResourecInfoSrc = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); - auto myResourecInfoDst = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); - myResourecInfoSrc->pitch = 0x100; - myResourecInfoDst->pitch = 0x200; - gmmSrc->gmmResourceInfo.reset(myResourecInfoSrc.release()); - gmmDst->gmmResourceInfo.reset(myResourecInfoDst.release()); - auto flags = gmmDst->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = true; - MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - mockAllocationSrc.setGmm(gmmSrc.get(), 0); - mockAllocationDst.setGmm(gmmDst.get(), 0); - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - properties.dstRowPitch = 0x1000; - properties.srcRowPitch = 0x1000; - - properties.srcAllocation = &mockAllocationSrc; - properties.dstAllocation = &mockAllocationDst; - auto expectedPitch = alignUp(static_cast(gmmDst->gmmResourceInfo->getRenderPitch()), TILED_Y_PITCH_ALIGNMENT); - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getDestinationPitch(), expectedPitch / sizeof(uint32_t)); - EXPECT_EQ(bltCmd.getSourcePitch(), properties.srcRowPitch); -} - -HWTEST2_F(BlitTests, givenSrcTiledImageAndNotTiledDstWhenAppendBlitCommandsForImagesThenPitchIsValueInDwords, IsGen12LP) { - constexpr uint32_t TILED_Y_PITCH_ALIGNMENT = 128; - using XY_COPY_BLT = typename FamilyType::XY_COPY_BLT; - auto gmmSrc = std::make_unique(); - auto gmmDst = std::make_unique(); - GMM_RESCREATE_PARAMS gmmParams = {}; - auto myResourecInfoSrc = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); - auto myResourecInfoDst = std::make_unique(pDevice->getRootDeviceEnvironment().getGmmClientContext(), &gmmParams); - myResourecInfoSrc->pitch = 0x100; - myResourecInfoDst->pitch = 0x200; - gmmSrc->gmmResourceInfo.reset(myResourecInfoSrc.release()); - gmmDst->gmmResourceInfo.reset(myResourecInfoDst.release()); - auto flags = gmmSrc->gmmResourceInfo->getResourceFlags(); - flags->Info.TiledY = true; - MockGraphicsAllocation mockAllocationSrc(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - MockGraphicsAllocation mockAllocationDst(0, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY, - reinterpret_cast(0x1234), 0x1000, 0, sizeof(uint32_t), - MemoryPool::System4KBPages); - mockAllocationSrc.setGmm(gmmSrc.get(), 0); - mockAllocationDst.setGmm(gmmDst.get(), 0); - auto bltCmd = FamilyType::cmdInitXyCopyBlt; - BlitProperties properties = {}; - properties.dstRowPitch = 0x1000; - properties.srcRowPitch = 0x1000; - - properties.srcAllocation = &mockAllocationSrc; - properties.dstAllocation = &mockAllocationDst; - auto expectedPitch = alignUp(static_cast(gmmSrc->gmmResourceInfo->getRenderPitch()), TILED_Y_PITCH_ALIGNMENT); - BlitCommandsHelper::appendBlitCommandsForImages(properties, bltCmd); - EXPECT_EQ(bltCmd.getSourcePitch(), expectedPitch / sizeof(uint32_t)); - EXPECT_EQ(bltCmd.getDestinationPitch(), properties.dstRowPitch); -} \ No newline at end of file