#include "util/format/u_format.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
/* Fixed function blending */
static bool
-factor_is_supported(enum blend_factor factor)
+factor_is_supported(enum pipe_blendfactor factor)
{
- return factor != BLEND_FACTOR_SRC_ALPHA_SATURATE &&
- factor != BLEND_FACTOR_SRC1_COLOR &&
- factor != BLEND_FACTOR_SRC1_ALPHA;
+ factor = util_blendfactor_without_invert(factor);
+
+ 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
* + dest * (2*src) wih the new source_2 value of C. Detect this case. */
static bool
-is_2srcdest(enum blend_func blend_func, enum blend_factor src_factor,
- bool invert_src, enum blend_factor dest_factor, bool invert_dest,
- bool is_alpha)
+is_2srcdest(enum pipe_blend_func blend_func, enum pipe_blendfactor src_factor,
+ enum pipe_blendfactor dest_factor, bool is_alpha)
{
- return (blend_func == BLEND_FUNC_ADD) &&
- ((src_factor == BLEND_FACTOR_DST_COLOR) ||
- ((src_factor == BLEND_FACTOR_DST_ALPHA) && is_alpha)) &&
- ((dest_factor == BLEND_FACTOR_SRC_COLOR) ||
- ((dest_factor == BLEND_FACTOR_SRC_ALPHA) && is_alpha)) &&
- !invert_src && !invert_dest;
+ return (blend_func == PIPE_BLEND_ADD) &&
+ ((src_factor == PIPE_BLENDFACTOR_DST_COLOR) ||
+ ((src_factor == PIPE_BLENDFACTOR_DST_ALPHA) && is_alpha)) &&
+ ((dest_factor == PIPE_BLENDFACTOR_SRC_COLOR) ||
+ ((dest_factor == PIPE_BLENDFACTOR_SRC_ALPHA) && is_alpha));
}
static bool
-can_fixed_function_equation(enum blend_func blend_func,
- enum blend_factor src_factor, bool invert_src,
- enum blend_factor dest_factor, bool invert_dest,
- bool is_alpha, bool supports_2src)
+can_fixed_function_equation(enum pipe_blend_func blend_func,
+ enum pipe_blendfactor src_factor,
+ enum pipe_blendfactor dest_factor, bool is_alpha,
+ bool supports_2src)
{
- if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor, invert_dest,
- is_alpha)) {
-
+ if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha))
return supports_2src;
- }
- if (blend_func != BLEND_FUNC_ADD && blend_func != BLEND_FUNC_SUBTRACT &&
- blend_func != BLEND_FUNC_REVERSE_SUBTRACT)
+ if (blend_func != PIPE_BLEND_ADD && blend_func != PIPE_BLEND_SUBTRACT &&
+ blend_func != PIPE_BLEND_REVERSE_SUBTRACT)
return false;
if (!factor_is_supported(src_factor) || !factor_is_supported(dest_factor))
return false;
- if (src_factor != dest_factor && src_factor != BLEND_FACTOR_ZERO &&
- dest_factor != BLEND_FACTOR_ZERO)
- return false;
+ /* Fixed function requires src/dest factors to match (up to invert) or be
+ * zero/one.
+ */
+ 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
-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 */
- else if (factor == BLEND_FACTOR_CONSTANT_ALPHA)
+ else if (factor == PIPE_BLENDFACTOR_CONST_ALPHA)
return 0b1000; /* A */
else
return 0b0000; /* - */
return !equation.blend_enable ||
(can_fixed_function_equation(
equation.rgb_func, equation.rgb_src_factor,
- equation.rgb_invert_src_factor, equation.rgb_dst_factor,
- equation.rgb_invert_dst_factor, false, supports_2src) &&
+ equation.rgb_dst_factor, false, supports_2src) &&
can_fixed_function_equation(
equation.alpha_func, equation.alpha_src_factor,
- equation.alpha_invert_src_factor, equation.alpha_dst_factor,
- equation.alpha_invert_dst_factor, true, supports_2src));
+ equation.alpha_dst_factor, true, supports_2src));
}
static enum mali_blend_operand_c
-to_c_factor(enum blend_factor factor)
+to_c_factor(enum pipe_blendfactor factor)
{
- switch (factor) {
- case BLEND_FACTOR_ZERO:
+ switch (util_blendfactor_without_invert(factor)) {
+ case PIPE_BLENDFACTOR_ONE:
+ /* Extra invert to flip back in caller */
return MALI_BLEND_OPERAND_C_ZERO;
- case BLEND_FACTOR_SRC_ALPHA:
+ case PIPE_BLENDFACTOR_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;
- case BLEND_FACTOR_SRC_COLOR:
+ case PIPE_BLENDFACTOR_SRC_COLOR:
return MALI_BLEND_OPERAND_C_SRC;
- case BLEND_FACTOR_DST_COLOR:
+ case PIPE_BLENDFACTOR_DST_COLOR:
return MALI_BLEND_OPERAND_C_DEST;
- case BLEND_FACTOR_CONSTANT_COLOR:
- case BLEND_FACTOR_CONSTANT_ALPHA:
+ case PIPE_BLENDFACTOR_CONST_COLOR:
+ case PIPE_BLENDFACTOR_CONST_ALPHA:
return MALI_BLEND_OPERAND_C_CONSTANT;
default:
}
static void
-to_panfrost_function(enum blend_func blend_func, enum blend_factor src_factor,
- bool invert_src, enum blend_factor dest_factor,
- bool invert_dest, bool is_alpha,
+to_panfrost_function(enum pipe_blend_func blend_func,
+ enum pipe_blendfactor src_factor,
+ enum pipe_blendfactor dest_factor, bool is_alpha,
struct MALI_BLEND_FUNCTION *function)
{
- assert(can_fixed_function_equation(blend_func, src_factor, invert_src,
- dest_factor, invert_dest, is_alpha,
- true));
+ assert(can_fixed_function_equation(blend_func, src_factor, dest_factor,
+ is_alpha, true));
+
+ /* 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 == BLEND_FACTOR_ZERO && !invert_src) {
+ if (src_factor == PIPE_BLENDFACTOR_ZERO) {
function->a = MALI_BLEND_OPERAND_A_ZERO;
function->b = MALI_BLEND_OPERAND_B_DEST;
- if (blend_func == BLEND_FUNC_SUBTRACT)
+ if (blend_func == PIPE_BLEND_SUBTRACT)
function->negate_b = true;
- function->invert_c = invert_dest;
+ function->invert_c = dest_inverted;
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->b = MALI_BLEND_OPERAND_B_DEST;
- if (blend_func == BLEND_FUNC_SUBTRACT)
+ if (blend_func == PIPE_BLEND_SUBTRACT)
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->invert_c = invert_dest;
+ function->invert_c = dest_inverted;
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->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->invert_c = invert_src;
+ function->invert_c = src_inverted;
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->b = MALI_BLEND_OPERAND_B_SRC;
- if (blend_func == BLEND_FUNC_SUBTRACT)
+ if (blend_func == PIPE_BLEND_SUBTRACT)
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->invert_c = invert_src;
+ function->invert_c = src_inverted;
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->invert_c = invert_src;
+ function->invert_c = src_inverted;
function->c = to_c_factor(src_factor);
switch (blend_func) {
- case BLEND_FUNC_ADD:
+ case PIPE_BLEND_ADD:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
break;
- case BLEND_FUNC_REVERSE_SUBTRACT:
+ case PIPE_BLEND_REVERSE_SUBTRACT:
function->negate_b = true;
FALLTHROUGH;
- case BLEND_FUNC_SUBTRACT:
+ case PIPE_BLEND_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
break;
default:
unreachable("Invalid blend function");
}
- } else if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor,
- invert_dest, is_alpha)) {
+ } else if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha)) {
/* src*dest + dest*src = 2*src*dest = 0 + dest*(2*src) */
function->a = MALI_BLEND_OPERAND_A_ZERO;
function->b = MALI_BLEND_OPERAND_B_DEST;
function->c = MALI_BLEND_OPERAND_C_SRC_X_2;
} 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->invert_c = invert_src;
+ function->invert_c = src_inverted;
function->c = to_c_factor(src_factor);
switch (blend_func) {
- case BLEND_FUNC_ADD:
+ case PIPE_BLEND_ADD:
function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
break;
- case BLEND_FUNC_REVERSE_SUBTRACT:
+ case PIPE_BLEND_REVERSE_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
function->negate_b = true;
break;
- case BLEND_FUNC_SUBTRACT:
+ case PIPE_BLEND_SUBTRACT:
function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
function->negate_a = true;
break;
return true;
/* Also detect open-coded opaque blending */
- return equation.rgb_src_factor == BLEND_FACTOR_ZERO &&
- equation.rgb_invert_src_factor &&
- equation.rgb_dst_factor == BLEND_FACTOR_ZERO &&
- !equation.rgb_invert_dst_factor &&
- (equation.rgb_func == BLEND_FUNC_ADD ||
- equation.rgb_func == BLEND_FUNC_SUBTRACT) &&
- equation.alpha_src_factor == BLEND_FACTOR_ZERO &&
- equation.alpha_invert_src_factor &&
- 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
- * src_alpha is the given constant.
+ return equation.rgb_src_factor == PIPE_BLENDFACTOR_ONE &&
+ equation.rgb_dst_factor == PIPE_BLENDFACTOR_ZERO &&
+ (equation.rgb_func == PIPE_BLEND_ADD ||
+ equation.rgb_func == PIPE_BLEND_SUBTRACT) &&
+ equation.alpha_src_factor == PIPE_BLENDFACTOR_ONE &&
+ equation.alpha_dst_factor == PIPE_BLENDFACTOR_ZERO &&
+ (equation.alpha_func == PIPE_BLEND_ADD ||
+ equation.alpha_func == PIPE_BLEND_SUBTRACT);
+}
+
+/* Check if a factor represents a constant value of val, assuming src_alpha is
+ * the given constant.
*/
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(srca == 0 || srca == 1);
- return ((invert ^ !val) && factor == BLEND_FACTOR_ZERO) ||
- ((invert ^ srca ^ !val) && factor == BLEND_FACTOR_SRC_ALPHA);
+ switch (factor) {
+ 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
bool
pan_blend_alpha_zero_nop(const struct pan_blend_equation eq)
{
- if (eq.rgb_func != BLEND_FUNC_ADD &&
- eq.rgb_func != BLEND_FUNC_REVERSE_SUBTRACT)
+ if (eq.rgb_func != PIPE_BLEND_ADD &&
+ eq.rgb_func != PIPE_BLEND_REVERSE_SUBTRACT)
return false;
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;
}
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;
- 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;
}
bool
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;
if (eq.color_mask != 0xf)
return false;
- return is_factor_01(eq.rgb_src_factor, eq.rgb_invert_src_factor, 1, 1) &&
- is_factor_01(eq.alpha_src_factor, eq.alpha_invert_src_factor, 1, 1) &&
- is_factor_01(eq.rgb_dst_factor, eq.rgb_invert_dst_factor, 0, 1) &&
- is_factor_01(eq.alpha_dst_factor, eq.alpha_invert_dst_factor, 0, 1);
+ return is_factor_01(eq.rgb_src_factor, 1, 1) &&
+ is_factor_01(eq.alpha_src_factor, 1, 1) &&
+ is_factor_01(eq.rgb_dst_factor, 0, 1) &&
+ is_factor_01(eq.alpha_dst_factor, 0, 1);
}
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 == BLEND_FACTOR_DST_COLOR ||
- (factor == BLEND_FACTOR_SRC_ALPHA_SATURATE && !alpha);
+ factor = util_blendfactor_without_invert(factor);
+
+ 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
bool
pan_blend_reads_dest(const struct pan_blend_equation equation)
{
- return (equation.color_mask && equation.color_mask != 0xF) ||
- is_dest_factor(equation.rgb_src_factor, false) ||
+ if (equation.color_mask && equation.color_mask != 0xF)
+ 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) ||
- equation.rgb_dst_factor != BLEND_FACTOR_ZERO ||
- equation.rgb_invert_dst_factor ||
- equation.alpha_dst_factor != BLEND_FACTOR_ZERO ||
- equation.alpha_invert_dst_factor;
+ equation.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
+ equation.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO;
}
/* Create the descriptor for a fixed blend mode given the corresponding API
/* Compile the fixed-function blend */
to_panfrost_function(equation.rgb_func, equation.rgb_src_factor,
- equation.rgb_invert_src_factor, equation.rgb_dst_factor,
- equation.rgb_invert_dst_factor, false, &out->rgb);
-
+ equation.rgb_dst_factor, false, &out->rgb);
to_panfrost_function(equation.alpha_func, equation.alpha_src_factor,
- equation.alpha_invert_src_factor,
- equation.alpha_dst_factor,
- equation.alpha_invert_dst_factor, true, &out->alpha);
+ equation.alpha_dst_factor, true, &out->alpha);
+
out->color_mask = equation.color_mask;
}
"add", "sub", "reverse_sub", "min", "max",
};
const char *factors[] = {
- "zero", "src_color", "src1_color", "dst_color", "src_alpha",
- "src1_alpha", "dst_alpha", "const_color", "const_alpha", "src_alpha_sat",
+ "one", "src_color", "src_alpha", "dst_alpha", "dst_color",
+ "src_alpha_sat", "const_color", "const_alpha", "src1_color", "src1_alpha",
};
int ret;
if (rt_state->equation.color_mask & 7) {
assert(rt_state->equation.rgb_func < ARRAY_SIZE(funcs));
- assert(rt_state->equation.rgb_src_factor < ARRAY_SIZE(factors));
- assert(rt_state->equation.rgb_dst_factor < ARRAY_SIZE(factors));
- 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 & 2) ? "G" : "",
- (rt_state->equation.color_mask & 4) ? "B" : "",
- funcs[rt_state->equation.rgb_func],
- rt_state->equation.rgb_invert_src_factor ? "-" : "",
- factors[rt_state->equation.rgb_src_factor],
- rt_state->equation.rgb_invert_dst_factor ? "-" : "",
- factors[rt_state->equation.rgb_dst_factor],
- rt_state->equation.color_mask & 8 ? ";" : "");
+ 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 & 2) ? "G" : "",
+ (rt_state->equation.color_mask & 4) ? "B" : "",
+ funcs[rt_state->equation.rgb_func],
+ util_blendfactor_is_inverted(rt_state->equation.rgb_src_factor) ? "-"
+ : "",
+ factors[util_blendfactor_without_invert(
+ 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 ? ";" : "");
assert(ret > 0);
str += ret;
len -= ret;
if (rt_state->equation.color_mask & 8) {
assert(rt_state->equation.alpha_func < ARRAY_SIZE(funcs));
- assert(rt_state->equation.alpha_src_factor < ARRAY_SIZE(factors));
- assert(rt_state->equation.alpha_dst_factor < ARRAY_SIZE(factors));
- ret = snprintf(str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
- funcs[rt_state->equation.alpha_func],
- rt_state->equation.alpha_invert_src_factor ? "-" : "",
- factors[rt_state->equation.alpha_src_factor],
- rt_state->equation.alpha_invert_dst_factor ? "-" : "",
- factors[rt_state->equation.alpha_dst_factor]);
+ ret = snprintf(
+ str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
+ funcs[rt_state->equation.alpha_func],
+ util_blendfactor_is_inverted(rt_state->equation.alpha_src_factor) ? "-"
+ : "",
+ factors[util_blendfactor_without_invert(
+ 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);
str += ret;
len -= ret;
options.rt[rt].rgb = replace;
options.rt[rt].alpha = replace;
} else {
- options.rt[rt].rgb.func = to_pipe_blend_func(rt_state->equation.rgb_func);
- options.rt[rt].rgb.src_factor =
- to_pipe_blendfactor(rt_state->equation.rgb_src_factor,
- rt_state->equation.rgb_invert_src_factor);
- options.rt[rt].rgb.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);
+ options.rt[rt].rgb.func = rt_state->equation.rgb_func;
+ options.rt[rt].rgb.src_factor = rt_state->equation.rgb_src_factor;
+ options.rt[rt].rgb.dst_factor = rt_state->equation.rgb_dst_factor;
+ options.rt[rt].alpha.func = rt_state->equation.alpha_func;
+ options.rt[rt].alpha.src_factor = rt_state->equation.alpha_src_factor;
+ options.rt[rt].alpha.dst_factor = rt_state->equation.alpha_dst_factor;
}
nir_ssa_def *pixel = nir_load_barycentric_pixel(&b, 32, .interp_mode = 1);
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
- RGBA(dst_factor, BLEND_FACTOR_SRC_ALPHA),
- RGBA(invert_dst_factor, true),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_INV_SRC_ALPHA),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_ZERO),
- RGBA(dst_factor, BLEND_FACTOR_ZERO),
- RGBA(invert_src_factor, true),
- RGBA(invert_dst_factor, true),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
- RGBA(dst_factor, BLEND_FACTOR_ZERO),
- RGBA(invert_dst_factor, true),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_SUBTRACT),
- RGBA(src_factor, BLEND_FACTOR_ZERO),
- RGBA(dst_factor, BLEND_FACTOR_ZERO),
- RGBA(invert_src_factor, true),
- RGBA(invert_dst_factor, true),
+ RGBA(func, PIPE_BLEND_SUBTRACT),
+ RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_SUBTRACT),
- RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
- RGBA(dst_factor, BLEND_FACTOR_ZERO),
- RGBA(invert_dst_factor, true),
+ RGBA(func, PIPE_BLEND_SUBTRACT),
+ RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_ZERO),
- RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xA,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_ZERO),
- RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xF,
- RGBA(func, BLEND_FUNC_ADD),
- RGBA(src_factor, BLEND_FACTOR_DST_COLOR),
- RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+ RGBA(func, PIPE_BLEND_ADD),
+ RGBA(src_factor, PIPE_BLENDFACTOR_DST_COLOR),
+ RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xC,
- .rgb_func = BLEND_FUNC_ADD,
- .rgb_src_factor = BLEND_FACTOR_ZERO,
- .rgb_invert_src_factor = true,
- .rgb_dst_factor= BLEND_FACTOR_ZERO,
+ .rgb_func = PIPE_BLEND_ADD,
+ .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+ .rgb_dst_factor= PIPE_BLENDFACTOR_ZERO,
- .alpha_func = BLEND_FUNC_ADD,
- .alpha_src_factor = BLEND_FACTOR_DST_COLOR,
- .alpha_dst_factor= BLEND_FACTOR_SRC_COLOR,
+ .alpha_func = PIPE_BLEND_ADD,
+ .alpha_src_factor = PIPE_BLENDFACTOR_DST_COLOR,
+ .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xC,
- .rgb_func = BLEND_FUNC_ADD,
- .rgb_src_factor = BLEND_FACTOR_ZERO,
- .rgb_invert_src_factor = true,
- .rgb_dst_factor= BLEND_FACTOR_ZERO,
+ .rgb_func = PIPE_BLEND_ADD,
+ .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+ .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
- .alpha_func = BLEND_FUNC_ADD,
- .alpha_src_factor = BLEND_FACTOR_DST_ALPHA,
- .alpha_dst_factor= BLEND_FACTOR_SRC_COLOR,
+ .alpha_func = PIPE_BLEND_ADD,
+ .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
+ .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
},
.constant_mask = 0x0,
.reads_dest = true,
.blend_enable = true,
.color_mask = 0xC,
- .rgb_func = BLEND_FUNC_ADD,
- .rgb_src_factor = BLEND_FACTOR_ZERO,
- .rgb_invert_src_factor = true,
- .rgb_dst_factor= BLEND_FACTOR_ZERO,
+ .rgb_func = PIPE_BLEND_ADD,
+ .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+ .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
- .alpha_func = BLEND_FUNC_ADD,
- .alpha_src_factor = BLEND_FACTOR_DST_ALPHA,
- .alpha_dst_factor= BLEND_FACTOR_SRC_ALPHA,
+ .alpha_func = PIPE_BLEND_ADD,
+ .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
+ .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_ALPHA,
},
.constant_mask = 0x0,
.reads_dest = true,
#include "nir/nir.h"
#include "nir/nir_builder.h"
#include "spirv/nir_spirv.h"
+#include "util/blend.h"
#include "util/mesa-sha1.h"
#include "util/u_atomic.h"
#include "util/u_debug.h"
+#include "vk_blend.h"
#include "vk_format.h"
#include "vk_util.h"
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
panvk_per_arch(blend_needs_lowering)(const struct panfrost_device *dev,
const struct pan_blend_state *state,
pipeline->blend.state.logicop_enable =
builder->create_info.gfx->pColorBlendState->logicOpEnable;
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 =
util_last_bit(builder->active_color_attachments);
memcpy(pipeline->blend.state.constants,
builder->create_info.gfx->pMultisampleState->rasterizationSamples;
out->equation.blend_enable = in->blendEnable;
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 =
- translate_blend_factor(in->srcColorBlendFactor, dest_has_alpha);
- out->equation.rgb_invert_src_factor =
- inverted_blend_factor(in->srcColorBlendFactor, dest_has_alpha);
+ vk_blend_factor_to_pipe(in->srcColorBlendFactor);
out->equation.rgb_dst_factor =
- translate_blend_factor(in->dstColorBlendFactor, dest_has_alpha);
- out->equation.rgb_invert_dst_factor =
- inverted_blend_factor(in->dstColorBlendFactor, dest_has_alpha);
- out->equation.alpha_func = translate_blend_op(in->alphaBlendOp);
+ vk_blend_factor_to_pipe(in->dstColorBlendFactor);
+ out->equation.alpha_func = vk_blend_op_to_pipe(in->alphaBlendOp);
out->equation.alpha_src_factor =
- translate_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha);
- out->equation.alpha_invert_src_factor =
- inverted_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha);
+ vk_blend_factor_to_pipe(in->srcAlphaBlendFactor);
out->equation.alpha_dst_factor =
- translate_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha);
- out->equation.alpha_invert_dst_factor =
- inverted_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha);
+ vk_blend_factor_to_pipe(in->dstAlphaBlendFactor);
+
+ 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);