1 /**************************************************************************
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
7 The Weather Channel (TM) funded Tungsten Graphics to develop the
8 initial release of the Radeon 8500 driver under the XFree86 license.
9 This notice must be preserved.
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial
23 portions of the Software.
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
29 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 **************************************************************************/
37 * Kevin E. Martin <martin@valinux.com>
38 * Gareth Hughes <gareth@valinux.com>
39 * Keith Whitwell <keith@tungstengraphics.com>
43 #include "main/glheader.h"
44 #include "swrast/swrast.h"
46 #include "radeon_common.h"
47 #include "radeon_lock.h"
48 #include "radeon_span.h"
52 static void radeonSetSpanFunctions(struct radeon_renderbuffer
*rrb
);
55 /* r200 depth buffer is always tiled - this is the formula
56 according to the docs unless I typo'ed in it
58 #if defined(RADEON_R200)
59 static GLubyte
*r200_depth_2byte(const struct radeon_renderbuffer
* rrb
,
62 GLubyte
*ptr
= rrb
->bo
->ptr
;
64 if (rrb
->has_surface
) {
65 offset
= x
* rrb
->cpp
+ y
* rrb
->pitch
;
69 b
= (((y
>> 4) * (rrb
->pitch
>> 8) + (x
>> 6)));
70 offset
+= (b
>> 1) << 12;
71 offset
+= (((rrb
->pitch
>> 8) & 0x1) ? (b
& 0x1) : ((b
& 0x1) ^ ((y
>> 4) & 0x1))) << 11;
72 offset
+= ((y
>> 2) & 0x3) << 9;
73 offset
+= ((x
>> 3) & 0x1) << 8;
74 offset
+= ((x
>> 4) & 0x3) << 6;
75 offset
+= ((x
>> 2) & 0x1) << 5;
76 offset
+= ((y
>> 1) & 0x1) << 4;
77 offset
+= ((x
>> 1) & 0x1) << 3;
78 offset
+= (y
& 0x1) << 2;
79 offset
+= (x
& 0x1) << 1;
84 static GLubyte
*r200_depth_4byte(const struct radeon_renderbuffer
* rrb
,
87 GLubyte
*ptr
= rrb
->bo
->ptr
;
89 if (rrb
->has_surface
) {
90 offset
= x
* rrb
->cpp
+ y
* rrb
->pitch
;
94 b
= (((y
& 0x7ff) >> 4) * (rrb
->pitch
>> 7) + (x
>> 5));
95 offset
+= (b
>> 1) << 12;
96 offset
+= (((rrb
->pitch
>> 7) & 0x1) ? (b
& 0x1) : ((b
& 0x1) ^ ((y
>> 4) & 0x1))) << 11;
97 offset
+= ((y
>> 2) & 0x3) << 9;
98 offset
+= ((x
>> 2) & 0x1) << 8;
99 offset
+= ((x
>> 3) & 0x3) << 6;
100 offset
+= ((y
>> 1) & 0x1) << 5;
101 offset
+= ((x
>> 1) & 0x1) << 4;
102 offset
+= (y
& 0x1) << 3;
103 offset
+= (x
& 0x1) << 2;
111 * - 1D (akin to macro-linear/micro-tiled on older asics)
112 * - 2D (akin to macro-tiled/micro-tiled on older asics)
113 * only 1D tiling is implemented below
115 #if defined(RADEON_R600)
116 static inline GLint
r600_1d_tile_helper(const struct radeon_renderbuffer
* rrb
,
117 GLint x
, GLint y
, GLint is_depth
, GLint is_stencil
)
119 GLint element_bytes
= rrb
->cpp
;
120 GLint num_samples
= 1;
121 GLint tile_width
= 8;
122 GLint tile_height
= 8;
123 GLint tile_thickness
= 1;
124 GLint pitch_elements
= rrb
->pitch
/ element_bytes
;
125 GLint height
= rrb
->base
.Height
;
127 GLint sample_number
= 0;
131 GLint tiles_per_slice
;
133 GLint tile_row_index
;
134 GLint tile_column_index
;
136 GLint pixel_number
= 0;
137 GLint element_offset
;
140 tile_bytes
= tile_width
* tile_height
* tile_thickness
* element_bytes
* num_samples
;
141 tiles_per_row
= pitch_elements
/ tile_width
;
142 tiles_per_slice
= tiles_per_row
* (height
/ tile_height
);
143 slice_offset
= (z
/ tile_thickness
) * tiles_per_slice
* tile_bytes
;
144 tile_row_index
= y
/ tile_height
;
145 tile_column_index
= x
/ tile_width
;
146 tile_offset
= ((tile_row_index
* tiles_per_row
) + tile_column_index
) * tile_bytes
;
149 GLint pixel_offset
= 0;
151 pixel_number
|= ((x
>> 0) & 1) << 0; // pn[0] = x[0]
152 pixel_number
|= ((y
>> 0) & 1) << 1; // pn[1] = y[0]
153 pixel_number
|= ((x
>> 1) & 1) << 2; // pn[2] = x[1]
154 pixel_number
|= ((y
>> 1) & 1) << 3; // pn[3] = y[1]
155 pixel_number
|= ((x
>> 2) & 1) << 4; // pn[4] = x[2]
156 pixel_number
|= ((y
>> 2) & 1) << 5; // pn[5] = y[2]
157 switch (element_bytes
) {
159 pixel_offset
= pixel_number
* element_bytes
* num_samples
;
162 /* stencil and depth data are stored separately within a tile.
163 * stencil is stored in a contiguous tile before the depth tile.
164 * stencil element is 1 byte, depth element is 3 bytes.
165 * stencil tile is 64 bytes.
168 pixel_offset
= pixel_number
* 1 * num_samples
;
170 pixel_offset
= (pixel_number
* 3 * num_samples
) + 64;
173 element_offset
= pixel_offset
+ (sample_number
* element_bytes
);
177 switch (element_bytes
) {
179 pixel_number
|= ((x
>> 0) & 1) << 0; // pn[0] = x[0]
180 pixel_number
|= ((x
>> 1) & 1) << 1; // pn[1] = x[1]
181 pixel_number
|= ((x
>> 2) & 1) << 2; // pn[2] = x[2]
182 pixel_number
|= ((y
>> 1) & 1) << 3; // pn[3] = y[1]
183 pixel_number
|= ((y
>> 0) & 1) << 4; // pn[4] = y[0]
184 pixel_number
|= ((y
>> 2) & 1) << 5; // pn[5] = y[2]
187 pixel_number
|= ((x
>> 0) & 1) << 0; // pn[0] = x[0]
188 pixel_number
|= ((x
>> 1) & 1) << 1; // pn[1] = x[1]
189 pixel_number
|= ((x
>> 2) & 1) << 2; // pn[2] = x[2]
190 pixel_number
|= ((y
>> 0) & 1) << 3; // pn[3] = y[0]
191 pixel_number
|= ((y
>> 1) & 1) << 4; // pn[4] = y[1]
192 pixel_number
|= ((y
>> 2) & 1) << 5; // pn[5] = y[2]
195 pixel_number
|= ((x
>> 0) & 1) << 0; // pn[0] = x[0]
196 pixel_number
|= ((x
>> 1) & 1) << 1; // pn[1] = x[1]
197 pixel_number
|= ((y
>> 0) & 1) << 2; // pn[2] = y[0]
198 pixel_number
|= ((x
>> 2) & 1) << 3; // pn[3] = x[2]
199 pixel_number
|= ((y
>> 1) & 1) << 4; // pn[4] = y[1]
200 pixel_number
|= ((y
>> 2) & 1) << 5; // pn[5] = y[2]
203 sample_offset
= sample_number
* (tile_bytes
/ num_samples
);
204 element_offset
= sample_offset
+ (pixel_number
* element_bytes
);
206 offset
= slice_offset
+ tile_offset
+ element_offset
;
211 static GLubyte
*r600_ptr_depth(const struct radeon_renderbuffer
* rrb
,
214 GLubyte
*ptr
= rrb
->bo
->ptr
;
215 GLint offset
= r600_1d_tile_helper(rrb
, x
, y
, 1, 0);
219 static GLubyte
*r600_ptr_stencil(const struct radeon_renderbuffer
* rrb
,
222 GLubyte
*ptr
= rrb
->bo
->ptr
;
223 GLint offset
= r600_1d_tile_helper(rrb
, x
, y
, 1, 1);
227 static GLubyte
*r600_ptr_color(const struct radeon_renderbuffer
* rrb
,
230 GLubyte
*ptr
= rrb
->bo
->ptr
;
231 uint32_t mask
= RADEON_BO_FLAGS_MACRO_TILE
| RADEON_BO_FLAGS_MICRO_TILE
;
234 if (rrb
->has_surface
|| !(rrb
->bo
->flags
& mask
)) {
235 offset
= x
* rrb
->cpp
+ y
* rrb
->pitch
;
237 offset
= r600_1d_tile_helper(rrb
, x
, y
, 0, 0);
244 /* radeon tiling on r300-r500 has 4 states,
245 macro-linear/micro-linear
246 macro-linear/micro-tiled
247 macro-tiled /micro-linear
248 macro-tiled /micro-tiled
250 2 byte surface - two types - we only provide 8x2 microtiling
254 static GLubyte
*radeon_ptr_4byte(const struct radeon_renderbuffer
* rrb
,
257 GLubyte
*ptr
= rrb
->bo
->ptr
;
258 uint32_t mask
= RADEON_BO_FLAGS_MACRO_TILE
| RADEON_BO_FLAGS_MICRO_TILE
;
261 if (rrb
->has_surface
|| !(rrb
->bo
->flags
& mask
)) {
262 offset
= x
* rrb
->cpp
+ y
* rrb
->pitch
;
265 if (rrb
->bo
->flags
& RADEON_BO_FLAGS_MACRO_TILE
) {
266 if (rrb
->bo
->flags
& RADEON_BO_FLAGS_MICRO_TILE
) {
267 offset
= ((y
>> 4) * (rrb
->pitch
>> 7) + (x
>> 5)) << 11;
268 offset
+= (((y
>> 3) ^ (x
>> 5)) & 0x1) << 10;
269 offset
+= (((y
>> 4) ^ (x
>> 4)) & 0x1) << 9;
270 offset
+= (((y
>> 2) ^ (x
>> 4)) & 0x1) << 8;
271 offset
+= (((y
>> 3) ^ (x
>> 3)) & 0x1) << 7;
272 offset
+= ((y
>> 1) & 0x1) << 6;
273 offset
+= ((x
>> 2) & 0x1) << 5;
274 offset
+= (y
& 1) << 4;
275 offset
+= (x
& 3) << 2;
277 offset
= ((y
>> 3) * (rrb
->pitch
>> 8) + (x
>> 6)) << 11;
278 offset
+= (((y
>> 2) ^ (x
>> 6)) & 0x1) << 10;
279 offset
+= (((y
>> 3) ^ (x
>> 5)) & 0x1) << 9;
280 offset
+= (((y
>> 1) ^ (x
>> 5)) & 0x1) << 8;
281 offset
+= (((y
>> 2) ^ (x
>> 4)) & 0x1) << 7;
282 offset
+= (y
& 1) << 6;
283 offset
+= (x
& 15) << 2;
286 offset
= ((y
>> 1) * (rrb
->pitch
>> 4) + (x
>> 2)) << 5;
287 offset
+= (y
& 1) << 4;
288 offset
+= (x
& 3) << 2;
294 static GLubyte
*radeon_ptr_2byte_8x2(const struct radeon_renderbuffer
* rrb
,
297 GLubyte
*ptr
= rrb
->bo
->ptr
;
298 uint32_t mask
= RADEON_BO_FLAGS_MACRO_TILE
| RADEON_BO_FLAGS_MICRO_TILE
;
301 if (rrb
->has_surface
|| !(rrb
->bo
->flags
& mask
)) {
302 offset
= x
* rrb
->cpp
+ y
* rrb
->pitch
;
305 if (rrb
->bo
->flags
& RADEON_BO_FLAGS_MACRO_TILE
) {
306 if (rrb
->bo
->flags
& RADEON_BO_FLAGS_MICRO_TILE
) {
307 offset
= ((y
>> 4) * (rrb
->pitch
>> 7) + (x
>> 6)) << 11;
308 offset
+= (((y
>> 3) ^ (x
>> 6)) & 0x1) << 10;
309 offset
+= (((y
>> 4) ^ (x
>> 5)) & 0x1) << 9;
310 offset
+= (((y
>> 2) ^ (x
>> 5)) & 0x1) << 8;
311 offset
+= (((y
>> 3) ^ (x
>> 4)) & 0x1) << 7;
312 offset
+= ((y
>> 1) & 0x1) << 6;
313 offset
+= ((x
>> 3) & 0x1) << 5;
314 offset
+= (y
& 1) << 4;
315 offset
+= (x
& 3) << 2;
317 offset
= ((y
>> 3) * (rrb
->pitch
>> 8) + (x
>> 7)) << 11;
318 offset
+= (((y
>> 2) ^ (x
>> 7)) & 0x1) << 10;
319 offset
+= (((y
>> 3) ^ (x
>> 6)) & 0x1) << 9;
320 offset
+= (((y
>> 1) ^ (x
>> 6)) & 0x1) << 8;
321 offset
+= (((y
>> 2) ^ (x
>> 5)) & 0x1) << 7;
322 offset
+= (y
& 1) << 6;
323 offset
+= ((x
>> 4) & 0x1) << 5;
324 offset
+= (x
& 15) << 2;
327 offset
= ((y
>> 1) * (rrb
->pitch
>> 4) + (x
>> 3)) << 5;
328 offset
+= (y
& 0x1) << 4;
329 offset
+= (x
& 0x7) << 1;
338 * Note that all information needed to access pixels in a renderbuffer
339 * should be obtained through the gl_renderbuffer parameter, not per-context
343 struct radeon_context *radeon = RADEON_CONTEXT(ctx); \
344 struct radeon_renderbuffer *rrb = (void *) rb; \
345 const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
346 const GLint yBias = ctx->DrawBuffer->Name ? 0 : rrb->base.Height - 1;\
347 unsigned int num_cliprects; \
348 struct drm_clip_rect *cliprects; \
352 radeon_get_cliprects(radeon, &cliprects, &num_cliprects, &x_off, &y_off);
354 #define LOCAL_DEPTH_VARS \
355 struct radeon_context *radeon = RADEON_CONTEXT(ctx); \
356 struct radeon_renderbuffer *rrb = (void *) rb; \
357 const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
358 const GLint yBias = ctx->DrawBuffer->Name ? 0 : rrb->base.Height - 1;\
359 unsigned int num_cliprects; \
360 struct drm_clip_rect *cliprects; \
362 radeon_get_cliprects(radeon, &cliprects, &num_cliprects, &x_off, &y_off);
364 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
366 #define Y_FLIP(_y) ((_y) * yScale + yBias)
372 /* XXX FBO: this is identical to the macro in spantmp2.h except we get
373 * the cliprect info from the context, not the driDrawable.
374 * Move this into spantmp2.h someday.
376 #define HW_CLIPLOOP() \
378 int _nc = num_cliprects; \
380 int minx = cliprects[_nc].x1 - x_off; \
381 int miny = cliprects[_nc].y1 - y_off; \
382 int maxx = cliprects[_nc].x2 - x_off; \
383 int maxy = cliprects[_nc].y2 - y_off;
385 /* ================================================================
389 /* 16 bit, RGB565 color spanline and pixel functions
391 #define SPANTMP_PIXEL_FMT GL_RGB
392 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
394 #define TAG(x) radeon##x##_RGB565
395 #define TAG2(x,y) radeon##x##_RGB565##y
396 #if defined(RADEON_R600)
397 #define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
399 #define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
401 #include "spantmp2.h"
403 /* 16 bit, ARGB1555 color spanline and pixel functions
405 #define SPANTMP_PIXEL_FMT GL_BGRA
406 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
408 #define TAG(x) radeon##x##_ARGB1555
409 #define TAG2(x,y) radeon##x##_ARGB1555##y
410 #if defined(RADEON_R600)
411 #define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
413 #define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
415 #include "spantmp2.h"
417 /* 16 bit, RGBA4 color spanline and pixel functions
419 #define SPANTMP_PIXEL_FMT GL_BGRA
420 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
422 #define TAG(x) radeon##x##_ARGB4444
423 #define TAG2(x,y) radeon##x##_ARGB4444##y
424 #if defined(RADEON_R600)
425 #define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
427 #define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
429 #include "spantmp2.h"
431 /* 32 bit, xRGB8888 color spanline and pixel functions
433 #define SPANTMP_PIXEL_FMT GL_BGRA
434 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
436 #define TAG(x) radeon##x##_xRGB8888
437 #define TAG2(x,y) radeon##x##_xRGB8888##y
438 #if defined(RADEON_R600)
439 #define GET_VALUE(_x, _y) ((*(GLuint*)(r600_ptr_color(rrb, _x + x_off, _y + y_off)) | 0xff000000))
440 #define PUT_VALUE(_x, _y, d) { \
441 GLuint *_ptr = (GLuint*)r600_ptr_color( rrb, _x + x_off, _y + y_off ); \
445 #define GET_VALUE(_x, _y) ((*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) | 0xff000000))
446 #define PUT_VALUE(_x, _y, d) { \
447 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
451 #include "spantmp2.h"
453 /* 32 bit, ARGB8888 color spanline and pixel functions
455 #define SPANTMP_PIXEL_FMT GL_BGRA
456 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
458 #define TAG(x) radeon##x##_ARGB8888
459 #define TAG2(x,y) radeon##x##_ARGB8888##y
460 #if defined(RADEON_R600)
461 #define GET_VALUE(_x, _y) (*(GLuint*)(r600_ptr_color(rrb, _x + x_off, _y + y_off)))
462 #define PUT_VALUE(_x, _y, d) { \
463 GLuint *_ptr = (GLuint*)r600_ptr_color( rrb, _x + x_off, _y + y_off ); \
467 #define GET_VALUE(_x, _y) (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)))
468 #define PUT_VALUE(_x, _y, d) { \
469 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
473 #include "spantmp2.h"
475 /* ================================================================
479 /* The Radeon family has depth tiling on all the time, so we have to convert
480 * the x,y coordinates into the memory bus address (mba) in the same
481 * manner as the engine. In each case, the linear block address (ba)
482 * is calculated, and then wired with x and y to produce the final
484 * The chip will do address translation on its own if the surface registers
485 * are set up correctly. It is not quite enough to get it working with hyperz
489 /* 16-bit depth buffer functions
491 #define VALUE_TYPE GLushort
493 #if defined(RADEON_R200)
494 #define WRITE_DEPTH( _x, _y, d ) \
495 *(GLushort *)r200_depth_2byte(rrb, _x + x_off, _y + y_off) = d
496 #elif defined(RADEON_R600)
497 #define WRITE_DEPTH( _x, _y, d ) \
498 *(GLushort *)r600_ptr_depth(rrb, _x + x_off, _y + y_off) = d
500 #define WRITE_DEPTH( _x, _y, d ) \
501 *(GLushort *)radeon_ptr_2byte_8x2(rrb, _x + x_off, _y + y_off) = d
504 #if defined(RADEON_R200)
505 #define READ_DEPTH( d, _x, _y ) \
506 d = *(GLushort *)r200_depth_2byte(rrb, _x + x_off, _y + y_off)
507 #elif defined(RADEON_R600)
508 #define READ_DEPTH( d, _x, _y ) \
509 d = *(GLushort *)r600_ptr_depth(rrb, _x + x_off, _y + y_off)
511 #define READ_DEPTH( d, _x, _y ) \
512 d = *(GLushort *)radeon_ptr_2byte_8x2(rrb, _x + x_off, _y + y_off)
515 #define TAG(x) radeon##x##_z16
516 #include "depthtmp.h"
520 * Careful: It looks like the R300 uses ZZZS byte order while the R200
521 * uses SZZZ for 24 bit depth, 8 bit stencil mode.
523 #define VALUE_TYPE GLuint
525 #if defined(RADEON_R300)
526 #define WRITE_DEPTH( _x, _y, d ) \
528 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
529 GLuint tmp = *_ptr; \
531 tmp |= ((d << 8) & 0xffffff00); \
534 #elif defined(RADEON_R600)
535 #define WRITE_DEPTH( _x, _y, d ) \
537 GLuint *_ptr = (GLuint*)r600_ptr_depth( rrb, _x + x_off, _y + y_off ); \
538 GLuint tmp = *_ptr; \
540 tmp |= ((d) & 0x00ffffff); \
543 #elif defined(RADEON_R200)
544 #define WRITE_DEPTH( _x, _y, d ) \
546 GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
547 GLuint tmp = *_ptr; \
549 tmp |= ((d) & 0x00ffffff); \
553 #define WRITE_DEPTH( _x, _y, d ) \
555 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
556 GLuint tmp = *_ptr; \
558 tmp |= ((d) & 0x00ffffff); \
563 #if defined(RADEON_R300)
564 #define READ_DEPTH( d, _x, _y ) \
566 d = (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) & 0xffffff00) >> 8; \
568 #elif defined(RADEON_R600)
569 #define READ_DEPTH( d, _x, _y ) \
571 d = (*(GLuint*)(r600_ptr_depth(rrb, _x + x_off, _y + y_off)) & 0x00ffffff); \
573 #elif defined(RADEON_R200)
574 #define READ_DEPTH( d, _x, _y ) \
576 d = *(GLuint*)(r200_depth_4byte(rrb, _x + x_off, _y + y_off)) & 0x00ffffff; \
579 #define READ_DEPTH( d, _x, _y ) \
580 d = *(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) & 0x00ffffff;
583 #define TAG(x) radeon##x##_z24
584 #include "depthtmp.h"
586 /* 24 bit depth, 8 bit stencil depthbuffer functions
589 * Careful: It looks like the R300 uses ZZZS byte order while the R200
590 * uses SZZZ for 24 bit depth, 8 bit stencil mode.
592 #define VALUE_TYPE GLuint
594 #if defined(RADEON_R300)
595 #define WRITE_DEPTH( _x, _y, d ) \
597 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
600 #elif defined(RADEON_R600)
601 #define WRITE_DEPTH( _x, _y, d ) \
603 GLuint *_ptr = (GLuint*)r600_ptr_depth( rrb, _x + x_off, _y + y_off ); \
604 GLuint tmp = *_ptr; \
606 tmp |= (((d) >> 8) & 0x00ffffff); \
608 _ptr = (GLuint*)r600_ptr_stencil(rrb, _x + x_off, _y + y_off); \
614 #elif defined(RADEON_R200)
615 #define WRITE_DEPTH( _x, _y, d ) \
617 GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
621 #define WRITE_DEPTH( _x, _y, d ) \
623 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
628 #if defined(RADEON_R300)
629 #define READ_DEPTH( d, _x, _y ) \
631 d = (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off))); \
633 #elif defined(RADEON_R600)
634 #define READ_DEPTH( d, _x, _y ) \
636 d = ((*(GLuint*)(r600_ptr_depth(rrb, _x + x_off, _y + y_off))) << 8) & 0xffffff00; \
637 d |= (*(GLuint*)(r600_ptr_stencil(rrb, _x + x_off, _y + y_off))) & 0x000000ff; \
639 #elif defined(RADEON_R200)
640 #define READ_DEPTH( d, _x, _y ) \
642 d = *(GLuint*)(r200_depth_4byte(rrb, _x + x_off, _y + y_off)); \
645 #define READ_DEPTH( d, _x, _y ) do { \
646 d = *(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off )); \
650 #define TAG(x) radeon##x##_s8_z24
651 #include "depthtmp.h"
653 /* ================================================================
657 /* 24 bit depth, 8 bit stencil depthbuffer functions
660 #define WRITE_STENCIL( _x, _y, d ) \
662 GLuint *_ptr = (GLuint*)radeon_ptr_4byte(rrb, _x + x_off, _y + y_off); \
663 GLuint tmp = *_ptr; \
668 #elif defined(RADEON_R600)
669 #define WRITE_STENCIL( _x, _y, d ) \
671 GLuint *_ptr = (GLuint*)r600_ptr_stencil(rrb, _x + x_off, _y + y_off); \
672 GLuint tmp = *_ptr; \
677 #elif defined(RADEON_R200)
678 #define WRITE_STENCIL( _x, _y, d ) \
680 GLuint *_ptr = (GLuint*)r200_depth_4byte(rrb, _x + x_off, _y + y_off); \
681 GLuint tmp = *_ptr; \
683 tmp |= (((d) & 0xff) << 24); \
687 #define WRITE_STENCIL( _x, _y, d ) \
689 GLuint *_ptr = (GLuint*)radeon_ptr_4byte(rrb, _x + x_off, _y + y_off); \
690 GLuint tmp = *_ptr; \
692 tmp |= (((d) & 0xff) << 24); \
698 #define READ_STENCIL( d, _x, _y ) \
700 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
701 GLuint tmp = *_ptr; \
702 d = tmp & 0x000000ff; \
704 #elif defined(RADEON_R600)
705 #define READ_STENCIL( d, _x, _y ) \
707 GLuint *_ptr = (GLuint*)r600_ptr_stencil( rrb, _x + x_off, _y + y_off ); \
708 GLuint tmp = *_ptr; \
709 d = tmp & 0x000000ff; \
711 #elif defined(RADEON_R200)
712 #define READ_STENCIL( d, _x, _y ) \
714 GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
715 GLuint tmp = *_ptr; \
716 d = (tmp & 0xff000000) >> 24; \
719 #define READ_STENCIL( d, _x, _y ) \
721 GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
722 GLuint tmp = *_ptr; \
723 d = (tmp & 0xff000000) >> 24; \
727 #define TAG(x) radeon##x##_s8_z24
728 #include "stenciltmp.h"
731 static void map_unmap_rb(struct gl_renderbuffer
*rb
, int flag
)
733 struct radeon_renderbuffer
*rrb
= radeon_renderbuffer(rb
);
736 if (rrb
== NULL
|| !rrb
->bo
)
740 if (rrb
->bo
->bom
->funcs
->bo_wait
)
741 radeon_bo_wait(rrb
->bo
);
742 r
= radeon_bo_map(rrb
->bo
, 1);
744 fprintf(stderr
, "(%s) error(%d) mapping buffer.\n",
748 radeonSetSpanFunctions(rrb
);
750 radeon_bo_unmap(rrb
->bo
);
757 radeon_map_unmap_buffers(GLcontext
*ctx
, GLboolean map
)
761 /* color draw buffers */
762 for (j
= 0; j
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; j
++)
763 map_unmap_rb(ctx
->DrawBuffer
->_ColorDrawBuffers
[j
], map
);
765 /* check for render to textures */
766 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
767 struct gl_renderbuffer_attachment
*att
=
768 ctx
->DrawBuffer
->Attachment
+ i
;
769 struct gl_texture_object
*tex
= att
->Texture
;
771 /* Render to texture. Note that a mipmapped texture need not
772 * be complete for render to texture, so we must restrict to
773 * mapping only the attached image.
775 radeon_texture_image
*image
= get_radeon_texture_image(tex
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
776 ASSERT(att
->Renderbuffer
);
779 radeon_teximage_map(image
, GL_TRUE
);
781 radeon_teximage_unmap(image
);
785 map_unmap_rb(ctx
->ReadBuffer
->_ColorReadBuffer
, map
);
787 /* depth buffer (Note wrapper!) */
788 if (ctx
->DrawBuffer
->_DepthBuffer
)
789 map_unmap_rb(ctx
->DrawBuffer
->_DepthBuffer
->Wrapped
, map
);
791 if (ctx
->DrawBuffer
->_StencilBuffer
)
792 map_unmap_rb(ctx
->DrawBuffer
->_StencilBuffer
->Wrapped
, map
);
795 static void radeonSpanRenderStart(GLcontext
* ctx
)
797 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
800 radeon_firevertices(rmesa
);
802 /* The locking and wait for idle should really only be needed in classic mode.
803 * In a future memory manager based implementation, this should become
804 * unnecessary due to the fact that mapping our buffers, textures, etc.
805 * should implicitly wait for any previous rendering commands that must
807 if (!rmesa
->radeonScreen
->driScreen
->dri2
.enabled
) {
808 LOCK_HARDWARE(rmesa
);
809 radeonWaitForIdleLocked(rmesa
);
812 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
813 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
814 ctx
->Driver
.MapTexture(ctx
, ctx
->Texture
.Unit
[i
]._Current
);
817 radeon_map_unmap_buffers(ctx
, 1);
820 static void radeonSpanRenderFinish(GLcontext
* ctx
)
822 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
825 if (!rmesa
->radeonScreen
->driScreen
->dri2
.enabled
) {
826 UNLOCK_HARDWARE(rmesa
);
828 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
829 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
830 ctx
->Driver
.UnmapTexture(ctx
, ctx
->Texture
.Unit
[i
]._Current
);
833 radeon_map_unmap_buffers(ctx
, 0);
836 void radeonInitSpanFuncs(GLcontext
* ctx
)
838 struct swrast_device_driver
*swdd
=
839 _swrast_GetDeviceDriverReference(ctx
);
840 swdd
->SpanRenderStart
= radeonSpanRenderStart
;
841 swdd
->SpanRenderFinish
= radeonSpanRenderFinish
;
845 * Plug in the Get/Put routines for the given driRenderbuffer.
847 static void radeonSetSpanFunctions(struct radeon_renderbuffer
*rrb
)
849 if (rrb
->base
.Format
== MESA_FORMAT_RGB565
) {
850 radeonInitPointers_RGB565(&rrb
->base
);
851 } else if (rrb
->base
.Format
== MESA_FORMAT_RGBA8888
) { /* XXX */
852 radeonInitPointers_xRGB8888(&rrb
->base
);
853 } else if (rrb
->base
.Format
== MESA_FORMAT_RGBA8888
) {
854 radeonInitPointers_ARGB8888(&rrb
->base
);
855 } else if (rrb
->base
.Format
== MESA_FORMAT_ARGB4444
) {
856 radeonInitPointers_ARGB4444(&rrb
->base
);
857 } else if (rrb
->base
.Format
== MESA_FORMAT_ARGB1555
) {
858 radeonInitPointers_ARGB1555(&rrb
->base
);
859 } else if (rrb
->base
.Format
== MESA_FORMAT_Z16
) {
860 radeonInitDepthPointers_z16(&rrb
->base
);
861 } else if (rrb
->base
.Format
== GL_DEPTH_COMPONENT32
) { /* XXX */
862 radeonInitDepthPointers_z24(&rrb
->base
);
863 } else if (rrb
->base
.Format
== MESA_FORMAT_S8_Z24
) {
864 radeonInitDepthPointers_s8_z24(&rrb
->base
);
865 } else if (rrb
->base
.Format
== MESA_FORMAT_S8
) {
866 radeonInitStencilPointers_s8_z24(&rrb
->base
);
868 fprintf(stderr
, "radeonSetSpanFunctions: bad format: 0x%04X\n", rrb
->base
.Format
);