4 #include "pipe/p_state.h"
5 #include "compiler/shader_enums.h"
8 * When faking RGBX render target formats with RGBA ones, the blender is still
9 * supposed to treat the destination's alpha channel as 1 instead of the
10 * garbage that's there. Return a blend factor that will take that into
14 util_blend_dst_alpha_to_one(int factor
)
17 case PIPE_BLENDFACTOR_DST_ALPHA
:
18 return PIPE_BLENDFACTOR_ONE
;
19 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
20 return PIPE_BLENDFACTOR_ZERO
;
26 /** To lower blending to software shaders, the Gallium blend mode has to
27 * be translated to something API-agnostic, as defined in shader_enums.h
30 static inline enum blend_func
31 util_blend_func_to_shader(enum pipe_blend_func func
)
35 return BLEND_FUNC_ADD
;
36 case PIPE_BLEND_SUBTRACT
:
37 return BLEND_FUNC_SUBTRACT
;
38 case PIPE_BLEND_REVERSE_SUBTRACT
:
39 return BLEND_FUNC_REVERSE_SUBTRACT
;
41 return BLEND_FUNC_MIN
;
43 return BLEND_FUNC_MAX
;
45 unreachable("Invalid blend function");
49 static inline enum blend_factor
50 util_blend_factor_to_shader(enum pipe_blendfactor factor
)
53 case PIPE_BLENDFACTOR_ZERO
:
54 case PIPE_BLENDFACTOR_ONE
:
55 return BLEND_FACTOR_ZERO
;
57 case PIPE_BLENDFACTOR_SRC_COLOR
:
58 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
59 return BLEND_FACTOR_SRC_COLOR
;
61 case PIPE_BLENDFACTOR_SRC_ALPHA
:
62 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
63 return BLEND_FACTOR_SRC_ALPHA
;
65 case PIPE_BLENDFACTOR_DST_ALPHA
:
66 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
67 return BLEND_FACTOR_DST_ALPHA
;
69 case PIPE_BLENDFACTOR_DST_COLOR
:
70 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
71 return BLEND_FACTOR_DST_COLOR
;
73 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
74 return BLEND_FACTOR_SRC_ALPHA_SATURATE
;
76 case PIPE_BLENDFACTOR_CONST_COLOR
:
77 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
78 return BLEND_FACTOR_CONSTANT_COLOR
;
80 case PIPE_BLENDFACTOR_CONST_ALPHA
:
81 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
82 return BLEND_FACTOR_CONSTANT_ALPHA
;
84 case PIPE_BLENDFACTOR_SRC1_COLOR
:
85 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
86 return BLEND_FACTOR_SRC1_COLOR
;
88 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
89 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
90 return BLEND_FACTOR_SRC1_ALPHA
;
93 unreachable("Invalid factor");
98 util_blend_factor_is_inverted(enum pipe_blendfactor factor
)
101 case PIPE_BLENDFACTOR_ONE
:
102 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
103 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
104 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
105 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
106 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
107 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
108 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
109 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
117 /* To determine if the destination needs to be read while blending */
120 util_blend_factor_uses_dest(enum pipe_blendfactor factor
, bool alpha
)
123 case PIPE_BLENDFACTOR_DST_ALPHA
:
124 case PIPE_BLENDFACTOR_DST_COLOR
:
125 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
126 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
128 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
136 util_blend_uses_dest(struct pipe_rt_blend_state rt
)
138 return rt
.blend_enable
&&
139 (util_blend_factor_uses_dest(rt
.rgb_src_factor
, false) ||
140 util_blend_factor_uses_dest(rt
.alpha_src_factor
, true) ||
141 rt
.rgb_dst_factor
!= PIPE_BLENDFACTOR_ZERO
||
142 rt
.alpha_dst_factor
!= PIPE_BLENDFACTOR_ZERO
);
145 #endif /* U_BLEND_H */