@@ -787,13 +787,21 @@ ur_result_t bindlessImagesHandleCopyFlags(
787787 ze_image_region_t DstRegion;
788788 UR_CALL (getImageRegionHelper (zeSrcImageDesc, &pCopyRegion->dstOffset ,
789789 &pCopyRegion->copyExtent , DstRegion));
790+ // UR accepts copy regions as byte-pixel-pixel format, i.e. X-axis offset
791+ // and width are specified as bytes, whilst Y/Z-axis offsets, height and
792+ // depth are specified as pixels (or rows and slices). ze_image_region_t,
793+ // however, accepts everything as pixels, so we need to do a conversion
794+ // here.
795+ auto PixelSizeInBytes = getPixelSizeBytes (pSrcImageFormat);
796+ DstRegion.originX /= PixelSizeInBytes;
797+ DstRegion.width /= PixelSizeInBytes;
798+
790799 auto *urDstImg = static_cast <ur_bindless_mem_handle_t *>(pDst);
791800
792- const char *SrcPtr =
793- static_cast <const char *>(pSrc) +
794- pCopyRegion->srcOffset .z * SrcSlicePitch +
795- pCopyRegion->srcOffset .y * SrcRowPitch +
796- pCopyRegion->srcOffset .x * getPixelSizeBytes (pSrcImageFormat);
801+ const char *SrcPtr = static_cast <const char *>(pSrc) +
802+ pCopyRegion->srcOffset .z * SrcSlicePitch +
803+ pCopyRegion->srcOffset .y * SrcRowPitch +
804+ pCopyRegion->srcOffset .x ;
797805
798806 ZE2UR_CALL (zeCommandListAppendImageCopyFromMemoryExt,
799807 (ZeCommandList, urDstImg->getZeImage (), SrcPtr, &DstRegion,
@@ -830,13 +838,20 @@ ur_result_t bindlessImagesHandleCopyFlags(
830838 ze_image_region_t SrcRegion;
831839 UR_CALL (getImageRegionHelper (zeSrcImageDesc, &pCopyRegion->srcOffset ,
832840 &pCopyRegion->copyExtent , SrcRegion));
841+ // UR accepts copy regions as byte-pixel-pixel format, i.e. X-axis offset
842+ // and width are specified as bytes, whilst Y/Z-axis offsets, height and
843+ // depth are specified as pixels (or rows and slices). ze_image_region_t,
844+ // however, accepts everything as pixels, so we need to do a conversion
845+ // here.
846+ auto PixelSizeInBytes = getPixelSizeBytes (pSrcImageFormat);
847+ SrcRegion.originX /= PixelSizeInBytes;
848+ SrcRegion.width /= PixelSizeInBytes;
833849
834850 auto *urSrcImg = reinterpret_cast <const ur_bindless_mem_handle_t *>(pSrc);
835851
836852 char *DstPtr =
837853 static_cast <char *>(pDst) + pCopyRegion->dstOffset .z * DstSlicePitch +
838- pCopyRegion->dstOffset .y * DstRowPitch +
839- pCopyRegion->dstOffset .x * getPixelSizeBytes (pDstImageFormat);
854+ pCopyRegion->dstOffset .y * DstRowPitch + pCopyRegion->dstOffset .x ;
840855 ZE2UR_CALL (zeCommandListAppendImageCopyToMemoryExt,
841856 (ZeCommandList, DstPtr, urSrcImg->getZeImage (), &SrcRegion,
842857 DstRowPitch, DstSlicePitch, zeSignalEvent, numWaitEvents,
@@ -866,11 +881,30 @@ ur_result_t bindlessImagesHandleCopyFlags(
866881 };
867882 case UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_DEVICE: {
868883 ze_image_region_t DstRegion;
869- UR_CALL (getImageRegionHelper (zeSrcImageDesc, &pCopyRegion->dstOffset ,
884+ UR_CALL (getImageRegionHelper (zeSrcImageDesc,
885+ &pCopyRegion->dstOffset ,
870886 &pCopyRegion->copyExtent , DstRegion));
887+ // UR accepts copy regions as byte-pixel-pixel format, i.e. X-axis offset
888+ // and width are specified as bytes, whilst Y/Z-axis offsets, height and
889+ // depth are specified as pixels (or rows and slices). ze_image_region_t,
890+ // however, accepts everything as pixels, so we need to do a conversion
891+ // here.
892+ auto PixelSizeInBytes = getPixelSizeBytes (pSrcImageFormat);
893+ DstRegion.originX /= PixelSizeInBytes;
894+ DstRegion.width /= PixelSizeInBytes;
895+
871896 ze_image_region_t SrcRegion;
872- UR_CALL (getImageRegionHelper (zeSrcImageDesc, &pCopyRegion->srcOffset ,
897+ UR_CALL (getImageRegionHelper (zeSrcImageDesc,
898+ &pCopyRegion->srcOffset ,
873899 &pCopyRegion->copyExtent , SrcRegion));
900+ // UR accepts copy regions as byte-pixel-pixel format, i.e. X-axis offset
901+ // and width are specified as bytes, whilst Y/Z-axis offsets, height and
902+ // depth are specified as pixels (or rows and slices). ze_image_region_t,
903+ // however, accepts everything as pixels, so we need to do a conversion
904+ // here.
905+ PixelSizeInBytes = getPixelSizeBytes (pSrcImageFormat);
906+ SrcRegion.originX /= PixelSizeInBytes;
907+ SrcRegion.width /= PixelSizeInBytes;
874908
875909 auto *urImgSrc = reinterpret_cast <const ur_bindless_mem_handle_t *>(pSrc);
876910 auto *urImgDst = reinterpret_cast <ur_bindless_mem_handle_t *>(pDst);
@@ -884,26 +918,20 @@ ur_result_t bindlessImagesHandleCopyFlags(
884918 };
885919 case UR_EXP_IMAGE_COPY_FLAG_HOST_TO_HOST: {
886920 // Copy between (possibly) pitched USM regions
921+ ze_copy_region_t ZeDstRegion = {(uint32_t )pCopyRegion->dstOffset .x ,
922+ (uint32_t )pCopyRegion->dstOffset .y ,
923+ (uint32_t )pCopyRegion->dstOffset .z ,
924+ (uint32_t )pCopyRegion->copyExtent .width ,
925+ (uint32_t )pCopyRegion->copyExtent .height ,
926+ (uint32_t )pCopyRegion->copyExtent .depth };
927+ ze_copy_region_t ZeSrcRegion = {(uint32_t )pCopyRegion->dstOffset .x ,
928+ (uint32_t )pCopyRegion->srcOffset .y ,
929+ (uint32_t )pCopyRegion->srcOffset .z ,
930+ (uint32_t )pCopyRegion->copyExtent .width ,
931+ (uint32_t )pCopyRegion->copyExtent .height ,
932+ (uint32_t )pCopyRegion->copyExtent .depth };
887933 uint32_t DstRowPitch = pDstImageDesc->rowPitch ;
888934 uint32_t SrcRowPitch = pSrcImageDesc->rowPitch ;
889- ze_copy_region_t ZeDstRegion = {
890- (uint32_t )(pCopyRegion->dstOffset .x *
891- getPixelSizeBytes (pDstImageFormat)),
892- (uint32_t )pCopyRegion->dstOffset .y ,
893- (uint32_t )pCopyRegion->dstOffset .z ,
894- (uint32_t )(pCopyRegion->copyExtent .width *
895- getPixelSizeBytes (pDstImageFormat)),
896- (uint32_t )pCopyRegion->copyExtent .height ,
897- (uint32_t )pCopyRegion->copyExtent .depth };
898- ze_copy_region_t ZeSrcRegion = {
899- (uint32_t )(pCopyRegion->dstOffset .x *
900- getPixelSizeBytes (pSrcImageFormat)),
901- (uint32_t )pCopyRegion->srcOffset .y ,
902- (uint32_t )pCopyRegion->srcOffset .z ,
903- (uint32_t )(pCopyRegion->copyExtent .width *
904- getPixelSizeBytes (pSrcImageFormat)),
905- (uint32_t )pCopyRegion->copyExtent .height ,
906- (uint32_t )pCopyRegion->copyExtent .depth };
907935 uint32_t DstSlicePitch = DstRowPitch * pDstImageDesc->height ;
908936 uint32_t SrcSlicePitch = SrcRowPitch * pSrcImageDesc->height ;
909937 ZE2UR_CALL (zeCommandListAppendMemoryCopyRegion,
0 commit comments