1 /*
2 * Copyright 2023 Valve Corporation
3 * Copyright 2007 VMware, Inc.
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef UTIL_BLEND_H
8 #define UTIL_BLEND_H
9
10 #include <stdbool.h>
11
12 #define PIPE_BLENDFACTOR_INVERT_BIT (0x10)
13
14 enum pipe_blendfactor {
15 PIPE_BLENDFACTOR_ONE = 1,
16 PIPE_BLENDFACTOR_SRC_COLOR,
17 PIPE_BLENDFACTOR_SRC_ALPHA,
18 PIPE_BLENDFACTOR_DST_ALPHA,
19 PIPE_BLENDFACTOR_DST_COLOR,
20 PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE,
21 PIPE_BLENDFACTOR_CONST_COLOR,
22 PIPE_BLENDFACTOR_CONST_ALPHA,
23 PIPE_BLENDFACTOR_SRC1_COLOR,
24 PIPE_BLENDFACTOR_SRC1_ALPHA,
25
26 PIPE_BLENDFACTOR_ZERO = PIPE_BLENDFACTOR_INVERT_BIT | PIPE_BLENDFACTOR_ONE,
27 PIPE_BLENDFACTOR_INV_SRC_COLOR,
28 PIPE_BLENDFACTOR_INV_SRC_ALPHA,
29 PIPE_BLENDFACTOR_INV_DST_ALPHA,
30 PIPE_BLENDFACTOR_INV_DST_COLOR,
31
32 /* Intentionally weird wrapping due to Gallium trace parsing this file */
33 PIPE_BLENDFACTOR_INV_CONST_COLOR = PIPE_BLENDFACTOR_INVERT_BIT
34 | PIPE_BLENDFACTOR_CONST_COLOR,
35 PIPE_BLENDFACTOR_INV_CONST_ALPHA,
36 PIPE_BLENDFACTOR_INV_SRC1_COLOR,
37 PIPE_BLENDFACTOR_INV_SRC1_ALPHA,
38 };
39
40 static inline bool
util_blendfactor_is_inverted(enum pipe_blendfactor factor)41 util_blendfactor_is_inverted(enum pipe_blendfactor factor)
42 {
43 /* By construction of the enum */
44 return (factor & PIPE_BLENDFACTOR_INVERT_BIT);
45 }
46
47 static inline enum pipe_blendfactor
util_blendfactor_without_invert(enum pipe_blendfactor factor)48 util_blendfactor_without_invert(enum pipe_blendfactor factor)
49 {
50 /* By construction of the enum */
51 return (enum pipe_blendfactor)(factor & ~PIPE_BLENDFACTOR_INVERT_BIT);
52 }
53
54 enum pipe_blend_func {
55 PIPE_BLEND_ADD,
56 PIPE_BLEND_SUBTRACT,
57 PIPE_BLEND_REVERSE_SUBTRACT,
58 PIPE_BLEND_MIN,
59 PIPE_BLEND_MAX,
60 };
61
62 enum pipe_logicop {
63 PIPE_LOGICOP_CLEAR,
64 PIPE_LOGICOP_NOR,
65 PIPE_LOGICOP_AND_INVERTED,
66 PIPE_LOGICOP_COPY_INVERTED,
67 PIPE_LOGICOP_AND_REVERSE,
68 PIPE_LOGICOP_INVERT,
69 PIPE_LOGICOP_XOR,
70 PIPE_LOGICOP_NAND,
71 PIPE_LOGICOP_AND,
72 PIPE_LOGICOP_EQUIV,
73 PIPE_LOGICOP_NOOP,
74 PIPE_LOGICOP_OR_INVERTED,
75 PIPE_LOGICOP_COPY,
76 PIPE_LOGICOP_OR_REVERSE,
77 PIPE_LOGICOP_OR,
78 PIPE_LOGICOP_SET,
79 };
80
81 /**
82 * When faking RGBX render target formats with RGBA ones, the blender is still
83 * supposed to treat the destination's alpha channel as 1 instead of the
84 * garbage that's there. Return a blend factor that will take that into
85 * account.
86 */
87 static inline enum pipe_blendfactor
util_blend_dst_alpha_to_one(enum pipe_blendfactor factor)88 util_blend_dst_alpha_to_one(enum pipe_blendfactor factor)
89 {
90 switch (factor) {
91 case PIPE_BLENDFACTOR_DST_ALPHA:
92 return PIPE_BLENDFACTOR_ONE;
93 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
94 return PIPE_BLENDFACTOR_ZERO;
95 default:
96 return factor;
97 }
98 }
99
100 #endif
101