2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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 * VIA, S3 GRAPHICS, 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 OTHER
22 * DEALINGS IN THE SOFTWARE.
28 * \author John Sheng (presumably of either VIA Technologies or S3 Graphics)
29 * \author Others at VIA Technologies?
30 * \author Others at S3 Graphics?
37 #include "simple_list.h"
38 #include "extensions.h"
39 #include "framebuffer.h"
40 #include "renderbuffer.h"
42 #include "swrast/swrast.h"
43 #include "swrast_setup/swrast_setup.h"
47 #include "tnl/t_pipeline.h"
49 #include "drivers/common/driverfuncs.h"
51 #include "via_screen.h"
54 #include "via_state.h"
58 #include "via_ioctl.h"
63 #include "drirenderbuffer.h"
65 #define need_GL_ARB_multisample
66 #define need_GL_ARB_point_parameters
67 #define need_GL_EXT_fog_coord
68 #define need_GL_EXT_secondary_color
69 #include "extension_helper.h"
71 #define DRIVER_DATE "20060710"
79 * Return various strings for \c glGetString.
83 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
85 static char buffer
[128];
91 return (GLubyte
*)"VIA Technology";
94 static const char * const chipset_names
[] = {
96 "CastleRock (CLE266)",
99 "UniChrome (PM8x0/CN400)",
101 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
102 unsigned id
= vmesa
->viaScreen
->deviceID
;
104 offset
= driGetRendererString( buffer
,
105 chipset_names
[(id
> VIA_PM800
) ? 0 : id
],
107 return (GLubyte
*)buffer
;
117 * Calculate a width that satisfies the hardware's alignment requirements.
118 * On the Unichrome hardware, each scanline must be aligned to a multiple of
121 * \param width Minimum buffer width, in pixels.
123 * \returns A pixel width that meets the alignment requirements.
125 static __inline__
unsigned
126 buffer_align( unsigned width
)
128 return (width
+ 0x0f) & ~0x0f;
133 viaDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
135 /* Don't free() since we're contained in via_context struct. */
139 viaRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
140 GLenum internalFormat
, GLuint width
, GLuint height
)
144 rb
->InternalFormat
= internalFormat
;
150 viaInitRenderbuffer(struct via_renderbuffer
*vrb
, GLenum format
,
151 __DRIdrawablePrivate
*dPriv
)
153 const GLuint name
= 0;
154 struct gl_renderbuffer
*rb
= & vrb
->Base
;
157 _mesa_init_renderbuffer(rb
, name
);
159 /* Make sure we're using a null-valued GetPointer routine */
160 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
162 rb
->InternalFormat
= format
;
164 if (format
== GL_RGBA
) {
166 rb
->_BaseFormat
= GL_RGBA
;
167 rb
->DataType
= GL_UNSIGNED_BYTE
;
169 else if (format
== GL_DEPTH_COMPONENT16
) {
171 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
172 /* we always Get/Put 32-bit Z values */
173 rb
->DataType
= GL_UNSIGNED_INT
;
175 else if (format
== GL_DEPTH_COMPONENT24
) {
177 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
178 /* we always Get/Put 32-bit Z values */
179 rb
->DataType
= GL_UNSIGNED_INT
;
183 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
184 rb
->_BaseFormat
= GL_STENCIL_INDEX
;
185 rb
->DataType
= GL_UNSIGNED_BYTE
;
188 rb
->Delete
= viaDeleteRenderbuffer
;
189 rb
->AllocStorage
= viaRenderbufferStorage
;
194 * Calculate the framebuffer parameters for all buffers (front, back, depth,
195 * and stencil) associated with the specified context.
198 * This function also calls \c AllocateBuffer to actually allocate the
204 calculate_buffer_parameters(struct via_context
*vmesa
,
205 struct gl_framebuffer
*fb
,
206 __DRIdrawablePrivate
*dPriv
)
208 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
209 const unsigned extra
= 32;
213 /* Normally, the renderbuffer would be added to the framebuffer just once
214 * when the framebuffer was created. The VIA driver is a bit funny
215 * though in that the front/back/depth renderbuffers are in the per-context
217 * That should be fixed someday.
220 if (!vmesa
->front
.Base
.InternalFormat
) {
221 /* do one-time init for the renderbuffers */
222 viaInitRenderbuffer(&vmesa
->front
, GL_RGBA
, dPriv
);
223 viaSetSpanFunctions(&vmesa
->front
, &fb
->Visual
);
224 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &vmesa
->front
.Base
);
226 if (fb
->Visual
.doubleBufferMode
) {
227 viaInitRenderbuffer(&vmesa
->back
, GL_RGBA
, dPriv
);
228 viaSetSpanFunctions(&vmesa
->back
, &fb
->Visual
);
229 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &vmesa
->back
.Base
);
232 if (vmesa
->glCtx
->Visual
.depthBits
> 0) {
233 viaInitRenderbuffer(&vmesa
->depth
,
234 (vmesa
->glCtx
->Visual
.depthBits
== 16
235 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
),
237 viaSetSpanFunctions(&vmesa
->depth
, &fb
->Visual
);
238 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &vmesa
->depth
.Base
);
241 if (vmesa
->glCtx
->Visual
.stencilBits
> 0) {
242 viaInitRenderbuffer(&vmesa
->stencil
, GL_STENCIL_INDEX8_EXT
,
244 viaSetSpanFunctions(&vmesa
->stencil
, &fb
->Visual
);
245 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &vmesa
->stencil
.Base
);
249 assert(vmesa
->front
.Base
.InternalFormat
);
250 assert(vmesa
->front
.Base
.AllocStorage
);
251 if (fb
->Visual
.doubleBufferMode
) {
252 assert(vmesa
->back
.Base
.AllocStorage
);
254 if (fb
->Visual
.depthBits
) {
255 assert(vmesa
->depth
.Base
.AllocStorage
);
259 /* Allocate front-buffer */
260 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
261 w
= vmesa
->driDrawable
->w
;
262 h
= vmesa
->driDrawable
->h
;
264 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
265 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
266 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
268 if (vmesa
->front
.map
)
269 via_free_draw_buffer(vmesa
, &vmesa
->front
);
270 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->front
))
274 w
= vmesa
->viaScreen
->width
;
275 h
= vmesa
->viaScreen
->height
;
277 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
278 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
279 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
280 if (getenv("ALTERNATE_SCREEN"))
281 vmesa
->front
.offset
= vmesa
->front
.size
;
283 vmesa
->front
.offset
= 0;
284 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
288 /* Allocate back-buffer */
289 if (vmesa
->hasBack
) {
290 vmesa
->back
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
291 vmesa
->back
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << shift
);
292 vmesa
->back
.pitch
+= extra
;
293 vmesa
->back
.pitch
= MIN2(vmesa
->back
.pitch
, vmesa
->front
.pitch
);
294 vmesa
->back
.size
= vmesa
->back
.pitch
* vmesa
->driDrawable
->h
;
296 via_free_draw_buffer(vmesa
, &vmesa
->back
);
297 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->back
))
302 via_free_draw_buffer(vmesa
, &vmesa
->back
);
303 (void) memset( &vmesa
->back
, 0, sizeof( vmesa
->back
) );
307 /* Allocate depth-buffer */
308 if ( vmesa
->hasStencil
|| vmesa
->hasDepth
) {
309 vmesa
->depth
.bpp
= vmesa
->depthBits
;
310 if (vmesa
->depth
.bpp
== 24)
311 vmesa
->depth
.bpp
= 32;
313 vmesa
->depth
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) *
314 (vmesa
->depth
.bpp
/8)) + extra
;
315 vmesa
->depth
.size
= vmesa
->depth
.pitch
* vmesa
->driDrawable
->h
;
317 if (vmesa
->depth
.map
)
318 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
319 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->depth
)) {
324 if (vmesa
->depth
.map
)
325 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
326 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
329 /* stencil buffer is same as depth buffer */
330 vmesa
->stencil
.handle
= vmesa
->depth
.handle
;
331 vmesa
->stencil
.size
= vmesa
->depth
.size
;
332 vmesa
->stencil
.offset
= vmesa
->depth
.offset
;
333 vmesa
->stencil
.index
= vmesa
->depth
.index
;
334 vmesa
->stencil
.pitch
= vmesa
->depth
.pitch
;
335 vmesa
->stencil
.bpp
= vmesa
->depth
.bpp
;
336 vmesa
->stencil
.map
= vmesa
->depth
.map
;
337 vmesa
->stencil
.orig
= vmesa
->depth
.orig
;
338 vmesa
->stencil
.origMap
= vmesa
->depth
.origMap
;
340 if( vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
341 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
342 vmesa
->doPageFlip
= vmesa
->allowPageFlip
;
343 if (vmesa
->hasBack
) {
344 assert(vmesa
->back
.pitch
== vmesa
->front
.pitch
);
348 vmesa
->doPageFlip
= GL_FALSE
;
354 void viaReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
355 GLuint width
, GLuint height
)
357 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
359 calculate_buffer_parameters(vmesa
, drawbuffer
, vmesa
->driDrawable
);
361 _mesa_resize_framebuffer(ctx
, drawbuffer
, width
, height
);
364 /* Extension strings exported by the Unichrome driver.
366 const struct dri_extension card_extensions
[] =
368 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
369 { "GL_ARB_multitexture", NULL
},
370 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
371 { "GL_ARB_texture_env_add", NULL
},
372 { "GL_ARB_texture_env_combine", NULL
},
373 /* { "GL_ARB_texture_env_dot3", NULL }, */
374 { "GL_ARB_texture_mirrored_repeat", NULL
},
375 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
376 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
377 { "GL_EXT_stencil_wrap", NULL
},
378 { "GL_EXT_texture_env_combine", NULL
},
379 /* { "GL_EXT_texture_env_dot3", NULL }, */
380 { "GL_EXT_texture_lod_bias", NULL
},
381 { "GL_NV_blend_square", NULL
},
385 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
386 extern const struct tnl_pipeline_stage _via_render_stage
;
388 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
389 &_tnl_vertex_transform_stage
,
390 &_tnl_normal_transform_stage
,
391 &_tnl_lighting_stage
,
392 &_tnl_fog_coordinate_stage
,
394 &_tnl_texture_transform_stage
,
395 /* REMOVE: point attenuation stage */
397 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
404 static const struct dri_debug_control debug_control
[] =
406 { "fall", DEBUG_FALLBACKS
},
407 { "tex", DEBUG_TEXTURE
},
408 { "ioctl", DEBUG_IOCTL
},
409 { "prim", DEBUG_PRIMS
},
410 { "vert", DEBUG_VERTS
},
411 { "state", DEBUG_STATE
},
412 { "verb", DEBUG_VERBOSE
},
413 { "dri", DEBUG_DRI
},
414 { "dma", DEBUG_DMA
},
415 { "san", DEBUG_SANITY
},
416 { "sync", DEBUG_SYNC
},
417 { "sleep", DEBUG_SLEEP
},
418 { "pix", DEBUG_PIXEL
},
425 AllocateDmaBuffer(struct via_context
*vmesa
)
428 via_free_dma_buffer(vmesa
);
430 if (!via_alloc_dma_buffer(vmesa
))
434 vmesa
->dmaCliprectAddr
= ~0;
439 FreeBuffer(struct via_context
*vmesa
)
441 if (vmesa
->front
.map
&& vmesa
->drawType
== GLX_PBUFFER_BIT
)
442 via_free_draw_buffer(vmesa
, &vmesa
->front
);
445 via_free_draw_buffer(vmesa
, &vmesa
->back
);
447 if (vmesa
->depth
.map
)
448 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
450 if (vmesa
->breadcrumb
.map
)
451 via_free_draw_buffer(vmesa
, &vmesa
->breadcrumb
);
454 via_free_dma_buffer(vmesa
);
459 viaCreateContext(const __GLcontextModes
*visual
,
460 __DRIcontextPrivate
*driContextPriv
,
461 void *sharedContextPrivate
)
463 GLcontext
*ctx
, *shareCtx
;
464 struct via_context
*vmesa
;
465 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
466 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
467 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
468 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
469 struct dd_function_table functions
;
471 /* Allocate via context */
472 vmesa
= (struct via_context
*) CALLOC_STRUCT(via_context
);
477 /* Parse configuration files.
479 driParseConfigFiles (&vmesa
->optionCache
, &viaScreen
->optionCache
,
480 sPriv
->myNum
, "unichrome");
482 /* pick back buffer */
483 vmesa
->hasBack
= visual
->doubleBufferMode
;
485 switch(visual
->depthBits
) {
487 vmesa
->hasDepth
= GL_FALSE
;
488 vmesa
->depthBits
= 0;
489 vmesa
->depth_max
= 1.0;
492 vmesa
->hasDepth
= GL_TRUE
;
493 vmesa
->depthBits
= visual
->depthBits
;
494 vmesa
->have_hw_stencil
= GL_FALSE
;
495 vmesa
->depth_max
= (GLfloat
)0xffff;
496 vmesa
->depth_clear_mask
= 0xf << 28;
497 vmesa
->ClearDepth
= 0xffff;
498 vmesa
->polygon_offset_scale
= 1.0 / vmesa
->depth_max
;
501 vmesa
->hasDepth
= GL_TRUE
;
502 vmesa
->depthBits
= visual
->depthBits
;
503 vmesa
->depth_max
= (GLfloat
) 0xffffff;
504 vmesa
->depth_clear_mask
= 0xe << 28;
505 vmesa
->ClearDepth
= 0xffffff00;
507 assert(visual
->haveStencilBuffer
);
508 assert(visual
->stencilBits
== 8);
510 vmesa
->have_hw_stencil
= GL_TRUE
;
511 vmesa
->stencilBits
= visual
->stencilBits
;
512 vmesa
->stencil_clear_mask
= 0x1 << 28;
513 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
516 vmesa
->hasDepth
= GL_TRUE
;
517 vmesa
->depthBits
= visual
->depthBits
;
518 assert(!visual
->haveStencilBuffer
);
519 vmesa
->have_hw_stencil
= GL_FALSE
;
520 vmesa
->depth_max
= (GLfloat
)0xffffffff;
521 vmesa
->depth_clear_mask
= 0xf << 28;
522 vmesa
->ClearDepth
= 0xffffffff;
523 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
530 make_empty_list(&vmesa
->freed_tex_buffers
);
531 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]);
532 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]);
533 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]);
535 _mesa_init_driver_functions(&functions
);
536 viaInitTextureFuncs(&functions
);
538 /* Allocate the Mesa context */
539 if (sharedContextPrivate
)
540 shareCtx
= ((struct via_context
*) sharedContextPrivate
)->glCtx
;
544 vmesa
->glCtx
= _mesa_create_context(visual
, shareCtx
, &functions
,
547 vmesa
->shareCtx
= shareCtx
;
553 driContextPriv
->driverPrivate
= vmesa
;
557 if (driQueryOptionb(&vmesa
->optionCache
, "excess_mipmap"))
558 ctx
->Const
.MaxTextureLevels
= 11;
560 ctx
->Const
.MaxTextureLevels
= 10;
562 ctx
->Const
.MaxTextureUnits
= 2;
563 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
564 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
566 ctx
->Const
.MinLineWidth
= 1.0;
567 ctx
->Const
.MinLineWidthAA
= 1.0;
568 ctx
->Const
.MaxLineWidth
= 1.0;
569 ctx
->Const
.MaxLineWidthAA
= 1.0;
570 ctx
->Const
.LineWidthGranularity
= 1.0;
572 ctx
->Const
.MinPointSize
= 1.0;
573 ctx
->Const
.MinPointSizeAA
= 1.0;
574 ctx
->Const
.MaxPointSize
= 1.0;
575 ctx
->Const
.MaxPointSizeAA
= 1.0;
576 ctx
->Const
.PointSizeGranularity
= 1.0;
578 ctx
->Driver
.GetString
= viaGetString
;
580 ctx
->DriverCtx
= (void *)vmesa
;
583 /* Initialize the software rasterizer and helper modules.
585 _swrast_CreateContext(ctx
);
586 _vbo_CreateContext(ctx
);
587 _tnl_CreateContext(ctx
);
588 _swsetup_CreateContext(ctx
);
590 /* Install the customized pipeline:
592 _tnl_destroy_pipeline(ctx
);
593 _tnl_install_pipeline(ctx
, via_pipeline
);
595 /* Configure swrast and T&L to match hardware characteristics:
597 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
598 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
599 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
600 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
602 /* vmesa->display = dpy; */
603 vmesa
->display
= sPriv
->display
;
605 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
606 vmesa
->driFd
= sPriv
->fd
;
607 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
609 vmesa
->viaScreen
= viaScreen
;
610 vmesa
->driScreen
= sPriv
;
611 vmesa
->sarea
= saPriv
;
613 vmesa
->renderIndex
= ~0;
614 vmesa
->setupIndex
= ~0;
615 vmesa
->hwPrimitive
= GL_POLYGON
+1;
617 /* KW: Hardwire this. Was previously set bogusly in
618 * viaCreateBuffer. Needs work before PBUFFER can be used:
620 vmesa
->drawType
= GLX_WINDOW_BIT
;
623 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
625 /* Do this early, before VIA_FLUSH_DMA can be called:
627 if (!AllocateDmaBuffer(vmesa
)) {
628 fprintf(stderr
,"AllocateDmaBuffer fail\n");
634 /* Allocate a small piece of fb memory for synchronization:
636 vmesa
->breadcrumb
.bpp
= 32;
637 vmesa
->breadcrumb
.pitch
= buffer_align( 64 ) << 2;
638 vmesa
->breadcrumb
.size
= vmesa
->breadcrumb
.pitch
;
640 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->breadcrumb
)) {
641 fprintf(stderr
,"AllocateDmaBuffer fail\n");
647 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
648 viaInitStateFuncs(ctx
);
649 viaInitTriFuncs(ctx
);
650 viaInitSpanFuncs(ctx
);
651 viaInitIoctlFuncs(ctx
);
654 if (getenv("VIA_DEBUG"))
655 VIA_DEBUG
= driParseDebugString( getenv( "VIA_DEBUG" ),
658 if (getenv("VIA_NO_RAST") ||
659 driQueryOptionb(&vmesa
->optionCache
, "no_rast"))
660 FALLBACK(vmesa
, VIA_FALLBACK_USER_DISABLE
, 1);
662 vmesa
->vblank_flags
=
663 vmesa
->viaScreen
->irqEnabled
?
664 driGetDefaultVBlankFlags(&vmesa
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
666 if (getenv("VIA_PAGEFLIP"))
667 vmesa
->allowPageFlip
= 1;
669 (*dri_interface
->getUST
)( &vmesa
->swap_ust
);
672 vmesa
->regMMIOBase
= (GLuint
*)((unsigned long)viaScreen
->reg
);
673 vmesa
->pnGEMode
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x4);
674 vmesa
->regEngineStatus
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x400);
675 vmesa
->regTranSet
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x43C);
676 vmesa
->regTranSpace
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x440);
677 vmesa
->agpBase
= viaScreen
->agpBase
;
684 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
686 GET_CURRENT_CONTEXT(ctx
);
687 struct via_context
*vmesa
=
688 (struct via_context
*)driContextPriv
->driverPrivate
;
689 struct via_context
*current
= ctx
? VIA_CONTEXT(ctx
) : NULL
;
690 assert(vmesa
); /* should never be null */
692 /* check if we're deleting the currently bound context */
693 if (vmesa
== current
) {
694 VIA_FLUSH_DMA(vmesa
);
695 _mesa_make_current(NULL
, NULL
, NULL
);
699 viaWaitIdle(vmesa
, GL_FALSE
);
700 if (vmesa
->doPageFlip
) {
701 LOCK_HARDWARE(vmesa
);
702 if (vmesa
->pfCurrentOffset
!= 0) {
703 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
704 viaResetPageFlippingLocked(vmesa
);
706 UNLOCK_HARDWARE(vmesa
);
709 _swsetup_DestroyContext(vmesa
->glCtx
);
710 _tnl_DestroyContext(vmesa
->glCtx
);
711 _vbo_DestroyContext(vmesa
->glCtx
);
712 _swrast_DestroyContext(vmesa
->glCtx
);
713 /* free the Mesa context */
714 _mesa_destroy_context(vmesa
->glCtx
);
715 /* release our data */
718 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]));
719 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]));
720 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]));
721 assert (is_empty_list(&vmesa
->freed_tex_buffers
));
723 driDestroyOptionCache(&vmesa
->optionCache
);
730 void viaXMesaWindowMoved(struct via_context
*vmesa
)
732 __DRIdrawablePrivate
*const drawable
= vmesa
->driDrawable
;
733 __DRIdrawablePrivate
*const readable
= vmesa
->driReadable
;
734 struct via_renderbuffer
*const draw_buffer
=
735 (struct via_renderbuffer
*) drawable
->driverPrivate
;
736 struct via_renderbuffer
*const read_buffer
=
737 (struct via_renderbuffer
*) readable
->driverPrivate
;
738 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
743 switch (vmesa
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0]) {
744 case BUFFER_BIT_BACK_LEFT
:
745 if (drawable
->numBackClipRects
== 0) {
746 vmesa
->numClipRects
= drawable
->numClipRects
;
747 vmesa
->pClipRects
= drawable
->pClipRects
;
750 vmesa
->numClipRects
= drawable
->numBackClipRects
;
751 vmesa
->pClipRects
= drawable
->pBackClipRects
;
754 case BUFFER_BIT_FRONT_LEFT
:
755 vmesa
->numClipRects
= drawable
->numClipRects
;
756 vmesa
->pClipRects
= drawable
->pClipRects
;
759 vmesa
->numClipRects
= 0;
763 if ((draw_buffer
->drawW
!= drawable
->w
)
764 || (draw_buffer
->drawH
!= drawable
->h
)) {
765 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->DrawBuffer
,
769 draw_buffer
->drawXoff
= (GLuint
)(((drawable
->x
* bytePerPixel
) & 0x1f) /
771 draw_buffer
->drawX
= drawable
->x
- draw_buffer
->drawXoff
;
772 draw_buffer
->drawY
= drawable
->y
;
773 draw_buffer
->drawW
= drawable
->w
;
774 draw_buffer
->drawH
= drawable
->h
;
776 if (drawable
!= readable
) {
777 if ((read_buffer
->drawW
!= readable
->w
)
778 || (read_buffer
->drawH
!= readable
->h
)) {
779 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->ReadBuffer
,
783 read_buffer
->drawXoff
= (GLuint
)(((readable
->x
* bytePerPixel
) & 0x1f) /
785 read_buffer
->drawX
= readable
->x
- read_buffer
->drawXoff
;
786 read_buffer
->drawY
= readable
->y
;
787 read_buffer
->drawW
= readable
->w
;
788 read_buffer
->drawH
= readable
->h
;
791 vmesa
->front
.orig
= (vmesa
->front
.offset
+
792 draw_buffer
->drawY
* vmesa
->front
.pitch
+
793 draw_buffer
->drawX
* bytePerPixel
);
795 vmesa
->front
.origMap
= (vmesa
->front
.map
+
796 draw_buffer
->drawY
* vmesa
->front
.pitch
+
797 draw_buffer
->drawX
* bytePerPixel
);
799 vmesa
->back
.orig
= vmesa
->back
.offset
;
800 vmesa
->depth
.orig
= vmesa
->depth
.offset
;
801 vmesa
->back
.origMap
= vmesa
->back
.map
;
802 vmesa
->depth
.origMap
= vmesa
->depth
.map
;
804 viaCalcViewport(vmesa
->glCtx
);
808 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
814 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
815 __DRIdrawablePrivate
*driDrawPriv
,
816 __DRIdrawablePrivate
*driReadPriv
)
818 if (VIA_DEBUG
& DEBUG_DRI
) {
819 fprintf(stderr
, "driContextPriv = %016lx\n", (unsigned long)driContextPriv
);
820 fprintf(stderr
, "driDrawPriv = %016lx\n", (unsigned long)driDrawPriv
);
821 fprintf(stderr
, "driReadPriv = %016lx\n", (unsigned long)driReadPriv
);
824 if (driContextPriv
) {
825 struct via_context
*vmesa
=
826 (struct via_context
*)driContextPriv
->driverPrivate
;
827 GLcontext
*ctx
= vmesa
->glCtx
;
828 struct gl_framebuffer
*drawBuffer
, *readBuffer
;
830 drawBuffer
= (GLframebuffer
*)driDrawPriv
->driverPrivate
;
831 readBuffer
= (GLframebuffer
*)driReadPriv
->driverPrivate
;
833 if (vmesa
->driDrawable
!= driDrawPriv
) {
834 driDrawableInitVBlank(driDrawPriv
, vmesa
->vblank_flags
,
838 if ((vmesa
->driDrawable
!= driDrawPriv
)
839 || (vmesa
->driReadable
!= driReadPriv
)) {
840 vmesa
->driDrawable
= driDrawPriv
;
841 vmesa
->driReadable
= driReadPriv
;
843 if ((drawBuffer
->Width
!= driDrawPriv
->w
)
844 || (drawBuffer
->Height
!= driDrawPriv
->h
)) {
845 _mesa_resize_framebuffer(ctx
, drawBuffer
,
846 driDrawPriv
->w
, driDrawPriv
->h
);
847 drawBuffer
->Initialized
= GL_TRUE
;
850 if (!calculate_buffer_parameters(vmesa
, drawBuffer
, driDrawPriv
)) {
854 if (driDrawPriv
!= driReadPriv
) {
855 if ((readBuffer
->Width
!= driReadPriv
->w
)
856 || (readBuffer
->Height
!= driReadPriv
->h
)) {
857 _mesa_resize_framebuffer(ctx
, readBuffer
,
858 driReadPriv
->w
, driReadPriv
->h
);
859 readBuffer
->Initialized
= GL_TRUE
;
862 if (!calculate_buffer_parameters(vmesa
, readBuffer
, driReadPriv
)) {
868 _mesa_make_current(vmesa
->glCtx
, drawBuffer
, readBuffer
);
870 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );
872 viaXMesaWindowMoved(vmesa
);
873 ctx
->Driver
.Scissor(vmesa
->glCtx
,
874 vmesa
->glCtx
->Scissor
.X
,
875 vmesa
->glCtx
->Scissor
.Y
,
876 vmesa
->glCtx
->Scissor
.Width
,
877 vmesa
->glCtx
->Scissor
.Height
);
880 _mesa_make_current(NULL
, NULL
, NULL
);
886 void viaGetLock(struct via_context
*vmesa
, GLuint flags
)
888 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
889 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
891 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
893 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
894 if (dPriv
!= vmesa
->driReadable
) {
895 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, vmesa
->driReadable
);
898 if (vmesa
->sarea
->ctxOwner
!= vmesa
->hHWContext
) {
899 vmesa
->sarea
->ctxOwner
= vmesa
->hHWContext
;
900 vmesa
->newEmitState
= ~0;
903 if (vmesa
->lastStamp
!= dPriv
->lastStamp
) {
904 viaXMesaWindowMoved(vmesa
);
905 driUpdateFramebufferSize(vmesa
->glCtx
, dPriv
);
906 vmesa
->newEmitState
= ~0;
907 vmesa
->lastStamp
= dPriv
->lastStamp
;
910 if (vmesa
->doPageFlip
&&
911 vmesa
->pfCurrentOffset
!= vmesa
->sarea
->pfCurrentOffset
) {
912 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
913 viaResetPageFlippingLocked(vmesa
);
919 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
921 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
924 dPriv
->driContextPriv
&&
925 dPriv
->driContextPriv
->driverPrivate
) {
926 struct via_context
*vmesa
=
927 (struct via_context
*)dPriv
->driContextPriv
->driverPrivate
;
928 GLcontext
*ctx
= vmesa
->glCtx
;
930 _mesa_notifySwapBuffers(ctx
);
932 if (ctx
->Visual
.doubleBufferMode
) {
933 if (vmesa
->doPageFlip
) {
937 viaCopyBuffer(dPriv
);
941 VIA_FLUSH_DMA(vmesa
);
944 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");