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 &driReadDrawableExtension
,
198 &driSwapControlExtension
.base
,
199 &driFrameTrackingExtension
.base
,
200 &driMediaStreamCounterExtension
.base
,
205 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
207 mgaScreenPrivate
*mgaScreen
;
208 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
210 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
211 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
215 /* Allocate the private area */
216 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
218 __driUtilMessage("Couldn't malloc screen struct");
222 mgaScreen
->sPriv
= sPriv
;
223 sPriv
->private = (void *)mgaScreen
;
225 if (sPriv
->drm_version
.minor
>= 1) {
227 drm_mga_getparam_t gp
;
229 gp
.param
= MGA_PARAM_IRQ_NR
;
230 gp
.value
= &mgaScreen
->irq
;
233 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
236 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
238 sPriv
->private = NULL
;
243 sPriv
->extensions
= mgaExtensions
;
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
->drm_version
.minor
< 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_vertex_program_stage
,
376 /* REMOVE: point attenuation stage */
378 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
379 /* Need new ioctl for wacceptseq */
386 static const struct dri_extension g400_extensions
[] =
388 { "GL_ARB_multitexture", NULL
},
389 { "GL_ARB_texture_env_add", NULL
},
390 { "GL_ARB_texture_env_combine", NULL
},
391 { "GL_ARB_texture_env_crossbar", NULL
},
392 { "GL_EXT_texture_env_combine", NULL
},
393 { "GL_EXT_texture_edge_clamp", NULL
},
394 { "GL_ATI_texture_env_combine3", NULL
},
398 static const struct dri_extension card_extensions
[] =
400 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
401 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
402 { "GL_ARB_texture_rectangle", NULL
},
403 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
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 */
546 ctx
->Const
.MinLineWidth
= 1.0;
547 ctx
->Const
.MinLineWidthAA
= 1.0;
548 ctx
->Const
.MaxLineWidth
= 10.0;
549 ctx
->Const
.MaxLineWidthAA
= 10.0;
550 ctx
->Const
.LineWidthGranularity
= 1.0;
552 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
554 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
555 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
556 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
557 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
559 switch (mesaVis
->depthBits
) {
561 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
562 mmesa
->depth_clear_mask
= ~0;
563 mmesa
->ClearDepth
= 0xffff;
566 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
567 if (mmesa
->hw_stencil
) {
568 mmesa
->depth_clear_mask
= 0xffffff00;
569 mmesa
->stencil_clear_mask
= 0x000000ff;
571 mmesa
->depth_clear_mask
= ~0;
572 mmesa
->ClearDepth
= 0xffffff00;
575 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
576 mmesa
->depth_clear_mask
= ~0;
577 mmesa
->ClearDepth
= 0xffffffff;
581 mmesa
->haveHwStipple
= GL_FALSE
;
582 mmesa
->RenderIndex
= -1; /* impossible value */
584 mmesa
->vertex_format
= 0;
585 mmesa
->CurrentTexObj
[0] = 0;
586 mmesa
->CurrentTexObj
[1] = 0;
587 mmesa
->tmu_source
[0] = 0;
588 mmesa
->tmu_source
[1] = 1;
590 mmesa
->texAge
[0] = 0;
591 mmesa
->texAge
[1] = 0;
593 /* Initialize the software rasterizer and helper modules.
595 _swrast_CreateContext( ctx
);
596 _vbo_CreateContext( ctx
);
597 _tnl_CreateContext( ctx
);
599 _swsetup_CreateContext( ctx
);
601 /* Install the customized pipeline:
603 _tnl_destroy_pipeline( ctx
);
604 _tnl_install_pipeline( ctx
, mga_pipeline
);
606 /* Configure swrast and T&L to match hardware characteristics:
608 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
609 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
610 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
611 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
613 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
615 ctx
->DriverCtx
= (void *) mmesa
;
618 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
620 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
621 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
624 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
625 driInitSingleExtension( ctx
, ARB_vp_extension
);
628 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
629 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
633 /* XXX these should really go right after _mesa_init_driver_functions() */
634 mgaDDInitStateFuncs( ctx
);
635 mgaDDInitSpanFuncs( ctx
);
636 mgaDDInitPixelFuncs( ctx
);
637 mgaDDInitTriFuncs( ctx
);
640 mgaInitState( mmesa
);
642 driContextPriv
->driverPrivate
= (void *) mmesa
;
645 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
649 mmesa
->vblank_flags
= (mmesa
->mgaScreen
->irq
== 0)
650 ? VBLANK_FLAG_NO_IRQ
: driGetDefaultVBlankFlags(&mmesa
->optionCache
);
652 (*dri_interface
->getUST
)( & mmesa
->swap_ust
);
654 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
655 fprintf(stderr
, "disabling 3D acceleration\n");
656 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
663 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
665 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
667 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
668 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
669 __FILE__
, __LINE__
);
671 assert(mmesa
); /* should never be null */
673 GLboolean release_texture_heaps
;
676 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
677 _swsetup_DestroyContext( mmesa
->glCtx
);
678 _tnl_DestroyContext( mmesa
->glCtx
);
679 _vbo_DestroyContext( mmesa
->glCtx
);
680 _swrast_DestroyContext( mmesa
->glCtx
);
682 mgaFreeVB( mmesa
->glCtx
);
684 /* free the Mesa context */
685 mmesa
->glCtx
->DriverCtx
= NULL
;
686 _mesa_destroy_context(mmesa
->glCtx
);
688 if ( release_texture_heaps
) {
689 /* This share group is about to go away, free our private
690 * texture object data.
694 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
695 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
696 mmesa
->texture_heaps
[ i
] = NULL
;
699 assert( is_empty_list( & mmesa
->swapped
) );
702 /* free the option cache */
703 driDestroyOptionCache (&mmesa
->optionCache
);
708 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
709 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
710 __FILE__
, __LINE__
);
715 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
716 __DRIdrawablePrivate
*driDrawPriv
,
717 const __GLcontextModes
*mesaVis
,
720 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
723 return GL_FALSE
; /* not implemented */
726 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
727 mesaVis
->depthBits
!= 24);
730 driDrawPriv
->driverPrivate
= (void *)
731 _mesa_create_framebuffer(mesaVis
,
732 GL_FALSE
, /* software depth buffer? */
734 mesaVis
->accumRedBits
> 0,
735 mesaVis
->alphaBits
> 0 );
737 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
740 driRenderbuffer
*frontRb
741 = driNewRenderbuffer(GL_RGBA
,
744 screen
->frontOffset
, screen
->frontPitch
,
746 mgaSetSpanFunctions(frontRb
, mesaVis
);
747 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
750 if (mesaVis
->doubleBufferMode
) {
751 driRenderbuffer
*backRb
752 = driNewRenderbuffer(GL_RGBA
,
755 screen
->backOffset
, screen
->backPitch
,
757 mgaSetSpanFunctions(backRb
, mesaVis
);
758 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
761 if (mesaVis
->depthBits
== 16) {
762 driRenderbuffer
*depthRb
763 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
766 screen
->depthOffset
, screen
->depthPitch
,
768 mgaSetSpanFunctions(depthRb
, mesaVis
);
769 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
771 else if (mesaVis
->depthBits
== 24) {
772 /* XXX is this right? */
773 if (mesaVis
->stencilBits
) {
774 driRenderbuffer
*depthRb
775 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
778 screen
->depthOffset
, screen
->depthPitch
,
780 mgaSetSpanFunctions(depthRb
, mesaVis
);
781 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
784 driRenderbuffer
*depthRb
785 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
788 screen
->depthOffset
, screen
->depthPitch
,
790 mgaSetSpanFunctions(depthRb
, mesaVis
);
791 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
794 else if (mesaVis
->depthBits
== 32) {
795 driRenderbuffer
*depthRb
796 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
799 screen
->depthOffset
, screen
->depthPitch
,
801 mgaSetSpanFunctions(depthRb
, mesaVis
);
802 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
805 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
806 driRenderbuffer
*stencilRb
807 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
810 screen
->depthOffset
, screen
->depthPitch
,
812 mgaSetSpanFunctions(stencilRb
, mesaVis
);
813 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
816 _mesa_add_soft_renderbuffers(fb
,
817 GL_FALSE
, /* color */
818 GL_FALSE
, /* depth */
820 mesaVis
->accumRedBits
> 0,
821 GL_FALSE
, /* alpha */
823 driDrawPriv
->driverPrivate
= (void *) fb
;
826 return (driDrawPriv
->driverPrivate
!= NULL
);
832 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
834 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
838 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
840 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
843 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
846 if (ctx
->Visual
.doubleBufferMode
) {
847 _mesa_notifySwapBuffers( ctx
);
848 mgaCopyBuffer( dPriv
);
851 /* XXX this shouldn't be an error but we can't handle it for now */
852 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
857 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
859 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
866 /* This looks buggy to me - the 'b' variable isn't used anywhere...
867 * Hmm - It seems that the drawable is already hooked in to
870 * But why are we doing context initialization here???
873 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
874 __DRIdrawablePrivate
*driDrawPriv
,
875 __DRIdrawablePrivate
*driReadPriv
)
877 if (driContextPriv
) {
878 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
880 if (mmesa
->driDrawable
!= driDrawPriv
) {
881 driDrawableInitVBlank( driDrawPriv
, mmesa
->vblank_flags
,
883 mmesa
->driDrawable
= driDrawPriv
;
885 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
888 mmesa
->driReadable
= driReadPriv
;
890 _mesa_make_current(mmesa
->glCtx
,
891 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
892 (GLframebuffer
*) driReadPriv
->driverPrivate
);
895 _mesa_make_current(NULL
, NULL
, NULL
);
902 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
904 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
905 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
906 int me
= mmesa
->hHWContext
;
909 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
911 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
912 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
913 mmesa
->lastStamp
= *(dPriv
->pStamp
);
914 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
915 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
916 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
917 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
920 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
922 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
924 if (sarea
->ctxOwner
!= me
) {
925 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
926 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
930 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
931 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
936 static const struct __DriverAPIRec mgaAPI
= {
937 .DestroyScreen
= mgaDestroyScreen
,
938 .CreateContext
= mgaCreateContext
,
939 .DestroyContext
= mgaDestroyContext
,
940 .CreateBuffer
= mgaCreateBuffer
,
941 .DestroyBuffer
= mgaDestroyBuffer
,
942 .SwapBuffers
= mgaSwapBuffers
,
943 .MakeCurrent
= mgaMakeCurrent
,
944 .UnbindContext
= mgaUnbindContext
,
945 .GetSwapInfo
= getSwapInfo
,
946 .GetMSC
= driGetMSC32
,
947 .WaitForMSC
= driWaitForMSC32
,
949 .SwapBuffersMSC
= NULL
954 * This is the driver specific part of the createNewScreen entry point.
956 * \todo maybe fold this into intelInitDriver
958 * \return the __GLcontextModes supported by this driver
960 __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
)
962 static const __DRIversion ddx_expected
= { 1, 2, 0 };
963 static const __DRIversion dri_expected
= { 4, 0, 0 };
964 static const __DRIversion drm_expected
= { 3, 0, 0 };
965 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
967 psp
->DriverAPI
= mgaAPI
;
968 if ( ! driCheckDriDdxDrmVersions2( "MGA",
969 &psp
->dri_version
, & dri_expected
,
970 &psp
->ddx_version
, & ddx_expected
,
971 &psp
->drm_version
, & drm_expected
) )
975 /* Calling driInitExtensions here, with a NULL context pointer,
976 * does not actually enable the extensions. It just makes sure
977 * that all the dispatch offsets for all the extensions that
978 * *might* be enables are known. This is needed because the
979 * dispatch offsets need to be known when _mesa_context_create is
980 * called, but we can't enable the extensions until we have a
983 * Hello chicken. Hello egg. How are you two today?
986 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
987 driInitExtensions( NULL
, g400_extensions
, GL_FALSE
);
988 driInitSingleExtension( NULL
, ARB_vp_extension
);
989 driInitExtensions( NULL
, NV_vp_extensions
, GL_FALSE
);
991 if (!mgaInitDriver(psp
))
994 return mgaFillInModes( dri_priv
->cpp
* 8,
995 (dri_priv
->cpp
== 2) ? 16 : 24,
996 (dri_priv
->cpp
== 2) ? 0 : 8,
997 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1002 * Get information about previous buffer swaps.
1005 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
1007 mgaContextPtr mmesa
;
1009 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
1010 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
1011 || (sInfo
== NULL
) ) {
1015 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
1016 sInfo
->swap_count
= mmesa
->swap_count
;
1017 sInfo
->swap_ust
= mmesa
->swap_ust
;
1018 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
1020 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
1021 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)