Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_blend.h
4561 views
#ifndef U_BLEND_H1#define U_BLEND_H23#include "pipe/p_state.h"4#include "compiler/shader_enums.h"56/**7* When faking RGBX render target formats with RGBA ones, the blender is still8* supposed to treat the destination's alpha channel as 1 instead of the9* garbage that's there. Return a blend factor that will take that into10* account.11*/12static inline int13util_blend_dst_alpha_to_one(int factor)14{15switch (factor) {16case PIPE_BLENDFACTOR_DST_ALPHA:17return PIPE_BLENDFACTOR_ONE;18case PIPE_BLENDFACTOR_INV_DST_ALPHA:19return PIPE_BLENDFACTOR_ZERO;20default:21return factor;22}23}2425/** To lower blending to software shaders, the Gallium blend mode has to26* be translated to something API-agnostic, as defined in shader_enums.h27* */2829static inline enum blend_func30util_blend_func_to_shader(enum pipe_blend_func func)31{32switch (func) {33case PIPE_BLEND_ADD:34return BLEND_FUNC_ADD;35case PIPE_BLEND_SUBTRACT:36return BLEND_FUNC_SUBTRACT;37case PIPE_BLEND_REVERSE_SUBTRACT:38return BLEND_FUNC_REVERSE_SUBTRACT;39case PIPE_BLEND_MIN:40return BLEND_FUNC_MIN;41case PIPE_BLEND_MAX:42return BLEND_FUNC_MAX;43default:44unreachable("Invalid blend function");45}46}4748static inline enum blend_factor49util_blend_factor_to_shader(enum pipe_blendfactor factor)50{51switch (factor) {52case PIPE_BLENDFACTOR_ZERO:53case PIPE_BLENDFACTOR_ONE:54return BLEND_FACTOR_ZERO;5556case PIPE_BLENDFACTOR_SRC_COLOR:57case PIPE_BLENDFACTOR_INV_SRC_COLOR:58return BLEND_FACTOR_SRC_COLOR;5960case PIPE_BLENDFACTOR_SRC_ALPHA:61case PIPE_BLENDFACTOR_INV_SRC_ALPHA:62return BLEND_FACTOR_SRC_ALPHA;6364case PIPE_BLENDFACTOR_DST_ALPHA:65case PIPE_BLENDFACTOR_INV_DST_ALPHA:66return BLEND_FACTOR_DST_ALPHA;6768case PIPE_BLENDFACTOR_DST_COLOR:69case PIPE_BLENDFACTOR_INV_DST_COLOR:70return BLEND_FACTOR_DST_COLOR;7172case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:73return BLEND_FACTOR_SRC_ALPHA_SATURATE;7475case PIPE_BLENDFACTOR_CONST_COLOR:76case PIPE_BLENDFACTOR_INV_CONST_COLOR:77return BLEND_FACTOR_CONSTANT_COLOR;7879case PIPE_BLENDFACTOR_CONST_ALPHA:80case PIPE_BLENDFACTOR_INV_CONST_ALPHA:81return BLEND_FACTOR_CONSTANT_ALPHA;8283case PIPE_BLENDFACTOR_SRC1_COLOR:84case PIPE_BLENDFACTOR_INV_SRC1_COLOR:85return BLEND_FACTOR_SRC1_COLOR;8687case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:88case PIPE_BLENDFACTOR_SRC1_ALPHA:89return BLEND_FACTOR_SRC1_ALPHA;9091default:92unreachable("Invalid factor");93}94}9596static inline bool97util_blend_factor_is_inverted(enum pipe_blendfactor factor)98{99switch (factor) {100case PIPE_BLENDFACTOR_ONE:101case PIPE_BLENDFACTOR_INV_SRC_COLOR:102case PIPE_BLENDFACTOR_INV_SRC_ALPHA:103case PIPE_BLENDFACTOR_INV_DST_ALPHA:104case PIPE_BLENDFACTOR_INV_DST_COLOR:105case PIPE_BLENDFACTOR_INV_CONST_COLOR:106case PIPE_BLENDFACTOR_INV_CONST_ALPHA:107case PIPE_BLENDFACTOR_INV_SRC1_COLOR:108case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:109return true;110111default:112return false;113}114}115116/* To determine if the destination needs to be read while blending */117118static inline bool119util_blend_factor_uses_dest(enum pipe_blendfactor factor, bool alpha)120{121switch (factor) {122case PIPE_BLENDFACTOR_DST_ALPHA:123case PIPE_BLENDFACTOR_DST_COLOR:124case PIPE_BLENDFACTOR_INV_DST_ALPHA:125case PIPE_BLENDFACTOR_INV_DST_COLOR:126return true;127case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:128return !alpha;129default:130return false;131}132}133134static inline bool135util_blend_uses_dest(struct pipe_rt_blend_state rt)136{137return rt.blend_enable &&138(util_blend_factor_uses_dest(rt.rgb_src_factor, false) ||139util_blend_factor_uses_dest(rt.alpha_src_factor, true) ||140rt.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||141rt.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO);142}143144#endif /* U_BLEND_H */145146147