[Mesa-dev] [PATCH 28/41] main: Nameless texture creation and deletion. Does not affect normal creation and deletion paths.

Anuj Phogat anuj.phogat at gmail.com
Wed Dec 31 10:45:05 PST 2014


On Mon, Dec 15, 2014 at 5:22 PM, Laura Ekstrand <laura at jlekstrand.net> wrote:
> In implementing ARB_DIRECT_STATE_ACCESS functions, it is often necessary to
> abstract the functionality of a traditional GL API function into a backend
> that both the traditional and dsa API functions can share.  For instance,
> glTexParameteri and glTextureParameteri both call _mesa_texture_parameteri,
> which takes a context object and a texture object as arguments.
>
> The existance of such backend functions provides the opportunity for
> driver internals (such as meta) to pass around the actual texture object
> rather than its ID or target, saving on texture object storage and look-up
> overhead.
>
> This patch provides nameless texture creation and deletion for meta.  This
> will be used in an upcoming refactor of meta.
> ---
>  src/mesa/main/texobj.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/mesa/main/texobj.h |  7 ++++++
>  2 files changed, 67 insertions(+)
>
> diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> index eb16f47..01088e3 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -1102,6 +1102,27 @@ invalidate_tex_image_error_check(struct gl_context *ctx, GLuint texture,
>     return t;
>  }
>
> +/**
> + * Wrapper for the driver function. Need this because _mesa_new_texture_object
> + * permits a target of 0 and does not initialize targetIndex.
> + */
> +struct gl_texture_object *
> +_mesa_create_nameless_texture( struct gl_context *ctx, GLenum target )
> +{
> +      struct gl_texture_object *texObj = NULL;
> +      GLint targetIndex;
> +
> +      if (target == 0)
> +         return texObj;
> +
> +      texObj = ctx->Driver.NewTextureObject(ctx, 0, target);
> +      targetIndex = _mesa_tex_target_to_index(ctx, texObj->Target);
> +      assert(targetIndex < NUM_TEXTURE_TARGETS);
> +      texObj->TargetIndex = targetIndex;
> +
> +      return texObj;
> +}
> +
>  /* Helper function for glCreateTextures and glGenTextures. Need this because
>   * glCreateTextures should throw errors if target = 0. This is not exposed to
>   * the rest of Mesa to encourage Mesa internals to use nameless textures,
> @@ -1405,6 +1426,45 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
>     }
>  }
>
> +/**
> + * This deletes a texObj without altering the hash table.
> + */
> +void
> +_mesa_delete_nameless_texture( struct gl_context *ctx,
> +                               struct gl_texture_object *texObj )
> +{
> +   FLUSH_VERTICES(ctx, 0);
> +   if (texObj) {
might use:
if (!texObj)
   return;
> +      _mesa_lock_texture(ctx, texObj);
> +
> +      /* Check if texture is bound to any framebuffer objects.
> +       * If so, unbind.
> +       * See section 4.4.2.3 of GL_EXT_framebuffer_object.
> +       */
> +      unbind_texobj_from_fbo(ctx, texObj);
> +
> +      /* Check if this texture is currently bound to any texture units.
> +       * If so, unbind it.
> +       */
> +      unbind_texobj_from_texunits(ctx, texObj);
> +
> +      /* Check if this texture is currently bound to any shader
> +       * image unit.  If so, unbind it.
> +       * See section 3.9.X of GL_ARB_shader_image_load_store.
> +       */
> +      unbind_texobj_from_image_units(ctx, texObj);
> +
> +      _mesa_unlock_texture(ctx, texObj);
> +
> +      ctx->NewState |= _NEW_TEXTURE;
> +
> +      /* Unreference the texobj.  If refcount hits zero, the texture
> +       * will be deleted.
> +       */
> +      _mesa_reference_texobj(&texObj, NULL);
> +   }
> +}
> +
>
>  /**
>   * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
> diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
> index 34daebb..3a62d63 100644
> --- a/src/mesa/main/texobj.h
> +++ b/src/mesa/main/texobj.h
> @@ -190,6 +190,13 @@ _mesa_unlock_context_textures( struct gl_context *ctx );
>  extern void
>  _mesa_lock_context_textures( struct gl_context *ctx );
>
> +extern struct gl_texture_object *
> +_mesa_create_nameless_texture( struct gl_context *ctx, GLenum target );
> +
> +extern void
> +_mesa_delete_nameless_texture( struct gl_context *ctx,
> +                               struct gl_texture_object *texObj );
> +
>  extern void
>  _mesa_bind_texture_unit( struct gl_context *ctx,
>                           GLuint unit,
> --
> 2.1.0
>
> _______________________________________________
> 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