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 #include "simple_list.h"
29 #include "extensions.h"
31 #include "swrast/swrast.h"
32 #include "swrast_setup/swrast_setup.h"
34 #include "array_cache/acache.h"
36 #include "tnl/t_pipeline.h"
38 #include "drivers/common/driverfuncs.h"
40 #include "via_screen.h"
43 #include "via_state.h"
48 #include "via_ioctl.h"
52 #include <X11/Xlibint.h>
57 viaContextPtr current_mesa
;
59 GLuint DRAW_FRONT
= 0;
61 GLuint VIA_PERFORMANCE
= 0;
62 #ifdef PERFORMANCE_MEASURE
65 hash_element hash_table
[HASH_TABLE_SIZE
][HASH_TABLE_DEPTH
];
67 /*=* John Sheng [2003.5.31] agp tex *=*/
68 extern GLuint agpFullCount
;
71 AllocateBuffer(viaContextPtr vmesa
)
73 vmesa
->front_base
= vmesa
->driScreen
->pFB
;
74 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
76 via_free_front_buffer(vmesa
);
77 if (!via_alloc_front_buffer(vmesa
))
83 via_free_back_buffer(vmesa
);
84 if (!via_alloc_back_buffer(vmesa
))
88 if (vmesa
->hasDepth
|| vmesa
->hasStencil
) {
90 via_free_depth_buffer(vmesa
);
91 if (!via_alloc_depth_buffer(vmesa
)) {
92 via_free_depth_buffer(vmesa
);
100 static const GLubyte
*viaGetString(GLcontext
*ctx
, GLenum name
)
104 return (GLubyte
*)"VIA Technology";
106 return (GLubyte
*)"Mesa DRI VIA CLE266 20020221";
112 void viaReAllocateBuffers(GLframebuffer
*drawbuffer
)
115 viaContextPtr vmesa
= current_mesa
;
118 ctx
->DrawBuffer
->Width
= drawbuffer
->Width
;
119 ctx
->DrawBuffer
->Height
= drawbuffer
->Height
;
122 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
124 ctx
->DrawBuffer
->Accum
= 0;
126 vmesa
->driDrawable
->w
= ctx
->DrawBuffer
->Width
;
127 vmesa
->driDrawable
->h
= ctx
->DrawBuffer
->Height
;
128 LOCK_HARDWARE(vmesa
);
130 /* Allocate back & depth buffer */
133 w
= vmesa
->driDrawable
->w
;
134 h
= vmesa
->driDrawable
->h
;
136 bpp
= vmesa
->viaScreen
->bitsPerPixel
;
138 if (VIA_DEBUG
) fprintf(stderr
, "driScreen->fbBPP = %d\n", bpp
);
141 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
142 vmesa
->back
.size
= w
* h
* bpp
/ 8;
143 vmesa
->back
.pitch
= w
<< 2;
146 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2 + 16;
147 vmesa
->back
.size
= w
* h
* bpp
/ 8;
148 vmesa
->back
.pitch
= w
<< 1;
151 if (VIA_DEBUG
) fprintf(stderr
, "resizebuffer backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
152 w
, h
, bpp
, vmesa
->back
.size
);
155 w
= vmesa
->driDrawable
->w
;
156 if (vmesa
->hasDepth
&& vmesa
->hasStencil
) {
157 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
158 vmesa
->depth
.size
= w
* h
* 4;
159 vmesa
->depth
.pitch
= w
<< 2;
160 vmesa
->depth
.bpp
= 32;
162 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 24\n");
163 if (VIA_DEBUG
) fprintf(stderr
, "StencilBits = 8\n");
166 else if (vmesa
->hasDepth
) {
167 /*=* John Sheng [2003.6.16] patch viewperf drv-08 draw nothing */
168 /*if(vmesa->viaScreen->bitsPerPixel == 32)*/
169 /*vmesa->depthBits = 16;*/
171 if (vmesa
->depthBits
== 16) {
172 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2 + 16;
173 vmesa
->depth
.size
= w
* h
* 2;
174 vmesa
->depth
.pitch
= w
<< 1;
175 vmesa
->depth
.bpp
= 16;
177 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 16\n");
181 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
182 vmesa
->depth
.size
= w
* h
* 4;
183 vmesa
->depth
.pitch
= w
<< 2;
184 vmesa
->depth
.bpp
= 32;
186 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 32\n");
190 else if (vmesa
->hasStencil
) {
191 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
192 vmesa
->depth
.size
= w
* h
* 4;
193 vmesa
->depth
.pitch
= w
<< 2;
194 vmesa
->depth
.bpp
= 32;
196 if (VIA_DEBUG
) fprintf(stderr
, "StencilBits = 8\n");
200 if (VIA_DEBUG
) fprintf(stderr
, "resizebuffer depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
201 w
, h
, vmesa
->depth
.bpp
, vmesa
->depth
.size
);
203 /*=* John Sheng [2003.5.31] flip *=*/
205 if(vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
206 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
207 vmesa
->back
.pitch
= vmesa
->front
.pitch
;
208 vmesa
->back
.size
= vmesa
->front
.size
;
212 if (!AllocateBuffer(vmesa
)) {
216 UNLOCK_HARDWARE(vmesa
);
218 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
221 static void viaBufferSize(GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
225 viaContextPtr vmesa
= current_mesa
;
226 *width
= vmesa
->driDrawable
->w
;
227 *height
= vmesa
->driDrawable
->h
;
230 static void viaInitExtensions(GLcontext
*ctx
)
232 _mesa_enable_imaging_extensions(ctx
);
233 _mesa_enable_extension(ctx
, "GL_ARB_multitexture");
234 _mesa_enable_extension(ctx
, "GL_ARB_texture_env_add");
235 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_add");
236 _mesa_enable_extension(ctx
, "GL_EXT_stencil_wrap");
237 _mesa_enable_extension(ctx
, "GL_EXT_texture_lod_bias");
238 /*=* John Sheng [2003.7.18] texture combine *=*/
239 _mesa_enable_extension(ctx
, "GL_ARB_texture_env_combine");
240 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_combine");
241 /*=* John Sheng [2003.7.18] texture dot3 *=*/
242 _mesa_enable_extension(ctx
, "GL_ARB_texture_env_dot3");
243 _mesa_enable_extension(ctx
, "GL_EXT_texture_env_dot3");
244 /*=* John Sheng [2003.7.18] point parameters */
245 _mesa_enable_extension(ctx
, "GL_ARB_point_parameters");
246 _mesa_enable_extension(ctx
, "GL_EXT_point_parameters");
249 extern const struct tnl_pipeline_stage _via_fastrender_stage
;
250 extern const struct tnl_pipeline_stage _via_render_stage
;
252 static const struct tnl_pipeline_stage
*via_pipeline
[] = {
253 &_tnl_vertex_transform_stage
,
254 &_tnl_normal_transform_stage
,
255 &_tnl_lighting_stage
,
256 &_tnl_fog_coordinate_stage
,
258 &_tnl_texture_transform_stage
,
259 /* REMOVE: point attenuation stage */
261 &_via_fastrender_stage
, /* ADD: unclipped rastersetup-to-dma */
262 &_via_render_stage
, /* ADD: modification from _tnl_render_stage */
270 AllocateDmaBuffer(const GLvisual
*visual
, viaContextPtr vmesa
)
273 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
275 if (vmesa
->dma
[0].map
&& vmesa
->dma
[1].map
)
276 via_free_dma_buffer(vmesa
);
278 if (!via_alloc_dma_buffer(vmesa
)) {
279 if (vmesa
->front
.map
)
280 via_free_front_buffer(vmesa
);
282 via_free_back_buffer(vmesa
);
283 if (vmesa
->depth
.map
)
284 via_free_depth_buffer(vmesa
);
289 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
295 InitVertexBuffer(viaContextPtr vmesa
)
299 addr
= (GLuint
*)vmesa
->dma
[0].map
;
301 *addr
= (HC_ParaType_NotTex
<< 16);
305 addr
= (GLuint
*)vmesa
->dma
[1].map
;
307 *addr
= (HC_ParaType_NotTex
<< 16);
312 vmesa
->dmaLow
= DMA_OFFSET
;
313 vmesa
->dmaHigh
= vmesa
->dma
[0].size
;
314 vmesa
->dmaAddr
= (unsigned char *)vmesa
->dma
[0].map
;
315 vmesa
->dmaLastPrim
= vmesa
->dmaLow
;
319 FreeBuffer(viaContextPtr vmesa
)
321 if (vmesa
->front
.map
)
322 via_free_front_buffer(vmesa
);
325 via_free_back_buffer(vmesa
);
327 if (vmesa
->depth
.map
)
328 via_free_depth_buffer(vmesa
);
330 if (vmesa
->dma
[0].map
&& vmesa
->dma
[1].map
)
331 via_free_dma_buffer(vmesa
);
335 viaCreateContext(const __GLcontextModes
*mesaVis
,
336 __DRIcontextPrivate
*driContextPriv
,
337 void *sharedContextPrivate
)
339 GLcontext
*ctx
, *shareCtx
;
341 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
342 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
343 drm_via_sarea_t
*saPriv
= (drm_via_sarea_t
*)
344 (((GLubyte
*)sPriv
->pSAREA
) + viaScreen
->sareaPrivOffset
);
345 struct dd_function_table functions
;
347 /* Allocate via context */
348 vmesa
= (viaContextPtr
) CALLOC_STRUCT(via_context_t
);
353 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
355 current_mesa
= vmesa
;
356 /* pick back buffer */
357 if (mesaVis
->doubleBufferMode
) {
358 vmesa
->hasBack
= GL_TRUE
;
361 vmesa
->hasBack
= GL_FALSE
;
364 if (mesaVis
->haveDepthBuffer
) {
365 vmesa
->hasDepth
= GL_TRUE
;
366 vmesa
->depthBits
= mesaVis
->depthBits
;
369 vmesa
->hasDepth
= GL_FALSE
;
370 vmesa
->depthBits
= 0;
372 /* pick stencil buffer */
373 if (mesaVis
->haveStencilBuffer
) {
374 vmesa
->hasStencil
= GL_TRUE
;
375 vmesa
->stencilBits
= mesaVis
->stencilBits
;
378 vmesa
->hasStencil
= GL_FALSE
;
379 vmesa
->stencilBits
= 0;
382 _mesa_init_driver_functions(&functions
);
383 viaInitTextureFuncs(&functions
);
385 /* Allocate the Mesa context */
386 if (sharedContextPrivate
)
387 shareCtx
= ((viaContextPtr
) sharedContextPrivate
)->glCtx
;
391 vmesa
->glCtx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, (void*) vmesa
);
393 vmesa
->shareCtx
= shareCtx
;
399 driContextPriv
->driverPrivate
= vmesa
;
404 /*=* John Sheng [2003.7.2] for visual config number can't excess 8 *=*/
405 /*if (viaScreen->textureSize < 2 * 1024 * 1024) {
406 ctx->Const.MaxTextureLevels = 9;
408 else if (viaScreen->textureSize < 8 * 1024 * 1024) {
409 ctx->Const.MaxTextureLevels = 10;
412 ctx->Const.MaxTextureLevels = 11;
414 ctx
->Const
.MaxTextureLevels
= 11;
416 ctx
->Const
.MaxTextureUnits
= 2;
418 ctx
->Const
.MinLineWidth
= 1.0;
419 ctx
->Const
.MinLineWidthAA
= 1.0;
420 ctx
->Const
.MaxLineWidth
= 3.0;
421 ctx
->Const
.MaxLineWidthAA
= 3.0;
422 ctx
->Const
.LineWidthGranularity
= 1.0;
424 ctx
->Const
.MinPointSize
= 1.0;
425 ctx
->Const
.MinPointSizeAA
= 1.0;
426 ctx
->Const
.MaxPointSize
= 3.0;
427 ctx
->Const
.MaxPointSizeAA
= 3.0;
428 ctx
->Const
.PointSizeGranularity
= 1.0;
430 ctx
->Driver
.GetBufferSize
= viaBufferSize
;
431 /* ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; *//* FIXME ?? */
432 ctx
->Driver
.GetString
= viaGetString
;
434 ctx
->DriverCtx
= (void *)vmesa
;
437 /* Initialize the software rasterizer and helper modules.
439 _swrast_CreateContext(ctx
);
440 _ac_CreateContext(ctx
);
441 _tnl_CreateContext(ctx
);
442 _swsetup_CreateContext(ctx
);
444 /* Install the customized pipeline:
446 _tnl_destroy_pipeline(ctx
);
447 _tnl_install_pipeline(ctx
, via_pipeline
);
449 /* Configure swrast and T&L to match hardware characteristics:
451 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
452 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
453 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
454 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
457 vmesa
->display
= dpy
;
458 vmesa
->display
= sPriv
->display
;
461 vmesa
->hHWContext
= driContextPriv
->hHWContext
;
462 vmesa
->driFd
= sPriv
->fd
;
463 vmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
465 vmesa
->viaScreen
= viaScreen
;
466 vmesa
->driScreen
= sPriv
;
467 vmesa
->sarea
= saPriv
;
468 vmesa
->glBuffer
= NULL
;
470 vmesa
->texHeap
= mmInit(0, viaScreen
->textureSize
);
471 vmesa
->stippleInHw
= 1;
472 vmesa
->renderIndex
= ~0;
473 vmesa
->dirty
= VIA_UPLOAD_ALL
;
474 vmesa
->uploadCliprects
= GL_TRUE
;
475 vmesa
->needUploadAllState
= 1;
477 make_empty_list(&vmesa
->TexObjList
);
478 make_empty_list(&vmesa
->SwappedOut
);
480 vmesa
->CurrentTexObj
[0] = 0;
481 vmesa
->CurrentTexObj
[1] = 0;
483 vmesa
->dma
[0].size
= DMA_SIZE
* 1024 * 1024;
484 vmesa
->dma
[1].size
= DMA_SIZE
* 1024 * 1024;
486 _math_matrix_ctr(&vmesa
->ViewportMatrix
);
488 viaInitExtensions(ctx
);
489 viaInitStateFuncs(ctx
);
490 viaInitTextures(ctx
);
491 viaInitTriFuncs(ctx
);
492 viaInitSpanFuncs(ctx
);
493 viaInitIoctlFuncs(ctx
);
497 if (getenv("VIA_DEBUG"))
502 if (getenv("DRAW_FRONT"))
507 #ifdef PERFORMANCE_MEASURE
508 if (getenv("VIA_PERFORMANCE"))
515 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
516 for (j
= 0; j
< HASH_TABLE_DEPTH
; j
++) {
517 hash_table
[i
][j
].count
= 0;
518 sprintf(hash_table
[i
][j
].func
, "%s", "NULL");
524 if (!AllocateDmaBuffer(mesaVis
, vmesa
)) {
525 fprintf(stderr
,"AllocateDmaBuffer fail\n");
530 InitVertexBuffer(vmesa
);
532 vmesa
->regMMIOBase
= (GLuint
*)((GLuint
)viaScreen
->reg
);
533 vmesa
->pnGEMode
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x4);
534 vmesa
->regEngineStatus
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x400);
535 vmesa
->regTranSet
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x43C);
536 vmesa
->regTranSpace
= (GLuint
*)((GLuint
)viaScreen
->reg
+ 0x440);
537 vmesa
->agpBase
= viaScreen
->agpBase
;
540 fprintf(stderr
, "regEngineStatus = %x\n", *vmesa
->regEngineStatus
);
543 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
547 int count
= 0, fbSize
;
551 saam
= XineramaIsActive(vmesa
->display
);
552 if (saam
&& vmesa
->viaScreen
->drixinerama
) {
553 vmesa
->xsi
= XineramaQueryScreens(vmesa
->display
, &count
);
554 /* Test RightOf or Down */
555 if (vmesa
->xsi
[0].x_org
== 0 && vmesa
->xsi
[0].y_org
== 0) {
556 if (vmesa
->xsi
[1].x_org
== vmesa
->xsi
[1].width
) {
557 vmesa
->saam
= RightOf
;
563 /* Test LeftOf or Up */
564 else if (vmesa
->xsi
[0].x_org
== vmesa
->xsi
[0].width
) {
565 vmesa
->saam
= LeftOf
;
567 else if (vmesa
->xsi
[0].y_org
== vmesa
->xsi
[0].height
) {
574 fbSize
= vmesa
->viaScreen
->fbSize
;
581 vmesa
->pSaamRects
= (drm_clip_rect_t
*) malloc(sizeof(drm_clip_rect_t
));
586 viaDestroyContext(__DRIcontextPrivate
*driContextPriv
)
588 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
589 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
590 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
591 viaScreenPrivate
*viaScreen
= (viaScreenPrivate
*)sPriv
->private;
593 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
595 assert(vmesa
); /* should never be null */
596 viaFlushPrimsLocked(vmesa
);
598 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
600 if (viaScreen
->VQEnable
) {
601 *vmesa
->regTranSet
= 0x00fe0000;
602 *vmesa
->regTranSet
= 0x00fe0000;
603 *vmesa
->regTranSpace
= 0x00000006;
604 *vmesa
->regTranSpace
= 0x40008c0f;
605 *vmesa
->regTranSpace
= 0x44000000;
606 *vmesa
->regTranSpace
= 0x45080c04;
607 *vmesa
->regTranSpace
= 0x46800408;
610 /*=* John Sheng [2003.5.31] flip *=*/
611 if(vmesa
->doPageFlip
) {
612 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x43c)) = 0x00fe0000;
613 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x440)) = 0x00001004;
615 *((volatile GLuint
*)((GLuint
)vmesa
->regMMIOBase
+ 0x214)) = 0;
617 /*=* John Sheng [2003.5.31] agp tex *=*/
618 if(VIA_DEBUG
) fprintf(stderr
, "agpFullCount = %d\n", agpFullCount
);
620 _swsetup_DestroyContext(vmesa
->glCtx
);
621 _tnl_DestroyContext(vmesa
->glCtx
);
622 _ac_DestroyContext(vmesa
->glCtx
);
623 _swrast_DestroyContext(vmesa
->glCtx
);
624 viaFreeVB(vmesa
->glCtx
);
626 /* free the Mesa context */
627 _mesa_destroy_context(vmesa
->glCtx
);
628 vmesa
->glCtx
->DriverCtx
= NULL
;
634 #ifdef PERFORMANCE_MEASURE
635 if (VIA_PERFORMANCE
) fprintf(stderr
, "idle = %d\n", idle
);
636 if (VIA_PERFORMANCE
) fprintf(stderr
, "busy = %d\n", busy
);
639 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
643 void viaXMesaSetFrontClipRects(viaContextPtr vmesa
)
645 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
647 vmesa
->numClipRects
= dPriv
->numClipRects
;
648 vmesa
->pClipRects
= dPriv
->pClipRects
;
649 vmesa
->drawX
= dPriv
->x
;
650 vmesa
->drawY
= dPriv
->y
;
651 vmesa
->drawW
= dPriv
->w
;
652 vmesa
->drawH
= dPriv
->h
;
654 viaEmitDrawingRectangle(vmesa
);
655 vmesa
->uploadCliprects
= GL_TRUE
;
658 void viaXMesaSetBackClipRects(viaContextPtr vmesa
)
660 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
661 /*=* John Sheng [2003.6.9] fix glxgears dirty screen */
662 /*if (vmesa->saam) {*/
663 vmesa
->numClipRects
= dPriv
->numClipRects
;
664 vmesa
->pClipRects
= dPriv
->pClipRects
;
665 vmesa
->drawX
= dPriv
->x
;
666 vmesa
->drawY
= dPriv
->y
;
667 vmesa
->drawW
= dPriv
->w
;
668 vmesa
->drawH
= dPriv
->h
;
671 if (dPriv->numBackClipRects == 0) {
672 vmesa->numClipRects = dPriv->numClipRects;
673 vmesa->pClipRects = dPriv->pClipRects;
674 vmesa->drawX = dPriv->x;
675 vmesa->drawY = dPriv->y;
676 vmesa->drawW = dPriv->w;
677 vmesa->drawH = dPriv->h;
680 vmesa->numClipRects = dPriv->numBackClipRects;
681 vmesa->pClipRects = dPriv->pBackClipRects;
682 vmesa->drawX = dPriv->backX;
683 vmesa->drawY = dPriv->backY;
684 vmesa->drawW = dPriv->w;
685 vmesa->drawH = dPriv->h;
688 viaEmitDrawingRectangle(vmesa
);
689 vmesa
->uploadCliprects
= GL_TRUE
;
692 void viaXMesaWindowMoved(viaContextPtr vmesa
)
694 GLuint bytePerPixel
= vmesa
->viaScreen
->bitsPerPixel
>> 3;
696 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
698 switch (vmesa
->glCtx
->Color
._DrawDestMask
) {
699 case __GL_FRONT_BUFFER_MASK
:
700 viaXMesaSetFrontClipRects(vmesa
);
702 case __GL_BACK_BUFFER_MASK
:
703 viaXMesaSetBackClipRects(vmesa
);
710 vmesa
->viaScreen
->fbOffset
= 0;
714 side
= vmesa
->saam
& P_MASK
;
718 /* full in screen 1 */
719 if (vmesa
->drawX
>= vmesa
->xsi
[0].width
) {
720 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
721 vmesa
->drawX
= vmesa
->drawX
- vmesa
->xsi
[1].width
;
722 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
723 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
724 vmesa
->drawX
= dPriv
->backX
;
725 vmesa
->drawY
= dPriv
->backY
;
729 /* full in screen 0 */
730 else if ((vmesa
->drawX
+ vmesa
->drawW
) <= vmesa
->xsi
[0].width
) {
731 vmesa
->viaScreen
->fbOffset
= 0;
735 /* between screen 0 && screen 1 */
737 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
738 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
739 vmesa
->drawXSaam
= dPriv
->backX
;
740 vmesa
->drawYSaam
= dPriv
->backY
;
741 vmesa
->viaScreen
->fbOffset
= 0;
747 /* full in screen 1 */
748 if (vmesa
->drawX
+ vmesa
->drawW
<= 0) {
749 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
750 vmesa
->drawX
= vmesa
->drawX
+ vmesa
->xsi
[1].width
;
751 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
752 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
753 vmesa
->drawX
= dPriv
->backX
;
754 vmesa
->drawY
= dPriv
->backY
;
758 /* full in screen 0 */
759 else if (vmesa
->drawX
>= 0) {
760 vmesa
->viaScreen
->fbOffset
= 0;
764 /* between screen 0 && screen 1 */
766 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
767 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
768 vmesa
->drawXSaam
= dPriv
->backX
;
769 vmesa
->drawYSaam
= dPriv
->backY
;
770 vmesa
->viaScreen
->fbOffset
= 0;
776 /* full in screen 1 */
777 if (vmesa
->drawY
>= vmesa
->xsi
[0].height
) {
778 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
779 vmesa
->drawY
= vmesa
->drawY
- vmesa
->xsi
[1].height
;
780 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
781 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
782 vmesa
->drawX
= dPriv
->backX
;
783 vmesa
->drawY
= dPriv
->backY
;
787 /* full in screen 0 */
788 else if ((vmesa
->drawY
+ vmesa
->drawH
) <= vmesa
->xsi
[0].height
) {
789 vmesa
->viaScreen
->fbOffset
= 0;
793 /* between screen 0 && screen 1 */
795 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
796 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
797 vmesa
->drawXSaam
= dPriv
->backX
;
798 vmesa
->drawYSaam
= dPriv
->backY
;
799 vmesa
->viaScreen
->fbOffset
= 0;
805 /* full in screen 1 */
806 if ((vmesa
->drawY
+ vmesa
->drawH
) <= 0) {
807 vmesa
->viaScreen
->fbOffset
= vmesa
->viaScreen
->fbSize
;
808 vmesa
->drawY
= vmesa
->drawY
+ vmesa
->xsi
[1].height
;
809 vmesa
->numClipRects
= dPriv
->numBackClipRects
;
810 vmesa
->pClipRects
= dPriv
->pBackClipRects
;
811 vmesa
->drawX
= dPriv
->backX
;
812 vmesa
->drawY
= dPriv
->backY
;
816 /* full in screen 0 */
817 else if (vmesa
->drawY
>= 0) {
818 vmesa
->viaScreen
->fbOffset
= 0;
822 /* between screen 0 && screen 1 */
824 vmesa
->numSaamRects
= dPriv
->numBackClipRects
;
825 vmesa
->pSaamRects
= dPriv
->pBackClipRects
;
826 vmesa
->drawXSaam
= dPriv
->backX
;
827 vmesa
->drawYSaam
= dPriv
->backY
;
828 vmesa
->viaScreen
->fbOffset
= 0;
834 vmesa
->viaScreen
->fbOffset
= 0;
839 GLuint pitch
, offset
;
840 pitch
= vmesa
->front
.pitch
;
841 offset
= vmesa
->viaScreen
->fbOffset
+ (vmesa
->drawY
* pitch
+ vmesa
->drawX
* bytePerPixel
);
842 vmesa
->drawXoff
= (GLuint
)((offset
& 0x1f) / bytePerPixel
);
844 if (vmesa
->pSaamRects
) {
845 offset
= vmesa
->viaScreen
->fbOffset
+ (vmesa
->pSaamRects
[0].y1
* pitch
+
846 vmesa
->pSaamRects
[0].x1
* bytePerPixel
);
847 vmesa
->drawXoffSaam
= (GLuint
)((offset
& 0x1f) / bytePerPixel
);
850 vmesa
->drawXoffSaam
= 0;
853 vmesa
->drawXoffSaam
= 0;
856 vmesa
->glCtx
->Driver
.Viewport(vmesa
->glCtx
,0 ,0 ,0 ,0);
860 viaUnbindContext(__DRIcontextPrivate
*driContextPriv
)
863 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
864 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
870 viaMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
871 __DRIdrawablePrivate
*driDrawPriv
,
872 __DRIdrawablePrivate
*driReadPriv
)
875 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
878 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driContextPriv
);
879 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driDrawPriv
);
880 fprintf(stderr
, "driContextPriv = %08x\n", (GLuint
)driReadPriv
);
884 if (driContextPriv
) {
885 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
886 current_mesa
= vmesa
;
888 vmesa
->driDrawable
= driDrawPriv
;
889 if (vmesa
->drawType
== GLX_PBUFFER_BIT
) {
892 w
= vmesa
->driDrawable
->w
;
893 h
= vmesa
->driDrawable
->h
;
894 bpp
= vmesa
->viaScreen
->bitsPerPixel
;
896 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
897 vmesa
->front
.size
= w
* h
* bpp
/ 8;
898 vmesa
->front
.pitch
= w
<< 2;
901 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2;
902 vmesa
->front
.size
= w
* h
* bpp
/ 8;
903 vmesa
->front
.pitch
= w
<< 1;
906 /*=* John Sheng [2003.6.20] fix resolution 720x480/720x576 front pitch error *=*/
911 bpp
= vmesa
->viaScreen
->bitsPerPixel
;
912 h
= vmesa
->viaScreen
->height
;
913 w
= vmesa
->viaScreen
->width
;
915 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
916 vmesa
->front
.size
= w
* h
* bpp
/ 8;
917 vmesa
->front
.pitch
= w
<< 2;
919 if (VIA_DEBUG
) fprintf(stderr
, "viaScreen->bitsPerPixel = %d\n", 32);
922 else if (bpp
== 0x10) {
923 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2;
924 vmesa
->front
.size
= w
* h
* bpp
/ 8;
925 vmesa
->front
.pitch
= w
<< 1;
927 if (VIA_DEBUG
) fprintf(stderr
, "viaScreen->bitsPerPixel = %d\n", 16);
930 vmesa
->front
.offset
= 0;
931 vmesa
->front
.map
= (char *) vmesa
->driScreen
->pFB
;
932 vmesa
->front
.size
= w
* h
* vmesa
->viaScreen
->bitsPerPixel
/8;
935 /* Allocate back & depth buffer */
939 w
= vmesa
->driDrawable
->w
;
941 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent: w = %d\n", w
);
943 h
= vmesa
->driDrawable
->h
;
946 bpp
= vmesa
->viaScreen
->bitsPerPixel
;
948 if (VIA_DEBUG
) fprintf(stderr
, "driScreen->fbBPP = %d\n", bpp
);
951 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
952 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
954 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
956 vmesa
->back
.size
= w
* h
* bpp
/ 8;
957 vmesa
->back
.pitch
= w
<< 2;
960 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
961 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2;
963 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2 + 16;
965 vmesa
->back
.size
= w
* h
* bpp
/ 8;
966 vmesa
->back
.pitch
= w
<< 1;
969 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent backbuffer: w = %d h = %d bpp = %d sizs = %d\n",
970 w
, h
, bpp
, vmesa
->back
.size
);
973 w
= vmesa
->driDrawable
->w
;
975 if (vmesa
->hasDepth
&& vmesa
->hasStencil
) {
976 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
977 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
979 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
981 vmesa
->depth
.size
= w
* h
* 4;
982 vmesa
->depth
.pitch
= w
<< 2;
983 vmesa
->depth
.bpp
= 32;
985 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 24\n");
986 if (VIA_DEBUG
) fprintf(stderr
, "StencilBits = 8\n");
989 else if (vmesa
->hasDepth
) {
991 /*=* John Sheng [2003.6.16] patch viewperf drv-08 draw nothing */
992 /*if(vmesa->viaScreen->bitsPerPixel == 32)*/
993 /*vmesa->depthBits = 16;*/
995 if (vmesa
->depthBits
== 16) {
996 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
997 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2;
999 w
= BUFFER_ALIGN_WIDTH(w
* 2, BUFFER_ALIGNMENT
) / 2 + 16;
1001 vmesa
->depth
.size
= w
* h
* 2;
1002 vmesa
->depth
.pitch
= w
<< 1;
1003 vmesa
->depth
.bpp
= 16;
1005 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 16\n");
1009 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
1010 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
1012 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
1014 vmesa
->depth
.size
= w
* h
* 4;
1015 vmesa
->depth
.pitch
= w
<< 2;
1016 vmesa
->depth
.bpp
= 32;
1018 if (VIA_DEBUG
) fprintf(stderr
, "depthBits = 32\n");
1022 else if (vmesa
->hasStencil
) {
1023 if (vmesa
->drawType
== GLX_PBUFFER_BIT
)
1024 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4;
1026 w
= BUFFER_ALIGN_WIDTH(w
* 4, BUFFER_ALIGNMENT
) / 4 + 8;
1028 vmesa
->depth
.size
= w
* h
* 4;
1029 vmesa
->depth
.pitch
= w
<< 2;
1030 vmesa
->depth
.bpp
= 32;
1032 if (VIA_DEBUG
) fprintf(stderr
, "StencilBits = 8\n");
1036 if (VIA_DEBUG
) fprintf(stderr
, "viaMakeCurrent depthbuffer: w = %d h = %d bpp = %d sizs = %d\n",
1037 w
, h
, vmesa
->depth
.bpp
, vmesa
->depth
.size
);
1039 /*=* John Sheng [2003.5.31] flip *=*/
1041 viaContextPtr vmesa
= (viaContextPtr
)driContextPriv
->driverPrivate
;
1042 if(vmesa
->viaScreen
->width
== vmesa
->driDrawable
->w
&&
1043 vmesa
->viaScreen
->height
== vmesa
->driDrawable
->h
) {
1044 vmesa
->doPageFlip
= GL_FALSE
;
1045 vmesa
->currentPage
= 0;
1046 vmesa
->back
.pitch
= vmesa
->front
.pitch
;
1050 if (!AllocateBuffer(vmesa
)) {
1055 _mesa_make_current2(vmesa
->glCtx
,
1056 (GLframebuffer
*)driDrawPriv
->driverPrivate
,
1057 (GLframebuffer
*)driReadPriv
->driverPrivate
);
1059 if (VIA_DEBUG
) fprintf(stderr
, "Context %d MakeCurrent\n", vmesa
->hHWContext
);
1061 viaXMesaWindowMoved(vmesa
);
1062 if (!vmesa
->glCtx
->Viewport
.Width
)
1063 _mesa_set_viewport(vmesa
->glCtx
, 0, 0,
1064 driDrawPriv
->w
, driDrawPriv
->h
);
1067 _mesa_make_current(0,0);
1071 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1076 void viaGetLock(viaContextPtr vmesa
, GLuint flags
)
1078 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
1079 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
1080 drm_via_sarea_t
*sarea
= vmesa
->sarea
;
1081 int me
= vmesa
->hHWContext
;
1082 __DRIdrawablePrivate
*pdp
;
1083 __DRIscreenPrivate
*psp
;
1087 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1088 if (VIA_DEBUG
) fprintf(stderr
, "drmGetLock - in\n");
1090 drmGetLock(vmesa
->driFd
, vmesa
->hHWContext
, flags
);
1093 DRM_UNLOCK(psp
->fd
, &psp
->pSAREA
->lock
,
1094 pdp
->driContextPriv
->hHWContext
);
1095 DRM_SPINLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
1096 __driUtilUpdateDrawableInfo(dPriv
);
1097 DRM_SPINUNLOCK(&psp
->pSAREA
->drawable_lock
, psp
->drawLockID
);
1098 DRM_LIGHT_LOCK(psp
->fd
, &psp
->pSAREA
->lock
,
1099 pdp
->driContextPriv
->hHWContext
);
1102 if (sarea
->ctxOwner
!= me
) {
1103 vmesa
->uploadCliprects
= GL_TRUE
;
1104 sarea
->ctxOwner
= me
;
1107 viaXMesaWindowMoved(vmesa
);
1109 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1113 void viaLock(viaContextPtr vmesa
, GLuint flags
)
1115 __DRIdrawablePrivate
*dPriv
= vmesa
->driDrawable
;
1116 __DRIscreenPrivate
*sPriv
= vmesa
->driScreen
;
1118 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1120 /*=* John Sheng [2003.6.16] for xf43 */
1121 if(dPriv
->pStamp
== NULL
)
1122 dPriv
->pStamp
= &dPriv
->lastStamp
;
1124 if (*(dPriv
->pStamp
) != dPriv
->lastStamp
|| vmesa
->saam
) {
1126 scrn
= vmesa
->saam
& S_MASK
;
1128 DRM_SPINLOCK(&sPriv
->pSAREA
->drawable_lock
, sPriv
->drawLockID
);
1131 __driUtilUpdateDrawableInfo(dPriv
);
1133 DRI_VALIDATE_DRAWABLE_INFO_ONCE(dPriv
);
1135 viaXMesaWindowMoved(vmesa
);
1136 DRM_SPINUNLOCK(&sPriv
->pSAREA
->drawable_lock
, sPriv
->drawLockID
);
1139 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1144 void viaUnLock(viaContextPtr vmesa
, GLuint flags
)
1146 drm_via_sarea_t
*sarea
= vmesa
->sarea
;
1147 int me
= vmesa
->hHWContext
;
1150 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1151 if (VIA_DEBUG
) fprintf(stderr
, "sarea->ctxOwner = %d\n", sarea
->ctxOwner
);
1152 if (VIA_DEBUG
) fprintf(stderr
, "me = %d\n", me
);
1154 if (sarea
->ctxOwner
== me
) {
1155 sarea
->ctxOwner
= 0;
1158 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);
1163 viaSwapBuffers(__DRIdrawablePrivate
*drawablePrivate
)
1165 __DRIdrawablePrivate
*dPriv
= (__DRIdrawablePrivate
*)drawablePrivate
;
1167 if (VIA_DEBUG
) fprintf(stderr
, "%s - in\n", __FUNCTION__
);
1169 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
1170 viaContextPtr vmesa
;
1173 vmesa
= (viaContextPtr
)dPriv
->driContextPriv
->driverPrivate
;
1175 if (ctx
->Visual
.doubleBufferMode
) {
1176 _mesa_notifySwapBuffers(ctx
);
1177 if (vmesa
->doPageFlip
) {
1181 viaCopyBuffer(dPriv
);
1185 VIA_FIREVERTICES(vmesa
);
1188 _mesa_problem(NULL
, "viaSwapBuffers: drawable has no context!\n");
1191 if (VIA_DEBUG
) fprintf(stderr
, "%s - out\n", __FUNCTION__
);