1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_screen.c,v 1.3 2002/02/22 21:45:03 dawes Exp $ */
30 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
33 * Gareth Hughes <gareth@valinux.com>
38 #include "tdfx_context.h"
39 #include "tdfx_lock.h"
41 #include "tdfx_tris.h"
45 char *prevLockFile
= 0;
51 /* | DEBUG_ALWAYS_SYNC */
52 /* | DEBUG_VERBOSE_API */
53 /* | DEBUG_VERBOSE_MSG */
54 /* | DEBUG_VERBOSE_LRU */
55 /* | DEBUG_VERBOSE_DRI */
56 /* | DEBUG_VERBOSE_IOCTL */
57 /* | DEBUG_VERBOSE_2D */
64 tdfxCreateScreen( __DRIscreenPrivate
*sPriv
)
66 tdfxScreenPrivate
*fxScreen
;
67 TDFXDRIPtr fxDRIPriv
= (TDFXDRIPtr
) sPriv
->pDevPriv
;
69 /* Allocate the private area */
70 fxScreen
= (tdfxScreenPrivate
*) CALLOC( sizeof(tdfxScreenPrivate
) );
74 fxScreen
->driScrnPriv
= sPriv
;
75 sPriv
->private = (void *) fxScreen
;
77 fxScreen
->regs
.handle
= fxDRIPriv
->regs
;
78 fxScreen
->regs
.size
= fxDRIPriv
->regsSize
;
79 fxScreen
->deviceID
= fxDRIPriv
->deviceID
;
80 fxScreen
->width
= fxDRIPriv
->width
;
81 fxScreen
->height
= fxDRIPriv
->height
;
82 fxScreen
->mem
= fxDRIPriv
->mem
;
83 fxScreen
->cpp
= fxDRIPriv
->cpp
;
84 fxScreen
->stride
= fxDRIPriv
->stride
;
85 fxScreen
->fifoOffset
= fxDRIPriv
->fifoOffset
;
86 fxScreen
->fifoSize
= fxDRIPriv
->fifoSize
;
87 fxScreen
->fbOffset
= fxDRIPriv
->fbOffset
;
88 fxScreen
->backOffset
= fxDRIPriv
->backOffset
;
89 fxScreen
->depthOffset
= fxDRIPriv
->depthOffset
;
90 fxScreen
->textureOffset
= fxDRIPriv
->textureOffset
;
91 fxScreen
->textureSize
= fxDRIPriv
->textureSize
;
92 fxScreen
->sarea_priv_offset
= fxDRIPriv
->sarea_priv_offset
;
94 if ( drmMap( sPriv
->fd
, fxScreen
->regs
.handle
,
95 fxScreen
->regs
.size
, &fxScreen
->regs
.map
) ) {
104 tdfxDestroyScreen( __DRIscreenPrivate
*sPriv
)
106 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
109 drmUnmap( fxScreen
->regs
.map
, fxScreen
->regs
.size
);
112 sPriv
->private = NULL
;
118 tdfxInitDriver( __DRIscreenPrivate
*sPriv
)
120 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
121 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)sPriv
);
124 /* Check the DRI externsion version */
125 if ( sPriv
->driMajor
!= 4 || sPriv
->driMinor
< 0 ) {
126 __driUtilMessage( "tdfx DRI driver expected DRI version 4.0.x "
127 "but got version %d.%d.%d",
128 sPriv
->driMajor
, sPriv
->driMinor
, sPriv
->driPatch
);
132 /* Check that the DDX driver version is compatible */
133 if ( sPriv
->ddxMajor
!= 1 ||
134 sPriv
->ddxMinor
< 0 ) {
136 "3dfx DRI driver expected DDX driver version 1.0.x "
137 "but got version %d.%d.%d",
138 sPriv
->ddxMajor
, sPriv
->ddxMinor
, sPriv
->ddxPatch
);
142 /* Check that the DRM driver version is compatible */
143 if ( sPriv
->drmMajor
!= 1 ||
144 sPriv
->drmMinor
< 0 ) {
146 "3dfx DRI driver expected DRM driver version 1.0.x "
147 "but got version %d.%d.%d",
148 sPriv
->drmMajor
, sPriv
->drmMinor
, sPriv
->drmPatch
);
152 if ( !tdfxCreateScreen( sPriv
) ) {
153 tdfxDestroyScreen( sPriv
);
162 tdfxCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
163 __DRIdrawablePrivate
*driDrawPriv
,
164 const __GLcontextModes
*mesaVis
,
168 return GL_FALSE
; /* not implemented */
171 driDrawPriv
->driverPrivate
= (void *)
172 _mesa_create_framebuffer( mesaVis
,
173 GL_FALSE
, /* software depth buffer? */
174 mesaVis
->stencilBits
> 0,
175 mesaVis
->accumRedBits
> 0,
176 GL_FALSE
/* software alpha channel? */ );
177 return (driDrawPriv
->driverPrivate
!= NULL
);
183 tdfxDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
185 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
190 tdfxSwapBuffers( __DRIdrawablePrivate
*driDrawPriv
)
193 GET_CURRENT_CONTEXT(ctx
);
194 tdfxContextPtr fxMesa
= 0;
195 GLframebuffer
*mesaBuffer
;
197 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
198 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driDrawPriv
);
201 mesaBuffer
= (GLframebuffer
*) driDrawPriv
->driverPrivate
;
202 if ( !mesaBuffer
->Visual
.doubleBufferMode
)
203 return; /* can't swap a single-buffered window */
205 /* If the current context's drawable matches the given drawable
206 * we have to do a glFinish (per the GLX spec).
209 __DRIdrawablePrivate
*curDrawPriv
;
210 fxMesa
= TDFX_CONTEXT(ctx
);
211 curDrawPriv
= fxMesa
->driContext
->driDrawablePriv
;
213 if ( curDrawPriv
== driDrawPriv
) {
214 /* swapping window bound to current context, flush first */
215 _mesa_notifySwapBuffers( ctx
);
216 LOCK_HARDWARE( fxMesa
);
219 /* find the fxMesa context previously bound to the window */
220 fxMesa
= (tdfxContextPtr
) driDrawPriv
->driContextPriv
->driverPrivate
;
223 LOCK_HARDWARE( fxMesa
);
224 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
225 printf("SwapBuf SetState 1\n");
226 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
233 static int prevStalls
= 0;
235 stalls
= fxMesa
->Glide
.grFifoGetStalls();
237 fprintf( stderr
, "%s:\n", __FUNCTION__
);
238 if ( stalls
!= prevStalls
) {
239 fprintf( stderr
, " %d stalls occurred\n",
240 stalls
- prevStalls
);
243 if ( fxMesa
&& fxMesa
->texSwaps
) {
244 fprintf( stderr
, " %d texture swaps occurred\n",
246 fxMesa
->texSwaps
= 0;
251 if (fxMesa
->scissoredClipRects
) {
252 /* restore clip rects without scissor box */
253 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
254 driDrawPriv
->w
, driDrawPriv
->h
,
255 driDrawPriv
->numClipRects
,
256 driDrawPriv
->pClipRects
);
259 fxMesa
->Glide
.grDRIBufferSwap( fxMesa
->Glide
.SwapInterval
);
261 if (fxMesa
->scissoredClipRects
) {
262 /* restore clip rects WITH scissor box */
263 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
264 driDrawPriv
->w
, driDrawPriv
->h
,
265 fxMesa
->numClipRects
, fxMesa
->pClipRects
);
274 fxMesa
->Glide
.grGet(GR_PENDING_BUFFERSWAPS
, 4, &result
);
275 } while ( result
> fxMesa
->maxPendingSwapBuffers
);
279 fxMesa
->stats
.swapBuffer
++;
282 if (ctx
->DriverCtx
!= fxMesa
) {
283 fxMesa
= TDFX_CONTEXT(ctx
);
284 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
285 printf("SwapBuf SetState 2\n");
286 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
288 UNLOCK_HARDWARE( fxMesa
);
294 tdfxOpenCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
300 static const struct __DriverAPIRec tdfxAPI
= {
301 .InitDriver
= tdfxInitDriver
,
302 .DestroyScreen
= tdfxDestroyScreen
,
303 .CreateContext
= tdfxCreateContext
,
304 .DestroyContext
= tdfxDestroyContext
,
305 .CreateBuffer
= tdfxCreateBuffer
,
306 .DestroyBuffer
= tdfxDestroyBuffer
,
307 .SwapBuffers
= tdfxSwapBuffers
,
308 .MakeCurrent
= tdfxMakeCurrent
,
309 .UnbindContext
= tdfxUnbindContext
,
310 .OpenFullScreen
= tdfxOpenCloseFullScreen
,
311 .CloseFullScreen
= tdfxOpenCloseFullScreen
,
316 .SwapBuffersMSC
= NULL
319 #ifdef USE_NEW_INTERFACE
321 * new interface code, derived from radeon_screen.c
322 * XXX this may still be wrong
324 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
326 static __GLcontextModes
*tdfxFillInModes(unsigned pixel_bits
,
328 unsigned stencil_bits
,
329 GLboolean have_back_buffer
)
331 __GLcontextModes
*modes
;
334 unsigned vis
[2] = { GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
};
335 unsigned deep
= (depth_bits
> 17);
336 unsigned i
, db
, depth
, accum
, stencil
;
338 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
339 * enough to add support. Basically, if a context is created with an
340 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
341 * will never be used.
344 num_modes
= (depth_bits
== 16) ? 32 : 16;
346 modes
= (*create_context_modes
)(num_modes
, sizeof(__GLcontextModes
));
349 for (i
= 0; i
<= 1; i
++) {
350 for (db
= 0; db
<= 1; db
++) {
351 for (depth
= 0; depth
<= 1; depth
++) {
352 for (accum
= 0; accum
<= 1; accum
++) {
353 for (stencil
= 0; stencil
<= !deep
; stencil
++) {
354 if (deep
) stencil
= depth
;
355 m
->redBits
= deep
? 8 : 5;
356 m
->greenBits
= deep
? 8 : 6;
357 m
->blueBits
= deep
? 8 : 5;
358 m
->alphaBits
= deep
? 8 : 0;
359 m
->redMask
= deep
?0xFF000000 :0x0000F800;
360 m
->greenMask
= deep
?0x00FF0000 :0x000007E0;
361 m
->blueMask
= deep
?0x0000FF00 :0x0000001F;
362 m
->alphaMask
= deep
? 0x000000FF : 0;
363 m
->rgbBits
= m
->redBits
+ m
->greenBits
+
364 m
->blueBits
+ m
->alphaBits
;
365 m
->accumRedBits
= accum
? 16 : 0;
366 m
->accumGreenBits
= accum
? 16 : 0;
367 m
->accumBlueBits
= accum
? 16 : 0;
368 m
->accumAlphaBits
= accum
? 16 : 0;
369 m
->stencilBits
= stencil
? 8 : 0;
372 : (depth
? 0 : depth_bits
);
373 m
->visualType
= i
? GLX_TRUE_COLOR
375 m
->renderType
= GLX_RGBA_BIT
;
376 m
->drawableType
= GLX_WINDOW_BIT
;
377 m
->rgbMode
= GL_TRUE
;
378 m
->doubleBufferMode
= db
? GL_TRUE
: GL_FALSE
;
380 m
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
381 m
->visualRating
= ((stencil
&& !deep
) || accum
)
385 if (deep
) stencil
= 0;
396 * This is the bootstrap function for the driver. libGL supplies all of the
397 * requisite information about the system, and the driver initializes itself.
398 * This routine also fills in the linked list pointed to by \c driver_modes
399 * with the \c __GLcontextModes that the driver can support for windows or
402 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
405 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
406 const __GLcontextModes
* modes
,
407 const __DRIversion
* ddx_version
,
408 const __DRIversion
* dri_version
,
409 const __DRIversion
* drm_version
,
410 const __DRIframebuffer
* frame_buffer
,
411 drmAddress pSAREA
, int fd
,
412 int internal_api_version
,
413 __GLcontextModes
** driver_modes
)
415 __DRIscreenPrivate
*psp
;
417 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
418 ddx_version
, dri_version
, drm_version
,
419 frame_buffer
, pSAREA
, fd
,
420 internal_api_version
, &tdfxAPI
);
422 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
423 glXGetProcAddress((const GLubyte
*)"__glXCreateContextModes");
425 if (create_context_modes
!= NULL
) {
426 /* divined from tdfx_dri.c, sketchy */
427 TDFXDRIPtr dri_priv
= (TDFXDRIPtr
) psp
->pDevPriv
;
428 int bpp
= (dri_priv
->cpp
> 2) ? 24 : 16;
430 /* XXX i wish it was like this */
431 /* bpp = dri_priv->bpp */
433 *driver_modes
= tdfxFillInModes(bpp
, (bpp
== 16) ? 16 : 24,
435 (dri_priv
->backOffset
!=dri_priv
->depthOffset
));
440 #endif /* USE_NEW_INTERFACE */
444 * This is the bootstrap function for the driver.
445 * The __driCreateScreen name is the symbol that libGL.so fetches.
446 * Return: pointer to a __DRIscreenPrivate.
448 #if !defined(DRI_NEW_INTERFACE_ONLY)
450 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
451 int numConfigs
, __GLXvisualConfig
*config
)
453 __DRIscreenPrivate
*psp
;
454 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &tdfxAPI
);
458 void *__driCreateScreen(struct DRIDriverRec
*driver
,
459 struct DRIDriverContextRec
*driverContext
)
461 __DRIscreenPrivate
*psp
;
462 psp
= __driUtilCreateScreen(driver
, driverContext
, &tdfxAPI
);
466 #endif /* !defined(DRI_NEW_INTERFACE_ONLY) */