mesa/st: add PIPE_CAP_GL_CLAMP

when this is not set, this triggers shader and sampler state updates any time a sampler
starts or stops using GL_CLAMP, applying bitmasks needed to run nir_lower_tex
and setting CLAMP_TO_BORDER/CLAMP_TO_EDGE as necessary to mimic the behavior

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8756>
This commit is contained in:
Mike Blumenkrantz
2021-01-25 17:37:29 -05:00
committed by Marge Bot
parent 10e71d5c9a
commit e8f71f6ac4
13 changed files with 128 additions and 1 deletions

View File

@@ -98,6 +98,17 @@ gl_filter_to_img_filter(GLenum filter)
return PIPE_TEX_FILTER_NEAREST;
}
static inline unsigned
get_border_clamp(unsigned wrap, bool clamp_to_border)
{
if (wrap == PIPE_TEX_WRAP_CLAMP)
wrap = clamp_to_border ? PIPE_TEX_WRAP_CLAMP_TO_BORDER :
PIPE_TEX_WRAP_CLAMP_TO_EDGE;
else if (wrap == PIPE_TEX_WRAP_MIRROR_CLAMP)
wrap = clamp_to_border ? PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER :
PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
return wrap;
}
/**
* Convert a gl_sampler_object to a pipe_sampler_state object.
@@ -123,6 +134,14 @@ st_convert_sampler(const struct st_context *st,
}
sampler->min_mip_filter = gl_filter_to_mip_filter(msamp->Attrib.MinFilter);
if (st->emulate_gl_clamp) {
bool clamp_to_border = sampler->min_img_filter != PIPE_TEX_FILTER_NEAREST &&
sampler->mag_img_filter != PIPE_TEX_FILTER_NEAREST;
sampler->wrap_s = get_border_clamp(sampler->wrap_s, clamp_to_border);
sampler->wrap_t = get_border_clamp(sampler->wrap_t, clamp_to_border);
sampler->wrap_r = get_border_clamp(sampler->wrap_r, clamp_to_border);
}
if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
sampler->normalized_coords = 1;