gallium: Add a transcode_astc driconf option

This is similar to the transcode_etc flag in that it changes the ASTC
fallback (when present) to use DXT5 instead of RGBA8888.  This reduces
the memory footprint of the app at the expense of a bit of correctness.
Because it's not quite correct, it's hidden behind a driconf option.

Reviewed-by: Eric Anholt <eric@anholt.net>
Acked-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Marek Olšák <maraeo@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10476>
This commit is contained in:
Jason Ekstrand 2021-04-26 18:01:16 -05:00
parent 7ae0719117
commit 91cbe8d855
8 changed files with 37 additions and 5 deletions

View File

@ -34,6 +34,7 @@ DRI_CONF_SECTION_DEBUG
DRI_CONF_FORCE_COMPAT_PROFILE(false)
DRI_CONF_FORCE_GL_NAMES_REUSE(false)
DRI_CONF_TRANSCODE_ETC(false)
DRI_CONF_TRANSCODE_ASTC(false)
DRI_CONF_FORCE_GL_VENDOR()
DRI_CONF_OVERRIDE_VRAM_SIZE()
DRI_CONF_GLX_EXTENSION_OVERRIDE()

View File

@ -105,6 +105,8 @@ dri_fill_st_options(struct dri_screen *screen)
driQueryOptionb(optionCache, "force_gl_names_reuse");
options->transcode_etc =
driQueryOptionb(optionCache, "transcode_etc");
options->transcode_astc =
driQueryOptionb(optionCache, "transcode_astc");
char *vendor_str = driQueryOptionstr(optionCache, "force_gl_vendor");
/* not an empty string */

View File

@ -242,6 +242,7 @@ struct st_config_options
bool force_integer_tex_nearest;
bool force_gl_names_reuse;
bool transcode_etc;
bool transcode_astc;
char *force_gl_vendor;
unsigned char config_options_sha1[20];
};

View File

@ -407,8 +407,14 @@ st_UnmapTextureImage(struct gl_context *ctx,
transfer->box.height,
texImage->TexFormat,
bgra);
} else if (_mesa_is_format_astc_2d(texImage->TexFormat)) {
_mesa_unpack_astc_2d_ldr(tmp, transfer->box.width * 4,
itransfer->temp_data,
itransfer->temp_stride,
transfer->box.width,
transfer->box.height,
texImage->TexFormat);
} else {
/* TODO: We could transcode ASTC too. */
unreachable("unexpected format for a compressed format fallback");
}

View File

@ -681,6 +681,10 @@ 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);
st->has_astc_2d_ldr =
screen->is_format_supported(screen, PIPE_FORMAT_ASTC_4x4_SRGB,
PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW);

View File

@ -143,6 +143,7 @@ struct st_context
boolean has_etc1;
boolean has_etc2;
boolean transcode_etc;
boolean transcode_astc;
boolean has_astc_2d_ldr;
boolean has_astc_5x5_ldr;
boolean prefer_blit_based_texture_transfer;

View File

@ -110,10 +110,24 @@ 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 PIPE_FORMAT_R8G8B8A8_SRGB;
else
return PIPE_FORMAT_R8G8B8A8_UNORM;
const struct util_format_description *desc =
util_format_description(mesaFormat);
if (_mesa_is_format_srgb(mesaFormat)) {
if (!st->transcode_astc)
return PIPE_FORMAT_R8G8B8A8_SRGB;
else if (desc->block.width * desc->block.height < 32)
return PIPE_FORMAT_DXT5_SRGBA;
else
return PIPE_FORMAT_DXT1_SRGBA;
} else {
if (!st->transcode_astc)
return PIPE_FORMAT_R8G8B8A8_UNORM;
else if (desc->block.width * desc->block.height < 32)
return PIPE_FORMAT_DXT5_RGBA;
else
return PIPE_FORMAT_DXT1_RGBA;
}
}
return mesaFormat;

View File

@ -233,6 +233,9 @@
#define DRI_CONF_TRANSCODE_ETC(def) \
DRI_CONF_OPT_B(transcode_etc, def, "Transcode ETC formats to DXTC if unsupported")
#define DRI_CONF_TRANSCODE_ASTC(def) \
DRI_CONF_OPT_B(transcode_astc, def, "Transcode ASTC formats to DXTC if unsupported")
#define DRI_CONF_GLX_EXTENSION_OVERRIDE() \
DRI_CONF_OPT_S_NODEF(glx_extension_override, \
"Allow enabling/disabling a list of GLX extensions")