[Mesa-dev] [PATCH 7/7] mesa: optimize out the realloc from glCopyTexImagexD()

Ian Romanick idr at freedesktop.org
Sat Feb 6 17:42:53 UTC 2016


On 02/05/2016 01:11 PM, Miklós Máté wrote:
> v2: comment about the purpose of the code
> ---
>  src/mesa/main/teximage.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 50141be..cac05d5 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -3486,6 +3486,21 @@ formats_differ_in_component_sizes(mesa_format f1, mesa_format f2)
>     return GL_FALSE;
>  }
>  
> +static GLboolean

static bool

> +canAvoidRealloc(struct gl_texture_image *texImage, GLenum internalFormat,

can_avoid_reallocation

> +      GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
> +{
> +   if (texImage->InternalFormat != internalFormat)
> +      return false;
> +   if (texImage->Border != border)
> +      return false;
> +   if (texImage->Width2 != width)
> +      return false;
> +   if (texImage->Height2 != height)
> +      return false;
> +   return true;
> +}
> +
>  /**
>   * Implement the glCopyTexImage1/2D() functions.
>   */
> @@ -3526,6 +3541,23 @@ copyteximage(struct gl_context *ctx, GLuint dims,
>     texObj = _mesa_get_current_tex_object(ctx, target);
>     assert(texObj);
>  
> +   /* First check if reallocating the texture buffer can be avoided.
> +    * Without the realloc the copy can be 20x faster.
> +    */
> +   _mesa_lock_texture(ctx, texObj);
> +   {
> +      texImage = _mesa_select_tex_image(texObj, target, level);
> +      if (texImage && canAvoidRealloc(texImage, internalFormat,
> +               x, y, width, height, border)) {

Indentation issue that Matt mentioned.

> +         _mesa_unlock_texture(ctx, texObj);
> +         /*_mesa_debug(ctx, "using shortcut\n");*/

Probably safe to remove the commented debug message.

> +         return _mesa_copy_texture_sub_image(ctx, dims, texObj, target, level,
> +               0, 0, 0, x, y, width, height, "CopyTexImage");
> +      }
> +      /*_mesa_debug(ctx, "can't shortcut\n");*/

Ditto.  Though maybe this case could warrant a perf debug message (for
GL_ARB_debug)?

> +   }
> +   _mesa_unlock_texture(ctx, texObj);
> +
>     texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
>                                             internalFormat, GL_NONE, GL_NONE);
>  
> 



More information about the mesa-dev mailing list