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_array_object
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 struct gl_config * 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_ARB_vertex_array_object", GL_ARB_vertex_array_object_functions },
387 { "GL_EXT_blend_logic_op", NULL },
388 { "GL_EXT_fog_coord", GL_EXT_fog_coord_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 },
401 static const struct dri_extension ARB_vp_extensions[] = {
402 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
403 { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions },
407 static const struct dri_extension NV_vp_extensions[] = {
408 { "GL_NV_vertex_program", GL_NV_vertex_program_functions },
409 { "GL_NV_vertex_program1_1", NULL },
413 static const struct dri_debug_control debug_control[] =
415 { "fall", DEBUG_VERBOSE_FALLBACK },
416 { "tex", DEBUG_VERBOSE_TEXTURE },
417 { "ioctl", DEBUG_VERBOSE_IOCTL },
418 { "verb", DEBUG_VERBOSE_MSG },
419 { "dri", DEBUG_VERBOSE_DRI },
425 mgaCreateContext( gl_api api,
426 const struct gl_config *mesaVis,
427 __DRIcontext *driContextPriv,
428 void *sharedContextPrivate )
432 struct gl_context *ctx, *shareCtx;
434 __DRIscreen *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(API_OPENGL, 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 ctx->Const.MaxDrawBuffers = 1;
538 mmesa->texture_depth = driQueryOptioni (&mmesa->optionCache,
540 if (mmesa->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
541 mmesa->texture_depth = ( mesaVis->rgbBits >= 24 ) ?
542 DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
543 mmesa->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
545 switch (mesaVis->depthBits) {
547 mmesa->depth_scale = 1.0/(GLdouble)0xffff;
548 mmesa->depth_clear_mask = ~0;
549 mmesa->ClearDepth = 0xffff;
552 mmesa->depth_scale = 1.0/(GLdouble)0xffffff;
553 if (mmesa->hw_stencil) {
554 mmesa->depth_clear_mask = 0xffffff00;
555 mmesa->stencil_clear_mask = 0x000000ff;
557 mmesa->depth_clear_mask = ~0;
558 mmesa->ClearDepth = 0xffffff00;
561 mmesa->depth_scale = 1.0/(GLdouble)0xffffffff;
562 mmesa->depth_clear_mask = ~0;
563 mmesa->ClearDepth = 0xffffffff;
567 mmesa->haveHwStipple = GL_FALSE;
568 mmesa->RenderIndex = -1; /* impossible value */
570 mmesa->vertex_format = 0;
571 mmesa->CurrentTexObj[0] = 0;
572 mmesa->CurrentTexObj[1] = 0;
573 mmesa->tmu_source[0] = 0;
574 mmesa->tmu_source[1] = 1;
576 mmesa->texAge[0] = 0;
577 mmesa->texAge[1] = 0;
579 /* Initialize the software rasterizer and helper modules.
581 _swrast_CreateContext( ctx );
582 _vbo_CreateContext( ctx );
583 _tnl_CreateContext( ctx );
585 _swsetup_CreateContext( ctx );
587 /* Install the customized pipeline:
589 _tnl_destroy_pipeline( ctx );
590 _tnl_install_pipeline( ctx, mga_pipeline );
592 /* Configure swrast and T&L to match hardware characteristics:
594 _swrast_allow_pixel_fog( ctx, GL_FALSE );
595 _swrast_allow_vertex_fog( ctx, GL_TRUE );
596 _tnl_allow_pixel_fog( ctx, GL_FALSE );
597 _tnl_allow_vertex_fog( ctx, GL_TRUE );
599 mmesa->primary_offset = mmesa->mgaScreen->primary.handle;
601 ctx->DriverCtx = (void *) mmesa;
604 driInitExtensions( ctx, card_extensions, GL_FALSE );
606 if (MGA_IS_G400(MGA_CONTEXT(ctx))) {
607 driInitExtensions( ctx, g400_extensions, GL_FALSE );
610 if ( driQueryOptionb( &mmesa->optionCache, "arb_vertex_program" ) ) {
611 driInitExtensions(ctx, ARB_vp_extensions, GL_FALSE);
614 if ( driQueryOptionb( &mmesa->optionCache, "nv_vertex_program" ) ) {
615 driInitExtensions( ctx, NV_vp_extensions, GL_FALSE );
619 /* XXX these should really go right after _mesa_init_driver_functions() */
620 mgaDDInitStateFuncs( ctx );
621 mgaDDInitSpanFuncs( ctx );
622 mgaDDInitPixelFuncs( ctx );
623 mgaDDInitTriFuncs( ctx );
626 mgaInitState( mmesa );
628 driContextPriv->driverPrivate = (void *) mmesa;
631 MGA_DEBUG = driParseDebugString( getenv( "MGA_DEBUG" ),
635 (*sPriv->systemTime->getUST)( & mmesa->swap_ust );
637 if (driQueryOptionb(&mmesa->optionCache, "no_rast")) {
638 fprintf(stderr, "disabling 3D acceleration\n");
639 FALLBACK(mmesa->glCtx, MGA_FALLBACK_DISABLE, 1);
646 mgaDestroyContext(__DRIcontext *driContextPriv)
648 mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
650 if (MGA_DEBUG&DEBUG_VERBOSE_DRI)
651 fprintf( stderr, "[%s:%d] mgaDestroyContext start\n",
652 __FILE__, __LINE__ );
654 assert(mmesa); /* should never be null */
656 GLboolean release_texture_heaps;
659 release_texture_heaps = (mmesa->glCtx->Shared->RefCount == 1);
660 _swsetup_DestroyContext( mmesa->glCtx );
661 _tnl_DestroyContext( mmesa->glCtx );
662 _vbo_DestroyContext( mmesa->glCtx );
663 _swrast_DestroyContext( mmesa->glCtx );
665 mgaFreeVB( mmesa->glCtx );
667 /* free the Mesa context */
668 mmesa->glCtx->DriverCtx = NULL;
669 _mesa_destroy_context(mmesa->glCtx);
671 if ( release_texture_heaps ) {
672 /* This share group is about to go away, free our private
673 * texture object data.
677 for ( i = 0 ; i < mmesa->nr_heaps ; i++ ) {
678 driDestroyTextureHeap( mmesa->texture_heaps[ i ] );
679 mmesa->texture_heaps[ i ] = NULL;
682 assert( is_empty_list( & mmesa->swapped ) );
685 /* free the option cache */
686 driDestroyOptionCache (&mmesa->optionCache);
691 if (MGA_DEBUG&DEBUG_VERBOSE_DRI)
692 fprintf( stderr, "[%s:%d] mgaDestroyContext done\n",
693 __FILE__, __LINE__ );
698 mgaCreateBuffer( __DRIscreen *driScrnPriv,
699 __DRIdrawable *driDrawPriv,
700 const struct gl_config *mesaVis,
703 mgaScreenPrivate *screen = (mgaScreenPrivate *) driScrnPriv->private;
706 return GL_FALSE; /* not implemented */
709 GLboolean swStencil = (mesaVis->stencilBits > 0 &&
710 mesaVis->depthBits != 24);
713 driDrawPriv->driverPrivate = (void *)
714 _mesa_create_framebuffer(mesaVis,
715 GL_FALSE, /* software depth buffer? */
717 mesaVis->accumRedBits > 0,
718 mesaVis->alphaBits > 0 );
720 struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
723 driRenderbuffer *frontRb
724 = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
727 screen->frontOffset, screen->frontPitch,
729 mgaSetSpanFunctions(frontRb, mesaVis);
730 _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
733 if (mesaVis->doubleBufferMode) {
734 driRenderbuffer *backRb
735 = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
738 screen->backOffset, screen->backPitch,
740 mgaSetSpanFunctions(backRb, mesaVis);
741 _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
744 if (mesaVis->depthBits == 16) {
745 driRenderbuffer *depthRb
746 = driNewRenderbuffer(MESA_FORMAT_Z16,
749 screen->depthOffset, screen->depthPitch,
751 mgaSetSpanFunctions(depthRb, mesaVis);
752 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
754 else if (mesaVis->depthBits == 24) {
755 /* XXX is this right? */
756 if (mesaVis->stencilBits) {
757 driRenderbuffer *depthRb
758 = driNewRenderbuffer(MESA_FORMAT_Z24_S8,
761 screen->depthOffset, screen->depthPitch,
763 mgaSetSpanFunctions(depthRb, mesaVis);
764 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
767 driRenderbuffer *depthRb
768 = driNewRenderbuffer(MESA_FORMAT_Z32,
771 screen->depthOffset, screen->depthPitch,
773 mgaSetSpanFunctions(depthRb, mesaVis);
774 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
777 else if (mesaVis->depthBits == 32) {
778 driRenderbuffer *depthRb
779 = driNewRenderbuffer(MESA_FORMAT_Z32,
782 screen->depthOffset, screen->depthPitch,
784 mgaSetSpanFunctions(depthRb, mesaVis);
785 _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
788 if (mesaVis->stencilBits > 0 && !swStencil) {
789 driRenderbuffer *stencilRb
790 = driNewRenderbuffer(MESA_FORMAT_S8,
793 screen->depthOffset, screen->depthPitch,
795 mgaSetSpanFunctions(stencilRb, mesaVis);
796 _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
799 _mesa_add_soft_renderbuffers(fb,
800 GL_FALSE, /* color */
801 GL_FALSE, /* depth */
803 mesaVis->accumRedBits > 0,
804 GL_FALSE, /* alpha */
806 driDrawPriv->driverPrivate = (void *) fb;
809 return (driDrawPriv->driverPrivate != NULL);
815 mgaDestroyBuffer(__DRIdrawable *driDrawPriv)
817 _mesa_reference_framebuffer((struct gl_framebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
821 mgaSwapBuffers(__DRIdrawable *dPriv)
823 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
825 struct gl_context *ctx;
826 mmesa = (mgaContextPtr) dPriv->driContextPriv->driverPrivate;
829 if (ctx->Visual.doubleBufferMode) {
830 _mesa_notifySwapBuffers( ctx );
831 mgaCopyBuffer( dPriv );
834 /* XXX this shouldn't be an error but we can't handle it for now */
835 _mesa_problem(NULL, "%s: drawable has no context!\n", __FUNCTION__);
840 mgaUnbindContext(__DRIcontext *driContextPriv)
842 mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
849 /* This looks buggy to me - the 'b' variable isn't used anywhere...
850 * Hmm - It seems that the drawable is already hooked in to
853 * But why are we doing context initialization here???
856 mgaMakeCurrent(__DRIcontext *driContextPriv,
857 __DRIdrawable *driDrawPriv,
858 __DRIdrawable *driReadPriv)
860 if (driContextPriv) {
861 mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
863 if (mmesa->driDrawable != driDrawPriv) {
864 if (driDrawPriv->swap_interval == (unsigned)-1) {
865 driDrawPriv->vblFlags = (mmesa->mgaScreen->irq == 0)
867 : driGetDefaultVBlankFlags(&mmesa->optionCache);
869 driDrawableInitVBlank( driDrawPriv );
872 mmesa->driDrawable = driDrawPriv;
874 mmesa->dirty_cliprects = (MGA_FRONT|MGA_BACK);
877 mmesa->driReadable = driReadPriv;
879 _mesa_make_current(mmesa->glCtx,
880 (struct gl_framebuffer *) driDrawPriv->driverPrivate,
881 (struct gl_framebuffer *) driReadPriv->driverPrivate);
884 _mesa_make_current(NULL, NULL, NULL);
891 void mgaGetLock( mgaContextPtr mmesa, GLuint flags )
893 __DRIdrawable *dPriv = mmesa->driDrawable;
894 drm_mga_sarea_t *sarea = mmesa->sarea;
895 int me = mmesa->hHWContext;
898 drmGetLock(mmesa->driFd, mmesa->hHWContext, flags);
900 DRI_VALIDATE_DRAWABLE_INFO( mmesa->driScreen, dPriv );
901 if (*(dPriv->pStamp) != mmesa->lastStamp) {
902 mmesa->lastStamp = *(dPriv->pStamp);
903 mmesa->SetupNewInputs |= VERT_BIT_POS;
904 mmesa->dirty_cliprects = (MGA_FRONT|MGA_BACK);
905 mgaUpdateRects( mmesa, (MGA_FRONT|MGA_BACK) );
906 driUpdateFramebufferSize(mmesa->glCtx, dPriv);
909 mmesa->dirty |= MGA_UPLOAD_CONTEXT | MGA_UPLOAD_CLIPRECTS;
911 mmesa->sarea->dirty |= MGA_UPLOAD_CONTEXT;
913 if (sarea->ctxOwner != me) {
914 mmesa->dirty |= (MGA_UPLOAD_CONTEXT | MGA_UPLOAD_TEX0 |
915 MGA_UPLOAD_TEX1 | MGA_UPLOAD_PIPE);
919 for ( i = 0 ; i < mmesa->nr_heaps ; i++ ) {
920 DRI_AGE_TEXTURES( mmesa->texture_heaps[ i ] );
926 * This is the driver specific part of the createNewScreen entry point.
928 * \todo maybe fold this into intelInitDriver
930 * \return the struct gl_config supported by this driver
932 static const __DRIconfig **mgaInitScreen(__DRIscreen *psp)
934 static const __DRIversion ddx_expected = { 1, 2, 0 };
935 static const __DRIversion dri_expected = { 4, 0, 0 };
936 static const __DRIversion drm_expected = { 3, 0, 0 };
937 MGADRIPtr dri_priv = (MGADRIPtr) psp->pDevPriv;
939 if ( ! driCheckDriDdxDrmVersions2( "MGA",
940 &psp->dri_version, & dri_expected,
941 &psp->ddx_version, & ddx_expected,
942 &psp->drm_version, & drm_expected ) )
946 if (!mgaInitDriver(psp))
949 return mgaFillInModes( psp,
951 (dri_priv->cpp == 2) ? 16 : 24,
952 (dri_priv->cpp == 2) ? 0 : 8,
953 (dri_priv->backOffset != dri_priv->depthOffset) );
958 * Get information about previous buffer swaps.
961 getSwapInfo( __DRIdrawable *dPriv, __DRIswapInfo * sInfo )
965 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
966 || (dPriv->driContextPriv->driverPrivate == NULL)
967 || (sInfo == NULL) ) {
971 mmesa = (mgaContextPtr) dPriv->driContextPriv->driverPrivate;
972 sInfo->swap_count = mmesa->swap_count;
973 sInfo->swap_ust = mmesa->swap_ust;
974 sInfo->swap_missed_count = mmesa->swap_missed_count;
976 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
977 ? driCalculateSwapUsage( dPriv, 0, mmesa->swap_missed_ust )
983 const struct __DriverAPIRec driDriverAPI = {
984 .InitScreen = mgaInitScreen,
985 .DestroyScreen = mgaDestroyScreen,
986 .CreateContext = mgaCreateContext,
987 .DestroyContext = mgaDestroyContext,
988 .CreateBuffer = mgaCreateBuffer,
989 .DestroyBuffer = mgaDestroyBuffer,
990 .SwapBuffers = mgaSwapBuffers,
991 .MakeCurrent = mgaMakeCurrent,
992 .UnbindContext = mgaUnbindContext,
993 .GetSwapInfo = getSwapInfo,
994 .GetDrawableMSC = driDrawableGetMSC32,
995 .WaitForMSC = driWaitForMSC32,
997 .SwapBuffersMSC = NULL
1000 /* This is the table of extensions that the loader will dlsym() for. */
1001 PUBLIC const __DRIextension *__driDriverExtensions[] = {
1002 &driCoreExtension.base,
1003 &driLegacyExtension.base,