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_vertex_program
73 #define need_GL_EXT_fog_coord
74 #define need_GL_EXT_gpu_program_parameters
75 #define need_GL_EXT_secondary_color
77 #define need_GL_EXT_paletted_texture
79 #define need_GL_APPLE_vertex_array_object
80 #define need_GL_NV_vertex_program
81 #include "main/remap_helper.h"
87 PUBLIC
const char __driConfigOptions
[] =
89 DRI_CONF_SECTION_PERFORMANCE
90 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
92 DRI_CONF_SECTION_QUALITY
93 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
94 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
96 DRI_CONF_SECTION_SOFTWARE
97 DRI_CONF_ARB_VERTEX_PROGRAM(true)
98 DRI_CONF_NV_VERTEX_PROGRAM(true)
100 DRI_CONF_SECTION_DEBUG
101 DRI_CONF_NO_RAST(false)
104 static const GLuint __driNConfigOptions
= 6;
110 static const __DRIconfig
**
111 mgaFillInModes( __DRIscreenPrivate
*psp
,
112 unsigned pixel_bits
, unsigned depth_bits
,
113 unsigned stencil_bits
, GLboolean have_back_buffer
)
115 __DRIconfig
**configs
;
116 __GLcontextModes
* m
;
117 unsigned depth_buffer_factor
;
118 unsigned back_buffer_factor
;
123 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
124 * support pageflipping at all.
126 static const GLenum back_buffer_modes
[] = {
127 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
130 uint8_t depth_bits_array
[3];
131 uint8_t stencil_bits_array
[3];
132 uint8_t msaa_samples_array
[1];
135 depth_bits_array
[0] = 0;
136 depth_bits_array
[1] = depth_bits
;
137 depth_bits_array
[2] = depth_bits
;
139 /* Just like with the accumulation buffer, always provide some modes
140 * with a stencil buffer. It will be a sw fallback, but some apps won't
143 stencil_bits_array
[0] = 0;
144 stencil_bits_array
[1] = 0;
145 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
147 msaa_samples_array
[0] = 0;
149 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
150 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
152 if ( pixel_bits
== 16 ) {
154 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
158 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
161 configs
= driCreateConfigs(fb_format
, fb_type
,
162 depth_bits_array
, stencil_bits_array
,
164 back_buffer_modes
, back_buffer_factor
,
165 msaa_samples_array
, 1);
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_texture_rectangle", NULL
},
389 { "GL_EXT_blend_logic_op", NULL
},
390 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
391 /* paletted_textures currently doesn't work, but we could fix them later */
392 #if defined( need_GL_EXT_paletted_texture )
393 { "GL_EXT_shared_texture_palette", NULL
},
394 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
396 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
397 { "GL_EXT_stencil_wrap", NULL
},
398 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions
},
399 { "GL_MESA_ycbcr_texture", NULL
},
400 { "GL_SGIS_generate_mipmap", NULL
},
404 static const struct dri_extension ARB_vp_extensions
[] = {
405 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
406 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
410 static const struct dri_extension NV_vp_extensions
[] = {
411 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
412 { "GL_NV_vertex_program1_1", NULL
},
416 static const struct dri_debug_control debug_control
[] =
418 { "fall", DEBUG_VERBOSE_FALLBACK
},
419 { "tex", DEBUG_VERBOSE_TEXTURE
},
420 { "ioctl", DEBUG_VERBOSE_IOCTL
},
421 { "verb", DEBUG_VERBOSE_MSG
},
422 { "dri", DEBUG_VERBOSE_DRI
},
428 mgaCreateContext( const __GLcontextModes
*mesaVis
,
429 __DRIcontextPrivate
*driContextPriv
,
430 void *sharedContextPrivate
)
434 GLcontext
*ctx
, *shareCtx
;
436 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
437 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
438 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
439 mgaScreen
->sarea_priv_offset
);
440 struct dd_function_table functions
;
442 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
443 fprintf(stderr
, "mgaCreateContext\n");
445 /* allocate mga context */
446 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
451 /* Init default driver functions then plug in our Radeon-specific functions
452 * (the texture functions are especially important)
454 _mesa_init_driver_functions( &functions
);
455 mgaInitDriverFuncs( &functions
);
456 mgaInitTextureFuncs( &functions
);
457 mgaInitIoctlFuncs( &functions
);
459 /* Allocate the Mesa context */
460 if (sharedContextPrivate
)
461 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
464 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
465 &functions
, (void *) mmesa
);
470 driContextPriv
->driverPrivate
= mmesa
;
473 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
474 mmesa
->driFd
= sPriv
->fd
;
475 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
477 mmesa
->mgaScreen
= mgaScreen
;
478 mmesa
->driScreen
= sPriv
;
479 mmesa
->sarea
= (void *)saPriv
;
481 /* Parse configuration files */
482 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
483 sPriv
->myNum
, "mga");
485 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
486 make_empty_list( & mmesa
->swapped
);
488 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
489 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
490 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
491 mgaScreen
->textureSize
[i
],
494 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
495 &mmesa
->sarea
->texAge
[i
],
497 sizeof( mgaTextureObject_t
),
498 (destroy_texture_object_t
*) mgaDestroyTexObj
);
501 /* Set the maximum texture size small enough that we can guarentee
502 * that both texture units can bind a maximal texture and have them
503 * on the card at once.
506 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
507 ctx
->Const
.MaxTextureUnits
= 1;
508 ctx
->Const
.MaxTextureImageUnits
= 1;
509 ctx
->Const
.MaxTextureCoordUnits
= 1;
510 maxlevels
= G200_TEX_MAXLEVELS
;
514 ctx
->Const
.MaxTextureUnits
= 2;
515 ctx
->Const
.MaxTextureImageUnits
= 2;
516 ctx
->Const
.MaxTextureCoordUnits
= 2;
517 maxlevels
= G400_TEX_MAXLEVELS
;
520 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
524 11, /* max 2D texture size is 2048x2048 */
525 0, /* 3D textures unsupported. */
526 0, /* cube textures unsupported. */
527 11, /* max texture rect size is 2048x2048 */
532 ctx
->Const
.MinLineWidth
= 1.0;
533 ctx
->Const
.MinLineWidthAA
= 1.0;
534 ctx
->Const
.MaxLineWidth
= 10.0;
535 ctx
->Const
.MaxLineWidthAA
= 10.0;
536 ctx
->Const
.LineWidthGranularity
= 1.0;
538 ctx
->Const
.MaxDrawBuffers
= 1;
540 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
542 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
543 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
544 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
545 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
547 switch (mesaVis
->depthBits
) {
549 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
550 mmesa
->depth_clear_mask
= ~0;
551 mmesa
->ClearDepth
= 0xffff;
554 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
555 if (mmesa
->hw_stencil
) {
556 mmesa
->depth_clear_mask
= 0xffffff00;
557 mmesa
->stencil_clear_mask
= 0x000000ff;
559 mmesa
->depth_clear_mask
= ~0;
560 mmesa
->ClearDepth
= 0xffffff00;
563 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
564 mmesa
->depth_clear_mask
= ~0;
565 mmesa
->ClearDepth
= 0xffffffff;
569 mmesa
->haveHwStipple
= GL_FALSE
;
570 mmesa
->RenderIndex
= -1; /* impossible value */
572 mmesa
->vertex_format
= 0;
573 mmesa
->CurrentTexObj
[0] = 0;
574 mmesa
->CurrentTexObj
[1] = 0;
575 mmesa
->tmu_source
[0] = 0;
576 mmesa
->tmu_source
[1] = 1;
578 mmesa
->texAge
[0] = 0;
579 mmesa
->texAge
[1] = 0;
581 /* Initialize the software rasterizer and helper modules.
583 _swrast_CreateContext( ctx
);
584 _vbo_CreateContext( ctx
);
585 _tnl_CreateContext( ctx
);
587 _swsetup_CreateContext( ctx
);
589 /* Install the customized pipeline:
591 _tnl_destroy_pipeline( ctx
);
592 _tnl_install_pipeline( ctx
, mga_pipeline
);
594 /* Configure swrast and T&L to match hardware characteristics:
596 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
597 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
598 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
599 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
601 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
603 ctx
->DriverCtx
= (void *) mmesa
;
606 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
608 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
609 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
612 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
613 driInitExtensions(ctx
, ARB_vp_extensions
, GL_FALSE
);
616 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
617 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
621 /* XXX these should really go right after _mesa_init_driver_functions() */
622 mgaDDInitStateFuncs( ctx
);
623 mgaDDInitSpanFuncs( ctx
);
624 mgaDDInitPixelFuncs( ctx
);
625 mgaDDInitTriFuncs( ctx
);
628 mgaInitState( mmesa
);
630 driContextPriv
->driverPrivate
= (void *) mmesa
;
633 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
637 (*sPriv
->systemTime
->getUST
)( & mmesa
->swap_ust
);
639 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
640 fprintf(stderr
, "disabling 3D acceleration\n");
641 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
648 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
650 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
652 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
653 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
654 __FILE__
, __LINE__
);
656 assert(mmesa
); /* should never be null */
658 GLboolean release_texture_heaps
;
661 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
662 _swsetup_DestroyContext( mmesa
->glCtx
);
663 _tnl_DestroyContext( mmesa
->glCtx
);
664 _vbo_DestroyContext( mmesa
->glCtx
);
665 _swrast_DestroyContext( mmesa
->glCtx
);
667 mgaFreeVB( mmesa
->glCtx
);
669 /* free the Mesa context */
670 mmesa
->glCtx
->DriverCtx
= NULL
;
671 _mesa_destroy_context(mmesa
->glCtx
);
673 if ( release_texture_heaps
) {
674 /* This share group is about to go away, free our private
675 * texture object data.
679 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
680 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
681 mmesa
->texture_heaps
[ i
] = NULL
;
684 assert( is_empty_list( & mmesa
->swapped
) );
687 /* free the option cache */
688 driDestroyOptionCache (&mmesa
->optionCache
);
693 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
694 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
695 __FILE__
, __LINE__
);
700 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
701 __DRIdrawablePrivate
*driDrawPriv
,
702 const __GLcontextModes
*mesaVis
,
705 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
708 return GL_FALSE
; /* not implemented */
711 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
712 mesaVis
->depthBits
!= 24);
715 driDrawPriv
->driverPrivate
= (void *)
716 _mesa_create_framebuffer(mesaVis
,
717 GL_FALSE
, /* software depth buffer? */
719 mesaVis
->accumRedBits
> 0,
720 mesaVis
->alphaBits
> 0 );
722 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
725 driRenderbuffer
*frontRb
726 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
729 screen
->frontOffset
, screen
->frontPitch
,
731 mgaSetSpanFunctions(frontRb
, mesaVis
);
732 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
735 if (mesaVis
->doubleBufferMode
) {
736 driRenderbuffer
*backRb
737 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
740 screen
->backOffset
, screen
->backPitch
,
742 mgaSetSpanFunctions(backRb
, mesaVis
);
743 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
746 if (mesaVis
->depthBits
== 16) {
747 driRenderbuffer
*depthRb
748 = driNewRenderbuffer(MESA_FORMAT_Z16
,
751 screen
->depthOffset
, screen
->depthPitch
,
753 mgaSetSpanFunctions(depthRb
, mesaVis
);
754 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
756 else if (mesaVis
->depthBits
== 24) {
757 /* XXX is this right? */
758 if (mesaVis
->stencilBits
) {
759 driRenderbuffer
*depthRb
760 = driNewRenderbuffer(MESA_FORMAT_Z24_S8
,
763 screen
->depthOffset
, screen
->depthPitch
,
765 mgaSetSpanFunctions(depthRb
, mesaVis
);
766 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
769 driRenderbuffer
*depthRb
770 = driNewRenderbuffer(MESA_FORMAT_Z32
,
773 screen
->depthOffset
, screen
->depthPitch
,
775 mgaSetSpanFunctions(depthRb
, mesaVis
);
776 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
779 else if (mesaVis
->depthBits
== 32) {
780 driRenderbuffer
*depthRb
781 = driNewRenderbuffer(MESA_FORMAT_Z32
,
784 screen
->depthOffset
, screen
->depthPitch
,
786 mgaSetSpanFunctions(depthRb
, mesaVis
);
787 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
790 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
791 driRenderbuffer
*stencilRb
792 = driNewRenderbuffer(MESA_FORMAT_S8
,
795 screen
->depthOffset
, screen
->depthPitch
,
797 mgaSetSpanFunctions(stencilRb
, mesaVis
);
798 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
801 _mesa_add_soft_renderbuffers(fb
,
802 GL_FALSE
, /* color */
803 GL_FALSE
, /* depth */
805 mesaVis
->accumRedBits
> 0,
806 GL_FALSE
, /* alpha */
808 driDrawPriv
->driverPrivate
= (void *) fb
;
811 return (driDrawPriv
->driverPrivate
!= NULL
);
817 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
819 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
823 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
825 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
828 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
831 if (ctx
->Visual
.doubleBufferMode
) {
832 _mesa_notifySwapBuffers( ctx
);
833 mgaCopyBuffer( dPriv
);
836 /* XXX this shouldn't be an error but we can't handle it for now */
837 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
842 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
844 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
851 /* This looks buggy to me - the 'b' variable isn't used anywhere...
852 * Hmm - It seems that the drawable is already hooked in to
855 * But why are we doing context initialization here???
858 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
859 __DRIdrawablePrivate
*driDrawPriv
,
860 __DRIdrawablePrivate
*driReadPriv
)
862 if (driContextPriv
) {
863 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
865 if (mmesa
->driDrawable
!= driDrawPriv
) {
866 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
867 driDrawPriv
->vblFlags
= (mmesa
->mgaScreen
->irq
== 0)
869 : driGetDefaultVBlankFlags(&mmesa
->optionCache
);
871 driDrawableInitVBlank( driDrawPriv
);
874 mmesa
->driDrawable
= driDrawPriv
;
876 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
879 mmesa
->driReadable
= driReadPriv
;
881 _mesa_make_current(mmesa
->glCtx
,
882 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
883 (GLframebuffer
*) driReadPriv
->driverPrivate
);
886 _mesa_make_current(NULL
, NULL
, NULL
);
893 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
895 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
896 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
897 int me
= mmesa
->hHWContext
;
900 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
902 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
903 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
904 mmesa
->lastStamp
= *(dPriv
->pStamp
);
905 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
906 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
907 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
908 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
911 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
913 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
915 if (sarea
->ctxOwner
!= me
) {
916 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
917 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
921 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
922 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
928 * This is the driver specific part of the createNewScreen entry point.
930 * \todo maybe fold this into intelInitDriver
932 * \return the __GLcontextModes supported by this driver
934 static const __DRIconfig
**mgaInitScreen(__DRIscreen
*psp
)
936 static const __DRIversion ddx_expected
= { 1, 2, 0 };
937 static const __DRIversion dri_expected
= { 4, 0, 0 };
938 static const __DRIversion drm_expected
= { 3, 0, 0 };
939 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
941 if ( ! driCheckDriDdxDrmVersions2( "MGA",
942 &psp
->dri_version
, & dri_expected
,
943 &psp
->ddx_version
, & ddx_expected
,
944 &psp
->drm_version
, & drm_expected
) )
948 if (!mgaInitDriver(psp
))
951 return mgaFillInModes( psp
,
953 (dri_priv
->cpp
== 2) ? 16 : 24,
954 (dri_priv
->cpp
== 2) ? 0 : 8,
955 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
960 * Get information about previous buffer swaps.
963 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
967 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
968 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
969 || (sInfo
== NULL
) ) {
973 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
974 sInfo
->swap_count
= mmesa
->swap_count
;
975 sInfo
->swap_ust
= mmesa
->swap_ust
;
976 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
978 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
979 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)
985 const struct __DriverAPIRec driDriverAPI
= {
986 .InitScreen
= mgaInitScreen
,
987 .DestroyScreen
= mgaDestroyScreen
,
988 .CreateContext
= mgaCreateContext
,
989 .DestroyContext
= mgaDestroyContext
,
990 .CreateBuffer
= mgaCreateBuffer
,
991 .DestroyBuffer
= mgaDestroyBuffer
,
992 .SwapBuffers
= mgaSwapBuffers
,
993 .MakeCurrent
= mgaMakeCurrent
,
994 .UnbindContext
= mgaUnbindContext
,
995 .GetSwapInfo
= getSwapInfo
,
996 .GetDrawableMSC
= driDrawableGetMSC32
,
997 .WaitForMSC
= driWaitForMSC32
,
999 .SwapBuffersMSC
= NULL