Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a2xx/fd2_blend.c
4574 views
/*1* Copyright (C) 2012-2013 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#include "pipe/p_state.h"27#include "util/u_blend.h"28#include "util/u_memory.h"29#include "util/u_string.h"3031#include "fd2_blend.h"32#include "fd2_context.h"33#include "fd2_util.h"3435static enum a2xx_rb_blend_opcode36blend_func(unsigned func)37{38switch (func) {39case PIPE_BLEND_ADD:40return BLEND2_DST_PLUS_SRC;41case PIPE_BLEND_MIN:42return BLEND2_MIN_DST_SRC;43case PIPE_BLEND_MAX:44return BLEND2_MAX_DST_SRC;45case PIPE_BLEND_SUBTRACT:46return BLEND2_SRC_MINUS_DST;47case PIPE_BLEND_REVERSE_SUBTRACT:48return BLEND2_DST_MINUS_SRC;49default:50DBG("invalid blend func: %x", func);51return 0;52}53}5455void *56fd2_blend_state_create(struct pipe_context *pctx,57const struct pipe_blend_state *cso)58{59const struct pipe_rt_blend_state *rt = &cso->rt[0];60struct fd2_blend_stateobj *so;61unsigned rop = PIPE_LOGICOP_COPY;6263if (cso->logicop_enable)64rop = cso->logicop_func; /* 1:1 mapping with hw */6566if (cso->independent_blend_enable) {67DBG("Unsupported! independent blend state");68return NULL;69}7071so = CALLOC_STRUCT(fd2_blend_stateobj);72if (!so)73return NULL;7475so->base = *cso;7677so->rb_colorcontrol = A2XX_RB_COLORCONTROL_ROP_CODE(rop);7879so->rb_blendcontrol =80A2XX_RB_BLEND_CONTROL_COLOR_SRCBLEND(81fd_blend_factor(rt->rgb_src_factor)) |82A2XX_RB_BLEND_CONTROL_COLOR_COMB_FCN(blend_func(rt->rgb_func)) |83A2XX_RB_BLEND_CONTROL_COLOR_DESTBLEND(84fd_blend_factor(rt->rgb_dst_factor));8586/* hardware doesn't support SRC_ALPHA_SATURATE for alpha, but it is87* equivalent to ONE */88unsigned alpha_src_factor = rt->alpha_src_factor;89if (alpha_src_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE)90alpha_src_factor = PIPE_BLENDFACTOR_ONE;9192so->rb_blendcontrol |=93A2XX_RB_BLEND_CONTROL_ALPHA_SRCBLEND(fd_blend_factor(alpha_src_factor)) |94A2XX_RB_BLEND_CONTROL_ALPHA_COMB_FCN(blend_func(rt->alpha_func)) |95A2XX_RB_BLEND_CONTROL_ALPHA_DESTBLEND(96fd_blend_factor(rt->alpha_dst_factor));9798if (rt->colormask & PIPE_MASK_R)99so->rb_colormask |= A2XX_RB_COLOR_MASK_WRITE_RED;100if (rt->colormask & PIPE_MASK_G)101so->rb_colormask |= A2XX_RB_COLOR_MASK_WRITE_GREEN;102if (rt->colormask & PIPE_MASK_B)103so->rb_colormask |= A2XX_RB_COLOR_MASK_WRITE_BLUE;104if (rt->colormask & PIPE_MASK_A)105so->rb_colormask |= A2XX_RB_COLOR_MASK_WRITE_ALPHA;106107if (!rt->blend_enable)108so->rb_colorcontrol |= A2XX_RB_COLORCONTROL_BLEND_DISABLE;109110if (cso->dither)111so->rb_colorcontrol |= A2XX_RB_COLORCONTROL_DITHER_MODE(DITHER_ALWAYS);112113return so;114}115116117