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 "r300_state.h"
47 #include "radeon_ioctl.h"
48 #include "r300_ioctl.h"
49 #include "radeon_span.h"
51 #include "radeon_buffer.h"
56 * Note that all information needed to access pixels in a renderbuffer
57 * should be obtained through the gl_renderbuffer parameter, not per-context
61 struct radeon_renderbuffer *rrb = (void *) rb; \
62 const __DRIdrawablePrivate *dPriv = rrb->dPriv; \
63 const GLuint bottom = dPriv->h - 1; \
67 #define LOCAL_DEPTH_VARS \
68 struct radeon_renderbuffer *rrb = (void *) rb; \
69 const __DRIdrawablePrivate *dPriv = rrb->dPriv; \
70 const GLuint bottom = dPriv->h - 1; \
71 GLuint xo = dPriv->x; \
74 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
76 #define Y_FLIP(Y) (bottom - (Y))
82 /* ================================================================
86 /* 16 bit, RGB565 color spanline and pixel functions
88 #define SPANTMP_PIXEL_FMT GL_RGB
89 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
91 #define TAG(x) radeon##x##_RGB565
92 #define TAG2(x,y) radeon##x##_RGB565##y
93 #define GET_PTR(X,Y) radeon_ptr16(rrb, (X), (Y))
96 /* 32 bit, ARGB8888 color spanline and pixel functions
98 #define SPANTMP_PIXEL_FMT GL_BGRA
99 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
101 #define TAG(x) radeon##x##_ARGB8888
102 #define TAG2(x,y) radeon##x##_ARGB8888##y
103 #define GET_PTR(X,Y) radeon_ptr32(rrb, (X), (Y))
104 #include "spantmp2.h"
106 /* ================================================================
110 /* The Radeon family has depth tiling on all the time, so we have to convert
111 * the x,y coordinates into the memory bus address (mba) in the same
112 * manner as the engine. In each case, the linear block address (ba)
113 * is calculated, and then wired with x and y to produce the final
115 * The chip will do address translation on its own if the surface registers
116 * are set up correctly. It is not quite enough to get it working with hyperz
120 /* 16-bit depth buffer functions
122 #define VALUE_TYPE GLushort
124 #define WRITE_DEPTH( _x, _y, d ) \
125 *(GLushort *)radeon_ptr(rrb, _x + xo, _y + yo) = d
127 #define READ_DEPTH( d, _x, _y ) \
128 d = *(GLushort *)radeon_ptr(rrb, _x + xo, _y + yo)
130 #define TAG(x) radeon##x##_z16
131 #include "depthtmp.h"
133 /* 24 bit depth, 8 bit stencil depthbuffer functions
135 * Careful: It looks like the R300 uses ZZZS byte order while the R200
136 * uses SZZZ for 24 bit depth, 8 bit stencil mode.
138 #define VALUE_TYPE GLuint
141 #define WRITE_DEPTH( _x, _y, d ) \
143 GLuint *_ptr = (GLuint*)radeon_ptr32( rrb, _x + xo, _y + yo ); \
144 GLuint tmp = *_ptr; \
146 tmp |= ((d << 8) & 0xffffff00); \
150 #define WRITE_DEPTH( _x, _y, d ) \
152 GLuint *_ptr = (GLuint*)radeon_ptr32( rrb, _x + xo, _y + yo ); \
153 GLuint tmp = *_ptr; \
155 tmp |= ((d) & 0x00ffffff); \
161 #define READ_DEPTH( d, _x, _y ) \
163 d = (*(GLuint*)(radeon_ptr32(rrb, _x + xo, _y + yo)) & 0xffffff00) >> 8; \
166 #define READ_DEPTH( d, _x, _y ) \
167 d = *(GLuint*)(radeon_ptr32(rrb, _x + xo, _y + yo )) & 0x00ffffff;
170 fprintf(stderr, "dval(%d, %d, %d, %d)=0x%08X\n", _x, xo, _y, yo, d);\
171 d = *(GLuint*)(radeon_ptr(rrb, _x + xo, _y + yo )) & 0x00ffffff;
173 #define TAG(x) radeon##x##_z24_s8
174 #include "depthtmp.h"
176 /* ================================================================
180 /* 24 bit depth, 8 bit stencil depthbuffer functions
183 #define WRITE_STENCIL( _x, _y, d ) \
185 GLuint *_ptr = (GLuint*)radeon_ptr32(rrb, _x + xo, _y + yo); \
186 GLuint tmp = *_ptr; \
192 #define WRITE_STENCIL( _x, _y, d ) \
194 GLuint *_ptr = (GLuint*)radeon_ptr32(rrb, _x + xo, _y + yo); \
195 GLuint tmp = *_ptr; \
197 tmp |= (((d) & 0xff) << 24); \
203 #define READ_STENCIL( d, _x, _y ) \
205 GLuint *_ptr = (GLuint*)radeon_ptr32( rrb, _x + xo, _y + yo ); \
206 GLuint tmp = *_ptr; \
207 d = tmp & 0x000000ff; \
210 #define READ_STENCIL( d, _x, _y ) \
212 GLuint *_ptr = (GLuint*)radeon_ptr32( rrb, _x + xo, _y + yo ); \
213 GLuint tmp = *_ptr; \
214 d = (tmp & 0xff000000) >> 24; \
218 #define TAG(x) radeon##x##_z24_s8
219 #include "stenciltmp.h"
221 void radeonInitSpanFuncs(GLcontext
* ctx
)
223 struct swrast_device_driver
*swdd
=
224 _swrast_GetDeviceDriverReference(ctx
);
225 swdd
->SpanRenderStart
= radeonSpanRenderStart
;
226 swdd
->SpanRenderFinish
= radeonSpanRenderFinish
;
230 * Plug in the Get/Put routines for the given driRenderbuffer.
232 void radeonSetSpanFunctions(struct radeon_renderbuffer
*rrb
)
234 if (rrb
->base
.InternalFormat
== GL_RGB5
) {
235 radeonInitPointers_RGB565(&rrb
->base
);
236 } else if (rrb
->base
.InternalFormat
== GL_RGBA8
) {
237 radeonInitPointers_ARGB8888(&rrb
->base
);
238 } else if (rrb
->base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
239 radeonInitDepthPointers_z16(&rrb
->base
);
240 } else if (rrb
->base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
241 radeonInitDepthPointers_z24_s8(&rrb
->base
);
242 } else if (rrb
->base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
243 radeonInitStencilPointers_z24_s8(&rrb
->base
);