[Mesa-dev] [PATCH 08/11] mesa: Extract computation of compressed pixel store params

Ian Romanick idr at freedesktop.org
Mon Jun 2 15:17:36 PDT 2014


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 06/01/2014 11:29 PM, Chris Forbes wrote:
> This logic is reusable across CompressedTex*Image* and
> GetCompressedTexImage; the strides calculated will also be needed
> in the PBO validation functions to ensure that the referenced range of
> bytes is valid.
> 
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
> ---
>  src/mesa/main/texstore.c | 47 +++++++++++++++++++++++++++++++++--------------
>  src/mesa/main/texstore.h | 17 +++++++++++++++++
>  2 files changed, 50 insertions(+), 14 deletions(-)
> 
> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
> index 7642146..b5b7254 100644
> --- a/src/mesa/main/texstore.c
> +++ b/src/mesa/main/texstore.c
> @@ -4195,6 +4195,26 @@ _mesa_store_compressed_teximage(struct gl_context *ctx, GLuint dims,
>  }
>  
>  
> +void
> +_mesa_compute_compressed_pixelstore(GLuint dims, struct gl_texture_image *texImage,
> +                              GLsizei width, GLsizei height, GLsizei depth,
> +                              const struct gl_pixelstore_attrib *packing,
> +                              struct compressed_pixelstore *store)
> +{
> +   GLuint bw, bh;
> +   const mesa_format texFormat = texImage->TexFormat;
> +
> +   _mesa_get_format_block_size(texFormat, &bw, &bh);
> +
> +   store->SkipBytes = 0;
> +   store->TotalBytesPerRow = store->CopyBytesPerRow =
> +         _mesa_format_row_stride(texFormat, width);
> +   store->TotalRowsPerSlice = store->CopyRowsPerSlice =
> +         (height + bh - 1) / bh;
> +   store->CopySlices = depth;
> +}
> +
> +
>  /**
>   * Fallback for Driver.CompressedTexSubImage()
>   */
> @@ -4206,20 +4226,19 @@ _mesa_store_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
>                                     GLenum format,
>                                     GLsizei imageSize, const GLvoid *data)
>  {
> -   GLint bytesPerRow, dstRowStride, srcRowStride;
> -   GLint i, rows;
> +   struct compressed_pixelstore store;
> +   GLint dstRowStride;
> +   GLint i, slice;
>     GLubyte *dstMap;
>     const GLubyte *src;
> -   const mesa_format texFormat = texImage->TexFormat;
> -   GLuint bw, bh;
> -   GLint slice;
>  
>     if (dims == 1) {
>        _mesa_problem(ctx, "Unexpected 1D compressed texsubimage call");
>        return;
>     }
>  
> -   _mesa_get_format_block_size(texFormat, &bw, &bh);
> +   _mesa_compute_compressed_pixelstore(dims, texImage, width, height, depth,
> +                                 &ctx->Unpack, &store);
>  
>     /* get pointer to src pixels (may be in a pbo which we'll map here) */
>     data = _mesa_validate_pbo_compressed_teximage(ctx, dims, imageSize, data,
> @@ -4228,10 +4247,9 @@ _mesa_store_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
>     if (!data)
>        return;
>  
> -   srcRowStride = _mesa_format_row_stride(texFormat, width);
> -   src = (const GLubyte *) data;
> +   src = (const GLubyte *) data + store.SkipBytes;
>  
> -   for (slice = 0; slice < depth; slice++) {
> +   for (slice = 0; slice < store.CopySlices; slice++) {
>        /* Map dest texture buffer */
>        ctx->Driver.MapTextureImage(ctx, texImage, slice + zoffset,
>                                    xoffset, yoffset, width, height,
> @@ -4239,17 +4257,18 @@ _mesa_store_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
>                                    &dstMap, &dstRowStride);
>  
>        if (dstMap) {
> -         bytesPerRow = srcRowStride;  /* bytes per row of blocks */
> -         rows = (height + bh - 1) / bh;  /* rows in blocks */
>  
>           /* copy rows of blocks */
> -         for (i = 0; i < rows; i++) {
> -            memcpy(dstMap, src, bytesPerRow);
> +         for (i = 0; i < store.CopyRowsPerSlice; i++) {
> +            memcpy(dstMap, src, store.CopyBytesPerRow);
>              dstMap += dstRowStride;
> -            src += srcRowStride;
> +            src += store.TotalBytesPerRow;
>           }
>  
>           ctx->Driver.UnmapTextureImage(ctx, texImage, slice + zoffset);
> +
> +         /* advance to next slice */
> +         src += store.TotalBytesPerRow * (store.TotalRowsPerSlice - store.CopyRowsPerSlice);
>        }
>        else {
>           _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage%uD",
> diff --git a/src/mesa/main/texstore.h b/src/mesa/main/texstore.h
> index 490f9f5..c4cfffd 100644
> --- a/src/mesa/main/texstore.h
> +++ b/src/mesa/main/texstore.h
> @@ -132,4 +132,21 @@ _mesa_store_compressed_texsubimage(struct gl_context *ctx, GLuint dims,
>                                     GLsizei imageSize, const GLvoid *data);
>  
>  
> +struct compressed_pixelstore {
> +   int SkipBytes;
> +   int CopyBytesPerRow;
> +   int CopyRowsPerSlice;
> +   int TotalBytesPerRow;
> +   int TotalRowsPerSlice;
> +   int CopySlices;
> +};
> +
> +
> +extern void
> +_mesa_compute_compressed_pixelstore(GLuint dims, struct gl_texture_image *texImage,
> +                              GLsizei width, GLsizei height, GLsizei depth,
> +                              const struct gl_pixelstore_attrib *packing,
> +                              struct compressed_pixelstore *store);
> +
> +
>  #endif
> 



More information about the mesa-dev mailing list