2 * Copyright 2000-2001 VA Linux Systems, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 * MGA screen and context initialization / creation code.
29 * \author Keith Whitwell <keith@tungstengraphics.com>
36 #include "mga_xmesa.h"
37 #include "main/context.h"
38 #include "main/matrix.h"
39 #include "main/simple_list.h"
40 #include "main/imports.h"
41 #include "main/framebuffer.h"
42 #include "main/renderbuffer.h"
44 #include "swrast/swrast.h"
45 #include "swrast_setup/swrast_setup.h"
49 #include "tnl/t_pipeline.h"
51 #include "drivers/common/driverfuncs.h"
61 #include "mga_xmesa.h"
67 #include "main/extensions.h"
68 #include "drirenderbuffer.h"
70 #include "GL/internal/dri_interface.h"
72 #define need_GL_ARB_multisample
73 #define need_GL_ARB_texture_compression
74 #define need_GL_ARB_vertex_buffer_object
75 #define need_GL_ARB_vertex_program
76 #define need_GL_EXT_fog_coord
77 #define need_GL_EXT_gpu_program_parameters
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_APPLE_vertex_array_object
84 #define need_GL_NV_vertex_program
85 #include "extension_helper.h"
91 PUBLIC
const char __driConfigOptions
[] =
93 DRI_CONF_SECTION_PERFORMANCE
94 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
96 DRI_CONF_SECTION_QUALITY
97 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
98 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
100 DRI_CONF_SECTION_SOFTWARE
101 DRI_CONF_ARB_VERTEX_PROGRAM(true)
102 DRI_CONF_NV_VERTEX_PROGRAM(true)
104 DRI_CONF_SECTION_DEBUG
105 DRI_CONF_NO_RAST(false)
108 static const GLuint __driNConfigOptions
= 6;
114 static const __DRIconfig
**
115 mgaFillInModes( __DRIscreenPrivate
*psp
,
116 unsigned pixel_bits
, unsigned depth_bits
,
117 unsigned stencil_bits
, GLboolean have_back_buffer
)
119 __DRIconfig
**configs
;
120 __GLcontextModes
* m
;
121 unsigned depth_buffer_factor
;
122 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 uint8_t depth_bits_array
[3];
135 uint8_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 if ( pixel_bits
== 16 ) {
155 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
159 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
162 configs
= driCreateConfigs(fb_format
, fb_type
,
163 depth_bits_array
, stencil_bits_array
,
165 back_buffer_modes
, back_buffer_factor
);
166 if (configs
== NULL
) {
167 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
168 __func__
, __LINE__
);
172 /* Mark the visual as slow if there are "fake" stencil bits.
174 for (i
= 0; configs
[i
]; i
++) {
175 m
= &configs
[i
]->modes
;
176 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
177 m
->visualRating
= GLX_SLOW_CONFIG
;
181 return (const __DRIconfig
**) configs
;
184 const __DRIextension
*mgaScreenExtensions
[] = {
185 &driReadDrawableExtension
,
186 &driSwapControlExtension
.base
,
187 &driFrameTrackingExtension
.base
,
188 &driMediaStreamCounterExtension
.base
,
193 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
195 mgaScreenPrivate
*mgaScreen
;
196 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
198 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
199 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
203 /* Allocate the private area */
204 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
206 __driUtilMessage("Couldn't malloc screen struct");
210 mgaScreen
->sPriv
= sPriv
;
211 sPriv
->private = (void *)mgaScreen
;
213 if (sPriv
->drm_version
.minor
>= 1) {
215 drm_mga_getparam_t gp
;
217 gp
.param
= MGA_PARAM_IRQ_NR
;
218 gp
.value
= &mgaScreen
->irq
;
221 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
224 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
226 sPriv
->private = NULL
;
231 sPriv
->extensions
= mgaScreenExtensions
;
233 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
234 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
236 sPriv
->private = NULL
;
237 __driUtilMessage("Unrecognized chipset");
242 mgaScreen
->chipset
= serverInfo
->chipset
;
243 mgaScreen
->cpp
= serverInfo
->cpp
;
245 mgaScreen
->agpMode
= serverInfo
->agpMode
;
247 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
248 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
249 mgaScreen
->backOffset
= serverInfo
->backOffset
;
250 mgaScreen
->backPitch
= serverInfo
->backPitch
;
251 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
252 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
255 /* The only reason that the MMIO region needs to be accessable and the
256 * primary DMA region base address needs to be known is so that the driver
257 * can busy wait for certain DMA operations to complete (see
258 * mgaWaitForFrameCompletion in mgaioctl.c).
260 * Starting with MGA DRM version 3.2, these are completely unneeded as
261 * there is a new, in-kernel mechanism for handling the wait.
264 if (mgaScreen
->sPriv
->drm_version
.minor
< 2) {
265 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
266 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
267 if ( drmMap( sPriv
->fd
,
268 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
269 &mgaScreen
->mmio
.map
) < 0 ) {
271 sPriv
->private = NULL
;
272 __driUtilMessage( "Couldn't map MMIO registers" );
276 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
277 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
280 (void) memset( & mgaScreen
->primary
, 0, sizeof( mgaScreen
->primary
) );
281 (void) memset( & mgaScreen
->mmio
, 0, sizeof( mgaScreen
->mmio
) );
284 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
285 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
286 PDEA_pagpxfer_enable
| 1);
288 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
289 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
292 /* The texVirtual array stores the base addresses in the CPU's address
293 * space of the texture memory pools. The base address of the on-card
294 * memory pool is calculated as an offset of the base of video memory. The
295 * AGP texture pool has to be mapped into the processes address space by
299 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
300 serverInfo
->textureOffset
);
302 if ( serverInfo
->agpTextureSize
> 0 ) {
303 if (drmMap(sPriv
->fd
, serverInfo
->agpTextureOffset
,
304 serverInfo
->agpTextureSize
,
305 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0) {
307 sPriv
->private = NULL
;
308 __driUtilMessage("Couldn't map agptexture region");
314 /* For calculating setupdma addresses.
317 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
318 if (!mgaScreen
->bufs
) {
320 sPriv
->private = NULL
;
321 __driUtilMessage("Couldn't map dma buffers");
324 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
326 /* parse information in __driConfigOptions */
327 driParseOptionInfo (&mgaScreen
->optionCache
,
328 __driConfigOptions
, __driNConfigOptions
);
335 mgaDestroyScreen(__DRIscreenPrivate
*sPriv
)
337 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
339 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
340 fprintf(stderr
, "mgaDestroyScreen\n");
342 drmUnmapBufs(mgaScreen
->bufs
);
345 /* free all option information */
346 driDestroyOptionInfo (&mgaScreen
->optionCache
);
349 sPriv
->private = NULL
;
353 extern const struct tnl_pipeline_stage _mga_render_stage
;
355 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
356 &_tnl_vertex_transform_stage
,
357 &_tnl_normal_transform_stage
,
358 &_tnl_lighting_stage
,
359 &_tnl_fog_coordinate_stage
,
361 &_tnl_texture_transform_stage
,
362 &_tnl_vertex_program_stage
,
364 /* REMOVE: point attenuation stage */
366 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
367 /* Need new ioctl for wacceptseq */
374 static const struct dri_extension g400_extensions
[] =
376 { "GL_ARB_multitexture", NULL
},
377 { "GL_ARB_texture_env_add", NULL
},
378 { "GL_ARB_texture_env_combine", NULL
},
379 { "GL_ARB_texture_env_crossbar", NULL
},
380 { "GL_EXT_texture_env_combine", NULL
},
381 { "GL_EXT_texture_edge_clamp", NULL
},
382 { "GL_ATI_texture_env_combine3", NULL
},
386 static const struct dri_extension card_extensions
[] =
388 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
389 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
390 { "GL_ARB_texture_rectangle", NULL
},
391 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
392 { "GL_EXT_blend_logic_op", NULL
},
393 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
394 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
395 /* paletted_textures currently doesn't work, but we could fix them later */
396 #if defined( need_GL_EXT_paletted_texture )
397 { "GL_EXT_shared_texture_palette", NULL
},
398 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
400 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
401 { "GL_EXT_stencil_wrap", NULL
},
402 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions
},
403 { "GL_MESA_ycbcr_texture", NULL
},
404 { "GL_SGIS_generate_mipmap", NULL
},
408 static const struct dri_extension ARB_vp_extensions
[] = {
409 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
410 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
414 static const struct dri_extension NV_vp_extensions
[] = {
415 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
416 { "GL_NV_vertex_program1_1", NULL
},
420 static const struct dri_debug_control debug_control
[] =
422 { "fall", DEBUG_VERBOSE_FALLBACK
},
423 { "tex", DEBUG_VERBOSE_TEXTURE
},
424 { "ioctl", DEBUG_VERBOSE_IOCTL
},
425 { "verb", DEBUG_VERBOSE_MSG
},
426 { "dri", DEBUG_VERBOSE_DRI
},
432 mgaCreateContext( const __GLcontextModes
*mesaVis
,
433 __DRIcontextPrivate
*driContextPriv
,
434 void *sharedContextPrivate
)
438 GLcontext
*ctx
, *shareCtx
;
440 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
441 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
442 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
443 mgaScreen
->sarea_priv_offset
);
444 struct dd_function_table functions
;
446 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
447 fprintf(stderr
, "mgaCreateContext\n");
449 /* allocate mga context */
450 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
455 /* Init default driver functions then plug in our Radeon-specific functions
456 * (the texture functions are especially important)
458 _mesa_init_driver_functions( &functions
);
459 mgaInitDriverFuncs( &functions
);
460 mgaInitTextureFuncs( &functions
);
461 mgaInitIoctlFuncs( &functions
);
463 /* Allocate the Mesa context */
464 if (sharedContextPrivate
)
465 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
468 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
469 &functions
, (void *) mmesa
);
474 driContextPriv
->driverPrivate
= mmesa
;
477 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
478 mmesa
->driFd
= sPriv
->fd
;
479 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
481 mmesa
->mgaScreen
= mgaScreen
;
482 mmesa
->driScreen
= sPriv
;
483 mmesa
->sarea
= (void *)saPriv
;
485 /* Parse configuration files */
486 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
487 sPriv
->myNum
, "mga");
489 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
490 make_empty_list( & mmesa
->swapped
);
492 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
493 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
494 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
495 mgaScreen
->textureSize
[i
],
498 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
499 &mmesa
->sarea
->texAge
[i
],
501 sizeof( mgaTextureObject_t
),
502 (destroy_texture_object_t
*) mgaDestroyTexObj
);
505 /* Set the maximum texture size small enough that we can guarentee
506 * that both texture units can bind a maximal texture and have them
507 * on the card at once.
510 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
511 ctx
->Const
.MaxTextureUnits
= 1;
512 ctx
->Const
.MaxTextureImageUnits
= 1;
513 ctx
->Const
.MaxTextureCoordUnits
= 1;
514 maxlevels
= G200_TEX_MAXLEVELS
;
518 ctx
->Const
.MaxTextureUnits
= 2;
519 ctx
->Const
.MaxTextureImageUnits
= 2;
520 ctx
->Const
.MaxTextureCoordUnits
= 2;
521 maxlevels
= G400_TEX_MAXLEVELS
;
524 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
528 11, /* max 2D texture size is 2048x2048 */
529 0, /* 3D textures unsupported. */
530 0, /* cube textures unsupported. */
531 11, /* max texture rect size is 2048x2048 */
536 ctx
->Const
.MinLineWidth
= 1.0;
537 ctx
->Const
.MinLineWidthAA
= 1.0;
538 ctx
->Const
.MaxLineWidth
= 10.0;
539 ctx
->Const
.MaxLineWidthAA
= 10.0;
540 ctx
->Const
.LineWidthGranularity
= 1.0;
542 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
544 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
545 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
546 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
547 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
549 switch (mesaVis
->depthBits
) {
551 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
552 mmesa
->depth_clear_mask
= ~0;
553 mmesa
->ClearDepth
= 0xffff;
556 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
557 if (mmesa
->hw_stencil
) {
558 mmesa
->depth_clear_mask
= 0xffffff00;
559 mmesa
->stencil_clear_mask
= 0x000000ff;
561 mmesa
->depth_clear_mask
= ~0;
562 mmesa
->ClearDepth
= 0xffffff00;
565 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
566 mmesa
->depth_clear_mask
= ~0;
567 mmesa
->ClearDepth
= 0xffffffff;
571 mmesa
->haveHwStipple
= GL_FALSE
;
572 mmesa
->RenderIndex
= -1; /* impossible value */
574 mmesa
->vertex_format
= 0;
575 mmesa
->CurrentTexObj
[0] = 0;
576 mmesa
->CurrentTexObj
[1] = 0;
577 mmesa
->tmu_source
[0] = 0;
578 mmesa
->tmu_source
[1] = 1;
580 mmesa
->texAge
[0] = 0;
581 mmesa
->texAge
[1] = 0;
583 /* Initialize the software rasterizer and helper modules.
585 _swrast_CreateContext( ctx
);
586 _vbo_CreateContext( ctx
);
587 _tnl_CreateContext( ctx
);
589 _swsetup_CreateContext( ctx
);
591 /* Install the customized pipeline:
593 _tnl_destroy_pipeline( ctx
);
594 _tnl_install_pipeline( ctx
, mga_pipeline
);
596 /* Configure swrast and T&L to match hardware characteristics:
598 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
599 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
600 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
601 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
603 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
605 ctx
->DriverCtx
= (void *) mmesa
;
608 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
610 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
611 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
614 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
615 driInitExtensions(ctx
, ARB_vp_extensions
, GL_FALSE
);
618 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
619 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
623 /* XXX these should really go right after _mesa_init_driver_functions() */
624 mgaDDInitStateFuncs( ctx
);
625 mgaDDInitSpanFuncs( ctx
);
626 mgaDDInitPixelFuncs( ctx
);
627 mgaDDInitTriFuncs( ctx
);
630 mgaInitState( mmesa
);
632 driContextPriv
->driverPrivate
= (void *) mmesa
;
635 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
639 (*sPriv
->systemTime
->getUST
)( & mmesa
->swap_ust
);
641 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
642 fprintf(stderr
, "disabling 3D acceleration\n");
643 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
650 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
652 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
654 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
655 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
656 __FILE__
, __LINE__
);
658 assert(mmesa
); /* should never be null */
660 GLboolean release_texture_heaps
;
663 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
664 _swsetup_DestroyContext( mmesa
->glCtx
);
665 _tnl_DestroyContext( mmesa
->glCtx
);
666 _vbo_DestroyContext( mmesa
->glCtx
);
667 _swrast_DestroyContext( mmesa
->glCtx
);
669 mgaFreeVB( mmesa
->glCtx
);
671 /* free the Mesa context */
672 mmesa
->glCtx
->DriverCtx
= NULL
;
673 _mesa_destroy_context(mmesa
->glCtx
);
675 if ( release_texture_heaps
) {
676 /* This share group is about to go away, free our private
677 * texture object data.
681 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
682 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
683 mmesa
->texture_heaps
[ i
] = NULL
;
686 assert( is_empty_list( & mmesa
->swapped
) );
689 /* free the option cache */
690 driDestroyOptionCache (&mmesa
->optionCache
);
695 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
696 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
697 __FILE__
, __LINE__
);
702 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
703 __DRIdrawablePrivate
*driDrawPriv
,
704 const __GLcontextModes
*mesaVis
,
707 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
710 return GL_FALSE
; /* not implemented */
713 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
714 mesaVis
->depthBits
!= 24);
717 driDrawPriv
->driverPrivate
= (void *)
718 _mesa_create_framebuffer(mesaVis
,
719 GL_FALSE
, /* software depth buffer? */
721 mesaVis
->accumRedBits
> 0,
722 mesaVis
->alphaBits
> 0 );
724 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
727 driRenderbuffer
*frontRb
728 = driNewRenderbuffer(GL_RGBA
,
731 screen
->frontOffset
, screen
->frontPitch
,
733 mgaSetSpanFunctions(frontRb
, mesaVis
);
734 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
737 if (mesaVis
->doubleBufferMode
) {
738 driRenderbuffer
*backRb
739 = driNewRenderbuffer(GL_RGBA
,
742 screen
->backOffset
, screen
->backPitch
,
744 mgaSetSpanFunctions(backRb
, mesaVis
);
745 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
748 if (mesaVis
->depthBits
== 16) {
749 driRenderbuffer
*depthRb
750 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
753 screen
->depthOffset
, screen
->depthPitch
,
755 mgaSetSpanFunctions(depthRb
, mesaVis
);
756 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
758 else if (mesaVis
->depthBits
== 24) {
759 /* XXX is this right? */
760 if (mesaVis
->stencilBits
) {
761 driRenderbuffer
*depthRb
762 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
765 screen
->depthOffset
, screen
->depthPitch
,
767 mgaSetSpanFunctions(depthRb
, mesaVis
);
768 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
771 driRenderbuffer
*depthRb
772 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
775 screen
->depthOffset
, screen
->depthPitch
,
777 mgaSetSpanFunctions(depthRb
, mesaVis
);
778 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
781 else if (mesaVis
->depthBits
== 32) {
782 driRenderbuffer
*depthRb
783 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
786 screen
->depthOffset
, screen
->depthPitch
,
788 mgaSetSpanFunctions(depthRb
, mesaVis
);
789 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
792 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
793 driRenderbuffer
*stencilRb
794 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
797 screen
->depthOffset
, screen
->depthPitch
,
799 mgaSetSpanFunctions(stencilRb
, mesaVis
);
800 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
803 _mesa_add_soft_renderbuffers(fb
,
804 GL_FALSE
, /* color */
805 GL_FALSE
, /* depth */
807 mesaVis
->accumRedBits
> 0,
808 GL_FALSE
, /* alpha */
810 driDrawPriv
->driverPrivate
= (void *) fb
;
813 return (driDrawPriv
->driverPrivate
!= NULL
);
819 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
821 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
825 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
827 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
830 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
833 if (ctx
->Visual
.doubleBufferMode
) {
834 _mesa_notifySwapBuffers( ctx
);
835 mgaCopyBuffer( dPriv
);
838 /* XXX this shouldn't be an error but we can't handle it for now */
839 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
844 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
846 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
853 /* This looks buggy to me - the 'b' variable isn't used anywhere...
854 * Hmm - It seems that the drawable is already hooked in to
857 * But why are we doing context initialization here???
860 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
861 __DRIdrawablePrivate
*driDrawPriv
,
862 __DRIdrawablePrivate
*driReadPriv
)
864 if (driContextPriv
) {
865 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
867 if (mmesa
->driDrawable
!= driDrawPriv
) {
868 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
869 driDrawPriv
->vblFlags
= (mmesa
->mgaScreen
->irq
== 0)
871 : driGetDefaultVBlankFlags(&mmesa
->optionCache
);
873 driDrawableInitVBlank( driDrawPriv
);
876 mmesa
->driDrawable
= driDrawPriv
;
878 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
881 mmesa
->driReadable
= driReadPriv
;
883 _mesa_make_current(mmesa
->glCtx
,
884 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
885 (GLframebuffer
*) driReadPriv
->driverPrivate
);
888 _mesa_make_current(NULL
, NULL
, NULL
);
895 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
897 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
898 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
899 int me
= mmesa
->hHWContext
;
902 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
904 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
905 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
906 mmesa
->lastStamp
= *(dPriv
->pStamp
);
907 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
908 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
909 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
910 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
913 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
915 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
917 if (sarea
->ctxOwner
!= me
) {
918 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
919 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
923 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
924 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
930 * This is the driver specific part of the createNewScreen entry point.
932 * \todo maybe fold this into intelInitDriver
934 * \return the __GLcontextModes supported by this driver
936 static const __DRIconfig
**mgaInitScreen(__DRIscreen
*psp
)
938 static const __DRIversion ddx_expected
= { 1, 2, 0 };
939 static const __DRIversion dri_expected
= { 4, 0, 0 };
940 static const __DRIversion drm_expected
= { 3, 0, 0 };
941 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
943 if ( ! driCheckDriDdxDrmVersions2( "MGA",
944 &psp
->dri_version
, & dri_expected
,
945 &psp
->ddx_version
, & ddx_expected
,
946 &psp
->drm_version
, & drm_expected
) )
950 /* Calling driInitExtensions here, with a NULL context pointer,
951 * does not actually enable the extensions. It just makes sure
952 * that all the dispatch offsets for all the extensions that
953 * *might* be enables are known. This is needed because the
954 * dispatch offsets need to be known when _mesa_context_create is
955 * called, but we can't enable the extensions until we have a
958 * Hello chicken. Hello egg. How are you two today?
961 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
962 driInitExtensions( NULL
, g400_extensions
, GL_FALSE
);
963 driInitExtensions(NULL
, ARB_vp_extensions
, GL_FALSE
);
964 driInitExtensions( NULL
, NV_vp_extensions
, GL_FALSE
);
966 if (!mgaInitDriver(psp
))
969 return mgaFillInModes( psp
,
971 (dri_priv
->cpp
== 2) ? 16 : 24,
972 (dri_priv
->cpp
== 2) ? 0 : 8,
973 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
978 * Get information about previous buffer swaps.
981 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
985 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
986 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
987 || (sInfo
== NULL
) ) {
991 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
992 sInfo
->swap_count
= mmesa
->swap_count
;
993 sInfo
->swap_ust
= mmesa
->swap_ust
;
994 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
996 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
997 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)
1003 const struct __DriverAPIRec driDriverAPI
= {
1004 .InitScreen
= mgaInitScreen
,
1005 .DestroyScreen
= mgaDestroyScreen
,
1006 .CreateContext
= mgaCreateContext
,
1007 .DestroyContext
= mgaDestroyContext
,
1008 .CreateBuffer
= mgaCreateBuffer
,
1009 .DestroyBuffer
= mgaDestroyBuffer
,
1010 .SwapBuffers
= mgaSwapBuffers
,
1011 .MakeCurrent
= mgaMakeCurrent
,
1012 .UnbindContext
= mgaUnbindContext
,
1013 .GetSwapInfo
= getSwapInfo
,
1014 .GetDrawableMSC
= driDrawableGetMSC32
,
1015 .WaitForMSC
= driWaitForMSC32
,
1017 .SwapBuffersMSC
= NULL