[Mesa-dev] [PATCH] st/mesa: use a single memcpy in st_ReadPixels when possible

Marek Olšák maraeo at gmail.com
Wed Jun 22 13:12:41 UTC 2016


Hi,

FYI, piglit "mesa_pack_invert-readpixels -auto -fbo" crashes with this commit.

Marek

On Tue, Jun 21, 2016 at 11:08 AM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> This avoids costly address recomputations, function overhead, and may trigger
> large copy optimizations.
> ---
>  src/mesa/state_tracker/st_cb_readpixels.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
> index 39d2274..77c6332 100644
> --- a/src/mesa/state_tracker/st_cb_readpixels.c
> +++ b/src/mesa/state_tracker/st_cb_readpixels.c
> @@ -520,14 +520,21 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y,
>     /* memcpy data into a user buffer */
>     {
>        const uint bytesPerRow = width * util_format_get_blocksize(dst_format);
> -      GLuint row;
> -
> -      for (row = 0; row < (unsigned) height; row++) {
> -         void *dest = _mesa_image_address2d(pack, pixels,
> -                                              width, height, format,
> -                                              type, row, 0);
> -         memcpy(dest, map, bytesPerRow);
> -         map += tex_xfer->stride;
> +      const uint destStride = _mesa_image_row_stride(pack, width, format, type);
> +      char *dest = _mesa_image_address2d(pack, pixels,
> +                                         width, height, format,
> +                                         type, 0, 0);
> +
> +      if (tex_xfer->stride == bytesPerRow && destStride == bytesPerRow) {
> +         memcpy(dest, map, bytesPerRow * height);
> +      } else {
> +         GLuint row;
> +
> +         for (row = 0; row < (unsigned) height; row++) {
> +            memcpy(dest, map, bytesPerRow);
> +            map += tex_xfer->stride;
> +            dest += destStride;
> +         }
>        }
>     }
>
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list