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_multi_draw_arrays
76 #define need_GL_EXT_secondary_color
78 #define need_GL_EXT_paletted_texture
80 #define need_GL_APPLE_vertex_array_object
81 #define need_GL_NV_vertex_program
82 #include "extension_helper.h"
88 PUBLIC
const char __driConfigOptions
[] =
90 DRI_CONF_SECTION_PERFORMANCE
91 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
93 DRI_CONF_SECTION_QUALITY
94 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
95 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
97 DRI_CONF_SECTION_SOFTWARE
98 DRI_CONF_ARB_VERTEX_PROGRAM(true)
99 DRI_CONF_NV_VERTEX_PROGRAM(true)
101 DRI_CONF_SECTION_DEBUG
102 DRI_CONF_NO_RAST(false)
105 static const GLuint __driNConfigOptions
= 6;
111 static const __DRIconfig
**
112 mgaFillInModes( __DRIscreenPrivate
*psp
,
113 unsigned pixel_bits
, unsigned depth_bits
,
114 unsigned stencil_bits
, GLboolean have_back_buffer
)
116 __DRIconfig
**configs
;
117 __GLcontextModes
* m
;
118 unsigned depth_buffer_factor
;
119 unsigned back_buffer_factor
;
124 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
125 * support pageflipping at all.
127 static const GLenum back_buffer_modes
[] = {
128 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
131 uint8_t depth_bits_array
[3];
132 uint8_t stencil_bits_array
[3];
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 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
148 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
150 if ( pixel_bits
== 16 ) {
152 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
156 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
159 configs
= driCreateConfigs(fb_format
, fb_type
,
160 depth_bits_array
, stencil_bits_array
,
162 back_buffer_modes
, back_buffer_factor
);
163 if (configs
== NULL
) {
164 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
165 __func__
, __LINE__
);
169 /* Mark the visual as slow if there are "fake" stencil bits.
171 for (i
= 0; configs
[i
]; i
++) {
172 m
= &configs
[i
]->modes
;
173 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
174 m
->visualRating
= GLX_SLOW_CONFIG
;
178 return (const __DRIconfig
**) configs
;
181 const __DRIextension
*mgaScreenExtensions
[] = {
182 &driReadDrawableExtension
,
183 &driSwapControlExtension
.base
,
184 &driFrameTrackingExtension
.base
,
185 &driMediaStreamCounterExtension
.base
,
190 mgaInitDriver(__DRIscreenPrivate
*sPriv
)
192 mgaScreenPrivate
*mgaScreen
;
193 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
195 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
196 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
200 /* Allocate the private area */
201 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
203 __driUtilMessage("Couldn't malloc screen struct");
207 mgaScreen
->sPriv
= sPriv
;
208 sPriv
->private = (void *)mgaScreen
;
210 if (sPriv
->drm_version
.minor
>= 1) {
212 drm_mga_getparam_t gp
;
214 gp
.param
= MGA_PARAM_IRQ_NR
;
215 gp
.value
= &mgaScreen
->irq
;
218 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
221 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
223 sPriv
->private = NULL
;
228 sPriv
->extensions
= mgaScreenExtensions
;
230 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
231 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
233 sPriv
->private = NULL
;
234 __driUtilMessage("Unrecognized chipset");
239 mgaScreen
->chipset
= serverInfo
->chipset
;
240 mgaScreen
->cpp
= serverInfo
->cpp
;
242 mgaScreen
->agpMode
= serverInfo
->agpMode
;
244 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
245 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
246 mgaScreen
->backOffset
= serverInfo
->backOffset
;
247 mgaScreen
->backPitch
= serverInfo
->backPitch
;
248 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
249 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
252 /* The only reason that the MMIO region needs to be accessable and the
253 * primary DMA region base address needs to be known is so that the driver
254 * can busy wait for certain DMA operations to complete (see
255 * mgaWaitForFrameCompletion in mgaioctl.c).
257 * Starting with MGA DRM version 3.2, these are completely unneeded as
258 * there is a new, in-kernel mechanism for handling the wait.
261 if (mgaScreen
->sPriv
->drm_version
.minor
< 2) {
262 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
263 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
264 if ( drmMap( sPriv
->fd
,
265 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
266 &mgaScreen
->mmio
.map
) < 0 ) {
268 sPriv
->private = NULL
;
269 __driUtilMessage( "Couldn't map MMIO registers" );
273 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
274 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
277 (void) memset( & mgaScreen
->primary
, 0, sizeof( mgaScreen
->primary
) );
278 (void) memset( & mgaScreen
->mmio
, 0, sizeof( mgaScreen
->mmio
) );
281 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
282 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
283 PDEA_pagpxfer_enable
| 1);
285 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
286 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
289 /* The texVirtual array stores the base addresses in the CPU's address
290 * space of the texture memory pools. The base address of the on-card
291 * memory pool is calculated as an offset of the base of video memory. The
292 * AGP texture pool has to be mapped into the processes address space by
296 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
297 serverInfo
->textureOffset
);
299 if ( serverInfo
->agpTextureSize
> 0 ) {
300 if (drmMap(sPriv
->fd
, serverInfo
->agpTextureOffset
,
301 serverInfo
->agpTextureSize
,
302 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0) {
304 sPriv
->private = NULL
;
305 __driUtilMessage("Couldn't map agptexture region");
311 /* For calculating setupdma addresses.
314 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
315 if (!mgaScreen
->bufs
) {
317 sPriv
->private = NULL
;
318 __driUtilMessage("Couldn't map dma buffers");
321 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
323 /* parse information in __driConfigOptions */
324 driParseOptionInfo (&mgaScreen
->optionCache
,
325 __driConfigOptions
, __driNConfigOptions
);
332 mgaDestroyScreen(__DRIscreenPrivate
*sPriv
)
334 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
336 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
337 fprintf(stderr
, "mgaDestroyScreen\n");
339 drmUnmapBufs(mgaScreen
->bufs
);
342 /* free all option information */
343 driDestroyOptionInfo (&mgaScreen
->optionCache
);
346 sPriv
->private = NULL
;
350 extern const struct tnl_pipeline_stage _mga_render_stage
;
352 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
353 &_tnl_vertex_transform_stage
,
354 &_tnl_normal_transform_stage
,
355 &_tnl_lighting_stage
,
356 &_tnl_fog_coordinate_stage
,
358 &_tnl_texture_transform_stage
,
359 &_tnl_vertex_program_stage
,
361 /* REMOVE: point attenuation stage */
363 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
364 /* Need new ioctl for wacceptseq */
371 static const struct dri_extension g400_extensions
[] =
373 { "GL_ARB_multitexture", NULL
},
374 { "GL_ARB_texture_env_add", NULL
},
375 { "GL_ARB_texture_env_combine", NULL
},
376 { "GL_ARB_texture_env_crossbar", NULL
},
377 { "GL_EXT_texture_env_combine", NULL
},
378 { "GL_EXT_texture_edge_clamp", NULL
},
379 { "GL_ATI_texture_env_combine3", NULL
},
383 static const struct dri_extension card_extensions
[] =
385 { "GL_ARB_texture_rectangle", NULL
},
386 { "GL_EXT_blend_logic_op", NULL
},
387 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
388 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
389 /* paletted_textures currently doesn't work, but we could fix them later */
390 #if defined( need_GL_EXT_paletted_texture )
391 { "GL_EXT_shared_texture_palette", NULL
},
392 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
394 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
395 { "GL_EXT_stencil_wrap", NULL
},
396 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions
},
397 { "GL_MESA_ycbcr_texture", NULL
},
398 { "GL_SGIS_generate_mipmap", NULL
},
402 static const struct dri_extension ARB_vp_extensions
[] = {
403 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
404 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
408 static const struct dri_extension NV_vp_extensions
[] = {
409 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
410 { "GL_NV_vertex_program1_1", NULL
},
414 static const struct dri_debug_control debug_control
[] =
416 { "fall", DEBUG_VERBOSE_FALLBACK
},
417 { "tex", DEBUG_VERBOSE_TEXTURE
},
418 { "ioctl", DEBUG_VERBOSE_IOCTL
},
419 { "verb", DEBUG_VERBOSE_MSG
},
420 { "dri", DEBUG_VERBOSE_DRI
},
426 mgaCreateContext( const __GLcontextModes
*mesaVis
,
427 __DRIcontextPrivate
*driContextPriv
,
428 void *sharedContextPrivate
)
432 GLcontext
*ctx
, *shareCtx
;
434 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
435 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
436 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
437 mgaScreen
->sarea_priv_offset
);
438 struct dd_function_table functions
;
440 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
441 fprintf(stderr
, "mgaCreateContext\n");
443 /* allocate mga context */
444 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
449 /* Init default driver functions then plug in our Radeon-specific functions
450 * (the texture functions are especially important)
452 _mesa_init_driver_functions( &functions
);
453 mgaInitDriverFuncs( &functions
);
454 mgaInitTextureFuncs( &functions
);
455 mgaInitIoctlFuncs( &functions
);
457 /* Allocate the Mesa context */
458 if (sharedContextPrivate
)
459 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
462 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
463 &functions
, (void *) mmesa
);
468 driContextPriv
->driverPrivate
= mmesa
;
471 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
472 mmesa
->driFd
= sPriv
->fd
;
473 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
475 mmesa
->mgaScreen
= mgaScreen
;
476 mmesa
->driScreen
= sPriv
;
477 mmesa
->sarea
= (void *)saPriv
;
479 /* Parse configuration files */
480 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
481 sPriv
->myNum
, "mga");
483 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
484 make_empty_list( & mmesa
->swapped
);
486 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
487 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
488 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
489 mgaScreen
->textureSize
[i
],
492 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
493 &mmesa
->sarea
->texAge
[i
],
495 sizeof( mgaTextureObject_t
),
496 (destroy_texture_object_t
*) mgaDestroyTexObj
);
499 /* Set the maximum texture size small enough that we can guarentee
500 * that both texture units can bind a maximal texture and have them
501 * on the card at once.
504 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
505 ctx
->Const
.MaxTextureUnits
= 1;
506 ctx
->Const
.MaxTextureImageUnits
= 1;
507 ctx
->Const
.MaxTextureCoordUnits
= 1;
508 maxlevels
= G200_TEX_MAXLEVELS
;
512 ctx
->Const
.MaxTextureUnits
= 2;
513 ctx
->Const
.MaxTextureImageUnits
= 2;
514 ctx
->Const
.MaxTextureCoordUnits
= 2;
515 maxlevels
= G400_TEX_MAXLEVELS
;
518 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
522 11, /* max 2D texture size is 2048x2048 */
523 0, /* 3D textures unsupported. */
524 0, /* cube textures unsupported. */
525 11, /* max texture rect size is 2048x2048 */
530 ctx
->Const
.MinLineWidth
= 1.0;
531 ctx
->Const
.MinLineWidthAA
= 1.0;
532 ctx
->Const
.MaxLineWidth
= 10.0;
533 ctx
->Const
.MaxLineWidthAA
= 10.0;
534 ctx
->Const
.LineWidthGranularity
= 1.0;
536 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
538 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
539 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
540 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
541 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
543 switch (mesaVis
->depthBits
) {
545 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
546 mmesa
->depth_clear_mask
= ~0;
547 mmesa
->ClearDepth
= 0xffff;
550 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
551 if (mmesa
->hw_stencil
) {
552 mmesa
->depth_clear_mask
= 0xffffff00;
553 mmesa
->stencil_clear_mask
= 0x000000ff;
555 mmesa
->depth_clear_mask
= ~0;
556 mmesa
->ClearDepth
= 0xffffff00;
559 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
560 mmesa
->depth_clear_mask
= ~0;
561 mmesa
->ClearDepth
= 0xffffffff;
565 mmesa
->haveHwStipple
= GL_FALSE
;
566 mmesa
->RenderIndex
= -1; /* impossible value */
568 mmesa
->vertex_format
= 0;
569 mmesa
->CurrentTexObj
[0] = 0;
570 mmesa
->CurrentTexObj
[1] = 0;
571 mmesa
->tmu_source
[0] = 0;
572 mmesa
->tmu_source
[1] = 1;
574 mmesa
->texAge
[0] = 0;
575 mmesa
->texAge
[1] = 0;
577 /* Initialize the software rasterizer and helper modules.
579 _swrast_CreateContext( ctx
);
580 _vbo_CreateContext( ctx
);
581 _tnl_CreateContext( ctx
);
583 _swsetup_CreateContext( ctx
);
585 /* Install the customized pipeline:
587 _tnl_destroy_pipeline( ctx
);
588 _tnl_install_pipeline( ctx
, mga_pipeline
);
590 /* Configure swrast and T&L to match hardware characteristics:
592 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
593 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
594 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
595 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
597 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
599 ctx
->DriverCtx
= (void *) mmesa
;
602 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
604 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
605 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
608 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
609 driInitExtensions(ctx
, ARB_vp_extensions
, GL_FALSE
);
612 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
613 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
617 /* XXX these should really go right after _mesa_init_driver_functions() */
618 mgaDDInitStateFuncs( ctx
);
619 mgaDDInitSpanFuncs( ctx
);
620 mgaDDInitPixelFuncs( ctx
);
621 mgaDDInitTriFuncs( ctx
);
624 mgaInitState( mmesa
);
626 driContextPriv
->driverPrivate
= (void *) mmesa
;
629 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
633 (*sPriv
->systemTime
->getUST
)( & mmesa
->swap_ust
);
635 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
636 fprintf(stderr
, "disabling 3D acceleration\n");
637 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
644 mgaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
646 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
648 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
649 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
650 __FILE__
, __LINE__
);
652 assert(mmesa
); /* should never be null */
654 GLboolean release_texture_heaps
;
657 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
658 _swsetup_DestroyContext( mmesa
->glCtx
);
659 _tnl_DestroyContext( mmesa
->glCtx
);
660 _vbo_DestroyContext( mmesa
->glCtx
);
661 _swrast_DestroyContext( mmesa
->glCtx
);
663 mgaFreeVB( mmesa
->glCtx
);
665 /* free the Mesa context */
666 mmesa
->glCtx
->DriverCtx
= NULL
;
667 _mesa_destroy_context(mmesa
->glCtx
);
669 if ( release_texture_heaps
) {
670 /* This share group is about to go away, free our private
671 * texture object data.
675 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
676 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
677 mmesa
->texture_heaps
[ i
] = NULL
;
680 assert( is_empty_list( & mmesa
->swapped
) );
683 /* free the option cache */
684 driDestroyOptionCache (&mmesa
->optionCache
);
689 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
690 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
691 __FILE__
, __LINE__
);
696 mgaCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
697 __DRIdrawablePrivate
*driDrawPriv
,
698 const __GLcontextModes
*mesaVis
,
701 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
704 return GL_FALSE
; /* not implemented */
707 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
708 mesaVis
->depthBits
!= 24);
711 driDrawPriv
->driverPrivate
= (void *)
712 _mesa_create_framebuffer(mesaVis
,
713 GL_FALSE
, /* software depth buffer? */
715 mesaVis
->accumRedBits
> 0,
716 mesaVis
->alphaBits
> 0 );
718 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
721 driRenderbuffer
*frontRb
722 = driNewRenderbuffer(GL_RGBA
,
725 screen
->frontOffset
, screen
->frontPitch
,
727 mgaSetSpanFunctions(frontRb
, mesaVis
);
728 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
731 if (mesaVis
->doubleBufferMode
) {
732 driRenderbuffer
*backRb
733 = driNewRenderbuffer(GL_RGBA
,
736 screen
->backOffset
, screen
->backPitch
,
738 mgaSetSpanFunctions(backRb
, mesaVis
);
739 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
742 if (mesaVis
->depthBits
== 16) {
743 driRenderbuffer
*depthRb
744 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
747 screen
->depthOffset
, screen
->depthPitch
,
749 mgaSetSpanFunctions(depthRb
, mesaVis
);
750 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
752 else if (mesaVis
->depthBits
== 24) {
753 /* XXX is this right? */
754 if (mesaVis
->stencilBits
) {
755 driRenderbuffer
*depthRb
756 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
759 screen
->depthOffset
, screen
->depthPitch
,
761 mgaSetSpanFunctions(depthRb
, mesaVis
);
762 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
765 driRenderbuffer
*depthRb
766 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
769 screen
->depthOffset
, screen
->depthPitch
,
771 mgaSetSpanFunctions(depthRb
, mesaVis
);
772 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
775 else if (mesaVis
->depthBits
== 32) {
776 driRenderbuffer
*depthRb
777 = driNewRenderbuffer(GL_DEPTH_COMPONENT32
,
780 screen
->depthOffset
, screen
->depthPitch
,
782 mgaSetSpanFunctions(depthRb
, mesaVis
);
783 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
786 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
787 driRenderbuffer
*stencilRb
788 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
791 screen
->depthOffset
, screen
->depthPitch
,
793 mgaSetSpanFunctions(stencilRb
, mesaVis
);
794 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
797 _mesa_add_soft_renderbuffers(fb
,
798 GL_FALSE
, /* color */
799 GL_FALSE
, /* depth */
801 mesaVis
->accumRedBits
> 0,
802 GL_FALSE
, /* alpha */
804 driDrawPriv
->driverPrivate
= (void *) fb
;
807 return (driDrawPriv
->driverPrivate
!= NULL
);
813 mgaDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
815 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
819 mgaSwapBuffers(__DRIdrawablePrivate
*dPriv
)
821 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
824 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
827 if (ctx
->Visual
.doubleBufferMode
) {
828 _mesa_notifySwapBuffers( ctx
);
829 mgaCopyBuffer( dPriv
);
832 /* XXX this shouldn't be an error but we can't handle it for now */
833 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
838 mgaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
840 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
847 /* This looks buggy to me - the 'b' variable isn't used anywhere...
848 * Hmm - It seems that the drawable is already hooked in to
851 * But why are we doing context initialization here???
854 mgaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
855 __DRIdrawablePrivate
*driDrawPriv
,
856 __DRIdrawablePrivate
*driReadPriv
)
858 if (driContextPriv
) {
859 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
861 if (mmesa
->driDrawable
!= driDrawPriv
) {
862 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
863 driDrawPriv
->vblFlags
= (mmesa
->mgaScreen
->irq
== 0)
865 : driGetDefaultVBlankFlags(&mmesa
->optionCache
);
867 driDrawableInitVBlank( driDrawPriv
);
870 mmesa
->driDrawable
= driDrawPriv
;
872 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
875 mmesa
->driReadable
= driReadPriv
;
877 _mesa_make_current(mmesa
->glCtx
,
878 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
879 (GLframebuffer
*) driReadPriv
->driverPrivate
);
882 _mesa_make_current(NULL
, NULL
, NULL
);
889 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
891 __DRIdrawablePrivate
*dPriv
= mmesa
->driDrawable
;
892 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
893 int me
= mmesa
->hHWContext
;
896 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
898 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
899 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
900 mmesa
->lastStamp
= *(dPriv
->pStamp
);
901 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
902 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
903 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
904 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
907 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
909 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
911 if (sarea
->ctxOwner
!= me
) {
912 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
913 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
917 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
918 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
924 * This is the driver specific part of the createNewScreen entry point.
926 * \todo maybe fold this into intelInitDriver
928 * \return the __GLcontextModes supported by this driver
930 static const __DRIconfig
**mgaInitScreen(__DRIscreen
*psp
)
932 static const __DRIversion ddx_expected
= { 1, 2, 0 };
933 static const __DRIversion dri_expected
= { 4, 0, 0 };
934 static const __DRIversion drm_expected
= { 3, 0, 0 };
935 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
937 if ( ! driCheckDriDdxDrmVersions2( "MGA",
938 &psp
->dri_version
, & dri_expected
,
939 &psp
->ddx_version
, & ddx_expected
,
940 &psp
->drm_version
, & drm_expected
) )
944 /* Calling driInitExtensions here, with a NULL context pointer,
945 * does not actually enable the extensions. It just makes sure
946 * that all the dispatch offsets for all the extensions that
947 * *might* be enables are known. This is needed because the
948 * dispatch offsets need to be known when _mesa_context_create is
949 * called, but we can't enable the extensions until we have a
952 * Hello chicken. Hello egg. How are you two today?
955 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
956 driInitExtensions( NULL
, g400_extensions
, GL_FALSE
);
957 driInitExtensions(NULL
, ARB_vp_extensions
, GL_FALSE
);
958 driInitExtensions( NULL
, NV_vp_extensions
, GL_FALSE
);
960 if (!mgaInitDriver(psp
))
963 return mgaFillInModes( psp
,
965 (dri_priv
->cpp
== 2) ? 16 : 24,
966 (dri_priv
->cpp
== 2) ? 0 : 8,
967 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
972 * Get information about previous buffer swaps.
975 getSwapInfo( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
)
979 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
980 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
981 || (sInfo
== NULL
) ) {
985 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
986 sInfo
->swap_count
= mmesa
->swap_count
;
987 sInfo
->swap_ust
= mmesa
->swap_ust
;
988 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
990 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
991 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)
997 const struct __DriverAPIRec driDriverAPI
= {
998 .InitScreen
= mgaInitScreen
,
999 .DestroyScreen
= mgaDestroyScreen
,
1000 .CreateContext
= mgaCreateContext
,
1001 .DestroyContext
= mgaDestroyContext
,
1002 .CreateBuffer
= mgaCreateBuffer
,
1003 .DestroyBuffer
= mgaDestroyBuffer
,
1004 .SwapBuffers
= mgaSwapBuffers
,
1005 .MakeCurrent
= mgaMakeCurrent
,
1006 .UnbindContext
= mgaUnbindContext
,
1007 .GetSwapInfo
= getSwapInfo
,
1008 .GetDrawableMSC
= driDrawableGetMSC32
,
1009 .WaitForMSC
= driWaitForMSC32
,
1011 .SwapBuffersMSC
= NULL