panfrost: Move the blend constant mask extraction out of make_fixed_blend_mode()
This way we can get a constant mask for the blend shader case too.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7066>
diff --git a/src/gallium/drivers/panfrost/pan_blend_cso.c b/src/gallium/drivers/panfrost/pan_blend_cso.c
index 4378b4d..4b724e2 100644
--- a/src/gallium/drivers/panfrost/pan_blend_cso.c
+++ b/src/gallium/drivers/panfrost/pan_blend_cso.c
@@ -125,11 +125,9 @@
continue;
}
+ rt->constant_mask = panfrost_blend_constant_mask(&pipe);
rt->has_fixed_function =
- panfrost_make_fixed_blend_mode(
- pipe,
- &rt->equation,
- &rt->constant_mask);
+ panfrost_make_fixed_blend_mode(pipe, &rt->equation);
/* v6 doesn't support blend constants in FF blend equations. */
if (rt->has_fixed_function && version == 6 && rt->constant_mask)
diff --git a/src/gallium/drivers/panfrost/pan_blending.c b/src/gallium/drivers/panfrost/pan_blending.c
index fda516c..e1b6a7b 100644
--- a/src/gallium/drivers/panfrost/pan_blending.c
+++ b/src/gallium/drivers/panfrost/pan_blending.c
@@ -256,22 +256,28 @@
* the factors for constants used to create a mask to check later. */
static unsigned
-panfrost_constant_mask(unsigned *factors, unsigned num_factors)
+panfrost_blend_factor_constant_mask(enum pipe_blendfactor factor)
{
unsigned mask = 0;
- for (unsigned i = 0; i < num_factors; ++i) {
- unsigned factor = uncomplement_factor(factors[i]);
-
- if (factor == PIPE_BLENDFACTOR_CONST_COLOR)
- mask |= 0b0111; /* RGB */
- else if (factor == PIPE_BLENDFACTOR_CONST_ALPHA)
- mask |= 0b1000; /* A */
- }
+ factor = uncomplement_factor(factor);
+ if (factor == PIPE_BLENDFACTOR_CONST_COLOR)
+ mask |= 0b0111; /* RGB */
+ else if (factor == PIPE_BLENDFACTOR_CONST_ALPHA)
+ mask |= 0b1000; /* A */
return mask;
}
+unsigned
+panfrost_blend_constant_mask(const struct pipe_rt_blend_state *blend)
+{
+ return panfrost_blend_factor_constant_mask(blend->rgb_src_factor) |
+ panfrost_blend_factor_constant_mask(blend->rgb_dst_factor) |
+ panfrost_blend_factor_constant_mask(blend->alpha_src_factor) |
+ panfrost_blend_factor_constant_mask(blend->alpha_dst_factor);
+}
+
/* Create the descriptor for a fixed blend mode given the corresponding Gallium
* state, if possible. Return true and write out the blend descriptor into
* blend_equation. If it is not possible with the fixed function
@@ -280,8 +286,7 @@
bool
panfrost_make_fixed_blend_mode(const struct pipe_rt_blend_state blend,
- struct MALI_BLEND_EQUATION *equation,
- unsigned *constant_mask)
+ struct MALI_BLEND_EQUATION *equation)
{
/* If no blending is enabled, default back on `replace` mode */
@@ -296,17 +301,6 @@
return true;
}
- /* At draw-time, we'll need to analyze the blend constant, so
- * precompute a mask for it -- even if we don't end up able to use
- * fixed-function blending */
-
- unsigned factors[] = {
- blend.rgb_src_factor, blend.rgb_dst_factor,
- blend.alpha_src_factor, blend.alpha_dst_factor,
- };
-
- *constant_mask = panfrost_constant_mask(factors, ARRAY_SIZE(factors));
-
/* Try to compile the actual fixed-function blend */
if (!to_panfrost_function(blend.rgb_func, blend.rgb_src_factor,
blend.rgb_dst_factor,
diff --git a/src/gallium/drivers/panfrost/pan_blending.h b/src/gallium/drivers/panfrost/pan_blending.h
index d34e472..e187074 100644
--- a/src/gallium/drivers/panfrost/pan_blending.h
+++ b/src/gallium/drivers/panfrost/pan_blending.h
@@ -32,10 +32,12 @@
struct panfrost_blend_state;
+unsigned
+panfrost_blend_constant_mask(const struct pipe_rt_blend_state *blend);
+
bool
panfrost_make_fixed_blend_mode(const struct pipe_rt_blend_state blend,
- struct MALI_BLEND_EQUATION *equation,
- unsigned *constant_mask);
+ struct MALI_BLEND_EQUATION *equation);
bool
panfrost_can_fixed_blend(enum pipe_format format);