Skip to content

Commit

Permalink
Correct IMAGE1D_BUFFER width size calculation in BCS
Browse files Browse the repository at this point in the history
Buffer's default bytesPerPixel value always equals 1 and as
IMAGE1D_BUFFER is originally an image, X coordinate needs to be
multiplied by bytesPerPixel in both copySize and (src/dst)Size.

Signed-off-by: Rafal Maziejuk <[email protected]>
Related-To: NEO-6134
  • Loading branch information
RafalMaziejukIntel authored and Compute-Runtime-Automation committed Mar 11, 2022
1 parent 6b29b03 commit 3490b48
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
17 changes: 12 additions & 5 deletions opencl/source/helpers/cl_blit_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct ClBlitProperties {
}
}

static void adjustBlitPropertiesForImage(MemObj *memObj, Vec3<size_t> &size, size_t &bytesPerPixel, uint64_t &gpuAddress, size_t &rowPitch, size_t &slicePitch, BlitterConstants::BlitDirection &blitDirection) {
static void adjustBlitPropertiesForImage(MemObj *memObj, BlitProperties &blitProperties, size_t &rowPitch, size_t &slicePitch, const bool isSource) {
auto image = castToObject<Image>(memObj);
const auto &imageDesc = image->getImageDesc();
auto image_width = imageDesc.image_width;
Expand All @@ -180,6 +180,12 @@ struct ClBlitProperties {
}

SurfaceOffsets surfaceOffsets;
auto &gpuAddress = isSource ? blitProperties.srcGpuAddress : blitProperties.dstGpuAddress;
auto &size = isSource ? blitProperties.srcSize : blitProperties.dstSize;
auto &copySize = blitProperties.copySize;
auto &bytesPerPixel = blitProperties.bytesPerPixel;
auto &blitDirection = blitProperties.blitDirection;

image->getSurfaceOffsets(surfaceOffsets);
gpuAddress += surfaceOffsets.offset;
size.x = image_width;
Expand All @@ -201,6 +207,9 @@ struct ClBlitProperties {
if (blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
blitDirection = BlitterConstants::BlitDirection::BufferToBuffer;
}

size.x *= bytesPerPixel;
copySize.x *= bytesPerPixel;
}
}

Expand All @@ -212,14 +221,12 @@ 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.blitDirection);
adjustBlitPropertiesForImage(builtinOpParams.srcMemObj, blitProperties, srcRowPitch, srcSlicePitch, true);
}

if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage ||
blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
adjustBlitPropertiesForImage(builtinOpParams.dstMemObj, blitProperties.dstSize, blitProperties.bytesPerPixel,
blitProperties.dstGpuAddress, dstRowPitch, dstSlicePitch, blitProperties.blitDirection);
adjustBlitPropertiesForImage(builtinOpParams.dstMemObj, blitProperties, dstRowPitch, dstSlicePitch, false);
}

blitProperties.srcRowPitch = srcRowPitch ? srcRowPitch : blitProperties.srcSize.x * blitProperties.bytesPerPixel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HWTEST_F(BcsTests, givenDebugCapabilityWhenEstimatingCommandSizeThenAddAllRequir
EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite() + sizeof(typename FamilyType::MI_BATCH_BUFFER_END);
expectedSize = alignUp(expectedSize, MemoryConstants::cacheLineSize);

BlitProperties blitProperties;
BlitProperties blitProperties{};
blitProperties.copySize = {bltSize, 1, 1};
BlitPropertiesContainer blitPropertiesContainer;
blitPropertiesContainer.push_back(blitProperties);
Expand Down Expand Up @@ -1443,20 +1443,18 @@ HWTEST_F(BcsTestsImages, givenImage1DWhenAdjustBlitPropertiesForImageIsCalledThe
imgDesc.image_height = 0u;
imgDesc.image_depth = 0u;
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc));
Vec3<size_t> size{0, 0, 0};
size_t bytesPerPixel = 0u;
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;
BlitProperties blitProperties{};
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();

uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, false);

