+ /* Note that the error semantics for multi-bind commands differ from
+ * those of other GL commands.
+ *
+ * The Issues section in the ARB_multi_bind spec says:
+ *
+ * "(11) Typically, OpenGL specifies that if an error is generated by
+ * a command, that command has no effect. This is somewhat
+ * unfortunate for multi-bind commands, because it would require
+ * a first pass to scan the entire list of bound objects for
+ * errors and then a second pass to actually perform the
+ * bindings. Should we have different error semantics?
+ *
+ * RESOLVED: Yes. In this specification, when the parameters for
+ * one of the <count> binding points are invalid, that binding
+ * point is not updated and an error will be generated. However,
+ * other binding points in the same command will be updated if
+ * their parameters are valid and no other error occurs."
+ */
+
+ _mesa_HashLockMutex(ctx->Shared->TexObjects);
+
+ for (i = 0; i < count; i++) {
+ struct gl_image_unit *u = &ctx->ImageUnits[first + i];
+ const GLuint texture = textures ? textures[i] : 0;
+
+ if (texture) {
+ struct gl_texture_object *texObj = u->TexObj;
+ GLenum tex_format;
+
+ if (!texObj || texObj->Name != texture) {
+ texObj = _mesa_lookup_texture_locked(ctx, texture);
+ if (!no_error && !texObj) {
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_OPERATION error is generated if any value
+ * in <textures> is not zero or the name of an existing
+ * texture object (per binding)."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindImageTextures(textures[%d]=%u "
+ "is not zero or the name of an existing texture "
+ "object)", i, texture);
+ continue;
+ }
+ }
+
+ if (texObj->Target == GL_TEXTURE_BUFFER) {
+ tex_format = texObj->BufferObjectFormat;
+ } else {
+ struct gl_texture_image *image = texObj->Image[0][0];
+
+ if (!no_error && (!image || image->Width == 0 ||
+ image->Height == 0 || image->Depth == 0)) {
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_OPERATION error is generated if the width,
+ * height, or depth of the level zero texture image of
+ * any texture in <textures> is zero (per binding)."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindImageTextures(the width, height or depth "
+ "of the level zero texture image of "
+ "textures[%d]=%u is zero)", i, texture);
+ continue;
+ }
+
+ tex_format = image->InternalFormat;
+ }
+
+ if (!no_error &&
+ !_mesa_is_shader_image_format_supported(ctx, tex_format)) {
+ /* The ARB_multi_bind spec says:
+ *
+ * "An INVALID_OPERATION error is generated if the internal
+ * format of the level zero texture image of any texture
+ * in <textures> is not found in table 8.33 (per binding)."
+ */
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "glBindImageTextures(the internal format %s of "
+ "the level zero texture image of textures[%d]=%u "
+ "is not supported)",
+ _mesa_enum_to_string(tex_format),
+ i, texture);
+ continue;
+ }
+
+ /* Update the texture binding */
+ set_image_binding(u, texObj, 0,
+ _mesa_tex_target_is_layered(texObj->Target),
+ 0, GL_READ_WRITE, tex_format);