2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/imports.h"
37 #include "main/colormac.h"
38 #include "swrast/swrast.h"
40 #include "r200_context.h"
41 #include "r200_ioctl.h"
42 #include "r200_state.h"
43 #include "r200_span.h"
49 * Note that all information needed to access pixels in a renderbuffer
50 * should be obtained through the gl_renderbuffer parameter, not per-context
54 driRenderbuffer *drb = (driRenderbuffer *) rb; \
55 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
56 const GLuint bottom = dPriv->h - 1; \
57 GLubyte *buf = (GLubyte *) drb->flippedData \
58 + (dPriv->y * drb->flippedPitch + dPriv->x) * drb->cpp; \
62 #define LOCAL_DEPTH_VARS \
63 driRenderbuffer *drb = (driRenderbuffer *) rb; \
64 const __DRIdrawablePrivate *dPriv = drb->dPriv; \
65 const GLuint bottom = dPriv->h - 1; \
66 GLuint xo = dPriv->x; \
67 GLuint yo = dPriv->y; \
68 GLubyte *buf = (GLubyte *) drb->Base.Data;
70 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
72 #define Y_FLIP(Y) (bottom - (Y))
80 /* ================================================================
84 /* 16 bit, RGB565 color spanline and pixel functions
86 #define SPANTMP_PIXEL_FMT GL_RGB
87 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
89 #define TAG(x) r200##x##_RGB565
90 #define TAG2(x,y) r200##x##_RGB565##y
91 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 2)
94 /* 32 bit, ARGB8888 color spanline and pixel functions
96 #define SPANTMP_PIXEL_FMT GL_BGRA
97 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
99 #define TAG(x) r200##x##_ARGB8888
100 #define TAG2(x,y) r200##x##_ARGB8888##y
101 #define GET_PTR(X,Y) (buf + ((Y) * drb->flippedPitch + (X)) * 4)
102 #include "spantmp2.h"
105 /* ================================================================
109 /* The Radeon family has depth tiling on all the time, so we have to convert
110 * the x,y coordinates into the memory bus address (mba) in the same
111 * manner as the engine. In each case, the linear block address (ba)
112 * is calculated, and then wired with x and y to produce the final
114 * The chip will do address translation on its own if the surface registers
115 * are set up correctly. It is not quite enough to get it working with hyperz too...
118 /* extract bit 'b' of x, result is zero or one */
119 #define BIT(x,b) ((x & (1<<b))>>b)
122 r200_mba_z32( driRenderbuffer
*drb
, GLint x
, GLint y
)
124 GLuint pitch
= drb
->pitch
;
125 if (drb
->depthHasSurface
) {
126 return 4 * (x
+ y
* pitch
);
129 GLuint b
= ((y
& 0x7FF) >> 4) * ((pitch
& 0xFFF) >> 5) + ((x
& 0x7FF) >> 5);
140 (((pitch
& 0x20) ? (b
& 0x01) : ((b
& 0x01) ^ (BIT(y
,4)))) << 11) |
147 r200_mba_z16( driRenderbuffer
*drb
, GLint x
, GLint y
)
149 GLuint pitch
= drb
->pitch
;
150 if (drb
->depthHasSurface
) {
151 return 2 * (x
+ y
* pitch
);
154 GLuint b
= ((y
& 0x7FF) >> 4) * ((pitch
& 0xFFF) >> 6) + ((x
& 0x7FF) >> 6);
166 (((pitch
& 0x40) ? (b
& 0x01) : ((b
& 0x01) ^ (BIT(y
,4)))) << 11) |
173 /* 16-bit depth buffer functions
175 #define VALUE_TYPE GLushort
177 #define WRITE_DEPTH( _x, _y, d ) \
178 *(GLushort *)(buf + r200_mba_z16( drb, _x + xo, _y + yo )) = d;
180 #define READ_DEPTH( d, _x, _y ) \
181 d = *(GLushort *)(buf + r200_mba_z16( drb, _x + xo, _y + yo ));
183 #define TAG(x) r200##x##_z16
184 #include "depthtmp.h"
187 /* 24 bit depth, 8 bit stencil depthbuffer functions
189 #define VALUE_TYPE GLuint
191 #define WRITE_DEPTH( _x, _y, d ) \
193 GLuint offset = r200_mba_z32( drb, _x + xo, _y + yo ); \
194 GLuint tmp = *(GLuint *)(buf + offset); \
196 tmp |= ((d) & 0x00ffffff); \
197 *(GLuint *)(buf + offset) = tmp; \
200 #define READ_DEPTH( d, _x, _y ) \
201 d = *(GLuint *)(buf + r200_mba_z32( drb, _x + xo, \
202 _y + yo )) & 0x00ffffff;
204 #define TAG(x) r200##x##_z24_s8
205 #include "depthtmp.h"
208 /* ================================================================
212 /* 24 bit depth, 8 bit stencil depthbuffer functions
214 #define WRITE_STENCIL( _x, _y, d ) \
216 GLuint offset = r200_mba_z32( drb, _x + xo, _y + yo ); \
217 GLuint tmp = *(GLuint *)(buf + offset); \
219 tmp |= (((d) & 0xff) << 24); \
220 *(GLuint *)(buf + offset) = tmp; \
223 #define READ_STENCIL( d, _x, _y ) \
225 GLuint offset = r200_mba_z32( drb, _x + xo, _y + yo ); \
226 GLuint tmp = *(GLuint *)(buf + offset); \
231 #define TAG(x) r200##x##_z24_s8
232 #include "stenciltmp.h"
235 /* Move locking out to get reasonable span performance (10x better
236 * than doing this in HW_LOCK above). WaitForIdle() is the main
240 static void r200SpanRenderStart( GLcontext
*ctx
)
242 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
244 R200_FIREVERTICES( rmesa
);
245 LOCK_HARDWARE( rmesa
);
246 r200WaitForIdleLocked( rmesa
);
248 /* Read & rewrite the first pixel in the frame buffer. This should
249 * be a noop, right? In fact without this conform fails as reading
250 * from the framebuffer sometimes produces old results -- the
251 * on-card read cache gets mixed up and doesn't notice that the
252 * framebuffer has been updated.
254 * In the worst case this is buggy too as p might get the wrong
255 * value first time, so really need a hidden pixel somewhere for this.
259 driRenderbuffer
*drb
=
260 (driRenderbuffer
*) ctx
->WinSysDrawBuffer
->_ColorDrawBuffers
[0];
262 (volatile int *)(rmesa
->dri
.screen
->pFB
+ drb
->offset
);
268 static void r200SpanRenderFinish( GLcontext
*ctx
)
270 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
271 _swrast_flush( ctx
);
272 UNLOCK_HARDWARE( rmesa
);
275 void r200InitSpanFuncs( GLcontext
*ctx
)
277 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
278 swdd
->SpanRenderStart
= r200SpanRenderStart
;
279 swdd
->SpanRenderFinish
= r200SpanRenderFinish
;
285 * Plug in the Get/Put routines for the given driRenderbuffer.
288 radeonSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
290 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
291 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
292 r200InitPointers_RGB565(&drb
->Base
);
295 r200InitPointers_ARGB8888(&drb
->Base
);
298 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT16
) {
299 r200InitDepthPointers_z16(&drb
->Base
);
301 else if (drb
->Base
.InternalFormat
== GL_DEPTH_COMPONENT24
) {
302 r200InitDepthPointers_z24_s8(&drb
->Base
);
304 else if (drb
->Base
.InternalFormat
== GL_STENCIL_INDEX8_EXT
) {
305 r200InitStencilPointers_z24_s8(&drb
->Base
);