spantmp2: Silence many "warning: unused parameter ‘ctx’"
[mesa.git] / src / mesa / drivers / dri / common / spantmp2.h
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * (C) Copyright IBM Corporation 2004
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 "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file spantmp2.h
28 *
29 * Template file of span read / write functions.
30 *
31 * \author Keith Whitwell <keithw@tungstengraphics.com>
32 * \author Gareth Hughes <gareth@nvidia.com>
33 * \author Ian Romanick <idr@us.ibm.com>
34 */
35
36 #include "main/colormac.h"
37 #include "spantmp_common.h"
38
39 #ifndef DBG
40 #define DBG 0
41 #endif
42
43 #ifndef HW_READ_CLIPLOOP
44 #define HW_READ_CLIPLOOP() HW_CLIPLOOP()
45 #endif
46
47 #ifndef HW_WRITE_CLIPLOOP
48 #define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
49 #endif
50
51 #if (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
52
53 /**
54 ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5
55 **/
56
57 #ifndef GET_VALUE
58 #ifndef GET_PTR
59 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
60 #endif
61
62 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
63 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
64 #endif /* GET_VALUE */
65
66 #define INIT_MONO_PIXEL(p, color) \
67 p = PACK_COLOR_565( color[0], color[1], color[2] )
68
69 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
70 PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) | \
71 (((int)g & 0xfc) << 3) | \
72 (((int)b & 0xf8) >> 3))) \
73
74 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
75
76 #define READ_RGBA( rgba, _x, _y ) \
77 do { \
78 GLushort p = GET_VALUE(_x, _y); \
79 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
80 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
81 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
82 rgba[3] = 0xff; \
83 } while (0)
84
85 #elif (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV)
86
87 /**
88 ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV
89 **/
90
91 #ifndef GET_VALUE
92 #ifndef GET_PTR
93 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
94 #endif
95
96 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
97 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
98 #endif /* GET_VALUE */
99
100 #define INIT_MONO_PIXEL(p, color) \
101 p = PACK_COLOR_565_REV( color[0], color[1], color[2] )
102
103 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
104 PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b ))
105
106 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
107
108 #define READ_RGBA( rgba, _x, _y ) \
109 do { \
110 GLushort p = GET_VALUE(_x, _y); \
111 p = p << 8 | p >> 8; \
112 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
113 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
114 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
115 rgba[3] = 0xff; \
116 } while (0)
117
118 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4)
119
120 /**
121 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4
122 **/
123
124 #ifndef GET_VALUE
125 #ifndef GET_PTR
126 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
127 #endif
128
129 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
130 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
131 #endif /* GET_VALUE */
132
133 #define INIT_MONO_PIXEL(p, color) \
134 p = PACK_COLOR_4444_REV(color[3], color[0], color[1], color[2])
135
136 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
137 PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b)) \
138
139 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
140
141 #define READ_RGBA( rgba, _x, _y ) \
142 do { \
143 GLushort p = GET_VALUE(_x, _y); \
144 rgba[0] = ((p >> 0) & 0xf) * 0x11; \
145 rgba[1] = ((p >> 12) & 0xf) * 0x11; \
146 rgba[2] = ((p >> 4) & 0xf) * 0x11; \
147 rgba[3] = ((p >> 8) & 0xf) * 0x11; \
148 } while (0)
149
150
151 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV)
152
153 /**
154 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV
155 **/
156
157 #ifndef GET_VALUE
158 #ifndef GET_PTR
159 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
160 #endif
161
162 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
163 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
164 #endif /* GET_VALUE */
165
166 #define INIT_MONO_PIXEL(p, color) \
167 p = PACK_COLOR_4444(color[3], color[0], color[1], color[2])
168
169 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
170 PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b)) \
171
172 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
173
174 #define READ_RGBA( rgba, _x, _y ) \
175 do { \
176 GLushort p = GET_VALUE(_x, _y); \
177 rgba[0] = ((p >> 8) & 0xf) * 0x11; \
178 rgba[1] = ((p >> 4) & 0xf) * 0x11; \
179 rgba[2] = ((p >> 0) & 0xf) * 0x11; \
180 rgba[3] = ((p >> 12) & 0xf) * 0x11; \
181 } while (0)
182
183
184 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV)
185
186 /**
187 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
188 **/
189
190 #ifndef GET_VALUE
191 #ifndef GET_PTR
192 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
193 #endif
194
195 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
196 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
197 #endif /* GET_VALUE */
198
199 #define INIT_MONO_PIXEL(p, color) \
200 p = PACK_COLOR_1555(color[3], color[0], color[1], color[2])
201
202 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
203 PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b)) \
204
205 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
206
207 #define READ_RGBA( rgba, _x, _y ) \
208 do { \
209 GLushort p = GET_VALUE(_x, _y); \
210 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
211 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
212 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
213 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
214 } while (0)
215
216 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5)
217
218 /**
219 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5
220 **/
221
222 #ifndef GET_VALUE
223 #ifndef GET_PTR
224 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
225 #endif
226
227 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
228 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
229 #endif /* GET_VALUE */
230
231 #define INIT_MONO_PIXEL(p, color) \
232 p = PACK_COLOR_1555_REV(color[3], color[0], color[1], color[2])
233
234 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
235 PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b)) \
236
237 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
238
239 #define READ_RGBA( rgba, _x, _y ) \
240 do { \
241 GLushort p = GET_VALUE(_x, _y); \
242 p = p << 8 | p >> 8; \
243 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
244 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
245 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
246 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
247 } while (0)
248
249 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
250
251 /**
252 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV
253 **/
254
255 #ifndef GET_VALUE
256 #ifndef GET_PTR
257 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
258 #endif
259
260 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
261 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
262 #endif /* GET_VALUE */
263
264 # define INIT_MONO_PIXEL(p, color) \
265 p = PACK_COLOR_8888(color[3], color[0], color[1], color[2])
266
267 # define WRITE_RGBA(_x, _y, r, g, b, a) \
268 PUT_VALUE(_x, _y, ((r << 16) | \
269 (g << 8) | \
270 (b << 0) | \
271 (a << 24)))
272
273 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
274
275 # if defined( USE_X86_ASM )
276 # define READ_RGBA(rgba, _x, _y) \
277 do { \
278 GLuint p = GET_VALUE(_x, _y); \
279 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
280 : "=r" (p) : "0" (p) ); \
281 ((GLuint *)rgba)[0] = p; \
282 } while (0)
283 # elif defined( MESA_BIG_ENDIAN )
284 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
285 * rotlwi instruction. It also produces good code on SPARC.
286 */
287 # define READ_RGBA( rgba, _x, _y ) \
288 do { \
289 GLuint p = GET_VALUE(_x, _y); \
290 GLuint t = p; \
291 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
292 } while (0)
293 # else
294 # define READ_RGBA( rgba, _x, _y ) \
295 do { \
296 GLuint p = GET_VALUE(_x, _y); \
297 rgba[0] = (p >> 16) & 0xff; \
298 rgba[1] = (p >> 8) & 0xff; \
299 rgba[2] = (p >> 0) & 0xff; \
300 rgba[3] = (p >> 24) & 0xff; \
301 } while (0)
302 # endif
303
304 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8)
305
306 /**
307 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8
308 **/
309
310 #ifndef GET_VALUE
311 #ifndef GET_PTR
312 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
313 #endif
314
315 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
316 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
317 #endif /* GET_VALUE */
318
319 # define INIT_MONO_PIXEL(p, color) \
320 p = PACK_COLOR_8888(color[2], color[1], color[0], color[3])
321
322 # define WRITE_RGBA(_x, _y, r, g, b, a) \
323 PUT_VALUE(_x, _y, ((r << 8) | \
324 (g << 16) | \
325 (b << 24) | \
326 (a << 0)))
327
328 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
329
330 # if defined( USE_X86_ASM )
331 # define READ_RGBA(rgba, _x, _y) \
332 do { \
333 GLuint p = GET_VALUE(_x, _y); \
334 __asm__ __volatile__( "rorl $8, %0" \
335 : "=r" (p) : "0" (p) ); \
336 ((GLuint *)rgba)[0] = p; \
337 } while (0)
338 # elif defined( MESA_BIG_ENDIAN )
339 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
340 * rotlwi instruction. It also produces good code on SPARC.
341 */
342 # define READ_RGBA( rgba, _x, _y ) \
343 do { \
344 GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y)); \
345 GLuint t = p; \
346 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
347 } while (0)
348 # else
349 # define READ_RGBA( rgba, _x, _y ) \
350 do { \
351 GLuint p = GET_VALUE(_x, _y); \
352 rgba[0] = (p >> 8) & 0xff; \
353 rgba[1] = (p >> 16) & 0xff; \
354 rgba[2] = (p >> 24) & 0xff; \
355 rgba[3] = (p >> 0) & 0xff; \
356 } while (0)
357 # endif
358
359 #elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
360
361 /**
362 ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV
363 **
364 ** This is really for MESA_FORMAT_XRGB8888. The spantmp code needs to be
365 ** kicked to the curb, and we need to just code-gen this.
366 **/
367
368 #ifndef GET_VALUE
369 #ifndef GET_PTR
370 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
371 #endif
372
373 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
374 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
375 #endif /* GET_VALUE */
376
377 # define INIT_MONO_PIXEL(p, color) \
378 p = PACK_COLOR_8888(0xff, color[0], color[1], color[2])
379
380 # define WRITE_RGBA(_x, _y, r, g, b, a) \
381 PUT_VALUE(_x, _y, ((r << 16) | \
382 (g << 8) | \
383 (b << 0) | \
384 (0xff << 24)))
385
386 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
387
388 # if defined( USE_X86_ASM )
389 # define READ_RGBA(rgba, _x, _y) \
390 do { \
391 GLuint p = GET_VALUE(_x, _y); \
392 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
393 : "=r" (p) : "0" (p) ); \
394 ((GLuint *)rgba)[0] = p | 0xff000000; \
395 } while (0)
396 # elif defined( MESA_BIG_ENDIAN )
397 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
398 * rotlwi instruction. It also produces good code on SPARC.
399 */
400 # define READ_RGBA( rgba, _x, _y ) \
401 do { \
402 GLuint p = GET_VALUE(_x, _y); \
403 *((uint32_t *) rgba) = (p << 8) | 0xff; \
404 } while (0)
405 # else
406 # define READ_RGBA( rgba, _x, _y ) \
407 do { \
408 GLuint p = GET_VALUE(_x, _y); \
409 rgba[0] = (p >> 16) & 0xff; \
410 rgba[1] = (p >> 8) & 0xff; \
411 rgba[2] = (p >> 0) & 0xff; \
412 rgba[3] = 0xff; \
413 } while (0)
414 # endif
415
416 #elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE)
417
418 /**
419 ** GL_ALPHA, GL_UNSIGNED_BYTE
420 **/
421
422 #ifndef GET_VALUE
423 #ifndef GET_PTR
424 #define GET_PTR(_x, _y) ( buf + (_x) + (_y) * pitch)
425 #endif
426
427 #define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y))
428 #define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v)
429 #endif /* GET_VALUE */
430
431 # define INIT_MONO_PIXEL(p, color) \
432 p = color[3]
433
434 # define WRITE_RGBA(_x, _y, r, g, b, a) \
435 PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */))
436
437 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
438
439 #define READ_RGBA( rgba, _x, _y ) \
440 do { \
441 GLubyte p = GET_VALUE(_x, _y); \
442 rgba[0] = 0; \
443 rgba[1] = 0; \
444 rgba[2] = 0; \
445 rgba[3] = p; \
446 } while (0)
447
448 #else
449 #error SPANTMP_PIXEL_FMT must be set to a valid value!
450 #endif
451
452
453
454 /**
455 ** Assembly routines.
456 **/
457
458 #if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM )
459 #include "x86/read_rgba_span_x86.h"
460 #include "x86/common_x86_asm.h"
461 #endif
462
463 static void TAG(WriteRGBASpan)( struct gl_context *ctx,
464 struct gl_renderbuffer *rb,
465 GLuint n, GLint x, GLint y,
466 const void *values, const GLubyte mask[] )
467 {
468 (void) ctx;
469
470 HW_WRITE_LOCK()
471 {
472 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
473 GLint x1;
474 GLint n1;
475 LOCAL_VARS;
476
477 y = Y_FLIP(y);
478
479 HW_WRITE_CLIPLOOP()
480 {
481 GLint i = 0;
482 CLIPSPAN(x,y,n,x1,n1,i);
483
484 if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
485 (int)i, (int)n1, (int)x1);
486
487 if (mask)
488 {
489 for (;n1>0;i++,x1++,n1--)
490 if (mask[i])
491 WRITE_RGBA( x1, y,
492 rgba[i][0], rgba[i][1],
493 rgba[i][2], rgba[i][3] );
494 }
495 else
496 {
497 for (;n1>0;i++,x1++,n1--)
498 WRITE_RGBA( x1, y,
499 rgba[i][0], rgba[i][1],
500 rgba[i][2], rgba[i][3] );
501 }
502 }
503 HW_ENDCLIPLOOP();
504 }
505 HW_WRITE_UNLOCK();
506 }
507
508 static void TAG(WriteRGBSpan)( struct gl_context *ctx,
509 struct gl_renderbuffer *rb,
510 GLuint n, GLint x, GLint y,
511 const void *values, const GLubyte mask[] )
512 {
513 (void) ctx;
514
515 HW_WRITE_LOCK()
516 {
517 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
518 GLint x1;
519 GLint n1;
520 LOCAL_VARS;
521
522 y = Y_FLIP(y);
523
524 HW_WRITE_CLIPLOOP()
525 {
526 GLint i = 0;
527 CLIPSPAN(x,y,n,x1,n1,i);
528
529 if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
530 (int)i, (int)n1, (int)x1);
531
532 if (mask)
533 {
534 for (;n1>0;i++,x1++,n1--)
535 if (mask[i])
536 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
537 }
538 else
539 {
540 for (;n1>0;i++,x1++,n1--)
541 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
542 }
543 }
544 HW_ENDCLIPLOOP();
545 }
546 HW_WRITE_UNLOCK();
547 }
548
549 static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
550 struct gl_renderbuffer *rb,
551 GLuint n, const GLint x[], const GLint y[],
552 const void *values, const GLubyte mask[] )
553 {
554 (void) ctx;
555
556 HW_WRITE_LOCK()
557 {
558 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
559 GLint i;
560 LOCAL_VARS;
561
562 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
563
564 HW_WRITE_CLIPLOOP()
565 {
566 if (mask)
567 {
568 for (i=0;i<n;i++)
569 {
570 if (mask[i]) {
571 const int fy = Y_FLIP(y[i]);
572 if (CLIPPIXEL(x[i],fy))
573 WRITE_RGBA( x[i], fy,
574 rgba[i][0], rgba[i][1],
575 rgba[i][2], rgba[i][3] );
576 }
577 }
578 }
579 else
580 {
581 for (i=0;i<n;i++)
582 {
583 const int fy = Y_FLIP(y[i]);
584 if (CLIPPIXEL(x[i],fy))
585 WRITE_RGBA( x[i], fy,
586 rgba[i][0], rgba[i][1],
587 rgba[i][2], rgba[i][3] );
588 }
589 }
590 }
591 HW_ENDCLIPLOOP();
592 }
593 HW_WRITE_UNLOCK();
594 }
595
596
597 static void TAG(WriteMonoRGBASpan)( struct gl_context *ctx,
598 struct gl_renderbuffer *rb,
599 GLuint n, GLint x, GLint y,
600 const void *value, const GLubyte mask[] )
601 {
602 (void) ctx;
603
604 HW_WRITE_LOCK()
605 {
606 const GLubyte *color = (const GLubyte *) value;
607 GLint x1;
608 GLint n1;
609 LOCAL_VARS;
610 INIT_MONO_PIXEL(p, color);
611
612 y = Y_FLIP( y );
613
614 if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
615
616 HW_WRITE_CLIPLOOP()
617 {
618 GLint i = 0;
619 CLIPSPAN(x,y,n,x1,n1,i);
620 if (mask)
621 {
622 for (;n1>0;i++,x1++,n1--)
623 if (mask[i])
624 WRITE_PIXEL( x1, y, p );
625 }
626 else
627 {
628 for (;n1>0;i++,x1++,n1--)
629 WRITE_PIXEL( x1, y, p );
630 }
631 }
632 HW_ENDCLIPLOOP();
633 }
634 HW_WRITE_UNLOCK();
635 }
636
637
638 static void TAG(WriteMonoRGBAPixels)( struct gl_context *ctx,
639 struct gl_renderbuffer *rb,
640 GLuint n,
641 const GLint x[], const GLint y[],
642 const void *value,
643 const GLubyte mask[] )
644 {
645 (void) ctx;
646
647 HW_WRITE_LOCK()
648 {
649 const GLubyte *color = (const GLubyte *) value;
650 GLint i;
651 LOCAL_VARS;
652 INIT_MONO_PIXEL(p, color);
653
654 if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
655
656 HW_WRITE_CLIPLOOP()
657 {
658 if (mask)
659 {
660 for (i=0;i<n;i++)
661 if (mask[i]) {
662 int fy = Y_FLIP(y[i]);
663 if (CLIPPIXEL( x[i], fy ))
664 WRITE_PIXEL( x[i], fy, p );
665 }
666 }
667 else
668 {
669 for (i=0;i<n;i++) {
670 int fy = Y_FLIP(y[i]);
671 if (CLIPPIXEL( x[i], fy ))
672 WRITE_PIXEL( x[i], fy, p );
673 }
674 }
675 }
676 HW_ENDCLIPLOOP();
677 }
678 HW_WRITE_UNLOCK();
679 }
680
681
682 static void TAG(ReadRGBASpan)( struct gl_context *ctx,
683 struct gl_renderbuffer *rb,
684 GLuint n, GLint x, GLint y, void *values)
685 {
686 (void) ctx;
687
688 HW_READ_LOCK()
689 {
690 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
691 GLint x1,n1;
692 LOCAL_VARS;
693
694 y = Y_FLIP(y);
695
696 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
697
698 HW_READ_CLIPLOOP()
699 {
700 GLint i = 0;
701 CLIPSPAN(x,y,n,x1,n1,i);
702 for (;n1>0;i++,x1++,n1--)
703 READ_RGBA( rgba[i], x1, y );
704 }
705 HW_ENDCLIPLOOP();
706 }
707 HW_READ_UNLOCK();
708 }
709
710
711 #if defined(GET_PTR) && \
712 defined(USE_MMX_ASM) && \
713 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
714 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
715 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
716 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
717 static void TAG2(ReadRGBASpan,_MMX)( struct gl_context *ctx,
718 struct gl_renderbuffer *rb,
719 GLuint n, GLint x, GLint y, void *values)
720 {
721 #ifndef USE_INNER_EMMS
722 /* The EMMS instruction is directly in-lined here because using GCC's
723 * built-in _mm_empty function was found to utterly destroy performance.
724 */
725 __asm__ __volatile__( "emms" );
726 #endif
727
728 (void) ctx;
729
730 HW_READ_LOCK()
731 {
732 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
733 GLint x1,n1;
734 LOCAL_VARS;
735
736 y = Y_FLIP(y);
737
738 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
739
740 HW_READ_CLIPLOOP()
741 {
742 GLint i = 0;
743 CLIPSPAN(x,y,n,x1,n1,i);
744
745 {
746 const void * src = GET_PTR( x1, y );
747 #if (SPANTMP_PIXEL_FMT == GL_RGB) && \
748 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
749 _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 );
750 #else
751 _generic_read_RGBA_span_BGRA8888_REV_MMX( src, rgba[i], n1 );
752 #endif
753 }
754 }
755 HW_ENDCLIPLOOP();
756 }
757 HW_READ_UNLOCK();
758 #ifndef USE_INNER_EMMS
759 __asm__ __volatile__( "emms" );
760 #endif
761 }
762 #endif
763
764
765 #if defined(GET_PTR) && \
766 defined(USE_SSE_ASM) && \
767 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
768 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
769 static void TAG2(ReadRGBASpan,_SSE2)( struct gl_context *ctx,
770 struct gl_renderbuffer *rb,
771 GLuint n, GLint x, GLint y,
772 void *values)
773 {
774 (void) ctx;
775
776 HW_READ_LOCK()
777 {
778 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
779 GLint x1,n1;
780 LOCAL_VARS;
781
782 y = Y_FLIP(y);
783
784 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
785
786 HW_READ_CLIPLOOP()
787 {
788 GLint i = 0;
789 CLIPSPAN(x,y,n,x1,n1,i);
790
791 {
792 const void * src = GET_PTR( x1, y );
793 _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 );
794 }
795 }
796 HW_ENDCLIPLOOP();
797 }
798 HW_READ_UNLOCK();
799 }
800 #endif
801
802 #if defined(GET_PTR) && \
803 defined(USE_SSE_ASM) && \
804 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
805 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
806 static void TAG2(ReadRGBASpan,_SSE)( struct gl_context *ctx,
807 struct gl_renderbuffer *rb,
808 GLuint n, GLint x, GLint y,
809 void *values)
810 {
811 #ifndef USE_INNER_EMMS
812 /* The EMMS instruction is directly in-lined here because using GCC's
813 * built-in _mm_empty function was found to utterly destroy performance.
814 */
815 __asm__ __volatile__( "emms" );
816 #endif
817
818 (void) ctx;
819
820 HW_READ_LOCK()
821 {
822 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
823 GLint x1,n1;
824 LOCAL_VARS;
825
826 y = Y_FLIP(y);
827
828 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
829
830 HW_READ_CLIPLOOP()
831 {
832 GLint i = 0;
833 CLIPSPAN(x,y,n,x1,n1,i);
834
835 {
836 const void * src = GET_PTR( x1, y );
837 _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 );
838 }
839 }
840 HW_ENDCLIPLOOP();
841 }
842 HW_READ_UNLOCK();
843 #ifndef USE_INNER_EMMS
844 __asm__ __volatile__( "emms" );
845 #endif
846 }
847 #endif
848
849
850 static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
851 struct gl_renderbuffer *rb,
852 GLuint n, const GLint x[], const GLint y[],
853 void *values )
854 {
855 (void) ctx;
856
857 HW_READ_LOCK()
858 {
859 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
860 GLint i;
861 LOCAL_VARS;
862
863 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
864
865 HW_READ_CLIPLOOP()
866 {
867 for (i=0;i<n;i++) {
868 int fy = Y_FLIP( y[i] );
869 if (CLIPPIXEL( x[i], fy ))
870 READ_RGBA( rgba[i], x[i], fy );
871 }
872 }
873 HW_ENDCLIPLOOP();
874 }
875 HW_READ_UNLOCK();
876 }
877
878 static void TAG(InitPointers)(struct gl_renderbuffer *rb)
879 {
880 rb->PutRow = TAG(WriteRGBASpan);
881 rb->PutRowRGB = TAG(WriteRGBSpan);
882 rb->PutMonoRow = TAG(WriteMonoRGBASpan);
883 rb->PutValues = TAG(WriteRGBAPixels);
884 rb->PutMonoValues = TAG(WriteMonoRGBAPixels);
885 rb->GetValues = TAG(ReadRGBAPixels);
886
887 #if defined(GET_PTR)
888 #if defined(USE_SSE_ASM) && \
889 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
890 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
891 if ( cpu_has_xmm2 ) {
892 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" );
893 rb->GetRow = TAG2(ReadRGBASpan, _SSE2);
894 }
895 else
896 #endif
897 #if defined(USE_SSE_ASM) && \
898 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
899 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
900 if ( cpu_has_xmm ) {
901 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" );
902 rb->GetRow = TAG2(ReadRGBASpan, _SSE);
903 }
904 else
905 #endif
906 #if defined(USE_MMX_ASM) && \
907 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
908 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
909 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
910 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
911 if ( cpu_has_mmx ) {
912 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" );
913 rb->GetRow = TAG2(ReadRGBASpan, _MMX);
914 }
915 else
916 #endif
917 #endif /* GET_PTR */
918 {
919 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" );
920 rb->GetRow = TAG(ReadRGBASpan);
921 }
922
923 }
924
925
926 #undef INIT_MONO_PIXEL
927 #undef WRITE_PIXEL
928 #undef WRITE_RGBA
929 #undef READ_RGBA
930 #undef TAG
931 #undef TAG2
932 #undef GET_VALUE
933 #undef PUT_VALUE
934 #undef GET_PTR
935 #undef SPANTMP_PIXEL_FMT
936 #undef SPANTMP_PIXEL_TYPE