Mesa (main): Revert "st/mesa: Transcode ASTC to BC7 (BPTC) where possible"

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 18 10:07:37 UTC 2022


Module: Mesa
Branch: main
Commit: c54555c496aea12d280ac6e882e81d3d69673e98
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c54555c496aea12d280ac6e882e81d3d69673e98

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue May 17 13:51:49 2022 -0700

Revert "st/mesa: Transcode ASTC to BC7 (BPTC) where possible"

This reverts commit 68ef895674b176b4faf875a4d7f4d787b330d4d9.

When trying out transcode_astc=true with BPTC on Asphalt 9, we observed
very poor image quality - to the point that basic UI icons were blocky,
and buttons with a black border had smeared pixels on the edges.  Using
DXT5 had no such issues.

I originally suspected there was a bug in the BPTC encoder, but I now
believe the issue is deeper than that.  The commit that introduced the
encoder, 17cde55c538009764207bd29b78a909d2c5d14b4, says:

   "The compressor is written from scratch and takes a very simple
    approach.  It always uses a single mode of the BPTC format (4 for
    unorm and 3 for half-floats) and picks the two endpoints by dividing
    the texels into those which have more or less than the average
    luminance of the block and then calculating an average color of the
    texels within each division.

    It's probably not really sensible to try to use BPTC compression at
    runtime because for example with the Nvidia offline compression tool
    it can take in the order of an hour to compress a full-screen image.
    With that in mind I don't think it's worth having a proper compressor
    in Mesa and this approach gives reasonable results for a usage that
    is basically a corner case."

In other words, the reason our BPTC compressor was so fast is that it
only implements one of the modes and does a low quality approximation.
This honestly should probably be improved somewhat, but the original
use case was for online-compression, the uncommon but mandatory OpenGL
feature where you can supply uncompressed data and trust the driver to
compress it for you (at unknown and uncontrolled quality and speed).

Unfortunately, the compressor as it stands is simply not usable for
transcoding ASTC data where we want to preserve the underlying image
quality as much as possible.

Reviewed-by: Emma Anholt <emma at anholt.net>
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16566>

---

 src/mesa/state_tracker/st_context.c | 21 +++++++--------------
 src/mesa/state_tracker/st_context.h |  3 +--
 src/mesa/state_tracker/st_format.c  | 16 ++++------------
 3 files changed, 12 insertions(+), 28 deletions(-)

diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index f306eea9237..efb459a01f9 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -568,20 +568,13 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
                        screen->is_format_supported(screen, PIPE_FORMAT_DXT1_SRGBA,
                                                    PIPE_TEXTURE_2D, 0, 0,
                                                    PIPE_BIND_SAMPLER_VIEW);
-   st->transcode_astc_to_bptc = options->transcode_astc &&
-      screen->is_format_supported(screen, PIPE_FORMAT_BPTC_SRGBA,
-                                  PIPE_TEXTURE_2D, 0, 0,
-                                  PIPE_BIND_SAMPLER_VIEW) &&
-      screen->is_format_supported(screen, PIPE_FORMAT_BPTC_RGBA_UNORM,
-                                  PIPE_TEXTURE_2D, 0, 0,
-                                  PIPE_BIND_SAMPLER_VIEW);
-   st->transcode_astc_to_dxt5 = options->transcode_astc &&
-      screen->is_format_supported(screen, PIPE_FORMAT_DXT5_SRGBA,
-                                  PIPE_TEXTURE_2D, 0, 0,
-                                  PIPE_BIND_SAMPLER_VIEW) &&
-      screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
-                                  PIPE_TEXTURE_2D, 0, 0,
-                                  PIPE_BIND_SAMPLER_VIEW);
+   st->transcode_astc = options->transcode_astc &&
+                        screen->is_format_supported(screen, PIPE_FORMAT_DXT5_SRGBA,
+                                                    PIPE_TEXTURE_2D, 0, 0,
+                                                    PIPE_BIND_SAMPLER_VIEW) &&
+                        screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
+                                                    PIPE_TEXTURE_2D, 0, 0,
+                                                    PIPE_BIND_SAMPLER_VIEW);
    st->has_astc_2d_ldr =
       screen->is_format_supported(screen, PIPE_FORMAT_ASTC_4x4_SRGB,
                                   PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 1498884b31e..d3eb1075617 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -140,8 +140,7 @@ struct st_context
    boolean has_etc1;
    boolean has_etc2;
    boolean transcode_etc;
-   boolean transcode_astc_to_bptc;
-   boolean transcode_astc_to_dxt5;
+   boolean transcode_astc;
    boolean has_astc_2d_ldr;
    boolean has_astc_5x5_ldr;
    boolean prefer_blit_based_texture_transfer;
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index fadd03073aa..252e0810d0c 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -111,19 +111,11 @@ st_mesa_format_to_pipe_format(const struct st_context *st,
 
    if (st_astc_format_fallback(st, mesaFormat)) {
       if (_mesa_is_format_srgb(mesaFormat)) {
-         if (st->transcode_astc_to_bptc)
-            return PIPE_FORMAT_BPTC_SRGBA;
-         else if (st->transcode_astc_to_dxt5)
-            return PIPE_FORMAT_DXT5_SRGBA;
-         else
-            return PIPE_FORMAT_R8G8B8A8_SRGB;
+         return st->transcode_astc ? PIPE_FORMAT_DXT5_SRGBA :
+                                     PIPE_FORMAT_R8G8B8A8_SRGB;
       } else {
-         if (st->transcode_astc_to_bptc)
-            return PIPE_FORMAT_BPTC_RGBA_UNORM;
-         else if (st->transcode_astc_to_dxt5)
-            return PIPE_FORMAT_DXT5_RGBA;
-         else
-            return PIPE_FORMAT_R8G8B8A8_UNORM;
+         return st->transcode_astc ? PIPE_FORMAT_DXT5_RGBA :
+                                     PIPE_FORMAT_R8G8B8A8_UNORM;
       }
    }
 



More information about the mesa-commit mailing list