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_ARB_vertex_buffer_object
68 #define need_GL_EXT_fog_coord
69 #define need_GL_EXT_secondary_color
70 #include "extension_helper.h"
72 #define DRIVER_DATE "20060710"
80 * Return various strings for \c glGetString.
84 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
86 static char buffer
[128];
92 return (GLubyte
*)"VIA Technology";
95 static const char * const chipset_names
[] = {
97 "CastleRock (CLE266)",
100 "UniChrome (PM8x0/CN400)",
102 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
103 unsigned id
= vmesa
->viaScreen
->deviceID
;
105 offset
= driGetRendererString( buffer
,
106 chipset_names
[(id
> VIA_PM800
) ? 0 : id
],
108 return (GLubyte
*)buffer
;
118 * Calculate a width that satisfies the hardware's alignment requirements.
119 * On the Unichrome hardware, each scanline must be aligned to a multiple of
122 * \param width Minimum buffer width, in pixels.
124 * \returns A pixel width that meets the alignment requirements.
126 static INLINE
unsigned
127 buffer_align( unsigned width
)
129 return (width
+ 0x0f) & ~0x0f;
134 viaDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
136 /* Don't free() since we're contained in via_context struct. */
140 viaRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
141 GLenum internalFormat
, GLuint width
, GLuint height
)
145 rb
->InternalFormat
= internalFormat
;
151 viaInitRenderbuffer(struct via_renderbuffer
*vrb
, GLenum format
,
152 __DRIdrawablePrivate
*dPriv
)
154 const GLuint name
= 0;
155 struct gl_renderbuffer
*rb
= & vrb
->Base
;
158 _mesa_init_renderbuffer(rb
, name
);
160 /* Make sure we're using a null-valued GetPointer routine */
161 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
163 rb
->InternalFormat
= format
;
165 if (format
== GL_RGBA
) {
167 rb
->_BaseFormat
= GL_RGBA
;
168 rb
->DataType
= GL_UNSIGNED_BYTE
;
170 else if (format
== GL_DEPTH_COMPONENT16
) {
172 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
173 /* we always Get/Put 32-bit Z values */
174 rb
->DataType
= GL_UNSIGNED_INT
;
176 else if (format
== GL_DEPTH_COMPONENT24
) {
178 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
179 /* we always Get/Put 32-bit Z values */
180 rb
->DataType
= GL_UNSIGNED_INT
;
184 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
185 rb
->_BaseFormat
= GL_STENCIL_INDEX
;
186 rb
->DataType
= GL_UNSIGNED_BYTE
;
189 rb
->Delete
= viaDeleteRenderbuffer
;
190 rb
->AllocStorage
= viaRenderbufferStorage
;
195 * Calculate the framebuffer parameters for all buffers (front, back, depth,
196 * and stencil) associated with the specified context.
199 * This function also calls \c AllocateBuffer to actually allocate the
205 calculate_buffer_parameters(struct via_context
*vmesa
,
206 struct gl_framebuffer
*fb
,
207 __DRIdrawablePrivate
*dPriv
)
209 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
210 const unsigned extra
= 32;
214 /* Normally, the renderbuffer would be added to the framebuffer just once
215 * when the framebuffer was created. The VIA driver is a bit funny
216 * though in that the front/back/depth renderbuffers are in the per-context
218 * That should be fixed someday.
221 if (!vmesa
->front
.Base
.InternalFormat
) {
222 /* do one-time init for the renderbuffers */
223 viaInitRenderbuffer(&vmesa
->front
, GL_RGBA
, dPriv
);
224 viaSetSpanFunctions(&vmesa
->front
, &fb
->Visual
);
225 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &vmesa
->front
.Base
);
227 if (fb
->Visual
.doubleBufferMode
) {
228 viaInitRenderbuffer(&vmesa
->back
, GL_RGBA
, dPriv
);
229 viaSetSpanFunctions(&vmesa
->back
, &fb
->Visual
);
230 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &vmesa
->back
.Base
);
233 if (vmesa
->glCtx
->Visual
.depthBits
> 0) {
234 viaInitRenderbuffer(&vmesa
->depth
,
235 (vmesa
->glCtx
->Visual
.depthBits
== 16
236 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
),
238 viaSetSpanFunctions(&vmesa
->depth
, &fb
->Visual
);
239 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &vmesa
->depth
.Base
);
242 if (vmesa
->glCtx
->Visual
.stencilBits
> 0) {
243 viaInitRenderbuffer(&vmesa
->stencil
, GL_STENCIL_INDEX8_EXT
,
245 viaSetSpanFunctions(&vmesa
->stencil
, &fb
->Visual
);
246 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &vmesa
->stencil
.Base
);
250 assert(vmesa
->front
.Base
.InternalFormat
);
251 assert(vmesa
->front
.Base
.AllocStorage
);
252 if (fb
->Visual
.doubleBufferMode
) {
253 assert(vmesa
->back
.Base
.AllocStorage
);
255 if (fb
->Visual
.depthBits
) {
256 assert(vmesa
->depth
.Base
.AllocStorage
);
260 /* Allocate front-buffer */
261 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
262 w
= vmesa
->driDrawable
->w
;
263 h
= vmesa
->driDrawable
->h
;
265 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
266 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
267 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
269 if (vmesa
->front
.map
)
270 via_free_draw_buffer(vmesa
, &vmesa
->front
);
271 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->front
))
275 w
= vmesa
->viaScreen
->width
;
276 h
= vmesa
->viaScreen
->height
;
278 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
279 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
280 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
281 if (getenv("ALTERNATE_SCREEN"))
282 vmesa
->front
.offset
= vmesa
->front
.size
;
284 vmesa
->front
.offset
= 0;
285 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
289 /* Allocate back-buffer */
290 if (vmesa
->hasBack
) {
291 vmesa
->back
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
292 vmesa
->back
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << shift
);
293 vmesa
->back
.pitch
+= extra
;
294 vmesa
->back
.pitch
= MIN2(vmesa
->back
.pitch
, vmesa
->front
.pitch
);
295 vmesa
->back
.size
= vmesa
->back
.pitch
* vmesa
->driDrawable
->h
;
297 via_free_draw_buffer(vmesa
, &vmesa
->back
);
298 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->back
))
303 via_free_draw_buffer(vmesa
, &vmesa
->back
);
304 (void) memset( &vmesa
->back
, 0, sizeof( vmesa
->back
) );
308 /* Allocate depth-buffer */
309 if ( vmesa
->hasStencil
|| vmesa
->hasDepth
) {
310 vmesa
->depth
.bpp
= vmesa
->depthBits
;
311 if (vmesa
->depth
.bpp
== 24)
312 vmesa
->depth
.bpp
= 32;
314 vmesa
->depth
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) *
315 (vmesa
->depth
.bpp
/8)) + extra
;
316 vmesa
->depth
.size
= vmesa
->depth
.pitch
* vmesa
->driDrawable
->h
;
318 if (vmesa
->depth
.map
)
319 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
320 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->depth
)) {
325 if (vmesa
->depth
.map
)
326 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
327 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
330 /* stencil buffer is same as depth buffer */
331 vmesa
->stencil
.handle
= vmesa
->depth
.handle
;
332 vmesa
->stencil
.size
= vmesa
->depth
.size
;
333 vmesa
->stencil
.offset
= vmesa
->depth
.offset
;
334 vmesa
->stencil
.index
= vmesa
->depth
.index
;
335 vmesa
->stencil
.pitch
= vmesa
->depth
.pitch
;
336 vmesa
->stencil
.bpp
= vmesa
->depth
.bpp
;
337 vmesa
->stencil
.map
= vmesa
->depth
.map
;
338 vmesa
->stencil
.orig
= vmesa
->depth
.orig
;
339 vmesa
->stencil
.origMap
= vmesa
->depth
.origMap
;
341 if( vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
342 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
343 vmesa
->doPageFlip
= vmesa
->allowPageFlip
;
344 if (vmesa
->hasBack
) {
345 assert(vmesa
->back
.pitch
== vmesa
->front
.pitch
);
349 vmesa
->doPageFlip
= GL_FALSE
;
355 void viaReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
356 GLuint width
, GLuint height
)
358 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
360 calculate_buffer_parameters(vmesa
, drawbuffer
, vmesa
->driDrawable
);
362 _mesa_resize_framebuffer(ctx
, drawbuffer
, width
, height
);
365 /* Extension strings exported by the Unichrome driver.
367 const struct dri_extension card_extensions
[] =
369 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
370 { "GL_ARB_multitexture", NULL
},
371 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
372 { "GL_ARB_texture_env_add", NULL
},
373 { "GL_ARB_texture_env_combine", NULL
},
374 /* { "GL_ARB_texture_env_dot3", NULL }, */
375 { "GL_ARB_texture_mirrored_repeat", NULL
},
376 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
377 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
378 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
379 { "GL_EXT_stencil_wrap", NULL
},
380 { "GL_EXT_texture_env_combine", NULL
},
381 /* { "GL_EXT_texture_env_dot3", NULL }, */
382 { "GL_EXT_texture_lod_bias", NULL
},
383 { "GL_NV_blend_square", NULL
},
387 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
388 extern const struct tnl_pipeline_stage _via_render_stage
;
390 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
391 &_tnl_vertex_transform_stage
,
392 &_tnl_normal_transform_stage
,
393 &_tnl_lighting_stage
,
394 &_tnl_fog_coordinate_stage
,
396 &_tnl_texture_transform_stage
,
397 /* REMOVE: point attenuation stage */
399 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
406 static const struct dri_debug_control debug_control
[] =
408 { "fall", DEBUG_FALLBACKS
},
409 { "tex", DEBUG_TEXTURE
},
410 { "ioctl", DEBUG_IOCTL
},
411 { "prim", DEBUG_PRIMS
},
412 { "vert", DEBUG_VERTS
},
413 { "state", DEBUG_STATE
},
414 { "verb", DEBUG_VERBOSE
},
415 { "dri", DEBUG_DRI
},
416 { "dma", DEBUG_DMA
},
417 { "san", DEBUG_SANITY
},
418 { "sync", DEBUG_SYNC
},
419 { "sleep", DEBUG_SLEEP
},
420 { "pix", DEBUG_PIXEL
},
427 AllocateDmaBuffer(struct via_context
*vmesa
)
430 via_free_dma_buffer(vmesa
);
432 if (!via_alloc_dma_buffer(vmesa
))
436 vmesa
->dmaCliprectAddr
= ~0;
441 FreeBuffer(struct via_context
*vmesa
)
443 if (vmesa
->front
.map
&& vmesa
->drawType
== GLX_PBUFFER_BIT
)
444 via_free_draw_buffer(vmesa
, &vmesa
->front
);
447 via_free_draw_buffer(vmesa
, &vmesa
->back
);
449 if (vmesa
->depth
.map
)
450 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
452 if (vmesa
->breadcrumb
.map
)
453 via_free_draw_buffer(vmesa
, &vmesa
->breadcrumb
);
456 via_free_dma_buffer(vmesa
);
461 viaCreateContext(const __GLcontextModes
*visual
,
462 __DRIcontextPrivate
*driContextPriv
,
463 void *sharedContextPrivate
)
465 GLcontext
*ctx
, *shareCtx
;
466 struct via_context
*vmesa
;
467 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
468 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
469 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
470 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
471 struct dd_function_table functions
;
473 /* Allocate via context */
474 vmesa
= (struct via_context
*) CALLOC_STRUCT(via_context
);
479 /* Parse configuration files.
481 driParseConfigFiles (&vmesa
->optionCache
, &viaScreen
->optionCache
,
482 sPriv
->myNum
, "unichrome");
484 /* pick back buffer */
485 vmesa
->hasBack
= visual
->doubleBufferMode
;
487 switch(visual
->depthBits
) {
489 vmesa
->hasDepth
= GL_FALSE
;
490 vmesa
->depthBits
= 0;
491 vmesa
->depth_max
= 1.0;
494 vmesa
->hasDepth
= GL_TRUE
;
495 vmesa
->depthBits
= visual
->depthBits
;
496 vmesa
->have_hw_stencil
= GL_FALSE
;
497 vmesa
->depth_max
= (GLfloat
)0xffff;
498 vmesa
->depth_clear_mask
= 0xf << 28;
499 vmesa
->ClearDepth
= 0xffff;
500 vmesa
->polygon_offset_scale
= 1.0 / vmesa
->depth_max
;
503 vmesa
->hasDepth
= GL_TRUE
;
504 vmesa
->depthBits
= visual
->depthBits
;
505 vmesa
->depth_max
= (GLfloat
) 0xffffff;
506 vmesa
->depth_clear_mask
= 0xe << 28;
507 vmesa
->ClearDepth
= 0xffffff00;
509 assert(visual
->haveStencilBuffer
);
510 assert(visual
->stencilBits
== 8);
512 vmesa
->have_hw_stencil
= GL_TRUE
;
513 vmesa
->stencilBits
= visual
->stencilBits
;
514 vmesa
->stencil_clear_mask
= 0x1 << 28;
515 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
518 vmesa
->hasDepth
= GL_TRUE
;
519 vmesa
->depthBits
= visual
->depthBits
;
520 assert(!visual
->haveStencilBuffer
);
521 vmesa
->have_hw_stencil
= GL_FALSE
;
522 vmesa
->depth_max
= (GLfloat
)0xffffffff;
523 vmesa
->depth_clear_mask
= 0xf << 28;
524 vmesa
->ClearDepth
= 0xffffffff;
525 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
532 make_empty_list(&vmesa
->freed_tex_buffers
);
533 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]);
534 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]);
535 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]);
537 _mesa_init_driver_functions(&functions
);
538 viaInitTextureFuncs(&functions
);
540 /* Allocate the Mesa context */
541 if (sharedContextPrivate
)
542 shareCtx
= ((struct via_context
*) sharedContextPrivate
)->glCtx
;
546 vmesa
->glCtx
= _mesa_create_context(visual
, shareCtx
, &functions
,
549 vmesa
->shareCtx
= shareCtx
;
555 driContextPriv
->driverPrivate
= vmesa
;
559 if (driQueryOptionb(&vmesa
->optionCache
, "excess_mipmap"))
560 ctx
->Const
.MaxTextureLevels
= 11;
562 ctx
->Const
.MaxTextureLevels
= 10;
564 ctx
->Const
.MaxTextureUnits
= 2;
565 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
566 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
568 ctx
->Const
.MinLineWidth
= 1.0;
569 ctx
->Const
.MinLineWidthAA
= 1.0;
570 ctx
->Const
.MaxLineWidth
= 1.0;
571 ctx
->Const
.MaxLineWidthAA
= 1.0;
572 ctx
->Const
.LineWidthGranularity
= 1.0;
574 ctx
->Const
.MinPointSize
= 1.0;
575 ctx
->Const
.MinPointSizeAA
= 1.0;
576 ctx
->Const
.MaxPointSize
= 1.0;
577 ctx
->Const
.MaxPointSizeAA
= 1.0;
578 ctx
->Const
.PointSizeGranularity
= 1.0;
580 ctx
->Driver
.GetString
= viaGetString
;
582 ctx
->DriverCtx
= (void *)vmesa
;
585 /* Initialize the software rasterizer and helper modules.
587 _swrast_CreateContext(ctx
);
588 _vbo_CreateContext(ctx
);
589 _tnl_CreateContext(ctx
);
590 _swsetup_CreateContext(ctx
);
592 /* Install the customized pipeline:
594 _tnl_destroy_pipeline(ctx
);
595 _tnl_install_pipeline(ctx
, via_pipeline
);
597 /* Configure swrast and T&L to match hardware characteristics:
599 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
600 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
601 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
602 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
604 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
605 vmesa
->driFd
= sPriv
->fd
;
606 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
608 vmesa
->viaScreen
= viaScreen
;
609 vmesa
->driScreen
= sPriv
;
610 vmesa
->sarea
= saPriv
;
612 vmesa
->renderIndex
= ~0;
613 vmesa
->setupIndex
= ~0;
614 vmesa
->hwPrimitive
= GL_POLYGON
+1;
616 /* KW: Hardwire this. Was previously set bogusly in
617 * viaCreateBuffer. Needs work before PBUFFER can be used:
619 vmesa
->drawType
= GLX_WINDOW_BIT
;
622 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
624 /* Do this early, before VIA_FLUSH_DMA can be called:
626 if (!AllocateDmaBuffer(vmesa
)) {
627 fprintf(stderr
,"AllocateDmaBuffer fail\n");
633 /* Allocate a small piece of fb memory for synchronization:
635 vmesa
->breadcrumb
.bpp
= 32;
636 vmesa
->breadcrumb
.pitch
= buffer_align( 64 ) << 2;
637 vmesa
->breadcrumb
.size
= vmesa
->breadcrumb
.pitch
;
639 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->breadcrumb
)) {
640 fprintf(stderr
,"AllocateDmaBuffer fail\n");
646 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
647 viaInitStateFuncs(ctx
);
648 viaInitTriFuncs(ctx
);
649 viaInitSpanFuncs(ctx
);
650 viaInitIoctlFuncs(ctx
);
653 if (getenv("VIA_DEBUG"))
654 VIA_DEBUG
= driParseDebugString( getenv( "VIA_DEBUG" ),
657 if (getenv("VIA_NO_RAST") ||
658 driQueryOptionb(&vmesa
->optionCache
, "no_rast"))
659 FALLBACK(vmesa
, VIA_FALLBACK_USER_DISABLE
, 1);
661 if (getenv("VIA_PAGEFLIP"))
662 vmesa
->allowPageFlip
= 1;
664 (*sPriv
->systemTime
->getUST
)( &vmesa
->swap_ust
);
667 vmesa
->regMMIOBase
= (GLuint
*)((unsigned long)viaScreen
->reg
);
668 vmesa
->pnGEMode
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x4);
669 vmesa
->regEngineStatus
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x400);
670 vmesa
->regTranSet
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x43C);
671 vmesa
->regTranSpace
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x440);
672 vmesa
->agpBase
= viaScreen
->agpBase
;
679 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
681 GET_CURRENT_CONTEXT(ctx
);
682 struct via_context
*vmesa
=
683 (struct via_context
*)driContextPriv
->driverPrivate
;
684 struct via_context
*current
= ctx
? VIA_CONTEXT(ctx
) : NULL
;
686 assert(vmesa
); /* should never be null */
688 if (vmesa
->driDrawable
) {
689 viaWaitIdle(vmesa
, GL_FALSE
);
691 if (vmesa
->doPageFlip
) {
692 LOCK_HARDWARE(vmesa
);
693 if (vmesa
->pfCurrentOffset
!= 0) {
694 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
695 viaResetPageFlippingLocked(vmesa
);
697 UNLOCK_HARDWARE(vmesa
);
701 /* check if we're deleting the currently bound context */
702 if (vmesa
== current
) {
703 VIA_FLUSH_DMA(vmesa
);
704 _mesa_make_current(NULL
, NULL
, NULL
);
707 _swsetup_DestroyContext(vmesa
->glCtx
);
708 _tnl_DestroyContext(vmesa
->glCtx
);
709 _vbo_DestroyContext(vmesa
->glCtx
);
710 _swrast_DestroyContext(vmesa
->glCtx
);
711 /* free the Mesa context */
712 _mesa_destroy_context(vmesa
->glCtx
);
713 /* release our data */
716 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]));
717 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]));
718 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]));
719 assert (is_empty_list(&vmesa
->freed_tex_buffers
));
721 driDestroyOptionCache(&vmesa
->optionCache
);
727 void viaXMesaWindowMoved(struct via_context
*vmesa
)
729 __DRIdrawablePrivate
*const drawable
= vmesa
->driDrawable
;
730 __DRIdrawablePrivate
*const readable
= vmesa
->driReadable
;
731 struct via_renderbuffer
* draw_buffer
;
732 struct via_renderbuffer
* read_buffer
;
733 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
738 draw_buffer
= (struct via_renderbuffer
*) drawable
->driverPrivate
;
739 read_buffer
= (struct via_renderbuffer
*) readable
->driverPrivate
;
741 switch (vmesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0]) {
742 case BUFFER_BACK_LEFT
:
743 if (drawable
->numBackClipRects
== 0) {
744 vmesa
->numClipRects
= drawable
->numClipRects
;
745 vmesa
->pClipRects
= drawable
->pClipRects
;
748 vmesa
->numClipRects
= drawable
->numBackClipRects
;
749 vmesa
->pClipRects
= drawable
->pBackClipRects
;
752 case BUFFER_FRONT_LEFT
:
753 vmesa
->numClipRects
= drawable
->numClipRects
;
754 vmesa
->pClipRects
= drawable
->pClipRects
;
757 vmesa
->numClipRects
= 0;
761 if ((draw_buffer
->drawW
!= drawable
->w
)
762 || (draw_buffer
->drawH
!= drawable
->h
)) {
763 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->DrawBuffer
,
767 draw_buffer
->drawX
= drawable
->x
;
768 draw_buffer
->drawY
= drawable
->y
;
769 draw_buffer
->drawW
= drawable
->w
;
770 draw_buffer
->drawH
= drawable
->h
;
772 if (drawable
!= readable
) {
773 if ((read_buffer
->drawW
!= readable
->w
)
774 || (read_buffer
->drawH
!= readable
->h
)) {
775 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->ReadBuffer
,
779 read_buffer
->drawX
= readable
->x
;
780 read_buffer
->drawY
= readable
->y
;
781 read_buffer
->drawW
= readable
->w
;
782 read_buffer
->drawH
= readable
->h
;
785 vmesa
->front
.orig
= (vmesa
->front
.offset
+
786 draw_buffer
->drawY
* vmesa
->front
.pitch
+
787 draw_buffer
->drawX
* bytePerPixel
);
789 vmesa
->front
.origMap
= (vmesa
->front
.map
+
790 draw_buffer
->drawY
* vmesa
->front
.pitch
+
791 draw_buffer
->drawX
* bytePerPixel
);
793 vmesa
->back
.orig
= (vmesa
->back
.offset
+
794 draw_buffer
->drawY
* vmesa
->back
.pitch
+
795 draw_buffer
->drawX
* bytePerPixel
);
797 vmesa
->back
.origMap
= (vmesa
->back
.map
+
798 draw_buffer
->drawY
* vmesa
->back
.pitch
+
799 draw_buffer
->drawX
* bytePerPixel
);
801 vmesa
->depth
.orig
= (vmesa
->depth
.offset
+
802 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
803 draw_buffer
->drawX
* bytePerPixel
);
805 vmesa
->depth
.origMap
= (vmesa
->depth
.map
+
806 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
807 draw_buffer
->drawX
* bytePerPixel
);
809 viaCalcViewport(vmesa
->glCtx
);
813 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
819 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
820 __DRIdrawablePrivate
*driDrawPriv
,
821 __DRIdrawablePrivate
*driReadPriv
)
823 if (VIA_DEBUG
& DEBUG_DRI
) {
824 fprintf(stderr
, "driContextPriv = %016lx\n", (unsigned long)driContextPriv
);
825 fprintf(stderr
, "driDrawPriv = %016lx\n", (unsigned long)driDrawPriv
);
826 fprintf(stderr
, "driReadPriv = %016lx\n", (unsigned long)driReadPriv
);
829 if (driContextPriv
) {
830 struct via_context
*vmesa
=
831 (struct via_context
*)driContextPriv
->driverPrivate
;
832 GLcontext
*ctx
= vmesa
->glCtx
;
833 struct gl_framebuffer
*drawBuffer
, *readBuffer
;
835 drawBuffer
= (GLframebuffer
*)driDrawPriv
->driverPrivate
;
836 readBuffer
= (GLframebuffer
*)driReadPriv
->driverPrivate
;
838 if ((vmesa
->driDrawable
!= driDrawPriv
)
839 || (vmesa
->driReadable
!= driReadPriv
)) {
840 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
841 driDrawPriv
->vblFlags
=
842 vmesa
->viaScreen
->irqEnabled
?
843 driGetDefaultVBlankFlags(&vmesa
->optionCache
) :
846 driDrawableInitVBlank(driDrawPriv
);
849 vmesa
->driDrawable
= driDrawPriv
;
850 vmesa
->driReadable
= driReadPriv
;
852 if ((drawBuffer
->Width
!= driDrawPriv
->w
)
853 || (drawBuffer
->Height
!= driDrawPriv
->h
)) {
854 _mesa_resize_framebuffer(ctx
, drawBuffer
,
855 driDrawPriv
->w
, driDrawPriv
->h
);
856 drawBuffer
->Initialized
= GL_TRUE
;
859 if (!calculate_buffer_parameters(vmesa
, drawBuffer
, driDrawPriv
)) {
863 if (driDrawPriv
!= driReadPriv
) {
864 if ((readBuffer
->Width
!= driReadPriv
->w
)
865 || (readBuffer
->Height
!= driReadPriv
->h
)) {
866 _mesa_resize_framebuffer(ctx
, readBuffer
,
867 driReadPriv
->w
, driReadPriv
->h
);
868 readBuffer
->Initialized
= GL_TRUE
;
871 if (!calculate_buffer_parameters(vmesa
, readBuffer
, driReadPriv
)) {
877 _mesa_make_current(vmesa
->glCtx
, drawBuffer
, readBuffer
);
879 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );
881 viaXMesaWindowMoved(vmesa
);
882 ctx
->Driver
.Scissor(vmesa
->glCtx
,
883 vmesa
->glCtx
->Scissor
.X
,
884 vmesa
->glCtx
->Scissor
.Y
,
885 vmesa
->glCtx
->Scissor
.Width
,
886 vmesa
->glCtx
->Scissor
.Height
);
889 _mesa_make_current(NULL
, NULL
, NULL
);
895 void viaGetLock(struct via_context
*vmesa
, GLuint flags
)
897 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
898 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
900 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
902 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
903 if (dPriv
!= vmesa
->driReadable
) {
904 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, vmesa
->driReadable
);
907 if (vmesa
->sarea
->ctxOwner
!= vmesa
->hHWContext
) {
908 vmesa
->sarea
->ctxOwner
= vmesa
->hHWContext
;
909 vmesa
->newEmitState
= ~0;
912 if (vmesa
->lastStamp
!= dPriv
->lastStamp
) {
913 viaXMesaWindowMoved(vmesa
);
914 driUpdateFramebufferSize(vmesa
->glCtx
, dPriv
);
915 vmesa
->newEmitState
= ~0;
916 vmesa
->lastStamp
= dPriv
->lastStamp
;
919 if (vmesa
->doPageFlip
&&
920 vmesa
->pfCurrentOffset
!= vmesa
->sarea
->pfCurrentOffset
) {
921 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
922 viaResetPageFlippingLocked(vmesa
);
928 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
930 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
933 dPriv
->driContextPriv
&&
934 dPriv
->driContextPriv
->driverPrivate
) {
935 struct via_context
*vmesa
=
936 (struct via_context
*)dPriv
->driContextPriv
->driverPrivate
;
937 GLcontext
*ctx
= vmesa
->glCtx
;
939 _mesa_notifySwapBuffers(ctx
);
941 if (ctx
->Visual
.doubleBufferMode
) {
942 if (vmesa
->doPageFlip
) {
946 viaCopyBuffer(dPriv
);
950 VIA_FLUSH_DMA(vmesa
);
953 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");