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.
28 * MGA screen and context initialization / creation code.
30 * \author Keith Whitwell <keith@tungstengraphics.com>
37 #include "mga_xmesa.h"
40 #include "simple_list.h"
42 #include "framebuffer.h"
43 #include "renderbuffer.h"
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
50 #include "tnl/t_pipeline.h"
52 #include "drivers/common/driverfuncs.h"
62 #include "mga_xmesa.h"
68 #include "extensions.h"
69 #include "drirenderbuffer.h"
71 #include "GL/internal/dri_interface.h"
73 #define need_GL_ARB_multisample
74 #define need_GL_ARB_texture_compression
75 #define need_GL_ARB_vertex_buffer_object
76 #define need_GL_ARB_vertex_program
77 #define need_GL_EXT_fog_coord
78 #define need_GL_EXT_multi_draw_arrays
79 #define need_GL_EXT_secondary_color
81 #define need_GL_EXT_paletted_texture
83 #define need_GL_NV_vertex_program
84 #include "extension_helper.h"
90 PUBLIC
const char __driConfigOptions
[] =
92 DRI_CONF_SECTION_PERFORMANCE
93 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
95 DRI_CONF_SECTION_QUALITY
96 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
97 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
99 DRI_CONF_SECTION_SOFTWARE
100 DRI_CONF_ARB_VERTEX_PROGRAM(true)
101 DRI_CONF_NV_VERTEX_PROGRAM(true)
103 DRI_CONF_SECTION_DEBUG
104 DRI_CONF_NO_RAST(false)
107 static const GLuint __driNConfigOptions
= 6;
113 static int getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
115 static __GLcontextModes
*
116 mgaFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
117 unsigned stencil_bits
, GLboolean have_back_buffer
)
119 __GLcontextModes
* modes
;
120 __GLcontextModes
* m
;
122 unsigned depth_buffer_factor
;
123 unsigned back_buffer_factor
;
127 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
128 * support pageflipping at all.
130 static const GLenum back_buffer_modes
[] = {
131 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
134 u_int8_t depth_bits_array
[3];
135 u_int8_t stencil_bits_array
[3];
138 depth_bits_array
[0] = 0;
139 depth_bits_array
[1] = depth_bits
;
140 depth_bits_array
[2] = depth_bits
;
142 /* Just like with the accumulation buffer, always provide some modes
143 * with a stencil buffer. It will be a sw fallback, but some apps won't
146 stencil_bits_array
[0] = 0;
147 stencil_bits_array
[1] = 0;
148 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
150 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
151 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
153 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
155 if ( pixel_bits
== 16 ) {
157 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
161 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
164 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
166 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
167 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
168 back_buffer_modes
, back_buffer_factor
,
170 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
171 __func__
, __LINE__
);
175 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
176 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
177 back_buffer_modes
, back_buffer_factor
,
178 GLX_DIRECT_COLOR
) ) {
179 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
180 __func__
, __LINE__
);
184 /* Mark the visual as slow if there are "fake" stencil bits.
186 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
187 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
188 m
->visualRating
= GLX_SLOW_CONFIG
;
196 static const __DRIextension
*mgaExtensions
[] = {
197 &driSwapControlExtension
.base
,
202 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
204 mgaScreenPrivate
*mgaScreen
;
205 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
206 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
207 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->getProcAddress("glxEnableExtension"));
209 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
210 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
214 /* Allocate the private area */
215 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
217 __driUtilMessage("Couldn't malloc screen struct");
221 mgaScreen
->sPriv
= sPriv
;
222 sPriv
->private = (void *)mgaScreen
;
224 if (sPriv
->drm_version
.minor
>= 1) {
226 drm_mga_getparam_t gp
;
228 gp
.param
= MGA_PARAM_IRQ_NR
;
229 gp
.value
= &mgaScreen
->irq
;
232 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
235 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
237 sPriv
->private = NULL
;
242 sPriv
->extensions
= mgaExtensions
;
244 if ( glx_enable_extension
!= NULL
) {
245 (*glx_enable_extension
)( sPriv
->psc
, "GLX_MESA_swap_frame_usage" );
246 (*glx_enable_extension
)( sPriv
->psc
, "GLX_SGI_make_current_read" );
247 (*glx_enable_extension
)( sPriv
->psc
, "GLX_SGI_video_sync" );
250 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
251 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
253 sPriv
->private = NULL
;
254 __driUtilMessage("Unrecognized chipset");
259 mgaScreen
->chipset
= serverInfo
->chipset
;
260 mgaScreen
->cpp
= serverInfo
->cpp
;
262 mgaScreen
->agpMode
= serverInfo
->agpMode
;
264 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
265 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
266 mgaScreen
->backOffset
= serverInfo
->backOffset
;
267 mgaScreen
->backPitch
= serverInfo
->backPitch
;
268 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
269 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
272 /* The only reason that the MMIO region needs to be accessable and the
273 * primary DMA region base address needs to be known is so that the driver
274 * can busy wait for certain DMA operations to complete (see
275 * mgaWaitForFrameCompletion in mgaioctl.c).
277 * Starting with MGA DRM version 3.2, these are completely unneeded as
278 * there is a new, in-kernel mechanism for handling the wait.
281 if (mgaScreen
->sPriv
->drm_version
.minor
< 2) {
282 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
283 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
284 if ( drmMap( sPriv
->fd
,
285 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
286 &mgaScreen
->mmio
.map
) < 0 ) {
288 sPriv
->private = NULL
;
289 __driUtilMessage( "Couldn't map MMIO registers" );
293 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
294 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
297 (void) memset( & mgaScreen
->primary
, 0, sizeof( mgaScreen
->primary
) );
298 (void) memset( & mgaScreen
->mmio
, 0, sizeof( mgaScreen
->mmio
) );
301 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
302 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
303 PDEA_pagpxfer_enable
| 1);
305 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
306 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
309 /* The texVirtual array stores the base addresses in the CPU's address
310 * space of the texture memory pools. The base address of the on-card
311 * memory pool is calculated as an offset of the base of video memory. The
312 * AGP texture pool has to be mapped into the processes address space by
316 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
317 serverInfo
->textureOffset
);
319 if ( serverInfo
->agpTextureSize
> 0 ) {
320 if (drmMap(sPriv
->fd
, serverInfo
->agpTextureOffset
,
321 serverInfo
->agpTextureSize
,
322 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0) {
324 sPriv
->private = NULL
;
325 __driUtilMessage("Couldn't map agptexture region");
331 /* For calculating setupdma addresses.
334 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
335 if (!mgaScreen
->bufs
) {
337 sPriv
->private = NULL
;
338 __driUtilMessage("Couldn't map dma buffers");
341 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
343 /* parse information in __driConfigOptions */
344 driParseOptionInfo (&mgaScreen
->optionCache
,
345 __driConfigOptions
, __driNConfigOptions
);
352 mgaDestroyScreen(__DRIscreenPrivate
*sPriv
)
354 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
356 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
357 fprintf(stderr
, "mgaDestroyScreen\n");
359 drmUnmapBufs(mgaScreen
->bufs
);
362 /* free all option information */
363 driDestroyOptionInfo (&mgaScreen
->optionCache
);
366 sPriv
->private = NULL
;
370 extern const struct tnl_pipeline_stage _mga_render_stage
;
372 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
373 &_tnl_vertex_transform_stage
,
374 &_tnl_normal_transform_stage
,
375 &_tnl_lighting_stage
,
376 &_tnl_fog_coordinate_stage
,
378 &_tnl_texture_transform_stage
,
379 &_tnl_vertex_program_stage
,
381 /* REMOVE: point attenuation stage */
383 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
384 /* Need new ioctl for wacceptseq */
391 static const struct dri_extension g400_extensions
[] =
393 { "GL_ARB_multitexture", NULL
},
394 { "GL_ARB_texture_env_add", NULL
},
395 { "GL_ARB_texture_env_combine", NULL
},
396 { "GL_ARB_texture_env_crossbar", NULL
},
397 { "GL_EXT_texture_env_combine", NULL
},
398 { "GL_EXT_texture_edge_clamp", NULL
},
399 { "GL_ATI_texture_env_combine3", NULL
},
403 static const struct dri_extension card_extensions
[] =
405 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
406 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
407 { "GL_ARB_texture_rectangle", NULL
},
408 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
409 { "GL_EXT_blend_logic_op", NULL
},
410 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
411 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
412 /* paletted_textures currently doesn't work, but we could fix them later */
413 #if defined( need_GL_EXT_paletted_texture )
414 { "GL_EXT_shared_texture_palette", NULL
},
415 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
417 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
418 { "GL_EXT_stencil_wrap", NULL
},
419 { "GL_MESA_ycbcr_texture", NULL
},
420 { "GL_SGIS_generate_mipmap", NULL
},
424 static const struct dri_extension ARB_vp_extension
[] = {
425 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
429 static const struct dri_extension NV_vp_extensions
[] = {
430 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
431 { "GL_NV_vertex_program1_1", NULL
},
435 static const struct dri_debug_control debug_control
[] =
437 { "fall", DEBUG_VERBOSE_FALLBACK
},
438 { "tex", DEBUG_VERBOSE_TEXTURE
},
439 { "ioctl", DEBUG_VERBOSE_IOCTL
},
440 { "verb", DEBUG_VERBOSE_MSG
},
441 { "dri", DEBUG_VERBOSE_DRI
},
447 mgaCreateContext( const __GLcontextModes
*mesaVis
,
448 __DRIcontextPrivate
*driContextPriv
,
449 void *sharedContextPrivate
)
453 GLcontext
*ctx
, *shareCtx
;
455 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
456 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
457 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
458 mgaScreen
->sarea_priv_offset
);
459 struct dd_function_table functions
;
461 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
462 fprintf(stderr
, "mgaCreateContext\n");
464 /* allocate mga context */
465 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
470 /* Init default driver functions then plug in our Radeon-specific functions
471 * (the texture functions are especially important)
473 _mesa_init_driver_functions( &functions
);
474 mgaInitDriverFuncs( &functions
);
475 mgaInitTextureFuncs( &functions
);
476 mgaInitIoctlFuncs( &functions
);
478 /* Allocate the Mesa context */
479 if (sharedContextPrivate
)
480 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
483 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
484 &functions
, (void *) mmesa
);
489 driContextPriv
->driverPrivate
= mmesa
;
492 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
493 mmesa
->driFd
= sPriv
->fd
;
494 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
496 mmesa
->mgaScreen
= mgaScreen
;
497 mmesa
->driScreen
= sPriv
;
498 mmesa
->sarea
= (void *)saPriv
;
500 /* Parse configuration files */
501 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
502 sPriv
->myNum
, "mga");
504 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
505 make_empty_list( & mmesa
->swapped
);
507 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
508 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
509 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
510 mgaScreen
->textureSize
[i
],
513 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
514 &mmesa
->sarea
->texAge
[i
],
516 sizeof( mgaTextureObject_t
),
517 (destroy_texture_object_t
*) mgaDestroyTexObj
);
520 /* Set the maximum texture size small enough that we can guarentee
521 * that both texture units can bind a maximal texture and have them
522 * on the card at once.
525 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
526 ctx
->Const
.MaxTextureUnits
= 1;
527 ctx
->Const
.MaxTextureImageUnits
= 1;
528 ctx
->Const
.MaxTextureCoordUnits
= 1;
529 maxlevels
= G200_TEX_MAXLEVELS
;
533 ctx
->Const
.MaxTextureUnits
= 2;
534 ctx
->Const
.MaxTextureImageUnits
= 2;
535 ctx
->Const
.MaxTextureCoordUnits
= 2;
536 maxlevels
= G400_TEX_MAXLEVELS
;
539 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
543 11, /* max 2D texture size is 2048x2048 */
544 0, /* 3D textures unsupported. */
545 0, /* cube textures unsupported. */
546 11, /* max texture rect size is 2048x2048 */
551 ctx
->Const
.MinLineWidth
= 1.0;
552 ctx
->Const
.MinLineWidthAA
= 1.0;
553 ctx
->Const
.MaxLineWidth
= 10.0;
554 ctx
->Const
.MaxLineWidthAA
= 10.0;
555 ctx
->Const
.LineWidthGranularity
= 1.0;
557 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
559 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
560 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
561 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
562 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
564 switch (mesaVis
->depthBits
) {
566 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
567 mmesa
->depth_clear_mask
= ~0;
568 mmesa
->ClearDepth
= 0xffff;
571 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
572 if (mmesa
->hw_stencil
) {
573 mmesa
->depth_clear_mask
= 0xffffff00;
574 mmesa
->stencil_clear_mask
= 0x000000ff;
576 mmesa
->depth_clear_mask
= ~0;
577 mmesa
->ClearDepth
= 0xffffff00;
580 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
581 mmesa
->depth_clear_mask
= ~0;
582 mmesa
->ClearDepth
= 0xffffffff;
586 mmesa
->haveHwStipple
= GL_FALSE
;
587 mmesa
->RenderIndex
= -1; /* impossible value */
589 mmesa
->vertex_format
= 0;
590 mmesa
->CurrentTexObj
[0] = 0;
591 mmesa
->CurrentTexObj
[1] = 0;
592 mmesa
->tmu_source
[0] = 0;
593 mmesa
->tmu_source
[1] = 1;
595 mmesa
->texAge
[0] = 0;
596 mmesa
->texAge
[1] = 0;
598 /* Initialize the software rasterizer and helper modules.
600 _swrast_CreateContext( ctx
);
601 _vbo_CreateContext( ctx
);
602 _tnl_CreateContext( ctx
);
604 _swsetup_CreateContext( ctx
);
606 /* Install the customized pipeline:
608 _tnl_destroy_pipeline( ctx
);
609 _tnl_install_pipeline( ctx
, mga_pipeline
);
611 /* Configure swrast and T&L to match hardware characteristics:
613 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
614 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
615 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
616 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
618 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
620 ctx
->DriverCtx
= (void *) mmesa
;
623 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
625 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
626 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
629 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
630 driInitSingleExtension( ctx
, ARB_vp_extension
);
633 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
634 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
638 /* XXX these should really go right after _mesa_init_driver_functions() */
639 mgaDDInitStateFuncs( ctx
);
640 mgaDDInitSpanFuncs( ctx
);
641 mgaDDInitPixelFuncs( ctx
);
642 mgaDDInitTriFuncs( ctx
);
645 mgaInitState( mmesa
);
647 driContextPriv
->driverPrivate
= (void *) mmesa
;
650 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
654 mmesa
->vblank_flags
= (mmesa
->mgaScreen
->irq
== 0)
655 ? VBLANK_FLAG_NO_IRQ
: driGetDefaultVBlankFlags(&mmesa
->optionCache
);
657 (*dri_interface
->getUST
)( & mmesa
->swap_ust
);
659 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
660 fprintf(stderr
, "disabling 3D acceleration\n");
661 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
668 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
670 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
672 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
673 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
674 __FILE__
, __LINE__
);
676 assert(mmesa
); /* should never be null */
678 GLboolean release_texture_heaps
;
681 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
682 _swsetup_DestroyContext( mmesa
->glCtx
);
683 _tnl_DestroyContext( mmesa
->glCtx
);
684 _vbo_DestroyContext( mmesa
->glCtx
);
685 _swrast_DestroyContext( mmesa
->glCtx
);
687 mgaFreeVB( mmesa
->glCtx
);
689 /* free the Mesa context */
690 mmesa
->glCtx
->DriverCtx
= NULL
;
691 _mesa_destroy_context(mmesa
->glCtx
);
693 if ( release_texture_heaps
) {
694 /* This share group is about to go away, free our private
695 * texture object data.
699 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
700 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
701 mmesa
->texture_heaps
[ i
] = NULL
;
704 assert( is_empty_list( & mmesa
->swapped
) );
707 /* free the option cache */
708 driDestroyOptionCache (&mmesa
->optionCache
);
713 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
714 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
715 __FILE__
, __LINE__
);
720 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
721 __DRIdrawablePrivate
*driDrawPriv
,
722 const __GLcontextModes
*mesaVis
,
725 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
728 return GL_FALSE
; /* not implemented */
731 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
732 mesaVis
->depthBits
!= 24);
735 driDrawPriv
->driverPrivate
= (void *)
736 _mesa_create_framebuffer(mesaVis
,
737 GL_FALSE
, /* software depth buffer? */
739 mesaVis
->accumRedBits
> 0,
740 mesaVis
->alphaBits
> 0 );
742 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
745 driRenderbuffer
*frontRb
746 = driNewRenderbuffer(GL_RGBA
,
749 screen
->frontOffset
, screen
->frontPitch
,
751 mgaSetSpanFunctions(frontRb
, mesaVis
);
752 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
755 if (mesaVis
->doubleBufferMode
) {
756 driRenderbuffer
*backRb
757 = driNewRenderbuffer(GL_RGBA
,
760 screen
->backOffset
, screen
->backPitch
,
762 mgaSetSpanFunctions(backRb
, mesaVis
);
763 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
766 if (mesaVis
->depthBits
== 16) {
767 driRenderbuffer
*depthRb
768 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
771 screen
->depthOffset
, screen
->depthPitch
,
773 mgaSetSpanFunctions(depthRb
, mesaVis
);
774 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
776 else if (mesaVis
->depthBits
== 24) {
777 /* XXX is this right? */
778 if (mesaVis
->stencilBits
) {
779 driRenderbuffer
*depthRb
780 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
783 screen
->depthOffset
, screen
->depthPitch
,
785 mgaSetSpanFunctions(depthRb
, mesaVis
);
786 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
789 driRenderbuffer
*depthRb
790 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
793 screen
->depthOffset
, screen
->depthPitch
,
795 mgaSetSpanFunctions(depthRb
, mesaVis
);
796 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
799 else if (mesaVis
->depthBits
== 32) {
800 driRenderbuffer
*depthRb
801 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
804 screen
->depthOffset
, screen
->depthPitch
,
806 mgaSetSpanFunctions(depthRb
, mesaVis
);
807 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
810 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
811 driRenderbuffer
*stencilRb
812 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
815 screen
->depthOffset
, screen
->depthPitch
,
817 mgaSetSpanFunctions(stencilRb
, mesaVis
);
818 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
821 _mesa_add_soft_renderbuffers(fb
,
822 GL_FALSE
, /* color */
823 GL_FALSE
, /* depth */
825 mesaVis
->accumRedBits
> 0,
826 GL_FALSE
, /* alpha */
828 driDrawPriv
->driverPrivate
= (void *) fb
;
831 return (driDrawPriv
->driverPrivate
!= NULL
);
837 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
839 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
843 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
845 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
848 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
851 if (ctx
->Visual
.doubleBufferMode
) {
852 _mesa_notifySwapBuffers( ctx
);
853 mgaCopyBuffer( dPriv
);
856 /* XXX this shouldn't be an error but we can't handle it for now */
857 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
862 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
864 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
871 /* This looks buggy to me - the 'b' variable isn't used anywhere...
872 * Hmm - It seems that the drawable is already hooked in to
875 * But why are we doing context initialization here???
878 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
879 __DRIdrawablePrivate
*driDrawPriv
,
880 __DRIdrawablePrivate
*driReadPriv
)
882 if (driContextPriv
) {
883 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
885 if (mmesa
->driDrawable
!= driDrawPriv
) {
886 driDrawableInitVBlank( driDrawPriv
, mmesa
->vblank_flags
,
888 mmesa
->driDrawable
= driDrawPriv
;
890 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
893 mmesa
->driReadable
= driReadPriv
;
895 _mesa_make_current(mmesa
->glCtx
,
896 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
897 (GLframebuffer
*) driReadPriv
->driverPrivate
);
900 _mesa_make_current(NULL
, NULL
, NULL
);
907 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
909 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
910 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
911 int me
= mmesa
->hHWContext
;
914 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
916 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
917 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
918 mmesa
->lastStamp
= *(dPriv
->pStamp
);
919 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
920 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
921 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
922 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
925 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
927 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
929 if (sarea
->ctxOwner
!= me
) {
930 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
931 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
935 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
936 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
941 static const struct __DriverAPIRec mgaAPI
= {
942 .DestroyScreen
= mgaDestroyScreen
,
943 .CreateContext
= mgaCreateContext
,
944 .DestroyContext
= mgaDestroyContext
,
945 .CreateBuffer
= mgaCreateBuffer
,
946 .DestroyBuffer
= mgaDestroyBuffer
,
947 .SwapBuffers
= mgaSwapBuffers
,
948 .MakeCurrent
= mgaMakeCurrent
,
949 .UnbindContext
= mgaUnbindContext
,
950 .GetSwapInfo
= getSwapInfo
,
951 .GetMSC
= driGetMSC32
,
952 .WaitForMSC
= driWaitForMSC32
,
954 .SwapBuffersMSC
= NULL
959 * This is the driver specific part of the createNewScreen entry point.
961 * \todo maybe fold this into intelInitDriver
963 * \return the __GLcontextModes supported by this driver
965 __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
967 static const __DRIversion ddx_expected
= { 1, 2, 0 };
968 static const __DRIversion dri_expected
= { 4, 0, 0 };
969 static const __DRIversion drm_expected
= { 3, 0, 0 };
970 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
972 psp
->DriverAPI
= mgaAPI
;
973 if ( ! driCheckDriDdxDrmVersions2( "MGA",
974 &psp
->dri_version
, & dri_expected
,
975 &psp
->ddx_version
, & ddx_expected
,
976 &psp
->drm_version
, & drm_expected
) )
980 /* Calling driInitExtensions here, with a NULL context pointer,
981 * does not actually enable the extensions. It just makes sure
982 * that all the dispatch offsets for all the extensions that
983 * *might* be enables are known. This is needed because the
984 * dispatch offsets need to be known when _mesa_context_create is
985 * called, but we can't enable the extensions until we have a
988 * Hello chicken. Hello egg. How are you two today?
991 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
992 driInitExtensions( NULL
, g400_extensions
, GL_FALSE
);
993 driInitSingleExtension( NULL
, ARB_vp_extension
);
994 driInitExtensions( NULL
, NV_vp_extensions
, GL_FALSE
);
996 if (!mgaInitDriver(psp
))
999 return mgaFillInModes( dri_priv
->cpp
* 8,
1000 (dri_priv
->cpp
== 2) ? 16 : 24,
1001 (dri_priv
->cpp
== 2) ? 0 : 8,
1002 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1007 * Get information about previous buffer swaps.
1010 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
1012 mgaContextPtr mmesa
;
1014 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
1015 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
1016 || (sInfo
== NULL
) ) {
1020 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
1021 sInfo
->swap_count
= mmesa
->swap_count
;
1022 sInfo
->swap_ust
= mmesa
->swap_ust
;
1023 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
1025 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
1026 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)