2 * Copyright (c) 2012-2015 Etnaviv Project
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Wladimir J. van der Laan <laanwj@gmail.com>
27 #include "etnaviv_blend.h"
29 #include "etnaviv_context.h"
30 #include "etnaviv_translate.h"
31 #include "pipe/p_defines.h"
32 #include "util/u_memory.h"
35 etna_blend_state_create(struct pipe_context
*pctx
,
36 const struct pipe_blend_state
*so
)
38 const struct pipe_rt_blend_state
*rt0
= &so
->rt
[0];
39 struct etna_blend_state
*co
= CALLOC_STRUCT(etna_blend_state
);
47 * - blend enabled in blend state
48 * - NOT source factor is ONE and destination factor ZERO for both rgb and
49 * alpha (which would mean that blending is effectively disabled)
51 co
->enable
= rt0
->blend_enable
&&
52 !(rt0
->rgb_src_factor
== PIPE_BLENDFACTOR_ONE
&&
53 rt0
->rgb_dst_factor
== PIPE_BLENDFACTOR_ZERO
&&
54 rt0
->alpha_src_factor
== PIPE_BLENDFACTOR_ONE
&&
55 rt0
->alpha_dst_factor
== PIPE_BLENDFACTOR_ZERO
);
57 /* Enable separate alpha if
58 * - Blending enabled (see above)
59 * - NOT source factor is equal to destination factor for both rgb abd
60 * alpha (which would effectively that mean alpha is not separate)
62 bool separate_alpha
= co
->enable
&&
63 !(rt0
->rgb_src_factor
== rt0
->alpha_src_factor
&&
64 rt0
->rgb_dst_factor
== rt0
->alpha_dst_factor
);
68 VIVS_PE_ALPHA_CONFIG_BLEND_ENABLE_COLOR
|
69 COND(separate_alpha
, VIVS_PE_ALPHA_CONFIG_BLEND_SEPARATE_ALPHA
) |
70 VIVS_PE_ALPHA_CONFIG_SRC_FUNC_COLOR(translate_blend_factor(rt0
->rgb_src_factor
)) |
71 VIVS_PE_ALPHA_CONFIG_SRC_FUNC_ALPHA(translate_blend_factor(rt0
->alpha_src_factor
)) |
72 VIVS_PE_ALPHA_CONFIG_DST_FUNC_COLOR(translate_blend_factor(rt0
->rgb_dst_factor
)) |
73 VIVS_PE_ALPHA_CONFIG_DST_FUNC_ALPHA(translate_blend_factor(rt0
->alpha_dst_factor
)) |
74 VIVS_PE_ALPHA_CONFIG_EQ_COLOR(translate_blend(rt0
->rgb_func
)) |
75 VIVS_PE_ALPHA_CONFIG_EQ_ALPHA(translate_blend(rt0
->alpha_func
));
77 co
->PE_ALPHA_CONFIG
= 0;
81 VIVS_PE_LOGIC_OP_OP(so
->logicop_enable
? so
->logicop_func
: LOGIC_OP_COPY
) |
84 /* independent_blend_enable not needed: only one rt supported */
85 /* XXX alpha_to_coverage / alpha_to_one? */
86 /* Set dither registers based on dither status. These registers set the
88 * for now, set the same values as the blob.
91 co
->PE_DITHER
[0] = 0x6e4ca280;
92 co
->PE_DITHER
[1] = 0x5d7f91b3;
94 co
->PE_DITHER
[0] = 0xffffffff;
95 co
->PE_DITHER
[1] = 0xffffffff;
102 etna_update_blend(struct etna_context
*ctx
)
104 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer_s
;
105 struct pipe_blend_state
*pblend
= ctx
->blend
;
106 struct etna_blend_state
*blend
= etna_blend_state(pblend
);
107 const struct pipe_rt_blend_state
*rt0
= &pblend
->rt
[0];
111 translate_rs_format_rb_swap(pfb
->cbufs
[0]->texture
->format
)) {
112 colormask
= rt0
->colormask
& (PIPE_MASK_A
| PIPE_MASK_G
);
113 if (rt0
->colormask
& PIPE_MASK_R
)
114 colormask
|= PIPE_MASK_B
;
115 if (rt0
->colormask
& PIPE_MASK_B
)
116 colormask
|= PIPE_MASK_R
;
118 colormask
= rt0
->colormask
;
121 /* If the complete render target is written, set full_overwrite:
122 * - The color mask is 1111
123 * - No blending is used
125 bool full_overwrite
= (rt0
->colormask
== 0xf) && !blend
->enable
;
126 blend
->PE_COLOR_FORMAT
=
127 VIVS_PE_COLOR_FORMAT_COMPONENTS(colormask
) |
128 COND(full_overwrite
, VIVS_PE_COLOR_FORMAT_OVERWRITE
);