[Mesa-dev] [PATCH 03/19] mesa: Optimize unbind_texobj_from_texunits()

Brian Paul brianp at vmware.com
Tue Apr 22 07:19:13 PDT 2014


On 04/21/2014 03:57 PM, Fredrik Höglund wrote:
> The texture can only be bound to the index that corresponds to its
> target, so there is no need to loop over all possible indices
> for every unit and checking if the texture is bound to it.
> ---
>
> v2: Restructure the loop to avoid using continue, and use
>      &= ~(1 << index) to clear bits in _BoundTextures.
>
>   src/mesa/main/texobj.c | 20 +++++++++++---------
>   1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> index 054b41b..7e43472 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -1093,18 +1093,20 @@ static void
>   unbind_texobj_from_texunits(struct gl_context *ctx,
>                               struct gl_texture_object *texObj)
>   {
> -   GLuint u, tex;
> +   const GLuint index = texObj->TargetIndex;

Should that be const gl_texture_index index = ... ?


> +   GLuint u;
> +
> +   if (texObj->Target == 0)
> +      return;
>
>      for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
>         struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
> -      for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
> -         if (texObj == unit->CurrentTex[tex]) {
> -            _mesa_reference_texobj(&unit->CurrentTex[tex],
> -                                   ctx->Shared->DefaultTex[tex]);
> -            ASSERT(unit->CurrentTex[tex]);
> -            unit->_BoundTextures &= ~(1 << tex);
> -            break;
> -         }
> +
> +      if (texObj == unit->CurrentTex[index]) {
> +         /* Bind the default texture for this unit/target */
> +         _mesa_reference_texobj(&unit->CurrentTex[index],
> +                                ctx->Shared->DefaultTex[index]);
> +         unit->_BoundTextures &= ~(1 << index);
>         }
>      }
>   }
>



More information about the mesa-dev mailing list