From 521d596d2718214b2c37c0bf0487fa38f7fe99aa Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 11 Jul 2023 07:50:35 -0400 Subject: [PATCH] util/blend: Add helpers for normalizing inverts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid duplicating piles of cases. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák Reviewed-by: Italo Nicola Part-of: --- src/util/blend.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/util/blend.h b/src/util/blend.h index d47d82df330..d95cadaffdf 100644 --- a/src/util/blend.h +++ b/src/util/blend.h @@ -7,6 +7,10 @@ #ifndef UTIL_BLEND_H #define UTIL_BLEND_H +#include + +#define PIPE_BLENDFACTOR_INVERT_BIT (0x10) + enum pipe_blendfactor { PIPE_BLENDFACTOR_ONE = 1, PIPE_BLENDFACTOR_SRC_COLOR, @@ -19,18 +23,34 @@ enum pipe_blendfactor { PIPE_BLENDFACTOR_SRC1_COLOR, PIPE_BLENDFACTOR_SRC1_ALPHA, - PIPE_BLENDFACTOR_ZERO = 0x11, + PIPE_BLENDFACTOR_ZERO = PIPE_BLENDFACTOR_INVERT_BIT | PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_INV_SRC_COLOR, PIPE_BLENDFACTOR_INV_SRC_ALPHA, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_INV_DST_COLOR, - PIPE_BLENDFACTOR_INV_CONST_COLOR = 0x17, + /* Intentionally weird wrapping due to Gallium trace parsing this file */ + PIPE_BLENDFACTOR_INV_CONST_COLOR = PIPE_BLENDFACTOR_INVERT_BIT + | PIPE_BLENDFACTOR_CONST_COLOR, PIPE_BLENDFACTOR_INV_CONST_ALPHA, PIPE_BLENDFACTOR_INV_SRC1_COLOR, PIPE_BLENDFACTOR_INV_SRC1_ALPHA, }; +static inline bool +util_blendfactor_is_inverted(enum pipe_blendfactor factor) +{ + /* By construction of the enum */ + return (factor & PIPE_BLENDFACTOR_INVERT_BIT); +} + +static inline enum pipe_blendfactor +util_blendfactor_without_invert(enum pipe_blendfactor factor) +{ + /* By construction of the enum */ + return (enum pipe_blendfactor)(factor & ~PIPE_BLENDFACTOR_INVERT_BIT); +} + enum pipe_blend_func { PIPE_BLEND_ADD, PIPE_BLEND_SUBTRACT,