[Mesa-dev] [PATCH 2/3] st/mesa: fix sampler view handling with shared textures

Christian König deathsimple at vodafone.de
Sun Mar 23 09:12:39 PDT 2014


From: Christian König <christian.koenig at amd.com>

Release the references to the sampler views before destroying the pipe context.

TODO: Do we need to lock something?

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/gallium/drivers/radeonsi/si_descriptors.c |  2 ++
 src/mesa/state_tracker/st_atom.h              |  2 ++
 src/mesa/state_tracker/st_atom_texture.c      |  8 ++++++++
 src/mesa/state_tracker/st_context.c           | 10 ++++++++++
 4 files changed, 22 insertions(+)

diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c
index 0c58d5f..c2a8363 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -341,6 +341,8 @@ void si_set_sampler_view(struct si_context *sctx, unsigned shader,
 {
 	struct si_sampler_views *views = &sctx->samplers[shader].views;
 
+	assert(!view || view->context == &sctx->b.b);
+
 	if (views->views[slot] == view)
 		return;
 
diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h
index 60d89d7..394c6ad 100644
--- a/src/mesa/state_tracker/st_atom.h
+++ b/src/mesa/state_tracker/st_atom.h
@@ -45,6 +45,8 @@ void st_destroy_atoms( struct st_context *st );
 
 void st_validate_state( struct st_context *st );
 
+void st_atom_texture_cleanup( struct st_context *st,
+                              struct gl_texture_object *texObj );
 
 extern const struct st_tracked_state st_update_array;
 extern const struct st_tracked_state st_update_framebuffer;
diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c
index dc7f635..2826d12 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -373,6 +373,14 @@ update_geometry_textures(struct st_context *st)
    }
 }
 
+void st_atom_texture_cleanup(struct st_context *st,
+                             struct gl_texture_object *texObj)
+{
+   struct st_texture_object *stObj = st_texture_object(texObj);
+
+   if (stObj->sampler_view && stObj->sampler_view->context == st->pipe)
+      pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+}
 
 const struct st_tracked_state st_update_fragment_texture = {
    "st_update_texture",					/* name */
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 0ffc762..816a095 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -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"
@@ -280,6 +281,13 @@ static void st_destroy_context_priv( struct st_context *st )
    free( st );
 }
 
+static void st_destroy_tex_sampler( 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_atom_texture_cleanup(st, texObj);
+}
  
 void st_destroy_context( struct st_context *st )
 {
@@ -288,6 +296,8 @@ void st_destroy_context( struct st_context *st )
    struct gl_context *ctx = st->ctx;
    GLuint i;
 
+   _mesa_HashWalk(ctx->Shared->TexObjects, st_destroy_tex_sampler, st);
+
    /* need to unbind and destroy CSO objects before anything else */
    cso_release_all(st->cso_context);
 
-- 
1.9.1



More information about the mesa-dev mailing list