st/nine: Refactor how user constbufs sizes are calculated
[mesa.git] / src / gallium / state_trackers / nine / nine_pipe.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #ifndef _NINE_PIPE_H_
24 #define _NINE_PIPE_H_
25
26 #include "d3d9.h"
27 #include "pipe/p_format.h"
28 #include "pipe/p_state.h" /* pipe_box */
29 #include "util/u_rect.h"
30 #include "nine_helpers.h"
31
32 struct cso_context;
33
34 extern const enum pipe_format nine_d3d9_to_pipe_format_map[120];
35 extern const D3DFORMAT nine_pipe_to_d3d9_format_map[PIPE_FORMAT_COUNT];
36
37 void nine_convert_dsa_state(struct cso_context *, const DWORD *);
38 void nine_convert_rasterizer_state(struct cso_context *, const DWORD *);
39 void nine_convert_blend_state(struct cso_context *, const DWORD *);
40 void nine_convert_sampler_state(struct cso_context *, int idx, const DWORD *);
41
42 void nine_pipe_context_clear(struct NineDevice9 *);
43
44 static INLINE unsigned d3dlock_buffer_to_pipe_transfer_usage(DWORD Flags)
45 {
46 unsigned usage;
47
48 if (Flags & D3DLOCK_DISCARD)
49 usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE;
50 else
51 if (Flags & D3DLOCK_READONLY)
52 usage = PIPE_TRANSFER_READ;
53 else
54 usage = PIPE_TRANSFER_READ_WRITE;
55
56 if (Flags & D3DLOCK_NOOVERWRITE)
57 usage = (PIPE_TRANSFER_UNSYNCHRONIZED |
58 PIPE_TRANSFER_DISCARD_RANGE | usage) & ~PIPE_TRANSFER_READ;
59 else
60 if (Flags & D3DLOCK_DONOTWAIT)
61 usage |= PIPE_TRANSFER_DONTBLOCK;
62
63 /*
64 if (Flags & D3DLOCK_NO_DIRTY_UPDATE)
65 usage |= PIPE_TRANSFER_FLUSH_EXPLICIT;
66 */
67
68 return usage;
69 }
70
71 static INLINE void
72 rect_to_pipe_box(struct pipe_box *dst, const RECT *src)
73 {
74 dst->x = src->left;
75 dst->y = src->top;
76 dst->z = 0;
77 dst->width = src->right - src->left;
78 dst->height = src->bottom - src->top;
79 dst->depth = 1;
80 }
81
82 static INLINE boolean
83 rect_to_pipe_box_clamp(struct pipe_box *dst, const RECT *src)
84 {
85 rect_to_pipe_box(dst, src);
86
87 if (dst->width <= 0 || dst->height <= 0) {
88 DBG_FLAG(DBG_UNKNOWN, "Warning: NULL box");
89 dst->width = MAX2(dst->width, 0);
90 dst->height = MAX2(dst->height, 0);
91 return TRUE;
92 }
93 return FALSE;
94 }
95
96 static INLINE boolean
97 rect_to_pipe_box_flip(struct pipe_box *dst, const RECT *src)
98 {
99 rect_to_pipe_box(dst, src);
100
101 if (dst->width >= 0 && dst->height >= 0)
102 return FALSE;
103 if (dst->width < 0) dst->width = -dst->width;
104 if (dst->height < 0) dst->height = -dst->height;
105 return TRUE;
106 }
107
108 static INLINE void
109 nine_u_rect_to_pipe_box(struct pipe_box *dst, const struct u_rect *rect, int z)
110 {
111 dst->x = rect->x0;
112 dst->y = rect->y0;
113 dst->z = z;
114 dst->width = rect->x1 - rect->x0;
115 dst->height = rect->y1 - rect->y0;
116 dst->depth = 1;
117 }
118
119 static INLINE void
120 rect_to_pipe_box_xy_only(struct pipe_box *dst, const RECT *src)
121 {
122 user_warn(src->left > src->right || src->top > src->bottom);
123
124 dst->x = src->left;
125 dst->y = src->top;
126 dst->width = src->right - src->left;
127 dst->height = src->bottom - src->top;
128 }
129
130 static INLINE boolean
131 rect_to_pipe_box_xy_only_clamp(struct pipe_box *dst, const RECT *src)
132 {
133 rect_to_pipe_box_xy_only(dst, src);
134
135 if (dst->width <= 0 || dst->height <= 0) {
136 DBG_FLAG(DBG_UNKNOWN, "Warning: NULL box");
137 dst->width = MAX2(dst->width, 0);
138 dst->height = MAX2(dst->height, 0);
139 return TRUE;
140 }
141 return FALSE;
142 }
143
144 static INLINE void
145 rect_to_g3d_u_rect(struct u_rect *dst, const RECT *src)
146 {
147 user_warn(src->left > src->right || src->top > src->bottom);
148
149 dst->x0 = src->left;
150 dst->x1 = src->right;
151 dst->y0 = src->top;
152 dst->y1 = src->bottom;
153 }
154
155 static INLINE void
156 d3dbox_to_pipe_box(struct pipe_box *dst, const D3DBOX *src)
157 {
158 user_warn(src->Left > src->Right);
159 user_warn(src->Top > src->Bottom);
160 user_warn(src->Front > src->Back);
161
162 dst->x = src->Left;
163 dst->y = src->Top;
164 dst->z = src->Front;
165 dst->width = src->Right - src->Left;
166 dst->height = src->Bottom - src->Top;
167 dst->depth = src->Back - src->Front;
168 }
169
170 static INLINE D3DFORMAT
171 pipe_to_d3d9_format(enum pipe_format format)
172 {
173 return nine_pipe_to_d3d9_format_map[format];
174 }
175
176 static INLINE enum pipe_format
177 d3d9_to_pipe_format(D3DFORMAT format)
178 {
179 if (format <= D3DFMT_A2B10G10R10_XR_BIAS)
180 return nine_d3d9_to_pipe_format_map[format];
181 switch (format) {
182 case D3DFMT_INTZ: return PIPE_FORMAT_Z24_UNORM_S8_UINT;
183 case D3DFMT_DXT1: return PIPE_FORMAT_DXT1_RGBA;
184 case D3DFMT_DXT2: return PIPE_FORMAT_DXT3_RGBA; /* XXX */
185 case D3DFMT_DXT3: return PIPE_FORMAT_DXT3_RGBA;
186 case D3DFMT_DXT4: return PIPE_FORMAT_DXT5_RGBA; /* XXX */
187 case D3DFMT_DXT5: return PIPE_FORMAT_DXT5_RGBA;
188 case D3DFMT_ATI1: return PIPE_FORMAT_RGTC1_UNORM;
189 case D3DFMT_ATI2: return PIPE_FORMAT_RGTC2_UNORM;
190 case D3DFMT_UYVY: return PIPE_FORMAT_UYVY;
191 case D3DFMT_YUY2: return PIPE_FORMAT_YUYV; /* XXX check */
192 case D3DFMT_NV12: return PIPE_FORMAT_NV12;
193 case D3DFMT_G8R8_G8B8: return PIPE_FORMAT_G8R8_G8B8_UNORM; /* XXX order ? */
194 case D3DFMT_R8G8_B8G8: return PIPE_FORMAT_R8G8_B8G8_UNORM; /* XXX order ? */
195 case D3DFMT_BINARYBUFFER: return PIPE_FORMAT_NONE; /* not a format */
196 case D3DFMT_MULTI2_ARGB8: return PIPE_FORMAT_NONE; /* not supported */
197 case D3DFMT_Y210: /* XXX */
198 case D3DFMT_Y216:
199 case D3DFMT_NV11:
200 case D3DFMT_DF16: /* useless, not supported by wine either */
201 case D3DFMT_DF24: /* useless, not supported by wine either */
202 case D3DFMT_NULL: /* special cased, only for surfaces */
203 return PIPE_FORMAT_NONE;
204 default:
205 DBG_FLAG(DBG_UNKNOWN, "unknown D3DFORMAT: 0x%x/%c%c%c%c\n",
206 format, (char)format, (char)(format >> 8),
207 (char)(format >> 16), (char)(format >> 24));
208 return PIPE_FORMAT_NONE;
209 }
210 }
211
212 static INLINE const char *
213 d3dformat_to_string(D3DFORMAT fmt)
214 {
215 switch (fmt) {
216 case D3DFMT_UNKNOWN: return "D3DFMT_UNKNOWN";
217 case D3DFMT_R8G8B8: return "D3DFMT_R8G8B8";
218 case D3DFMT_A8R8G8B8: return "D3DFMT_A8R8G8B8";
219 case D3DFMT_X8R8G8B8: return "D3DFMT_X8R8G8B8";
220 case D3DFMT_R5G6B5: return "D3DFMT_R5G6B5";
221 case D3DFMT_X1R5G5B5: return "D3DFMT_X1R5G5B5";
222 case D3DFMT_A1R5G5B5: return "D3DFMT_A1R5G5B5";
223 case D3DFMT_A4R4G4B4: return "D3DFMT_A4R4G4B4";
224 case D3DFMT_R3G3B2: return "D3DFMT_R3G3B2";
225 case D3DFMT_A8: return "D3DFMT_A8";
226 case D3DFMT_A8R3G3B2: return "D3DFMT_A8R3G3B2";
227 case D3DFMT_X4R4G4B4: return "D3DFMT_X4R4G4B4";
228 case D3DFMT_A2B10G10R10: return "D3DFMT_A2B10G10R10";
229 case D3DFMT_A8B8G8R8: return "D3DFMT_A8B8G8R8";
230 case D3DFMT_X8B8G8R8: return "D3DFMT_X8B8G8R8";
231 case D3DFMT_G16R16: return "D3DFMT_G16R16";
232 case D3DFMT_A2R10G10B10: return "D3DFMT_A2R10G10B10";
233 case D3DFMT_A16B16G16R16: return "D3DFMT_A16B16G16R16";
234 case D3DFMT_A8P8: return "D3DFMT_A8P8";
235 case D3DFMT_P8: return "D3DFMT_P8";
236 case D3DFMT_L8: return "D3DFMT_L8";
237 case D3DFMT_A8L8: return "D3DFMT_A8L8";
238 case D3DFMT_A4L4: return "D3DFMT_A4L4";
239 case D3DFMT_V8U8: return "D3DFMT_V8U8";
240 case D3DFMT_L6V5U5: return "D3DFMT_L6V5U5";
241 case D3DFMT_X8L8V8U8: return "D3DFMT_X8L8V8U8";
242 case D3DFMT_Q8W8V8U8: return "D3DFMT_Q8W8V8U8";
243 case D3DFMT_V16U16: return "D3DFMT_V16U16";
244 case D3DFMT_A2W10V10U10: return "D3DFMT_A2W10V10U10";
245 case D3DFMT_UYVY: return "D3DFMT_UYVY";
246 case D3DFMT_R8G8_B8G8: return "D3DFMT_R8G8_B8G8";
247 case D3DFMT_YUY2: return "D3DFMT_YUY2";
248 case D3DFMT_G8R8_G8B8: return "D3DFMT_G8R8_G8B8";
249 case D3DFMT_DXT1: return "D3DFMT_DXT1";
250 case D3DFMT_DXT2: return "D3DFMT_DXT2";
251 case D3DFMT_DXT3: return "D3DFMT_DXT3";
252 case D3DFMT_DXT4: return "D3DFMT_DXT4";
253 case D3DFMT_DXT5: return "D3DFMT_DXT5";
254 case D3DFMT_ATI1: return "D3DFMT_ATI1";
255 case D3DFMT_ATI2: return "D3DFMT_ATI2";
256 case D3DFMT_D16_LOCKABLE: return "D3DFMT_D16_LOCKABLE";
257 case D3DFMT_D32: return "D3DFMT_D32";
258 case D3DFMT_D15S1: return "D3DFMT_D15S1";
259 case D3DFMT_D24S8: return "D3DFMT_D24S8";
260 case D3DFMT_D24X8: return "D3DFMT_D24X8";
261 case D3DFMT_D24X4S4: return "D3DFMT_D24X4S4";
262 case D3DFMT_D16: return "D3DFMT_D16";
263 case D3DFMT_D32F_LOCKABLE: return "D3DFMT_D32F_LOCKABLE";
264 case D3DFMT_D24FS8: return "D3DFMT_D24FS8";
265 case D3DFMT_D32_LOCKABLE: return "D3DFMT_D32_LOCKABLE";
266 case D3DFMT_S8_LOCKABLE: return "D3DFMT_S8_LOCKABLE";
267 case D3DFMT_L16: return "D3DFMT_L16";
268 case D3DFMT_VERTEXDATA: return "D3DFMT_VERTEXDATA";
269 case D3DFMT_INDEX16: return "D3DFMT_INDEX16";
270 case D3DFMT_INDEX32: return "D3DFMT_INDEX32";
271 case D3DFMT_Q16W16V16U16: return "D3DFMT_Q16W16V16U16";
272 case D3DFMT_MULTI2_ARGB8: return "D3DFMT_MULTI2_ARGB8";
273 case D3DFMT_R16F: return "D3DFMT_R16F";
274 case D3DFMT_G16R16F: return "D3DFMT_G16R16F";
275 case D3DFMT_A16B16G16R16F: return "D3DFMT_A16B16G16R16F";
276 case D3DFMT_R32F: return "D3DFMT_R32F";
277 case D3DFMT_G32R32F: return "D3DFMT_G32R32F";
278 case D3DFMT_A32B32G32R32F: return "D3DFMT_A32B32G32R32F";
279 case D3DFMT_CxV8U8: return "D3DFMT_CxV8U8";
280 case D3DFMT_A1: return "D3DFMT_A1";
281 case D3DFMT_A2B10G10R10_XR_BIAS: return "D3DFMT_A2B10G10R10_XR_BIAS";
282 case D3DFMT_BINARYBUFFER: return "D3DFMT_BINARYBUFFER";
283 case D3DFMT_DF16: return "D3DFMT_DF16";
284 case D3DFMT_DF24: return "D3DFMT_DF24";
285 case D3DFMT_INTZ: return "D3DFMT_INTZ";
286 case D3DFMT_NVDB: return "D3DFMT_NVDB";
287 case D3DFMT_NULL: return "D3DFMT_NULL";
288 default:
289 break;
290 }
291 return "Unknown";
292 }
293
294 static INLINE unsigned
295 nine_fvf_stride( DWORD fvf )
296 {
297 unsigned texcount, i, size = 0;
298
299 switch (fvf & D3DFVF_POSITION_MASK) {
300 case D3DFVF_XYZ: size += 3*4; break;
301 case D3DFVF_XYZRHW: size += 4*4; break;
302 case D3DFVF_XYZB1: size += 4*4; break;
303 case D3DFVF_XYZB2: size += 5*4; break;
304 case D3DFVF_XYZB3: size += 6*4; break;
305 case D3DFVF_XYZB4: size += 7*4; break;
306 case D3DFVF_XYZB5: size += 8*4; break;
307 case D3DFVF_XYZW: size += 4*4; break;
308 default:
309 user_warn("Position doesn't match any known combination.");
310 break;
311 }
312
313 if (fvf & D3DFVF_NORMAL) { size += 3*4; }
314 if (fvf & D3DFVF_PSIZE) { size += 1*4; }
315 if (fvf & D3DFVF_DIFFUSE) { size += 1*4; }
316 if (fvf & D3DFVF_SPECULAR) { size += 1*4; }
317
318 texcount = (fvf >> D3DFVF_TEXCOUNT_SHIFT) & D3DFVF_TEXCOUNT_MASK;
319 if (user_error(texcount <= 8))
320 texcount = 8;
321
322 for (i = 0; i < texcount; ++i) {
323 unsigned texformat = (fvf>>(16+i*2))&0x3;
324 /* texformats are defined having been shifted around so 1=3,2=0,3=1,4=2
325 * meaning we can just do this instead of the switch below */
326 size += (((texformat+1)&0x3)+1)*4;
327
328 /*
329 switch (texformat) {
330 case D3DFVF_TEXTUREFORMAT1: size += 1*4;
331 case D3DFVF_TEXTUREFORMAT2: size += 2*4;
332 case D3DFVF_TEXTUREFORMAT3: size += 3*4;
333 case D3DFVF_TEXTUREFORMAT4: size += 4*4;
334 }
335 */
336 }
337
338 return size;
339 }
340
341 static INLINE void
342 d3dcolor_to_rgba(float *rgba, D3DCOLOR color)
343 {
344 rgba[0] = (float)((color >> 16) & 0xFF) / 0xFF;
345 rgba[1] = (float)((color >> 8) & 0xFF) / 0xFF;
346 rgba[2] = (float)((color >> 0) & 0xFF) / 0xFF;
347 rgba[3] = (float)((color >> 24) & 0xFF) / 0xFF;
348 }
349
350 static INLINE void
351 d3dcolor_to_pipe_color_union(union pipe_color_union *rgba, D3DCOLOR color)
352 {
353 d3dcolor_to_rgba(&rgba->f[0], color);
354 }
355
356 static INLINE unsigned
357 d3dprimitivetype_to_pipe_prim(D3DPRIMITIVETYPE prim)
358 {
359 switch (prim) {
360 case D3DPT_POINTLIST: return PIPE_PRIM_POINTS;
361 case D3DPT_LINELIST: return PIPE_PRIM_LINES;
362 case D3DPT_LINESTRIP: return PIPE_PRIM_LINE_STRIP;
363 case D3DPT_TRIANGLELIST: return PIPE_PRIM_TRIANGLES;
364 case D3DPT_TRIANGLESTRIP: return PIPE_PRIM_TRIANGLE_STRIP;
365 case D3DPT_TRIANGLEFAN: return PIPE_PRIM_TRIANGLE_FAN;
366 default:
367 assert(0);
368 return PIPE_PRIM_POINTS;
369 }
370 }
371
372 static INLINE unsigned
373 prim_count_to_vertex_count(D3DPRIMITIVETYPE prim, UINT count)
374 {
375 switch (prim) {
376 case D3DPT_POINTLIST: return count;
377 case D3DPT_LINELIST: return count * 2;
378 case D3DPT_LINESTRIP: return count + 1;
379 case D3DPT_TRIANGLELIST: return count * 3;
380 case D3DPT_TRIANGLESTRIP: return count + 2;
381 case D3DPT_TRIANGLEFAN: return count + 2;
382 default:
383 assert(0);
384 return 0;
385 }
386 }
387
388 static INLINE unsigned
389 d3dcmpfunc_to_pipe_func(D3DCMPFUNC func)
390 {
391 switch (func) {
392 case D3DCMP_NEVER: return PIPE_FUNC_NEVER;
393 case D3DCMP_LESS: return PIPE_FUNC_LESS;
394 case D3DCMP_EQUAL: return PIPE_FUNC_EQUAL;
395 case D3DCMP_LESSEQUAL: return PIPE_FUNC_LEQUAL;
396 case D3DCMP_GREATER: return PIPE_FUNC_GREATER;
397 case D3DCMP_NOTEQUAL: return PIPE_FUNC_NOTEQUAL;
398 case D3DCMP_GREATEREQUAL: return PIPE_FUNC_GEQUAL;
399 case D3DCMP_ALWAYS: return PIPE_FUNC_ALWAYS;
400 default:
401 assert(0);
402 return PIPE_FUNC_NEVER;
403 }
404 }
405
406 static INLINE unsigned
407 d3dstencilop_to_pipe_stencil_op(D3DSTENCILOP op)
408 {
409 switch (op) {
410 case D3DSTENCILOP_KEEP: return PIPE_STENCIL_OP_KEEP;
411 case D3DSTENCILOP_ZERO: return PIPE_STENCIL_OP_ZERO;
412 case D3DSTENCILOP_REPLACE: return PIPE_STENCIL_OP_REPLACE;
413 case D3DSTENCILOP_INCRSAT: return PIPE_STENCIL_OP_INCR;
414 case D3DSTENCILOP_DECRSAT: return PIPE_STENCIL_OP_DECR;
415 case D3DSTENCILOP_INVERT: return PIPE_STENCIL_OP_INVERT;
416 case D3DSTENCILOP_INCR: return PIPE_STENCIL_OP_INCR_WRAP;
417 case D3DSTENCILOP_DECR: return PIPE_STENCIL_OP_DECR_WRAP;
418 default:
419 return PIPE_STENCIL_OP_ZERO;
420 }
421 }
422
423 static INLINE unsigned
424 d3dcull_to_pipe_face(D3DCULL cull)
425 {
426 switch (cull) {
427 case D3DCULL_NONE: return PIPE_FACE_NONE;
428 case D3DCULL_CW: return PIPE_FACE_FRONT;
429 case D3DCULL_CCW: return PIPE_FACE_BACK;
430 default:
431 assert(0);
432 return PIPE_FACE_NONE;
433 }
434 }
435
436 static INLINE unsigned
437 d3dfillmode_to_pipe_polygon_mode(D3DFILLMODE mode)
438 {
439 switch (mode) {
440 case D3DFILL_POINT: return PIPE_POLYGON_MODE_POINT;
441 case D3DFILL_WIREFRAME: return PIPE_POLYGON_MODE_LINE;
442 case D3DFILL_SOLID: return PIPE_POLYGON_MODE_FILL;
443 default:
444 assert(0);
445 return PIPE_POLYGON_MODE_FILL;
446 }
447 }
448
449 static INLINE unsigned
450 d3dblendop_to_pipe_blend(D3DBLENDOP op)
451 {
452 switch (op) {
453 case D3DBLENDOP_ADD: return PIPE_BLEND_ADD;
454 case D3DBLENDOP_SUBTRACT: return PIPE_BLEND_SUBTRACT;
455 case D3DBLENDOP_REVSUBTRACT: return PIPE_BLEND_REVERSE_SUBTRACT;
456 case D3DBLENDOP_MIN: return PIPE_BLEND_MIN;
457 case D3DBLENDOP_MAX: return PIPE_BLEND_MAX;
458 default:
459 assert(0);
460 return PIPE_BLEND_ADD;
461 }
462 }
463
464 /* NOTE: The COLOR factors for are equal to the ALPHA ones for alpha.
465 * Drivers may check RGB and ALPHA factors for equality so we should not
466 * simply substitute the ALPHA variants.
467 */
468 static INLINE unsigned
469 d3dblend_alpha_to_pipe_blendfactor(D3DBLEND b)
470 {
471 switch (b) {
472 case D3DBLEND_ZERO: return PIPE_BLENDFACTOR_ZERO;
473 case D3DBLEND_ONE: return PIPE_BLENDFACTOR_ONE;
474 case D3DBLEND_SRCCOLOR: return PIPE_BLENDFACTOR_SRC_COLOR/*ALPHA*/;
475 case D3DBLEND_INVSRCCOLOR: return PIPE_BLENDFACTOR_INV_SRC_COLOR/*ALPHA*/;
476 case D3DBLEND_SRCALPHA: return PIPE_BLENDFACTOR_SRC_ALPHA;
477 case D3DBLEND_INVSRCALPHA: return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
478 case D3DBLEND_DESTALPHA: return PIPE_BLENDFACTOR_DST_ALPHA;
479 case D3DBLEND_INVDESTALPHA: return PIPE_BLENDFACTOR_INV_DST_ALPHA;
480 case D3DBLEND_DESTCOLOR: return PIPE_BLENDFACTOR_DST_COLOR/*ALPHA*/;
481 case D3DBLEND_INVDESTCOLOR: return PIPE_BLENDFACTOR_INV_DST_COLOR/*ALPHA*/;
482 case D3DBLEND_SRCALPHASAT: return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
483 case D3DBLEND_BOTHSRCALPHA: return PIPE_BLENDFACTOR_SRC_ALPHA;
484 case D3DBLEND_BOTHINVSRCALPHA: return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
485 case D3DBLEND_BLENDFACTOR: return PIPE_BLENDFACTOR_CONST_COLOR/*ALPHA*/;
486 case D3DBLEND_INVBLENDFACTOR: return PIPE_BLENDFACTOR_INV_CONST_COLOR/*ALPHA*/;
487 case D3DBLEND_SRCCOLOR2: return PIPE_BLENDFACTOR_ONE; /* XXX */
488 case D3DBLEND_INVSRCCOLOR2: return PIPE_BLENDFACTOR_ZERO; /* XXX */
489 default:
490 DBG_FLAG(DBG_UNKNOWN, "Unhandled blend factor %d\n", b);
491 return PIPE_BLENDFACTOR_ZERO;
492 }
493 }
494
495 static INLINE unsigned
496 d3dblend_color_to_pipe_blendfactor(D3DBLEND b)
497 {
498 switch (b) {
499 case D3DBLEND_ZERO: return PIPE_BLENDFACTOR_ZERO;
500 case D3DBLEND_ONE: return PIPE_BLENDFACTOR_ONE;
501 case D3DBLEND_SRCCOLOR: return PIPE_BLENDFACTOR_SRC_COLOR;
502 case D3DBLEND_INVSRCCOLOR: return PIPE_BLENDFACTOR_INV_SRC_COLOR;
503 case D3DBLEND_SRCALPHA: return PIPE_BLENDFACTOR_SRC_ALPHA;
504 case D3DBLEND_INVSRCALPHA: return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
505 case D3DBLEND_DESTALPHA: return PIPE_BLENDFACTOR_DST_ALPHA;
506 case D3DBLEND_INVDESTALPHA: return PIPE_BLENDFACTOR_INV_DST_ALPHA;
507 case D3DBLEND_DESTCOLOR: return PIPE_BLENDFACTOR_DST_COLOR;
508 case D3DBLEND_INVDESTCOLOR: return PIPE_BLENDFACTOR_INV_DST_COLOR;
509 case D3DBLEND_SRCALPHASAT: return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
510 case D3DBLEND_BOTHSRCALPHA: return PIPE_BLENDFACTOR_SRC_ALPHA;
511 case D3DBLEND_BOTHINVSRCALPHA: return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
512 case D3DBLEND_BLENDFACTOR: return PIPE_BLENDFACTOR_CONST_COLOR;
513 case D3DBLEND_INVBLENDFACTOR: return PIPE_BLENDFACTOR_INV_CONST_COLOR;
514 case D3DBLEND_SRCCOLOR2: return PIPE_BLENDFACTOR_SRC1_COLOR;
515 case D3DBLEND_INVSRCCOLOR2: return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
516 default:
517 DBG_FLAG(DBG_UNKNOWN, "Unhandled blend factor %d\n", b);
518 return PIPE_BLENDFACTOR_ZERO;
519 }
520 }
521
522 static INLINE unsigned
523 d3dtextureaddress_to_pipe_tex_wrap(D3DTEXTUREADDRESS addr)
524 {
525 switch (addr) {
526 case D3DTADDRESS_WRAP: return PIPE_TEX_WRAP_REPEAT;
527 case D3DTADDRESS_MIRROR: return PIPE_TEX_WRAP_MIRROR_REPEAT;
528 case D3DTADDRESS_CLAMP: return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
529 case D3DTADDRESS_BORDER: return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
530 case D3DTADDRESS_MIRRORONCE: return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
531 default:
532 assert(0);
533 return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
534 }
535 }
536
537 static INLINE unsigned
538 d3dtexturefiltertype_to_pipe_tex_filter(D3DTEXTUREFILTERTYPE filter)
539 {
540 switch (filter) {
541 case D3DTEXF_POINT: return PIPE_TEX_FILTER_NEAREST;
542 case D3DTEXF_LINEAR: return PIPE_TEX_FILTER_LINEAR;
543 case D3DTEXF_ANISOTROPIC: return PIPE_TEX_FILTER_LINEAR;
544
545 case D3DTEXF_NONE:
546 case D3DTEXF_PYRAMIDALQUAD:
547 case D3DTEXF_GAUSSIANQUAD:
548 case D3DTEXF_CONVOLUTIONMONO:
549 default:
550 assert(0);
551 return PIPE_TEX_FILTER_NEAREST;
552 }
553 }
554
555 static INLINE unsigned
556 d3dtexturefiltertype_to_pipe_tex_mipfilter(D3DTEXTUREFILTERTYPE filter)
557 {
558 switch (filter) {
559 case D3DTEXF_NONE: return PIPE_TEX_MIPFILTER_NONE;
560 case D3DTEXF_POINT: return PIPE_TEX_FILTER_NEAREST;
561 case D3DTEXF_LINEAR: return PIPE_TEX_FILTER_LINEAR;
562 case D3DTEXF_ANISOTROPIC: return PIPE_TEX_FILTER_LINEAR;
563
564 case D3DTEXF_PYRAMIDALQUAD:
565 case D3DTEXF_GAUSSIANQUAD:
566 case D3DTEXF_CONVOLUTIONMONO:
567 default:
568 assert(0);
569 return PIPE_TEX_MIPFILTER_NONE;
570 }
571 }
572
573 #endif /* _NINE_PIPE_H_ */