mesa: Reset image unit state to the default values when a bound image is deleted.
authorFrancisco Jerez <currojerez@riseup.net>
Sun, 16 Aug 2015 23:00:48 +0000 (02:00 +0300)
committerFrancisco Jerez <currojerez@riseup.net>
Thu, 20 Aug 2015 09:26:53 +0000 (12:26 +0300)
The ES31-CTS.shader_image_load_store.basic-api-bind conformance test
expects the whole image unit state to be reset when the bound texture
object is deleted.  The ARB_shader_image_load_store extension is
rather vague regarding what should happen with image unit state other
than the texture object in that case, but the GL 4.2 and GLES 3.1
specifications (section "Automatic Unbinding of Deleted Objects")
explicitly require it to be reset to the default values.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/main/shaderimage.c
src/mesa/main/shaderimage.h
src/mesa/main/texobj.c

index 2d8693150b1488c6dc70f89f695660aece6db393..48e3e09dd5d4cacb57542288a6414ed4e4db2ea0 100644 (file)
@@ -394,17 +394,24 @@ is_image_format_supported(const struct gl_context *ctx, GLenum format)
    }
 }
 
+struct gl_image_unit
+_mesa_default_image_unit(struct gl_context *ctx)
+{
+   const struct gl_image_unit u = {
+      .Access = GL_READ_ONLY,
+      .Format = GL_R8,
+      ._ActualFormat = _mesa_get_shader_image_format(GL_R8)
+   };
+   return u;
+}
+
 void
 _mesa_init_image_units(struct gl_context *ctx)
 {
    unsigned i;
 
-   for (i = 0; i < ARRAY_SIZE(ctx->ImageUnits); ++i) {
-      struct gl_image_unit *u = &ctx->ImageUnits[i];
-      u->Access = GL_READ_ONLY;
-      u->Format = GL_R8;
-      u->_ActualFormat = _mesa_get_shader_image_format(u->Format);
-   }
+   for (i = 0; i < ARRAY_SIZE(ctx->ImageUnits); ++i)
+      ctx->ImageUnits[i] = _mesa_default_image_unit(ctx);
 }
 
 static GLboolean
index d08ece81f11d735f4d65cf2669e1117589daa470..bbe088a24592b3d5c0b8a76c38d842bbbda2c5c0 100644 (file)
@@ -42,6 +42,12 @@ struct gl_context;
 mesa_format
 _mesa_get_shader_image_format(GLenum format);
 
+/**
+ * Get a single image unit struct with the default state.
+ */
+struct gl_image_unit
+_mesa_default_image_unit(struct gl_context *ctx);
+
 /**
  * Initialize a context's shader image units to the default state.
  */
index cd7cfd6a4fb9406d47406f16f1fcd91ad0ec700b..395e4d3359f7303eae2385cf40184c0a4b87079a 100644 (file)
@@ -37,6 +37,7 @@
 #include "hash.h"
 #include "imports.h"
 #include "macros.h"
+#include "shaderimage.h"
 #include "teximage.h"
 #include "texobj.h"
 #include "texstate.h"
@@ -1411,8 +1412,10 @@ unbind_texobj_from_image_units(struct gl_context *ctx,
    for (i = 0; i < ctx->Const.MaxImageUnits; i++) {
       struct gl_image_unit *unit = &ctx->ImageUnits[i];
 
-      if (texObj == unit->TexObj)
+      if (texObj == unit->TexObj) {
          _mesa_reference_texobj(&unit->TexObj, NULL);
+         *unit = _mesa_default_image_unit(ctx);
+      }
    }
 }