diff options
author | Alyssa Rosenzweig <[email protected]> | 2019-05-06 02:03:48 +0000 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2019-05-10 15:49:16 +0000 |
commit | 6b0472b18199aecba30052ad7d2936de943d0cfb (patch) | |
tree | 9c768327ececc6ec6163859d3936577a6d24acf3 /src/gallium | |
parent | f41be53a1706181be85a8ba41681e28b4780f6e1 (diff) |
gallium: Add helper to convert PIPE blending to shader_enum style
Complementing the new API-agnostic shader_enum blending style, we add
helpers to translate between the two forms. Ideally, we could just use
PIPE blending directly, but that makes Vulkan support challenging.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/util/u_blend.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_blend.h b/src/gallium/auxiliary/util/u_blend.h index 4f969778972..ed3f7589345 100644 --- a/src/gallium/auxiliary/util/u_blend.h +++ b/src/gallium/auxiliary/util/u_blend.h @@ -2,6 +2,7 @@ #define U_BLEND_H #include "pipe/p_state.h" +#include "compiler/shader_enums.h" /** * When faking RGBX render target formats with RGBA ones, the blender is still @@ -22,4 +23,95 @@ util_blend_dst_alpha_to_one(int factor) } } +/** To lower blending to software shaders, the Gallium blend mode has to + * be translated to something API-agnostic, as defined in shader_enums.h + * */ + +static inline enum blend_func +util_blend_func_to_shader(enum pipe_blend_func func) +{ + switch (func) { + case PIPE_BLEND_ADD: + return BLEND_FUNC_ADD; + case PIPE_BLEND_SUBTRACT: + return BLEND_FUNC_SUBTRACT; + case PIPE_BLEND_REVERSE_SUBTRACT: + return BLEND_FUNC_REVERSE_SUBTRACT; + case PIPE_BLEND_MIN: + return BLEND_FUNC_MIN; + case PIPE_BLEND_MAX: + return BLEND_FUNC_MAX; + default: + unreachable("Invalid blend function"); + } +} + +static inline enum blend_factor +util_blend_factor_to_shader(enum pipe_blendfactor factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ZERO: + case PIPE_BLENDFACTOR_ONE: + return BLEND_FACTOR_ZERO; + + case PIPE_BLENDFACTOR_SRC_COLOR: + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + return BLEND_FACTOR_SRC_COLOR; + + case PIPE_BLENDFACTOR_SRC_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + return BLEND_FACTOR_SRC_ALPHA; + + case PIPE_BLENDFACTOR_DST_ALPHA: + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + return BLEND_FACTOR_DST_ALPHA; + + case PIPE_BLENDFACTOR_DST_COLOR: + case PIPE_BLENDFACTOR_INV_DST_COLOR: + return BLEND_FACTOR_DST_COLOR; + + case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: + return BLEND_FACTOR_SRC_ALPHA_SATURATE; + + case PIPE_BLENDFACTOR_CONST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + return BLEND_FACTOR_CONSTANT_COLOR; + + case PIPE_BLENDFACTOR_CONST_ALPHA: + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + return BLEND_FACTOR_CONSTANT_ALPHA; + + case PIPE_BLENDFACTOR_SRC1_COLOR: + case PIPE_BLENDFACTOR_SRC1_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + /* unimplemented */ + assert(0); + return BLEND_FACTOR_ZERO; + + default: + unreachable("Invalid factor"); + } +} + +static inline bool +util_blend_factor_is_inverted(enum pipe_blendfactor factor) +{ + switch (factor) { + case PIPE_BLENDFACTOR_ONE: + case PIPE_BLENDFACTOR_INV_SRC_COLOR: + case PIPE_BLENDFACTOR_INV_SRC_ALPHA: + case PIPE_BLENDFACTOR_INV_DST_ALPHA: + case PIPE_BLENDFACTOR_INV_DST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_COLOR: + case PIPE_BLENDFACTOR_INV_CONST_ALPHA: + case PIPE_BLENDFACTOR_INV_SRC1_COLOR: + case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: + return true; + + default: + return false; + } +} + #endif /* U_BLEND_H */ |