From 34a75ce15ce1b264a27179081e97cb2e7248b555 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Tue, 23 Nov 2021 18:10:19 -0800 Subject: [PATCH] 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 Reviewed-by: Erico Nunes Signed-off-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/lima_draw.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 1d00fd40199..f1613a8d37a 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -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) |