Skip to content

Commit 880fd69

Browse files
committed
WIP
1 parent 388ccf5 commit 880fd69

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

sycl/source/handler.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,27 @@ fill_copy_args(detail::handler_impl *impl,
262262
auto ZCopyExtentComponent = detail::fill_image_type(SrcImgDesc, UrSrcDesc);
263263
detail::fill_image_type(DestImgDesc, UrDestDesc);
264264

265-
impl->MSrcOffset = {SrcOffset[0], SrcOffset[1], SrcOffset[2]};
266-
impl->MDestOffset = {DestOffset[0], DestOffset[1], DestOffset[2]};
265+
// Copy args computed here are directly passed to UR. Various offsets and
266+
// extents end up passed as ur_rect_offset_t and ur_rect_region_t. Both those
267+
// structs expect theirfirst component to be in bytes, not in pixels
268+
size_t SrcPixelSize = SrcImgDesc.num_channels * get_channel_size(SrcImgDesc);
269+
size_t DestPixelSize =
270+
DestImgDesc.num_channels * get_channel_size(DestImgDesc);
271+
272+
impl->MSrcOffset = {SrcOffset[0] * SrcPixelSize, SrcOffset[1], SrcOffset[2]};
273+
impl->MDestOffset = {DestOffset[0] * DestPixelSize, DestOffset[1],
274+
DestOffset[2]};
267275
impl->MSrcImageDesc = UrSrcDesc;
268276
impl->MDstImageDesc = UrDestDesc;
269277
impl->MSrcImageFormat = UrSrcFormat;
270278
impl->MDstImageFormat = UrDestFormat;
271279
impl->MImageCopyFlags = ImageCopyFlags;
272280

273281
if (CopyExtent.size() != 0) {
274-
impl->MCopyExtent = {CopyExtent[0], CopyExtent[1], CopyExtent[2]};
282+
impl->MCopyExtent = {CopyExtent[0] * SrcPixelSize, CopyExtent[1],
283+
CopyExtent[2]};
275284
} else {
276-
impl->MCopyExtent = {SrcImgDesc.width, SrcImgDesc.height,
285+
impl->MCopyExtent = {SrcImgDesc.width * SrcPixelSize, SrcImgDesc.height,
277286
ZCopyExtentComponent};
278287
}
279288

unified-runtime/source/adapters/level_zero/image_common.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,20 @@ ur_result_t getImageRegionHelper(ze_image_desc_t ZeImageDesc,
747747
UR_RESULT_ERROR_INVALID_VALUE);
748748
#endif // !NDEBUG
749749

750-
uint32_t OriginX = ur_cast<uint32_t>(Origin->x);
750+
// ur_rect_offset_t and ur_rect_region_t describe first component using bytes
751+
// ze_image_region_t however uses pixels for it
752+
753+
// TODO: this is less efficient than a direct calculation of a pixel size
754+
// using ze_image_format_t
755+
ur_image_format_t UrImageFormat;
756+
UR_CALL(ze2urImageFormat(ZeImageDesc.format, &UrImageFormat));
757+
uint32_t PixelSizeBytes = getPixelSizeBytes(&UrImageFormat);
758+
759+
uint32_t OriginX = ur_cast<uint32_t>(Origin->x) / PixelSizeBytes;
751760
uint32_t OriginY = ur_cast<uint32_t>(Origin->y);
752761
uint32_t OriginZ = ur_cast<uint32_t>(Origin->z);
753762

754-
uint32_t Width = ur_cast<uint32_t>(Region->width);
763+
uint32_t Width = ur_cast<uint32_t>(Region->width) / PixelSizeBytes;
755764
uint32_t Height = (ZeImageDesc.type == ZE_IMAGE_TYPE_1DARRAY)
756765
? ZeImageDesc.arraylevels
757766
: ur_cast<uint32_t>(Region->height);

0 commit comments

Comments
 (0)