r300: add half_float_vertex support
[mesa.git] / src / gallium / drivers / r300 / r300_state_inlines.h
1 /*
2 * Copyright 2009 Joakim Sindholt <opensource@zhasha.com>
3 * Corbin Simpson <MostAwesomeDude@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #ifndef R300_STATE_INLINES_H
25 #define R300_STATE_INLINES_H
26
27 #include "draw/draw_vertex.h"
28
29 #include "pipe/p_format.h"
30
31 #include "util/u_format.h"
32
33 #include "r300_reg.h"
34
35 /* Some maths. These should probably find their way to u_math, if needed. */
36
37 static INLINE int pack_float_16_6x(float f) {
38 return ((int)(f * 6.0) & 0xffff);
39 }
40
41 /* Blend state. */
42
43 static INLINE uint32_t r300_translate_blend_function(int blend_func)
44 {
45 switch (blend_func) {
46 case PIPE_BLEND_ADD:
47 return R300_COMB_FCN_ADD_CLAMP;
48 case PIPE_BLEND_SUBTRACT:
49 return R300_COMB_FCN_SUB_CLAMP;
50 case PIPE_BLEND_REVERSE_SUBTRACT:
51 return R300_COMB_FCN_RSUB_CLAMP;
52 case PIPE_BLEND_MIN:
53 return R300_COMB_FCN_MIN;
54 case PIPE_BLEND_MAX:
55 return R300_COMB_FCN_MAX;
56 default:
57 debug_printf("r300: Unknown blend function %d\n", blend_func);
58 assert(0);
59 break;
60 }
61 return 0;
62 }
63
64 /* XXX we can also offer the D3D versions of some of these... */
65 static INLINE uint32_t r300_translate_blend_factor(int blend_fact)
66 {
67 switch (blend_fact) {
68 case PIPE_BLENDFACTOR_ONE:
69 return R300_BLEND_GL_ONE;
70 case PIPE_BLENDFACTOR_SRC_COLOR:
71 return R300_BLEND_GL_SRC_COLOR;
72 case PIPE_BLENDFACTOR_SRC_ALPHA:
73 return R300_BLEND_GL_SRC_ALPHA;
74 case PIPE_BLENDFACTOR_DST_ALPHA:
75 return R300_BLEND_GL_DST_ALPHA;
76 case PIPE_BLENDFACTOR_DST_COLOR:
77 return R300_BLEND_GL_DST_COLOR;
78 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
79 return R300_BLEND_GL_SRC_ALPHA_SATURATE;
80 case PIPE_BLENDFACTOR_CONST_COLOR:
81 return R300_BLEND_GL_CONST_COLOR;
82 case PIPE_BLENDFACTOR_CONST_ALPHA:
83 return R300_BLEND_GL_CONST_ALPHA;
84 case PIPE_BLENDFACTOR_ZERO:
85 return R300_BLEND_GL_ZERO;
86 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
87 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR;
88 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
89 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA;
90 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
91 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA;
92 case PIPE_BLENDFACTOR_INV_DST_COLOR:
93 return R300_BLEND_GL_ONE_MINUS_DST_COLOR;
94 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
95 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR;
96 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
97 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA;
98
99 case PIPE_BLENDFACTOR_SRC1_COLOR:
100 case PIPE_BLENDFACTOR_SRC1_ALPHA:
101 case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
102 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
103 debug_printf("r300: Implementation error: "
104 "Bad blend factor %d not supported!\n", blend_fact);
105 assert(0);
106 break;
107
108 default:
109 debug_printf("r300: Unknown blend factor %d\n", blend_fact);
110 assert(0);
111 break;
112 }
113 return 0;
114 }
115
116 /* DSA state. */
117
118 static INLINE uint32_t r300_translate_depth_stencil_function(int zs_func)
119 {
120 switch (zs_func) {
121 case PIPE_FUNC_NEVER:
122 return R300_ZS_NEVER;
123 case PIPE_FUNC_LESS:
124 return R300_ZS_LESS;
125 case PIPE_FUNC_EQUAL:
126 return R300_ZS_EQUAL;
127 case PIPE_FUNC_LEQUAL:
128 return R300_ZS_LEQUAL;
129 case PIPE_FUNC_GREATER:
130 return R300_ZS_GREATER;
131 case PIPE_FUNC_NOTEQUAL:
132 return R300_ZS_NOTEQUAL;
133 case PIPE_FUNC_GEQUAL:
134 return R300_ZS_GEQUAL;
135 case PIPE_FUNC_ALWAYS:
136 return R300_ZS_ALWAYS;
137 default:
138 debug_printf("r300: Unknown depth/stencil function %d\n",
139 zs_func);
140 assert(0);
141 break;
142 }
143 return 0;
144 }
145
146 static INLINE uint32_t r300_translate_stencil_op(int s_op)
147 {
148 switch (s_op) {
149 case PIPE_STENCIL_OP_KEEP:
150 return R300_ZS_KEEP;
151 case PIPE_STENCIL_OP_ZERO:
152 return R300_ZS_ZERO;
153 case PIPE_STENCIL_OP_REPLACE:
154 return R300_ZS_REPLACE;
155 case PIPE_STENCIL_OP_INCR:
156 return R300_ZS_INCR;
157 case PIPE_STENCIL_OP_DECR:
158 return R300_ZS_DECR;
159 case PIPE_STENCIL_OP_INCR_WRAP:
160 return R300_ZS_INCR_WRAP;
161 case PIPE_STENCIL_OP_DECR_WRAP:
162 return R300_ZS_DECR_WRAP;
163 case PIPE_STENCIL_OP_INVERT:
164 return R300_ZS_INVERT;
165 default:
166 debug_printf("r300: Unknown stencil op %d", s_op);
167 assert(0);
168 break;
169 }
170 return 0;
171 }
172
173 static INLINE uint32_t r300_translate_alpha_function(int alpha_func)
174 {
175 switch (alpha_func) {
176 case PIPE_FUNC_NEVER:
177 return R300_FG_ALPHA_FUNC_NEVER;
178 case PIPE_FUNC_LESS:
179 return R300_FG_ALPHA_FUNC_LESS;
180 case PIPE_FUNC_EQUAL:
181 return R300_FG_ALPHA_FUNC_EQUAL;
182 case PIPE_FUNC_LEQUAL:
183 return R300_FG_ALPHA_FUNC_LE;
184 case PIPE_FUNC_GREATER:
185 return R300_FG_ALPHA_FUNC_GREATER;
186 case PIPE_FUNC_NOTEQUAL:
187 return R300_FG_ALPHA_FUNC_NOTEQUAL;
188 case PIPE_FUNC_GEQUAL:
189 return R300_FG_ALPHA_FUNC_GE;
190 case PIPE_FUNC_ALWAYS:
191 return R300_FG_ALPHA_FUNC_ALWAYS;
192 default:
193 debug_printf("r300: Unknown alpha function %d", alpha_func);
194 assert(0);
195 break;
196 }
197 return 0;
198 }
199
200 static INLINE uint32_t
201 r300_translate_polygon_mode_front(unsigned mode) {
202 switch (mode)
203 {
204 case PIPE_POLYGON_MODE_FILL:
205 return R300_GA_POLY_MODE_FRONT_PTYPE_TRI;
206 case PIPE_POLYGON_MODE_LINE:
207 return R300_GA_POLY_MODE_FRONT_PTYPE_LINE;
208 case PIPE_POLYGON_MODE_POINT:
209 return R300_GA_POLY_MODE_FRONT_PTYPE_POINT;
210
211 default:
212 debug_printf("r300: Bad polygon mode %i in %s\n", mode,
213 __FUNCTION__);
214 return R300_GA_POLY_MODE_FRONT_PTYPE_TRI;
215 }
216 }
217
218 static INLINE uint32_t
219 r300_translate_polygon_mode_back(unsigned mode) {
220 switch (mode)
221 {
222 case PIPE_POLYGON_MODE_FILL:
223 return R300_GA_POLY_MODE_BACK_PTYPE_TRI;
224 case PIPE_POLYGON_MODE_LINE:
225 return R300_GA_POLY_MODE_BACK_PTYPE_LINE;
226 case PIPE_POLYGON_MODE_POINT:
227 return R300_GA_POLY_MODE_BACK_PTYPE_POINT;
228
229 default:
230 debug_printf("r300: Bad polygon mode %i in %s\n", mode,
231 __FUNCTION__);
232 return R300_GA_POLY_MODE_BACK_PTYPE_TRI;
233 }
234 }
235
236 /* Texture sampler state. */
237
238 static INLINE uint32_t r300_translate_wrap(int wrap)
239 {
240 switch (wrap) {
241 case PIPE_TEX_WRAP_REPEAT:
242 return R300_TX_REPEAT;
243 case PIPE_TEX_WRAP_CLAMP:
244 return R300_TX_CLAMP;
245 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
246 return R300_TX_CLAMP_TO_EDGE;
247 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
248 return R300_TX_CLAMP_TO_BORDER;
249 case PIPE_TEX_WRAP_MIRROR_REPEAT:
250 return R300_TX_REPEAT | R300_TX_MIRRORED;
251 case PIPE_TEX_WRAP_MIRROR_CLAMP:
252 return R300_TX_CLAMP | R300_TX_MIRRORED;
253 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
254 return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
255 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
256 return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED;
257 default:
258 debug_printf("r300: Unknown texture wrap %d", wrap);
259 assert(0);
260 return 0;
261 }
262 }
263
264 static INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip,
265 int is_anisotropic)
266 {
267 uint32_t retval = 0;
268 if (is_anisotropic)
269 retval |= R300_TX_MIN_FILTER_ANISO | R300_TX_MAG_FILTER_ANISO;
270 else {
271 switch (min) {
272 case PIPE_TEX_FILTER_NEAREST:
273 retval |= R300_TX_MIN_FILTER_NEAREST;
274 break;
275 case PIPE_TEX_FILTER_LINEAR:
276 retval |= R300_TX_MIN_FILTER_LINEAR;
277 break;
278 default:
279 debug_printf("r300: Unknown texture filter %d\n", min);
280 assert(0);
281 break;
282 }
283 switch (mag) {
284 case PIPE_TEX_FILTER_NEAREST:
285 retval |= R300_TX_MAG_FILTER_NEAREST;
286 break;
287 case PIPE_TEX_FILTER_LINEAR:
288 retval |= R300_TX_MAG_FILTER_LINEAR;
289 break;
290 default:
291 debug_printf("r300: Unknown texture filter %d\n", mag);
292 assert(0);
293 break;
294 }
295 }
296 switch (mip) {
297 case PIPE_TEX_MIPFILTER_NONE:
298 retval |= R300_TX_MIN_FILTER_MIP_NONE;
299 break;
300 case PIPE_TEX_MIPFILTER_NEAREST:
301 retval |= R300_TX_MIN_FILTER_MIP_NEAREST;
302 break;
303 case PIPE_TEX_MIPFILTER_LINEAR:
304 retval |= R300_TX_MIN_FILTER_MIP_LINEAR;
305 break;
306 default:
307 debug_printf("r300: Unknown texture filter %d\n", mip);
308 assert(0);
309 break;
310 }
311
312 return retval;
313 }
314
315 static INLINE uint32_t r300_anisotropy(unsigned max_aniso)
316 {
317 if (max_aniso >= 16) {
318 return R300_TX_MAX_ANISO_16_TO_1;
319 } else if (max_aniso >= 8) {
320 return R300_TX_MAX_ANISO_8_TO_1;
321 } else if (max_aniso >= 4) {
322 return R300_TX_MAX_ANISO_4_TO_1;
323 } else if (max_aniso >= 2) {
324 return R300_TX_MAX_ANISO_2_TO_1;
325 } else {
326 return R300_TX_MAX_ANISO_1_TO_1;
327 }
328 }
329
330 /* Buffer formats. */
331
332 /* Colorbuffer formats. This is the unswizzled format of the RB3D block's
333 * output. For the swizzling of the targets, check the shader's format. */
334 static INLINE uint32_t r300_translate_colorformat(enum pipe_format format)
335 {
336 switch (format) {
337 /* 8-bit buffers */
338 case PIPE_FORMAT_A8_UNORM:
339 case PIPE_FORMAT_I8_UNORM:
340 case PIPE_FORMAT_L8_UNORM:
341 /* case PIPE_FORMAT_S8_UNORM: ??? */
342 return R300_COLOR_FORMAT_I8;
343 /* 16-bit buffers */
344 case PIPE_FORMAT_R5G6B5_UNORM:
345 return R300_COLOR_FORMAT_RGB565;
346 case PIPE_FORMAT_A1R5G5B5_UNORM:
347 return R300_COLOR_FORMAT_ARGB1555;
348 case PIPE_FORMAT_A4R4G4B4_UNORM:
349 return R300_COLOR_FORMAT_ARGB4444;
350 /* 32-bit buffers */
351 case PIPE_FORMAT_A8R8G8B8_UNORM:
352 case PIPE_FORMAT_X8R8G8B8_UNORM:
353 case PIPE_FORMAT_R8G8B8A8_UNORM:
354 case PIPE_FORMAT_R8G8B8X8_UNORM:
355 return R300_COLOR_FORMAT_ARGB8888;
356 /* XXX Not in pipe_format
357 case PIPE_FORMAT_A32R32G32B32:
358 return R300_COLOR_FORMAT_ARGB32323232;
359 case PIPE_FORMAT_A16R16G16B16:
360 return R300_COLOR_FORMAT_ARGB16161616;
361 case PIPE_FORMAT_A10R10G10B10_UNORM:
362 return R500_COLOR_FORMAT_ARGB10101010;
363 case PIPE_FORMAT_A2R10G10B10_UNORM:
364 return R500_COLOR_FORMAT_ARGB2101010;
365 case PIPE_FORMAT_I10_UNORM:
366 return R500_COLOR_FORMAT_I10; */
367 default:
368 debug_printf("r300: Implementation error: "
369 "Got unsupported color format %s in %s\n",
370 util_format_name(format), __FUNCTION__);
371 assert(0);
372 break;
373 }
374 return 0;
375 }
376
377 /* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */
378 static INLINE uint32_t r300_translate_zsformat(enum pipe_format format)
379 {
380 switch (format) {
381 /* 16-bit depth, no stencil */
382 case PIPE_FORMAT_Z16_UNORM:
383 return R300_DEPTHFORMAT_16BIT_INT_Z;
384 /* 24-bit depth, ignored stencil */
385 case PIPE_FORMAT_Z24X8_UNORM:
386 /* 24-bit depth, 8-bit stencil */
387 case PIPE_FORMAT_Z24S8_UNORM:
388 return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL;
389 default:
390 debug_printf("r300: Implementation error: "
391 "Got unsupported ZS format %s in %s\n",
392 util_format_name(format), __FUNCTION__);
393 assert(0);
394 break;
395 }
396 return 0;
397 }
398
399 /* Shader output formats. This is essentially the swizzle from the shader
400 * to the RB3D block.
401 *
402 * Note that formats are stored from C3 to C0. */
403 static INLINE uint32_t r300_translate_out_fmt(enum pipe_format format)
404 {
405 switch (format) {
406 case PIPE_FORMAT_R5G6B5_UNORM:
407 /* C_5_6_5 is missing in US_OUT_FMT, but C4_8 works just fine. */
408 case PIPE_FORMAT_A1R5G5B5_UNORM:
409 /* C_1_5_5_5 is missing in US_OUT_FMT, but C4_8 works just fine. */
410 case PIPE_FORMAT_A4R4G4B4_UNORM:
411 /* C4_4 is missing in US_OUT_FMT, but C4_8 works just fine. */
412 case PIPE_FORMAT_A8R8G8B8_UNORM:
413 case PIPE_FORMAT_X8R8G8B8_UNORM:
414 return R300_US_OUT_FMT_C4_8 |
415 R300_C0_SEL_B | R300_C1_SEL_G |
416 R300_C2_SEL_R | R300_C3_SEL_A;
417 case PIPE_FORMAT_R8G8B8A8_UNORM:
418 case PIPE_FORMAT_R8G8B8X8_UNORM:
419 return R300_US_OUT_FMT_C4_8 |
420 R300_C0_SEL_A | R300_C1_SEL_B |
421 R300_C2_SEL_G | R300_C3_SEL_R;
422
423 /* 8-bit outputs */
424 case PIPE_FORMAT_A8_UNORM:
425 return R300_US_OUT_FMT_C4_8 |
426 R300_C0_SEL_A;
427 case PIPE_FORMAT_I8_UNORM:
428 case PIPE_FORMAT_L8_UNORM:
429 return R300_US_OUT_FMT_C4_8 |
430 R300_C0_SEL_R;
431 /* R300_OUT_SIGN(x) */
432 default:
433 debug_printf("r300: Implementation error: "
434 "Got unsupported output format %s in %s\n",
435 util_format_name(format), __FUNCTION__);
436 assert(0);
437 return R300_US_OUT_FMT_UNUSED;
438 }
439 return 0;
440 }
441
442 /* Non-CSO state. (For now.) */
443
444 static INLINE uint32_t r300_translate_gb_pipes(int pipe_count)
445 {
446 switch (pipe_count) {
447 case 1:
448 return R300_GB_TILE_PIPE_COUNT_RV300;
449 break;
450 case 2:
451 return R300_GB_TILE_PIPE_COUNT_R300;
452 break;
453 case 3:
454 return R300_GB_TILE_PIPE_COUNT_R420_3P;
455 break;
456 case 4:
457 return R300_GB_TILE_PIPE_COUNT_R420;
458 break;
459 }
460 return 0;
461 }
462
463 /* Utility function to count the number of components in RGBAZS formats.
464 * XXX should go to util or p_format.h */
465 static INLINE unsigned pf_component_count(enum pipe_format format) {
466 unsigned count = 0;
467
468 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
469 count++;
470 }
471 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 1)) {
472 count++;
473 }
474 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 2)) {
475 count++;
476 }
477 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3)) {
478 count++;
479 }
480 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0)) {
481 count++;
482 }
483 if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
484 count++;
485 }
486
487 return count;
488 }
489
490 /* Translate pipe_formats into PSC vertex types. */
491 static INLINE uint16_t
492 r300_translate_vertex_data_type(enum pipe_format format) {
493 uint32_t result = 0;
494 const struct util_format_description *desc;
495 unsigned components = pf_component_count(format);
496
497 desc = util_format_description(format);
498
499 if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
500 desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) {
501 debug_printf("r300: Bad format %s in %s:%d\n", util_format_name(format),
502 __FUNCTION__, __LINE__);
503 assert(0);
504 }
505
506 switch (desc->channel[0].type) {
507 /* Half-floats, floats, doubles */
508 case UTIL_FORMAT_TYPE_FLOAT:
509 switch (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
510 case 16:
511 /* XXX Supported only on RV350 and later. */
512 if (components > 2) {
513 result = R300_DATA_TYPE_FLT16_4;
514 } else {
515 result = R300_DATA_TYPE_FLT16_2;
516 }
517 break;
518 case 32:
519 result = R300_DATA_TYPE_FLOAT_1 + (components - 1);
520 break;
521 default:
522 debug_printf("r300: Bad format %s in %s:%d\n",
523 util_format_name(format), __FUNCTION__, __LINE__);
524 assert(0);
525 }
526 break;
527 /* Unsigned ints */
528 case UTIL_FORMAT_TYPE_UNSIGNED:
529 /* Signed ints */
530 case UTIL_FORMAT_TYPE_SIGNED:
531 switch (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
532 case 8:
533 result = R300_DATA_TYPE_BYTE;
534 break;
535 case 16:
536 if (components > 2) {
537 result = R300_DATA_TYPE_SHORT_4;
538 } else {
539 result = R300_DATA_TYPE_SHORT_2;
540 }
541 break;
542 default:
543 debug_printf("r300: Bad format %s in %s:%d\n",
544 util_format_name(format), __FUNCTION__, __LINE__);
545 debug_printf("r300: util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) == %d\n",
546 util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0));
547 assert(0);
548 }
549 break;
550 default:
551 debug_printf("r300: Bad format %s in %s:%d\n",
552 util_format_name(format), __FUNCTION__, __LINE__);
553 assert(0);
554 }
555
556 if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
557 result |= R300_SIGNED;
558 }
559 if (desc->channel[0].normalized) {
560 result |= R300_NORMALIZE;
561 }
562
563 return result;
564 }
565
566 static INLINE uint16_t
567 r300_translate_vertex_data_swizzle(enum pipe_format format) {
568 const struct util_format_description *desc = util_format_description(format);
569 unsigned swizzle[4], i;
570
571 assert(format);
572
573 if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
574 desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) {
575 debug_printf("r300: Bad format %s in %s:%d\n",
576 util_format_name(format), __FUNCTION__, __LINE__);
577 return 0;
578 }
579
580 /* Swizzles for 8bits formats are in the reversed order, not sure why. */
581 if (desc->channel[0].size == 8) {
582 for (i = 0; i < 4; i++) {
583 if (desc->swizzle[i] <= 3) {
584 swizzle[i] = 3 - desc->swizzle[i];
585 } else {
586 swizzle[i] = desc->swizzle[i];
587 }
588 }
589 } else {
590 for (i = 0; i < 4; i++) {
591 swizzle[i] = desc->swizzle[i];
592 }
593 }
594
595 return ((swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) |
596 (swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) |
597 (swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) |
598 (swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) |
599 (0xf << R300_WRITE_ENA_SHIFT));
600 }
601
602 #endif /* R300_STATE_INLINES_H */