+static void
+intel_set_texture_image_mt(struct brw_context *brw,
+ struct gl_texture_image *image,
+ GLenum internal_format,
+ struct intel_mipmap_tree *mt)
+
+{
+ struct gl_texture_object *texobj = image->TexObject;
+ struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
+ struct intel_texture_image *intel_image = intel_texture_image(image);
+
+ _mesa_init_teximage_fields(&brw->ctx, image,
+ mt->logical_width0, mt->logical_height0, 1,
+ 0, internal_format, mt->format);
+
+ brw->ctx.Driver.FreeTextureImageBuffer(&brw->ctx, image);
+
+ intel_texobj->needs_validate = true;
+ intel_image->base.RowStride = mt->pitch / mt->cpp;
+ assert(mt->pitch % mt->cpp == 0);
+
+ intel_miptree_reference(&intel_image->mt, mt);
+
+ /* Immediately validate the image to the object. */
+ intel_miptree_reference(&intel_texobj->mt, mt);
+}
+
+static struct intel_mipmap_tree *
+create_mt_for_planar_dri_image(struct brw_context *brw,
+ GLenum target, __DRIimage *image)
+{
+ struct intel_image_format *f = image->planar_format;
+ struct intel_mipmap_tree *planar_mt;
+
+ for (int i = 0; i < f->nplanes; i++) {
+ const int index = f->planes[i].buffer_index;
+ const uint32_t dri_format = f->planes[i].dri_format;
+ const mesa_format format = driImageFormatToGLFormat(dri_format);
+ const uint32_t width = image->width >> f->planes[i].width_shift;
+ const uint32_t height = image->height >> f->planes[i].height_shift;
+
+ /* Disable creation of the texture's aux buffers because the driver
+ * exposes no EGL API to manage them. That is, there is no API for
+ * resolving the aux buffer's content to the main buffer nor for
+ * invalidating the aux buffer's content.
+ */
+ struct intel_mipmap_tree *mt =
+ intel_miptree_create_for_bo(brw, image->bo, format,
+ image->offsets[index],
+ width, height, 1,
+ image->strides[index],
+ MIPTREE_LAYOUT_DISABLE_AUX);
+ if (mt == NULL)
+ return NULL;
+
+ mt->target = target;
+ mt->total_width = width;
+ mt->total_height = height;
+
+ if (i == 0)
+ planar_mt = mt;
+ else
+ planar_mt->plane[i - 1] = mt;
+ }
+
+ return planar_mt;
+}
+