Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_blend.c
4574 views
/*1* Copyright (C) 2014 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 "fd4_blend.h"32#include "fd4_context.h"33#include "fd4_format.h"3435static enum a3xx_rb_blend_opcode36blend_func(unsigned func)37{38switch (func) {39case PIPE_BLEND_ADD:40return BLEND_DST_PLUS_SRC;41case PIPE_BLEND_MIN:42return BLEND_MIN_DST_SRC;43case PIPE_BLEND_MAX:44return BLEND_MAX_DST_SRC;45case PIPE_BLEND_SUBTRACT:46return BLEND_SRC_MINUS_DST;47case PIPE_BLEND_REVERSE_SUBTRACT:48return BLEND_DST_MINUS_SRC;49default:50DBG("invalid blend func: %x", func);51return 0;52}53}5455void *56fd4_blend_state_create(struct pipe_context *pctx,57const struct pipe_blend_state *cso)58{59struct fd4_blend_stateobj *so;60enum a3xx_rop_code rop = ROP_COPY;61bool reads_dest = false;62unsigned i, mrt_blend = 0;6364if (cso->logicop_enable) {65rop = cso->logicop_func; /* maps 1:1 */66reads_dest = util_logicop_reads_dest(cso->logicop_func);67}6869so = CALLOC_STRUCT(fd4_blend_stateobj);70if (!so)71return NULL;7273so->base = *cso;7475for (i = 0; i < ARRAY_SIZE(so->rb_mrt); i++) {76const struct pipe_rt_blend_state *rt;7778if (cso->independent_blend_enable)79rt = &cso->rt[i];80else81rt = &cso->rt[0];8283so->rb_mrt[i].blend_control =84A4XX_RB_MRT_BLEND_CONTROL_RGB_SRC_FACTOR(85fd_blend_factor(rt->rgb_src_factor)) |86A4XX_RB_MRT_BLEND_CONTROL_RGB_BLEND_OPCODE(blend_func(rt->rgb_func)) |87A4XX_RB_MRT_BLEND_CONTROL_RGB_DEST_FACTOR(88fd_blend_factor(rt->rgb_dst_factor)) |89A4XX_RB_MRT_BLEND_CONTROL_ALPHA_SRC_FACTOR(90fd_blend_factor(rt->alpha_src_factor)) |91A4XX_RB_MRT_BLEND_CONTROL_ALPHA_BLEND_OPCODE(92blend_func(rt->alpha_func)) |93A4XX_RB_MRT_BLEND_CONTROL_ALPHA_DEST_FACTOR(94fd_blend_factor(rt->alpha_dst_factor));9596so->rb_mrt[i].control =97A4XX_RB_MRT_CONTROL_ROP_CODE(rop) |98COND(cso->logicop_enable, A4XX_RB_MRT_CONTROL_ROP_ENABLE) |99A4XX_RB_MRT_CONTROL_COMPONENT_ENABLE(rt->colormask);100101if (rt->blend_enable) {102so->rb_mrt[i].control |= A4XX_RB_MRT_CONTROL_READ_DEST_ENABLE |103A4XX_RB_MRT_CONTROL_BLEND |104A4XX_RB_MRT_CONTROL_BLEND2;105mrt_blend |= (1 << i);106}107108if (reads_dest) {109so->rb_mrt[i].control |= A4XX_RB_MRT_CONTROL_READ_DEST_ENABLE;110mrt_blend |= (1 << i);111}112113if (cso->dither)114so->rb_mrt[i].buf_info |=115A4XX_RB_MRT_BUF_INFO_DITHER_MODE(DITHER_ALWAYS);116}117118so->rb_fs_output =119A4XX_RB_FS_OUTPUT_ENABLE_BLEND(mrt_blend) |120COND(cso->independent_blend_enable, A4XX_RB_FS_OUTPUT_INDEPENDENT_BLEND);121122return so;123}124125126