radeon: remove obsolete GetRow/PutRow code
[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 WRITE_RGBA( _x, _y, r, g, b, a ) \
67 PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) | \
68 (((int)g & 0xfc) << 3) | \
69 (((int)b & 0xf8) >> 3))) \
70
71 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
72
73 #define READ_RGBA( rgba, _x, _y ) \
74 do { \
75 GLushort p = GET_VALUE(_x, _y); \
76 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
77 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
78 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
79 rgba[3] = 0xff; \
80 } while (0)
81
82 #elif (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV)
83
84 /**
85 ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV
86 **/
87
88 #ifndef GET_VALUE
89 #ifndef GET_PTR
90 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
91 #endif
92
93 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
94 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
95 #endif /* GET_VALUE */
96
97 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
98 PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b ))
99
100 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
101
102 #define READ_RGBA( rgba, _x, _y ) \
103 do { \
104 GLushort p = GET_VALUE(_x, _y); \
105 p = p << 8 | p >> 8; \
106 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
107 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
108 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
109 rgba[3] = 0xff; \
110 } while (0)
111
112 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4)
113
114 /**
115 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4
116 **/
117
118 #ifndef GET_VALUE
119 #ifndef GET_PTR
120 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
121 #endif
122
123 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
124 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
125 #endif /* GET_VALUE */
126
127 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
128 PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b)) \
129
130 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
131
132 #define READ_RGBA( rgba, _x, _y ) \
133 do { \
134 GLushort p = GET_VALUE(_x, _y); \
135 rgba[0] = ((p >> 0) & 0xf) * 0x11; \
136 rgba[1] = ((p >> 12) & 0xf) * 0x11; \
137 rgba[2] = ((p >> 4) & 0xf) * 0x11; \
138 rgba[3] = ((p >> 8) & 0xf) * 0x11; \
139 } while (0)
140
141
142 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV)
143
144 /**
145 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV
146 **/
147
148 #ifndef GET_VALUE
149 #ifndef GET_PTR
150 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
151 #endif
152
153 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
154 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
155 #endif /* GET_VALUE */
156
157 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
158 PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b)) \
159
160 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
161
162 #define READ_RGBA( rgba, _x, _y ) \
163 do { \
164 GLushort p = GET_VALUE(_x, _y); \
165 rgba[0] = ((p >> 8) & 0xf) * 0x11; \
166 rgba[1] = ((p >> 4) & 0xf) * 0x11; \
167 rgba[2] = ((p >> 0) & 0xf) * 0x11; \
168 rgba[3] = ((p >> 12) & 0xf) * 0x11; \
169 } while (0)
170
171
172 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV)
173
174 /**
175 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
176 **/
177
178 #ifndef GET_VALUE
179 #ifndef GET_PTR
180 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
181 #endif
182
183 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
184 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
185 #endif /* GET_VALUE */
186
187 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
188 PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b)) \
189
190 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
191
192 #define READ_RGBA( rgba, _x, _y ) \
193 do { \
194 GLushort p = GET_VALUE(_x, _y); \
195 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
196 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
197 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
198 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
199 } while (0)
200
201 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5)
202
203 /**
204 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5
205 **/
206
207 #ifndef GET_VALUE
208 #ifndef GET_PTR
209 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
210 #endif
211
212 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
213 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
214 #endif /* GET_VALUE */
215
216 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
217 PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b)) \
218
219 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
220
221 #define READ_RGBA( rgba, _x, _y ) \
222 do { \
223 GLushort p = GET_VALUE(_x, _y); \
224 p = p << 8 | p >> 8; \
225 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
226 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
227 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
228 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
229 } while (0)
230
231 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
232
233 /**
234 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV
235 **/
236
237 #ifndef GET_VALUE
238 #ifndef GET_PTR
239 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
240 #endif
241
242 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
243 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
244 #endif /* GET_VALUE */
245
246 # define WRITE_RGBA(_x, _y, r, g, b, a) \
247 PUT_VALUE(_x, _y, ((r << 16) | \
248 (g << 8) | \
249 (b << 0) | \
250 (a << 24)))
251
252 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
253
254 # if defined( USE_X86_ASM )
255 # define READ_RGBA(rgba, _x, _y) \
256 do { \
257 GLuint p = GET_VALUE(_x, _y); \
258 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
259 : "=r" (p) : "0" (p) ); \
260 ((GLuint *)rgba)[0] = p; \
261 } while (0)
262 # elif defined( MESA_BIG_ENDIAN )
263 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
264 * rotlwi instruction. It also produces good code on SPARC.
265 */
266 # define READ_RGBA( rgba, _x, _y ) \
267 do { \
268 GLuint p = GET_VALUE(_x, _y); \
269 GLuint t = p; \
270 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
271 } while (0)
272 # else
273 # define READ_RGBA( rgba, _x, _y ) \
274 do { \
275 GLuint p = GET_VALUE(_x, _y); \
276 rgba[0] = (p >> 16) & 0xff; \
277 rgba[1] = (p >> 8) & 0xff; \
278 rgba[2] = (p >> 0) & 0xff; \
279 rgba[3] = (p >> 24) & 0xff; \
280 } while (0)
281 # endif
282
283 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8)
284
285 /**
286 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8
287 **/
288
289 #ifndef GET_VALUE
290 #ifndef GET_PTR
291 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
292 #endif
293
294 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
295 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
296 #endif /* GET_VALUE */
297
298 # define WRITE_RGBA(_x, _y, r, g, b, a) \
299 PUT_VALUE(_x, _y, ((r << 8) | \
300 (g << 16) | \
301 (b << 24) | \
302 (a << 0)))
303
304 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
305
306 # if defined( USE_X86_ASM )
307 # define READ_RGBA(rgba, _x, _y) \
308 do { \
309 GLuint p = GET_VALUE(_x, _y); \
310 __asm__ __volatile__( "rorl $8, %0" \
311 : "=r" (p) : "0" (p) ); \
312 ((GLuint *)rgba)[0] = p; \
313 } while (0)
314 # elif defined( MESA_BIG_ENDIAN )
315 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
316 * rotlwi instruction. It also produces good code on SPARC.
317 */
318 # define READ_RGBA( rgba, _x, _y ) \
319 do { \
320 GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y)); \
321 GLuint t = p; \
322 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
323 } while (0)
324 # else
325 # define READ_RGBA( rgba, _x, _y ) \
326 do { \
327 GLuint p = GET_VALUE(_x, _y); \
328 rgba[0] = (p >> 8) & 0xff; \
329 rgba[1] = (p >> 16) & 0xff; \
330 rgba[2] = (p >> 24) & 0xff; \
331 rgba[3] = (p >> 0) & 0xff; \
332 } while (0)
333 # endif
334
335 #elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
336
337 /**
338 ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV
339 **
340 ** This is really for MESA_FORMAT_XRGB8888. The spantmp code needs to be
341 ** kicked to the curb, and we need to just code-gen this.
342 **/
343
344 #ifndef GET_VALUE
345 #ifndef GET_PTR
346 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
347 #endif
348
349 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
350 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
351 #endif /* GET_VALUE */
352
353 # define WRITE_RGBA(_x, _y, r, g, b, a) \
354 PUT_VALUE(_x, _y, ((r << 16) | \
355 (g << 8) | \
356 (b << 0) | \
357 (0xff << 24)))
358
359 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
360
361 # if defined( USE_X86_ASM )
362 # define READ_RGBA(rgba, _x, _y) \
363 do { \
364 GLuint p = GET_VALUE(_x, _y); \
365 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
366 : "=r" (p) : "0" (p) ); \
367 ((GLuint *)rgba)[0] = p | 0xff000000; \
368 } while (0)
369 # elif defined( MESA_BIG_ENDIAN )
370 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
371 * rotlwi instruction. It also produces good code on SPARC.
372 */
373 # define READ_RGBA( rgba, _x, _y ) \
374 do { \
375 GLuint p = GET_VALUE(_x, _y); \
376 *((uint32_t *) rgba) = (p << 8) | 0xff; \
377 } while (0)
378 # else
379 # define READ_RGBA( rgba, _x, _y ) \
380 do { \
381 GLuint p = GET_VALUE(_x, _y); \
382 rgba[0] = (p >> 16) & 0xff; \
383 rgba[1] = (p >> 8) & 0xff; \
384 rgba[2] = (p >> 0) & 0xff; \
385 rgba[3] = 0xff; \
386 } while (0)
387 # endif
388
389 #elif (SPANTMP_PIXEL_FMT == GL_ALPHA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_BYTE)
390
391 /**
392 ** GL_ALPHA, GL_UNSIGNED_BYTE
393 **/
394
395 #ifndef GET_VALUE
396 #ifndef GET_PTR
397 #define GET_PTR(_x, _y) ( buf + (_x) + (_y) * pitch)
398 #endif
399
400 #define GET_VALUE(_x, _y) *(volatile GLubyte *)(GET_PTR(_x, _y))
401 #define PUT_VALUE(_x, _y, _v) *(volatile GLubyte *)(GET_PTR(_x, _y)) = (_v)
402 #endif /* GET_VALUE */
403
404 # define WRITE_RGBA(_x, _y, r, g, b, a) \
405 PUT_VALUE(_x, _y, a | (r & 0 /* quiet warnings */))
406
407 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
408
409 #define READ_RGBA( rgba, _x, _y ) \
410 do { \
411 GLubyte p = GET_VALUE(_x, _y); \
412 rgba[0] = 0; \
413 rgba[1] = 0; \
414 rgba[2] = 0; \
415 rgba[3] = p; \
416 } while (0)
417
418 #else
419 #error SPANTMP_PIXEL_FMT must be set to a valid value!
420 #endif
421
422
423
424 /**
425 ** Assembly routines.
426 **/
427
428 #if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM )
429 #include "x86/read_rgba_span_x86.h"
430 #include "x86/common_x86_asm.h"
431 #endif
432
433 static void TAG(WriteRGBASpan)( struct gl_context *ctx,
434 struct gl_renderbuffer *rb,
435 GLuint n, GLint x, GLint y,
436 const void *values, const GLubyte mask[] )
437 {
438 (void) ctx;
439
440 HW_WRITE_LOCK()
441 {
442 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
443 GLint x1;
444 GLint n1;
445 LOCAL_VARS;
446
447 y = Y_FLIP(y);
448
449 HW_WRITE_CLIPLOOP()
450 {
451 GLint i = 0;
452 CLIPSPAN(x,y,n,x1,n1,i);
453
454 if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
455 (int)i, (int)n1, (int)x1);
456
457 if (mask)
458 {
459 for (;n1>0;i++,x1++,n1--)
460 if (mask[i])
461 WRITE_RGBA( x1, y,
462 rgba[i][0], rgba[i][1],
463 rgba[i][2], rgba[i][3] );
464 }
465 else
466 {
467 for (;n1>0;i++,x1++,n1--)
468 WRITE_RGBA( x1, y,
469 rgba[i][0], rgba[i][1],
470 rgba[i][2], rgba[i][3] );
471 }
472 }
473 HW_ENDCLIPLOOP();
474 }
475 HW_WRITE_UNLOCK();
476 }
477
478
479 static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
480 struct gl_renderbuffer *rb,
481 GLuint n, const GLint x[], const GLint y[],
482 const void *values, const GLubyte mask[] )
483 {
484 (void) ctx;
485
486 HW_WRITE_LOCK()
487 {
488 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
489 GLint i;
490 LOCAL_VARS;
491
492 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
493
494 HW_WRITE_CLIPLOOP()
495 {
496 if (mask)
497 {
498 for (i=0;i<n;i++)
499 {
500 if (mask[i]) {
501 const int fy = Y_FLIP(y[i]);
502 if (CLIPPIXEL(x[i],fy))
503 WRITE_RGBA( x[i], fy,
504 rgba[i][0], rgba[i][1],
505 rgba[i][2], rgba[i][3] );
506 }
507 }
508 }
509 else
510 {
511 for (i=0;i<n;i++)
512 {
513 const int fy = Y_FLIP(y[i]);
514 if (CLIPPIXEL(x[i],fy))
515 WRITE_RGBA( x[i], fy,
516 rgba[i][0], rgba[i][1],
517 rgba[i][2], rgba[i][3] );
518 }
519 }
520 }
521 HW_ENDCLIPLOOP();
522 }
523 HW_WRITE_UNLOCK();
524 }
525
526
527 static void TAG(ReadRGBASpan)( struct gl_context *ctx,
528 struct gl_renderbuffer *rb,
529 GLuint n, GLint x, GLint y, void *values)
530 {
531 (void) ctx;
532
533 HW_READ_LOCK()
534 {
535 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
536 GLint x1,n1;
537 LOCAL_VARS;
538
539 y = Y_FLIP(y);
540
541 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
542
543 HW_READ_CLIPLOOP()
544 {
545 GLint i = 0;
546 CLIPSPAN(x,y,n,x1,n1,i);
547 for (;n1>0;i++,x1++,n1--)
548 READ_RGBA( rgba[i], x1, y );
549 }
550 HW_ENDCLIPLOOP();
551 }
552 HW_READ_UNLOCK();
553 }
554
555
556 #if defined(GET_PTR) && \
557 defined(USE_MMX_ASM) && \
558 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
559 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
560 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
561 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
562 static void TAG2(ReadRGBASpan,_MMX)( struct gl_context *ctx,
563 struct gl_renderbuffer *rb,
564 GLuint n, GLint x, GLint y, void *values)
565 {
566 #ifndef USE_INNER_EMMS
567 /* The EMMS instruction is directly in-lined here because using GCC's
568 * built-in _mm_empty function was found to utterly destroy performance.
569 */
570 __asm__ __volatile__( "emms" );
571 #endif
572
573 (void) ctx;
574
575 HW_READ_LOCK()
576 {
577 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
578 GLint x1,n1;
579 LOCAL_VARS;
580
581 y = Y_FLIP(y);
582
583 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
584
585 HW_READ_CLIPLOOP()
586 {
587 GLint i = 0;
588 CLIPSPAN(x,y,n,x1,n1,i);
589
590 {
591 const void * src = GET_PTR( x1, y );
592 #if (SPANTMP_PIXEL_FMT == GL_RGB) && \
593 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
594 _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 );
595 #else
596 _generic_read_RGBA_span_BGRA8888_REV_MMX( src, rgba[i], n1 );
597 #endif
598 }
599 }
600 HW_ENDCLIPLOOP();
601 }
602 HW_READ_UNLOCK();
603 #ifndef USE_INNER_EMMS
604 __asm__ __volatile__( "emms" );
605 #endif
606 }
607 #endif
608
609
610 #if defined(GET_PTR) && \
611 defined(USE_SSE_ASM) && \
612 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
613 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
614 static void TAG2(ReadRGBASpan,_SSE2)( struct gl_context *ctx,
615 struct gl_renderbuffer *rb,
616 GLuint n, GLint x, GLint y,
617 void *values)
618 {
619 (void) ctx;
620
621 HW_READ_LOCK()
622 {
623 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
624 GLint x1,n1;
625 LOCAL_VARS;
626
627 y = Y_FLIP(y);
628
629 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
630
631 HW_READ_CLIPLOOP()
632 {
633 GLint i = 0;
634 CLIPSPAN(x,y,n,x1,n1,i);
635
636 {
637 const void * src = GET_PTR( x1, y );
638 _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 );
639 }
640 }
641 HW_ENDCLIPLOOP();
642 }
643 HW_READ_UNLOCK();
644 }
645 #endif
646
647 #if defined(GET_PTR) && \
648 defined(USE_SSE_ASM) && \
649 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
650 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
651 static void TAG2(ReadRGBASpan,_SSE)( struct gl_context *ctx,
652 struct gl_renderbuffer *rb,
653 GLuint n, GLint x, GLint y,
654 void *values)
655 {
656 #ifndef USE_INNER_EMMS
657 /* The EMMS instruction is directly in-lined here because using GCC's
658 * built-in _mm_empty function was found to utterly destroy performance.
659 */
660 __asm__ __volatile__( "emms" );
661 #endif
662
663 (void) ctx;
664
665 HW_READ_LOCK()
666 {
667 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
668 GLint x1,n1;
669 LOCAL_VARS;
670
671 y = Y_FLIP(y);
672
673 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
674
675 HW_READ_CLIPLOOP()
676 {
677 GLint i = 0;
678 CLIPSPAN(x,y,n,x1,n1,i);
679
680 {
681 const void * src = GET_PTR( x1, y );
682 _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 );
683 }
684 }
685 HW_ENDCLIPLOOP();
686 }
687 HW_READ_UNLOCK();
688 #ifndef USE_INNER_EMMS
689 __asm__ __volatile__( "emms" );
690 #endif
691 }
692 #endif
693
694
695 static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
696 struct gl_renderbuffer *rb,
697 GLuint n, const GLint x[], const GLint y[],
698 void *values )
699 {
700 (void) ctx;
701
702 HW_READ_LOCK()
703 {
704 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
705 GLint i;
706 LOCAL_VARS;
707
708 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
709
710 HW_READ_CLIPLOOP()
711 {
712 for (i=0;i<n;i++) {
713 int fy = Y_FLIP( y[i] );
714 if (CLIPPIXEL( x[i], fy ))
715 READ_RGBA( rgba[i], x[i], fy );
716 }
717 }
718 HW_ENDCLIPLOOP();
719 }
720 HW_READ_UNLOCK();
721 }
722
723 static void TAG(InitPointers)(struct gl_renderbuffer *rb)
724 {
725 rb->PutRow = TAG(WriteRGBASpan);
726 rb->PutValues = TAG(WriteRGBAPixels);
727 rb->GetValues = TAG(ReadRGBAPixels);
728
729 #if defined(GET_PTR)
730 #if defined(USE_SSE_ASM) && \
731 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
732 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
733 if ( cpu_has_xmm2 ) {
734 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" );
735 rb->GetRow = TAG2(ReadRGBASpan, _SSE2);
736 }
737 else
738 #endif
739 #if defined(USE_SSE_ASM) && \
740 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
741 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
742 if ( cpu_has_xmm ) {
743 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" );
744 rb->GetRow = TAG2(ReadRGBASpan, _SSE);
745 }
746 else
747 #endif
748 #if defined(USE_MMX_ASM) && \
749 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
750 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
751 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
752 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
753 if ( cpu_has_mmx ) {
754 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" );
755 rb->GetRow = TAG2(ReadRGBASpan, _MMX);
756 }
757 else
758 #endif
759 #endif /* GET_PTR */
760 {
761 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" );
762 rb->GetRow = TAG(ReadRGBASpan);
763 }
764
765 }
766
767
768 #undef WRITE_PIXEL
769 #undef WRITE_RGBA
770 #undef READ_RGBA
771 #undef TAG
772 #undef TAG2
773 #undef GET_VALUE
774 #undef PUT_VALUE
775 #undef GET_PTR
776 #undef SPANTMP_PIXEL_FMT
777 #undef SPANTMP_PIXEL_TYPE