Mesa (main): st/mesa: Transcode ASTC to BC7 (BPTC) where possible
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Apr 13 08:47:10 UTC 2022
Module: Mesa
Branch: main
Commit: 68ef895674b176b4faf875a4d7f4d787b330d4d9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=68ef895674b176b4faf875a4d7f4d787b330d4d9
Author: Kenneth Graunke <kenneth at whitecape.org>
Date: Tue Feb 15 12:47:49 2022 -0800
st/mesa: Transcode ASTC to BC7 (BPTC) where possible
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 at intel.com>
Reviewed-by: Emma Anholt <emma at anholt.net>
Reviewed-by: Nanley Chery <nanley.g.chery at intel.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15875>
---
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, 28 insertions(+), 12 deletions(-)
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 1e79efde7b7..88286f44634 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 5f422769615..4c8c838ad10 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -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;
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index a2b6625fbba..794ae63841d 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -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;
}
}
More information about the mesa-commit
mailing list