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>
44 #include "framebuffer.h"
46 #include "drivers/common/driverfuncs.h"
47 #include "swrast/swrast.h"
49 #include "radeon_screen.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_macros.h"
52 #include "radeon_reg.h"
54 #include "radeon_state.h"
55 #include "r300_state.h"
59 #include "xmlpool.h" /* for symbolic values of enum-type options */
61 #define DRIVER_DATE "20060815"
64 /* Return various strings for glGetString().
66 static const GLubyte
*radeonGetString(GLcontext
* ctx
, GLenum name
)
68 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
69 static char buffer
[128];
73 if (IS_R300_CLASS(radeon
->radeonScreen
))
74 return (GLubyte
*) "DRI R300 Project";
76 return (GLubyte
*) "Tungsten Graphics, Inc.";
81 GLuint agp_mode
= (radeon
->radeonScreen
->card_type
==RADEON_CARD_PCI
) ? 0 :
82 radeon
->radeonScreen
->AGPMode
;
85 if (IS_R300_CLASS(radeon
->radeonScreen
))
90 offset
= driGetRendererString(buffer
, chipname
, DRIVER_DATE
,
93 if (IS_R300_CLASS(radeon
->radeonScreen
)) {
94 sprintf(&buffer
[offset
], " %sTCL",
95 (radeon
->radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)
98 sprintf(&buffer
[offset
], " %sTCL",
99 !(radeon
->TclFallback
& RADEON_TCL_FALLBACK_TCL_DISABLE
)
103 return (GLubyte
*) buffer
;
111 /* Initialize the driver's misc functions.
113 static void radeonInitDriverFuncs(struct dd_function_table
*functions
)
115 functions
->GetString
= radeonGetString
;
120 * Create and initialize all common fields of the context,
121 * including the Mesa context itself.
123 GLboolean
radeonInitContext(radeonContextPtr radeon
,
124 struct dd_function_table
* functions
,
125 const __GLcontextModes
* glVisual
,
126 __DRIcontextPrivate
* driContextPriv
,
127 void *sharedContextPrivate
)
129 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
130 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
135 /* Fill in additional standard functions. */
136 radeonInitDriverFuncs(functions
);
138 /* Allocate and initialize the Mesa context */
139 if (sharedContextPrivate
)
140 shareCtx
= ((radeonContextPtr
)sharedContextPrivate
)->glCtx
;
143 radeon
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
144 functions
, (void *)radeon
);
149 driContextPriv
->driverPrivate
= radeon
;
152 radeon
->dri
.context
= driContextPriv
;
153 radeon
->dri
.screen
= sPriv
;
154 radeon
->dri
.drawable
= NULL
;
155 radeon
->dri
.readable
= NULL
;
156 radeon
->dri
.hwContext
= driContextPriv
->hHWContext
;
157 radeon
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
158 radeon
->dri
.fd
= sPriv
->fd
;
159 radeon
->dri
.drmMinor
= sPriv
->drmMinor
;
161 radeon
->radeonScreen
= screen
;
162 radeon
->sarea
= (drm_radeon_sarea_t
*) ((GLubyte
*) sPriv
->pSAREA
+
163 screen
->sarea_priv_offset
);
166 fthrottle_mode
= driQueryOptioni(&radeon
->optionCache
, "fthrottle_mode");
167 radeon
->iw
.irq_seq
= -1;
168 radeon
->irqsEmitted
= 0;
169 radeon
->do_irqs
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
170 radeon
->radeonScreen
->irq
);
172 radeon
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
174 if (!radeon
->do_irqs
)
176 "IRQ's not enabled, falling back to %s: %d %d\n",
177 radeon
->do_usleeps
? "usleeps" : "busy waits",
178 fthrottle_mode
, radeon
->radeonScreen
->irq
);
180 radeon
->vblank_flags
= (radeon
->radeonScreen
->irq
!= 0)
181 ? driGetDefaultVBlankFlags(&radeon
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
183 (*dri_interface
->getUST
) (&radeon
->swap_ust
);
190 * Cleanup common context fields.
191 * Called by r200DestroyContext/r300DestroyContext
193 void radeonCleanupContext(radeonContextPtr radeon
)
195 /* _mesa_destroy_context() might result in calls to functions that
196 * depend on the DriverCtx, so don't set it to NULL before.
198 * radeon->glCtx->DriverCtx = NULL;
201 /* free the Mesa context */
202 _mesa_destroy_context(radeon
->glCtx
);
204 if (radeon
->state
.scissor
.pClipRects
) {
205 FREE(radeon
->state
.scissor
.pClipRects
);
206 radeon
->state
.scissor
.pClipRects
= 0;
212 * Swap front and back buffer.
214 void radeonSwapBuffers(__DRIdrawablePrivate
* dPriv
)
216 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
217 radeonContextPtr radeon
;
220 radeon
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
223 if (ctx
->Visual
.doubleBufferMode
) {
224 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
225 if (radeon
->doPageFlip
) {
226 radeonPageFlip(dPriv
);
228 radeonCopyBuffer(dPriv
, NULL
);
232 /* XXX this shouldn't be an error but we can't handle it for now */
233 _mesa_problem(NULL
, "%s: drawable has no context!",
238 void radeonCopySubBuffer(__DRIdrawablePrivate
* dPriv
,
239 int x
, int y
, int w
, int h
)
241 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
242 radeonContextPtr radeon
;
245 radeon
= (radeonContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
248 if (ctx
->Visual
.doubleBufferMode
) {
249 drm_clip_rect_t rect
;
250 rect
.x1
= x
+ dPriv
->x
;
251 rect
.y1
= (dPriv
->h
- y
- h
) + dPriv
->y
;
252 rect
.x2
= rect
.x1
+ w
;
253 rect
.y2
= rect
.y1
+ h
;
254 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
255 radeonCopyBuffer(dPriv
, &rect
);
258 /* XXX this shouldn't be an error but we can't handle it for now */
259 _mesa_problem(NULL
, "%s: drawable has no context!",
264 /* Force the context `c' to be the current context and associate with it
267 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
268 __DRIdrawablePrivate
* driDrawPriv
,
269 __DRIdrawablePrivate
* driReadPriv
)
271 if (driContextPriv
) {
272 radeonContextPtr radeon
=
273 (radeonContextPtr
) driContextPriv
->driverPrivate
;
275 if (RADEON_DEBUG
& DEBUG_DRI
)
276 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,
279 if (radeon
->dri
.drawable
!= driDrawPriv
) {
280 driDrawableInitVBlank(driDrawPriv
,
281 radeon
->vblank_flags
,
285 radeon
->dri
.readable
= driReadPriv
;
287 if (radeon
->dri
.drawable
!= driDrawPriv
||
288 radeon
->lastStamp
!= driDrawPriv
->lastStamp
) {
289 radeon
->dri
.drawable
= driDrawPriv
;
291 radeonSetCliprects(radeon
);
292 r300UpdateViewportOffset(radeon
->glCtx
);
295 _mesa_make_current(radeon
->glCtx
,
296 (GLframebuffer
*) driDrawPriv
->
298 (GLframebuffer
*) driReadPriv
->
301 _mesa_update_state(radeon
->glCtx
);
303 radeonUpdatePageFlipping(radeon
);
305 if (RADEON_DEBUG
& DEBUG_DRI
)
306 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
307 _mesa_make_current(0, 0, 0);
310 if (RADEON_DEBUG
& DEBUG_DRI
)
311 fprintf(stderr
, "End %s\n", __FUNCTION__
);
315 /* Force the context `c' to be unbound from its buffer.
317 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
)
319 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
321 if (RADEON_DEBUG
& DEBUG_DRI
)
322 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,