732a85ecf0bdf6af17a4575f9ebe962847de0795
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 "radeon_context.h"
47 #include "radeon_ioctl.h"
48 #include "radeon_state.h"
49 #include "radeon_span.h"
50 #include "radeon_tex.h"
52 #include "drirenderbuffer.h"
57 * Note that all information needed to access pixels in a renderbuffer
58 * should be obtained through the gl_renderbuffer parameter, not per-context
62 driRenderbuffer *drb = (driRenderbuffer *) rb; \
63 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
64 const GLuint bottom = dPriv->h - 1; \
65 GLubyte *buf = (GLubyte *) drb->flippedData \
66 + (dPriv->y * drb->flippedPitch + dPriv->x) * drb->cpp; \
70 #define LOCAL_DEPTH_VARS \
71 driRenderbuffer *drb = (driRenderbuffer *) rb; \
72 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
73 const GLuint bottom = dPriv->h - 1; \
74 GLuint xo = dPriv->x; \
75 GLuint yo = dPriv->y; \
76 GLubyte *buf = (GLubyte *) drb->Base.Data;
78 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
80 #define Y_FLIP(Y) (bottom - (Y))
86 /* ================================================================
90 /* 16 bit, RGB565 color spanline and pixel functions
92 #define SPANTMP_PIXEL_FMT GL_RGB
93 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
95 #define TAG(x) radeon##x##_RGB565
96 #define TAG2(x,y) radeon##x##_RGB565##y
97 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 2)
100 /* 32 bit, ARGB8888 color spanline and pixel functions
102 #define SPANTMP_PIXEL_FMT GL_BGRA
103 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
105 #define TAG(x) radeon##x##_ARGB8888
106 #define TAG2(x,y) radeon##x##_ARGB8888##y
107 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 4)
108 #include "spantmp2.h"
110 /* ================================================================
114 /* The Radeon family has depth tiling on all the time, so we have to convert
115 * the x,y coordinates into the memory bus address (mba) in the same
116 * manner as the engine. In each case, the linear block address (ba)
117 * is calculated, and then wired with x and y to produce the final
119 * The chip will do address translation on its own if the surface registers
120 * are set up correctly. It is not quite enough to get it working with hyperz
124 static GLuint
radeon_mba_z32(const driRenderbuffer
* drb
, GLint x
, GLint y
)
126 GLuint pitch
= drb
->pitch
;
127 if (drb
->depthHasSurface
) {
128 return 4 * (x
+ y
* pitch
);
130 GLuint ba
, address
= 0; /* a[0..1] = 0 */
133 ba
= (y
/ 8) * (pitch
/ 8) + (x
/ 8);
135 ba
= (y
/ 16) * (pitch
/ 16) + (x
/ 16);
138 address
|= (x
& 0x7) << 2; /* a[2..4] = x[0..2] */
139 address
|= (y
& 0x3) << 5; /* a[5..6] = y[0..1] */
140 address
|= (((x
& 0x10) >> 2) ^ (y
& 0x4)) << 5; /* a[7] = x[4] ^ y[2] */
141 address
|= (ba
& 0x3) << 8; /* a[8..9] = ba[0..1] */
143 address
|= (y
& 0x8) << 7; /* a[10] = y[3] */
144 address
|= (((x
& 0x8) << 1) ^ (y
& 0x10)) << 7; /* a[11] = x[3] ^ y[4] */
145 address
|= (ba
& ~0x3) << 10; /* a[12..] = ba[2..] */
152 radeon_mba_z16(const driRenderbuffer
* drb
, GLint x
, GLint y
)
154 GLuint pitch
= drb
->pitch
;
155 if (drb
->depthHasSurface
) {
156 return 2 * (x
+ y
* pitch
);
158 GLuint ba
, address
= 0; /* a[0] = 0 */
160 ba
= (y
/ 16) * (pitch
/ 32) + (x
/ 32);
162 address
|= (x
& 0x7) << 1; /* a[1..3] = x[0..2] */
163 address
|= (y
& 0x7) << 4; /* a[4..6] = y[0..2] */
164 address
|= (x
& 0x8) << 4; /* a[7] = x[3] */
165 address
|= (ba
& 0x3) << 8; /* a[8..9] = ba[0..1] */
166 address
|= (y
& 0x8) << 7; /* a[10] = y[3] */
167 address
|= ((x
& 0x10) ^ (y
& 0x10)) << 7; /* a[11] = x[4] ^ y[4] */
168 address
|= (ba
& ~0x3) << 10; /* a[12..] = ba[2..] */
174 /* 16-bit depth buffer functions
176 #define WRITE_DEPTH( _x, _y, d ) \
177 *(GLushort *)(buf + radeon_mba_z16( drb, _x + xo, _y + yo )) = d;
179 #define READ_DEPTH( d, _x, _y ) \
180 d = *(GLushort *)(buf + radeon_mba_z16( drb, _x + xo, _y + yo ));
182 #define TAG(x) radeon##x##_z16
183 #include "depthtmp.h"
185 /* 24 bit depth, 8 bit stencil depthbuffer functions
187 * Careful: It looks like the R300 uses ZZZS byte order while the R200
188 * uses SZZZ for 24 bit depth, 8 bit stencil mode.
191 #define WRITE_DEPTH( _x, _y, d ) \
193 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
194 GLuint tmp = *(GLuint *)(buf + offset); \
196 tmp |= ((d << 8) & 0xffffff00); \
197 *(GLuint *)(buf + offset) = tmp; \
200 #define WRITE_DEPTH( _x, _y, d ) \
202 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
203 GLuint tmp = *(GLuint *)(buf + offset); \
205 tmp |= ((d) & 0x00ffffff); \
206 *(GLuint *)(buf + offset) = tmp; \
211 #define READ_DEPTH( d, _x, _y ) \
213 d = (*(GLuint *)(buf + radeon_mba_z32( drb, _x + xo, \
214 _y + yo )) & 0xffffff00) >> 8; \
217 #define READ_DEPTH( d, _x, _y ) \
218 d = *(GLuint *)(buf + radeon_mba_z32( drb, _x + xo, \
219 _y + yo )) & 0x00ffffff;
222 #define TAG(x) radeon##x##_z24_s8
223 #include "depthtmp.h"
225 /* ================================================================
229 /* 24 bit depth, 8 bit stencil depthbuffer functions
232 #define WRITE_STENCIL( _x, _y, d ) \
234 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
235 GLuint tmp = *(GLuint *)(buf + offset); \
238 *(GLuint *)(buf + offset) = tmp; \
241 #define WRITE_STENCIL( _x, _y, d ) \
243 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
244 GLuint tmp = *(GLuint *)(buf + offset); \
246 tmp |= (((d) & 0xff) << 24); \
247 *(GLuint *)(buf + offset) = tmp; \
252 #define READ_STENCIL( d, _x, _y ) \
254 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
255 GLuint tmp = *(GLuint *)(buf + offset); \
256 d = tmp & 0x000000ff; \
259 #define READ_STENCIL( d, _x, _y ) \
261 GLuint offset = radeon_mba_z32( drb, _x + xo, _y + yo ); \
262 GLuint tmp = *(GLuint *)(buf + offset); \
263 d = (tmp & 0xff000000) >> 24; \
267 #define TAG(x) radeon##x##_z24_s8
268 #include "stenciltmp.h"
270 /* Move locking out to get reasonable span performance (10x better
271 * than doing this in HW_LOCK above). WaitForIdle() is the main
275 static void radeonSpanRenderStart(GLcontext
* ctx
)
277 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
279 r300ContextPtr r300
= (r300ContextPtr
) rmesa
;
280 R300_FIREVERTICES(r300
);
282 RADEON_FIREVERTICES(rmesa
);
284 LOCK_HARDWARE(rmesa
);
285 radeonWaitForIdleLocked(rmesa
);
288 static void radeonSpanRenderFinish(GLcontext
* ctx
)
290 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
292 UNLOCK_HARDWARE(rmesa
);
295 void radeonInitSpanFuncs(GLcontext
* ctx
)
297 struct swrast_device_driver
*swdd
=
298 _swrast_GetDeviceDriverReference(ctx
);
299 swdd
->SpanRenderStart
= radeonSpanRenderStart
;
300 swdd
->SpanRenderFinish
= radeonSpanRenderFinish
;
304 * Plug in the Get/Put routines for the given driRenderbuffer.
306 void radeonSetSpanFunctions(driRenderbuffer
* drb
, const GLvisual
* vis
)
308 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
309 if (vis
->redBits
== 5 && vis
->greenBits
== 6
310 && vis
->blueBits
== 5) {
311 radeonInitPointers_RGB565(&drb
->Base
);
313 radeonInitPointers_ARGB8888(&drb
->Base
);
315 } else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
316 radeonInitDepthPointers_z16(&drb
->Base
);
317 } else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
318 radeonInitDepthPointers_z24_s8(&drb
->Base
);
319 } else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
320 radeonInitStencilPointers_z24_s8(&drb
->Base
);