2 #include "util/u_memory.h"
3 #include "pipe/p_context.h"
4 #include "pipe/p_state.h"
6 #include "brw_context.h"
7 #include "brw_defines.h"
10 static int translate_logicop(unsigned logicop
)
13 case PIPE_LOGICOP_CLEAR
:
14 return BRW_LOGICOPFUNCTION_CLEAR
;
15 case PIPE_LOGICOP_AND
:
16 return BRW_LOGICOPFUNCTION_AND
;
17 case PIPE_LOGICOP_AND_REVERSE
:
18 return BRW_LOGICOPFUNCTION_AND_REVERSE
;
19 case PIPE_LOGICOP_COPY
:
20 return BRW_LOGICOPFUNCTION_COPY
;
21 case PIPE_LOGICOP_COPY_INVERTED
:
22 return BRW_LOGICOPFUNCTION_COPY_INVERTED
;
23 case PIPE_LOGICOP_AND_INVERTED
:
24 return BRW_LOGICOPFUNCTION_AND_INVERTED
;
25 case PIPE_LOGICOP_NOOP
:
26 return BRW_LOGICOPFUNCTION_NOOP
;
27 case PIPE_LOGICOP_XOR
:
28 return BRW_LOGICOPFUNCTION_XOR
;
30 return BRW_LOGICOPFUNCTION_OR
;
31 case PIPE_LOGICOP_OR_INVERTED
:
32 return BRW_LOGICOPFUNCTION_OR_INVERTED
;
33 case PIPE_LOGICOP_NOR
:
34 return BRW_LOGICOPFUNCTION_NOR
;
35 case PIPE_LOGICOP_EQUIV
:
36 return BRW_LOGICOPFUNCTION_EQUIV
;
37 case PIPE_LOGICOP_INVERT
:
38 return BRW_LOGICOPFUNCTION_INVERT
;
39 case PIPE_LOGICOP_OR_REVERSE
:
40 return BRW_LOGICOPFUNCTION_OR_REVERSE
;
41 case PIPE_LOGICOP_NAND
:
42 return BRW_LOGICOPFUNCTION_NAND
;
43 case PIPE_LOGICOP_SET
:
44 return BRW_LOGICOPFUNCTION_SET
;
47 return BRW_LOGICOPFUNCTION_SET
;
52 static unsigned translate_blend_equation( unsigned mode
)
56 return BRW_BLENDFUNCTION_ADD
;
58 return BRW_BLENDFUNCTION_MIN
;
60 return BRW_BLENDFUNCTION_MAX
;
61 case PIPE_BLEND_SUBTRACT
:
62 return BRW_BLENDFUNCTION_SUBTRACT
;
63 case PIPE_BLEND_REVERSE_SUBTRACT
:
64 return BRW_BLENDFUNCTION_REVERSE_SUBTRACT
;
67 return BRW_BLENDFUNCTION_ADD
;
71 static unsigned translate_blend_factor( unsigned factor
)
74 case PIPE_BLENDFACTOR_ZERO
:
75 return BRW_BLENDFACTOR_ZERO
;
76 case PIPE_BLENDFACTOR_SRC_ALPHA
:
77 return BRW_BLENDFACTOR_SRC_ALPHA
;
78 case PIPE_BLENDFACTOR_ONE
:
79 return BRW_BLENDFACTOR_ONE
;
80 case PIPE_BLENDFACTOR_SRC_COLOR
:
81 return BRW_BLENDFACTOR_SRC_COLOR
;
82 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
83 return BRW_BLENDFACTOR_INV_SRC_COLOR
;
84 case PIPE_BLENDFACTOR_DST_COLOR
:
85 return BRW_BLENDFACTOR_DST_COLOR
;
86 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
87 return BRW_BLENDFACTOR_INV_DST_COLOR
;
88 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
89 return BRW_BLENDFACTOR_INV_SRC_ALPHA
;
90 case PIPE_BLENDFACTOR_DST_ALPHA
:
91 return BRW_BLENDFACTOR_DST_ALPHA
;
92 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
93 return BRW_BLENDFACTOR_INV_DST_ALPHA
;
94 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
95 return BRW_BLENDFACTOR_SRC_ALPHA_SATURATE
;
96 case PIPE_BLENDFACTOR_CONST_COLOR
:
97 return BRW_BLENDFACTOR_CONST_COLOR
;
98 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
99 return BRW_BLENDFACTOR_INV_CONST_COLOR
;
100 case PIPE_BLENDFACTOR_CONST_ALPHA
:
101 return BRW_BLENDFACTOR_CONST_ALPHA
;
102 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
103 return BRW_BLENDFACTOR_INV_CONST_ALPHA
;
106 return BRW_BLENDFACTOR_ZERO
;
110 static void *brw_create_blend_state( struct pipe_context
*pipe
,
111 const struct pipe_blend_state
*templ
)
113 struct brw_blend_state
*blend
= CALLOC_STRUCT(brw_blend_state
);
115 if (templ
->logicop_enable
) {
116 blend
->cc2
.logicop_enable
= 1;
117 blend
->cc5
.logicop_func
= translate_logicop(templ
->logicop_func
);
119 else if (templ
->blend_enable
) {
120 blend
->cc6
.dest_blend_factor
= translate_blend_factor(templ
->rgb_dst_factor
);
121 blend
->cc6
.src_blend_factor
= translate_blend_factor(templ
->rgb_src_factor
);
122 blend
->cc6
.blend_function
= translate_blend_equation(templ
->rgb_func
);
124 blend
->cc5
.ia_dest_blend_factor
= translate_blend_factor(templ
->alpha_dst_factor
);
125 blend
->cc5
.ia_src_blend_factor
= translate_blend_factor(templ
->alpha_src_factor
);
126 blend
->cc5
.ia_blend_function
= translate_blend_equation(templ
->alpha_func
);
128 blend
->cc3
.blend_enable
= 1;
129 blend
->cc3
.ia_blend_enable
=
130 (blend
->cc6
.dest_blend_factor
!= blend
->cc5
.ia_dest_blend_factor
||
131 blend
->cc6
.src_blend_factor
!= blend
->cc5
.ia_src_blend_factor
||
132 blend
->cc6
.blend_function
!= blend
->cc5
.ia_blend_function
);
135 blend
->cc5
.dither_enable
= templ
->dither
;
137 if (BRW_DEBUG
& DEBUG_STATS
)
138 blend
->cc5
.statistics_enable
= 1;
140 return (void *)blend
;
143 static void brw_bind_blend_state(struct pipe_context
*pipe
,
146 struct brw_context
*brw
= brw_context(pipe
);
147 brw
->curr
.blend
= (const struct brw_blend_state
*)cso
;
148 brw
->state
.dirty
.mesa
|= PIPE_NEW_BLEND
;
151 static void brw_delete_blend_state(struct pipe_context
*pipe
,
154 struct brw_context
*brw
= brw_context(pipe
);
155 assert((const void *)cso
!= (const void *)brw
->curr
.blend
);
160 static void brw_set_blend_color(struct pipe_context
*pipe
,
161 const struct pipe_blend_color
*blend_color
)
163 struct brw_context
*brw
= brw_context(pipe
);
164 struct brw_blend_constant_color
*bcc
= &brw
->curr
.bcc
;
166 memset(bcc
, 0, sizeof(*bcc
));
167 bcc
->header
.opcode
= CMD_BLEND_CONSTANT_COLOR
;
168 bcc
->header
.length
= sizeof(*bcc
)/4-2;
169 bcc
->blend_constant_color
[0] = blend_color
->color
[0];
170 bcc
->blend_constant_color
[1] = blend_color
->color
[1];
171 bcc
->blend_constant_color
[2] = blend_color
->color
[2];
172 bcc
->blend_constant_color
[3] = blend_color
->color
[3];
174 brw
->state
.dirty
.mesa
|= PIPE_NEW_BLEND_COLOR
;
178 void brw_pipe_blend_init( struct brw_context
*brw
)
180 brw
->base
.set_blend_color
= brw_set_blend_color
;
181 brw
->base
.create_blend_state
= brw_create_blend_state
;
182 brw
->base
.bind_blend_state
= brw_bind_blend_state
;
183 brw
->base
.delete_blend_state
= brw_delete_blend_state
;
186 void brw_pipe_blend_cleanup( struct brw_context
*brw
)