st/mesa: Transcode ASTC to BC7 (BPTC) where possible
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 15 Feb 2022 20:47:49 +0000 (12:47 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 13 Apr 2022 07:58:11 +0000 (07:58 +0000)
This patch adds support for transcoding ASTC to BC7 (BPTC) and prefers
it over BC3 (DXT5) when hardware supports that format.

BC7 is a much newer format (~2009 vs. ~1999) and offers higher quality
than the older BC3 format.  Furthermore, our encoder seems to be faster.

Tapani put together a small benchmark for transcoding a 1024x1024 ASTC
texture, and switching from BC3 to BC7 improves performance of that
microbenchmark by 25% on my Tigerlake NUC (with hardware ASTC disabled
so we can test this path).  Presumably, this isn't fundamental to the
formats, but rather reflects the speed of our in-tree compressors.

So, we should use BC7 where possible.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15875>

src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_format.c

index 1e79efd..88286f4 100644 (file)
@@ -570,13 +570,20 @@ 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 = 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_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->has_astc_2d_ldr =
       screen->is_format_supported(screen, PIPE_FORMAT_ASTC_4x4_SRGB,
                                   PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW);
index 5f42276..4c8c838 100644 (file)
@@ -140,7 +140,8 @@ struct st_context
    boolean has_etc1;
    boolean has_etc2;
    boolean transcode_etc;
-   boolean transcode_astc;
+   boolean transcode_astc_to_bptc;
+   boolean transcode_astc_to_dxt5;
    boolean has_astc_2d_ldr;
    boolean has_astc_5x5_ldr;
    boolean prefer_blit_based_texture_transfer;
index a2b6625..794ae63 100644 (file)
@@ -111,11 +111,19 @@ st_mesa_format_to_pipe_format(const struct st_context *st,
 
    if (st_astc_format_fallback(st, mesaFormat)) {
       if (_mesa_is_format_srgb(mesaFormat)) {
-         return st->transcode_astc ? PIPE_FORMAT_DXT5_SRGBA :
-                                     PIPE_FORMAT_R8G8B8A8_SRGB;
+         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;
       } else {
-         return st->transcode_astc ? PIPE_FORMAT_DXT5_RGBA :
-                                     PIPE_FORMAT_R8G8B8A8_UNORM;
+         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;
       }
    }