i965/i915: Add colorspace support to YUV sampling
[mesa.git] / src / mesa / drivers / dri / i965 / intel_tex_image.c
index 34491aa36efa51cc12f19dca9d776a721233a96d..c0a4a9c2ca9163364830fe1201266f37c393a35c 100644 (file)
@@ -208,7 +208,7 @@ intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
        !(texImage->TexObject->Target == GL_TEXTURE_2D ||
          texImage->TexObject->Target == GL_TEXTURE_RECTANGLE) ||
        pixels == NULL ||
-       _mesa_is_bufferobj(packing->BufferObj) ||
+       packing->BufferObj ||
        packing->Alignment > 4 ||
        packing->SkipPixels > 0 ||
        packing->SkipRows > 0 ||
@@ -322,12 +322,13 @@ intel_upload_tex(struct gl_context * ctx,
    bool ok;
 
    /* Check that there is actually data to store. */
-   if (pixels == NULL && !_mesa_is_bufferobj(packing->BufferObj))
+   if (pixels == NULL && !packing->BufferObj)
       return;
 
-   bool tex_busy = mt && brw_bo_busy(mt->bo);
+   bool tex_busy = mt &&
+      (brw_batch_references(&brw->batch, mt->bo) || brw_bo_busy(mt->bo));
 
-   if (_mesa_is_bufferobj(packing->BufferObj) || tex_busy ||
+   if (packing->BufferObj || tex_busy ||
        mt->aux_usage == ISL_AUX_USAGE_CCS_E) {
       ok = intel_texsubimage_blorp(brw, dims, texImage,
                                    xoffset, yoffset, zoffset,
@@ -633,6 +634,7 @@ intel_image_target_texture(struct gl_context *ctx, GLenum target,
 
    struct intel_texture_object *intel_texobj = intel_texture_object(texObj);
    intel_texobj->planar_format = image->planar_format;
+   intel_texobj->yuv_color_space = image->yuv_color_space;
 
    GLenum internal_format =
       image->internal_format != 0 ?
@@ -649,6 +651,17 @@ intel_image_target_texture(struct gl_context *ctx, GLenum target,
          internal_format = GL_RGB10_A2;
    }
 
+   /* Guess sized internal format for dma-bufs, as specified by
+    * EXT_EGL_image_storage.
+    */
+   if (storage && target == GL_TEXTURE_2D && image->imported_dmabuf) {
+      internal_format = driGLFormatToSizedInternalGLFormat(image->format);
+      if (internal_format == GL_NONE) {
+         _mesa_error(ctx, GL_INVALID_OPERATION, __func__);
+         return;
+      }
+   }
+
    intel_set_texture_image_mt(brw, texImage, internal_format, mt->format, mt);
    intel_miptree_release(&mt);
 }
@@ -663,6 +676,23 @@ intel_image_target_texture_2d(struct gl_context *ctx, GLenum target,
                               false);
 }
 
+static void
+intel_image_target_tex_storage(struct gl_context *ctx, GLenum target,
+                              struct gl_texture_object *texObj,
+                              struct gl_texture_image *texImage,
+                              GLeglImageOES image_handle)
+{
+   struct intel_texture_object *intel_texobj = intel_texture_object(texObj);
+   intel_image_target_texture(ctx, target, texObj, texImage, image_handle,
+                              true);
+
+   /* The miptree is in a validated state, so no need to check later. */
+   intel_texobj->needs_validate = false;
+   intel_texobj->validated_first_level = 0;
+   intel_texobj->validated_last_level = 0;
+   intel_texobj->_Format = texImage->TexFormat;
+}
+
 static bool
 intel_gettexsubimage_blorp(struct brw_context *brw,
                            struct gl_texture_image *tex_image,
@@ -727,7 +757,7 @@ intel_gettexsubimage_tiled_memcpy(struct gl_context *ctx,
        !(texImage->TexObject->Target == GL_TEXTURE_2D ||
          texImage->TexObject->Target == GL_TEXTURE_RECTANGLE) ||
        pixels == NULL ||
-       _mesa_is_bufferobj(packing->BufferObj) ||
+       packing->BufferObj ||
        packing->Alignment > 4 ||
        packing->SkipPixels > 0 ||
        packing->SkipRows > 0 ||
@@ -838,7 +868,7 @@ intel_get_tex_sub_image(struct gl_context *ctx,
 
    DBG("%s\n", __func__);
 
-   if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+   if (ctx->Pack.BufferObj) {
       if (intel_gettexsubimage_blorp(brw, texImage,
                                      xoffset, yoffset, zoffset,
                                      width, height, depth, format, type,
@@ -955,6 +985,7 @@ intelInitTextureImageFuncs(struct dd_function_table *functions)
    functions->TexSubImage = intelTexSubImage;
    functions->CompressedTexSubImage = intelCompressedTexSubImage;
    functions->EGLImageTargetTexture2D = intel_image_target_texture_2d;
+   functions->EGLImageTargetTexStorage = intel_image_target_tex_storage;
    functions->BindRenderbufferTexImage = intel_bind_renderbuffer_tex_image;
    functions->GetTexSubImage = intel_get_tex_sub_image;
 }