Skip to content

Commit 3490b48

Browse files
Correct IMAGE1D_BUFFER width size calculation in BCS
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
1 parent 6b29b03 commit 3490b48

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

opencl/source/helpers/cl_blit_properties.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct ClBlitProperties {
168168
}
169169
}
170170

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

182182
SurfaceOffsets surfaceOffsets;
183+
auto &gpuAddress = isSource ? blitProperties.srcGpuAddress : blitProperties.dstGpuAddress;
184+
auto &size = isSource ? blitProperties.srcSize : blitProperties.dstSize;
185+
auto &copySize = blitProperties.copySize;
186+
auto &bytesPerPixel = blitProperties.bytesPerPixel;
187+
auto &blitDirection = blitProperties.blitDirection;
188+
183189
image->getSurfaceOffsets(surfaceOffsets);
184190
gpuAddress += surfaceOffsets.offset;
185191
size.x = image_width;
@@ -201,6 +207,9 @@ struct ClBlitProperties {
201207
if (blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
202208
blitDirection = BlitterConstants::BlitDirection::BufferToBuffer;
203209
}
210+
211+
size.x *= bytesPerPixel;
212+
copySize.x *= bytesPerPixel;
204213
}
205214
}
206215

@@ -212,14 +221,12 @@ struct ClBlitProperties {
212221

213222
if (blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToHostPtr ||
214223
blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
215-
adjustBlitPropertiesForImage(builtinOpParams.srcMemObj, blitProperties.srcSize, blitProperties.bytesPerPixel,
216-
blitProperties.srcGpuAddress, srcRowPitch, srcSlicePitch, blitProperties.blitDirection);
224+
adjustBlitPropertiesForImage(builtinOpParams.srcMemObj, blitProperties, srcRowPitch, srcSlicePitch, true);
217225
}
218226

219227
if (blitProperties.blitDirection == BlitterConstants::BlitDirection::HostPtrToImage ||
220228
blitProperties.blitDirection == BlitterConstants::BlitDirection::ImageToImage) {
221-
adjustBlitPropertiesForImage(builtinOpParams.dstMemObj, blitProperties.dstSize, blitProperties.bytesPerPixel,
222-
blitProperties.dstGpuAddress, dstRowPitch, dstSlicePitch, blitProperties.blitDirection);
229+
adjustBlitPropertiesForImage(builtinOpParams.dstMemObj, blitProperties, dstRowPitch, dstSlicePitch, false);
223230
}
224231

225232
blitProperties.srcRowPitch = srcRowPitch ? srcRowPitch : blitProperties.srcSize.x * blitProperties.bytesPerPixel;

opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp

+40-33
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ HWTEST_F(BcsTests, givenDebugCapabilityWhenEstimatingCommandSizeThenAddAllRequir
8484
EncodeMiFlushDW<FamilyType>::getMiFlushDwCmdSizeForDataWrite() + sizeof(typename FamilyType::MI_BATCH_BUFFER_END);
8585
expectedSize = alignUp(expectedSize, MemoryConstants::cacheLineSize);
8686

87-
BlitProperties blitProperties;
87+
BlitProperties blitProperties{};
8888
blitProperties.copySize = {bltSize, 1, 1};
8989
BlitPropertiesContainer blitPropertiesContainer;
9090
blitPropertiesContainer.push_back(blitProperties);
@@ -1443,20 +1443,18 @@ HWTEST_F(BcsTestsImages, givenImage1DWhenAdjustBlitPropertiesForImageIsCalledThe
14431443
imgDesc.image_height = 0u;
14441444
imgDesc.image_depth = 0u;
14451445
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc));
1446-
Vec3<size_t> size{0, 0, 0};
1447-
size_t bytesPerPixel = 0u;
14481446
size_t expectedBytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes;
14491447
size_t expectedRowPitch = image->getImageDesc().image_row_pitch;
14501448
size_t expectedSlicePitch = image->getImageDesc().image_slice_pitch;
1451-
BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage;
1449+
BlitProperties blitProperties{};
1450+
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
14521451

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

1456-
EXPECT_EQ(imgDesc.image_width, size.x);
1457-
EXPECT_EQ(1u, size.y);
1458-
EXPECT_EQ(1u, size.z);
1459-
EXPECT_EQ(expectedBytesPerPixel, bytesPerPixel);
1454+
EXPECT_EQ(imgDesc.image_width, blitProperties.dstSize.x);
1455+
EXPECT_EQ(1u, blitProperties.dstSize.y);
1456+
EXPECT_EQ(1u, blitProperties.dstSize.z);
1457+
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
14601458
EXPECT_EQ(expectedRowPitch, rowPitch);
14611459
EXPECT_EQ(expectedSlicePitch, slicePitch);
14621460
}
@@ -1469,15 +1467,28 @@ HWTEST_F(BcsTestsImages, givenImage1DBufferWhenAdjustBlitPropertiesForImageIsCal
14691467

14701468
cl_image_desc imgDesc = Image1dBufferDefaults::imageDesc;
14711469
imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
1472-
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc));
1473-
Vec3<size_t> size{0, 0, 0};
1474-
size_t bytesPerPixel = 0u;
1475-
1476-
uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
1470+
cl_image_format imgFormat{};
1471+
imgFormat.image_channel_order = CL_RGBA;
1472+
imgFormat.image_channel_data_type = CL_UNSIGNED_INT8;
1473+
std::unique_ptr<Image> image(Image1dHelper<>::create(context.get(), &imgDesc, &imgFormat));
1474+
size_t expectedBytesPerPixel = 4;
1475+
BlitProperties blitProperties{};
1476+
blitProperties.srcGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
14771477