EXPECT_EQ(imgDesc.image_width, size.x);
EXPECT_EQ(1u, size.y);
EXPECT_EQ(1u, size.z);
EXPECT_EQ(expectedBytesPerPixel, bytesPerPixel);
EXPECT_EQ(imgDesc.image_width, blitProperties.dstSize.x);
EXPECT_EQ(1u, blitProperties.dstSize.y);
EXPECT_EQ(1u, blitProperties.dstSize.z);
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
EXPECT_EQ(expectedRowPitch, rowPitch);
EXPECT_EQ(expectedSlicePitch, slicePitch);
}
Expand All @@ -1469,15 +1467,28 @@ HWTEST_F(BcsTestsImages, givenImage1DBufferWhenAdjustBlitPropertiesForImageIsCal

cl_image_desc imgDesc = Image1dBufferDefaults::imageDesc;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc));
Vec3<size_t> size{0, 0, 0};
size_t bytesPerPixel = 0u;

uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
cl_image_format imgFormat{};
imgFormat.image_channel_order = CL_RGBA;
imgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc, &imgFormat));
size_t expectedBytesPerPixel = 4;
BlitProperties blitProperties{};
blitProperties.srcGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();

for (auto &[blitDirection, expectedBlitDirection] : testParams) {
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
EXPECT_EQ(expectedBlitDirection, blitDirection);
blitProperties.blitDirection = blitDirection;
blitProperties.copySize = {1, 1, 1};
blitProperties.srcSize = {imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth};

ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, true);
EXPECT_EQ(expectedBlitDirection, blitProperties.blitDirection);
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
EXPECT_EQ(imgDesc.image_width, blitProperties.srcSize.x / blitProperties.bytesPerPixel);
EXPECT_EQ(imgDesc.image_height, blitProperties.srcSize.y);
EXPECT_EQ(imgDesc.image_depth, blitProperties.srcSize.z);
EXPECT_EQ(1u, blitProperties.copySize.x / blitProperties.bytesPerPixel);
EXPECT_EQ(1u, blitProperties.copySize.y);
EXPECT_EQ(1u, blitProperties.copySize.z);
}
}

Expand All @@ -1490,39 +1501,35 @@ HWTEST_F(BcsTestsImages, givenImage2DArrayWhenAdjustBlitPropertiesForImageIsCall
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;

std::unique_ptr<Image> image(Image2dArrayHelper<>::create(context.get(), &imgDesc));
Vec3<size_t> size{0, 0, 0};
size_t bytesPerPixel = 0u;
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;
BlitProperties blitProperties{};
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();

uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, false);

EXPECT_EQ(imgDesc.image_width, size.x);
EXPECT_EQ(imgDesc.image_height, size.y);
EXPECT_EQ(imgDesc.image_array_size, size.z);
EXPECT_EQ(expectedBytesPerPixel, bytesPerPixel);
EXPECT_EQ(imgDesc.image_width, blitProperties.dstSize.x);
EXPECT_EQ(imgDesc.image_height, blitProperties.dstSize.y);
EXPECT_EQ(imgDesc.image_array_size, blitProperties.dstSize.z);
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
EXPECT_EQ(expectedRowPitch, rowPitch);
EXPECT_EQ(expectedSlicePitch, slicePitch);
}

HWTEST_F(BcsTestsImages, givenImageWithSurfaceOffsetWhenAdjustBlitPropertiesForImageIsCalledThenGpuAddressIsCorrect) {
cl_image_desc imgDesc = Image1dDefaults::imageDesc;
std::unique_ptr<Image> image(Image2dArrayHelper<>::create(context.get(), &imgDesc));
Vec3<size_t> 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;
BlitProperties blitProperties{};
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
uint64_t expectedGpuAddress = blitProperties.dstGpuAddress + surfaceOffset;

ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, false);

EXPECT_EQ(gpuAddress, expectedGpuAddress);
EXPECT_EQ(blitProperties.dstGpuAddress, expectedGpuAddress);
}

HWTEST_F(BcsTests, givenHostPtrToImageWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) {
Expand Down

0 comments on commit 3490b48

Please sign in to comment.