From: Nicolai Hähnle Date: Wed, 9 Nov 2016 14:46:21 +0000 (+0100) Subject: st/mesa: simplify and fix st_GetTexSubImage X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=22360406f78b29eb0548b2f71bfb8ed447b3c1dd;p=mesa.git st/mesa: simplify and fix st_GetTexSubImage By using _mesa_image_address, the code becomes simpler _and_ fixes the bug that GL_PACK_SKIP_IMAGES was applied even on non-3D textures. Also, converting a whole slice at a time simplifies the format translation fallback path. Fixes parts of GL45-CTS.gtf32.GL3Tests.packed_pixels.packed_pixels_pixelstore. v2: fix a silly mistake during code movement Reviewed-by: Marek Olšák Reviewed-by: Edward O'Callaghan --- diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 45f04487b38..e358c738c07 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1826,6 +1826,7 @@ st_GetTexSubImage(struct gl_context * ctx, mesa_format mesa_format; GLenum gl_target = texImage->TexObject->Target; enum pipe_texture_target pipe_target; + unsigned dims; struct pipe_blit_info blit; unsigned bind; struct pipe_transfer *tex_xfer; @@ -2014,6 +2015,7 @@ st_GetTexSubImage(struct gl_context * ctx, } mesa_format = st_pipe_format_to_mesa_format(dst_format); + dims = _mesa_get_texture_dimensions(gl_target); /* copy/pack data into user buffer */ if (_mesa_format_matches_format_and_type(mesa_format, format, type, @@ -2023,39 +2025,31 @@ st_GetTexSubImage(struct gl_context * ctx, GLuint row, slice; for (slice = 0; slice < depth; slice++) { - if (gl_target == GL_TEXTURE_1D_ARRAY) { - /* 1D array textures. - * We need to convert gallium coords to GL coords. - */ - void *dest = _mesa_image_address3d(&ctx->Pack, pixels, - width, depth, format, - type, 0, slice, 0); - memcpy(dest, map, bytesPerRow); - } - else { - ubyte *slice_map = map; + ubyte *slice_map = map; - for (row = 0; row < height; row++) { - void *dest = _mesa_image_address3d(&ctx->Pack, pixels, - width, height, format, - type, slice, row, 0); - memcpy(dest, slice_map, bytesPerRow); - slice_map += tex_xfer->stride; - } + for (row = 0; row < height; row++) { + void *dest = _mesa_image_address(dims, &ctx->Pack, pixels, + width, height, format, type, + slice, row, 0); + + memcpy(dest, slice_map, bytesPerRow); + + slice_map += tex_xfer->stride; } + map += tex_xfer->layer_stride; } } else { /* format translation via floats */ - GLuint row, slice; + GLuint slice; GLfloat *rgba; uint32_t dstMesaFormat; int dstStride, srcStride; assert(util_format_is_compressed(src->format)); - rgba = malloc(width * 4 * sizeof(GLfloat)); + rgba = malloc(width * height * 4 * sizeof(GLfloat)); if (!rgba) { goto end; } @@ -2067,37 +2061,18 @@ st_GetTexSubImage(struct gl_context * ctx, dstStride = _mesa_image_row_stride(&ctx->Pack, width, format, type); srcStride = 4 * width * sizeof(GLfloat); for (slice = 0; slice < depth; slice++) { - if (gl_target == GL_TEXTURE_1D_ARRAY) { - /* 1D array textures. - * We need to convert gallium coords to GL coords. - */ - void *dest = _mesa_image_address3d(&ctx->Pack, pixels, - width, depth, format, - type, 0, slice, 0); + void *dest = _mesa_image_address(dims, &ctx->Pack, pixels, + width, height, format, type, + slice, 0, 0); - /* get float[4] rgba row from surface */ - pipe_get_tile_rgba_format(tex_xfer, map, 0, 0, width, 1, - dst_format, rgba); + /* get float[4] rgba row from surface */ + pipe_get_tile_rgba_format(tex_xfer, map, 0, 0, width, height, + dst_format, rgba); + + _mesa_format_convert(dest, dstMesaFormat, dstStride, + rgba, RGBA32_FLOAT, srcStride, + width, height, NULL); - _mesa_format_convert(dest, dstMesaFormat, dstStride, - rgba, RGBA32_FLOAT, srcStride, - width, 1, NULL); - } - else { - for (row = 0; row < height; row++) { - void *dest = _mesa_image_address3d(&ctx->Pack, pixels, - width, height, format, - type, slice, row, 0); - - /* get float[4] rgba row from surface */ - pipe_get_tile_rgba_format(tex_xfer, map, 0, row, width, 1, - dst_format, rgba); - - _mesa_format_convert(dest, dstMesaFormat, dstStride, - rgba, RGBA32_FLOAT, srcStride, - width, 1, NULL); - } - } map += tex_xfer->layer_stride; }