Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a3xx/fd3_blend.c
4574 views
/*1* Copyright (C) 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_dual_blend.h"29#include "util/u_memory.h"30#include "util/u_string.h"3132#include "fd3_blend.h"33#include "fd3_context.h"34#include "fd3_format.h"3536static enum a3xx_rb_blend_opcode37blend_func(unsigned func)38{39switch (func) {40case PIPE_BLEND_ADD:41return BLEND_DST_PLUS_SRC;42case PIPE_BLEND_MIN:43return BLEND_MIN_DST_SRC;44case PIPE_BLEND_MAX:45return BLEND_MAX_DST_SRC;46case PIPE_BLEND_SUBTRACT:47return BLEND_SRC_MINUS_DST;48case PIPE_BLEND_REVERSE_SUBTRACT:49return BLEND_DST_MINUS_SRC;50default:51DBG("invalid blend func: %x", func);52return 0;53}54}5556void *57fd3_blend_state_create(struct pipe_context *pctx,58const struct pipe_blend_state *cso)59{60struct fd3_blend_stateobj *so;61enum a3xx_rop_code rop = ROP_COPY;62bool reads_dest = false;63int i;6465if (cso->logicop_enable) {66rop = cso->logicop_func; /* maps 1:1 */67reads_dest = util_logicop_reads_dest(cso->logicop_func);68}6970so = CALLOC_STRUCT(fd3_blend_stateobj);71if (!so)72return NULL;7374so->base = *cso;7576for (i = 0; i < ARRAY_SIZE(so->rb_mrt); i++) {77const struct pipe_rt_blend_state *rt;78if (cso->independent_blend_enable)79rt = &cso->rt[i];80else81rt = &cso->rt[0];8283so->rb_mrt[i].blend_control =84A3XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(85fd_blend_factor(rt->rgb_src_factor)) |86A3XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(blend_func(rt->rgb_func)) |87A3XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(88fd_blend_factor(rt->rgb_dst_factor)) |89A3XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(90fd_blend_factor(rt->alpha_src_factor)) |91A3XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(92blend_func(rt->alpha_func)) |93A3XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(94fd_blend_factor(rt->alpha_dst_factor));9596so->rb_mrt[i].control =97A3XX_RB_MRT_CONTROL_ROP_CODE(rop) |98A3XX_RB_MRT_CONTROL_COMPONENT_ENABLE(rt->colormask);99100if (rt->blend_enable)101so->rb_mrt[i].control |= A3XX_RB_MRT_CONTROL_READ_DEST_ENABLE |102A3XX_RB_MRT_CONTROL_BLEND |103A3XX_RB_MRT_CONTROL_BLEND2;104105if (reads_dest)106so->rb_mrt[i].control |= A3XX_RB_MRT_CONTROL_READ_DEST_ENABLE;107108if (cso->dither)109so->rb_mrt[i].control |=110A3XX_RB_MRT_CONTROL_DITHER_MODE(DITHER_ALWAYS);111}112113if (cso->rt[0].blend_enable && util_blend_state_is_dual(cso, 0))114so->rb_render_control = A3XX_RB_RENDER_CONTROL_DUAL_COLOR_IN_ENABLE;115116return so;117}118119120