mesa: release references to image textures when a context is destroyed
authorGert Wollny <gert.wollny@collabora.com>
Sat, 2 Feb 2019 12:17:16 +0000 (13:17 +0100)
committerGert Wollny <gw.fossdev@gmail.com>
Tue, 5 Feb 2019 10:53:41 +0000 (10:53 +0000)
When a texture is still bound as an image and the context it was bound in
is destroyed but not the texture, then the texture will still hold the
resource and will not be freed when it is finally destroyed. Hence, release
these references when the context is destroyed.

This leak was triggered by virglrenderer:
https://gitlab.freedesktop.org/virgl/virglrenderer/issues/86

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/context.c
src/mesa/main/shaderimage.c
src/mesa/main/shaderimage.h

index 492f01d..e5a89d9 100644 (file)
 #include "util/disk_cache.h"
 #include "util/strtod.h"
 #include "stencil.h"
+#include "shaderimage.h"
 #include "texcompress_s3tc.h"
 #include "texstate.h"
 #include "transformfeedback.h"
@@ -1345,6 +1346,7 @@ _mesa_free_context_data( struct gl_context *ctx )
    _mesa_free_buffer_objects(ctx);
    _mesa_free_eval_data( ctx );
    _mesa_free_texture_data( ctx );
+   _mesa_free_image_textures(ctx);
    _mesa_free_matrix_data( ctx );
    _mesa_free_pipeline_data(ctx);
    _mesa_free_program_data(ctx);
index 31ac852..242a8c2 100644 (file)
@@ -469,6 +469,16 @@ _mesa_init_image_units(struct gl_context *ctx)
       ctx->ImageUnits[i] = _mesa_default_image_unit(ctx);
 }
 
+
+void
+_mesa_free_image_textures(struct gl_context *ctx)
+{
+   unsigned i;
+
+   for (i = 0; i < ARRAY_SIZE(ctx->ImageUnits); ++i)
+      _mesa_reference_texobj(&ctx->ImageUnits[i].TexObj, NULL);
+}
+
 GLboolean
 _mesa_is_image_unit_valid(struct gl_context *ctx, struct gl_image_unit *u)
 {
index 6a9e3d6..daed275 100644 (file)
@@ -68,6 +68,9 @@ _mesa_default_image_unit(struct gl_context *ctx);
 void
 _mesa_init_image_units(struct gl_context *ctx);
 
+void
+_mesa_free_image_textures(struct gl_context *ctx);
+
 /**
  * Return GL_TRUE if the state of the image unit passed as argument is valid
  * and access from the shader is allowed.  Otherwise loads from this unit