gallium: add PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_ALPHA_NOT_W

mesa/gallium and util_format have different handling of alpha channels:
* mesa/gallium always uses w for the alpha swizzle
* util_format uses the actual component

for drivers which need to use the latter handling, this quirk will use the right
border color

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17687>
This commit is contained in:
Mike Blumenkrantz 2022-07-21 11:42:28 -04:00 committed by Marge Bot
parent 03b893acb3
commit 55ef65d4f4
4 changed files with 46 additions and 26 deletions

View file

@ -1029,6 +1029,7 @@ enum pipe_quirk_texture_border_color_swizzle {
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 = (1 << 0),
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600 = (1 << 1),
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO = (1 << 2),
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_ALPHA_NOT_W = (1 << 3),
};
enum pipe_endian

View file

@ -91,7 +91,6 @@ st_convert_sampler(const struct st_context *st,
PIPE_TEX_WRAP_MIRROR_REPEAT |
PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE) & 0x1) == 0);
/* For non-black borders... */
if (msamp->Attrib.IsBorderColorNonZero &&
/* This is true if wrap modes are using the border color: */
(sampler->wrap_s | sampler->wrap_t | sampler->wrap_r) & 0x1) {
@ -103,40 +102,56 @@ st_convert_sampler(const struct st_context *st,
if (texobj->StencilSampling)
texBaseFormat = GL_STENCIL_INDEX;
if (st->apply_texture_swizzle_to_border_color) {
const struct gl_texture_object *stobj = st_texture_object_const(texobj);
/* XXX: clean that up to not use the sampler view at all */
const struct st_sampler_view *sv = st_texture_get_current_sampler_view(st, stobj);
if (st->apply_texture_swizzle_to_border_color ||
st->alpha_border_color_is_not_w || st->use_format_with_border_color) {
if (st->apply_texture_swizzle_to_border_color) {
const struct gl_texture_object *stobj = st_texture_object_const(texobj);
/* XXX: clean that up to not use the sampler view at all */
const struct st_sampler_view *sv = st_texture_get_current_sampler_view(st, stobj);
if (sv) {
struct pipe_sampler_view *view = sv->view;
union pipe_color_union tmp = sampler->border_color;
const unsigned char swz[4] =
{
view->swizzle_r,
view->swizzle_g,
view->swizzle_b,
view->swizzle_a,
};
if (sv) {
struct pipe_sampler_view *view = sv->view;
union pipe_color_union tmp = sampler->border_color;
const unsigned char swz[4] =
{
view->swizzle_r,
view->swizzle_g,
view->swizzle_b,
view->swizzle_a,
};
st_translate_color(&tmp, texBaseFormat, is_integer);
st_translate_color(&tmp, texBaseFormat, is_integer);
util_format_apply_color_swizzle(&sampler->border_color,
&tmp, swz, is_integer);
util_format_apply_color_swizzle(&sampler->border_color,
&tmp, swz, is_integer);
} else {
st_translate_color(&sampler->border_color,
texBaseFormat, is_integer);
}
} else {
st_translate_color(&sampler->border_color,
texBaseFormat, is_integer);
}
} else {
st_translate_color(&sampler->border_color,
texBaseFormat, is_integer);
if (st->use_format_with_border_color) {
bool srgb_skip_decode = false;
if (!ignore_srgb_decode && msamp->Attrib.sRGBDecode == GL_SKIP_DECODE_EXT)
srgb_skip_decode = true;
sampler->border_color_format = st_get_sampler_view_format(st, texobj, srgb_skip_decode);
enum pipe_format format = st_get_sampler_view_format(st, texobj, srgb_skip_decode);
if (st->use_format_with_border_color)
sampler->border_color_format = format;
/* alpha is not w, so set it to the first available component: */
if (st->alpha_border_color_is_not_w && util_format_is_alpha(format)) {
/* use x component */
sampler->border_color.ui[0] = sampler->border_color.ui[3];
} else if (st->alpha_border_color_is_not_w && util_format_is_luminance_alpha(format)) {
/* use y component */
sampler->border_color.ui[1] = sampler->border_color.ui[3];
} else {
/* not an alpha format */
st_translate_color(&sampler->border_color,
texBaseFormat, is_integer);
}
}
} else {
st_translate_color(&sampler->border_color,
texBaseFormat, is_integer);
}
sampler->border_color_is_integer = is_integer;
}

View file

@ -598,6 +598,9 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
st->use_format_with_border_color =
!!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) &
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO);
st->alpha_border_color_is_not_w =
!!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) &
PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_ALPHA_NOT_W);
st->emulate_gl_clamp =
!screen->get_param(screen, PIPE_CAP_GL_CLAMP);
st->texture_buffer_sampler =

View file

@ -186,6 +186,7 @@ struct st_context
boolean needs_texcoord_semantic;
boolean apply_texture_swizzle_to_border_color;
boolean use_format_with_border_color;
boolean alpha_border_color_is_not_w;
boolean emulate_gl_clamp;
boolean texture_buffer_sampler;