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 **************************************************************************/
31 * \file radeon_context.c
32 * Common context initialization.
34 * \author Keith Whitwell <keith@tungstengraphics.com>
45 #include "drivers/common/driverfuncs.h"
46 #include "swrast/swrast.h"
48 #include "radeon_screen.h"
49 #include "r200_context.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_macros.h"
52 #include "radeon_reg.h"
53 #include "r200_state.h"
57 #include "xmlpool.h" /* for symbolic values of enum-type options */
59 #define DRIVER_DATE "20040924"
62 /* Return various strings for glGetString().
64 static const GLubyte
*radeonGetString(GLcontext
* ctx
, GLenum name
)
66 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
67 static char buffer
[128];
71 return (GLubyte
*) "Tungsten Graphics, Inc.";
76 GLuint agp_mode
= radeon
->radeonScreen
->IsPCI
? 0 :
77 radeon
->radeonScreen
->AGPMode
;
80 if (IS_FAMILY_R300(radeon
))
85 offset
= driGetRendererString(buffer
, chipname
, DRIVER_DATE
,
88 sprintf(&buffer
[offset
], " %sTCL",
89 !(radeon
->TclFallback
& RADEON_TCL_FALLBACK_TCL_DISABLE
)
92 return (GLubyte
*) buffer
;
101 /* Return the width and height of the given buffer.
103 static void radeonGetBufferSize(GLframebuffer
* buffer
,
104 GLuint
* width
, GLuint
* height
)
106 GET_CURRENT_CONTEXT(ctx
);
107 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
109 LOCK_HARDWARE(radeon
);
110 *width
= radeon
->dri
.drawable
->w
;
111 *height
= radeon
->dri
.drawable
->h
;
112 UNLOCK_HARDWARE(radeon
);
116 /* Initialize the driver's misc functions.
118 static void radeonInitDriverFuncs(struct dd_function_table
*functions
)
120 functions
->GetBufferSize
= radeonGetBufferSize
;
121 functions
->ResizeBuffers
= _swrast_alloc_buffers
;
122 functions
->GetString
= radeonGetString
;
126 static int get_ust_nop(int64_t * ust
)
133 * Create and initialize all common fields of the context,
134 * including the Mesa context itself.
136 GLboolean
radeonInitContext(radeonContextPtr radeon
,
137 struct dd_function_table
* functions
,
138 const __GLcontextModes
* glVisual
,
139 __DRIcontextPrivate
* driContextPriv
,
140 void *sharedContextPrivate
)
142 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
143 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
148 /* Fill in additional standard functions. */
149 radeonInitDriverFuncs(functions
);
151 /* Allocate and initialize the Mesa context */
152 if (sharedContextPrivate
)
153 shareCtx
= ((radeonContextPtr
)sharedContextPrivate
)->glCtx
;
156 radeon
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
157 functions
, (void *)radeon
);
162 driContextPriv
->driverPrivate
= radeon
;
165 radeon
->dri
.context
= driContextPriv
;
166 radeon
->dri
.screen
= sPriv
;
167 radeon
->dri
.drawable
= NULL
; /* Set by XMesaMakeCurrent */
168 radeon
->dri
.hwContext
= driContextPriv
->hHWContext
;
169 radeon
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
170 radeon
->dri
.fd
= sPriv
->fd
;
171 radeon
->dri
.drmMinor
= sPriv
->drmMinor
;
173 radeon
->radeonScreen
= screen
;
174 radeon
->sarea
= (drm_radeon_sarea_t
*) ((GLubyte
*) sPriv
->pSAREA
+
175 screen
->sarea_priv_offset
);
178 fthrottle_mode
= driQueryOptioni(&radeon
->optionCache
, "fthrottle_mode");
179 radeon
->iw
.irq_seq
= -1;
180 radeon
->irqsEmitted
= 0;
181 radeon
->do_irqs
= (radeon
->dri
.drmMinor
>= 6 &&
182 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
183 radeon
->radeonScreen
->irq
);
185 radeon
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
187 if (!radeon
->do_irqs
)
189 "IRQ's not enabled, falling back to %s: %d %d %d\n",
190 radeon
->do_usleeps
? "usleeps" : "busy waits",
191 radeon
->dri
.drmMinor
,
192 fthrottle_mode
, radeon
->radeonScreen
->irq
);
194 radeon
->vblank_flags
= (radeon
->radeonScreen
->irq
!= 0)
195 ? driGetDefaultVBlankFlags(&radeon
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
198 (PFNGLXGETUSTPROC
) glXGetProcAddress((const GLubyte
*)
200 if (radeon
->get_ust
== NULL
) {
201 radeon
->get_ust
= get_ust_nop
;
203 (*radeon
->get_ust
) (&radeon
->swap_ust
);
210 * Cleanup common context fields.
211 * Called by r200DestroyContext/r300DestroyContext
213 void radeonCleanupContext(radeonContextPtr radeon
)
215 /* free the Mesa context */
216 radeon
->glCtx
->DriverCtx
= NULL
;
217 _mesa_destroy_context(radeon
->glCtx
);
219 if (radeon
->state
.scissor
.pClipRects
) {
220 FREE(radeon
->state
.scissor
.pClipRects
);
221 radeon
->state
.scissor
.pClipRects
= 0;
227 * Swap front and back buffer.
229 void radeonSwapBuffers(__DRIdrawablePrivate
* dPriv
)
231 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
232 radeonContextPtr radeon
;
235 radeon
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
238 if (ctx
->Visual
.doubleBufferMode
) {
239 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
240 if (radeon
->doPageFlip
) {
241 radeonPageFlip(dPriv
);
243 radeonCopyBuffer(dPriv
);
247 /* XXX this shouldn't be an error but we can't handle it for now */
248 _mesa_problem(NULL
, "%s: drawable has no context!",
254 /* Force the context `c' to be the current context and associate with it
257 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
258 __DRIdrawablePrivate
* driDrawPriv
,
259 __DRIdrawablePrivate
* driReadPriv
)
261 if (driContextPriv
) {
262 radeonContextPtr radeon
=
263 (radeonContextPtr
) driContextPriv
->driverPrivate
;
265 if (RADEON_DEBUG
& DEBUG_DRI
)
266 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,
269 if (radeon
->dri
.drawable
!= driDrawPriv
) {
270 driDrawableInitVBlank(driDrawPriv
,
271 radeon
->vblank_flags
);
272 radeon
->dri
.drawable
= driDrawPriv
;
274 if (IS_FAMILY_R200(radeon
)) {
275 r200UpdateWindow(radeon
->glCtx
);
276 r200UpdateViewportOffset(radeon
->glCtx
);
280 _mesa_make_current2(radeon
->glCtx
,
281 (GLframebuffer
*) driDrawPriv
->
283 (GLframebuffer
*) driReadPriv
->
286 if (!radeon
->glCtx
->Viewport
.Width
) {
287 _mesa_set_viewport(radeon
->glCtx
, 0, 0,
288 driDrawPriv
->w
, driDrawPriv
->h
);
291 _mesa_update_state(radeon
->glCtx
);
293 if (IS_FAMILY_R200(radeon
))
294 r200ValidateState(radeon
->glCtx
);
297 if (RADEON_DEBUG
& DEBUG_DRI
)
298 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
299 _mesa_make_current(0, 0);
302 if (RADEON_DEBUG
& DEBUG_DRI
)
303 fprintf(stderr
, "End %s\n", __FUNCTION__
);
307 /* Force the context `c' to be unbound from its buffer.
309 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
)
311 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
313 if (RADEON_DEBUG
& DEBUG_DRI
)
314 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,