st/mesa: use pipe_sampler_view_release for releasing sampler views
authorMarek Olšák <marek.olsak@amd.com>
Thu, 16 Oct 2014 21:19:59 +0000 (23:19 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 16 Oct 2014 21:31:20 +0000 (23:31 +0200)
This fixes a crash when exiting Firefox. I have really no idea how Firefox
does it. It seems to involve multiple contexts and multithreading.

v2: added an XXX comment

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81680

Acked by Christian König.
Cc: 10.2 10.3 <mesa-stable@lists.freedesktop.org>
Tested-by: Benjamin Bellec <b.bellec@gmail.com>
src/mesa/state_tracker/st_cb_eglimage.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_gen_mipmap.c
src/mesa/state_tracker/st_texture.c
src/mesa/state_tracker/st_texture.h
src/mesa/state_tracker/st_vdpau.c

index 34eb809591895ba7c1e65946d424777fbb11ef5e..8531afb29a741b3bfbe27aa446bbdbe842be75ce 100644 (file)
@@ -96,6 +96,7 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
                 struct gl_texture_image *texImage,
                 struct pipe_surface *ps)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj;
    struct st_texture_image *stImage;
    GLenum internalFormat;
@@ -124,7 +125,7 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
 
    /* FIXME create a non-default sampler view from the pipe_surface? */
    pipe_resource_reference(&stObj->pt, ps->texture);
-   st_texture_release_all_sampler_views(stObj);
+   st_texture_release_all_sampler_views(st, stObj);
    pipe_resource_reference(&stImage->pt, stObj->pt);
 
    stObj->width0 = ps->width;
index dfa188a3f5c2f4508daa9512e889559bbd653f89..a8dbb78884811abd71eeae9be22c5782b171839b 100644 (file)
@@ -152,10 +152,11 @@ static void
 st_DeleteTextureObject(struct gl_context *ctx,
                        struct gl_texture_object *texObj)
 {
+   struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj = st_texture_object(texObj);
 
    pipe_resource_reference(&stObj->pt, NULL);
-   st_texture_release_all_sampler_views(stObj);
+   st_texture_release_all_sampler_views(st, stObj);
    st_texture_free_sampler_views(stObj);
    _mesa_delete_texture_object(ctx, texObj);
 }
@@ -512,7 +513,7 @@ st_AllocTextureImageBuffer(struct gl_context *ctx,
    /* The parent texture object does not have space for this image */
 
    pipe_resource_reference(&stObj->pt, NULL);
-   st_texture_release_all_sampler_views(stObj);
+   st_texture_release_all_sampler_views(st, stObj);
 
    if (!guess_and_alloc_texture(st, stObj, stImage)) {
       /* Probably out of memory.
@@ -1571,13 +1572,13 @@ st_finalize_texture(struct gl_context *ctx,
 
       if (!st_obj) {
          pipe_resource_reference(&stObj->pt, NULL);
-         st_texture_release_all_sampler_views(stObj);
+         st_texture_release_all_sampler_views(st, stObj);
          return GL_TRUE;
       }
 
       if (st_obj->buffer != stObj->pt) {
          pipe_resource_reference(&stObj->pt, st_obj->buffer);
-         st_texture_release_all_sampler_views(stObj);
+         st_texture_release_all_sampler_views(st, stObj);
          stObj->width0 = stObj->pt->width0 / _mesa_get_format_bytes(tObj->_BufferObjectFormat);
          stObj->height0 = 1;
          stObj->depth0 = 1;
@@ -1598,7 +1599,7 @@ st_finalize_texture(struct gl_context *ctx,
        firstImage->pt != stObj->pt &&
        (!stObj->pt || firstImage->pt->last_level >= stObj->pt->last_level)) {
       pipe_resource_reference(&stObj->pt, firstImage->pt);
-      st_texture_release_all_sampler_views(stObj);
+      st_texture_release_all_sampler_views(st, stObj);
    }
 
    /* If this texture comes from a window system, there is nothing else to do. */
@@ -1646,7 +1647,7 @@ st_finalize_texture(struct gl_context *ctx,
           * gallium texture now.  We'll make a new one below.
           */
          pipe_resource_reference(&stObj->pt, NULL);
-         st_texture_release_all_sampler_views(stObj);
+         st_texture_release_all_sampler_views(st, stObj);
          st->dirty.st |= ST_NEW_FRAMEBUFFER;
       }
    }
index 18cf504a759fdfa000f92b24853f44e1782716e8..26e1c21f6c5a395294129d7bba8ed7b92c45ac10 100644 (file)
@@ -124,7 +124,7 @@ st_generate_mipmap(struct gl_context *ctx, GLenum target,
 
       /* release the old tex (will likely be freed too) */
       pipe_resource_reference(&oldTex, NULL);
-      st_texture_release_all_sampler_views(stObj);
+      st_texture_release_all_sampler_views(st, stObj);
    }
    else {
       /* Make sure that the base texture image data is present in the
index 5996b7d1b74a9128210d92e6f5b567c2033609cd..ada9841897f468f271f22b2d6ad075db295a2ba5 100644 (file)
@@ -519,12 +519,14 @@ st_texture_release_sampler_view(struct st_context *st,
 }
 
 void
-st_texture_release_all_sampler_views(struct st_texture_object *stObj)
+st_texture_release_all_sampler_views(struct st_context *st,
+                                     struct st_texture_object *stObj)
 {
    GLuint i;
 
+   /* XXX This should use sampler_views[i]->pipe, not st->pipe */
    for (i = 0; i < stObj->num_sampler_views; ++i)
-      pipe_sampler_view_reference(&stObj->sampler_views[i], NULL);
+      pipe_sampler_view_release(st->pipe, &stObj->sampler_views[i]);
 }
 
 
index ce1cf8b0a94b8d0c9f57a72d7bcb96afc1906d26..d66afcb560bc47b6abf0c81c57baea3707cb43d6 100644 (file)
@@ -255,7 +255,8 @@ st_texture_release_sampler_view(struct st_context *st,
                                 struct st_texture_object *stObj);
 
 extern void
-st_texture_release_all_sampler_views(struct st_texture_object *stObj);
+st_texture_release_all_sampler_views(struct st_context *st,
+                                     struct st_texture_object *stObj);
 
 void
 st_texture_free_sampler_views(struct st_texture_object *stObj);
index 8c10cdaf38b8d986d9c3cf0893d90bd9fb8a3700..6ccaf3e3f186127aa84c6502fc440bd541dabc15 100644 (file)
@@ -139,7 +139,7 @@ st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access,
                               texFormat);
 
    pipe_resource_reference(&stObj->pt, res);
-   st_texture_release_all_sampler_views(stObj);
+   st_texture_release_all_sampler_views(st, stObj);
    pipe_resource_reference(&stImage->pt, res);
 
    u_sampler_view_default_template(&templ, res, res->format);
@@ -172,7 +172,7 @@ st_vdpau_unmap_surface(struct gl_context *ctx, GLenum target, GLenum access,
    struct st_texture_image *stImage = st_texture_image(texImage);
 
    pipe_resource_reference(&stObj->pt, NULL);
-   st_texture_release_all_sampler_views(stObj);
+   st_texture_release_all_sampler_views(st, stObj);
    pipe_resource_reference(&stImage->pt, NULL);
 
    _mesa_dirty_texobj(ctx, texObj);