From 910540dd506c58363b428d40fdde4f0778513fe1 Mon Sep 17 00:00:00 2001 From: David Stevens Date: Thu, 26 Sep 2019 17:28:49 +0900 Subject: [PATCH] virgl/gbm: fix transfer host plane offset and stride - Host plane offset queried from the gbm_bo should not be accumulated across plane transfer loop iterations. - Host plane stride cannot be calculated from host plane0 stride in a generic way, as alignment adjustments cannot be subsampled. Instead of trying of trying to calculate the stride, just query the gbm_bo for it. Signed-off-by: David Stevens Reviewed-by: Gurchetan Singh --- src/virgl_gbm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/virgl_gbm.c b/src/virgl_gbm.c index 033edd2..e87c8f0 100644 --- a/src/virgl_gbm.c +++ b/src/virgl_gbm.c @@ -308,7 +308,7 @@ int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, struct iovec *iove uint32_t num_iovecs, const struct vrend_transfer_info *info) { void *map_data; - uint32_t host_plane_offset, guest_plane_offset, guest_stride0, calc_stride0, host_map_stride0; + uint32_t guest_plane_offset, guest_stride0, calc_stride0, host_map_stride0; uint32_t width = gbm_bo_get_width(bo); uint32_t height = gbm_bo_get_height(bo); @@ -318,7 +318,7 @@ int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, struct iovec *iove if (!layout) return -1; - host_plane_offset = guest_plane_offset = host_map_stride0 = guest_stride0 = 0; + guest_plane_offset = host_map_stride0 = guest_stride0 = 0; uint32_t map_flags = (direction == VIRGL_TRANSFER_TO_HOST) ? GBM_BO_TRANSFER_WRITE : GBM_BO_TRANSFER_READ; void *addr = gbm_bo_map(bo, 0, 0, width, height, map_flags, &host_map_stride0, &map_data); @@ -342,7 +342,7 @@ int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, struct iovec *iove return -1; for (int plane = 0; plane < plane_count; plane++) { - host_plane_offset += gbm_bo_get_offset(bo, plane); + uint32_t host_plane_offset = gbm_bo_get_offset(bo, plane); uint32_t subsampled_x = info->box->x / layout->horizontal_subsampling[plane]; uint32_t subsampled_y = info->box->y / layout->vertical_subsampling[plane]; @@ -353,8 +353,8 @@ int virgl_gbm_transfer(struct gbm_bo *bo, uint32_t direction, struct iovec *iove uint32_t plane_byte_ratio = layout->bytes_per_pixel[plane] / layout->bytes_per_pixel[0]; uint32_t guest_plane_stride = (guest_stride0 * plane_byte_ratio) / layout->horizontal_subsampling[plane]; - uint32_t host_plane_stride = (host_map_stride0 * plane_byte_ratio) - / layout->horizontal_subsampling[plane]; + uint32_t host_plane_stride = plane == 0 + ? host_map_stride0 : gbm_bo_get_stride_for_plane(bo, plane); uint32_t guest_resource_offset = guest_plane_offset + (subsampled_y * guest_plane_stride) + subsampled_x * layout->bytes_per_pixel[plane];