1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
33 #include "freedreno_blend.h"
34 #include "freedreno_context.h"
35 #include "freedreno_util.h"
37 static enum rb_blend_op
38 blend_factor(unsigned factor
)
41 case PIPE_BLENDFACTOR_ONE
:
43 case PIPE_BLENDFACTOR_SRC_COLOR
:
44 return RB_BLEND_SRC_COLOR
;
45 case PIPE_BLENDFACTOR_SRC_ALPHA
:
46 return RB_BLEND_SRC_ALPHA
;
47 case PIPE_BLENDFACTOR_DST_ALPHA
:
48 return RB_BLEND_DST_ALPHA
;
49 case PIPE_BLENDFACTOR_DST_COLOR
:
50 return RB_BLEND_DST_COLOR
;
51 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
52 return RB_BLEND_SRC_ALPHA_SATURATE
;
53 case PIPE_BLENDFACTOR_CONST_COLOR
:
54 return RB_BLEND_CONSTANT_COLOR
;
55 case PIPE_BLENDFACTOR_CONST_ALPHA
:
56 return RB_BLEND_CONSTANT_ALPHA
;
57 case PIPE_BLENDFACTOR_ZERO
:
60 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
61 return RB_BLEND_ONE_MINUS_SRC_COLOR
;
62 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
63 return RB_BLEND_ONE_MINUS_SRC_ALPHA
;
64 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
65 return RB_BLEND_ONE_MINUS_DST_ALPHA
;
66 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
67 return RB_BLEND_ONE_MINUS_DST_COLOR
;
68 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
69 return RB_BLEND_ONE_MINUS_CONSTANT_COLOR
;
70 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
71 return RB_BLEND_ONE_MINUS_CONSTANT_ALPHA
;
72 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
73 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
74 case PIPE_BLENDFACTOR_SRC1_COLOR
:
75 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
76 /* I don't think these are supported */
78 DBG("invalid blend factor: %x", factor
);
83 static enum rb_comb_func
84 blend_func(unsigned func
)
88 return COMB_DST_PLUS_SRC
;
90 return COMB_MIN_DST_SRC
;
92 return COMB_MAX_DST_SRC
;
93 case PIPE_BLEND_SUBTRACT
:
94 return COMB_SRC_MINUS_DST
;
95 case PIPE_BLEND_REVERSE_SUBTRACT
:
96 return COMB_DST_MINUS_SRC
;
98 DBG("invalid blend func: %x", func
);
104 fd_blend_state_create(struct pipe_context
*pctx
,
105 const struct pipe_blend_state
*cso
)
107 const struct pipe_rt_blend_state
*rt
= &cso
->rt
[0];
108 struct fd_blend_stateobj
*so
;
110 if (cso
->logicop_enable
) {
111 DBG("Unsupported! logicop");
115 if (cso
->independent_blend_enable
) {
116 DBG("Unsupported! independent blend state");
120 so
= CALLOC_STRUCT(fd_blend_stateobj
);
126 so
->rb_colorcontrol
= RB_COLORCONTROL_ROP_CODE(12);
128 so
->rb_blendcontrol
=
129 RB_BLENDCONTROL_COLOR_SRCBLEND(blend_factor(rt
->rgb_src_factor
)) |
130 RB_BLENDCONTROL_COLOR_COMB_FCN(blend_func(rt
->rgb_func
)) |
131 RB_BLENDCONTROL_COLOR_DESTBLEND(blend_factor(rt
->rgb_dst_factor
)) |
132 RB_BLENDCONTROL_ALPHA_SRCBLEND(blend_factor(rt
->alpha_src_factor
)) |
133 RB_BLENDCONTROL_ALPHA_COMB_FCN(blend_func(rt
->alpha_func
)) |
134 RB_BLENDCONTROL_ALPHA_DESTBLEND(blend_factor(rt
->alpha_dst_factor
));
136 if (rt
->colormask
& PIPE_MASK_R
)
137 so
->rb_colormask
|= RB_COLOR_MASK_WRITE_RED
;
138 if (rt
->colormask
& PIPE_MASK_G
)
139 so
->rb_colormask
|= RB_COLOR_MASK_WRITE_GREEN
;
140 if (rt
->colormask
& PIPE_MASK_B
)
141 so
->rb_colormask
|= RB_COLOR_MASK_WRITE_BLUE
;
142 if (rt
->colormask
& PIPE_MASK_A
)
143 so
->rb_colormask
|= RB_COLOR_MASK_WRITE_ALPHA
;
145 if (!rt
->blend_enable
)
146 so
->rb_colorcontrol
|= RB_COLORCONTROL_BLEND_DISABLE
;
149 so
->rb_colorcontrol
|= RB_COLORCONTROL_DITHER_MODE(DITHER_ALWAYS
);
155 fd_blend_state_bind(struct pipe_context
*pctx
, void *hwcso
)
157 struct fd_context
*ctx
= fd_context(pctx
);
159 ctx
->dirty
|= FD_DIRTY_BLEND
;
163 fd_blend_state_delete(struct pipe_context
*pctx
, void *hwcso
)
169 fd_blend_init(struct pipe_context
*pctx
)
171 pctx
->create_blend_state
= fd_blend_state_create
;
172 pctx
->bind_blend_state
= fd_blend_state_bind
;
173 pctx
->delete_blend_state
= fd_blend_state_delete
;