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_span.h"
42 #include "tdfx_tris.h"
44 #include "framebuffer.h"
45 #include "renderbuffer.h"
51 char *prevLockFile
= 0;
59 PUBLIC
const char __driConfigOptions
[] =
61 DRI_CONF_SECTION_DEBUG
62 DRI_CONF_NO_RAST(false)
66 static const GLuint __driNConfigOptions
= 1;
68 extern const struct dri_extension card_extensions
[];
69 extern const struct dri_extension napalm_extensions
[];
72 tdfxCreateScreen( __DRIscreenPrivate
*sPriv
)
74 tdfxScreenPrivate
*fxScreen
;
75 TDFXDRIPtr fxDRIPriv
= (TDFXDRIPtr
) sPriv
->pDevPriv
;
76 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
77 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->getProcAddress("glxEnableExtension"));
79 if (sPriv
->devPrivSize
!= sizeof(TDFXDRIRec
)) {
80 fprintf(stderr
,"\nERROR! sizeof(TDFXDRIRec) does not match passed size from device driver\n");
84 /* Allocate the private area */
85 fxScreen
= (tdfxScreenPrivate
*) CALLOC( sizeof(tdfxScreenPrivate
) );
89 /* parse information in __driConfigOptions */
90 driParseOptionInfo (&fxScreen
->optionCache
,
91 __driConfigOptions
, __driNConfigOptions
);
93 fxScreen
->driScrnPriv
= sPriv
;
94 sPriv
->private = (void *) fxScreen
;
96 fxScreen
->regs
.handle
= fxDRIPriv
->regs
;
97 fxScreen
->regs
.size
= fxDRIPriv
->regsSize
;
98 fxScreen
->deviceID
= fxDRIPriv
->deviceID
;
99 fxScreen
->width
= fxDRIPriv
->width
;
100 fxScreen
->height
= fxDRIPriv
->height
;
101 fxScreen
->mem
= fxDRIPriv
->mem
;
102 fxScreen
->cpp
= fxDRIPriv
->cpp
;
103 fxScreen
->stride
= fxDRIPriv
->stride
;
104 fxScreen
->fifoOffset
= fxDRIPriv
->fifoOffset
;
105 fxScreen
->fifoSize
= fxDRIPriv
->fifoSize
;
106 fxScreen
->fbOffset
= fxDRIPriv
->fbOffset
;
107 fxScreen
->backOffset
= fxDRIPriv
->backOffset
;
108 fxScreen
->depthOffset
= fxDRIPriv
->depthOffset
;
109 fxScreen
->textureOffset
= fxDRIPriv
->textureOffset
;
110 fxScreen
->textureSize
= fxDRIPriv
->textureSize
;
111 fxScreen
->sarea_priv_offset
= fxDRIPriv
->sarea_priv_offset
;
113 if ( drmMap( sPriv
->fd
, fxScreen
->regs
.handle
,
114 fxScreen
->regs
.size
, &fxScreen
->regs
.map
) ) {
118 if (glx_enable_extension
!= NULL
) {
119 (*glx_enable_extension
)(sPriv
->psc
, "GLX_SGI_make_current_read");
127 tdfxDestroyScreen( __DRIscreenPrivate
*sPriv
)
129 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
134 drmUnmap( fxScreen
->regs
.map
, fxScreen
->regs
.size
);
136 /* free all option information */
137 driDestroyOptionInfo (&fxScreen
->optionCache
);
140 sPriv
->private = NULL
;
145 tdfxInitDriver( __DRIscreenPrivate
*sPriv
)
147 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
148 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)sPriv
);
151 if ( !tdfxCreateScreen( sPriv
) ) {
152 tdfxDestroyScreen( sPriv
);
161 tdfxCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
162 __DRIdrawablePrivate
*driDrawPriv
,
163 const __GLcontextModes
*mesaVis
,
166 tdfxScreenPrivate
*screen
= (tdfxScreenPrivate
*) driScrnPriv
->private;
169 return GL_FALSE
; /* not implemented */
172 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
175 driRenderbuffer
*frontRb
176 = driNewRenderbuffer(GL_RGBA
, NULL
, screen
->cpp
,
177 screen
->fbOffset
, screen
->width
, driDrawPriv
);
178 tdfxSetSpanFunctions(frontRb
, mesaVis
);
179 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
182 if (mesaVis
->doubleBufferMode
) {
183 driRenderbuffer
*backRb
184 = driNewRenderbuffer(GL_RGBA
, NULL
, screen
->cpp
,
185 screen
->backOffset
, screen
->width
,
187 tdfxSetSpanFunctions(backRb
, mesaVis
);
188 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
189 backRb
->backBuffer
= GL_TRUE
;
192 if (mesaVis
->depthBits
== 16) {
193 driRenderbuffer
*depthRb
194 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
, NULL
, screen
->cpp
,
195 screen
->depthOffset
, screen
->width
,
197 tdfxSetSpanFunctions(depthRb
, mesaVis
);
198 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
200 else if (mesaVis
->depthBits
== 24) {
201 driRenderbuffer
*depthRb
202 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
, NULL
, screen
->cpp
,
203 screen
->depthOffset
, screen
->width
,
205 tdfxSetSpanFunctions(depthRb
, mesaVis
);
206 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
209 if (mesaVis
->stencilBits
> 0) {
210 driRenderbuffer
*stencilRb
211 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
, NULL
, screen
->cpp
,
212 screen
->depthOffset
, screen
->width
,
214 tdfxSetSpanFunctions(stencilRb
, mesaVis
);
215 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
218 _mesa_add_soft_renderbuffers(fb
,
219 GL_FALSE
, /* color */
220 GL_FALSE
, /* depth */
221 GL_FALSE
, /*swStencil,*/
222 mesaVis
->accumRedBits
> 0,
223 GL_FALSE
, /* alpha */
225 driDrawPriv
->driverPrivate
= (void *) fb
;
227 return (driDrawPriv
->driverPrivate
!= NULL
);
233 tdfxDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
235 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
240 tdfxSwapBuffers( __DRIdrawablePrivate
*driDrawPriv
)
243 GET_CURRENT_CONTEXT(ctx
);
244 tdfxContextPtr fxMesa
= 0;
245 GLframebuffer
*mesaBuffer
;
247 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
248 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driDrawPriv
);
251 mesaBuffer
= (GLframebuffer
*) driDrawPriv
->driverPrivate
;
252 if ( !mesaBuffer
->Visual
.doubleBufferMode
)
253 return; /* can't swap a single-buffered window */
255 /* If the current context's drawable matches the given drawable
256 * we have to do a glFinish (per the GLX spec).
259 __DRIdrawablePrivate
*curDrawPriv
;
260 fxMesa
= TDFX_CONTEXT(ctx
);
261 curDrawPriv
= fxMesa
->driContext
->driDrawablePriv
;
263 if ( curDrawPriv
== driDrawPriv
) {
264 /* swapping window bound to current context, flush first */
265 _mesa_notifySwapBuffers( ctx
);
266 LOCK_HARDWARE( fxMesa
);
269 /* find the fxMesa context previously bound to the window */
270 fxMesa
= (tdfxContextPtr
) driDrawPriv
->driContextPriv
->driverPrivate
;
273 LOCK_HARDWARE( fxMesa
);
274 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
276 printf("SwapBuf SetState 1\n");
278 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
285 static int prevStalls
= 0;
287 stalls
= fxMesa
->Glide
.grFifoGetStalls();
289 fprintf( stderr
, "%s:\n", __FUNCTION__
);
290 if ( stalls
!= prevStalls
) {
291 fprintf( stderr
, " %d stalls occurred\n",
292 stalls
- prevStalls
);
295 if ( fxMesa
&& fxMesa
->texSwaps
) {
296 fprintf( stderr
, " %d texture swaps occurred\n",
298 fxMesa
->texSwaps
= 0;
303 if (fxMesa
->scissoredClipRects
) {
304 /* restore clip rects without scissor box */
305 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
306 driDrawPriv
->w
, driDrawPriv
->h
,
307 driDrawPriv
->numClipRects
,
308 driDrawPriv
->pClipRects
);
311 fxMesa
->Glide
.grDRIBufferSwap( fxMesa
->Glide
.SwapInterval
);
313 if (fxMesa
->scissoredClipRects
) {
314 /* restore clip rects WITH scissor box */
315 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
316 driDrawPriv
->w
, driDrawPriv
->h
,
317 fxMesa
->numClipRects
, fxMesa
->pClipRects
);
326 fxMesa
->Glide
.grGet(GR_PENDING_BUFFERSWAPS
, 4, &result
);
327 } while ( result
> fxMesa
->maxPendingSwapBuffers
);
331 fxMesa
->stats
.swapBuffer
++;
334 if (ctx
->DriverCtx
!= fxMesa
) {
335 fxMesa
= TDFX_CONTEXT(ctx
);
336 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
338 printf("SwapBuf SetState 2\n");
340 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
342 UNLOCK_HARDWARE( fxMesa
);
347 static const struct __DriverAPIRec tdfxAPI
= {
348 .InitDriver
= tdfxInitDriver
,
349 .DestroyScreen
= tdfxDestroyScreen
,
350 .CreateContext
= tdfxCreateContext
,
351 .DestroyContext
= tdfxDestroyContext
,
352 .CreateBuffer
= tdfxCreateBuffer
,
353 .DestroyBuffer
= tdfxDestroyBuffer
,
354 .SwapBuffers
= tdfxSwapBuffers
,
355 .MakeCurrent
= tdfxMakeCurrent
,
356 .UnbindContext
= tdfxUnbindContext
,
361 .SwapBuffersMSC
= NULL
365 static __GLcontextModes
*tdfxFillInModes(unsigned pixel_bits
,
367 unsigned stencil_bits
,
368 GLboolean have_back_buffer
)
370 __GLcontextModes
*modes
;
373 unsigned vis
[2] = { GLX_TRUE_COLOR
, GLX_DIRECT_COLOR
};
374 unsigned deep
= (depth_bits
> 17);
375 unsigned i
, db
, depth
, accum
, stencil
;
377 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
378 * enough to add support. Basically, if a context is created with an
379 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
380 * will never be used.
383 num_modes
= (depth_bits
== 16) ? 32 : 16;
385 modes
= (*dri_interface
->createContextModes
)(num_modes
, sizeof(__GLcontextModes
));
388 for (i
= 0; i
<= 1; i
++) {
389 for (db
= 0; db
<= 1; db
++) {
390 for (depth
= 0; depth
<= 1; depth
++) {
391 for (accum
= 0; accum
<= 1; accum
++) {
392 for (stencil
= 0; stencil
<= !deep
; stencil
++) {
393 if (deep
) stencil
= depth
;
394 m
->redBits
= deep
? 8 : 5;
395 m
->greenBits
= deep
? 8 : 6;
396 m
->blueBits
= deep
? 8 : 5;
397 m
->alphaBits
= deep
? 8 : 0;
398 m
->redMask
= deep
?0xFF000000 :0x0000F800;
399 m
->greenMask
= deep
?0x00FF0000 :0x000007E0;
400 m
->blueMask
= deep
?0x0000FF00 :0x0000001F;
401 m
->alphaMask
= deep
? 0x000000FF : 0;
402 m
->rgbBits
= m
->redBits
+ m
->greenBits
+
403 m
->blueBits
+ m
->alphaBits
;
404 m
->accumRedBits
= accum
? 16 : 0;
405 m
->accumGreenBits
= accum
? 16 : 0;
406 m
->accumBlueBits
= accum
? 16 : 0;
407 m
->accumAlphaBits
= (accum
&& deep
) ? 16 : 0;
408 m
->stencilBits
= stencil
? 8 : 0;
411 : (depth
? 0 : depth_bits
);
412 m
->visualType
= vis
[i
];
413 m
->renderType
= GLX_RGBA_BIT
;
414 m
->drawableType
= GLX_WINDOW_BIT
;
415 m
->rgbMode
= GL_TRUE
;
416 m
->doubleBufferMode
= db
? GL_TRUE
: GL_FALSE
;
418 m
->swapMethod
= GLX_SWAP_UNDEFINED_OML
;
419 m
->visualRating
= ((stencil
&& !deep
) || accum
)
423 if (deep
) stencil
= 0;
434 * This is the bootstrap function for the driver. libGL supplies all of the
435 * requisite information about the system, and the driver initializes itself.
436 * This routine also fills in the linked list pointed to by \c driver_modes
437 * with the \c __GLcontextModes that the driver can support for windows or
440 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
444 void *__DRI_CREATE_NEW_SCREEN(int scrn
, __DRIscreen
*psc
,
445 const __GLcontextModes
* modes
,
446 const __DRIversion
* ddx_version
,
447 const __DRIversion
* dri_version
,
448 const __DRIversion
* drm_version
,
449 const __DRIframebuffer
* frame_buffer
,
450 drmAddress pSAREA
, int fd
,
451 int internal_api_version
,
452 const __DRIinterfaceMethods
* interface
,
453 __GLcontextModes
** driver_modes
)
455 __DRIscreenPrivate
*psp
;
456 static const __DRIversion ddx_expected
= { 1, 1, 0 };
457 static const __DRIversion dri_expected
= { 4, 0, 0 };
458 static const __DRIversion drm_expected
= { 1, 0, 0 };
460 dri_interface
= interface
;
462 if ( ! driCheckDriDdxDrmVersions2( "tdfx",
463 dri_version
, & dri_expected
,
464 ddx_version
, & ddx_expected
,
465 drm_version
, & drm_expected
) ) {
469 psp
= __driUtilCreateNewScreen(scrn
, psc
, NULL
,
470 ddx_version
, dri_version
, drm_version
,
471 frame_buffer
, pSAREA
, fd
,
472 internal_api_version
, &tdfxAPI
);
475 /* divined from tdfx_dri.c, sketchy */
476 TDFXDRIPtr dri_priv
= (TDFXDRIPtr
) psp
->pDevPriv
;
477 int bpp
= (dri_priv
->cpp
> 2) ? 24 : 16;
479 /* XXX i wish it was like this */
480 /* bpp = dri_priv->bpp */
482 *driver_modes
= tdfxFillInModes(bpp
, (bpp
== 16) ? 16 : 24,
484 (dri_priv
->backOffset
!=dri_priv
->depthOffset
));
486 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
487 * enable the extensions. It just makes sure that all the dispatch offsets for all
488 * the extensions that *might* be enables are known. This is needed because the
489 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
490 * enable the extensions until we have a context pointer.
492 * Hello chicken. Hello egg. How are you two today?
494 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
495 driInitExtensions( NULL
, napalm_extensions
, GL_FALSE
);