[Mesa-dev] [PATCH 4/6] mesa: add common format-independent memcpy-based ReadPixels path

Brian Paul brianp at vmware.com
Thu Mar 14 12:27:32 PDT 2013


On 03/14/2013 12:45 PM, Marek Olšák wrote:
> I'll need the _mesa_readpixels_needs_slow_path function for the blit-based
> version, but it's also useful to have this memcpy-based path in one place
> and not scattered across several functions.
> ---
>   src/mesa/main/readpix.c |  194 ++++++++++++++++++++++++++++++++++++++---------
>   src/mesa/main/readpix.h |    4 +
>   2 files changed, 164 insertions(+), 34 deletions(-)
>
> diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
> index e6d0ecd..790cf2a 100644
> --- a/src/mesa/main/readpix.c
> +++ b/src/mesa/main/readpix.c
> @@ -108,11 +108,145 @@ get_readpixels_transfer_ops(struct gl_context *ctx, gl_format texFormat,
>
>
>   /**
> - * Tries to implement glReadPixels() of GL_DEPTH_COMPONENT using memcpy of the
> - * mapping.
> + * Return true if memcpy cannot be used for ReadPixels.
> + *
> + * If uses_blit is true, the function returns true if a simple 3D engine blit
> + * cannot be used for ReadPixels packing.
> + *
> + * NOTE: This doesn't take swizzling and format conversions between
> + *       the readbuffer and the pixel pack buffer into account.
>    */
> +GLboolean
> +_mesa_readpixels_needs_slow_path(struct gl_context *ctx, GLenum format,

const *ctx?


> +                                 GLenum type, GLboolean uses_blit)
> +{
> +   struct gl_renderbuffer *rb =
> +         _mesa_get_read_renderbuffer_for_format(ctx, format);
> +   GLenum srcType;
> +
> +   ASSERT(rb);
> +
> +   /* There are different rules depending on the base format. */
> +   switch (format) {
> +   case GL_DEPTH_STENCIL:
> +      return !_mesa_has_depthstencil_combined(ctx->ReadBuffer) ||
> +             ctx->Pixel.DepthScale != 1.0f || ctx->Pixel.DepthBias != 0.0f ||
> +             ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
> +             ctx->Pixel.MapStencilFlag;
> +
> +   case GL_DEPTH_COMPONENT:
> +      return ctx->Pixel.DepthScale != 1.0f || ctx->Pixel.DepthBias != 0.0f;
> +
> +   case GL_STENCIL_INDEX:
> +      return ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset ||
> +             ctx->Pixel.MapStencilFlag;
> +
> +   default:
> +      /* Color formats. */
> +      if (need_rgb_to_luminance_conversion(rb->Format, format)) {
> +         return GL_TRUE;
> +      }
> +
> +      /* Conversion between signed and unsigned integers needs masking
> +       * (it isn't just memcpy). */
> +      srcType = _mesa_get_format_datatype(rb->Format);
> +
> +      if ((srcType == GL_INT&&
> +           (type == GL_UNSIGNED_INT ||
> +            type == GL_UNSIGNED_SHORT ||
> +            type == GL_UNSIGNED_BYTE)) ||
> +          (srcType == GL_UNSIGNED_INT&&
> +           (type == GL_INT ||
> +            type == GL_SHORT ||
> +            type == GL_BYTE))) {
> +         return GL_TRUE;
> +      }
> +
> +      /* And finally, see if there are any transfer ops. */
> +      return get_readpixels_transfer_ops(ctx, rb->Format, format, type,
> +                                         uses_blit) != 0;
> +   }
> +   return GL_FALSE;
> +}
> +
> +
> +static GLboolean
> +readpixels_can_use_memcpy(struct gl_context *ctx,  GLenum format, GLenum type,

const *ctx?


[...]


Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list