Module: Mesa Branch: main Commit: 521d596d2718214b2c37c0bf0487fa38f7fe99aa URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=521d596d2718214b2c37c0bf0487fa38f7fe99aa
Author: Alyssa Rosenzweig <[email protected]> Date: Tue Jul 11 07:50:35 2023 -0400 util/blend: Add helpers for normalizing inverts To avoid duplicating piles of cases. Signed-off-by: Alyssa Rosenzweig <[email protected]> Reviewed-by: Marek Olšák <[email protected]> Reviewed-by: Italo Nicola <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24076> --- 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 <stdbool.h> + +#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,
