panfrost: Convert to PIPE_BLEND enums internally

This removes all the users of the compiler enums, and is a lot more natural now
that nir_lower_blend speaks PIPE_BLEND enums.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Italo Nicola <italonicola@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24076>
This commit is contained in:
Alyssa Rosenzweig 2023-07-11 08:42:36 -04:00 committed by Marge Bot
parent a2d56c4c73
commit f55efb4ae6
6 changed files with 267 additions and 522 deletions

View file

@ -4201,24 +4201,12 @@ panfrost_create_blend_state(struct pipe_context *pipe,
equation.blend_enable = pipe.blend_enable; equation.blend_enable = pipe.blend_enable;
if (pipe.blend_enable) { if (pipe.blend_enable) {
equation.rgb_func = util_blend_func_to_shader(pipe.rgb_func); equation.rgb_func = pipe.rgb_func;
equation.rgb_src_factor = equation.rgb_src_factor = pipe.rgb_src_factor;
util_blend_factor_to_shader(pipe.rgb_src_factor); equation.rgb_dst_factor = pipe.rgb_dst_factor;
equation.rgb_invert_src_factor = equation.alpha_func = pipe.alpha_func;
util_blend_factor_is_inverted(pipe.rgb_src_factor); equation.alpha_src_factor = pipe.alpha_src_factor;
equation.rgb_dst_factor = equation.alpha_dst_factor = pipe.alpha_dst_factor;
util_blend_factor_to_shader(pipe.rgb_dst_factor);
equation.rgb_invert_dst_factor =
util_blend_factor_is_inverted(pipe.rgb_dst_factor);
equation.alpha_func = util_blend_func_to_shader(pipe.alpha_func);
equation.alpha_src_factor =
util_blend_factor_to_shader(pipe.alpha_src_factor);
equation.alpha_invert_src_factor =
util_blend_factor_is_inverted(pipe.alpha_src_factor);
equation.alpha_dst_factor =
util_blend_factor_to_shader(pipe.alpha_dst_factor);
equation.alpha_invert_dst_factor =
util_blend_factor_is_inverted(pipe.alpha_dst_factor);
} }
/* Determine some common properties */ /* Determine some common properties */

View file

@ -37,77 +37,18 @@
#include "util/format/u_format.h" #include "util/format/u_format.h"
#include "pan_texture.h" #include "pan_texture.h"
static inline enum pipe_blend_func
to_pipe_blend_func(enum blend_func func)
{
switch (func) {
case BLEND_FUNC_ADD:
return PIPE_BLEND_ADD;
case BLEND_FUNC_SUBTRACT:
return PIPE_BLEND_SUBTRACT;
case BLEND_FUNC_REVERSE_SUBTRACT:
return PIPE_BLEND_REVERSE_SUBTRACT;
case BLEND_FUNC_MIN:
return PIPE_BLEND_MIN;
case BLEND_FUNC_MAX:
return PIPE_BLEND_MAX;
}
unreachable("invalid");
}
static inline enum pipe_blendfactor
to_pipe_blendfactor_uninverted(enum blend_factor factor)
{
switch (factor) {
case BLEND_FACTOR_SRC_COLOR:
return PIPE_BLENDFACTOR_SRC_COLOR;
case BLEND_FACTOR_SRC1_COLOR:
return PIPE_BLENDFACTOR_SRC1_COLOR;
case BLEND_FACTOR_DST_COLOR:
return PIPE_BLENDFACTOR_DST_COLOR;
case BLEND_FACTOR_SRC_ALPHA:
return PIPE_BLENDFACTOR_SRC_ALPHA;
case BLEND_FACTOR_SRC1_ALPHA:
return PIPE_BLENDFACTOR_SRC1_ALPHA;
case BLEND_FACTOR_DST_ALPHA:
return PIPE_BLENDFACTOR_DST_ALPHA;
case BLEND_FACTOR_CONSTANT_COLOR:
return PIPE_BLENDFACTOR_CONST_COLOR;
case BLEND_FACTOR_CONSTANT_ALPHA:
return PIPE_BLENDFACTOR_CONST_ALPHA;
case BLEND_FACTOR_SRC_ALPHA_SATURATE:
return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
default:
unreachable("Invalid");
}
}
static inline enum pipe_blendfactor
to_pipe_blendfactor(enum blend_factor factor, bool inverted)
{
/* Flipped so handle special */
if (factor == BLEND_FACTOR_ZERO)
return inverted ? PIPE_BLENDFACTOR_ONE : PIPE_BLENDFACTOR_ZERO;
enum pipe_blendfactor pipe = to_pipe_blendfactor_uninverted(factor);
if (inverted)
pipe |= PIPE_BLENDFACTOR_INVERT_BIT;
return pipe;
}
#ifndef PAN_ARCH #ifndef PAN_ARCH
/* Fixed function blending */ /* Fixed function blending */
static bool static bool
factor_is_supported(enum blend_factor factor) factor_is_supported(enum pipe_blendfactor factor)
{ {
return factor != BLEND_FACTOR_SRC_ALPHA_SATURATE && factor = util_blendfactor_without_invert(factor);
factor != BLEND_FACTOR_SRC1_COLOR &&
factor != BLEND_FACTOR_SRC1_ALPHA; return factor != PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE &&
factor != PIPE_BLENDFACTOR_SRC1_COLOR &&
factor != PIPE_BLENDFACTOR_SRC1_ALPHA;
} }
/* OpenGL allows encoding (src*dest + dest*src) which is incompatiblle with /* OpenGL allows encoding (src*dest + dest*src) which is incompatiblle with
@ -116,50 +57,50 @@ factor_is_supported(enum blend_factor factor)
* + dest * (2*src) wih the new source_2 value of C. Detect this case. */ * + dest * (2*src) wih the new source_2 value of C. Detect this case. */
static bool static bool
is_2srcdest(enum blend_func blend_func, enum blend_factor src_factor, is_2srcdest(enum pipe_blend_func blend_func, enum pipe_blendfactor src_factor,
bool invert_src, enum blend_factor dest_factor, bool invert_dest, enum pipe_blendfactor dest_factor, bool is_alpha)
bool is_alpha)
{ {
return (blend_func == BLEND_FUNC_ADD) && return (blend_func == PIPE_BLEND_ADD) &&
((src_factor == BLEND_FACTOR_DST_COLOR) || ((src_factor == PIPE_BLENDFACTOR_DST_COLOR) ||
((src_factor == BLEND_FACTOR_DST_ALPHA) && is_alpha)) && ((src_factor == PIPE_BLENDFACTOR_DST_ALPHA) && is_alpha)) &&
((dest_factor == BLEND_FACTOR_SRC_COLOR) || ((dest_factor == PIPE_BLENDFACTOR_SRC_COLOR) ||
((dest_factor == BLEND_FACTOR_SRC_ALPHA) && is_alpha)) && ((dest_factor == PIPE_BLENDFACTOR_SRC_ALPHA) && is_alpha));
!invert_src && !invert_dest;
} }
static bool static bool
can_fixed_function_equation(enum blend_func blend_func, can_fixed_function_equation(enum pipe_blend_func blend_func,
enum blend_factor src_factor, bool invert_src, enum pipe_blendfactor src_factor,
enum blend_factor dest_factor, bool invert_dest, enum pipe_blendfactor dest_factor, bool is_alpha,
bool is_alpha, bool supports_2src) bool supports_2src)
{ {
if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor, invert_dest, if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha))
is_alpha)) {
return supports_2src; return supports_2src;
}
if (blend_func != BLEND_FUNC_ADD && blend_func != BLEND_FUNC_SUBTRACT && if (blend_func != PIPE_BLEND_ADD && blend_func != PIPE_BLEND_SUBTRACT &&
blend_func != BLEND_FUNC_REVERSE_SUBTRACT) blend_func != PIPE_BLEND_REVERSE_SUBTRACT)
return false; return false;
if (!factor_is_supported(src_factor) || !factor_is_supported(dest_factor)) if (!factor_is_supported(src_factor) || !factor_is_supported(dest_factor))
return false; return false;
if (src_factor != dest_factor && src_factor != BLEND_FACTOR_ZERO && /* Fixed function requires src/dest factors to match (up to invert) or be
dest_factor != BLEND_FACTOR_ZERO) * zero/one.
return false; */
enum pipe_blendfactor src = util_blendfactor_without_invert(src_factor);
enum pipe_blendfactor dest = util_blendfactor_without_invert(dest_factor);
return true; return (src == dest) || (src == PIPE_BLENDFACTOR_ONE) ||
(dest == PIPE_BLENDFACTOR_ONE);
} }
static unsigned static unsigned
blend_factor_constant_mask(enum blend_factor factor) blend_factor_constant_mask(enum pipe_blendfactor factor)
{ {
if (factor == BLEND_FACTOR_CONSTANT_COLOR) factor = util_blendfactor_without_invert(factor);
if (factor == PIPE_BLENDFACTOR_CONST_COLOR)
return 0b0111; /* RGB */ return 0b0111; /* RGB */
else if (factor == BLEND_FACTOR_CONSTANT_ALPHA) else if (factor == PIPE_BLENDFACTOR_CONST_ALPHA)
return 0b1000; /* A */ return 0b1000; /* A */
else else
return 0b0000; /* - */ return 0b0000; /* - */
@ -199,35 +140,34 @@ pan_blend_can_fixed_function(const struct pan_blend_equation equation,
return !equation.blend_enable || return !equation.blend_enable ||
(can_fixed_function_equation( (can_fixed_function_equation(
equation.rgb_func, equation.rgb_src_factor, equation.rgb_func, equation.rgb_src_factor,
equation.rgb_invert_src_factor, equation.rgb_dst_factor, equation.rgb_dst_factor, false, supports_2src) &&
equation.rgb_invert_dst_factor, false, supports_2src) &&
can_fixed_function_equation( can_fixed_function_equation(
equation.alpha_func, equation.alpha_src_factor, equation.alpha_func, equation.alpha_src_factor,
equation.alpha_invert_src_factor, equation.alpha_dst_factor, equation.alpha_dst_factor, true, supports_2src));
equation.alpha_invert_dst_factor, true, supports_2src));
} }
static enum mali_blend_operand_c static enum mali_blend_operand_c
to_c_factor(enum blend_factor factor) to_c_factor(enum pipe_blendfactor factor)
{ {
switch (factor) { switch (util_blendfactor_without_invert(factor)) {
case BLEND_FACTOR_ZERO: case PIPE_BLENDFACTOR_ONE:
/* Extra invert to flip back in caller */
return MALI_BLEND_OPERAND_C_ZERO; return MALI_BLEND_OPERAND_C_ZERO;
case BLEND_FACTOR_SRC_ALPHA: case PIPE_BLENDFACTOR_SRC_ALPHA:
return MALI_BLEND_OPERAND_C_SRC_ALPHA; return MALI_BLEND_OPERAND_C_SRC_ALPHA;
case BLEND_FACTOR_DST_ALPHA: case PIPE_BLENDFACTOR_DST_ALPHA:
return MALI_BLEND_OPERAND_C_DEST_ALPHA; return MALI_BLEND_OPERAND_C_DEST_ALPHA;
case BLEND_FACTOR_SRC_COLOR: case PIPE_BLENDFACTOR_SRC_COLOR:
return MALI_BLEND_OPERAND_C_SRC; return MALI_BLEND_OPERAND_C_SRC;
case BLEND_FACTOR_DST_COLOR: case PIPE_BLENDFACTOR_DST_COLOR:
return MALI_BLEND_OPERAND_C_DEST; return MALI_BLEND_OPERAND_C_DEST;
case BLEND_FACTOR_CONSTANT_COLOR: case PIPE_BLENDFACTOR_CONST_COLOR:
case BLEND_FACTOR_CONSTANT_ALPHA: case PIPE_BLENDFACTOR_CONST_ALPHA:
return MALI_BLEND_OPERAND_C_CONSTANT; return MALI_BLEND_OPERAND_C_CONSTANT;
default: default:
@ -236,87 +176,98 @@ to_c_factor(enum blend_factor factor)
} }
static void static void
to_panfrost_function(enum blend_func blend_func, enum blend_factor src_factor, to_panfrost_function(enum pipe_blend_func blend_func,
bool invert_src, enum blend_factor dest_factor, enum pipe_blendfactor src_factor,
bool invert_dest, bool is_alpha, enum pipe_blendfactor dest_factor, bool is_alpha,
struct MALI_BLEND_FUNCTION *function) struct MALI_BLEND_FUNCTION *function)
{ {
assert(can_fixed_function_equation(blend_func, src_factor, invert_src, assert(can_fixed_function_equation(blend_func, src_factor, dest_factor,
dest_factor, invert_dest, is_alpha, is_alpha, true));
true));
if (src_factor == BLEND_FACTOR_ZERO && !invert_src) { /* We handle ZERO/ONE specially since it's the hardware has 0 and can invert
* to 1 but Gallium has 0 as the uninverted version.
*/
bool src_inverted =
util_blendfactor_is_inverted(src_factor) ^
(util_blendfactor_without_invert(src_factor) == PIPE_BLENDFACTOR_ONE);
bool dest_inverted =
util_blendfactor_is_inverted(dest_factor) ^
(util_blendfactor_without_invert(dest_factor) == PIPE_BLENDFACTOR_ONE);
if (src_factor == PIPE_BLENDFACTOR_ZERO) {
function->a = MALI_BLEND_OPERAND_A_ZERO; function->a = MALI_BLEND_OPERAND_A_ZERO;
function->b = MALI_BLEND_OPERAND_B_DEST; function->b = MALI_BLEND_OPERAND_B_DEST;
if (blend_func == BLEND_FUNC_SUBTRACT) if (blend_func == PIPE_BLEND_SUBTRACT)
function->negate_b = true; function->negate_b = true;
function->invert_c = invert_dest; function->invert_c = dest_inverted;
function->c = to_c_factor(dest_factor); function->c = to_c_factor(dest_factor);
} else if (src_factor == BLEND_FACTOR_ZERO && invert_src) { } else if (src_factor == PIPE_BLENDFACTOR_ONE) {
function->a = MALI_BLEND_OPERAND_A_SRC; function->a = MALI_BLEND_OPERAND_A_SRC;
function->b = MALI_BLEND_OPERAND_B_DEST; function->b = MALI_BLEND_OPERAND_B_DEST;
if (blend_func == BLEND_FUNC_SUBTRACT) if (blend_func == PIPE_BLEND_SUBTRACT)
function->negate_b = true; function->negate_b = true;
else if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT) else if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
function->negate_a = true; function->negate_a = true;
function->invert_c = invert_dest; function->invert_c = dest_inverted;
function->c = to_c_factor(dest_factor); function->c = to_c_factor(dest_factor);
} else if (dest_factor == BLEND_FACTOR_ZERO && !invert_dest) { } else if (dest_factor == PIPE_BLENDFACTOR_ZERO) {
function->a = MALI_BLEND_OPERAND_A_ZERO; function->a = MALI_BLEND_OPERAND_A_ZERO;
function->b = MALI_BLEND_OPERAND_B_SRC; function->b = MALI_BLEND_OPERAND_B_SRC;
if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT) if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
function->negate_b = true; function->negate_b = true;
function->invert_c = invert_src; function->invert_c = src_inverted;
function->c = to_c_factor(src_factor); function->c = to_c_factor(src_factor);
} else if (dest_factor == BLEND_FACTOR_ZERO && invert_dest) { } else if (dest_factor == PIPE_BLENDFACTOR_ONE) {
function->a = MALI_BLEND_OPERAND_A_DEST; function->a = MALI_BLEND_OPERAND_A_DEST;
function->b = MALI_BLEND_OPERAND_B_SRC; function->b = MALI_BLEND_OPERAND_B_SRC;
if (blend_func == BLEND_FUNC_SUBTRACT) if (blend_func == PIPE_BLEND_SUBTRACT)
function->negate_a = true; function->negate_a = true;
else if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT) else if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
function->negate_b = true; function->negate_b = true;
function->invert_c = invert_src; function->invert_c = src_inverted;
function->c = to_c_factor(src_factor); function->c = to_c_factor(src_factor);
} else if (src_factor == dest_factor && invert_src == invert_dest) { } else if (src_factor == dest_factor) {
function->a = MALI_BLEND_OPERAND_A_ZERO; function->a = MALI_BLEND_OPERAND_A_ZERO;
function->invert_c = invert_src; function->invert_c = src_inverted;
function->c = to_c_factor(src_factor); function->c = to_c_factor(src_factor);
switch (blend_func) { switch (blend_func) {
case BLEND_FUNC_ADD: case PIPE_BLEND_ADD:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST; function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
break; break;
case BLEND_FUNC_REVERSE_SUBTRACT: case PIPE_BLEND_REVERSE_SUBTRACT:
function->negate_b = true; function->negate_b = true;
FALLTHROUGH; FALLTHROUGH;
case BLEND_FUNC_SUBTRACT: case PIPE_BLEND_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST; function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
break; break;
default: default:
unreachable("Invalid blend function"); unreachable("Invalid blend function");
} }
} else if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor, } else if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha)) {
invert_dest, is_alpha)) {
/* src*dest + dest*src = 2*src*dest = 0 + dest*(2*src) */ /* src*dest + dest*src = 2*src*dest = 0 + dest*(2*src) */
function->a = MALI_BLEND_OPERAND_A_ZERO; function->a = MALI_BLEND_OPERAND_A_ZERO;
function->b = MALI_BLEND_OPERAND_B_DEST; function->b = MALI_BLEND_OPERAND_B_DEST;
function->c = MALI_BLEND_OPERAND_C_SRC_X_2; function->c = MALI_BLEND_OPERAND_C_SRC_X_2;
} else { } else {
assert(src_factor == dest_factor && invert_src != invert_dest); assert(util_blendfactor_without_invert(src_factor) ==
util_blendfactor_without_invert(dest_factor) &&
src_inverted != dest_inverted);
function->a = MALI_BLEND_OPERAND_A_DEST; function->a = MALI_BLEND_OPERAND_A_DEST;
function->invert_c = invert_src; function->invert_c = src_inverted;
function->c = to_c_factor(src_factor); function->c = to_c_factor(src_factor);
switch (blend_func) { switch (blend_func) {
case BLEND_FUNC_ADD: case PIPE_BLEND_ADD:
function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST; function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
break; break;
case BLEND_FUNC_REVERSE_SUBTRACT: case PIPE_BLEND_REVERSE_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST; function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
function->negate_b = true; function->negate_b = true;
break; break;
case BLEND_FUNC_SUBTRACT: case PIPE_BLEND_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST; function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
function->negate_a = true; function->negate_a = true;
break; break;
@ -339,32 +290,42 @@ pan_blend_is_opaque(const struct pan_blend_equation equation)
return true; return true;
/* Also detect open-coded opaque blending */ /* Also detect open-coded opaque blending */
return equation.rgb_src_factor == BLEND_FACTOR_ZERO && return equation.rgb_src_factor == PIPE_BLENDFACTOR_ONE &&
equation.rgb_invert_src_factor && equation.rgb_dst_factor == PIPE_BLENDFACTOR_ZERO &&
equation.rgb_dst_factor == BLEND_FACTOR_ZERO && (equation.rgb_func == PIPE_BLEND_ADD ||
!equation.rgb_invert_dst_factor && equation.rgb_func == PIPE_BLEND_SUBTRACT) &&
(equation.rgb_func == BLEND_FUNC_ADD || equation.alpha_src_factor == PIPE_BLENDFACTOR_ONE &&
equation.rgb_func == BLEND_FUNC_SUBTRACT) && equation.alpha_dst_factor == PIPE_BLENDFACTOR_ZERO &&
equation.alpha_src_factor == BLEND_FACTOR_ZERO && (equation.alpha_func == PIPE_BLEND_ADD ||
equation.alpha_invert_src_factor && equation.alpha_func == PIPE_BLEND_SUBTRACT);
equation.alpha_dst_factor == BLEND_FACTOR_ZERO &&
!equation.alpha_invert_dst_factor &&
(equation.alpha_func == BLEND_FUNC_ADD ||
equation.alpha_func == BLEND_FUNC_SUBTRACT);
} }
/* Check if (factor, invert) represents a constant value of val, assuming /* Check if a factor represents a constant value of val, assuming src_alpha is
* src_alpha is the given constant. * the given constant.
*/ */
static inline bool static inline bool
is_factor_01(unsigned factor, bool invert, unsigned val, unsigned srca) is_factor_01(enum pipe_blendfactor factor, unsigned val, unsigned srca)
{ {
assert(val == 0 || val == 1); assert(val == 0 || val == 1);
assert(srca == 0 || srca == 1); assert(srca == 0 || srca == 1);
return ((invert ^ !val) && factor == BLEND_FACTOR_ZERO) || switch (factor) {
((invert ^ srca ^ !val) && factor == BLEND_FACTOR_SRC_ALPHA); case PIPE_BLENDFACTOR_ZERO:
return (val == 0);
case PIPE_BLENDFACTOR_ONE:
return (val == 1);
case PIPE_BLENDFACTOR_SRC_ALPHA:
return (val == srca);
case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
return (val == (1 - srca));
default:
return false;
}
} }
/* Returns if src alpha = 0 implies the blended colour equals the destination /* Returns if src alpha = 0 implies the blended colour equals the destination
@ -387,20 +348,20 @@ is_factor_01(unsigned factor, bool invert, unsigned val, unsigned srca)
bool bool
pan_blend_alpha_zero_nop(const struct pan_blend_equation eq) pan_blend_alpha_zero_nop(const struct pan_blend_equation eq)
{ {
if (eq.rgb_func != BLEND_FUNC_ADD && if (eq.rgb_func != PIPE_BLEND_ADD &&
eq.rgb_func != BLEND_FUNC_REVERSE_SUBTRACT) eq.rgb_func != PIPE_BLEND_REVERSE_SUBTRACT)
return false; return false;
if (eq.color_mask & 0x8) { if (eq.color_mask & 0x8) {
if (!is_factor_01(eq.alpha_dst_factor, eq.alpha_invert_dst_factor, 1, 0)) if (!is_factor_01(eq.alpha_dst_factor, 1, 0))
return false; return false;
} }
if (eq.color_mask & 0x7) { if (eq.color_mask & 0x7) {
if (!is_factor_01(eq.rgb_dst_factor, eq.rgb_invert_dst_factor, 1, 0)) if (!is_factor_01(eq.rgb_dst_factor, 1, 0))
return false; return false;
if (!is_factor_01(eq.rgb_src_factor, eq.rgb_invert_src_factor, 0, 0)) if (!is_factor_01(eq.rgb_src_factor, 0, 0))
return false; return false;
} }
@ -425,24 +386,26 @@ pan_blend_alpha_zero_nop(const struct pan_blend_equation eq)
bool bool
pan_blend_alpha_one_store(const struct pan_blend_equation eq) pan_blend_alpha_one_store(const struct pan_blend_equation eq)
{ {
if (eq.rgb_func != BLEND_FUNC_ADD && eq.rgb_func != BLEND_FUNC_SUBTRACT) if (eq.rgb_func != PIPE_BLEND_ADD && eq.rgb_func != PIPE_BLEND_SUBTRACT)
return false; return false;
if (eq.color_mask != 0xf) if (eq.color_mask != 0xf)
return false; return false;
return is_factor_01(eq.rgb_src_factor, eq.rgb_invert_src_factor, 1, 1) && return is_factor_01(eq.rgb_src_factor, 1, 1) &&
is_factor_01(eq.alpha_src_factor, eq.alpha_invert_src_factor, 1, 1) && is_factor_01(eq.alpha_src_factor, 1, 1) &&
is_factor_01(eq.rgb_dst_factor, eq.rgb_invert_dst_factor, 0, 1) && is_factor_01(eq.rgb_dst_factor, 0, 1) &&
is_factor_01(eq.alpha_dst_factor, eq.alpha_invert_dst_factor, 0, 1); is_factor_01(eq.alpha_dst_factor, 0, 1);
} }
static bool static bool
is_dest_factor(enum blend_factor factor, bool alpha) is_dest_factor(enum pipe_blendfactor factor, bool alpha)
{ {
return factor == BLEND_FACTOR_DST_ALPHA || factor = util_blendfactor_without_invert(factor);
factor == BLEND_FACTOR_DST_COLOR ||
(factor == BLEND_FACTOR_SRC_ALPHA_SATURATE && !alpha); return factor == PIPE_BLENDFACTOR_DST_ALPHA ||
factor == PIPE_BLENDFACTOR_DST_COLOR ||
(factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE && !alpha);
} }
/* Determines if a blend equation reads back the destination. This can occur by /* Determines if a blend equation reads back the destination. This can occur by
@ -452,13 +415,16 @@ is_dest_factor(enum blend_factor factor, bool alpha)
bool bool
pan_blend_reads_dest(const struct pan_blend_equation equation) pan_blend_reads_dest(const struct pan_blend_equation equation)
{ {
return (equation.color_mask && equation.color_mask != 0xF) || if (equation.color_mask && equation.color_mask != 0xF)
is_dest_factor(equation.rgb_src_factor, false) || return true;
if (!equation.blend_enable)
return false;
return is_dest_factor(equation.rgb_src_factor, false) ||
is_dest_factor(equation.alpha_src_factor, true) || is_dest_factor(equation.alpha_src_factor, true) ||
equation.rgb_dst_factor != BLEND_FACTOR_ZERO || equation.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
equation.rgb_invert_dst_factor || equation.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO;
equation.alpha_dst_factor != BLEND_FACTOR_ZERO ||
equation.alpha_invert_dst_factor;
} }
/* Create the descriptor for a fixed blend mode given the corresponding API /* Create the descriptor for a fixed blend mode given the corresponding API
@ -482,13 +448,10 @@ pan_blend_to_fixed_function_equation(const struct pan_blend_equation equation,
/* Compile the fixed-function blend */ /* Compile the fixed-function blend */
to_panfrost_function(equation.rgb_func, equation.rgb_src_factor, to_panfrost_function(equation.rgb_func, equation.rgb_src_factor,
equation.rgb_invert_src_factor, equation.rgb_dst_factor, equation.rgb_dst_factor, false, &out->rgb);
equation.rgb_invert_dst_factor, false, &out->rgb);
to_panfrost_function(equation.alpha_func, equation.alpha_src_factor, to_panfrost_function(equation.alpha_func, equation.alpha_src_factor,
equation.alpha_invert_src_factor, equation.alpha_dst_factor, true, &out->alpha);
equation.alpha_dst_factor,
equation.alpha_invert_dst_factor, true, &out->alpha);
out->color_mask = equation.color_mask; out->color_mask = equation.color_mask;
} }
@ -583,8 +546,8 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
"add", "sub", "reverse_sub", "min", "max", "add", "sub", "reverse_sub", "min", "max",
}; };
const char *factors[] = { const char *factors[] = {
"zero", "src_color", "src1_color", "dst_color", "src_alpha", "one", "src_color", "src_alpha", "dst_alpha", "dst_color",
"src1_alpha", "dst_alpha", "const_color", "const_alpha", "src_alpha_sat", "src_alpha_sat", "const_color", "const_alpha", "src1_color", "src1_alpha",
}; };
int ret; int ret;
@ -600,18 +563,20 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
if (rt_state->equation.color_mask & 7) { if (rt_state->equation.color_mask & 7) {
assert(rt_state->equation.rgb_func < ARRAY_SIZE(funcs)); assert(rt_state->equation.rgb_func < ARRAY_SIZE(funcs));
assert(rt_state->equation.rgb_src_factor < ARRAY_SIZE(factors)); ret = snprintf(
assert(rt_state->equation.rgb_dst_factor < ARRAY_SIZE(factors)); str, len, "%s%s%s(func=%s,src_factor=%s%s,dst_factor=%s%s)%s",
ret =
snprintf(str, len, "%s%s%s(func=%s,src_factor=%s%s,dst_factor=%s%s)%s",
(rt_state->equation.color_mask & 1) ? "R" : "", (rt_state->equation.color_mask & 1) ? "R" : "",
(rt_state->equation.color_mask & 2) ? "G" : "", (rt_state->equation.color_mask & 2) ? "G" : "",
(rt_state->equation.color_mask & 4) ? "B" : "", (rt_state->equation.color_mask & 4) ? "B" : "",
funcs[rt_state->equation.rgb_func], funcs[rt_state->equation.rgb_func],
rt_state->equation.rgb_invert_src_factor ? "-" : "", util_blendfactor_is_inverted(rt_state->equation.rgb_src_factor) ? "-"
factors[rt_state->equation.rgb_src_factor], : "",
rt_state->equation.rgb_invert_dst_factor ? "-" : "", factors[util_blendfactor_without_invert(
factors[rt_state->equation.rgb_dst_factor], rt_state->equation.rgb_src_factor)],
util_blendfactor_is_inverted(rt_state->equation.rgb_dst_factor) ? "-"
: "",
factors[util_blendfactor_without_invert(
rt_state->equation.rgb_dst_factor)],
rt_state->equation.color_mask & 8 ? ";" : ""); rt_state->equation.color_mask & 8 ? ";" : "");
assert(ret > 0); assert(ret > 0);
str += ret; str += ret;
@ -620,14 +585,17 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
if (rt_state->equation.color_mask & 8) { if (rt_state->equation.color_mask & 8) {
assert(rt_state->equation.alpha_func < ARRAY_SIZE(funcs)); assert(rt_state->equation.alpha_func < ARRAY_SIZE(funcs));
assert(rt_state->equation.alpha_src_factor < ARRAY_SIZE(factors)); ret = snprintf(
assert(rt_state->equation.alpha_dst_factor < ARRAY_SIZE(factors)); str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
ret = snprintf(str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
funcs[rt_state->equation.alpha_func], funcs[rt_state->equation.alpha_func],
rt_state->equation.alpha_invert_src_factor ? "-" : "", util_blendfactor_is_inverted(rt_state->equation.alpha_src_factor) ? "-"
factors[rt_state->equation.alpha_src_factor], : "",
rt_state->equation.alpha_invert_dst_factor ? "-" : "", factors[util_blendfactor_without_invert(
factors[rt_state->equation.alpha_dst_factor]); rt_state->equation.alpha_src_factor)],
util_blendfactor_is_inverted(rt_state->equation.alpha_dst_factor) ? "-"
: "",
factors[util_blendfactor_without_invert(
rt_state->equation.alpha_dst_factor)]);
assert(ret > 0); assert(ret > 0);
str += ret; str += ret;
len -= ret; len -= ret;
@ -707,21 +675,12 @@ GENX(pan_blend_create_shader)(const struct panfrost_device *dev,
options.rt[rt].rgb = replace; options.rt[rt].rgb = replace;
options.rt[rt].alpha = replace; options.rt[rt].alpha = replace;
} else { } else {
options.rt[rt].rgb.func = to_pipe_blend_func(rt_state->equation.rgb_func); options.rt[rt].rgb.func = rt_state->equation.rgb_func;
options.rt[rt].rgb.src_factor = options.rt[rt].rgb.src_factor = rt_state->equation.rgb_src_factor;
to_pipe_blendfactor(rt_state->equation.rgb_src_factor, options.rt[rt].rgb.dst_factor = rt_state->equation.rgb_dst_factor;
rt_state->equation.rgb_invert_src_factor); options.rt[rt].alpha.func = rt_state->equation.alpha_func;
options.rt[rt].rgb.dst_factor = options.rt[rt].alpha.src_factor = rt_state->equation.alpha_src_factor;
to_pipe_blendfactor(rt_state->equation.rgb_dst_factor, options.rt[rt].alpha.dst_factor = rt_state->equation.alpha_dst_factor;
rt_state->equation.rgb_invert_dst_factor);
options.rt[rt].alpha.func =
to_pipe_blend_func(rt_state->equation.alpha_func);
options.rt[rt].alpha.src_factor =
to_pipe_blendfactor(rt_state->equation.alpha_src_factor,
rt_state->equation.alpha_invert_src_factor);
options.rt[rt].alpha.dst_factor =
to_pipe_blendfactor(rt_state->equation.alpha_dst_factor,
rt_state->equation.alpha_invert_dst_factor);
} }
nir_ssa_def *pixel = nir_load_barycentric_pixel(&b, 32, .interp_mode = 1); nir_ssa_def *pixel = nir_load_barycentric_pixel(&b, 32, .interp_mode = 1);

View file

@ -28,7 +28,7 @@
#include "genxml/gen_macros.h" #include "genxml/gen_macros.h"
#include "compiler/nir/nir.h" #include "compiler/nir/nir.h"
#include "compiler/shader_enums.h" #include "util/blend.h"
#include "util/format/u_format.h" #include "util/format/u_format.h"
#include "util/u_dynarray.h" #include "util/u_dynarray.h"
@ -39,17 +39,14 @@ struct panfrost_device;
struct pan_blend_equation { struct pan_blend_equation {
unsigned blend_enable : 1; unsigned blend_enable : 1;
enum blend_func rgb_func : 3; enum pipe_blend_func rgb_func : 3;
unsigned rgb_invert_src_factor : 1; enum pipe_blendfactor rgb_src_factor : 5;
enum blend_factor rgb_src_factor : 4; enum pipe_blendfactor rgb_dst_factor : 5;
unsigned rgb_invert_dst_factor : 1; enum pipe_blend_func alpha_func : 3;
enum blend_factor rgb_dst_factor : 4; enum pipe_blendfactor alpha_src_factor : 5;
enum blend_func alpha_func : 3; enum pipe_blendfactor alpha_dst_factor : 5;
unsigned alpha_invert_src_factor : 1;
enum blend_factor alpha_src_factor : 4;
unsigned alpha_invert_dst_factor : 1;
enum blend_factor alpha_dst_factor : 4;
unsigned color_mask : 4; unsigned color_mask : 4;
unsigned padding : 1;
}; };
struct pan_blend_rt_state { struct pan_blend_rt_state {

View file

@ -62,10 +62,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA), RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
RGBA(dst_factor, BLEND_FACTOR_SRC_ALPHA), RGBA(dst_factor, PIPE_BLENDFACTOR_INV_SRC_ALPHA),
RGBA(invert_dst_factor, true),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -81,11 +80,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_ZERO), RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
RGBA(dst_factor, BLEND_FACTOR_ZERO), RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
RGBA(invert_src_factor, true),
RGBA(invert_dst_factor, true),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -101,10 +98,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA), RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
RGBA(dst_factor, BLEND_FACTOR_ZERO), RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
RGBA(invert_dst_factor, true),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -120,11 +116,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_SUBTRACT), RGBA(func, PIPE_BLEND_SUBTRACT),
RGBA(src_factor, BLEND_FACTOR_ZERO), RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
RGBA(dst_factor, BLEND_FACTOR_ZERO), RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
RGBA(invert_src_factor, true),
RGBA(invert_dst_factor, true),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -140,10 +134,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_SUBTRACT), RGBA(func, PIPE_BLEND_SUBTRACT),
RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA), RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
RGBA(dst_factor, BLEND_FACTOR_ZERO), RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
RGBA(invert_dst_factor, true),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -159,9 +152,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_ZERO), RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR), RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -191,9 +184,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xA, .color_mask = 0xA,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_ZERO), RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR), RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -209,9 +202,9 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xF, .color_mask = 0xF,
RGBA(func, BLEND_FUNC_ADD), RGBA(func, PIPE_BLEND_ADD),
RGBA(src_factor, BLEND_FACTOR_DST_COLOR), RGBA(src_factor, PIPE_BLENDFACTOR_DST_COLOR),
RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR), RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -227,14 +220,13 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xC, .color_mask = 0xC,
.rgb_func = BLEND_FUNC_ADD, .rgb_func = PIPE_BLEND_ADD,
.rgb_src_factor = BLEND_FACTOR_ZERO, .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
.rgb_invert_src_factor = true, .rgb_dst_factor= PIPE_BLENDFACTOR_ZERO,
.rgb_dst_factor= BLEND_FACTOR_ZERO,
.alpha_func = BLEND_FUNC_ADD, .alpha_func = PIPE_BLEND_ADD,
.alpha_src_factor = BLEND_FACTOR_DST_COLOR, .alpha_src_factor = PIPE_BLENDFACTOR_DST_COLOR,
.alpha_dst_factor= BLEND_FACTOR_SRC_COLOR, .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -250,14 +242,13 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xC, .color_mask = 0xC,
.rgb_func = BLEND_FUNC_ADD, .rgb_func = PIPE_BLEND_ADD,
.rgb_src_factor = BLEND_FACTOR_ZERO, .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
.rgb_invert_src_factor = true, .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
.rgb_dst_factor= BLEND_FACTOR_ZERO,
.alpha_func = BLEND_FUNC_ADD, .alpha_func = PIPE_BLEND_ADD,
.alpha_src_factor = BLEND_FACTOR_DST_ALPHA, .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
.alpha_dst_factor= BLEND_FACTOR_SRC_COLOR, .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,
@ -273,14 +264,13 @@ static const struct test blend_tests[] = {
.blend_enable = true, .blend_enable = true,
.color_mask = 0xC, .color_mask = 0xC,
.rgb_func = BLEND_FUNC_ADD, .rgb_func = PIPE_BLEND_ADD,
.rgb_src_factor = BLEND_FACTOR_ZERO, .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
.rgb_invert_src_factor = true, .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
.rgb_dst_factor= BLEND_FACTOR_ZERO,
.alpha_func = BLEND_FUNC_ADD, .alpha_func = PIPE_BLEND_ADD,
.alpha_src_factor = BLEND_FACTOR_DST_ALPHA, .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
.alpha_dst_factor= BLEND_FACTOR_SRC_ALPHA, .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_ALPHA,
}, },
.constant_mask = 0x0, .constant_mask = 0x0,
.reads_dest = true, .reads_dest = true,

