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/simple_list.h"
39 #include "main/imports.h"
40 #include "main/framebuffer.h"
41 #include "main/renderbuffer.h"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
48 #include "tnl/t_pipeline.h"
50 #include "drivers/common/driverfuncs.h"
60 #include "mga_xmesa.h"
66 #include "drirenderbuffer.h"
68 #include "GL/internal/dri_interface.h"
70 #define need_GL_ARB_vertex_program
71 #define need_GL_EXT_fog_coord
72 #define need_GL_EXT_gpu_program_parameters
73 #define need_GL_EXT_secondary_color
75 #define need_GL_EXT_paletted_texture
77 #define need_GL_APPLE_vertex_array_object
78 #define need_GL_NV_vertex_program
79 #include "main/remap_helper.h"
85 PUBLIC
const char __driConfigOptions
[] =
87 DRI_CONF_SECTION_PERFORMANCE
88 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
90 DRI_CONF_SECTION_QUALITY
91 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
92 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
94 DRI_CONF_SECTION_SOFTWARE
95 DRI_CONF_ARB_VERTEX_PROGRAM(true)
96 DRI_CONF_NV_VERTEX_PROGRAM(true)
98 DRI_CONF_SECTION_DEBUG
99 DRI_CONF_NO_RAST(false)
102 static const GLuint __driNConfigOptions
= 6;
108 static const __DRIconfig
**
109 mgaFillInModes( __DRIscreen
*psp
,
110 unsigned pixel_bits
, unsigned depth_bits
,
111 unsigned stencil_bits
, GLboolean have_back_buffer
)
113 __DRIconfig
**configs
;
114 __GLcontextModes
* m
;
115 unsigned depth_buffer_factor
;
116 unsigned back_buffer_factor
;
121 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
122 * support pageflipping at all.
124 static const GLenum back_buffer_modes
[] = {
125 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
128 uint8_t depth_bits_array
[3];
129 uint8_t stencil_bits_array
[3];
130 uint8_t msaa_samples_array
[1];
133 depth_bits_array
[0] = 0;
134 depth_bits_array
[1] = depth_bits
;
135 depth_bits_array
[2] = depth_bits
;
137 /* Just like with the accumulation buffer, always provide some modes
138 * with a stencil buffer. It will be a sw fallback, but some apps won't
141 stencil_bits_array
[0] = 0;
142 stencil_bits_array
[1] = 0;
143 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
145 msaa_samples_array
[0] = 0;
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 msaa_samples_array
, 1, GL_TRUE
);
164 if (configs
== NULL
) {
165 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
166 __func__
, __LINE__
);
170 /* Mark the visual as slow if there are "fake" stencil bits.
172 for (i
= 0; configs
[i
]; i
++) {
173 m
= &configs
[i
]->modes
;
174 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
175 m
->visualRating
= GLX_SLOW_CONFIG
;
179 return (const __DRIconfig
**) configs
;
182 const __DRIextension
*mgaScreenExtensions
[] = {
183 &driReadDrawableExtension
,
184 &driSwapControlExtension
.base
,
185 &driMediaStreamCounterExtension
.base
,
190 mgaInitDriver(__DRIscreen
*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(__DRIscreen
*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 /* paletted_textures currently doesn't work, but we could fix them later */
389 #if defined( need_GL_EXT_paletted_texture )
390 { "GL_EXT_shared_texture_palette", NULL
},
391 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
393 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
394 { "GL_EXT_stencil_wrap", NULL
},
395 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions
},
396 { "GL_MESA_ycbcr_texture", NULL
},
400 static const struct dri_extension ARB_vp_extensions
[] = {
401 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
402 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
406 static const struct dri_extension NV_vp_extensions
[] = {
407 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
408 { "GL_NV_vertex_program1_1", NULL
},
412 static const struct dri_debug_control debug_control
[] =
414 { "fall", DEBUG_VERBOSE_FALLBACK
},
415 { "tex", DEBUG_VERBOSE_TEXTURE
},
416 { "ioctl", DEBUG_VERBOSE_IOCTL
},
417 { "verb", DEBUG_VERBOSE_MSG
},
418 { "dri", DEBUG_VERBOSE_DRI
},
424 mgaCreateContext( gl_api api
,
425 const __GLcontextModes
*mesaVis
,
426 __DRIcontext
*driContextPriv
,
427 void *sharedContextPrivate
)
431 GLcontext
*ctx
, *shareCtx
;
433 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
434 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
435 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
436 mgaScreen
->sarea_priv_offset
);
437 struct dd_function_table functions
;
439 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
440 fprintf(stderr
, "mgaCreateContext\n");
442 /* allocate mga context */
443 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
448 /* Init default driver functions then plug in our Radeon-specific functions
449 * (the texture functions are especially important)
451 _mesa_init_driver_functions( &functions
);
452 mgaInitDriverFuncs( &functions
);
453 mgaInitTextureFuncs( &functions
);
454 mgaInitIoctlFuncs( &functions
);
456 /* Allocate the Mesa context */
457 if (sharedContextPrivate
)
458 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
461 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
462 &functions
, (void *) mmesa
);
467 driContextPriv
->driverPrivate
= mmesa
;
470 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
471 mmesa
->driFd
= sPriv
->fd
;
472 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
474 mmesa
->mgaScreen
= mgaScreen
;
475 mmesa
->driScreen
= sPriv
;
476 mmesa
->sarea
= (void *)saPriv
;
478 /* Parse configuration files */
479 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
480 sPriv
->myNum
, "mga");
482 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
483 make_empty_list( & mmesa
->swapped
);
485 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
486 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
487 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
488 mgaScreen
->textureSize
[i
],
491 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
492 &mmesa
->sarea
->texAge
[i
],
494 sizeof( mgaTextureObject_t
),
495 (destroy_texture_object_t
*) mgaDestroyTexObj
);
498 /* Set the maximum texture size small enough that we can guarentee
499 * that both texture units can bind a maximal texture and have them
500 * on the card at once.
503 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
504 ctx
->Const
.MaxTextureUnits
= 1;
505 ctx
->Const
.MaxTextureImageUnits
= 1;
506 ctx
->Const
.MaxTextureCoordUnits
= 1;
507 maxlevels
= G200_TEX_MAXLEVELS
;
511 ctx
->Const
.MaxTextureUnits
= 2;
512 ctx
->Const
.MaxTextureImageUnits
= 2;
513 ctx
->Const
.MaxTextureCoordUnits
= 2;
514 maxlevels
= G400_TEX_MAXLEVELS
;
517 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
521 11, /* max 2D texture size is 2048x2048 */
522 0, /* 3D textures unsupported. */
523 0, /* cube textures unsupported. */
524 11, /* max texture rect size is 2048x2048 */
529 ctx
->Const
.MinLineWidth
= 1.0;
530 ctx
->Const
.MinLineWidthAA
= 1.0;
531 ctx
->Const
.MaxLineWidth
= 10.0;
532 ctx
->Const
.MaxLineWidthAA
= 10.0;
533 ctx
->Const
.LineWidthGranularity
= 1.0;
535 ctx
->Const
.MaxDrawBuffers
= 1;
537 mmesa
->texture_depth
= driQueryOptioni (&mmesa
->optionCache
,
539 if (mmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
540 mmesa
->texture_depth
= ( mesaVis
->rgbBits
>= 24 ) ?
541 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
542 mmesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
544 switch (mesaVis
->depthBits
) {
546 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffff;
547 mmesa
->depth_clear_mask
= ~0;
548 mmesa
->ClearDepth
= 0xffff;
551 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffff;
552 if (mmesa
->hw_stencil
) {
553 mmesa
->depth_clear_mask
= 0xffffff00;
554 mmesa
->stencil_clear_mask
= 0x000000ff;
556 mmesa
->depth_clear_mask
= ~0;
557 mmesa
->ClearDepth
= 0xffffff00;
560 mmesa
->depth_scale
= 1.0/(GLdouble
)0xffffffff;
561 mmesa
->depth_clear_mask
= ~0;
562 mmesa
->ClearDepth
= 0xffffffff;
566 mmesa
->haveHwStipple
= GL_FALSE
;
567 mmesa
->RenderIndex
= -1; /* impossible value */
569 mmesa
->vertex_format
= 0;
570 mmesa
->CurrentTexObj
[0] = 0;
571 mmesa
->CurrentTexObj
[1] = 0;
572 mmesa
->tmu_source
[0] = 0;
573 mmesa
->tmu_source
[1] = 1;
575 mmesa
->texAge
[0] = 0;
576 mmesa
->texAge
[1] = 0;
578 /* Initialize the software rasterizer and helper modules.
580 _swrast_CreateContext( ctx
);
581 _vbo_CreateContext( ctx
);
582 _tnl_CreateContext( ctx
);
584 _swsetup_CreateContext( ctx
);
586 /* Install the customized pipeline:
588 _tnl_destroy_pipeline( ctx
);
589 _tnl_install_pipeline( ctx
, mga_pipeline
);
591 /* Configure swrast and T&L to match hardware characteristics:
593 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
594 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
595 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
596 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
598 mmesa
->primary_offset
= mmesa
->mgaScreen
->primary
.handle
;
600 ctx
->DriverCtx
= (void *) mmesa
;
603 driInitExtensions( ctx
, card_extensions
, GL_FALSE
);
605 if (MGA_IS_G400(MGA_CONTEXT(ctx
))) {
606 driInitExtensions( ctx
, g400_extensions
, GL_FALSE
);
609 if ( driQueryOptionb( &mmesa
->optionCache
, "arb_vertex_program" ) ) {
610 driInitExtensions(ctx
, ARB_vp_extensions
, GL_FALSE
);
613 if ( driQueryOptionb( &mmesa
->optionCache
, "nv_vertex_program" ) ) {
614 driInitExtensions( ctx
, NV_vp_extensions
, GL_FALSE
);
618 /* XXX these should really go right after _mesa_init_driver_functions() */
619 mgaDDInitStateFuncs( ctx
);
620 mgaDDInitSpanFuncs( ctx
);
621 mgaDDInitPixelFuncs( ctx
);
622 mgaDDInitTriFuncs( ctx
);
625 mgaInitState( mmesa
);
627 driContextPriv
->driverPrivate
= (void *) mmesa
;
630 MGA_DEBUG
= driParseDebugString( getenv( "MGA_DEBUG" ),
634 (*sPriv
->systemTime
->getUST
)( & mmesa
->swap_ust
);
636 if (driQueryOptionb(&mmesa
->optionCache
, "no_rast")) {
637 fprintf(stderr
, "disabling 3D acceleration\n");
638 FALLBACK(mmesa
->glCtx
, MGA_FALLBACK_DISABLE
, 1);
645 mgaDestroyContext(__DRIcontext
*driContextPriv
)
647 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
649 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
650 fprintf( stderr
, "[%s:%d] mgaDestroyContext start\n",
651 __FILE__
, __LINE__
);
653 assert(mmesa
); /* should never be null */
655 GLboolean release_texture_heaps
;
658 release_texture_heaps
= (mmesa
->glCtx
->Shared
->RefCount
== 1);
659 _swsetup_DestroyContext( mmesa
->glCtx
);
660 _tnl_DestroyContext( mmesa
->glCtx
);
661 _vbo_DestroyContext( mmesa
->glCtx
);
662 _swrast_DestroyContext( mmesa
->glCtx
);
664 mgaFreeVB( mmesa
->glCtx
);
666 /* free the Mesa context */
667 mmesa
->glCtx
->DriverCtx
= NULL
;
668 _mesa_destroy_context(mmesa
->glCtx
);
670 if ( release_texture_heaps
) {
671 /* This share group is about to go away, free our private
672 * texture object data.
676 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
677 driDestroyTextureHeap( mmesa
->texture_heaps
[ i
] );
678 mmesa
->texture_heaps
[ i
] = NULL
;
681 assert( is_empty_list( & mmesa
->swapped
) );
684 /* free the option cache */
685 driDestroyOptionCache (&mmesa
->optionCache
);
690 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
691 fprintf( stderr
, "[%s:%d] mgaDestroyContext done\n",
692 __FILE__
, __LINE__
);
697 mgaCreateBuffer( __DRIscreen
*driScrnPriv
,
698 __DRIdrawable
*driDrawPriv
,
699 const __GLcontextModes
*mesaVis
,
702 mgaScreenPrivate
*screen
= (mgaScreenPrivate
*) driScrnPriv
->private;
705 return GL_FALSE
; /* not implemented */
708 GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
709 mesaVis
->depthBits
!= 24);
712 driDrawPriv
->driverPrivate
= (void *)
713 _mesa_create_framebuffer(mesaVis
,
714 GL_FALSE
, /* software depth buffer? */
716 mesaVis
->accumRedBits
> 0,
717 mesaVis
->alphaBits
> 0 );
719 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
722 driRenderbuffer
*frontRb
723 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
726 screen
->frontOffset
, screen
->frontPitch
,
728 mgaSetSpanFunctions(frontRb
, mesaVis
);
729 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
732 if (mesaVis
->doubleBufferMode
) {
733 driRenderbuffer
*backRb
734 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
737 screen
->backOffset
, screen
->backPitch
,
739 mgaSetSpanFunctions(backRb
, mesaVis
);
740 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
743 if (mesaVis
->depthBits
== 16) {
744 driRenderbuffer
*depthRb
745 = driNewRenderbuffer(MESA_FORMAT_Z16
,
748 screen
->depthOffset
, screen
->depthPitch
,
750 mgaSetSpanFunctions(depthRb
, mesaVis
);
751 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
753 else if (mesaVis
->depthBits
== 24) {
754 /* XXX is this right? */
755 if (mesaVis
->stencilBits
) {
756 driRenderbuffer
*depthRb
757 = driNewRenderbuffer(MESA_FORMAT_Z24_S8
,
760 screen
->depthOffset
, screen
->depthPitch
,
762 mgaSetSpanFunctions(depthRb
, mesaVis
);
763 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
766 driRenderbuffer
*depthRb
767 = driNewRenderbuffer(MESA_FORMAT_Z32
,
770 screen
->depthOffset
, screen
->depthPitch
,
772 mgaSetSpanFunctions(depthRb
, mesaVis
);
773 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
776 else if (mesaVis
->depthBits
== 32) {
777 driRenderbuffer
*depthRb
778 = driNewRenderbuffer(MESA_FORMAT_Z32
,
781 screen
->depthOffset
, screen
->depthPitch
,
783 mgaSetSpanFunctions(depthRb
, mesaVis
);
784 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
787 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
788 driRenderbuffer
*stencilRb
789 = driNewRenderbuffer(MESA_FORMAT_S8
,
792 screen
->depthOffset
, screen
->depthPitch
,
794 mgaSetSpanFunctions(stencilRb
, mesaVis
);
795 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
798 _mesa_add_soft_renderbuffers(fb
,
799 GL_FALSE
, /* color */
800 GL_FALSE
, /* depth */
802 mesaVis
->accumRedBits
> 0,
803 GL_FALSE
, /* alpha */
805 driDrawPriv
->driverPrivate
= (void *) fb
;
808 return (driDrawPriv
->driverPrivate
!= NULL
);
814 mgaDestroyBuffer(__DRIdrawable
*driDrawPriv
)
816 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
820 mgaSwapBuffers(__DRIdrawable
*dPriv
)
822 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
825 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
828 if (ctx
->Visual
.doubleBufferMode
) {
829 _mesa_notifySwapBuffers( ctx
);
830 mgaCopyBuffer( dPriv
);
833 /* XXX this shouldn't be an error but we can't handle it for now */
834 _mesa_problem(NULL
, "%s: drawable has no context!\n", __FUNCTION__
);
839 mgaUnbindContext(__DRIcontext
*driContextPriv
)
841 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
848 /* This looks buggy to me - the 'b' variable isn't used anywhere...
849 * Hmm - It seems that the drawable is already hooked in to
852 * But why are we doing context initialization here???
855 mgaMakeCurrent(__DRIcontext
*driContextPriv
,
856 __DRIdrawable
*driDrawPriv
,
857 __DRIdrawable
*driReadPriv
)
859 if (driContextPriv
) {
860 mgaContextPtr mmesa
= (mgaContextPtr
) driContextPriv
->driverPrivate
;
862 if (mmesa
->driDrawable
!= driDrawPriv
) {
863 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
864 driDrawPriv
->vblFlags
= (mmesa
->mgaScreen
->irq
== 0)
866 : driGetDefaultVBlankFlags(&mmesa
->optionCache
);
868 driDrawableInitVBlank( driDrawPriv
);
871 mmesa
->driDrawable
= driDrawPriv
;
873 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
876 mmesa
->driReadable
= driReadPriv
;
878 _mesa_make_current(mmesa
->glCtx
,
879 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
880 (GLframebuffer
*) driReadPriv
->driverPrivate
);
883 _mesa_make_current(NULL
, NULL
, NULL
);
890 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
892 __DRIdrawable
*dPriv
= mmesa
->driDrawable
;
893 drm_mga_sarea_t
*sarea
= mmesa
->sarea
;
894 int me
= mmesa
->hHWContext
;
897 drmGetLock(mmesa
->driFd
, mmesa
->hHWContext
, flags
);
899 DRI_VALIDATE_DRAWABLE_INFO( mmesa
->driScreen
, dPriv
);
900 if (*(dPriv
->pStamp
) != mmesa
->lastStamp
) {
901 mmesa
->lastStamp
= *(dPriv
->pStamp
);
902 mmesa
->SetupNewInputs
|= VERT_BIT_POS
;
903 mmesa
->dirty_cliprects
= (MGA_FRONT
|MGA_BACK
);
904 mgaUpdateRects( mmesa
, (MGA_FRONT
|MGA_BACK
) );
905 driUpdateFramebufferSize(mmesa
->glCtx
, dPriv
);
908 mmesa
->dirty
|= MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_CLIPRECTS
;
910 mmesa
->sarea
->dirty
|= MGA_UPLOAD_CONTEXT
;
912 if (sarea
->ctxOwner
!= me
) {
913 mmesa
->dirty
|= (MGA_UPLOAD_CONTEXT
| MGA_UPLOAD_TEX0
|
914 MGA_UPLOAD_TEX1
| MGA_UPLOAD_PIPE
);
918 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
919 DRI_AGE_TEXTURES( mmesa
->texture_heaps
[ i
] );
925 * This is the driver specific part of the createNewScreen entry point.
927 * \todo maybe fold this into intelInitDriver
929 * \return the __GLcontextModes supported by this driver
931 static const __DRIconfig
**mgaInitScreen(__DRIscreen
*psp
)
933 static const __DRIversion ddx_expected
= { 1, 2, 0 };
934 static const __DRIversion dri_expected
= { 4, 0, 0 };
935 static const __DRIversion drm_expected
= { 3, 0, 0 };
936 MGADRIPtr dri_priv
= (MGADRIPtr
) psp
->pDevPriv
;
938 if ( ! driCheckDriDdxDrmVersions2( "MGA",
939 &psp
->dri_version
, & dri_expected
,
940 &psp
->ddx_version
, & ddx_expected
,
941 &psp
->drm_version
, & drm_expected
) )
945 if (!mgaInitDriver(psp
))
948 return mgaFillInModes( psp
,
950 (dri_priv
->cpp
== 2) ? 16 : 24,
951 (dri_priv
->cpp
== 2) ? 0 : 8,
952 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
957 * Get information about previous buffer swaps.
960 getSwapInfo( __DRIdrawable
*dPriv
, __DRIswapInfo
* sInfo
)
964 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
965 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
966 || (sInfo
== NULL
) ) {
970 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
971 sInfo
->swap_count
= mmesa
->swap_count
;
972 sInfo
->swap_ust
= mmesa
->swap_ust
;
973 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
975 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
976 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)
982 const struct __DriverAPIRec driDriverAPI
= {
983 .InitScreen
= mgaInitScreen
,
984 .DestroyScreen
= mgaDestroyScreen
,
985 .CreateContext
= mgaCreateContext
,
986 .DestroyContext
= mgaDestroyContext
,
987 .CreateBuffer
= mgaCreateBuffer
,
988 .DestroyBuffer
= mgaDestroyBuffer
,
989 .SwapBuffers
= mgaSwapBuffers
,
990 .MakeCurrent
= mgaMakeCurrent
,
991 .UnbindContext
= mgaUnbindContext
,
992 .GetSwapInfo
= getSwapInfo
,
993 .GetDrawableMSC
= driDrawableGetMSC32
,
994 .WaitForMSC
= driWaitForMSC32
,
996 .SwapBuffersMSC
= NULL
999 /* This is the table of extensions that the loader will dlsym() for. */
1000 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1001 &driCoreExtension
.base
,
1002 &driLegacyExtension
.base
,