From 8e6308363bf0e52c10f4c3951c2c4d25341d0133 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 22 Nov 2019 21:33:19 -0800 Subject: [PATCH] st/mesa: Allow ASTC5x5 fallbacks separately from other ASTC LDR formats. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch allows us to fake ASTC 5x5 specifically, while leaving the other ASTC LDR formats with native support. I plan to use this in iris, at least for the time being. Reviewed-by: Tapani Pälli Reviewed-by: Marek Olšák --- src/mesa/state_tracker/st_cb_texture.c | 16 ++++++++++++++-- src/mesa/state_tracker/st_context.c | 3 +++ src/mesa/state_tracker/st_context.h | 1 + src/mesa/state_tracker/st_format.c | 2 +- src/mesa/state_tracker/st_texture.h | 3 +++ src/mesa/state_tracker/tests/st_format.c | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index df5f16efd62..21f67659c0d 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -226,6 +226,18 @@ st_FreeTextureImageBuffer(struct gl_context *ctx, st_texture_release_all_sampler_views(st, stObj); } +bool +st_astc_format_fallback(const struct st_context *st, mesa_format format) +{ + if (!_mesa_is_format_astc_2d(format)) + return false; + + if (format == MESA_FORMAT_RGBA_ASTC_5x5 || + format == MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5) + return !st->has_astc_5x5_ldr; + + return !st->has_astc_2d_ldr; +} bool st_compressed_format_fallback(struct st_context *st, mesa_format format) @@ -236,8 +248,8 @@ st_compressed_format_fallback(struct st_context *st, mesa_format format) if (_mesa_is_format_etc2(format)) return !st->has_etc2; - if (_mesa_is_format_astc_2d(format)) - return !st->has_astc_2d_ldr; + if (st_astc_format_fallback(st, format)) + return true; return false; } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index c45c7f7e5fb..992f9fe00c9 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -652,6 +652,9 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->has_astc_2d_ldr = screen->is_format_supported(screen, PIPE_FORMAT_ASTC_4x4_SRGB, PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW); + st->has_astc_5x5_ldr = + screen->is_format_supported(screen, PIPE_FORMAT_ASTC_5x5_SRGB, + PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW); st->prefer_blit_based_texture_transfer = screen->get_param(screen, PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); st->force_persample_in_shader = diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 054a9e9317e..9a6a1f80d33 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -137,6 +137,7 @@ struct st_context boolean has_etc1; boolean has_etc2; boolean has_astc_2d_ldr; + boolean has_astc_5x5_ldr; boolean prefer_blit_based_texture_transfer; boolean force_persample_in_shader; boolean has_shareable_shaders; diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 4bbb781932d..fb071beb64b 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -106,7 +106,7 @@ st_mesa_format_to_pipe_format(const struct st_context *st, } } - if (_mesa_is_format_astc_2d(mesaFormat) && !st->has_astc_2d_ldr) { + if (st_astc_format_fallback(st, mesaFormat)) { if (_mesa_is_format_srgb(mesaFormat)) return PIPE_FORMAT_R8G8B8A8_SRGB; else diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 1fc36631c2e..7948daa6542 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -322,6 +322,9 @@ st_destroy_bound_texture_handles(struct st_context *st); void st_destroy_bound_image_handles(struct st_context *st); +bool +st_astc_format_fallback(const struct st_context *st, mesa_format format); + bool st_compressed_format_fallback(struct st_context *st, mesa_format format); diff --git a/src/mesa/state_tracker/tests/st_format.c b/src/mesa/state_tracker/tests/st_format.c index 0def5ff3359..64e6bb1b33c 100644 --- a/src/mesa/state_tracker/tests/st_format.c +++ b/src/mesa/state_tracker/tests/st_format.c @@ -59,6 +59,7 @@ int main(int argc, char **argv) .has_etc1 = true, .has_etc2 = true, .has_astc_2d_ldr = true, + .has_astc_5x5_ldr = true, }; struct st_context *st = &local_st; -- 2.30.2