View file

@ -34,9 +34,11 @@
#include "nir/nir.h" #include "nir/nir.h"
#include "nir/nir_builder.h" #include "nir/nir_builder.h"
#include "spirv/nir_spirv.h" #include "spirv/nir_spirv.h"
#include "util/blend.h"
#include "util/mesa-sha1.h" #include "util/mesa-sha1.h"
#include "util/u_atomic.h" #include "util/u_atomic.h"
#include "util/u_debug.h" #include "util/u_debug.h"
#include "vk_blend.h"
#include "vk_format.h" #include "vk_format.h"
#include "vk_util.h" #include "vk_util.h"
@ -391,126 +393,6 @@ panvk_pipeline_builder_parse_input_assembly(
builder->create_info.gfx->pInputAssemblyState->topology); builder->create_info.gfx->pInputAssemblyState->topology);
} }
static enum pipe_logicop
translate_logicop(VkLogicOp in)
{
switch (in) {
case VK_LOGIC_OP_CLEAR:
return PIPE_LOGICOP_CLEAR;
case VK_LOGIC_OP_AND:
return PIPE_LOGICOP_AND;
case VK_LOGIC_OP_AND_REVERSE:
return PIPE_LOGICOP_AND_REVERSE;
case VK_LOGIC_OP_COPY:
return PIPE_LOGICOP_COPY;
case VK_LOGIC_OP_AND_INVERTED:
return PIPE_LOGICOP_AND_INVERTED;
case VK_LOGIC_OP_NO_OP:
return PIPE_LOGICOP_NOOP;
case VK_LOGIC_OP_XOR:
return PIPE_LOGICOP_XOR;
case VK_LOGIC_OP_OR:
return PIPE_LOGICOP_OR;
case VK_LOGIC_OP_NOR:
return PIPE_LOGICOP_NOR;
case VK_LOGIC_OP_EQUIVALENT:
return PIPE_LOGICOP_EQUIV;
case VK_LOGIC_OP_INVERT:
return PIPE_LOGICOP_INVERT;
case VK_LOGIC_OP_OR_REVERSE:
return PIPE_LOGICOP_OR_REVERSE;
case VK_LOGIC_OP_COPY_INVERTED:
return PIPE_LOGICOP_COPY_INVERTED;
case VK_LOGIC_OP_OR_INVERTED:
return PIPE_LOGICOP_OR_INVERTED;
case VK_LOGIC_OP_NAND:
return PIPE_LOGICOP_NAND;
case VK_LOGIC_OP_SET:
return PIPE_LOGICOP_SET;
default:
unreachable("Invalid logicop");
}
}
static enum blend_func
translate_blend_op(VkBlendOp in)
{
switch (in) {
case VK_BLEND_OP_ADD:
return BLEND_FUNC_ADD;
case VK_BLEND_OP_SUBTRACT:
return BLEND_FUNC_SUBTRACT;
case VK_BLEND_OP_REVERSE_SUBTRACT:
return BLEND_FUNC_REVERSE_SUBTRACT;
case VK_BLEND_OP_MIN:
return BLEND_FUNC_MIN;
case VK_BLEND_OP_MAX:
return BLEND_FUNC_MAX;
default:
unreachable("Invalid blend op");
}
}
static enum blend_factor
translate_blend_factor(VkBlendFactor in, bool dest_has_alpha)
{
switch (in) {
case VK_BLEND_FACTOR_ZERO:
case VK_BLEND_FACTOR_ONE:
return BLEND_FACTOR_ZERO;
case VK_BLEND_FACTOR_SRC_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
return BLEND_FACTOR_SRC_COLOR;
case VK_BLEND_FACTOR_DST_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
return BLEND_FACTOR_DST_COLOR;
case VK_BLEND_FACTOR_SRC_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
return BLEND_FACTOR_SRC_ALPHA;
case VK_BLEND_FACTOR_DST_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
return dest_has_alpha ? BLEND_FACTOR_DST_ALPHA : BLEND_FACTOR_ZERO;
case VK_BLEND_FACTOR_CONSTANT_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
return BLEND_FACTOR_CONSTANT_COLOR;
case VK_BLEND_FACTOR_CONSTANT_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
return BLEND_FACTOR_CONSTANT_ALPHA;
case VK_BLEND_FACTOR_SRC1_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
return BLEND_FACTOR_SRC1_COLOR;
case VK_BLEND_FACTOR_SRC1_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
return BLEND_FACTOR_SRC1_ALPHA;
case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
return BLEND_FACTOR_SRC_ALPHA_SATURATE;
default:
unreachable("Invalid blend factor");
}
}
static bool
inverted_blend_factor(VkBlendFactor in, bool dest_has_alpha)
{
switch (in) {
case VK_BLEND_FACTOR_ONE:
case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
return true;
case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
return dest_has_alpha ? true : false;
case VK_BLEND_FACTOR_DST_ALPHA:
return !dest_has_alpha ? true : false;
default:
return false;
}
}
bool bool
panvk_per_arch(blend_needs_lowering)(const struct panfrost_device *dev, panvk_per_arch(blend_needs_lowering)(const struct panfrost_device *dev,
const struct pan_blend_state *state, const struct pan_blend_state *state,
@ -548,7 +430,7 @@ panvk_pipeline_builder_parse_color_blend(struct panvk_pipeline_builder *builder,
pipeline->blend.state.logicop_enable = pipeline->blend.state.logicop_enable =
builder->create_info.gfx->pColorBlendState->logicOpEnable; builder->create_info.gfx->pColorBlendState->logicOpEnable;
pipeline->blend.state.logicop_func = pipeline->blend.state.logicop_func =
translate_logicop(builder->create_info.gfx->pColorBlendState->logicOp); vk_logic_op_to_pipe(builder->create_info.gfx->pColorBlendState->logicOp);
pipeline->blend.state.rt_count = pipeline->blend.state.rt_count =
util_last_bit(builder->active_color_attachments); util_last_bit(builder->active_color_attachments);
memcpy(pipeline->blend.state.constants, memcpy(pipeline->blend.state.constants,
@ -568,24 +450,28 @@ panvk_pipeline_builder_parse_color_blend(struct panvk_pipeline_builder *builder,
builder->create_info.gfx->pMultisampleState->rasterizationSamples; builder->create_info.gfx->pMultisampleState->rasterizationSamples;
out->equation.blend_enable = in->blendEnable; out->equation.blend_enable = in->blendEnable;
out->equation.color_mask = in->colorWriteMask; out->equation.color_mask = in->colorWriteMask;
out->equation.rgb_func = translate_blend_op(in->colorBlendOp); out->equation.rgb_func = vk_blend_op_to_pipe(in->colorBlendOp);
out->equation.rgb_src_factor = out->equation.rgb_src_factor =
translate_blend_factor(in->srcColorBlendFactor, dest_has_alpha); vk_blend_factor_to_pipe(in->srcColorBlendFactor);
out->equation.rgb_invert_src_factor =
inverted_blend_factor(in->srcColorBlendFactor, dest_has_alpha);
out->equation.rgb_dst_factor = out->equation.rgb_dst_factor =
translate_blend_factor(in->dstColorBlendFactor, dest_has_alpha); vk_blend_factor_to_pipe(in->dstColorBlendFactor);
out->equation.rgb_invert_dst_factor = out->equation.alpha_func = vk_blend_op_to_pipe(in->alphaBlendOp);
inverted_blend_factor(in->dstColorBlendFactor, dest_has_alpha);
out->equation.alpha_func = translate_blend_op(in->alphaBlendOp);
out->equation.alpha_src_factor = out->equation.alpha_src_factor =
translate_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha); vk_blend_factor_to_pipe(in->srcAlphaBlendFactor);
out->equation.alpha_invert_src_factor =
inverted_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha);
out->equation.alpha_dst_factor = out->equation.alpha_dst_factor =
translate_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha); vk_blend_factor_to_pipe(in->dstAlphaBlendFactor);
out->equation.alpha_invert_dst_factor =
inverted_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha); if (!dest_has_alpha) {
out->equation.rgb_src_factor =
util_blend_dst_alpha_to_one(out->equation.rgb_src_factor);
out->equation.rgb_dst_factor =
util_blend_dst_alpha_to_one(out->equation.rgb_dst_factor);
out->equation.alpha_src_factor =
util_blend_dst_alpha_to_one(out->equation.alpha_src_factor);
out->equation.alpha_dst_factor =
util_blend_dst_alpha_to_one(out->equation.alpha_dst_factor);
}
pipeline->blend.reads_dest |= pan_blend_reads_dest(out->equation); pipeline->blend.reads_dest |= pan_blend_reads_dest(out->equation);

View file

@ -120,67 +120,6 @@ panvk_lower_sysvals(nir_builder *b, nir_instr *instr, void *data)
return true; return true;
} }
static inline enum pipe_blend_func
to_pipe_blend_func(enum blend_func func)
{
switch (func) {
case BLEND_FUNC_ADD:
return PIPE_BLEND_ADD;
case BLEND_FUNC_SUBTRACT:
return PIPE_BLEND_SUBTRACT;
case BLEND_FUNC_REVERSE_SUBTRACT:
return PIPE_BLEND_REVERSE_SUBTRACT;
case BLEND_FUNC_MIN:
return PIPE_BLEND_MIN;
case BLEND_FUNC_MAX:
return PIPE_BLEND_MAX;
}
unreachable("invalid");
}
static inline enum pipe_blendfactor
to_pipe_blendfactor_uninverted(enum blend_factor factor)
{
switch (factor) {
case BLEND_FACTOR_SRC_COLOR:
return PIPE_BLENDFACTOR_SRC_COLOR;
case BLEND_FACTOR_SRC1_COLOR:
return PIPE_BLENDFACTOR_SRC1_COLOR;
case BLEND_FACTOR_DST_COLOR:
return PIPE_BLENDFACTOR_DST_COLOR;
case BLEND_FACTOR_SRC_ALPHA:
return PIPE_BLENDFACTOR_SRC_ALPHA;
case BLEND_FACTOR_SRC1_ALPHA:
return PIPE_BLENDFACTOR_SRC1_ALPHA;
case BLEND_FACTOR_DST_ALPHA:
return PIPE_BLENDFACTOR_DST_ALPHA;
case BLEND_FACTOR_CONSTANT_COLOR:
return PIPE_BLENDFACTOR_CONST_COLOR;
case BLEND_FACTOR_CONSTANT_ALPHA:
return PIPE_BLENDFACTOR_CONST_ALPHA;
case BLEND_FACTOR_SRC_ALPHA_SATURATE:
return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
default:
unreachable("Invalid");
}
}
static inline enum pipe_blendfactor
to_pipe_blendfactor(enum blend_factor factor, bool inverted)
{
/* Flipped so handle special */
if (factor == BLEND_FACTOR_ZERO)
return inverted ? PIPE_BLENDFACTOR_ONE : PIPE_BLENDFACTOR_ZERO;
enum pipe_blendfactor pipe = to_pipe_blendfactor_uninverted(factor);
if (inverted)
pipe |= PIPE_BLENDFACTOR_INVERT_BIT;
return pipe;
}
static void static void
panvk_lower_blend(struct panfrost_device *pdev, nir_shader *nir, panvk_lower_blend(struct panfrost_device *pdev, nir_shader *nir,
struct panfrost_compile_inputs *inputs, struct panfrost_compile_inputs *inputs,
@ -214,36 +153,22 @@ panvk_lower_blend(struct panfrost_device *pdev, nir_shader *nir,
options.rt[rt].rgb = replace; options.rt[rt].rgb = replace;
options.rt[rt].alpha = replace; options.rt[rt].alpha = replace;
} else { } else {
options.rt[rt].rgb.func = options.rt[rt].rgb.func = rt_state->equation.rgb_func;
to_pipe_blend_func(rt_state->equation.rgb_func); options.rt[rt].rgb.src_factor = rt_state->equation.rgb_src_factor;
options.rt[rt].rgb.src_factor = options.rt[rt].rgb.dst_factor = rt_state->equation.rgb_dst_factor;
to_pipe_blendfactor(rt_state->equation.rgb_src_factor, options.rt[rt].alpha.func = rt_state->equation.alpha_func;
rt_state->equation.rgb_invert_src_factor); options.rt[rt].alpha.src_factor = rt_state->equation.alpha_src_factor;
options.rt[rt].rgb.dst_factor = options.rt[rt].alpha.dst_factor = rt_state->equation.alpha_dst_factor;
to_pipe_blendfactor(rt_state->equation.rgb_dst_factor,
rt_state->equation.rgb_invert_dst_factor);
options.rt[rt].alpha.func =
to_pipe_blend_func(rt_state->equation.alpha_func);
options.rt[rt].alpha.src_factor =
to_pipe_blendfactor(rt_state->equation.alpha_src_factor,
rt_state->equation.alpha_invert_src_factor);
options.rt[rt].alpha.dst_factor =
to_pipe_blendfactor(rt_state->equation.alpha_dst_factor,
rt_state->equation.alpha_invert_dst_factor);
} }
/* Update the equation to force a color replacement */ /* Update the equation to force a color replacement */
rt_state->equation.color_mask = 0xf; rt_state->equation.color_mask = 0xf;
rt_state->equation.rgb_func = BLEND_FUNC_ADD; rt_state->equation.rgb_func = PIPE_BLEND_ADD;
rt_state->equation.rgb_src_factor = BLEND_FACTOR_ZERO; rt_state->equation.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
rt_state->equation.rgb_invert_src_factor = true; rt_state->equation.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
rt_state->equation.rgb_dst_factor = BLEND_FACTOR_ZERO; rt_state->equation.alpha_func = PIPE_BLEND_ADD;
rt_state->equation.rgb_invert_dst_factor = false; rt_state->equation.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
rt_state->equation.alpha_func = BLEND_FUNC_ADD; rt_state->equation.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
rt_state->equation.alpha_src_factor = BLEND_FACTOR_ZERO;
rt_state->equation.alpha_invert_src_factor = true;
rt_state->equation.alpha_dst_factor = BLEND_FACTOR_ZERO;
rt_state->equation.alpha_invert_dst_factor = false;
lower_blend = true; lower_blend = true;
} }