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?
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/matrix.h"
36 #include "main/state.h"
37 #include "main/simple_list.h"
38 #include "main/extensions.h"
39 #include "main/framebuffer.h"
40 #include "main/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"
62 #include "main/macros.h"
63 #include "drirenderbuffer.h"
65 #define need_GL_ARB_point_parameters
66 #define need_GL_EXT_fog_coord
67 #define need_GL_EXT_secondary_color
68 #include "extension_helper.h"
70 #define DRIVER_DATE "20060710"
78 * Return various strings for \c glGetString.
82 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
84 static char buffer
[128];
90 return (GLubyte
*)"VIA Technology";
93 static const char * const chipset_names
[] = {
95 "CastleRock (CLE266)",
98 "UniChrome (PM8x0/CN400)",
100 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
101 unsigned id
= vmesa
->viaScreen
->deviceID
;
103 offset
= driGetRendererString( buffer
,
104 chipset_names
[(id
> VIA_PM800
) ? 0 : id
],
106 return (GLubyte
*)buffer
;
116 * Calculate a width that satisfies the hardware's alignment requirements.
117 * On the Unichrome hardware, each scanline must be aligned to a multiple of
120 * \param width Minimum buffer width, in pixels.
122 * \returns A pixel width that meets the alignment requirements.
124 static INLINE
unsigned
125 buffer_align( unsigned width
)
127 return (width
+ 0x0f) & ~0x0f;
132 viaDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
134 /* Don't free() since we're contained in via_context struct. */
138 viaRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
139 GLenum internalFormat
, GLuint width
, GLuint height
)
143 rb
->InternalFormat
= internalFormat
;
149 viaInitRenderbuffer(struct via_renderbuffer
*vrb
, GLenum format
,
150 __DRIdrawablePrivate
*dPriv
)
152 const GLuint name
= 0;
153 struct gl_renderbuffer
*rb
= & vrb
->Base
;
156 _mesa_init_renderbuffer(rb
, name
);
158 /* Make sure we're using a null-valued GetPointer routine */
159 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
161 rb
->InternalFormat
= format
;
163 if (format
== GL_RGBA
) {
165 rb
->_BaseFormat
= GL_RGBA
;
166 rb
->DataType
= GL_UNSIGNED_BYTE
;
168 else if (format
== GL_DEPTH_COMPONENT16
) {
170 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
171 /* we always Get/Put 32-bit Z values */
172 rb
->DataType
= GL_UNSIGNED_INT
;
174 else if (format
== GL_DEPTH_COMPONENT24
) {
176 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
177 /* we always Get/Put 32-bit Z values */
178 rb
->DataType
= GL_UNSIGNED_INT
;
182 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
183 rb
->_BaseFormat
= GL_STENCIL_INDEX
;
184 rb
->DataType
= GL_UNSIGNED_BYTE
;
187 rb
->Delete
= viaDeleteRenderbuffer
;
188 rb
->AllocStorage
= viaRenderbufferStorage
;
193 * Calculate the framebuffer parameters for all buffers (front, back, depth,
194 * and stencil) associated with the specified context.
197 * This function also calls \c AllocateBuffer to actually allocate the
203 calculate_buffer_parameters(struct via_context
*vmesa
,
204 struct gl_framebuffer
*fb
,
205 __DRIdrawablePrivate
*dPriv
)
207 const unsigned shift
= vmesa
->viaScreen
->bitsPerPixel
/ 16;
208 const unsigned extra
= 32;
212 /* Normally, the renderbuffer would be added to the framebuffer just once
213 * when the framebuffer was created. The VIA driver is a bit funny
214 * though in that the front/back/depth renderbuffers are in the per-context
216 * That should be fixed someday.
219 if (!vmesa
->front
.Base
.InternalFormat
) {
220 /* do one-time init for the renderbuffers */
221 viaInitRenderbuffer(&vmesa
->front
, GL_RGBA
, dPriv
);
222 viaSetSpanFunctions(&vmesa
->front
, &fb
->Visual
);
223 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &vmesa
->front
.Base
);
225 if (fb
->Visual
.doubleBufferMode
) {
226 viaInitRenderbuffer(&vmesa
->back
, GL_RGBA
, dPriv
);
227 viaSetSpanFunctions(&vmesa
->back
, &fb
->Visual
);
228 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &vmesa
->back
.Base
);
231 if (vmesa
->glCtx
->Visual
.depthBits
> 0) {
232 viaInitRenderbuffer(&vmesa
->depth
,
233 (vmesa
->glCtx
->Visual
.depthBits
== 16
234 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
),
236 viaSetSpanFunctions(&vmesa
->depth
, &fb
->Visual
);
237 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &vmesa
->depth
.Base
);
240 if (vmesa
->glCtx
->Visual
.stencilBits
> 0) {
241 viaInitRenderbuffer(&vmesa
->stencil
, GL_STENCIL_INDEX8_EXT
,
243 viaSetSpanFunctions(&vmesa
->stencil
, &fb
->Visual
);
244 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &vmesa
->stencil
.Base
);
248 assert(vmesa
->front
.Base
.InternalFormat
);
249 assert(vmesa
->front
.Base
.AllocStorage
);
250 if (fb
->Visual
.doubleBufferMode
) {
251 assert(vmesa
->back
.Base
.AllocStorage
);
253 if (fb
->Visual
.depthBits
) {
254 assert(vmesa
->depth
.Base
.AllocStorage
);
258 /* Allocate front-buffer */
259 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
260 w
= vmesa
->driDrawable
->w
;
261 h
= vmesa
->driDrawable
->h
;
263 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
264 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
265 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
267 if (vmesa
->front
.map
)
268 via_free_draw_buffer(vmesa
, &vmesa
->front
);
269 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->front
))
273 w
= vmesa
->viaScreen
->width
;
274 h
= vmesa
->viaScreen
->height
;
276 vmesa
->front
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
277 vmesa
->front
.pitch
= buffer_align( w
) << shift
; /* bytes, not pixels */
278 vmesa
->front
.size
= vmesa
->front
.pitch
* h
;
279 if (getenv("ALTERNATE_SCREEN"))
280 vmesa
->front
.offset
= vmesa
->front
.size
;
282 vmesa
->front
.offset
= 0;
283 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
287 /* Allocate back-buffer */
288 if (vmesa
->hasBack
) {
289 vmesa
->back
.bpp
= vmesa
->viaScreen
->bitsPerPixel
;
290 vmesa
->back
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) << shift
);
291 vmesa
->back
.pitch
+= extra
;
292 vmesa
->back
.pitch
= MIN2(vmesa
->back
.pitch
, vmesa
->front
.pitch
);
293 vmesa
->back
.size
= vmesa
->back
.pitch
* vmesa
->driDrawable
->h
;
295 via_free_draw_buffer(vmesa
, &vmesa
->back
);
296 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->back
))
301 via_free_draw_buffer(vmesa
, &vmesa
->back
);
302 (void) memset( &vmesa
->back
, 0, sizeof( vmesa
->back
) );
306 /* Allocate depth-buffer */
307 if ( vmesa
->hasStencil
|| vmesa
->hasDepth
) {
308 vmesa
->depth
.bpp
= vmesa
->depthBits
;
309 if (vmesa
->depth
.bpp
== 24)
310 vmesa
->depth
.bpp
= 32;
312 vmesa
->depth
.pitch
= (buffer_align( vmesa
->driDrawable
->w
) *
313 (vmesa
->depth
.bpp
/8)) + extra
;
314 vmesa
->depth
.size
= vmesa
->depth
.pitch
* vmesa
->driDrawable
->h
;
316 if (vmesa
->depth
.map
)
317 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
318 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->depth
)) {
323 if (vmesa
->depth
.map
)
324 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
325 (void) memset( & vmesa
->depth
, 0, sizeof( vmesa
->depth
) );
328 /* stencil buffer is same as depth buffer */
329 vmesa
->stencil
.handle
= vmesa
->depth
.handle
;
330 vmesa
->stencil
.size
= vmesa
->depth
.size
;
331 vmesa
->stencil
.offset
= vmesa
->depth
.offset
;
332 vmesa
->stencil
.index
= vmesa
->depth
.index
;
333 vmesa
->stencil
.pitch
= vmesa
->depth
.pitch
;
334 vmesa
->stencil
.bpp
= vmesa
->depth
.bpp
;
335 vmesa
->stencil
.map
= vmesa
->depth
.map
;
336 vmesa
->stencil
.orig
= vmesa
->depth
.orig
;
337 vmesa
->stencil
.origMap
= vmesa
->depth
.origMap
;
339 if( vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
340 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
341 vmesa
->doPageFlip
= vmesa
->allowPageFlip
;
342 if (vmesa
->hasBack
) {
343 assert(vmesa
->back
.pitch
== vmesa
->front
.pitch
);
347 vmesa
->doPageFlip
= GL_FALSE
;
353 void viaReAllocateBuffers(GLcontext
*ctx
, GLframebuffer
*drawbuffer
,
354 GLuint width
, GLuint height
)
356 struct via_context
*vmesa
= VIA_CONTEXT(ctx
);
358 calculate_buffer_parameters(vmesa
, drawbuffer
, vmesa
->driDrawable
);
360 _mesa_resize_framebuffer(ctx
, drawbuffer
, width
, height
);
363 /* Extension strings exported by the Unichrome driver.
365 const struct dri_extension card_extensions
[] =
367 { "GL_ARB_multitexture", NULL
},
368 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
369 { "GL_ARB_texture_env_add", NULL
},
370 { "GL_ARB_texture_env_combine", NULL
},
371 /* { "GL_ARB_texture_env_dot3", NULL }, */
372 { "GL_ARB_texture_mirrored_repeat", NULL
},
373 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
374 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
375 { "GL_EXT_stencil_wrap", NULL
},
376 { "GL_EXT_texture_env_combine", NULL
},
377 /* { "GL_EXT_texture_env_dot3", NULL }, */
378 { "GL_EXT_texture_lod_bias", NULL
},
379 { "GL_NV_blend_square", NULL
},
383 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
384 extern const struct tnl_pipeline_stage _via_render_stage
;
386 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
387 &_tnl_vertex_transform_stage
,
388 &_tnl_normal_transform_stage
,
389 &_tnl_lighting_stage
,
390 &_tnl_fog_coordinate_stage
,
392 &_tnl_texture_transform_stage
,
393 /* REMOVE: point attenuation stage */
395 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
402 static const struct dri_debug_control debug_control
[] =
404 { "fall", DEBUG_FALLBACKS
},
405 { "tex", DEBUG_TEXTURE
},
406 { "ioctl", DEBUG_IOCTL
},
407 { "prim", DEBUG_PRIMS
},
408 { "vert", DEBUG_VERTS
},
409 { "state", DEBUG_STATE
},
410 { "verb", DEBUG_VERBOSE
},
411 { "dri", DEBUG_DRI
},
412 { "dma", DEBUG_DMA
},
413 { "san", DEBUG_SANITY
},
414 { "sync", DEBUG_SYNC
},
415 { "sleep", DEBUG_SLEEP
},
416 { "pix", DEBUG_PIXEL
},
423 AllocateDmaBuffer(struct via_context
*vmesa
)
426 via_free_dma_buffer(vmesa
);
428 if (!via_alloc_dma_buffer(vmesa
))
432 vmesa
->dmaCliprectAddr
= ~0;
437 FreeBuffer(struct via_context
*vmesa
)
439 if (vmesa
->front
.map
&& vmesa
->drawType
== GLX_PBUFFER_BIT
)
440 via_free_draw_buffer(vmesa
, &vmesa
->front
);
443 via_free_draw_buffer(vmesa
, &vmesa
->back
);
445 if (vmesa
->depth
.map
)
446 via_free_draw_buffer(vmesa
, &vmesa
->depth
);
448 if (vmesa
->breadcrumb
.map
)
449 via_free_draw_buffer(vmesa
, &vmesa
->breadcrumb
);
452 via_free_dma_buffer(vmesa
);
457 viaCreateContext(const __GLcontextModes
*visual
,
458 __DRIcontextPrivate
*driContextPriv
,
459 void *sharedContextPrivate
)
461 GLcontext
*ctx
, *shareCtx
;
462 struct via_context
*vmesa
;
463 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
464 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
465 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
466 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
467 struct dd_function_table functions
;
469 /* Allocate via context */
470 vmesa
= (struct via_context
*) CALLOC_STRUCT(via_context
);
475 /* Parse configuration files.
477 driParseConfigFiles (&vmesa
->optionCache
, &viaScreen
->optionCache
,
478 sPriv
->myNum
, "unichrome");
480 /* pick back buffer */
481 vmesa
->hasBack
= visual
->doubleBufferMode
;
483 switch(visual
->depthBits
) {
485 vmesa
->hasDepth
= GL_FALSE
;
486 vmesa
->depthBits
= 0;
487 vmesa
->depth_max
= 1.0;
490 vmesa
->hasDepth
= GL_TRUE
;
491 vmesa
->depthBits
= visual
->depthBits
;
492 vmesa
->have_hw_stencil
= GL_FALSE
;
493 vmesa
->depth_max
= (GLfloat
)0xffff;
494 vmesa
->depth_clear_mask
= 0xf << 28;
495 vmesa
->ClearDepth
= 0xffff;
496 vmesa
->polygon_offset_scale
= 1.0 / vmesa
->depth_max
;
499 vmesa
->hasDepth
= GL_TRUE
;
500 vmesa
->depthBits
= visual
->depthBits
;
501 vmesa
->depth_max
= (GLfloat
) 0xffffff;
502 vmesa
->depth_clear_mask
= 0xe << 28;
503 vmesa
->ClearDepth
= 0xffffff00;
505 assert(visual
->haveStencilBuffer
);
506 assert(visual
->stencilBits
== 8);
508 vmesa
->have_hw_stencil
= GL_TRUE
;
509 vmesa
->stencilBits
= visual
->stencilBits
;
510 vmesa
->stencil_clear_mask
= 0x1 << 28;
511 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
514 vmesa
->hasDepth
= GL_TRUE
;
515 vmesa
->depthBits
= visual
->depthBits
;
516 assert(!visual
->haveStencilBuffer
);
517 vmesa
->have_hw_stencil
= GL_FALSE
;
518 vmesa
->depth_max
= (GLfloat
)0xffffffff;
519 vmesa
->depth_clear_mask
= 0xf << 28;
520 vmesa
->ClearDepth
= 0xffffffff;
521 vmesa
->polygon_offset_scale
= 2.0 / vmesa
->depth_max
;
528 make_empty_list(&vmesa
->freed_tex_buffers
);
529 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]);
530 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]);
531 make_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]);
533 _mesa_init_driver_functions(&functions
);
534 viaInitTextureFuncs(&functions
);
536 /* Allocate the Mesa context */
537 if (sharedContextPrivate
)
538 shareCtx
= ((struct via_context
*) sharedContextPrivate
)->glCtx
;
542 vmesa
->glCtx
= _mesa_create_context(visual
, shareCtx
, &functions
,
545 vmesa
->shareCtx
= shareCtx
;
551 driContextPriv
->driverPrivate
= vmesa
;
555 if (driQueryOptionb(&vmesa
->optionCache
, "excess_mipmap"))
556 ctx
->Const
.MaxTextureLevels
= 11;
558 ctx
->Const
.MaxTextureLevels
= 10;
560 ctx
->Const
.MaxTextureUnits
= 2;
561 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
562 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
564 ctx
->Const
.MinLineWidth
= 1.0;
565 ctx
->Const
.MinLineWidthAA
= 1.0;
566 ctx
->Const
.MaxLineWidth
= 1.0;
567 ctx
->Const
.MaxLineWidthAA
= 1.0;
568 ctx
->Const
.LineWidthGranularity
= 1.0;
570 ctx
->Const
.MinPointSize
= 1.0;
571 ctx
->Const
.MinPointSizeAA
= 1.0;
572 ctx
->Const
.MaxPointSize
= 1.0;
573 ctx
->Const
.MaxPointSizeAA
= 1.0;
574 ctx
->Const
.PointSizeGranularity
= 1.0;
576 ctx
->Const
.MaxDrawBuffers
= 1;
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
->hHWContext
= driContextPriv
->hHWContext
;
603 vmesa
->driFd
= sPriv
->fd
;
604 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
606 vmesa
->viaScreen
= viaScreen
;
607 vmesa
->driScreen
= sPriv
;
608 vmesa
->sarea
= saPriv
;
610 vmesa
->renderIndex
= ~0;
611 vmesa
->setupIndex
= ~0;
612 vmesa
->hwPrimitive
= GL_POLYGON
+1;
614 /* KW: Hardwire this. Was previously set bogusly in
615 * viaCreateBuffer. Needs work before PBUFFER can be used:
617 vmesa
->drawType
= GLX_WINDOW_BIT
;
620 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
622 /* Do this early, before VIA_FLUSH_DMA can be called:
624 if (!AllocateDmaBuffer(vmesa
)) {
625 fprintf(stderr
,"AllocateDmaBuffer fail\n");
631 /* Allocate a small piece of fb memory for synchronization:
633 vmesa
->breadcrumb
.bpp
= 32;
634 vmesa
->breadcrumb
.pitch
= buffer_align( 64 ) << 2;
635 vmesa
->breadcrumb
.size
= vmesa
->breadcrumb
.pitch
;
637 if (!via_alloc_draw_buffer(vmesa
, &vmesa
->breadcrumb
)) {
638 fprintf(stderr
,"AllocateDmaBuffer fail\n");
644 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
645 viaInitStateFuncs(ctx
);
646 viaInitTriFuncs(ctx
);
647 viaInitSpanFuncs(ctx
);
648 viaInitIoctlFuncs(ctx
);
651 if (getenv("VIA_DEBUG"))
652 VIA_DEBUG
= driParseDebugString( getenv( "VIA_DEBUG" ),
655 if (getenv("VIA_NO_RAST") ||
656 driQueryOptionb(&vmesa
->optionCache
, "no_rast"))
657 FALLBACK(vmesa
, VIA_FALLBACK_USER_DISABLE
, 1);
659 if (getenv("VIA_PAGEFLIP"))
660 vmesa
->allowPageFlip
= 1;
662 (*sPriv
->systemTime
->getUST
)( &vmesa
->swap_ust
);
665 vmesa
->regMMIOBase
= (GLuint
*)((unsigned long)viaScreen
->reg
);
666 vmesa
->pnGEMode
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x4);
667 vmesa
->regEngineStatus
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x400);
668 vmesa
->regTranSet
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x43C);
669 vmesa
->regTranSpace
= (GLuint
*)((unsigned long)viaScreen
->reg
+ 0x440);
670 vmesa
->agpBase
= viaScreen
->agpBase
;
677 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
679 GET_CURRENT_CONTEXT(ctx
);
680 struct via_context
*vmesa
=
681 (struct via_context
*)driContextPriv
->driverPrivate
;
682 struct via_context
*current
= ctx
? VIA_CONTEXT(ctx
) : NULL
;
684 assert(vmesa
); /* should never be null */
686 if (vmesa
->driDrawable
) {
687 viaWaitIdle(vmesa
, GL_FALSE
);
689 if (vmesa
->doPageFlip
) {
690 LOCK_HARDWARE(vmesa
);
691 if (vmesa
->pfCurrentOffset
!= 0) {
692 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
693 viaResetPageFlippingLocked(vmesa
);
695 UNLOCK_HARDWARE(vmesa
);
699 /* check if we're deleting the currently bound context */
700 if (vmesa
== current
) {
701 VIA_FLUSH_DMA(vmesa
);
702 _mesa_make_current(NULL
, NULL
, NULL
);
705 _swsetup_DestroyContext(vmesa
->glCtx
);
706 _tnl_DestroyContext(vmesa
->glCtx
);
707 _vbo_DestroyContext(vmesa
->glCtx
);
708 _swrast_DestroyContext(vmesa
->glCtx
);
709 /* free the Mesa context */
710 _mesa_destroy_context(vmesa
->glCtx
);
711 /* release our data */
714 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_AGP
]));
715 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_VIDEO
]));
716 assert (is_empty_list(&vmesa
->tex_image_list
[VIA_MEM_SYSTEM
]));
717 assert (is_empty_list(&vmesa
->freed_tex_buffers
));
719 driDestroyOptionCache(&vmesa
->optionCache
);
725 void viaXMesaWindowMoved(struct via_context
*vmesa
)
727 __DRIdrawablePrivate
*const drawable
= vmesa
->driDrawable
;
728 __DRIdrawablePrivate
*const readable
= vmesa
->driReadable
;
729 struct via_renderbuffer
* draw_buffer
;
730 struct via_renderbuffer
* read_buffer
;
731 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
736 draw_buffer
= (struct via_renderbuffer
*) drawable
->driverPrivate
;
737 read_buffer
= (struct via_renderbuffer
*) readable
->driverPrivate
;
739 switch (vmesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0]) {
740 case BUFFER_BACK_LEFT
:
741 if (drawable
->numBackClipRects
== 0) {
742 vmesa
->numClipRects
= drawable
->numClipRects
;
743 vmesa
->pClipRects
= drawable
->pClipRects
;
746 vmesa
->numClipRects
= drawable
->numBackClipRects
;
747 vmesa
->pClipRects
= drawable
->pBackClipRects
;
750 case BUFFER_FRONT_LEFT
:
751 vmesa
->numClipRects
= drawable
->numClipRects
;
752 vmesa
->pClipRects
= drawable
->pClipRects
;
755 vmesa
->numClipRects
= 0;
759 if ((draw_buffer
->drawW
!= drawable
->w
)
760 || (draw_buffer
->drawH
!= drawable
->h
)) {
761 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->DrawBuffer
,
765 draw_buffer
->drawX
= drawable
->x
;
766 draw_buffer
->drawY
= drawable
->y
;
767 draw_buffer
->drawW
= drawable
->w
;
768 draw_buffer
->drawH
= drawable
->h
;
770 if (drawable
!= readable
) {
771 if ((read_buffer
->drawW
!= readable
->w
)
772 || (read_buffer
->drawH
!= readable
->h
)) {
773 calculate_buffer_parameters(vmesa
, vmesa
->glCtx
->ReadBuffer
,
777 read_buffer
->drawX
= readable
->x
;
778 read_buffer
->drawY
= readable
->y
;
779 read_buffer
->drawW
= readable
->w
;
780 read_buffer
->drawH
= readable
->h
;
783 vmesa
->front
.orig
= (vmesa
->front
.offset
+
784 draw_buffer
->drawY
* vmesa
->front
.pitch
+
785 draw_buffer
->drawX
* bytePerPixel
);
787 vmesa
->front
.origMap
= (vmesa
->front
.map
+
788 draw_buffer
->drawY
* vmesa
->front
.pitch
+
789 draw_buffer
->drawX
* bytePerPixel
);
791 vmesa
->back
.orig
= (vmesa
->back
.offset
+
792 draw_buffer
->drawY
* vmesa
->back
.pitch
+
793 draw_buffer
->drawX
* bytePerPixel
);
795 vmesa
->back
.origMap
= (vmesa
->back
.map
+
796 draw_buffer
->drawY
* vmesa
->back
.pitch
+
797 draw_buffer
->drawX
* bytePerPixel
);
799 vmesa
->depth
.orig
= (vmesa
->depth
.offset
+
800 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
801 draw_buffer
->drawX
* bytePerPixel
);
803 vmesa
->depth
.origMap
= (vmesa
->depth
.map
+
804 draw_buffer
->drawY
* vmesa
->depth
.pitch
+
805 draw_buffer
->drawX
* bytePerPixel
);
807 viaCalcViewport(vmesa
->glCtx
);
811 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
817 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
818 __DRIdrawablePrivate
*driDrawPriv
,
819 __DRIdrawablePrivate
*driReadPriv
)
821 if (VIA_DEBUG
& DEBUG_DRI
) {
822 fprintf(stderr
, "driContextPriv = %016lx\n", (unsigned long)driContextPriv
);
823 fprintf(stderr
, "driDrawPriv = %016lx\n", (unsigned long)driDrawPriv
);
824 fprintf(stderr
, "driReadPriv = %016lx\n", (unsigned long)driReadPriv
);
827 if (driContextPriv
) {
828 struct via_context
*vmesa
=
829 (struct via_context
*)driContextPriv
->driverPrivate
;
830 GLcontext
*ctx
= vmesa
->glCtx
;
831 struct gl_framebuffer
*drawBuffer
, *readBuffer
;
833 drawBuffer
= (GLframebuffer
*)driDrawPriv
->driverPrivate
;
834 readBuffer
= (GLframebuffer
*)driReadPriv
->driverPrivate
;
836 if ((vmesa
->driDrawable
!= driDrawPriv
)
837 || (vmesa
->driReadable
!= driReadPriv
)) {
838 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
839 driDrawPriv
->vblFlags
=
840 vmesa
->viaScreen
->irqEnabled
?
841 driGetDefaultVBlankFlags(&vmesa
->optionCache
) :
844 driDrawableInitVBlank(driDrawPriv
);
847 vmesa
->driDrawable
= driDrawPriv
;
848 vmesa
->driReadable
= driReadPriv
;
850 if ((drawBuffer
->Width
!= driDrawPriv
->w
)
851 || (drawBuffer
->Height
!= driDrawPriv
->h
)) {
852 _mesa_resize_framebuffer(ctx
, drawBuffer
,
853 driDrawPriv
->w
, driDrawPriv
->h
);
854 drawBuffer
->Initialized
= GL_TRUE
;
857 if (!calculate_buffer_parameters(vmesa
, drawBuffer
, driDrawPriv
)) {
861 if (driDrawPriv
!= driReadPriv
) {
862 if ((readBuffer
->Width
!= driReadPriv
->w
)
863 || (readBuffer
->Height
!= driReadPriv
->h
)) {
864 _mesa_resize_framebuffer(ctx
, readBuffer
,
865 driReadPriv
->w
, driReadPriv
->h
);
866 readBuffer
->Initialized
= GL_TRUE
;
869 if (!calculate_buffer_parameters(vmesa
, readBuffer
, driReadPriv
)) {
875 _mesa_make_current(vmesa
->glCtx
, drawBuffer
, readBuffer
);
877 ctx
->Driver
.DrawBuffer( ctx
, ctx
->Color
.DrawBuffer
[0] );
879 viaXMesaWindowMoved(vmesa
);
880 ctx
->Driver
.Scissor(vmesa
->glCtx
,
881 vmesa
->glCtx
->Scissor
.X
,
882 vmesa
->glCtx
->Scissor
.Y
,
883 vmesa
->glCtx
->Scissor
.Width
,
884 vmesa
->glCtx
->Scissor
.Height
);
887 _mesa_make_current(NULL
, NULL
, NULL
);
893 void viaGetLock(struct via_context
*vmesa
, GLuint flags
)
895 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
896 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
898 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
900 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
901 if (dPriv
!= vmesa
->driReadable
) {
902 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, vmesa
->driReadable
);
905 if (vmesa
->sarea
->ctxOwner
!= vmesa
->hHWContext
) {
906 vmesa
->sarea
->ctxOwner
= vmesa
->hHWContext
;
907 vmesa
->newEmitState
= ~0;
910 if (vmesa
->lastStamp
!= dPriv
->lastStamp
) {
911 viaXMesaWindowMoved(vmesa
);
912 driUpdateFramebufferSize(vmesa
->glCtx
, dPriv
);
913 vmesa
->newEmitState
= ~0;
914 vmesa
->lastStamp
= dPriv
->lastStamp
;
917 if (vmesa
->doPageFlip
&&
918 vmesa
->pfCurrentOffset
!= vmesa
->sarea
->pfCurrentOffset
) {
919 fprintf(stderr
, "%s - reset pf\n", __FUNCTION__
);
920 viaResetPageFlippingLocked(vmesa
);
926 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
928 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
931 dPriv
->driContextPriv
&&
932 dPriv
->driContextPriv
->driverPrivate
) {
933 struct via_context
*vmesa
=
934 (struct via_context
*)dPriv
->driContextPriv
->driverPrivate
;
935 GLcontext
*ctx
= vmesa
->glCtx
;
937 _mesa_notifySwapBuffers(ctx
);
939 if (ctx
->Visual
.doubleBufferMode
) {
940 if (vmesa
->doPageFlip
) {
944 viaCopyBuffer(dPriv
);
948 VIA_FLUSH_DMA(vmesa
);
951 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");