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