st/mesa: fix sampler view handling with shared textures v4
authorChristian König <christian.koenig@amd.com>
Sun, 23 Mar 2014 16:01:38 +0000 (17:01 +0100)
committerChristian König <christian.koenig@amd.com>
Wed, 26 Mar 2014 11:06:43 +0000 (12:06 +0100)
Release the references to the sampler views before
destroying the pipe context.

v2: remove TODO and unrelated change
v3: move to st_texture.[ch], rename callback, add comment
v4: fix rebase mess up and add further cleanups

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Cc: "10.0 10.1" <mesa-stable@lists.freedesktop.org>
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_texture.c
src/mesa/state_tracker/st_texture.h

index 0ffc7626388bac7d2bd6c7caadaf020ffebfd97e..807a86fdf93e5af195d2de0ae717caad8222c378 100644 (file)
@@ -33,6 +33,7 @@
 #include "main/shaderobj.h"
 #include "main/version.h"
 #include "main/vtxfmt.h"
+#include "main/hash.h"
 #include "program/prog_cache.h"
 #include "vbo/vbo.h"
 #include "glapi/glapi.h"
@@ -66,6 +67,7 @@
 #include "st_gen_mipmap.h"
 #include "st_program.h"
 #include "st_vdpau.h"
+#include "st_texture.h"
 #include "pipe/p_context.h"
 #include "util/u_inlines.h"
 #include "util/u_upload_mgr.h"
@@ -280,6 +282,19 @@ static void st_destroy_context_priv( struct st_context *st )
    free( st );
 }
 
+
+/**
+ * Callback to release the sampler view attached to a texture object.
+ * Called by _mesa_HashWalk().
+ */
+static void
+destroy_tex_sampler_cb(GLuint id, void *data, void *userData)
+{
+   struct gl_texture_object *texObj = (struct gl_texture_object *) data;
+   struct st_context *st = (struct st_context *) userData;
+
+   st_texture_release_sampler_view(st, st_texture_object(texObj));
+}
  
 void st_destroy_context( struct st_context *st )
 {
@@ -288,6 +303,8 @@ void st_destroy_context( struct st_context *st )
    struct gl_context *ctx = st->ctx;
    GLuint i;
 
+   _mesa_HashWalk(ctx->Shared->TexObjects, destroy_tex_sampler_cb, st);
+
    /* need to unbind and destroy CSO objects before anything else */
    cso_release_all(st->cso_context);
 
index b5ccc76d4b96d2d40bfa3d5066b5ed06a6b0fe2a..a3b345356e1d7b9d66c770fbdf2180c4c87df7e0 100644 (file)
@@ -412,3 +412,10 @@ st_create_color_map_texture(struct gl_context *ctx)
    return pt;
 }
 
+void
+st_texture_release_sampler_view(struct st_context *st,
+                                struct st_texture_object *stObj)
+{
+   if (stObj->sampler_view && stObj->sampler_view->context == st->pipe)
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+}
index bce2a0934e82bc1fe54e22ffdd223c42a42459d4..b4a27a00a9b511966df32a188a82664fd1cc8046 100644 (file)
@@ -227,4 +227,8 @@ st_texture_image_copy(struct pipe_context *pipe,
 extern struct pipe_resource *
 st_create_color_map_texture(struct gl_context *ctx);
 
+extern void
+st_texture_release_sampler_view(struct st_context *st,
+                                struct st_texture_object *stObj);
+
 #endif