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