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
29 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
32 * Gareth Hughes <gareth@valinux.com>
37 #include "tdfx_context.h"
38 #include "tdfx_lock.h"
40 #include "tdfx_span.h"
41 #include "tdfx_tris.h"
43 #include "main/framebuffer.h"
44 #include "main/renderbuffer.h"
50 char *prevLockFile
= 0;
58 PUBLIC
const char __driConfigOptions
[] =
60 DRI_CONF_SECTION_DEBUG
61 DRI_CONF_NO_RAST(false)
65 static const __DRIextension
*tdfxExtensions
[] = {
66 &driReadDrawableExtension
,
70 static const GLuint __driNConfigOptions
= 1;
72 extern const struct dri_extension card_extensions
[];
73 extern const struct dri_extension napalm_extensions
[];
76 tdfxCreateScreen( __DRIscreenPrivate
*sPriv
)
78 tdfxScreenPrivate
*fxScreen
;
79 TDFXDRIPtr fxDRIPriv
= (TDFXDRIPtr
) sPriv
->pDevPriv
;
81 if (sPriv
->devPrivSize
!= sizeof(TDFXDRIRec
)) {
82 fprintf(stderr
,"\nERROR! sizeof(TDFXDRIRec) does not match passed size from device driver\n");
86 /* Allocate the private area */
87 fxScreen
= (tdfxScreenPrivate
*) CALLOC( sizeof(tdfxScreenPrivate
) );
91 /* parse information in __driConfigOptions */
92 driParseOptionInfo (&fxScreen
->optionCache
,
93 __driConfigOptions
, __driNConfigOptions
);
95 fxScreen
->driScrnPriv
= sPriv
;
96 sPriv
->private = (void *) fxScreen
;
98 fxScreen
->regs
.handle
= fxDRIPriv
->regs
;
99 fxScreen
->regs
.size
= fxDRIPriv
->regsSize
;
100 fxScreen
->deviceID
= fxDRIPriv
->deviceID
;
101 fxScreen
->width
= fxDRIPriv
->width
;
102 fxScreen
->height
= fxDRIPriv
->height
;
103 fxScreen
->mem
= fxDRIPriv
->mem
;
104 fxScreen
->cpp
= fxDRIPriv
->cpp
;
105 fxScreen
->stride
= fxDRIPriv
->stride
;
106 fxScreen
->fifoOffset
= fxDRIPriv
->fifoOffset
;
107 fxScreen
->fifoSize
= fxDRIPriv
->fifoSize
;
108 fxScreen
->fbOffset
= fxDRIPriv
->fbOffset
;
109 fxScreen
->backOffset
= fxDRIPriv
->backOffset
;
110 fxScreen
->depthOffset
= fxDRIPriv
->depthOffset
;
111 fxScreen
->textureOffset
= fxDRIPriv
->textureOffset
;
112 fxScreen
->textureSize
= fxDRIPriv
->textureSize
;
113 fxScreen
->sarea_priv_offset
= fxDRIPriv
->sarea_priv_offset
;
115 if ( drmMap( sPriv
->fd
, fxScreen
->regs
.handle
,
116 fxScreen
->regs
.size
, &fxScreen
->regs
.map
) ) {
120 sPriv
->extensions
= tdfxExtensions
;
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
);
346 static const __DRIconfig
**
347 tdfxFillInModes(__DRIscreenPrivate
*psp
,
350 unsigned stencil_bits
,
351 GLboolean have_back_buffer
)
353 unsigned deep
= (depth_bits
> 17);
355 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
356 * enough to add support. Basically, if a context is created with an
357 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
358 * will never be used.
361 static const GLenum db_modes
[2] = { GLX_NONE
, GLX_SWAP_UNDEFINED_OML
};
362 uint8_t depth_bits_array
[4];
363 uint8_t stencil_bits_array
[4];
365 depth_bits_array
[0] = 0;
366 depth_bits_array
[1] = 24;
367 stencil_bits_array
[0] = 0;
368 stencil_bits_array
[1] = 8;
370 depth_bits_array
[0] = depth_bits
;
371 depth_bits_array
[1] = 0;
372 depth_bits_array
[2] = depth_bits
;
373 depth_bits_array
[3] = 0;
374 stencil_bits_array
[0] = 0;
375 stencil_bits_array
[1] = 0;
376 stencil_bits_array
[2] = 8;
377 stencil_bits_array
[3] = 8;
380 return driCreateConfigs(
381 deep
? GL_RGBA
: GL_RGB
,
382 deep
? GL_UNSIGNED_INT_8_8_8_8
: GL_UNSIGNED_SHORT_5_6_5
,
390 * This is the driver specific part of the createNewScreen entry point.
392 * \todo maybe fold this into intelInitDriver
394 * \return the __GLcontextModes supported by this driver
396 static const __DRIconfig
**
397 tdfxInitScreen(__DRIscreen
*psp
)
399 static const __DRIversion ddx_expected
= { 1, 1, 0 };
400 static const __DRIversion dri_expected
= { 4, 0, 0 };
401 static const __DRIversion drm_expected
= { 1, 0, 0 };
403 /* divined from tdfx_dri.c, sketchy */
404 TDFXDRIPtr dri_priv
= (TDFXDRIPtr
) psp
->pDevPriv
;
406 /* XXX i wish it was like this */
407 /* bpp = dri_priv->bpp */
408 int bpp
= (dri_priv
->cpp
> 2) ? 24 : 16;
410 if ( ! driCheckDriDdxDrmVersions2( "tdfx",
411 &psp
->dri_version
, & dri_expected
,
412 &psp
->ddx_version
, & ddx_expected
,
413 &psp
->drm_version
, & drm_expected
) )
416 /* Calling driInitExtensions here, with a NULL context pointer,
417 * does not actually enable the extensions. It just makes sure
418 * that all the dispatch offsets for all the extensions that
419 * *might* be enables are known. This is needed because the
420 * dispatch offsets need to be known when _mesa_context_create is
421 * called, but we can't enable the extensions until we have a
424 * Hello chicken. Hello egg. How are you two today?
426 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
427 driInitExtensions( NULL
, napalm_extensions
, GL_FALSE
);
429 if (!tdfxInitDriver(psp
))
432 return tdfxFillInModes(psp
,
433 bpp
, (bpp
== 16) ? 16 : 24,
435 (dri_priv
->backOffset
!=dri_priv
->depthOffset
));
438 const struct __DriverAPIRec driDriverAPI
= {
439 .InitScreen
= tdfxInitScreen
,
440 .DestroyScreen
= tdfxDestroyScreen
,
441 .CreateContext
= tdfxCreateContext
,
442 .DestroyContext
= tdfxDestroyContext
,
443 .CreateBuffer
= tdfxCreateBuffer
,
444 .DestroyBuffer
= tdfxDestroyBuffer
,
445 .SwapBuffers
= tdfxSwapBuffers
,
446 .MakeCurrent
= tdfxMakeCurrent
,
447 .UnbindContext
= tdfxUnbindContext
,
449 .GetDrawableMSC
= NULL
,
452 .SwapBuffersMSC
= NULL