-/*
- * Note that all information needed to access pixels in a renderbuffer
- * should be obtained through the gl_renderbuffer parameter, not per-context
- * information.
- */
-#define LOCAL_VARS \
- struct radeon_context *radeon = RADEON_CONTEXT(ctx); \
- struct radeon_renderbuffer *rrb = (void *) rb; \
- const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
- const GLint yBias = ctx->DrawBuffer->Name ? 0 : rrb->base.Height - 1;\
- unsigned int num_cliprects; \
- struct drm_clip_rect *cliprects; \
- int x_off, y_off; \
- GLuint p; \
- (void)p; \
- radeon_get_cliprects(radeon, &cliprects, &num_cliprects, &x_off, &y_off);
-
-#define LOCAL_DEPTH_VARS \
- struct radeon_context *radeon = RADEON_CONTEXT(ctx); \
- struct radeon_renderbuffer *rrb = (void *) rb; \
- const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
- const GLint yBias = ctx->DrawBuffer->Name ? 0 : rrb->base.Height - 1;\
- unsigned int num_cliprects; \
- struct drm_clip_rect *cliprects; \
- int x_off, y_off; \
- radeon_get_cliprects(radeon, &cliprects, &num_cliprects, &x_off, &y_off);
-
-#define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
-
-#define Y_FLIP(_y) ((_y) * yScale + yBias)
-
-#define HW_LOCK()
-
-#define HW_UNLOCK()
-
-/* XXX FBO: this is identical to the macro in spantmp2.h except we get
- * the cliprect info from the context, not the driDrawable.
- * Move this into spantmp2.h someday.
- */
-#define HW_CLIPLOOP() \
- do { \
- int _nc = num_cliprects; \
- while ( _nc-- ) { \
- int minx = cliprects[_nc].x1 - x_off; \
- int miny = cliprects[_nc].y1 - y_off; \
- int maxx = cliprects[_nc].x2 - x_off; \
- int maxy = cliprects[_nc].y2 - y_off;
-
-/* ================================================================
- * Color buffer
- */
-
-/* 16 bit, RGB565 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_RGB
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
-
-#define TAG(x) radeon##x##_RGB565
-#define TAG2(x,y) radeon##x##_RGB565##y
-#if defined(RADEON_R600)
-#define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
-#else
-#define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
-#endif
-#include "spantmp2.h"
-
-/* 16 bit, ARGB1555 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
-
-#define TAG(x) radeon##x##_ARGB1555
-#define TAG2(x,y) radeon##x##_ARGB1555##y
-#if defined(RADEON_R600)
-#define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
-#else
-#define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
-#endif
-#include "spantmp2.h"
-
-/* 16 bit, RGBA4 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
-
-#define TAG(x) radeon##x##_ARGB4444
-#define TAG2(x,y) radeon##x##_ARGB4444##y
-#if defined(RADEON_R600)
-#define GET_PTR(X,Y) r600_ptr_color(rrb, (X) + x_off, (Y) + y_off)
-#else
-#define GET_PTR(X,Y) radeon_ptr_2byte_8x2(rrb, (X) + x_off, (Y) + y_off)
-#endif
-#include "spantmp2.h"
-
-/* 32 bit, xRGB8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-
-#define TAG(x) radeon##x##_xRGB8888
-#define TAG2(x,y) radeon##x##_xRGB8888##y
-#if defined(RADEON_R600)
-#define GET_VALUE(_x, _y) ((*(GLuint*)(r600_ptr_color(rrb, _x + x_off, _y + y_off)) | 0xff000000))
-#define PUT_VALUE(_x, _y, d) { \
- GLuint *_ptr = (GLuint*)r600_ptr_color( rrb, _x + x_off, _y + y_off ); \
- *_ptr = d; \
-} while (0)
-#else
-#define GET_VALUE(_x, _y) ((*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) | 0xff000000))
-#define PUT_VALUE(_x, _y, d) { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- *_ptr = d; \
-} while (0)
-#endif
-#include "spantmp2.h"
-
-/* 32 bit, ARGB8888 color spanline and pixel functions
- */
-#define SPANTMP_PIXEL_FMT GL_BGRA
-#define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
-
-#define TAG(x) radeon##x##_ARGB8888
-#define TAG2(x,y) radeon##x##_ARGB8888##y
-#if defined(RADEON_R600)
-#define GET_VALUE(_x, _y) (*(GLuint*)(r600_ptr_color(rrb, _x + x_off, _y + y_off)))
-#define PUT_VALUE(_x, _y, d) { \
- GLuint *_ptr = (GLuint*)r600_ptr_color( rrb, _x + x_off, _y + y_off ); \
- *_ptr = d; \
-} while (0)
-#else
-#define GET_VALUE(_x, _y) (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)))
-#define PUT_VALUE(_x, _y, d) { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- *_ptr = d; \
-} while (0)
-#endif
-#include "spantmp2.h"
-
-/* ================================================================
- * Depth buffer
- */
-
-/* The Radeon family has depth tiling on all the time, so we have to convert
- * the x,y coordinates into the memory bus address (mba) in the same
- * manner as the engine. In each case, the linear block address (ba)
- * is calculated, and then wired with x and y to produce the final
- * memory address.
- * The chip will do address translation on its own if the surface registers
- * are set up correctly. It is not quite enough to get it working with hyperz
- * too...
- */
-
-/* 16-bit depth buffer functions
- */
-#define VALUE_TYPE GLushort
-
-#if defined(RADEON_R200)
-#define WRITE_DEPTH( _x, _y, d ) \
- *(GLushort *)r200_depth_2byte(rrb, _x + x_off, _y + y_off) = d
-#elif defined(RADEON_R600)
-#define WRITE_DEPTH( _x, _y, d ) \
- *(GLushort *)r600_ptr_depth(rrb, _x + x_off, _y + y_off) = d
-#else
-#define WRITE_DEPTH( _x, _y, d ) \
- *(GLushort *)radeon_ptr_2byte_8x2(rrb, _x + x_off, _y + y_off) = d
-#endif
-
-#if defined(RADEON_R200)
-#define READ_DEPTH( d, _x, _y ) \
- d = *(GLushort *)r200_depth_2byte(rrb, _x + x_off, _y + y_off)
-#elif defined(RADEON_R600)
-#define READ_DEPTH( d, _x, _y ) \
- d = *(GLushort *)r600_ptr_depth(rrb, _x + x_off, _y + y_off)
-#else
-#define READ_DEPTH( d, _x, _y ) \
- d = *(GLushort *)radeon_ptr_2byte_8x2(rrb, _x + x_off, _y + y_off)
-#endif
-
-#define TAG(x) radeon##x##_z16
-#include "depthtmp.h"
-
-/* 24 bit depth
- *
- * Careful: It looks like the R300 uses ZZZS byte order while the R200
- * uses SZZZ for 24 bit depth, 8 bit stencil mode.
- */
-#define VALUE_TYPE GLuint
-
-#if defined(RADEON_R300)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- tmp &= 0x000000ff; \
- tmp |= ((d << 8) & 0xffffff00); \
- *_ptr = tmp; \
-} while (0)
-#elif defined(RADEON_R600)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r600_ptr_depth( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- tmp &= 0xff000000; \
- tmp |= ((d) & 0x00ffffff); \
- *_ptr = tmp; \
-} while (0)
-#elif defined(RADEON_R200)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- tmp &= 0xff000000; \
- tmp |= ((d) & 0x00ffffff); \
- *_ptr = tmp; \
-} while (0)
-#else
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- tmp &= 0xff000000; \
- tmp |= ((d) & 0x00ffffff); \
- *_ptr = tmp; \
-} while (0)
-#endif
-
-#if defined(RADEON_R300)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) & 0xffffff00) >> 8; \
- }while(0)
-#elif defined(RADEON_R600)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = (*(GLuint*)(r600_ptr_depth(rrb, _x + x_off, _y + y_off)) & 0x00ffffff); \
- }while(0)
-#elif defined(RADEON_R200)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = *(GLuint*)(r200_depth_4byte(rrb, _x + x_off, _y + y_off)) & 0x00ffffff; \
- }while(0)
-#else
-#define READ_DEPTH( d, _x, _y ) \
- d = *(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off)) & 0x00ffffff;
-#endif
-
-#define TAG(x) radeon##x##_z24
-#include "depthtmp.h"
-
-/* 24 bit depth, 8 bit stencil depthbuffer functions
- * EXT_depth_stencil
- *
- * Careful: It looks like the R300 uses ZZZS byte order while the R200
- * uses SZZZ for 24 bit depth, 8 bit stencil mode.
- */
-#define VALUE_TYPE GLuint
-
-#if defined(RADEON_R300)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- *_ptr = d; \
-} while (0)
-#elif defined(RADEON_R600)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r600_ptr_depth( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- tmp &= 0xff000000; \
- tmp |= (((d) >> 8) & 0x00ffffff); \
- *_ptr = tmp; \
- _ptr = (GLuint*)r600_ptr_stencil(rrb, _x + x_off, _y + y_off); \
- tmp = *_ptr; \
- tmp &= 0xffffff00; \
- tmp |= (d) & 0xff; \
- *_ptr = tmp; \
-} while (0)
-#elif defined(RADEON_R200)
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = z24s8_to_s8z24(d); \
- *_ptr = tmp; \
-} while (0)
-#else
-#define WRITE_DEPTH( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = z24s8_to_s8z24(d); \
- *_ptr = tmp; \
-} while (0)
-#endif
-
-#if defined(RADEON_R300)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = (*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off))); \
- }while(0)
-#elif defined(RADEON_R600)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = ((*(GLuint*)(r600_ptr_depth(rrb, _x + x_off, _y + y_off))) << 8) & 0xffffff00; \
- d |= (*(GLuint*)(r600_ptr_stencil(rrb, _x + x_off, _y + y_off))) & 0x000000ff; \
- }while(0)
-#elif defined(RADEON_R200)
-#define READ_DEPTH( d, _x, _y ) \
- do { \
- d = s8z24_to_z24s8(*(GLuint*)(r200_depth_4byte(rrb, _x + x_off, _y + y_off))); \
- }while(0)
-#else
-#define READ_DEPTH( d, _x, _y ) do { \
- d = s8z24_to_z24s8(*(GLuint*)(radeon_ptr_4byte(rrb, _x + x_off, _y + y_off ))); \
- } while (0)
-#endif
-
-#define TAG(x) radeon##x##_z24_s8
-#include "depthtmp.h"
-
-/* ================================================================
- * Stencil buffer
- */
-
-/* 24 bit depth, 8 bit stencil depthbuffer functions
- */
-#ifdef RADEON_R300
-#define WRITE_STENCIL( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte(rrb, _x + x_off, _y + y_off); \
- GLuint tmp = *_ptr; \
- tmp &= 0xffffff00; \
- tmp |= (d) & 0xff; \
- *_ptr = tmp; \
-} while (0)
-#elif defined(RADEON_R600)
-#define WRITE_STENCIL( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r600_ptr_stencil(rrb, _x + x_off, _y + y_off); \
- GLuint tmp = *_ptr; \
- tmp &= 0xffffff00; \
- tmp |= (d) & 0xff; \
- *_ptr = tmp; \
-} while (0)
-#elif defined(RADEON_R200)
-#define WRITE_STENCIL( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)r200_depth_4byte(rrb, _x + x_off, _y + y_off); \
- GLuint tmp = *_ptr; \
- tmp &= 0x00ffffff; \
- tmp |= (((d) & 0xff) << 24); \
- *_ptr = tmp; \
-} while (0)
-#else
-#define WRITE_STENCIL( _x, _y, d ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte(rrb, _x + x_off, _y + y_off); \
- GLuint tmp = *_ptr; \
- tmp &= 0x00ffffff; \
- tmp |= (((d) & 0xff) << 24); \
- *_ptr = tmp; \
-} while (0)
-#endif
-
-#ifdef RADEON_R300
-#define READ_STENCIL( d, _x, _y ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- d = tmp & 0x000000ff; \
-} while (0)
-#elif defined(RADEON_R600)
-#define READ_STENCIL( d, _x, _y ) \
-do { \
- GLuint *_ptr = (GLuint*)r600_ptr_stencil( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- d = tmp & 0x000000ff; \
-} while (0)
-#elif defined(RADEON_R200)
-#define READ_STENCIL( d, _x, _y ) \
-do { \
- GLuint *_ptr = (GLuint*)r200_depth_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- d = (tmp & 0xff000000) >> 24; \
-} while (0)
-#else
-#define READ_STENCIL( d, _x, _y ) \
-do { \
- GLuint *_ptr = (GLuint*)radeon_ptr_4byte( rrb, _x + x_off, _y + y_off ); \
- GLuint tmp = *_ptr; \
- d = (tmp & 0xff000000) >> 24; \
-} while (0)
-#endif
-
-#define TAG(x) radeon##x##_z24_s8
-#include "stenciltmp.h"
-
-
-static void map_unmap_rb(struct gl_renderbuffer *rb, int flag)
-{
- struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
- int r;
-
- if (rrb == NULL || !rrb->bo)
- return;