summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/i915simple/i915_state_inlines.h
blob: 0934ac79a41029ba4b8537e746f4db41189ac442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**************************************************************************
 * 
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

#ifndef I915_STATE_INLINES_H
#define I915_STATE_INLINES_H

#include "p_compiler.h"
#include "p_defines.h"
#include "i915_reg.h"


static INLINE unsigned
i915_translate_compare_func(unsigned func)
{
   switch (func) {
   case PIPE_FUNC_NEVER:
      return COMPAREFUNC_NEVER;
   case PIPE_FUNC_LESS:
      return COMPAREFUNC_LESS;
   case PIPE_FUNC_LEQUAL:
      return COMPAREFUNC_LEQUAL;
   case PIPE_FUNC_GREATER:
      return COMPAREFUNC_GREATER;
   case PIPE_FUNC_GEQUAL:
      return COMPAREFUNC_GEQUAL;
   case PIPE_FUNC_NOTEQUAL:
      return COMPAREFUNC_NOTEQUAL;
   case PIPE_FUNC_EQUAL:
      return COMPAREFUNC_EQUAL;
   case PIPE_FUNC_ALWAYS:
      return COMPAREFUNC_ALWAYS;
   default:
      return COMPAREFUNC_ALWAYS;
   }
}

static INLINE unsigned
i915_translate_stencil_op(unsigned op)
{
   switch (op) {
   case PIPE_STENCIL_OP_KEEP:
      return STENCILOP_KEEP;
   case PIPE_STENCIL_OP_ZERO:
      return STENCILOP_ZERO;
   case PIPE_STENCIL_OP_REPLACE:
      return STENCILOP_REPLACE;
   case PIPE_STENCIL_OP_INCR:
      return STENCILOP_INCRSAT;
   case PIPE_STENCIL_OP_DECR:
      return STENCILOP_DECRSAT;
   case PIPE_STENCIL_OP_INCR_WRAP:
      return STENCILOP_INCR;
   case PIPE_STENCIL_OP_DECR_WRAP:
      return STENCILOP_DECR;
   case PIPE_STENCIL_OP_INVERT:
      return STENCILOP_INVERT;
   default:
      return STENCILOP_ZERO;
   }
}

static INLINE unsigned
i915_translate_blend_factor(unsigned factor)
{
   switch (factor) {
   case PIPE_BLENDFACTOR_ZERO:
      return BLENDFACT_ZERO;
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      return BLENDFACT_SRC_ALPHA;
   case PIPE_BLENDFACTOR_ONE:
      return BLENDFACT_ONE;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      return BLENDFACT_SRC_COLR;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      return BLENDFACT_INV_SRC_COLR;
   case PIPE_BLENDFACTOR_DST_COLOR:
      return BLENDFACT_DST_COLR;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      return BLENDFACT_INV_DST_COLR;
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
      return BLENDFACT_INV_SRC_ALPHA;
   case PIPE_BLENDFACTOR_DST_ALPHA:
      return BLENDFACT_DST_ALPHA;
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
      return BLENDFACT_INV_DST_ALPHA;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      return BLENDFACT_SRC_ALPHA_SATURATE;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      return BLENDFACT_CONST_COLOR;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      return BLENDFACT_INV_CONST_COLOR;
   case PIPE_BLENDFACTOR_CONST_ALPHA:
      return BLENDFACT_CONST_ALPHA;
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
      return BLENDFACT_INV_CONST_ALPHA;
   default:
      return BLENDFACT_ZERO;
   }
}

static INLINE unsigned
i915_translate_blend_func(unsigned mode)
{
   switch (mode) {
   case PIPE_BLEND_ADD:
      return BLENDFUNC_ADD;
   case PIPE_BLEND_MIN:
      return BLENDFUNC_MIN;
   case PIPE_BLEND_MAX:
      return BLENDFUNC_MAX;
   case PIPE_BLEND_SUBTRACT:
      return BLENDFUNC_SUBTRACT;
   case PIPE_BLEND_REVERSE_SUBTRACT:
      return BLENDFUNC_REVERSE_SUBTRACT;
   default:
      return 0;
   }
}


static INLINE unsigned
i915_translate_logic_op(unsigned opcode)
{
   switch (opcode) {
   case PIPE_LOGICOP_CLEAR:
      return LOGICOP_CLEAR;
   case PIPE_LOGICOP_AND:
      return LOGICOP_AND;
   case PIPE_LOGICOP_AND_REVERSE:
      return LOGICOP_AND_RVRSE;
   case PIPE_LOGICOP_COPY:
      return LOGICOP_COPY;
   case PIPE_LOGICOP_COPY_INVERTED:
      return LOGICOP_COPY_INV;
   case PIPE_LOGICOP_AND_INVERTED:
      return LOGICOP_AND_INV;
   case PIPE_LOGICOP_NOOP:
      return LOGICOP_NOOP;
   case PIPE_LOGICOP_XOR:
      return LOGICOP_XOR;
   case PIPE_LOGICOP_OR:
      return LOGICOP_OR;
   case PIPE_LOGICOP_OR_INVERTED:
      return LOGICOP_OR_INV;
   case PIPE_LOGICOP_NOR:
      return LOGICOP_NOR;
   case PIPE_LOGICOP_EQUIV:
      return LOGICOP_EQUIV;
   case PIPE_LOGICOP_INVERT:
      return LOGICOP_INV;
   case PIPE_LOGICOP_OR_REVERSE:
      return LOGICOP_OR_RVRSE;
   case PIPE_LOGICOP_NAND:
      return LOGICOP_NAND;
   case PIPE_LOGICOP_SET:
      return LOGICOP_SET;
   default:
      return LOGICOP_SET;
   }
}



static INLINE boolean i915_validate_vertices( unsigned hw_prim, unsigned nr )
{
   boolean ok;

   switch (hw_prim) {
   case PRIM3D_POINTLIST:
      ok = (nr >= 1);
      assert(ok);
      break;
   case PRIM3D_LINELIST:
      ok = (nr >= 2) && (nr % 2) == 0;
      assert(ok);
      break;
   case PRIM3D_LINESTRIP:
      ok = (nr >= 2);
      assert(ok);
      break;
   case PRIM3D_TRILIST:
      ok = (nr >= 3) && (nr % 3) == 0;
      assert(ok);
      break;
   case PRIM3D_TRISTRIP:
      ok = (nr >= 3);
      assert(ok);
      break;
   case PRIM3D_TRIFAN:
      ok = (nr >= 3);
      assert(ok);
      break;
   case PRIM3D_POLY:
      ok = (nr >= 3);
      assert(ok);
      break;
   default:
      assert(0);
      ok = 0;
      break;
   }

   return ok;
}

#endif