lima: fix blending with min/max ops

It turns out that BLEND_MIN and BLEND_MAX in Utgard take blend factors
into account. My guess is that actual equation looks like:

OP(As * S + Ad * D, Ad) for alpha, and
OP(Cs * S + Cd * D, Cd) for color.

So we have to set S factor to 1 and D factor to 0 to be compliant with
GL spec.

Fixes following piglit tests:
spec@!opengl 1.4@blendminmax
spec@arb_blend_func_extended@arb_blend_func_extended-fbo-extended-blend
(with patch my for ES2_compatibility and EXT_blend_func_extended)

Reviewed-by: Andreas Baierl <ichgeh@imkreisrum.de>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13873>
This commit is contained in:
Vasily Khoruzhick 2021-11-23 18:10:19 -08:00 committed by Marge Bot
parent 5f9434b611
commit 34a75ce15c
1 changed files with 16 additions and 0 deletions

View File

@ -517,6 +517,22 @@ lima_calculate_alpha_blend(enum pipe_blend_func rgb_func, enum pipe_blend_func a
if (alpha_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE)
alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
/* MIN and MAX ops actually do OP(As * S + Ad * D, Ad), so
* we need to set S to 1 and D to 0 to get correct result */
if (alpha_func == PIPE_BLEND_MIN ||
alpha_func == PIPE_BLEND_MAX) {
alpha_src_factor = PIPE_BLENDFACTOR_ONE;
alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
}
/* MIN and MAX ops actually do OP(Cs * S + Cd * D, Cd), so
* we need to set S to 1 and D to 0 to get correct result */
if (rgb_func == PIPE_BLEND_MIN ||
rgb_func == PIPE_BLEND_MAX) {
rgb_src_factor = PIPE_BLENDFACTOR_ONE;
rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
}
return lima_blend_func(rgb_func) |
(lima_blend_func(alpha_func) << 3) |
(lima_blend_factor(rgb_src_factor) << 6) |