Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a5xx/fd5_blend.c
4574 views
/*1* Copyright (C) 2016 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 "fd5_blend.h"32#include "fd5_context.h"33#include "fd5_format.h"3435// XXX move somewhere common.. same across a3xx/a4xx/a5xx..36static 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 *57fd5_blend_state_create(struct pipe_context *pctx,58const struct pipe_blend_state *cso)59{60struct fd5_blend_stateobj *so;61enum a3xx_rop_code rop = ROP_COPY;62bool reads_dest = false;63unsigned i, mrt_blend = 0;6465if (cso->logicop_enable) {66rop = cso->logicop_func; /* maps 1:1 */67reads_dest = util_logicop_reads_dest(cso->logicop_func);68}6970so = CALLOC_STRUCT(fd5_blend_stateobj);71if (!so)72return NULL;7374so->base = *cso;7576so->lrz_write = true; /* unless blend enabled for any MRT */7778for (i = 0; i < ARRAY_SIZE(so->rb_mrt); i++) {79const struct pipe_rt_blend_state *rt;8081if (cso->independent_blend_enable)82rt = &cso->rt[i];83else84rt = &cso->rt[0];8586so->rb_mrt[i].blend_control =87A5XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(88fd_blend_factor(rt->rgb_src_factor)) |89A5XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(blend_func(rt->rgb_func)) |90A5XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(91fd_blend_factor(rt->rgb_dst_factor)) |92A5XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(93fd_blend_factor(rt->alpha_src_factor)) |94A5XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(95blend_func(rt->alpha_func)) |96A5XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(97fd_blend_factor(rt->alpha_dst_factor));9899so->rb_mrt[i].control =100A5XX_RB_MRT_CONTROL_ROP_CODE(rop) |101COND(cso->logicop_enable, A5XX_RB_MRT_CONTROL_ROP_ENABLE) |102A5XX_RB_MRT_CONTROL_COMPONENT_ENABLE(rt->colormask);103104if (rt->blend_enable) {105so->rb_mrt[i].control |=106// A5XX_RB_MRT_CONTROL_READ_DEST_ENABLE |107A5XX_RB_MRT_CONTROL_BLEND | A5XX_RB_MRT_CONTROL_BLEND2;108mrt_blend |= (1 << i);109so->lrz_write = false;110}111112if (reads_dest) {113// so->rb_mrt[i].control |=114// A5XX_RB_MRT_CONTROL_READ_DEST_ENABLE;115mrt_blend |= (1 << i);116}117118// if (cso->dither)119// so->rb_mrt[i].buf_info |=120// A5XX_RB_MRT_BUF_INFO_DITHER_MODE(DITHER_ALWAYS);121}122123so->rb_blend_cntl =124A5XX_RB_BLEND_CNTL_ENABLE_BLEND(mrt_blend) |125COND(cso->alpha_to_coverage, A5XX_RB_BLEND_CNTL_ALPHA_TO_COVERAGE) |126COND(cso->independent_blend_enable, A5XX_RB_BLEND_CNTL_INDEPENDENT_BLEND);127so->sp_blend_cntl =128A5XX_SP_BLEND_CNTL_ENABLE_BLEND(mrt_blend) |129A5XX_SP_BLEND_CNTL_UNK8 |130COND(cso->alpha_to_coverage, A5XX_SP_BLEND_CNTL_ALPHA_TO_COVERAGE);131132return so;133}134135136