1 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mga_xmesa.c,v 1.19 2003/03/26 20:43:49 tsi Exp $ */
3 * Copyright 2000-2001 VA Linux Systems, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "mga_xmesa.h"
35 #include "simple_list.h"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
41 #include "array_cache/acache.h"
43 #include "tnl/t_pipeline.h"
45 #include "drivers/common/driverfuncs.h"
55 #include "mga_xmesa.h"
63 #include "GL/internal/dri_interface.h"
70 const char __driConfigOptions
[] =
72 DRI_CONF_SECTION_PERFORMANCE
73 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
75 DRI_CONF_SECTION_QUALITY
76 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
77 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
80 static const GLuint __driNConfigOptions
= 3;
82 #ifdef USE_NEW_INTERFACE
83 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
84 #endif /* USE_NEW_INTERFACE */
90 static int getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
92 #ifdef USE_NEW_INTERFACE
93 static __GLcontextModes
* fill_in_modes( __GLcontextModes
* modes
,
96 unsigned stencil_bits
,
97 const GLenum
* db_modes
,
98 unsigned num_db_modes
,
101 static const uint8_t bits
[2][4] = {
106 static const uint32_t masks
[2][4] = {
107 { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 },
108 { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }
113 const unsigned index
= ((pixel_bits
+ 15) / 16) - 1;
115 for ( i
= 0 ; i
< num_db_modes
; i
++ ) {
116 for ( j
= 0 ; j
< 2 ; j
++ ) {
118 modes
->redBits
= bits
[index
][0];
119 modes
->greenBits
= bits
[index
][1];
120 modes
->blueBits
= bits
[index
][2];
121 modes
->alphaBits
= bits
[index
][3];
122 modes
->redMask
= masks
[index
][0];
123 modes
->greenMask
= masks
[index
][1];
124 modes
->blueMask
= masks
[index
][2];
125 modes
->alphaMask
= masks
[index
][3];
126 modes
->rgbBits
= modes
->redBits
+ modes
->greenBits
129 modes
->accumRedBits
= 16 * j
;
130 modes
->accumGreenBits
= 16 * j
;
131 modes
->accumBlueBits
= 16 * j
;
132 modes
->accumAlphaBits
= (masks
[index
][3] != 0) ? 16 * j
: 0;
133 modes
->visualRating
= (j
== 0) ? GLX_NONE
: GLX_SLOW_CONFIG
;
135 modes
->stencilBits
= stencil_bits
;
136 modes
->depthBits
= depth_bits
;
138 modes
->visualType
= visType
;
139 modes
->renderType
= GLX_RGBA_BIT
;
140 modes
->drawableType
= GLX_WINDOW_BIT
;
141 modes
->rgbMode
= GL_TRUE
;
143 if ( db_modes
[i
] == GLX_NONE
) {
144 modes
->doubleBufferMode
= GL_FALSE
;
147 modes
->doubleBufferMode
= GL_TRUE
;
148 modes
->swapMethod
= db_modes
[i
];
157 #endif /* USE_NEW_INTERFACE */
160 #ifdef USE_NEW_INTERFACE
161 static __GLcontextModes
*
162 mgaFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
163 unsigned stencil_bits
, GLboolean have_back_buffer
)
165 __GLcontextModes
* modes
;
166 __GLcontextModes
* m
;
168 unsigned depth_buffer_factor
;
169 unsigned back_buffer_factor
;
172 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
173 * support pageflipping at all.
175 static const GLenum back_buffer_modes
[] = {
176 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
179 int depth_buffer_modes
[2][2];
182 depth_buffer_modes
[0][0] = depth_bits
;
183 depth_buffer_modes
[1][0] = depth_bits
;
185 /* Just like with the accumulation buffer, always provide some modes
186 * with a stencil buffer. It will be a sw fallback, but some apps won't
189 depth_buffer_modes
[0][1] = 0;
190 depth_buffer_modes
[1][1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
192 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
193 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
195 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
197 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
199 for ( i
= 0 ; i
< depth_buffer_factor
; i
++ ) {
200 m
= fill_in_modes( m
, pixel_bits
,
201 depth_buffer_modes
[i
][0], depth_buffer_modes
[i
][1],
202 back_buffer_modes
, back_buffer_factor
,
206 for ( i
= 0 ; i
< depth_buffer_factor
; i
++ ) {
207 m
= fill_in_modes( m
, pixel_bits
,
208 depth_buffer_modes
[i
][0], depth_buffer_modes
[i
][1],
209 back_buffer_modes
, back_buffer_factor
,
213 /* Mark the visual as slow if there are "fake" stencil bits.
215 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
216 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
217 m
->visualRating
= GLX_SLOW_CONFIG
;
223 #endif /* USE_NEW_INTERFACE */
227 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
229 mgaScreenPrivate
*mgaScreen
;
230 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
233 /* Allocate the private area */
234 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
236 __driUtilMessage("Couldn't malloc screen struct");
240 mgaScreen
->sPriv
= sPriv
;
241 sPriv
->private = (void *)mgaScreen
;
243 if (sPriv
->drmMinor
>= 1) {
245 drm_mga_getparam_t gp
;
247 gp
.param
= MGA_PARAM_IRQ_NR
;
248 gp
.value
= &mgaScreen
->irq
;
251 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
254 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
256 sPriv
->private = NULL
;
261 mgaScreen
->linecomp_sane
= (sPriv
->ddxMajor
> 1) || (sPriv
->ddxMinor
> 1)
262 || ((sPriv
->ddxMinor
== 1) && (sPriv
->ddxPatch
> 0));
264 if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
265 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
266 (PFNGLXSCRENABLEEXTENSIONPROC
) glXGetProcAddress( (const GLubyte
*) "__glXScrEnableExtension" );
267 void * const psc
= sPriv
->psc
->screenConfigs
;
269 if ( glx_enable_extension
!= NULL
) {
270 if ( mgaScreen
->linecomp_sane
) {
271 (*glx_enable_extension
)( psc
, "GLX_SGI_swap_control" );
272 (*glx_enable_extension
)( psc
, "GLX_SGI_video_sync" );
273 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_control" );
276 (*glx_enable_extension
)( psc
, "GLX_SGI_make_current_read" );
277 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_frame_usage" );
279 if ( driCompareGLXAPIVersion( 20030915 ) >= 0 ) {
280 (*glx_enable_extension
)( psc
, "GLX_SGIX_fbconfig" );
281 (*glx_enable_extension
)( psc
, "GLX_OML_swap_method" );
287 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
288 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
290 sPriv
->private = NULL
;
291 __driUtilMessage("Unrecognized chipset");
296 mgaScreen
->chipset
= serverInfo
->chipset
;
297 mgaScreen
->width
= serverInfo
->width
;
298 mgaScreen
->height
= serverInfo
->height
;
299 mgaScreen
->mem
= serverInfo
->mem
;
300 mgaScreen
->cpp
= serverInfo
->cpp
;
302 mgaScreen
->agpMode
= serverInfo
->agpMode
;
304 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
305 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
306 mgaScreen
->backOffset
= serverInfo
->backOffset
;
307 mgaScreen
->backPitch
= serverInfo
->backPitch
;
308 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
309 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
311 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
312 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
313 if ( drmMap( sPriv
->fd
,
314 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
315 &mgaScreen
->mmio
.map
) < 0 ) {
317 sPriv
->private = NULL
;
318 __driUtilMessage( "Couldn't map MMIO registers" );
322 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
323 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
324 mgaScreen
->buffers
.handle
= serverInfo
->buffers
.handle
;
325 mgaScreen
->buffers
.size
= serverInfo
->buffers
.size
;
328 mgaScreen
->agp
.handle
= serverInfo
->agp
;
329 mgaScreen
->agp
.size
= serverInfo
->agpSize
;
331 if (drmMap(sPriv
->fd
,
332 mgaScreen
->agp
.handle
,
334 (drmAddress
*)&mgaScreen
->agp
.map
) != 0)
337 sPriv
->private = NULL
;
338 __driUtilMessage("Couldn't map agp region");
343 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
344 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
345 PDEA_pagpxfer_enable
| 1);
347 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
348 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
350 mgaScreen
->logTextureGranularity
[MGA_CARD_HEAP
] =
351 serverInfo
->logTextureGranularity
;
352 mgaScreen
->logTextureGranularity
[MGA_AGP_HEAP
] =
353 serverInfo
->logAgpTextureGranularity
;
355 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
356 serverInfo
->textureOffset
);
357 if (drmMap(sPriv
->fd
,
358 serverInfo
->agpTextureOffset
,
359 serverInfo
->agpTextureSize
,
360 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0)
363 sPriv
->private = NULL
;
364 __driUtilMessage("Couldn't map agptexture region");
369 mgaScreen
->texVirtual
[MGA_AGP_HEAP
] = (mgaScreen
->agp
.map
+
370 serverInfo
->agpTextureOffset
);
373 mgaScreen
->mAccess
= serverInfo
->mAccess
;
375 /* For calculating setupdma addresses.
377 mgaScreen
->dmaOffset
= serverInfo
->buffers
.handle
;
379 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
380 if (!mgaScreen
->bufs
) {
381 /*drmUnmap(mgaScreen->agp_tex.map, mgaScreen->agp_tex.size);*/
383 sPriv
->private = NULL
;
384 __driUtilMessage("Couldn't map dma buffers");
387 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
389 /* parse information in __driConfigOptions */
390 driParseOptionInfo (&mgaScreen
->optionCache
,
391 __driConfigOptions
, __driNConfigOptions
);
398 mgaDestroyScreen(__DRIscreenPrivate
*sPriv
)
400 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
402 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
403 fprintf(stderr
, "mgaDestroyScreen\n");
405 drmUnmapBufs(mgaScreen
->bufs
);
407 /*drmUnmap(mgaScreen->agp_tex.map, mgaScreen->agp_tex.size);*/
409 /* free all option information */
410 driDestroyOptionInfo (&mgaScreen
->optionCache
);
413 sPriv
->private = NULL
;
417 extern const struct tnl_pipeline_stage _mga_render_stage
;
419 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
420 &_tnl_vertex_transform_stage
,
421 &_tnl_normal_transform_stage
,
422 &_tnl_lighting_stage
,
423 &_tnl_fog_coordinate_stage
,
425 &_tnl_texture_transform_stage
,
426 /* REMOVE: point attenuation stage */
428 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
429 /* Need new ioctl for wacceptseq */
436 static const char * const g400_extensions
[] =
438 "GL_ARB_multitexture",
439 "GL_ARB_texture_env_add",
440 "GL_ARB_texture_env_combine",
441 "GL_ARB_texture_env_crossbar",
442 "GL_EXT_texture_env_combine",
443 "GL_EXT_texture_edge_clamp",
444 "GL_ATI_texture_env_combine3",
445 #if defined (MESA_packed_depth_stencil)
446 "GL_MESA_packed_depth_stencil",
451 static const char * const card_extensions
[] =
453 "GL_ARB_multisample",
454 "GL_ARB_texture_compression",
455 "GL_EXT_blend_logic_op",
457 /* paletted_textures currently doesn't work, but we could fix them later */
459 "GL_EXT_shared_texture_palette",
460 "GL_EXT_paletted_texture",
462 "GL_EXT_secondary_color",
463 "GL_EXT_stencil_wrap",
464 "GL_EXT_texture_rectangle",
465 "GL_MESA_ycbcr_texture",
466 "GL_SGIS_generate_mipmap",
467 "GL_SGIS_texture_lod",
471 static const struct dri_debug_control debug_control
[] =
473 { "fall", DEBUG_VERBOSE_FALLBACK
},
474 { "tex", DEBUG_VERBOSE_TEXTURE
},
475 { "ioctl", DEBUG_VERBOSE_IOCTL
},
476 { "verb", DEBUG_VERBOSE_MSG
},
477 { "dri", DEBUG_VERBOSE_DRI
},
483 get_ust_nop( int64_t * ust
)
491 mgaCreateContext( const __GLcontextModes
*mesaVis
,
492 __DRIcontextPrivate
*driContextPriv
,
493 void *sharedContextPrivate
)
497 GLcontext
*ctx
, *shareCtx
;
499 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
500 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
501 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
502 mgaScreen
->sarea_priv_offset
);
503 struct dd_function_table functions
;
505 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
506 fprintf(stderr
, "mgaCreateContext\n");
508 /* allocate mga context */
509 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
514 /* Init default driver functions then plug in our Radeon-specific functions
515 * (the texture functions are especially important)
517 _mesa_init_driver_functions( &functions
);
518 mgaInitDriverFuncs( &functions
);
519 mgaInitTextureFuncs( &functions
);
520 mgaInitIoctlFuncs( &functions
);
522 /* Allocate the Mesa context */
523 if (sharedContextPrivate
)
524 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
527 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
528 &functions
, (void *) mmesa
);
533 driContextPriv
->driverPrivate
= mmesa
;
536 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
537 mmesa
->driFd
= sPriv
->fd
;
538 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
540 mmesa
->mgaScreen
= mgaScreen
;
541 mmesa
->driScreen
= sPriv
;
542 mmesa
->sarea
= (void *)saPriv
;
544 /* Parse configuration files */
545 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
546 sPriv
->myNum
, "mga");
548 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
549 make_empty_list( & mmesa
->swapped
);
551 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
552 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
553 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
554 mgaScreen
->textureSize
[i
],
557 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
558 &mmesa
->sarea
->texAge
[i
],
560 sizeof( mgaTextureObject_t
),
561 (destroy_texture_object_t
*) mgaDestroyTexObj
);
564 /* Set the maximum texture size small enough that we can guarentee
565 * that both texture units can bind a maximal texture and have them
566 * on the card at once.
569 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
570 ctx
->Const
.MaxTextureUnits
= 1;
571 ctx
->Const
.MaxTextureImageUnits
= 1;
572 ctx
->Const
.MaxTextureCoordUnits
= 1;
573 maxlevels
= G200_TEX_MAXLEVELS
;
577 ctx
->Const
.MaxTextureUnits
= 2;
578 ctx
->Const
.MaxTextureImageUnits
= 2;
579 ctx
->Const
.MaxTextureCoordUnits
= 2;
580 maxlevels
= G400_TEX_MAXLEVELS
;
583 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
587 11, /* max 2D texture size is 2048x2048 */
588 0, /* 3D textures unsupported. */
589 0, /* cube textures unsupported. */
590 11, /* max texture rect size is 2048x2048 */
594 ctx
->Const
.MinLineWidth
= 1.0;
595 ctx
->Const
.MinLineWidthAA
= 1.0;
596 ctx
->Const
.MaxLineWidth
= 10.0;
597 ctx
->Const
.MaxLineWidthAA
= 10.0;
598 ctx
->Const
.LineWidthGranularity
= 1.0;
600 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
602 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
603 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
604 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
605 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
607 switch (mesaVis
->depthBits
) {
609 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
610 mmesa
->depth_clear_mask
= ~0;
611 mmesa
->ClearDepth
= 0xffff;
614 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
615 if (mmesa
->hw_stencil
) {
616 mmesa
->depth_clear_mask
= 0xffffff00;
617 mmesa
->stencil_clear_mask
= 0x000000ff;
619 mmesa
->depth_clear_mask
= ~0;
620 mmesa
->ClearDepth
= 0xffffff00;
623 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
624 mmesa
->depth_clear_mask
= ~0;
625 mmesa
->ClearDepth
= 0xffffffff;
629 mmesa
->haveHwStipple
= GL_FALSE
;
630 mmesa
->RenderIndex
= -1; /* impossible value */
632 mmesa
->vertex_format
= 0;
633 mmesa
->CurrentTexObj
[0] = 0;
634 mmesa
->CurrentTexObj
[1] = 0;
635 mmesa
->tmu_source
[0] = 0;
636 mmesa
->tmu_source
[1] = 1;
638 mmesa
->texAge
[0] = 0;
639 mmesa
->texAge
[1] = 0;
641 /* Initialize the software rasterizer and helper modules.
643 _swrast_CreateContext( ctx
);
644 _ac_CreateContext( ctx
);
645 _tnl_CreateContext( ctx
);
647 _swsetup_CreateContext( ctx
);
649 /* Install the customized pipeline:
651 _tnl_destroy_pipeline( ctx
);
652 _tnl_install_pipeline( ctx
, mga_pipeline
);
654 /* Configure swrast and T&L to match hardware characteristics:
656 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
657 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
658 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
659 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
661 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
663 ctx
->DriverCtx
= (void *) mmesa
;
666 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
668 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
669 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
672 /* XXX these should really go right after _mesa_init_driver_functions() */
673 mgaDDInitStateFuncs( ctx
);
674 mgaDDInitSpanFuncs( ctx
);
675 mgaDDInitPixelFuncs( ctx
);
676 mgaDDInitTriFuncs( ctx
);
679 mgaInitState( mmesa
);
681 driContextPriv
->driverPrivate
= (void *) mmesa
;
684 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
688 mmesa
->vblank_flags
= ((mmesa
->mgaScreen
->irq
== 0)
689 || !mmesa
->mgaScreen
->linecomp_sane
)
690 ? VBLANK_FLAG_NO_IRQ
: driGetDefaultVBlankFlags(&mmesa
->optionCache
);
692 mmesa
->get_ust
= (PFNGLXGETUSTPROC
) glXGetProcAddress( (const GLubyte
*) "__glXGetUST" );
693 if ( mmesa
->get_ust
== NULL
) {
694 mmesa
->get_ust
= get_ust_nop
;
697 mmesa
->get_ust
= get_ust_nop
;
700 (*mmesa
->get_ust
)( & mmesa
->swap_ust
);
706 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
708 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
710 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
711 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
712 __FILE__
, __LINE__
);
714 assert(mmesa
); /* should never be null */
716 GLboolean release_texture_heaps
;
719 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
720 _swsetup_DestroyContext( mmesa
->glCtx
);
721 _tnl_DestroyContext( mmesa
->glCtx
);
722 _ac_DestroyContext( mmesa
->glCtx
);
723 _swrast_DestroyContext( mmesa
->glCtx
);
725 mgaFreeVB( mmesa
->glCtx
);
727 /* free the Mesa context */
728 mmesa
->glCtx
->DriverCtx
= NULL
;
729 _mesa_destroy_context(mmesa
->glCtx
);
731 if ( release_texture_heaps
) {
732 /* This share group is about to go away, free our private
733 * texture object data.
737 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
738 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
739 mmesa
->texture_heaps
[ i
] = NULL
;
742 assert( is_empty_list( & mmesa
->swapped
) );
745 /* free the option cache */
746 driDestroyOptionCache (&mmesa
->optionCache
);
751 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
752 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
753 __FILE__
, __LINE__
);
758 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
759 __DRIdrawablePrivate
*driDrawPriv
,
760 const __GLcontextModes
*mesaVis
,
764 return GL_FALSE
; /* not implemented */
767 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
768 mesaVis
->depthBits
!= 24);
770 driDrawPriv
->driverPrivate
= (void *)
771 _mesa_create_framebuffer(mesaVis
,
772 GL_FALSE
, /* software depth buffer? */
774 mesaVis
->accumRedBits
> 0,
775 mesaVis
->alphaBits
> 0 );
777 return (driDrawPriv
->driverPrivate
!= NULL
);
783 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
785 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
789 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
791 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
794 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
797 if (ctx
->Visual
.doubleBufferMode
) {
798 _mesa_notifySwapBuffers( ctx
);
799 mgaCopyBuffer( dPriv
);
802 /* XXX this shouldn't be an error but we can't handle it for now */
803 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
808 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
810 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
817 /* This looks buggy to me - the 'b' variable isn't used anywhere...
818 * Hmm - It seems that the drawable is already hooked in to
821 * But why are we doing context initialization here???
824 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
825 __DRIdrawablePrivate
*driDrawPriv
,
826 __DRIdrawablePrivate
*driReadPriv
)
828 if (driContextPriv
) {
829 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
831 if (mmesa
->driDrawable
!= driDrawPriv
) {
832 driDrawableInitVBlank( driDrawPriv
, mmesa
->vblank_flags
);
833 mmesa
->driDrawable
= driDrawPriv
;
835 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
836 mmesa
->mesa_drawable
= driDrawPriv
;
839 mmesa
->driReadable
= driReadPriv
;
841 _mesa_make_current2(mmesa
->glCtx
,
842 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
843 (GLframebuffer
*) driReadPriv
->driverPrivate
);
845 if (!mmesa
->glCtx
->Viewport
.Width
)
846 _mesa_set_viewport(mmesa
->glCtx
, 0, 0,
847 driDrawPriv
->w
, driDrawPriv
->h
);
851 _mesa_make_current(NULL
, NULL
);
858 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
860 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
861 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
862 int me
= mmesa
->hHWContext
;
865 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
867 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
868 mmesa
->lastStamp
= *(dPriv
->pStamp
);
869 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
870 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
871 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
874 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
876 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
878 if (sarea
->ctxOwner
!= me
) {
879 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
880 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
884 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
885 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
888 sarea
->last_quiescent
= -1; /* just kill it for now */
892 static const struct __DriverAPIRec mgaAPI
= {
893 .InitDriver
= mgaInitDriver
,
894 .DestroyScreen
= mgaDestroyScreen
,
895 .CreateContext
= mgaCreateContext
,
896 .DestroyContext
= mgaDestroyContext
,
897 .CreateBuffer
= mgaCreateBuffer
,
898 .DestroyBuffer
= mgaDestroyBuffer
,
899 .SwapBuffers
= mgaSwapBuffers
,
900 .MakeCurrent
= mgaMakeCurrent
,
901 .UnbindContext
= mgaUnbindContext
,
902 .GetSwapInfo
= getSwapInfo
,
903 .GetMSC
= driGetMSC32
,
904 .WaitForMSC
= driWaitForMSC32
,
906 .SwapBuffersMSC
= NULL
911 * This is the bootstrap function for the driver.
912 * The __driCreateScreen name is the symbol that libGL.so fetches.
913 * Return: pointer to a __DRIscreenPrivate.
915 #if !defined(DRI_NEW_INTERFACE_ONLY)
917 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
918 int numConfigs
, __GLXvisualConfig
*config
)
920 __DRIscreenPrivate
*psp
;
921 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &mgaAPI
);
925 void *__driCreateScreen(struct DRIDriverRec
*driver
,
926 struct DRIDriverContextRec
*driverContext
)
928 __DRIscreenPrivate
*psp
;
929 psp
= __driUtilCreateScreen(driver
, driverContext
, &mgaAPI
);
933 #endif /* !defined(DRI_NEW_INTERFACE_ONLY) */
937 * This is the bootstrap function for the driver. libGL supplies all of the
938 * requisite information about the system, and the driver initializes itself.
939 * This routine also fills in the linked list pointed to by \c driver_modes
940 * with the \c __GLcontextModes that the driver can support for windows or
943 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
946 #ifdef USE_NEW_INTERFACE
947 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
948 const __GLcontextModes
* modes
,
949 const __DRIversion
* ddx_version
,
950 const __DRIversion
* dri_version
,
951 const __DRIversion
* drm_version
,
952 const __DRIframebuffer
* frame_buffer
,
953 drmAddress pSAREA
, int fd
,
954 int internal_api_version
,
955 __GLcontextModes
** driver_modes
)
958 __DRIscreenPrivate
*psp
;
959 static const __DRIversion ddx_expected
= { 4, 0, 0 };
960 static const __DRIversion dri_expected
= { 1, 0, 0 };
961 static const __DRIversion drm_expected
= { 3, 0, 0 };
963 if ( ! driCheckDriDdxDrmVersions2( "MGA",
964 dri_version
, & dri_expected
,
965 ddx_version
, & ddx_expected
,
966 drm_version
, & drm_expected
) ) {
970 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
971 ddx_version
, dri_version
, drm_version
,
972 frame_buffer
, pSAREA
, fd
,
973 internal_api_version
, &mgaAPI
);
975 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
976 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
977 if ( create_context_modes
!= NULL
) {
978 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
979 *driver_modes
= mgaFillInModes( dri_priv
->cpp
* 8,
980 (dri_priv
->cpp
== 2) ? 16 : 24,
981 (dri_priv
->cpp
== 2) ? 0 : 8,
982 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
988 #endif /* USE_NEW_INTERFACE */
992 * Get information about previous buffer swaps.
995 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
999 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
1000 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
1001 || (sInfo
== NULL
) ) {
1005 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
1006 sInfo
->swap_count
= mmesa
->swap_count
;
1007 sInfo
->swap_ust
= mmesa
->swap_ust
;
1008 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
1010 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
1011 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)