From 8abb5c8b41bbdeb86b025fdc43600eb41f9302c5 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 29 Aug 2022 10:38:59 +0200 Subject: [PATCH] mesa/st: force nearest-filtering for fp32 textures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenGL 3.0 requires ARB_texture_float, which technically speaking requires linear-filtering support for FP32 textures. However, because a lot of early implementations just ignore this and does nearest filtering instead due to lack of hardware features for this, this functionality was never added to the OpenGL CTS. The result is that FP32 is a feature that is required on paper, but is unreliable to be used by applications in practice. This is mostly fine; for most filterable use-cases (e.g colors), FP16 is fine and saves a bunch of bandwidth, and for cases where you really need the extra bits (depth-reads etc), filtering is usually not what's wanted. To save drivers that doesn't support filtering of FP32 filtering from having to manually whack the state, and get needless CSOs in the CSO caches, let's force this in early, where we already do the same for integer textures. Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/consts_exts.h | 6 ++++++ src/mesa/state_tracker/st_atom_sampler.c | 3 ++- src/mesa/state_tracker/st_context.c | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index 1ed1f0edd65..17f3586ffd8 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -685,6 +685,12 @@ struct gl_constants */ GLboolean ForceIntegerTexNearest; + /** + * Treat 32-bit floating-point textures using GL_LINEAR filters as + * GL_NEAREST. + */ + GLboolean ForceFloat32TexNearest; + /** * Does the driver support real 32-bit integers? (Otherwise, integers are * simulated via floats.) diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index c2724abf332..239847985bc 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -70,7 +70,8 @@ st_convert_sampler(const struct st_context *st, sampler->seamless_cube_map |= seamless_cube_map; - if (texobj->_IsIntegerFormat) { + if (texobj->_IsIntegerFormat || + (texobj->_IsFloat && st->ctx->Const.ForceFloat32TexNearest)) { sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler->min_mip_filter = PIPE_TEX_FILTER_NEAREST; sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index ab7350e4248..bb5addff18c 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -699,6 +699,9 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, ctx->Const.NoClippingOnCopyTex = screen->get_param(screen, PIPE_CAP_NO_CLIP_ON_COPY_TEX); + ctx->Const.ForceFloat32TexNearest = + !screen->get_param(screen, PIPE_CAP_TEXTURE_FLOAT_LINEAR); + ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].PositionAlwaysInvariant = options->vs_position_always_invariant; ctx->Const.ShaderCompilerOptions[MESA_SHADER_TESS_EVAL].PositionAlwaysPrecise = options->vs_position_always_precise;