diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 2c39d486bde..96a95cc38c8 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -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 diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index a690eca4e22..5ed72c9c696 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -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; } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index d3fc9774b76..530ea2c61c8 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -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 = diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index e90c170dcfb..005d18988ce 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -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;