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 "main/framebuffer.h"
45 #include "main/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 __DRIextension
*tdfxExtensions
[] = {
67 &driReadDrawableExtension
,
71 static const GLuint __driNConfigOptions
= 1;
73 extern const struct dri_extension card_extensions
[];
74 extern const struct dri_extension napalm_extensions
[];
77 tdfxCreateScreen( __DRIscreenPrivate
*sPriv
)
79 tdfxScreenPrivate
*fxScreen
;
80 TDFXDRIPtr fxDRIPriv
= (TDFXDRIPtr
) sPriv
->pDevPriv
;
82 if (sPriv
->devPrivSize
!= sizeof(TDFXDRIRec
)) {
83 fprintf(stderr
,"\nERROR! sizeof(TDFXDRIRec) does not match passed size from device driver\n");
87 /* Allocate the private area */
88 fxScreen
= (tdfxScreenPrivate
*) CALLOC( sizeof(tdfxScreenPrivate
) );
92 /* parse information in __driConfigOptions */
93 driParseOptionInfo (&fxScreen
->optionCache
,
94 __driConfigOptions
, __driNConfigOptions
);
96 fxScreen
->driScrnPriv
= sPriv
;
97 sPriv
->private = (void *) fxScreen
;
99 fxScreen
->regs
.handle
= fxDRIPriv
->regs
;
100 fxScreen
->regs
.size
= fxDRIPriv
->regsSize
;
101 fxScreen
->deviceID
= fxDRIPriv
->deviceID
;
102 fxScreen
->width
= fxDRIPriv
->width
;
103 fxScreen
->height
= fxDRIPriv
->height
;
104 fxScreen
->mem
= fxDRIPriv
->mem
;
105 fxScreen
->cpp
= fxDRIPriv
->cpp
;
106 fxScreen
->stride
= fxDRIPriv
->stride
;
107 fxScreen
->fifoOffset
= fxDRIPriv
->fifoOffset
;
108 fxScreen
->fifoSize
= fxDRIPriv
->fifoSize
;
109 fxScreen
->fbOffset
= fxDRIPriv
->fbOffset
;
110 fxScreen
->backOffset
= fxDRIPriv
->backOffset
;
111 fxScreen
->depthOffset
= fxDRIPriv
->depthOffset
;
112 fxScreen
->textureOffset
= fxDRIPriv
->textureOffset
;
113 fxScreen
->textureSize
= fxDRIPriv
->textureSize
;
114 fxScreen
->sarea_priv_offset
= fxDRIPriv
->sarea_priv_offset
;
116 if ( drmMap( sPriv
->fd
, fxScreen
->regs
.handle
,
117 fxScreen
->regs
.size
, &fxScreen
->regs
.map
) ) {
121 sPriv
->extensions
= tdfxExtensions
;
128 tdfxDestroyScreen( __DRIscreenPrivate
*sPriv
)
130 tdfxScreenPrivate
*fxScreen
= (tdfxScreenPrivate
*) sPriv
->private;
135 drmUnmap( fxScreen
->regs
.map
, fxScreen
->regs
.size
);
137 /* free all option information */
138 driDestroyOptionInfo (&fxScreen
->optionCache
);
141 sPriv
->private = NULL
;
146 tdfxInitDriver( __DRIscreenPrivate
*sPriv
)
148 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
149 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)sPriv
);
152 if ( !tdfxCreateScreen( sPriv
) ) {
153 tdfxDestroyScreen( sPriv
);
162 tdfxCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
163 __DRIdrawablePrivate
*driDrawPriv
,
164 const __GLcontextModes
*mesaVis
,
167 tdfxScreenPrivate
*screen
= (tdfxScreenPrivate
*) driScrnPriv
->private;
170 return GL_FALSE
; /* not implemented */
173 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
176 driRenderbuffer
*frontRb
177 = driNewRenderbuffer(GL_RGBA
, NULL
, screen
->cpp
,
178 screen
->fbOffset
, screen
->width
, driDrawPriv
);
179 tdfxSetSpanFunctions(frontRb
, mesaVis
);
180 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
183 if (mesaVis
->doubleBufferMode
) {
184 driRenderbuffer
*backRb
185 = driNewRenderbuffer(GL_RGBA
, NULL
, screen
->cpp
,
186 screen
->backOffset
, screen
->width
,
188 tdfxSetSpanFunctions(backRb
, mesaVis
);
189 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
190 backRb
->backBuffer
= GL_TRUE
;
193 if (mesaVis
->depthBits
== 16) {
194 driRenderbuffer
*depthRb
195 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
, NULL
, screen
->cpp
,
196 screen
->depthOffset
, screen
->width
,
198 tdfxSetSpanFunctions(depthRb
, mesaVis
);
199 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
201 else if (mesaVis
->depthBits
== 24) {
202 driRenderbuffer
*depthRb
203 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
, NULL
, screen
->cpp
,
204 screen
->depthOffset
, screen
->width
,
206 tdfxSetSpanFunctions(depthRb
, mesaVis
);
207 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
210 if (mesaVis
->stencilBits
> 0) {
211 driRenderbuffer
*stencilRb
212 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
, NULL
, screen
->cpp
,
213 screen
->depthOffset
, screen
->width
,
215 tdfxSetSpanFunctions(stencilRb
, mesaVis
);
216 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
219 _mesa_add_soft_renderbuffers(fb
,
220 GL_FALSE
, /* color */
221 GL_FALSE
, /* depth */
222 GL_FALSE
, /*swStencil,*/
223 mesaVis
->accumRedBits
> 0,
224 GL_FALSE
, /* alpha */
226 driDrawPriv
->driverPrivate
= (void *) fb
;
228 return (driDrawPriv
->driverPrivate
!= NULL
);
234 tdfxDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
236 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
241 tdfxSwapBuffers( __DRIdrawablePrivate
*driDrawPriv
)
244 GET_CURRENT_CONTEXT(ctx
);
245 tdfxContextPtr fxMesa
= 0;
246 GLframebuffer
*mesaBuffer
;
248 if ( TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
249 fprintf( stderr
, "%s( %p )\n", __FUNCTION__
, (void *)driDrawPriv
);
252 mesaBuffer
= (GLframebuffer
*) driDrawPriv
->driverPrivate
;
253 if ( !mesaBuffer
->Visual
.doubleBufferMode
)
254 return; /* can't swap a single-buffered window */
256 /* If the current context's drawable matches the given drawable
257 * we have to do a glFinish (per the GLX spec).
260 __DRIdrawablePrivate
*curDrawPriv
;
261 fxMesa
= TDFX_CONTEXT(ctx
);
262 curDrawPriv
= fxMesa
->driContext
->driDrawablePriv
;
264 if ( curDrawPriv
== driDrawPriv
) {
265 /* swapping window bound to current context, flush first */
266 _mesa_notifySwapBuffers( ctx
);
267 LOCK_HARDWARE( fxMesa
);
270 /* find the fxMesa context previously bound to the window */
271 fxMesa
= (tdfxContextPtr
) driDrawPriv
->driContextPriv
->driverPrivate
;
274 LOCK_HARDWARE( fxMesa
);
275 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
277 printf("SwapBuf SetState 1\n");
279 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
286 static int prevStalls
= 0;
288 stalls
= fxMesa
->Glide
.grFifoGetStalls();
290 fprintf( stderr
, "%s:\n", __FUNCTION__
);
291 if ( stalls
!= prevStalls
) {
292 fprintf( stderr
, " %d stalls occurred\n",
293 stalls
- prevStalls
);
296 if ( fxMesa
&& fxMesa
->texSwaps
) {
297 fprintf( stderr
, " %d texture swaps occurred\n",
299 fxMesa
->texSwaps
= 0;
304 if (fxMesa
->scissoredClipRects
) {
305 /* restore clip rects without scissor box */
306 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
307 driDrawPriv
->w
, driDrawPriv
->h
,
308 driDrawPriv
->numClipRects
,
309 driDrawPriv
->pClipRects
);
312 fxMesa
->Glide
.grDRIBufferSwap( fxMesa
->Glide
.SwapInterval
);
314 if (fxMesa
->scissoredClipRects
) {
315 /* restore clip rects WITH scissor box */
316 fxMesa
->Glide
.grDRIPosition( driDrawPriv
->x
, driDrawPriv
->y
,
317 driDrawPriv
->w
, driDrawPriv
->h
,
318 fxMesa
->numClipRects
, fxMesa
->pClipRects
);
327 fxMesa
->Glide
.grGet(GR_PENDING_BUFFERSWAPS
, 4, &result
);
328 } while ( result
> fxMesa
->maxPendingSwapBuffers
);
332 fxMesa
->stats
.swapBuffer
++;
335 if (ctx
->DriverCtx
!= fxMesa
) {
336 fxMesa
= TDFX_CONTEXT(ctx
);
337 fxMesa
->Glide
.grSstSelect( fxMesa
->Glide
.Board
);
339 printf("SwapBuf SetState 2\n");
341 fxMesa
->Glide
.grGlideSetState(fxMesa
->Glide
.State
);
343 UNLOCK_HARDWARE( fxMesa
);
347 static const __DRIconfig
**
348 tdfxFillInModes(__DRIscreenPrivate
*psp
,
351 unsigned stencil_bits
,
352 GLboolean have_back_buffer
)
354 unsigned deep
= (depth_bits
> 17);
356 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
357 * enough to add support. Basically, if a context is created with an
358 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
359 * will never be used.
362 static const GLenum db_modes
[2] = { GLX_NONE
, GLX_SWAP_UNDEFINED_OML
};
363 uint8_t depth_bits_array
[4];
364 uint8_t stencil_bits_array
[4];
366 depth_bits_array
[0] = 0;
367 depth_bits_array
[1] = 24;
368 stencil_bits_array
[0] = 0;
369 stencil_bits_array
[1] = 8;
371 depth_bits_array
[0] = depth_bits
;
372 depth_bits_array
[1] = 0;
373 depth_bits_array
[2] = depth_bits
;
374 depth_bits_array
[3] = 0;
375 stencil_bits_array
[0] = 0;
376 stencil_bits_array
[1] = 0;
377 stencil_bits_array
[2] = 8;
378 stencil_bits_array
[3] = 8;
381 return driCreateConfigs(
382 deep
? GL_RGBA
: GL_RGB
,
383 deep
? GL_UNSIGNED_INT_8_8_8_8
: GL_UNSIGNED_SHORT_5_6_5
,
391 * This is the driver specific part of the createNewScreen entry point.
393 * \todo maybe fold this into intelInitDriver
395 * \return the __GLcontextModes supported by this driver
397 static const __DRIconfig
**
398 tdfxInitScreen(__DRIscreen
*psp
)
400 static const __DRIversion ddx_expected
= { 1, 1, 0 };
401 static const __DRIversion dri_expected
= { 4, 0, 0 };
402 static const __DRIversion drm_expected
= { 1, 0, 0 };
404 /* divined from tdfx_dri.c, sketchy */
405 TDFXDRIPtr dri_priv
= (TDFXDRIPtr
) psp
->pDevPriv
;
407 /* XXX i wish it was like this */
408 /* bpp = dri_priv->bpp */
409 int bpp
= (dri_priv
->cpp
> 2) ? 24 : 16;
411 if ( ! driCheckDriDdxDrmVersions2( "tdfx",
412 &psp
->dri_version
, & dri_expected
,
413 &psp
->ddx_version
, & ddx_expected
,
414 &psp
->drm_version
, & drm_expected
) )
417 /* Calling driInitExtensions here, with a NULL context pointer,
418 * does not actually enable the extensions. It just makes sure
419 * that all the dispatch offsets for all the extensions that
420 * *might* be enables are known. This is needed because the
421 * dispatch offsets need to be known when _mesa_context_create is
422 * called, but we can't enable the extensions until we have a
425 * Hello chicken. Hello egg. How are you two today?
427 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
428 driInitExtensions( NULL
, napalm_extensions
, GL_FALSE
);
430 if (!tdfxInitDriver(psp
))
433 return tdfxFillInModes(psp
,
434 bpp
, (bpp
== 16) ? 16 : 24,
436 (dri_priv
->backOffset
!=dri_priv
->depthOffset
));
439 const struct __DriverAPIRec driDriverAPI
= {
440 .InitScreen
= tdfxInitScreen
,
441 .DestroyScreen
= tdfxDestroyScreen
,
442 .CreateContext
= tdfxCreateContext
,
443 .DestroyContext
= tdfxDestroyContext
,
444 .CreateBuffer
= tdfxCreateBuffer
,
445 .DestroyBuffer
= tdfxDestroyBuffer
,
446 .SwapBuffers
= tdfxSwapBuffers
,
447 .MakeCurrent
= tdfxMakeCurrent
,
448 .UnbindContext
= tdfxUnbindContext
,
450 .GetDrawableMSC
= NULL
,
453 .SwapBuffersMSC
= NULL