From 067018d4e745a9145627793c7f458ced4d4b4010 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 3 Jun 2019 15:19:18 -0700 Subject: [PATCH] virgl: fix texture resolving with compressed formats util_format_translate_3d expects the source box to be aligned to the block size. When resolving, make sure the size of the staging buffer is aligned to the block size. Signed-off-by: Chia-I Wu Reviewed-by: Alexandros Frantzis --- src/gallium/drivers/virgl/virgl_texture.c | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_texture.c b/src/gallium/drivers/virgl/virgl_texture.c index bba5830d33c..926f8a56f9d 100644 --- a/src/gallium/drivers/virgl/virgl_texture.c +++ b/src/gallium/drivers/virgl/virgl_texture.c @@ -38,10 +38,6 @@ static void virgl_copy_region_with_blit(struct pipe_context *pipe, { struct pipe_blit_info blit; - assert(src_box->width == dst_box->width); - assert(src_box->height == dst_box->height); - assert(src_box->depth == dst_box->depth); - memset(&blit, 0, sizeof(blit)); blit.src.resource = src; blit.src.format = src->format; @@ -53,9 +49,9 @@ static void virgl_copy_region_with_blit(struct pipe_context *pipe, blit.dst.box.x = dst_box->x; blit.dst.box.y = dst_box->y; blit.dst.box.z = dst_box->z; - blit.dst.box.width = src_box->width; - blit.dst.box.height = src_box->height; - blit.dst.box.depth = src_box->depth; + blit.dst.box.width = dst_box->width; + blit.dst.box.height = dst_box->height; + blit.dst.box.depth = dst_box->depth; blit.mask = util_format_get_mask(src->format) & util_format_get_mask(dst->format); blit.filter = PIPE_TEX_FILTER_NEAREST; @@ -184,15 +180,22 @@ static void *texture_transfer_map_resolve(struct pipe_context *ctx, assert(virgl_has_readback_format(ctx->screen, fmt)); } - virgl_init_temp_resource_from_box(&templ, resource, box, level, 0, fmt); + struct pipe_box dst_box = *box; + dst_box.x = dst_box.y = dst_box.z = 0; + if (usage & PIPE_TRANSFER_READ) { + /* readback should scale to the block size */ + dst_box.width = align(dst_box.width, + util_format_get_blockwidth(resource->format)); + dst_box.height = align(dst_box.height, + util_format_get_blockheight(resource->format)); + } + + virgl_init_temp_resource_from_box(&templ, resource, &dst_box, level, 0, fmt); resolve_tmp = ctx->screen->resource_create(ctx->screen, &templ); if (!resolve_tmp) return NULL; - struct pipe_box dst_box = *box; - dst_box.x = dst_box.y = dst_box.z = 0; - if (usage & PIPE_TRANSFER_READ) { virgl_copy_region_with_blit(ctx, resolve_tmp, 0, &dst_box, resource, level, box); @@ -227,7 +230,9 @@ static void *texture_transfer_map_resolve(struct pipe_context *ctx, trans->resolve_transfer->stride, trans->resolve_transfer->layer_stride, 0, 0, 0, - box->width, box->height, box->depth)) { + dst_box.width, + dst_box.height, + dst_box.depth)) { debug_printf("failed to translate format %s to %s\n", util_format_short_name(fmt), util_format_short_name(resource->format)); -- 2.30.2