From 385c60948e67b80ef0f57a873ee3e48d109cf6a7 Mon Sep 17 00:00:00 2001 From: Rafal Maziejuk Date: Tue, 1 Mar 2022 18:22:20 +0000 Subject: [PATCH] Treat IMAGE1D_BUFFER type as buffer in BCS This type of image needs to be treated as buffer in order to allow width to be greater than 16383. Signed-off-by: Rafal Maziejuk Related-To: NEO-6134 --- opencl/source/helpers/cl_blit_properties.h | 22 +++++++++++--- .../command_stream_receiver_hw_2_tests.cpp | 29 +++++++++++++++++-- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/opencl/source/helpers/cl_blit_properties.h b/opencl/source/helpers/cl_blit_properties.h index 8de1317fc1..464ca3a371 100644 --- a/opencl/source/helpers/cl_blit_properties.h +++ b/opencl/source/helpers/cl_blit_properties.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -168,7 +168,7 @@ struct ClBlitProperties { } } - static void adjustBlitPropertiesForImage(MemObj *memObj, Vec3 &size, size_t &bytesPerPixel, uint64_t &gpuAddress, size_t &rowPitch, size_t &slicePitch) { + static void adjustBlitPropertiesForImage(MemObj *memObj, Vec3 &size, size_t &bytesPerPixel, uint64_t &gpuAddress, size_t &rowPitch, size_t &slicePitch, BlitterConstants::BlitDirection &blitDirection) { auto image = castToObject(memObj); const auto &imageDesc = image->getImageDesc(); auto image_width = imageDesc.image_width; @@ -188,6 +188,20 @@ struct ClBlitProperties { bytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; rowPitch = imageDesc.image_row_pitch; slicePitch = imageDesc.image_slice_pitch; + + if (imageDesc.image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER) { + if (blitDirection == BlitterConstants::BlitDirection::HostPtrToImage) { + blitDirection = BlitterConstants::BlitDirection::HostPtrToBuffer; + } + + if (blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr) { + blitDirection = BlitterConstants::BlitDirection::BufferToHostPtr; + } + + if (blitDirection == BlitterConstants::BlitDirection::ImageToImage) { + blitDirection = BlitterConstants::BlitDirection::BufferToBuffer; + } + } } static void setBlitPropertiesForImage(BlitProperties &blitProperties, const BuiltinOpParams &builtinOpParams) { @@ -199,13 +213,13 @@ struct ClBlitProperties { if (blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr || blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) { adjustBlitPropertiesForImage(builtinOpParams.srcMemObj, blitProperties.srcSize, blitProperties.bytesPerPixel, - blitProperties.srcGpuAddress, srcRowPitch, srcSlicePitch); + blitProperties.srcGpuAddress, srcRowPitch, srcSlicePitch, blitProperties.blitDirection); } if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage || blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) { adjustBlitPropertiesForImage(builtinOpParams.dstMemObj, blitProperties.dstSize, blitProperties.bytesPerPixel, - blitProperties.dstGpuAddress, dstRowPitch, dstSlicePitch); + blitProperties.dstGpuAddress, dstRowPitch, dstSlicePitch, blitProperties.blitDirection); } blitProperties.srcRowPitch = srcRowPitch ? srcRowPitch : blitProperties.srcSize.x * blitProperties.bytesPerPixel; 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 12055124c7..5328b55a44 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 @@ -1448,9 +1448,10 @@ HWTEST_F(BcsTestsImages, givenImage1DWhenAdjustBlitPropertiesForImageIsCalledThe size_t expectedBytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; size_t expectedRowPitch = image->getImageDesc().image_row_pitch; size_t expectedSlicePitch = image->getImageDesc().image_slice_pitch; + BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage; uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress(); - ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch); + ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection); EXPECT_EQ(imgDesc.image_width, size.x); EXPECT_EQ(1u, size.y); @@ -1460,6 +1461,26 @@ HWTEST_F(BcsTestsImages, givenImage1DWhenAdjustBlitPropertiesForImageIsCalledThe EXPECT_EQ(expectedSlicePitch, slicePitch); } +HWTEST_F(BcsTestsImages, givenImage1DBufferWhenAdjustBlitPropertiesForImageIsCalledThenValuesAreSetCorrectly) { + using BlitterConstants::BlitDirection; + std::array, 3> testParams = {{{BlitDirection::HostPtrToImage, BlitDirection::HostPtrToBuffer}, + {BlitDirection::ImageToHostPtr, BlitDirection::BufferToHostPtr}, + {BlitDirection::ImageToImage, BlitDirection::BufferToBuffer}}}; + + cl_image_desc imgDesc = Image1dBufferDefaults::imageDesc; + imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER; + std::unique_ptr image(Image1dHelper<>::create(context.get(), &imgDesc)); + Vec3 size{0, 0, 0}; + size_t bytesPerPixel = 0u; + + uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress(); + + for (auto &[blitDirection, expectedBlitDirection] : testParams) { + ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection); + EXPECT_EQ(expectedBlitDirection, blitDirection); + } +} + HWTEST_F(BcsTestsImages, givenImage2DArrayWhenAdjustBlitPropertiesForImageIsCalledThenValuesAreSetCorrectly) { cl_image_desc imgDesc = Image1dDefaults::imageDesc; imgDesc.image_width = 10u; @@ -1474,9 +1495,10 @@ HWTEST_F(BcsTestsImages, givenImage2DArrayWhenAdjustBlitPropertiesForImageIsCall size_t expectedBytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes; size_t expectedRowPitch = image->getImageDesc().image_row_pitch; size_t expectedSlicePitch = image->getImageDesc().image_slice_pitch; + BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage; uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress(); - ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch); + ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection); EXPECT_EQ(imgDesc.image_width, size.x); EXPECT_EQ(imgDesc.image_height, size.y); @@ -1491,13 +1513,14 @@ HWTEST_F(BcsTestsImages, givenImageWithSurfaceOffsetWhenAdjustBlitPropertiesForI std::unique_ptr image(Image2dArrayHelper<>::create(context.get(), &imgDesc)); Vec3 size{0, 0, 0}; size_t bytesPerPixel = 0u; + BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage; uint64_t surfaceOffset = 0x01000; image->setSurfaceOffsets(surfaceOffset, 0, 0, 0); uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress(); uint64_t expectedGpuAddress = gpuAddress + surfaceOffset; - ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch); + ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection); EXPECT_EQ(gpuAddress, expectedGpuAddress); }