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"
48 #include "array_cache/acache.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_program
76 #define need_GL_EXT_fog_coord
77 #define need_GL_EXT_multi_draw_arrays
78 #define need_GL_EXT_secondary_color
80 #define need_GL_EXT_paletted_texture
82 #define need_GL_NV_vertex_program
83 #include "extension_helper.h"
89 PUBLIC
const char __driConfigOptions
[] =
91 DRI_CONF_SECTION_PERFORMANCE
92 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
94 DRI_CONF_SECTION_QUALITY
95 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
96 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
98 DRI_CONF_SECTION_SOFTWARE
99 DRI_CONF_ARB_VERTEX_PROGRAM(true)
100 DRI_CONF_NV_VERTEX_PROGRAM(true)
102 DRI_CONF_SECTION_DEBUG
103 DRI_CONF_NO_RAST(false)
106 static const GLuint __driNConfigOptions
= 6;
112 static int getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
114 static __GLcontextModes
*
115 mgaFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
116 unsigned stencil_bits
, GLboolean have_back_buffer
)
118 __GLcontextModes
* modes
;
119 __GLcontextModes
* m
;
121 unsigned depth_buffer_factor
;
122 unsigned back_buffer_factor
;
126 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
127 * support pageflipping at all.
129 static const GLenum back_buffer_modes
[] = {
130 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
133 u_int8_t depth_bits_array
[3];
134 u_int8_t stencil_bits_array
[3];
137 depth_bits_array
[0] = 0;
138 depth_bits_array
[1] = depth_bits
;
139 depth_bits_array
[2] = depth_bits
;
141 /* Just like with the accumulation buffer, always provide some modes
142 * with a stencil buffer. It will be a sw fallback, but some apps won't
145 stencil_bits_array
[0] = 0;
146 stencil_bits_array
[1] = 0;
147 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
149 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
150 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
152 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
154 if ( pixel_bits
== 16 ) {
156 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
160 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
163 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
165 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
166 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
167 back_buffer_modes
, back_buffer_factor
,
169 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
170 __func__
, __LINE__
);
174 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
175 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
176 back_buffer_modes
, back_buffer_factor
,
177 GLX_DIRECT_COLOR
) ) {
178 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
179 __func__
, __LINE__
);
183 /* Mark the visual as slow if there are "fake" stencil bits.
185 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
186 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
187 m
->visualRating
= GLX_SLOW_CONFIG
;
196 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
198 mgaScreenPrivate
*mgaScreen
;
199 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
200 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
201 (PFNGLXSCRENABLEEXTENSIONPROC
) (*dri_interface
->getProcAddress("glxEnableExtension"));
202 void * const psc
= sPriv
->psc
->screenConfigs
;
204 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
205 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
209 /* Allocate the private area */
210 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
212 __driUtilMessage("Couldn't malloc screen struct");
216 mgaScreen
->sPriv
= sPriv
;
217 sPriv
->private = (void *)mgaScreen
;
219 if (sPriv
->drmMinor
>= 1) {
221 drm_mga_getparam_t gp
;
223 gp
.param
= MGA_PARAM_IRQ_NR
;
224 gp
.value
= &mgaScreen
->irq
;
227 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
230 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
232 sPriv
->private = NULL
;
237 if ( glx_enable_extension
!= NULL
) {
238 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_control" );
239 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_frame_usage" );
240 (*glx_enable_extension
)( psc
, "GLX_SGI_make_current_read" );
241 (*glx_enable_extension
)( psc
, "GLX_SGI_swap_control" );
242 (*glx_enable_extension
)( psc
, "GLX_SGI_video_sync" );
245 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
246 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
248 sPriv
->private = NULL
;
249 __driUtilMessage("Unrecognized chipset");
254 mgaScreen
->chipset
= serverInfo
->chipset
;
255 mgaScreen
->cpp
= serverInfo
->cpp
;
257 mgaScreen
->agpMode
= serverInfo
->agpMode
;
259 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
260 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
261 mgaScreen
->backOffset
= serverInfo
->backOffset
;
262 mgaScreen
->backPitch
= serverInfo
->backPitch
;
263 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
264 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
267 /* The only reason that the MMIO region needs to be accessable and the
268 * primary DMA region base address needs to be known is so that the driver
269 * can busy wait for certain DMA operations to complete (see
270 * mgaWaitForFrameCompletion in mgaioctl.c).
272 * Starting with MGA DRM version 3.2, these are completely unneeded as
273 * there is a new, in-kernel mechanism for handling the wait.
276 if (mgaScreen
->sPriv
->drmMinor
< 2) {
277 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
278 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
279 if ( drmMap( sPriv
->fd
,
280 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
281 &mgaScreen
->mmio
.map
) < 0 ) {
283 sPriv
->private = NULL
;
284 __driUtilMessage( "Couldn't map MMIO registers" );
288 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
289 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
292 (void) memset( & mgaScreen
->primary
, 0, sizeof( mgaScreen
->primary
) );
293 (void) memset( & mgaScreen
->mmio
, 0, sizeof( mgaScreen
->mmio
) );
296 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
297 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
298 PDEA_pagpxfer_enable
| 1);
300 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
301 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
304 /* The texVirtual array stores the base addresses in the CPU's address
305 * space of the texture memory pools. The base address of the on-card
306 * memory pool is calculated as an offset of the base of video memory. The
307 * AGP texture pool has to be mapped into the processes address space by
311 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
312 serverInfo
->textureOffset
);
314 if ( serverInfo
->agpTextureSize
> 0 ) {
315 if (drmMap(sPriv
->fd
, serverInfo
->agpTextureOffset
,
316 serverInfo
->agpTextureSize
,
317 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0) {
319 sPriv
->private = NULL
;
320 __driUtilMessage("Couldn't map agptexture region");
326 /* For calculating setupdma addresses.
329 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
330 if (!mgaScreen
->bufs
) {
332 sPriv
->private = NULL
;
333 __driUtilMessage("Couldn't map dma buffers");
336 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
338 /* parse information in __driConfigOptions */
339 driParseOptionInfo (&mgaScreen
->optionCache
,
340 __driConfigOptions
, __driNConfigOptions
);
347 mgaDestroyScreen(__DRIscreenPrivate
*sPriv
)
349 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
351 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
352 fprintf(stderr
, "mgaDestroyScreen\n");
354 drmUnmapBufs(mgaScreen
->bufs
);
357 /* free all option information */
358 driDestroyOptionInfo (&mgaScreen
->optionCache
);
361 sPriv
->private = NULL
;
365 extern const struct tnl_pipeline_stage _mga_render_stage
;
367 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
368 &_tnl_vertex_transform_stage
,
369 &_tnl_normal_transform_stage
,
370 &_tnl_lighting_stage
,
371 &_tnl_fog_coordinate_stage
,
373 &_tnl_texture_transform_stage
,
374 &_tnl_arb_vertex_program_stage
,
375 &_tnl_vertex_program_stage
,
377 /* REMOVE: point attenuation stage */
379 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
380 /* Need new ioctl for wacceptseq */
387 static const struct dri_extension g400_extensions
[] =
389 { "GL_ARB_multitexture", NULL
},
390 { "GL_ARB_texture_env_add", NULL
},
391 { "GL_ARB_texture_env_combine", NULL
},
392 { "GL_ARB_texture_env_crossbar", NULL
},
393 { "GL_EXT_texture_env_combine", NULL
},
394 { "GL_EXT_texture_edge_clamp", NULL
},
395 { "GL_ATI_texture_env_combine3", NULL
},
399 static const struct dri_extension card_extensions
[] =
401 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
402 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
403 { "GL_ARB_texture_rectangle", NULL
},
404 { "GL_EXT_blend_logic_op", NULL
},
405 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
406 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
407 /* paletted_textures currently doesn't work, but we could fix them later */
408 #if defined( need_GL_EXT_paletted_texture )
409 { "GL_EXT_shared_texture_palette", NULL
},
410 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
412 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
413 { "GL_EXT_stencil_wrap", NULL
},
414 { "GL_MESA_ycbcr_texture", NULL
},
415 { "GL_SGIS_generate_mipmap", NULL
},
419 static const struct dri_extension ARB_vp_extension
[] = {
420 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
424 static const struct dri_extension NV_vp_extensions
[] = {
425 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
426 { "GL_NV_vertex_program1_1", NULL
},
430 static const struct dri_debug_control debug_control
[] =
432 { "fall", DEBUG_VERBOSE_FALLBACK
},
433 { "tex", DEBUG_VERBOSE_TEXTURE
},
434 { "ioctl", DEBUG_VERBOSE_IOCTL
},
435 { "verb", DEBUG_VERBOSE_MSG
},
436 { "dri", DEBUG_VERBOSE_DRI
},
442 mgaCreateContext( const __GLcontextModes
*mesaVis
,
443 __DRIcontextPrivate
*driContextPriv
,
444 void *sharedContextPrivate
)
448 GLcontext
*ctx
, *shareCtx
;
450 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
451 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
452 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
453 mgaScreen
->sarea_priv_offset
);
454 struct dd_function_table functions
;
456 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
457 fprintf(stderr
, "mgaCreateContext\n");
459 /* allocate mga context */
460 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
465 /* Init default driver functions then plug in our Radeon-specific functions
466 * (the texture functions are especially important)
468 _mesa_init_driver_functions( &functions
);
469 mgaInitDriverFuncs( &functions
);
470 mgaInitTextureFuncs( &functions
);
471 mgaInitIoctlFuncs( &functions
);
473 /* Allocate the Mesa context */
474 if (sharedContextPrivate
)
475 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
478 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
479 &functions
, (void *) mmesa
);
484 driContextPriv
->driverPrivate
= mmesa
;
487 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
488 mmesa
->driFd
= sPriv
->fd
;
489 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
491 mmesa
->mgaScreen
= mgaScreen
;
492 mmesa
->driScreen
= sPriv
;
493 mmesa
->sarea
= (void *)saPriv
;
495 /* Parse configuration files */
496 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
497 sPriv
->myNum
, "mga");
499 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
500 make_empty_list( & mmesa
->swapped
);
502 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
503 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
504 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
505 mgaScreen
->textureSize
[i
],
508 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
509 &mmesa
->sarea
->texAge
[i
],
511 sizeof( mgaTextureObject_t
),
512 (destroy_texture_object_t
*) mgaDestroyTexObj
);
515 /* Set the maximum texture size small enough that we can guarentee
516 * that both texture units can bind a maximal texture and have them
517 * on the card at once.
520 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
521 ctx
->Const
.MaxTextureUnits
= 1;
522 ctx
->Const
.MaxTextureImageUnits
= 1;
523 ctx
->Const
.MaxTextureCoordUnits
= 1;
524 maxlevels
= G200_TEX_MAXLEVELS
;
528 ctx
->Const
.MaxTextureUnits
= 2;
529 ctx
->Const
.MaxTextureImageUnits
= 2;
530 ctx
->Const
.MaxTextureCoordUnits
= 2;
531 maxlevels
= G400_TEX_MAXLEVELS
;
534 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
538 11, /* max 2D texture size is 2048x2048 */
539 0, /* 3D textures unsupported. */
540 0, /* cube textures unsupported. */
541 11, /* max texture rect size is 2048x2048 */
545 ctx
->Const
.MinLineWidth
= 1.0;
546 ctx
->Const
.MinLineWidthAA
= 1.0;
547 ctx
->Const
.MaxLineWidth
= 10.0;
548 ctx
->Const
.MaxLineWidthAA
= 10.0;
549 ctx
->Const
.LineWidthGranularity
= 1.0;
551 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
553 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
554 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
555 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
556 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
558 switch (mesaVis
->depthBits
) {
560 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
561 mmesa
->depth_clear_mask
= ~0;
562 mmesa
->ClearDepth
= 0xffff;
565 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
566 if (mmesa
->hw_stencil
) {
567 mmesa
->depth_clear_mask
= 0xffffff00;
568 mmesa
->stencil_clear_mask
= 0x000000ff;
570 mmesa
->depth_clear_mask
= ~0;
571 mmesa
->ClearDepth
= 0xffffff00;
574 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
575 mmesa
->depth_clear_mask
= ~0;
576 mmesa
->ClearDepth
= 0xffffffff;
580 mmesa
->haveHwStipple
= GL_FALSE
;
581 mmesa
->RenderIndex
= -1; /* impossible value */
583 mmesa
->vertex_format
= 0;
584 mmesa
->CurrentTexObj
[0] = 0;
585 mmesa
->CurrentTexObj
[1] = 0;
586 mmesa
->tmu_source
[0] = 0;
587 mmesa
->tmu_source
[1] = 1;
589 mmesa
->texAge
[0] = 0;
590 mmesa
->texAge
[1] = 0;
592 /* Initialize the software rasterizer and helper modules.
594 _swrast_CreateContext( ctx
);
595 _ac_CreateContext( ctx
);
596 _tnl_CreateContext( ctx
);
598 _swsetup_CreateContext( ctx
);
600 /* Install the customized pipeline:
602 _tnl_destroy_pipeline( ctx
);
603 _tnl_install_pipeline( ctx
, mga_pipeline
);
605 /* Configure swrast and T&L to match hardware characteristics:
607 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
608 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
609 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
610 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
612 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
614 ctx
->DriverCtx
= (void *) mmesa
;
617 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
619 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
620 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
623 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
624 driInitSingleExtension( ctx
, ARB_vp_extension
);
627 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
628 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
632 /* XXX these should really go right after _mesa_init_driver_functions() */
633 mgaDDInitStateFuncs( ctx
);
634 mgaDDInitSpanFuncs( ctx
);
635 mgaDDInitPixelFuncs( ctx
);
636 mgaDDInitTriFuncs( ctx
);
639 mgaInitState( mmesa
);
641 driContextPriv
->driverPrivate
= (void *) mmesa
;
644 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
648 mmesa
->vblank_flags
= (mmesa
->mgaScreen
->irq
== 0)
649 ? VBLANK_FLAG_NO_IRQ
: driGetDefaultVBlankFlags(&mmesa
->optionCache
);
651 (*dri_interface
->getUST
)( & mmesa
->swap_ust
);
653 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
654 fprintf(stderr
, "disabling 3D acceleration\n");
655 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
662 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
664 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
666 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
667 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
668 __FILE__
, __LINE__
);
670 assert(mmesa
); /* should never be null */
672 GLboolean release_texture_heaps
;
675 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
676 _swsetup_DestroyContext( mmesa
->glCtx
);
677 _tnl_DestroyContext( mmesa
->glCtx
);
678 _ac_DestroyContext( mmesa
->glCtx
);
679 _swrast_DestroyContext( mmesa
->glCtx
);
681 mgaFreeVB( mmesa
->glCtx
);
683 /* free the Mesa context */
684 mmesa
->glCtx
->DriverCtx
= NULL
;
685 _mesa_destroy_context(mmesa
->glCtx
);
687 if ( release_texture_heaps
) {
688 /* This share group is about to go away, free our private
689 * texture object data.
693 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
694 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
695 mmesa
->texture_heaps
[ i
] = NULL
;
698 assert( is_empty_list( & mmesa
->swapped
) );
701 /* free the option cache */
702 driDestroyOptionCache (&mmesa
->optionCache
);
707 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
708 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
709 __FILE__
, __LINE__
);
714 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
715 __DRIdrawablePrivate
*driDrawPriv
,
716 const __GLcontextModes
*mesaVis
,
719 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
722 return GL_FALSE
; /* not implemented */
725 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
726 mesaVis
->depthBits
!= 24);
729 driDrawPriv
->driverPrivate
= (void *)
730 _mesa_create_framebuffer(mesaVis
,
731 GL_FALSE
, /* software depth buffer? */
733 mesaVis
->accumRedBits
> 0,
734 mesaVis
->alphaBits
> 0 );
736 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
739 driRenderbuffer
*frontRb
740 = driNewRenderbuffer(GL_RGBA
,
743 screen
->frontOffset
, screen
->frontPitch
,
745 mgaSetSpanFunctions(frontRb
, mesaVis
);
746 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
749 if (mesaVis
->doubleBufferMode
) {
750 driRenderbuffer
*backRb
751 = driNewRenderbuffer(GL_RGBA
,
754 screen
->backOffset
, screen
->backPitch
,
756 mgaSetSpanFunctions(backRb
, mesaVis
);
757 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
760 if (mesaVis
->depthBits
== 16) {
761 driRenderbuffer
*depthRb
762 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
765 screen
->depthOffset
, screen
->depthPitch
,
767 mgaSetSpanFunctions(depthRb
, mesaVis
);
768 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
770 else if (mesaVis
->depthBits
== 24) {
771 /* XXX is this right? */
772 if (mesaVis
->stencilBits
) {
773 driRenderbuffer
*depthRb
774 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
777 screen
->depthOffset
, screen
->depthPitch
,
779 mgaSetSpanFunctions(depthRb
, mesaVis
);
780 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
783 driRenderbuffer
*depthRb
784 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
787 screen
->depthOffset
, screen
->depthPitch
,
789 mgaSetSpanFunctions(depthRb
, mesaVis
);
790 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
793 else if (mesaVis
->depthBits
== 32) {
794 driRenderbuffer
*depthRb
795 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
798 screen
->depthOffset
, screen
->depthPitch
,
800 mgaSetSpanFunctions(depthRb
, mesaVis
);
801 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
804 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
805 driRenderbuffer
*stencilRb
806 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
809 screen
->depthOffset
, screen
->depthPitch
,
811 mgaSetSpanFunctions(stencilRb
, mesaVis
);
812 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
815 _mesa_add_soft_renderbuffers(fb
,
816 GL_FALSE
, /* color */
817 GL_FALSE
, /* depth */
819 mesaVis
->accumRedBits
> 0,
820 GL_FALSE
, /* alpha */
822 driDrawPriv
->driverPrivate
= (void *) fb
;
825 return (driDrawPriv
->driverPrivate
!= NULL
);
831 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
833 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
837 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
839 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
842 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
845 if (ctx
->Visual
.doubleBufferMode
) {
846 _mesa_notifySwapBuffers( ctx
);
847 mgaCopyBuffer( dPriv
);
850 /* XXX this shouldn't be an error but we can't handle it for now */
851 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
856 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
858 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
865 /* This looks buggy to me - the 'b' variable isn't used anywhere...
866 * Hmm - It seems that the drawable is already hooked in to
869 * But why are we doing context initialization here???
872 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
873 __DRIdrawablePrivate
*driDrawPriv
,
874 __DRIdrawablePrivate
*driReadPriv
)
876 if (driContextPriv
) {
877 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
879 if (mmesa
->driDrawable
!= driDrawPriv
) {
880 driDrawableInitVBlank( driDrawPriv
, mmesa
->vblank_flags
);
881 mmesa
->driDrawable
= driDrawPriv
;
883 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
884 mmesa
->mesa_drawable
= driDrawPriv
;
887 mmesa
->driReadable
= driReadPriv
;
889 _mesa_make_current(mmesa
->glCtx
,
890 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
891 (GLframebuffer
*) driReadPriv
->driverPrivate
);
894 _mesa_make_current(NULL
, NULL
, NULL
);
901 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
903 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
904 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
905 int me
= mmesa
->hHWContext
;
908 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
910 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
911 mmesa
->lastStamp
= *(dPriv
->pStamp
);
912 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
913 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
914 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
915 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
918 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
920 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
922 if (sarea
->ctxOwner
!= me
) {
923 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
924 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
928 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
929 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
934 static const struct __DriverAPIRec mgaAPI
= {
935 .InitDriver
= mgaInitDriver
,
936 .DestroyScreen
= mgaDestroyScreen
,
937 .CreateContext
= mgaCreateContext
,
938 .DestroyContext
= mgaDestroyContext
,
939 .CreateBuffer
= mgaCreateBuffer
,
940 .DestroyBuffer
= mgaDestroyBuffer
,
941 .SwapBuffers
= mgaSwapBuffers
,
942 .MakeCurrent
= mgaMakeCurrent
,
943 .UnbindContext
= mgaUnbindContext
,
944 .GetSwapInfo
= getSwapInfo
,
945 .GetMSC
= driGetMSC32
,
946 .WaitForMSC
= driWaitForMSC32
,
948 .SwapBuffersMSC
= NULL
953 * This is the bootstrap function for the driver. libGL supplies all of the
954 * requisite information about the system, and the driver initializes itself.
955 * This routine also fills in the linked list pointed to by \c driver_modes
956 * with the \c __GLcontextModes that the driver can support for windows or
959 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
963 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
964 const __GLcontextModes
* modes
,
965 const __DRIversion
* ddx_version
,
966 const __DRIversion
* dri_version
,
967 const __DRIversion
* drm_version
,
968 const __DRIframebuffer
* frame_buffer
,
969 drmAddress pSAREA
, int fd
,
970 int internal_api_version
,
971 const __DRIinterfaceMethods
* interface
,
972 __GLcontextModes
** driver_modes
)
975 __DRIscreenPrivate
*psp
;
976 static const __DRIversion ddx_expected
= { 1, 2, 0 };
977 static const __DRIversion dri_expected
= { 4, 0, 0 };
978 static const __DRIversion drm_expected
= { 3, 0, 0 };
980 dri_interface
= interface
;
982 if ( ! driCheckDriDdxDrmVersions2( "MGA",
983 dri_version
, & dri_expected
,
984 ddx_version
, & ddx_expected
,
985 drm_version
, & drm_expected
) ) {
989 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
990 ddx_version
, dri_version
, drm_version
,
991 frame_buffer
, pSAREA
, fd
,
992 internal_api_version
, &mgaAPI
);
994 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
995 *driver_modes
= mgaFillInModes( dri_priv
->cpp
* 8,
996 (dri_priv
->cpp
== 2) ? 16 : 24,
997 (dri_priv
->cpp
== 2) ? 0 : 8,
998 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1000 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
1001 * enable the extensions. It just makes sure that all the dispatch offsets for all
1002 * the extensions that *might* be enables are known. This is needed because the
1003 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
1004 * enable the extensions until we have a context pointer.
1006 * Hello chicken. Hello egg. How are you two today?
1008 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
1009 driInitExtensions( NULL
, g400_extensions
, GL_FALSE
);
1010 driInitSingleExtension( NULL
, ARB_vp_extension
);
1011 driInitExtensions( NULL
, NV_vp_extensions
, GL_FALSE
);
1015 return (void *) psp
;
1020 * Get information about previous buffer swaps.
1023 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
1025 mgaContextPtr mmesa
;
1027 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
1028 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
1029 || (sInfo
== NULL
) ) {
1033 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
1034 sInfo
->swap_count
= mmesa
->swap_count
;
1035 sInfo
->swap_ust
= mmesa
->swap_ust
;
1036 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
1038 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
1039 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)