xref: /aosp_15_r20/external/mesa3d/src/gallium/auxiliary/util/u_blend.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 #ifndef U_BLEND_H
2 #define U_BLEND_H
3 
4 #include "pipe/p_state.h"
5 #include "compiler/shader_enums.h"
6 
7 static inline bool
util_blend_factor_uses_dest(enum pipe_blendfactor factor,bool alpha)8 util_blend_factor_uses_dest(enum pipe_blendfactor factor, bool alpha)
9 {
10    switch (factor) {
11       case PIPE_BLENDFACTOR_DST_ALPHA:
12       case PIPE_BLENDFACTOR_DST_COLOR:
13       case PIPE_BLENDFACTOR_INV_DST_ALPHA:
14       case PIPE_BLENDFACTOR_INV_DST_COLOR:
15          return true;
16       case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
17          return !alpha;
18       default:
19          return false;
20    }
21 }
22 
23 static inline bool
util_blend_uses_dest(struct pipe_rt_blend_state rt)24 util_blend_uses_dest(struct pipe_rt_blend_state rt)
25 {
26    return rt.blend_enable &&
27       (util_blend_factor_uses_dest((enum pipe_blendfactor)rt.rgb_src_factor, false) ||
28        util_blend_factor_uses_dest((enum pipe_blendfactor)rt.alpha_src_factor, true) ||
29        rt.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
30        rt.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO);
31 }
32 
33 #endif /* U_BLEND_H */
34