Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / drivers / i915 / i915_state_inlines.h
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef I915_STATE_INLINES_H
29 #define I915_STATE_INLINES_H
30
31 #include "pipe/p_compiler.h"
32 #include "pipe/p_defines.h"
33 #include "util/u_debug.h"
34 #include "i915_reg.h"
35
36
37 static INLINE unsigned
38 i915_translate_compare_func(unsigned func)
39 {
40 switch (func) {
41 case PIPE_FUNC_NEVER:
42 return COMPAREFUNC_NEVER;
43 case PIPE_FUNC_LESS:
44 return COMPAREFUNC_LESS;
45 case PIPE_FUNC_LEQUAL:
46 return COMPAREFUNC_LEQUAL;
47 case PIPE_FUNC_GREATER:
48 return COMPAREFUNC_GREATER;
49 case PIPE_FUNC_GEQUAL:
50 return COMPAREFUNC_GEQUAL;
51 case PIPE_FUNC_NOTEQUAL:
52 return COMPAREFUNC_NOTEQUAL;
53 case PIPE_FUNC_EQUAL:
54 return COMPAREFUNC_EQUAL;
55 case PIPE_FUNC_ALWAYS:
56 return COMPAREFUNC_ALWAYS;
57 default:
58 return COMPAREFUNC_ALWAYS;
59 }
60 }
61
62 static INLINE unsigned
63 i915_translate_stencil_op(unsigned op)
64 {
65 switch (op) {
66 case PIPE_STENCIL_OP_KEEP:
67 return STENCILOP_KEEP;
68 case PIPE_STENCIL_OP_ZERO:
69 return STENCILOP_ZERO;
70 case PIPE_STENCIL_OP_REPLACE:
71 return STENCILOP_REPLACE;
72 case PIPE_STENCIL_OP_INCR:
73 return STENCILOP_INCRSAT;
74 case PIPE_STENCIL_OP_DECR:
75 return STENCILOP_DECRSAT;
76 case PIPE_STENCIL_OP_INCR_WRAP:
77 return STENCILOP_INCR;
78 case PIPE_STENCIL_OP_DECR_WRAP:
79 return STENCILOP_DECR;
80 case PIPE_STENCIL_OP_INVERT:
81 return STENCILOP_INVERT;
82 default:
83 return STENCILOP_ZERO;
84 }
85 }
86
87 static INLINE unsigned
88 i915_translate_blend_factor(unsigned factor)
89 {
90 switch (factor) {
91 case PIPE_BLENDFACTOR_ZERO:
92 return BLENDFACT_ZERO;
93 case PIPE_BLENDFACTOR_SRC_ALPHA:
94 return BLENDFACT_SRC_ALPHA;
95 case PIPE_BLENDFACTOR_ONE:
96 return BLENDFACT_ONE;
97 case PIPE_BLENDFACTOR_SRC_COLOR:
98 return BLENDFACT_SRC_COLR;
99 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
100 return BLENDFACT_INV_SRC_COLR;
101 case PIPE_BLENDFACTOR_DST_COLOR:
102 return BLENDFACT_DST_COLR;
103 case PIPE_BLENDFACTOR_INV_DST_COLOR:
104 return BLENDFACT_INV_DST_COLR;
105 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
106 return BLENDFACT_INV_SRC_ALPHA;
107 case PIPE_BLENDFACTOR_DST_ALPHA:
108 return BLENDFACT_DST_ALPHA;
109 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
110 return BLENDFACT_INV_DST_ALPHA;
111 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
112 return BLENDFACT_SRC_ALPHA_SATURATE;
113 case PIPE_BLENDFACTOR_CONST_COLOR:
114 return BLENDFACT_CONST_COLOR;
115 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
116 return BLENDFACT_INV_CONST_COLOR;
117 case PIPE_BLENDFACTOR_CONST_ALPHA:
118 return BLENDFACT_CONST_ALPHA;
119 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
120 return BLENDFACT_INV_CONST_ALPHA;
121 default:
122 return BLENDFACT_ZERO;
123 }
124 }
125
126 static INLINE unsigned
127 i915_translate_blend_func(unsigned mode)
128 {
129 switch (mode) {
130 case PIPE_BLEND_ADD:
131 return BLENDFUNC_ADD;
132 case PIPE_BLEND_MIN:
133 return BLENDFUNC_MIN;
134 case PIPE_BLEND_MAX:
135 return BLENDFUNC_MAX;
136 case PIPE_BLEND_SUBTRACT:
137 return BLENDFUNC_SUBTRACT;
138 case PIPE_BLEND_REVERSE_SUBTRACT:
139 return BLENDFUNC_REVERSE_SUBTRACT;
140 default:
141 return 0;
142 }
143 }
144
145
146 static INLINE unsigned
147 i915_translate_logic_op(unsigned opcode)
148 {
149 switch (opcode) {
150 case PIPE_LOGICOP_CLEAR:
151 return LOGICOP_CLEAR;
152 case PIPE_LOGICOP_AND:
153 return LOGICOP_AND;
154 case PIPE_LOGICOP_AND_REVERSE:
155 return LOGICOP_AND_RVRSE;
156 case PIPE_LOGICOP_COPY:
157 return LOGICOP_COPY;
158 case PIPE_LOGICOP_COPY_INVERTED:
159 return LOGICOP_COPY_INV;
160 case PIPE_LOGICOP_AND_INVERTED:
161 return LOGICOP_AND_INV;
162 case PIPE_LOGICOP_NOOP:
163 return LOGICOP_NOOP;
164 case PIPE_LOGICOP_XOR:
165 return LOGICOP_XOR;
166 case PIPE_LOGICOP_OR:
167 return LOGICOP_OR;
168 case PIPE_LOGICOP_OR_INVERTED:
169 return LOGICOP_OR_INV;
170 case PIPE_LOGICOP_NOR:
171 return LOGICOP_NOR;
172 case PIPE_LOGICOP_EQUIV:
173 return LOGICOP_EQUIV;
174 case PIPE_LOGICOP_INVERT:
175 return LOGICOP_INV;
176 case PIPE_LOGICOP_OR_REVERSE:
177 return LOGICOP_OR_RVRSE;
178 case PIPE_LOGICOP_NAND:
179 return LOGICOP_NAND;
180 case PIPE_LOGICOP_SET:
181 return LOGICOP_SET;
182 default:
183 return LOGICOP_SET;
184 }
185 }
186
187
188
189 static INLINE boolean i915_validate_vertices( unsigned hw_prim, unsigned nr )
190 {
191 boolean ok;
192
193 switch (hw_prim) {
194 case PRIM3D_POINTLIST:
195 ok = (nr >= 1);
196 assert(ok);
197 break;
198 case PRIM3D_LINELIST:
199 ok = (nr >= 2) && (nr % 2) == 0;
200 assert(ok);
201 break;
202 case PRIM3D_LINESTRIP:
203 ok = (nr >= 2);
204 assert(ok);
205 break;
206 case PRIM3D_TRILIST:
207 ok = (nr >= 3) && (nr % 3) == 0;
208 assert(ok);
209 break;
210 case PRIM3D_TRISTRIP:
211 ok = (nr >= 3);
212 assert(ok);
213 break;
214 case PRIM3D_TRIFAN:
215 ok = (nr >= 3);
216 assert(ok);
217 break;
218 case PRIM3D_POLY:
219 ok = (nr >= 3);
220 assert(ok);
221 break;
222 default:
223 assert(0);
224 ok = 0;
225 break;
226 }
227
228 return ok;
229 }
230
231 #endif