14781478
for (auto &[blitDirection, expectedBlitDirection] : testParams) {
1479-
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
1480-
EXPECT_EQ(expectedBlitDirection, blitDirection);
1479+
blitProperties.blitDirection = blitDirection;
1480+
blitProperties.copySize = {1, 1, 1};
1481+
blitProperties.srcSize = {imgDesc.image_width, imgDesc.image_height, imgDesc.image_depth};
1482+
1483+
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, true);
1484+
EXPECT_EQ(expectedBlitDirection, blitProperties.blitDirection);
1485+
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
1486+
EXPECT_EQ(imgDesc.image_width, blitProperties.srcSize.x / blitProperties.bytesPerPixel);
1487+
EXPECT_EQ(imgDesc.image_height, blitProperties.srcSize.y);
1488+
EXPECT_EQ(imgDesc.image_depth, blitProperties.srcSize.z);
1489+
EXPECT_EQ(1u, blitProperties.copySize.x / blitProperties.bytesPerPixel);
1490+
EXPECT_EQ(1u, blitProperties.copySize.y);
1491+
EXPECT_EQ(1u, blitProperties.copySize.z);
14811492
}
14821493
}
14831494

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

14921503
std::unique_ptr<Image> image(Image2dArrayHelper<>::create(context.get(), &imgDesc));
1493-
Vec3<size_t> size{0, 0, 0};
1494-
size_t bytesPerPixel = 0u;
14951504
size_t expectedBytesPerPixel = image->getSurfaceFormatInfo().surfaceFormat.ImageElementSizeInBytes;
14961505
size_t expectedRowPitch = image->getImageDesc().image_row_pitch;
14971506
size_t expectedSlicePitch = image->getImageDesc().image_slice_pitch;
1498-
BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage;
1507+
BlitProperties blitProperties{};
1508+
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
14991509

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

1503-
EXPECT_EQ(imgDesc.image_width, size.x);
1504-
EXPECT_EQ(imgDesc.image_height, size.y);
1505-
EXPECT_EQ(imgDesc.image_array_size, size.z);
1506-
EXPECT_EQ(expectedBytesPerPixel, bytesPerPixel);
1512+
EXPECT_EQ(imgDesc.image_width, blitProperties.dstSize.x);
1513+
EXPECT_EQ(imgDesc.image_height, blitProperties.dstSize.y);
1514+
EXPECT_EQ(imgDesc.image_array_size, blitProperties.dstSize.z);
1515+
EXPECT_EQ(expectedBytesPerPixel, blitProperties.bytesPerPixel);
15071516
EXPECT_EQ(expectedRowPitch, rowPitch);
15081517
EXPECT_EQ(expectedSlicePitch, slicePitch);
15091518
}
15101519

15111520
HWTEST_F(BcsTestsImages, givenImageWithSurfaceOffsetWhenAdjustBlitPropertiesForImageIsCalledThenGpuAddressIsCorrect) {
15121521
cl_image_desc imgDesc = Image1dDefaults::imageDesc;
15131522
std::unique_ptr<Image> image(Image2dArrayHelper<>::create(context.get(), &imgDesc));
1514-
Vec3<size_t> size{0, 0, 0};
1515-
size_t bytesPerPixel = 0u;
1516-
BlitterConstants::BlitDirection blitDirection = BlitterConstants::BlitDirection::HostPtrToImage;
15171523

15181524
uint64_t surfaceOffset = 0x01000;
15191525
image->setSurfaceOffsets(surfaceOffset, 0, 0, 0);
1520-
uint64_t gpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
1521-
uint64_t expectedGpuAddress = gpuAddress + surfaceOffset;
1526+
BlitProperties blitProperties{};
1527+
blitProperties.dstGpuAddress = image->getGraphicsAllocation(0)->getGpuAddress();
1528+
uint64_t expectedGpuAddress = blitProperties.dstGpuAddress + surfaceOffset;
15221529

1523-
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), size, bytesPerPixel, gpuAddress, rowPitch, slicePitch, blitDirection);
1530+
ClBlitProperties::adjustBlitPropertiesForImage(image.get(), blitProperties, rowPitch, slicePitch, false);
15241531

1525-
EXPECT_EQ(gpuAddress, expectedGpuAddress);
1532+
EXPECT_EQ(blitProperties.dstGpuAddress, expectedGpuAddress);
15261533
}
15271534

15281535
HWTEST_F(BcsTests, givenHostPtrToImageWhenConstructPropertiesIsCalledThenValuesAreSetCorrectly) {

0 commit comments

Comments
 (0)