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>
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 "drirenderbuffer.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 driRenderbuffer *drb = (driRenderbuffer *) rb; \
62 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
63 const GLuint bottom = dPriv->h - 1; \
64 GLubyte *buf = (GLubyte *) drb->flippedData \
65 + (dPriv->y * drb->flippedPitch + dPriv->x) * drb->cpp; \
69 #define LOCAL_DEPTH_VARS \
70 driRenderbuffer *drb = (driRenderbuffer *) rb; \
71 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
72 const GLuint bottom = dPriv->h - 1; \
73 GLuint xo = dPriv->x; \
74 GLuint yo = dPriv->y; \
75 GLubyte *buf = (GLubyte *) drb->Base.Data;
77 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
79 #define Y_FLIP(Y) (bottom - (Y))
85 /* ================================================================
89 /* 16 bit, RGB565 color spanline and pixel functions
91 #define SPANTMP_PIXEL_FMT GL_RGB
92 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
94 #define TAG(x) radeon##x##_RGB565
95 #define TAG2(x,y) radeon##x##_RGB565##y
96 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 2)
99 /* 32 bit, ARGB8888 color spanline and pixel functions
101 #define SPANTMP_PIXEL_FMT GL_BGRA
102 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
104 #define TAG(x) radeon##x##_ARGB8888
105 #define TAG2(x,y) radeon##x##_ARGB8888##y
106 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 4)
107 #include "spantmp2.h"
109 /* ================================================================
113 /* The Radeon family has depth tiling on all the time, so we have to convert
114 * the x,y coordinates into the memory bus address (mba) in the same
115 * manner as the engine. In each case, the linear block address (ba)
116 * is calculated, and then wired with x and y to produce the final
118 * The chip will do address translation on its own if the surface registers
119 * are set up correctly. It is not quite enough to get it working with hyperz
123 static GLuint
radeon_mba_z32(const driRenderbuffer
* drb
, GLint x
, GLint y
)
125 GLuint pitch
= drb
->pitch
;
126 if (drb
->depthHasSurface
) {
127 return 4 * (x
+ y
* pitch
);
129 GLuint ba
, address
= 0; /* a[0..1] = 0 */
131 ba
= (y
/ 8) * (pitch
/ 8) + (x
/ 8);
133 address
|= (x
& 0x7) << 2; /* a[2..4] = x[0..2] */
134 address
|= (y
& 0x3) << 5; /* a[5..6] = y[0..1] */
135 address
|= (((x
& 0x10) >> 2) ^ (y
& 0x4)) << 5; /* a[7] = x[4] ^ y[2] */
136 address
|= (ba
& 0x3) << 8; /* a[8..9] = ba[0..1] */
138 address
|= (y
& 0x8) << 7; /* a[10] = y[3] */
139 address
|= (((x
& 0x8) << 1) ^ (y
& 0x10)) << 7; /* a[11] = x[3] ^ y[4] */
140 address
|= (ba
& ~0x3) << 10; /* a[12..] = ba[2..] */
147 radeon_mba_z16(const driRenderbuffer
* drb
, GLint x
, GLint y
)
149 GLuint pitch
= drb
->pitch
;
150 if (drb
->depthHasSurface
) {
151 return 2 * (x
+ y
* pitch
);
153 GLuint ba
, address
= 0; /* a[0] = 0 */
155 ba
= (y
/ 16) * (pitch
/ 32) + (x
/ 32);
157 address
|= (x
& 0x7) << 1; /* a[1..3] = x[0..2] */
158 address
|= (y
& 0x7) << 4; /* a[4..6] = y[0..2] */
159 address
|= (x
& 0x8) << 4; /* a[7] = x[3] */
160 address
|= (ba
& 0x3) << 8; /* a[8..9] = ba[0..1] */
161 address
|= (y
& 0x8) << 7; /* a[10] = y[3] */
162 address
|= ((x
& 0x10) ^ (y
& 0x10)) << 7; /* a[11] = x[4] ^ y[4] */
163 address
|= (ba
& ~0x3) << 10; /* a[12..] = ba[2..] */
169 /* 16-bit depth buffer functions
171 #define WRITE_DEPTH( _x, _y, d ) \
172 *(GLushort *)(buf + radeon_mba_z16( drb, _x + xo, _y + yo )) = d;
174 #define READ_DEPTH( d, _x, _y ) \
175 d = *(GLushort *)(buf + radeon_mba_z16( drb, _x + xo, _y + yo ));
177 #define TAG(x) radeon##x##_z16
178 #include "depthtmp.h"
180 /* 24 bit depth, 8 bit stencil depthbuffer functions
182 * Careful: It looks like the R300 uses ZZZS byte order while the R200
183 * uses SZZZ for 24 bit depth, 8 bit stencil mode.
185 #define WRITE_DEPTH( _x, _y, d ) \
187 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
188 GLuint tmp = *(GLuint *)(buf + offset); \
190 tmp |= ((d << 8) & 0xffffff00); \
191 *(GLuint *)(buf + offset) = tmp; \
194 #define READ_DEPTH( d, _x, _y ) \
196 d = (*(GLuint *)(buf + radeon_mba_z32( drb, _x + xo, \
197 _y + yo )) & 0xffffff00) >> 8; \
200 #define TAG(x) radeon##x##_z24_s8
201 #include "depthtmp.h"
203 /* ================================================================
207 /* 24 bit depth, 8 bit stencil depthbuffer functions
209 #define WRITE_STENCIL( _x, _y, d ) \
211 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
212 GLuint tmp = *(GLuint *)(buf + offset); \
215 *(GLuint *)(buf + offset) = tmp; \
218 #define READ_STENCIL( d, _x, _y ) \
220 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
221 GLuint tmp = *(GLuint *)(buf + offset); \
222 d = tmp & 0x000000ff; \
225 #define TAG(x) radeon##x##_z24_s8
226 #include "stenciltmp.h"
228 /* Move locking out to get reasonable span performance (10x better
229 * than doing this in HW_LOCK above). WaitForIdle() is the main
233 static void radeonSpanRenderStart(GLcontext
* ctx
)
235 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
237 r300ContextPtr r300
= (r300ContextPtr
) rmesa
;
238 R300_FIREVERTICES(r300
);
240 RADEON_FIREVERTICES(rmesa
);
242 LOCK_HARDWARE(rmesa
);
243 radeonWaitForIdleLocked(rmesa
);
246 static void radeonSpanRenderFinish(GLcontext
* ctx
)
248 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
250 UNLOCK_HARDWARE(rmesa
);
253 void radeonInitSpanFuncs(GLcontext
* ctx
)
255 struct swrast_device_driver
*swdd
=
256 _swrast_GetDeviceDriverReference(ctx
);
257 swdd
->SpanRenderStart
= radeonSpanRenderStart
;
258 swdd
->SpanRenderFinish
= radeonSpanRenderFinish
;
262 * Plug in the Get/Put routines for the given driRenderbuffer.
264 void radeonSetSpanFunctions(driRenderbuffer
* drb
, const GLvisual
* vis
)
266 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
267 if (vis
->redBits
== 5 && vis
->greenBits
== 6
268 && vis
->blueBits
== 5) {
269 radeonInitPointers_RGB565(&drb
->Base
);
271 radeonInitPointers_ARGB8888(&drb
->Base
);
273 } else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
274 radeonInitDepthPointers_z16(&drb
->Base
);
275 } else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
276 radeonInitDepthPointers_z24_s8(&drb
->Base
);
277 } else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
278 radeonInitStencilPointers_z24_s8(&drb
->Base
);