Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[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 "i915_reg.h"
34
35
36 static INLINE unsigned
37 i915_translate_compare_func(unsigned func)
38 {
39 switch (func) {
40 case PIPE_FUNC_NEVER:
41 return COMPAREFUNC_NEVER;
42 case PIPE_FUNC_LESS:
43 return COMPAREFUNC_LESS;
44 case PIPE_FUNC_LEQUAL:
45 return COMPAREFUNC_LEQUAL;
46 case PIPE_FUNC_GREATER:
47 return COMPAREFUNC_GREATER;
48 case PIPE_FUNC_GEQUAL:
49 return COMPAREFUNC_GEQUAL;
50 case PIPE_FUNC_NOTEQUAL:
51 return COMPAREFUNC_NOTEQUAL;
52 case PIPE_FUNC_EQUAL:
53 return COMPAREFUNC_EQUAL;
54 case PIPE_FUNC_ALWAYS:
55 return COMPAREFUNC_ALWAYS;
56 default:
57 return COMPAREFUNC_ALWAYS;
58 }
59 }
60
61 static INLINE unsigned
62 i915_translate_stencil_op(unsigned op)
63 {
64 switch (op) {
65 case PIPE_STENCIL_OP_KEEP:
66 return STENCILOP_KEEP;
67 case PIPE_STENCIL_OP_ZERO:
68 return STENCILOP_ZERO;
69 case PIPE_STENCIL_OP_REPLACE:
70 return STENCILOP_REPLACE;
71 case PIPE_STENCIL_OP_INCR:
72 return STENCILOP_INCRSAT;
73 case PIPE_STENCIL_OP_DECR:
74 return STENCILOP_DECRSAT;
75 case PIPE_STENCIL_OP_INCR_WRAP:
76 return STENCILOP_INCR;
77 case PIPE_STENCIL_OP_DECR_WRAP:
78 return STENCILOP_DECR;
79 case PIPE_STENCIL_OP_INVERT:
80 return STENCILOP_INVERT;
81 default:
82 return STENCILOP_ZERO;
83 }
84 }
85
86 static INLINE unsigned
87 i915_translate_blend_factor(unsigned factor)
88 {
89 switch (factor) {
90 case PIPE_BLENDFACTOR_ZERO:
91 return BLENDFACT_ZERO;
92 case PIPE_BLENDFACTOR_SRC_ALPHA:
93 return BLENDFACT_SRC_ALPHA;
94 case PIPE_BLENDFACTOR_ONE:
95 return BLENDFACT_ONE;
96 case PIPE_BLENDFACTOR_SRC_COLOR:
97 return BLENDFACT_SRC_COLR;
98 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
99 return BLENDFACT_INV_SRC_COLR;
100 case PIPE_BLENDFACTOR_DST_COLOR:
101 return BLENDFACT_DST_COLR;
102 case PIPE_BLENDFACTOR_INV_DST_COLOR:
103 return BLENDFACT_INV_DST_COLR;
104 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
105 return BLENDFACT_INV_SRC_ALPHA;
106 case PIPE_BLENDFACTOR_DST_ALPHA:
107 return BLENDFACT_DST_ALPHA;
108 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
109 return BLENDFACT_INV_DST_ALPHA;
110 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
111 return BLENDFACT_SRC_ALPHA_SATURATE;
112 case PIPE_BLENDFACTOR_CONST_COLOR:
113 return BLENDFACT_CONST_COLOR;
114 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
115 return BLENDFACT_INV_CONST_COLOR;
116 case PIPE_BLENDFACTOR_CONST_ALPHA:
117 return BLENDFACT_CONST_ALPHA;
118 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
119 return BLENDFACT_INV_CONST_ALPHA;
120 default:
121 return BLENDFACT_ZERO;
122 }
123 }
124
125 static INLINE unsigned
126 i915_translate_blend_func(unsigned mode)
127 {
128 switch (mode) {
129 case PIPE_BLEND_ADD:
130 return BLENDFUNC_ADD;
131 case PIPE_BLEND_MIN:
132 return BLENDFUNC_MIN;
133 case PIPE_BLEND_MAX:
134 return BLENDFUNC_MAX;
135 case PIPE_BLEND_SUBTRACT:
136 return BLENDFUNC_SUBTRACT;
137 case PIPE_BLEND_REVERSE_SUBTRACT:
138 return BLENDFUNC_REVERSE_SUBTRACT;
139 default:
140 return 0;
141 }
142 }
143
144
145 static INLINE unsigned
146 i915_translate_logic_op(unsigned opcode)
147 {
148 switch (opcode) {
149 case PIPE_LOGICOP_CLEAR:
150 return LOGICOP_CLEAR;
151 case PIPE_LOGICOP_AND:
152 return LOGICOP_AND;
153 case PIPE_LOGICOP_AND_REVERSE:
154 return LOGICOP_AND_RVRSE;
155 case PIPE_LOGICOP_COPY:
156 return LOGICOP_COPY;
157 case PIPE_LOGICOP_COPY_INVERTED:
158 return LOGICOP_COPY_INV;
159 case PIPE_LOGICOP_AND_INVERTED:
160 return LOGICOP_AND_INV;
161 case PIPE_LOGICOP_NOOP:
162 return LOGICOP_NOOP;
163 case PIPE_LOGICOP_XOR:
164 return LOGICOP_XOR;
165 case PIPE_LOGICOP_OR:
166 return LOGICOP_OR;
167 case PIPE_LOGICOP_OR_INVERTED:
168 return LOGICOP_OR_INV;
169 case PIPE_LOGICOP_NOR:
170 return LOGICOP_NOR;
171 case PIPE_LOGICOP_EQUIV:
172 return LOGICOP_EQUIV;
173 case PIPE_LOGICOP_INVERT:
174 return LOGICOP_INV;
175 case PIPE_LOGICOP_OR_REVERSE:
176 return LOGICOP_OR_RVRSE;
177 case PIPE_LOGICOP_NAND:
178 return LOGICOP_NAND;
179 case PIPE_LOGICOP_SET:
180 return LOGICOP_SET;
181 default:
182 return LOGICOP_SET;
183 }
184 }
185
186
187
188 static INLINE boolean i915_validate_vertices( unsigned hw_prim, unsigned nr )
189 {
190 boolean ok;
191
192 switch (hw_prim) {
193 case PRIM3D_POINTLIST:
194 ok = (nr >= 1);
195 assert(ok);
196 break;
197 case PRIM3D_LINELIST:
198 ok = (nr >= 2) && (nr % 2) == 0;
199 assert(ok);
200 break;
201 case PRIM3D_LINESTRIP:
202 ok = (nr >= 2);
203 assert(ok);
204 break;
205 case PRIM3D_TRILIST:
206 ok = (nr >= 3) && (nr % 3) == 0;
207 assert(ok);
208 break;
209 case PRIM3D_TRISTRIP:
210 ok = (nr >= 3);
211 assert(ok);
212 break;
213 case PRIM3D_TRIFAN:
214 ok = (nr >= 3);
215 assert(ok);
216 break;
217 case PRIM3D_POLY:
218 ok = (nr >= 3);
219 assert(ok);
220 break;
221 default:
222 assert(0);
223 ok = 0;
224 break;
225 }
226
227 return ok;
228 }
229
230 #endif