[Mesa-stable] [PATCH 2/6] i965/miptree: Loosen the format check in miptree_match_image

Jason Ekstrand jason at jlekstrand.net
Wed Nov 29 04:37:32 UTC 2017


This function is used to determine when we need to re-allocate a
miptree.  Since we do nothing different in miptree allocation for
sRGB vs. linear, loosening this should be safe and may lead to less
copying and reallocating in some odd cases.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Chad Versace <chadversary at chromium.org>
Cc: "17.3" <mesa-stable at lists.freedesktop.org>
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c  | 25 +++++++++++++++++++++++--
 src/mesa/drivers/dri/i965/intel_tex.c          |  2 +-
 src/mesa/drivers/dri/i965/intel_tex_obj.h      |  4 ++--
 src/mesa/drivers/dri/i965/intel_tex_validate.c |  2 +-
 4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 024ce3e..b5da58f 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -1298,7 +1298,8 @@ intel_miptree_match_image(struct intel_mipmap_tree *mt,
    if (mt->etc_format != MESA_FORMAT_NONE)
       mt_format = mt->etc_format;
 
-   if (image->TexFormat != mt_format)
+   if (_mesa_get_srgb_format_linear(image->TexFormat) !=
+       _mesa_get_srgb_format_linear(mt_format))
       return false;
 
    intel_get_image_dims(image, &width, &height, &depth);
@@ -1537,7 +1538,8 @@ intel_miptree_copy_slice(struct brw_context *brw,
    assert(src_layer < get_num_phys_layers(&src_mt->surf,
                                           src_level - src_mt->first_level));
 
-   assert(src_mt->format == dst_mt->format);
+   assert(_mesa_get_srgb_format_linear(src_mt->format) ==
+          _mesa_get_srgb_format_linear(dst_mt->format));
 
    if (dst_mt->compressed) {
       unsigned int i, j;
@@ -2588,6 +2590,25 @@ intel_miptree_texture_format(struct brw_context *brw,
    if (format == MESA_FORMAT_NONE)
       format = mt->format;
 
+   /* For depth and stencil formats, the view format may be a combined depth
+    * stencil format even though the miptree is depth-only.  We ignore the
+    * view format and just use the miptree format.  This is safe because
+    * texture views are not allowed on depth/stencil textures.
+    */
+   const GLenum base_format = _mesa_get_format_base_format(mt->format);
+   if (base_format == GL_DEPTH_COMPONENT ||
+       base_format == GL_DEPTH_STENCIL)
+      format = mt->format;
+
+   /* For ETC textures on gen7 and earlier, the view format will be ETC but
+    * we actually store a decompressed texture in the miptree.  We want the
+    * miptree format.
+    */
+   if (mt->etc_format != MESA_FORMAT_NONE) {
+      assert(view_format == mt->etc_format);
+      format = mt->format;
+   }
+
    return translate_tex_format(brw, format, srgb_decode);
 }
 
diff --git a/src/mesa/drivers/dri/i965/intel_tex.c b/src/mesa/drivers/dri/i965/intel_tex.c
index 65a1cb3..0650b6e 100644
--- a/src/mesa/drivers/dri/i965/intel_tex.c
+++ b/src/mesa/drivers/dri/i965/intel_tex.c
@@ -176,7 +176,7 @@ intel_alloc_texture_storage(struct gl_context *ctx,
    intel_texobj->needs_validate = false;
    intel_texobj->validated_first_level = 0;
    intel_texobj->validated_last_level = levels - 1;
-   intel_texobj->_Format = intel_texobj->mt->format;
+   intel_texobj->_Format = first_image->TexFormat;
 
    return true;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_tex_obj.h b/src/mesa/drivers/dri/i965/intel_tex_obj.h
index 27c18b7..526f5ce 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_obj.h
+++ b/src/mesa/drivers/dri/i965/intel_tex_obj.h
@@ -57,8 +57,8 @@ struct intel_texture_object
    bool needs_validate;
 
    /* Mesa format for the validated texture object. For non-views this
-    * will always be the same as mt->format. For views, it may differ
-    * since the mt is shared across views with differing formats.
+    * will always be the same as texObj->Image[0][0].TexFormat. For views, it
+    * may differ since the mt is shared across views with differing formats.
     */
    mesa_format _Format;
 
diff --git a/src/mesa/drivers/dri/i965/intel_tex_validate.c b/src/mesa/drivers/dri/i965/intel_tex_validate.c
index 2b7798c..ef7f907 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/i965/intel_tex_validate.c
@@ -174,7 +174,7 @@ intel_finalize_mipmap_tree(struct brw_context *brw, GLuint unit)
 
    intelObj->validated_first_level = validate_first_level;
    intelObj->validated_last_level = validate_last_level;
-   intelObj->_Format = intelObj->mt->format;
+   intelObj->_Format = firstImage->base.Base.TexFormat,
    intelObj->needs_validate = false;
 }
 
-- 
2.5.0.400.gff86faf



More information about the mesa-stable mailing list