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

Marek Olšák maraeo at gmail.com
Wed Dec 16 08:44:20 PST 2015


On Wed, Dec 16, 2015 at 12:05 AM, Miklós Máté <mtmkls at gmail.com> wrote:
> Apitrace showed this call to be 5ms (9 times per frame),
> but in reality it's about 500us. This shortcut makes it 20us.
> ---
>  src/mesa/main/teximage.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index ab60a2f..ba13720 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -3393,6 +3393,21 @@ formats_differ_in_component_sizes(mesa_format f1, mesa_format f2)
>     return GL_FALSE;
>  }
>
> +static GLboolean
> +canAvoidRealloc(struct gl_texture_image *texImage, GLenum internalFormat,
> +      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.
>   */
> @@ -3433,6 +3448,20 @@ copyteximage(struct gl_context *ctx, GLuint dims,
>     texObj = _mesa_get_current_tex_object(ctx, target);
>     assert(texObj);
>

Here should be an explanation why it's needed. Also, we don't use "//" comments.

> +   _mesa_lock_texture(ctx, texObj);
> +   {
> +      texImage = _mesa_select_tex_image(texObj, target, level);
> +      if (texImage && canAvoidRealloc(texImage, internalFormat,
> +               x, y, width, height, border)) {
> +         _mesa_unlock_texture(ctx, texObj);
> +         //_mesa_debug(0, "using shortcut\n");
> +         return _mesa_copy_texture_sub_image(ctx, dims, texObj, target, level,
> +               0, 0, 0, x, y, width, height, "CopyTexImage");
> +      }
> +      //_mesa_debug(0, "can't shortcut %p, %dx%d\n", texImage, width, height);
> +   }
> +   _mesa_unlock_texture(ctx, texObj);
> +
>     texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
>                                             internalFormat, GL_NONE, GL_NONE);
>
> --
> 2.6.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list