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"
65 #include "drirenderbuffer.h"
67 #include "GL/internal/dri_interface.h"
69 #define need_GL_ARB_vertex_program
70 #define need_GL_EXT_fog_coord
71 #define need_GL_EXT_gpu_program_parameters
72 #define need_GL_EXT_secondary_color
74 #define need_GL_EXT_paletted_texture
76 #define need_GL_APPLE_vertex_array_object
77 #define need_GL_NV_vertex_program
78 #include "main/remap_helper.h"
84 PUBLIC
const char __driConfigOptions
[] =
86 DRI_CONF_SECTION_PERFORMANCE
87 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
89 DRI_CONF_SECTION_QUALITY
90 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
91 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
93 DRI_CONF_SECTION_SOFTWARE
94 DRI_CONF_ARB_VERTEX_PROGRAM(true)
95 DRI_CONF_NV_VERTEX_PROGRAM(true)
97 DRI_CONF_SECTION_DEBUG
98 DRI_CONF_NO_RAST(false)
101 static const GLuint __driNConfigOptions
= 6;
107 static const __DRIconfig
**
108 mgaFillInModes( __DRIscreen
*psp
,
109 unsigned pixel_bits
, unsigned depth_bits
,
110 unsigned stencil_bits
, GLboolean have_back_buffer
)
112 __DRIconfig
**configs
;
113 struct gl_config
* m
;
114 unsigned depth_buffer_factor
;
115 unsigned back_buffer_factor
;
120 /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
121 * support pageflipping at all.
123 static const GLenum back_buffer_modes
[] = {
124 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
127 uint8_t depth_bits_array
[3];
128 uint8_t stencil_bits_array
[3];
129 uint8_t msaa_samples_array
[1];
132 depth_bits_array
[0] = 0;
133 depth_bits_array
[1] = depth_bits
;
134 depth_bits_array
[2] = depth_bits
;
136 /* Just like with the accumulation buffer, always provide some modes
137 * with a stencil buffer. It will be a sw fallback, but some apps won't
140 stencil_bits_array
[0] = 0;
141 stencil_bits_array
[1] = 0;
142 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
144 msaa_samples_array
[0] = 0;
146 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
147 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
149 if ( pixel_bits
== 16 ) {
151 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
155 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
158 configs
= driCreateConfigs(fb_format
, fb_type
,
159 depth_bits_array
, stencil_bits_array
,
161 back_buffer_modes
, back_buffer_factor
,
162 msaa_samples_array
, 1, GL_TRUE
);
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 &driMediaStreamCounterExtension
.base
,
189 mgaInitDriver(__DRIscreen
*sPriv
)
191 mgaScreenPrivate
*mgaScreen
;
192 MGADRIPtr serverInfo
= (MGADRIPtr
)sPriv
->pDevPriv
;
194 if (sPriv
->devPrivSize
!= sizeof(MGADRIRec
)) {
195 fprintf(stderr
,"\nERROR! sizeof(MGADRIRec) does not match passed size from device driver\n");
199 /* Allocate the private area */
200 mgaScreen
= (mgaScreenPrivate
*)MALLOC(sizeof(mgaScreenPrivate
));
202 __driUtilMessage("Couldn't malloc screen struct");
206 mgaScreen
->sPriv
= sPriv
;
207 sPriv
->private = (void *)mgaScreen
;
209 if (sPriv
->drm_version
.minor
>= 1) {
211 drm_mga_getparam_t gp
;
213 gp
.param
= MGA_PARAM_IRQ_NR
;
214 gp
.value
= &mgaScreen
->irq
;
217 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_MGA_GETPARAM
,
220 fprintf(stderr
, "drmMgaGetParam (MGA_PARAM_IRQ_NR): %d\n", ret
);
222 sPriv
->private = NULL
;
227 sPriv
->extensions
= mgaScreenExtensions
;
229 if (serverInfo
->chipset
!= MGA_CARD_TYPE_G200
&&
230 serverInfo
->chipset
!= MGA_CARD_TYPE_G400
) {
232 sPriv
->private = NULL
;
233 __driUtilMessage("Unrecognized chipset");
238 mgaScreen
->chipset
= serverInfo
->chipset
;
239 mgaScreen
->cpp
= serverInfo
->cpp
;
241 mgaScreen
->agpMode
= serverInfo
->agpMode
;
243 mgaScreen
->frontPitch
= serverInfo
->frontPitch
;
244 mgaScreen
->frontOffset
= serverInfo
->frontOffset
;
245 mgaScreen
->backOffset
= serverInfo
->backOffset
;
246 mgaScreen
->backPitch
= serverInfo
->backPitch
;
247 mgaScreen
->depthOffset
= serverInfo
->depthOffset
;
248 mgaScreen
->depthPitch
= serverInfo
->depthPitch
;
251 /* The only reason that the MMIO region needs to be accessable and the
252 * primary DMA region base address needs to be known is so that the driver
253 * can busy wait for certain DMA operations to complete (see
254 * mgaWaitForFrameCompletion in mgaioctl.c).
256 * Starting with MGA DRM version 3.2, these are completely unneeded as
257 * there is a new, in-kernel mechanism for handling the wait.
260 if (mgaScreen
->sPriv
->drm_version
.minor
< 2) {
261 mgaScreen
->mmio
.handle
= serverInfo
->registers
.handle
;
262 mgaScreen
->mmio
.size
= serverInfo
->registers
.size
;
263 if ( drmMap( sPriv
->fd
,
264 mgaScreen
->mmio
.handle
, mgaScreen
->mmio
.size
,
265 &mgaScreen
->mmio
.map
) < 0 ) {
267 sPriv
->private = NULL
;
268 __driUtilMessage( "Couldn't map MMIO registers" );
272 mgaScreen
->primary
.handle
= serverInfo
->primary
.handle
;
273 mgaScreen
->primary
.size
= serverInfo
->primary
.size
;
276 (void) memset( & mgaScreen
->primary
, 0, sizeof( mgaScreen
->primary
) );
277 (void) memset( & mgaScreen
->mmio
, 0, sizeof( mgaScreen
->mmio
) );
280 mgaScreen
->textureOffset
[MGA_CARD_HEAP
] = serverInfo
->textureOffset
;
281 mgaScreen
->textureOffset
[MGA_AGP_HEAP
] = (serverInfo
->agpTextureOffset
|
282 PDEA_pagpxfer_enable
| 1);
284 mgaScreen
->textureSize
[MGA_CARD_HEAP
] = serverInfo
->textureSize
;
285 mgaScreen
->textureSize
[MGA_AGP_HEAP
] = serverInfo
->agpTextureSize
;
288 /* The texVirtual array stores the base addresses in the CPU's address
289 * space of the texture memory pools. The base address of the on-card
290 * memory pool is calculated as an offset of the base of video memory. The
291 * AGP texture pool has to be mapped into the processes address space by
295 mgaScreen
->texVirtual
[MGA_CARD_HEAP
] = (char *)(mgaScreen
->sPriv
->pFB
+
296 serverInfo
->textureOffset
);
298 if ( serverInfo
->agpTextureSize
> 0 ) {
299 if (drmMap(sPriv
->fd
, serverInfo
->agpTextureOffset
,
300 serverInfo
->agpTextureSize
,
301 (drmAddress
*)&mgaScreen
->texVirtual
[MGA_AGP_HEAP
]) != 0) {
303 sPriv
->private = NULL
;
304 __driUtilMessage("Couldn't map agptexture region");
310 /* For calculating setupdma addresses.
313 mgaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
314 if (!mgaScreen
->bufs
) {
316 sPriv
->private = NULL
;
317 __driUtilMessage("Couldn't map dma buffers");
320 mgaScreen
->sarea_priv_offset
= serverInfo
->sarea_priv_offset
;
322 /* parse information in __driConfigOptions */
323 driParseOptionInfo (&mgaScreen
->optionCache
,
324 __driConfigOptions
, __driNConfigOptions
);
331 mgaDestroyScreen(__DRIscreen
*sPriv
)
333 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*) sPriv
->private;
335 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
336 fprintf(stderr
, "mgaDestroyScreen\n");
338 drmUnmapBufs(mgaScreen
->bufs
);
341 /* free all option information */
342 driDestroyOptionInfo (&mgaScreen
->optionCache
);
345 sPriv
->private = NULL
;
349 extern const struct tnl_pipeline_stage _mga_render_stage
;
351 static const struct tnl_pipeline_stage
*mga_pipeline
[] = {
352 &_tnl_vertex_transform_stage
,
353 &_tnl_normal_transform_stage
,
354 &_tnl_lighting_stage
,
355 &_tnl_fog_coordinate_stage
,
357 &_tnl_texture_transform_stage
,
358 &_tnl_vertex_program_stage
,
360 /* REMOVE: point attenuation stage */
362 &_mga_render_stage
, /* ADD: unclipped rastersetup-to-dma */
363 /* Need new ioctl for wacceptseq */
370 static const struct dri_extension g400_extensions
[] =
372 { "GL_ARB_multitexture", NULL
},
373 { "GL_ARB_texture_env_add", NULL
},
374 { "GL_ARB_texture_env_combine", NULL
},
375 { "GL_ARB_texture_env_crossbar", NULL
},
376 { "GL_EXT_texture_env_combine", NULL
},
377 { "GL_EXT_texture_edge_clamp", NULL
},
378 { "GL_ATI_texture_env_combine3", NULL
},
382 static const struct dri_extension card_extensions
[] =
384 { "GL_ARB_texture_rectangle", NULL
},
385 { "GL_EXT_blend_logic_op", NULL
},
386 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
387 /* paletted_textures currently doesn't work, but we could fix them later */
388 #if defined( need_GL_EXT_paletted_texture )
389 { "GL_EXT_shared_texture_palette", NULL
},
390 { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions
},
392 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
393 { "GL_EXT_stencil_wrap", NULL
},
394 { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions
},
395 { "GL_MESA_ycbcr_texture", NULL
},
399 static const struct dri_extension ARB_vp_extensions
[] = {
400 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
401 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions
},
405 static const struct dri_extension NV_vp_extensions
[] = {
406 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
407 { "GL_NV_vertex_program1_1", NULL
},
411 static const struct dri_debug_control debug_control
[] =
413 { "fall", DEBUG_VERBOSE_FALLBACK
},
414 { "tex", DEBUG_VERBOSE_TEXTURE
},
415 { "ioctl", DEBUG_VERBOSE_IOCTL
},
416 { "verb", DEBUG_VERBOSE_MSG
},
417 { "dri", DEBUG_VERBOSE_DRI
},
423 mgaCreateContext( gl_api api
,
424 const struct gl_config
*mesaVis
,
425 __DRIcontext
*driContextPriv
,
426 void *sharedContextPrivate
)
430 struct gl_context
*ctx
, *shareCtx
;
432 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
433 mgaScreenPrivate
*mgaScreen
= (mgaScreenPrivate
*)sPriv
->private;
434 drm_mga_sarea_t
*saPriv
= (drm_mga_sarea_t
*)(((char*)sPriv
->pSAREA
)+
435 mgaScreen
->sarea_priv_offset
);
436 struct dd_function_table functions
;
438 if (MGA_DEBUG
&DEBUG_VERBOSE_DRI
)
439 fprintf(stderr
, "mgaCreateContext\n");
441 /* allocate mga context */
442 mmesa
= (mgaContextPtr
) CALLOC(sizeof(mgaContext
));
447 /* Init default driver functions then plug in our Radeon-specific functions
448 * (the texture functions are especially important)
450 _mesa_init_driver_functions( &functions
);
451 mgaInitDriverFuncs( &functions
);
452 mgaInitTextureFuncs( &functions
);
453 mgaInitIoctlFuncs( &functions
);
455 /* Allocate the Mesa context */
456 if (sharedContextPrivate
)
457 shareCtx
= ((mgaContextPtr
) sharedContextPrivate
)->glCtx
;
460 mmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
,
461 &functions
, (void *) mmesa
);
466 driContextPriv
->driverPrivate
= mmesa
;
469 mmesa
->hHWContext
= driContextPriv
->hHWContext
;
470 mmesa
->driFd
= sPriv
->fd
;
471 mmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
473 mmesa
->mgaScreen
= mgaScreen
;
474 mmesa
->driScreen
= sPriv
;
475 mmesa
->sarea
= (void *)saPriv
;
477 /* Parse configuration files */
478 driParseConfigFiles (&mmesa
->optionCache
, &mgaScreen
->optionCache
,
479 sPriv
->myNum
, "mga");
481 (void) memset( mmesa
->texture_heaps
, 0, sizeof( mmesa
->texture_heaps
) );
482 make_empty_list( & mmesa
->swapped
);
484 mmesa
->nr_heaps
= mgaScreen
->texVirtual
[MGA_AGP_HEAP
] ? 2 : 1;
485 for ( i
= 0 ; i
< mmesa
->nr_heaps
; i
++ ) {
486 mmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, mmesa
,
487 mgaScreen
->textureSize
[i
],
490 (drmTextureRegionPtr
)mmesa
->sarea
->texList
[i
],
491 &mmesa
->sarea
->texAge
[i
],
493 sizeof( mgaTextureObject_t
),
494 (destroy_texture_object_t
*) mgaDestroyTexObj
);
497 /* Set the maximum texture size small enough that we can guarentee
498 * that both texture units can bind a maximal texture and have them
499 * on the card at once.
502 if ( mgaScreen
->chipset
== MGA_CARD_TYPE_G200
) {
503 ctx
->Const
.MaxTextureUnits
= 1;
504 ctx
->Const
.MaxTextureImageUnits
= 1;
505 ctx
->Const
.MaxTextureCoordUnits
= 1;
506 maxlevels
= G200_TEX_MAXLEVELS
;
510 ctx
->Const
.MaxTextureUnits
= 2;
511 ctx
->Const
.MaxTextureImageUnits
= 2;
512 ctx
->Const
.MaxTextureCoordUnits
= 2;
513 maxlevels
= G400_TEX_MAXLEVELS
;
516 driCalculateMaxTextureLevels( mmesa
->texture_heaps
,
520 11, /* max 2D texture size is 2048x2048 */
521 0, /* 3D textures unsupported. */
522 0, /* cube textures unsupported. */
523 11, /* max texture rect size is 2048x2048 */
528 ctx
->Const
.MinLineWidth
= 1.0;
529 ctx
->Const
.MinLineWidthAA
= 1.0;
530 ctx
->Const
.MaxLineWidth
= 10.0;
531 ctx
->Const
.MaxLineWidthAA
= 10.0;
532 ctx
->Const
.LineWidthGranularity
= 1.0;
534 ctx
->Const
.MaxDrawBuffers
= 1;
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(__DRIcontext
*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( __DRIscreen
*driScrnPriv
,
697 __DRIdrawable
*driDrawPriv
,
698 const struct gl_config
*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(MESA_FORMAT_ARGB8888
,
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(MESA_FORMAT_ARGB8888
,
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(MESA_FORMAT_Z16
,
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(MESA_FORMAT_Z24_S8
,
759 screen
->depthOffset
, screen
->depthPitch
,
761 mgaSetSpanFunctions(depthRb
, mesaVis
);
762 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
765 driRenderbuffer
*depthRb
766 = driNewRenderbuffer(MESA_FORMAT_Z32
,
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(MESA_FORMAT_Z32
,
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(MESA_FORMAT_S8
,
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(__DRIdrawable
*driDrawPriv
)
815 _mesa_reference_framebuffer((struct gl_framebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
819 mgaSwapBuffers(__DRIdrawable
*dPriv
)
821 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
823 struct gl_context
*ctx
;
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(__DRIcontext
*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(__DRIcontext
*driContextPriv
,
855 __DRIdrawable
*driDrawPriv
,
856 __DRIdrawable
*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 (struct gl_framebuffer
*) driDrawPriv
->driverPrivate
,
879 (struct gl_framebuffer
*) driReadPriv
->driverPrivate
);
882 _mesa_make_current(NULL
, NULL
, NULL
);
889 void mgaGetLock( mgaContextPtr mmesa
, GLuint flags
)
891 __DRIdrawable
*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 struct gl_config 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 if (!mgaInitDriver(psp
))
947 return mgaFillInModes( psp
,
949 (dri_priv
->cpp
== 2) ? 16 : 24,
950 (dri_priv
->cpp
== 2) ? 0 : 8,
951 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
956 * Get information about previous buffer swaps.
959 getSwapInfo( __DRIdrawable
*dPriv
, __DRIswapInfo
* sInfo
)
963 if ( (dPriv
== NULL
) || (dPriv
->driContextPriv
== NULL
)
964 || (dPriv
->driContextPriv
->driverPrivate
== NULL
)
965 || (sInfo
== NULL
) ) {
969 mmesa
= (mgaContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
970 sInfo
->swap_count
= mmesa
->swap_count
;
971 sInfo
->swap_ust
= mmesa
->swap_ust
;
972 sInfo
->swap_missed_count
= mmesa
->swap_missed_count
;
974 sInfo
->swap_missed_usage
= (sInfo
->swap_missed_count
!= 0)
975 ? driCalculateSwapUsage( dPriv
, 0, mmesa
->swap_missed_ust
)
981 const struct __DriverAPIRec driDriverAPI
= {
982 .InitScreen
= mgaInitScreen
,
983 .DestroyScreen
= mgaDestroyScreen
,
984 .CreateContext
= mgaCreateContext
,
985 .DestroyContext
= mgaDestroyContext
,
986 .CreateBuffer
= mgaCreateBuffer
,
987 .DestroyBuffer
= mgaDestroyBuffer
,
988 .SwapBuffers
= mgaSwapBuffers
,
989 .MakeCurrent
= mgaMakeCurrent
,
990 .UnbindContext
= mgaUnbindContext
,
991 .GetSwapInfo
= getSwapInfo
,
992 .GetDrawableMSC
= driDrawableGetMSC32
,
993 .WaitForMSC
= driWaitForMSC32
,
995 .SwapBuffersMSC
= NULL
998 /* This is the table of extensions that the loader will dlsym() for. */
999 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1000 &driCoreExtension
.base
,
1001 &driLegacyExtension
.base
,