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.
26 #ifdef GLX_DIRECT_RENDERING
28 #include <X11/Xlibint.h>
31 #include "savagecontext.h"
35 #include "simple_list.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
42 #include "array_cache/acache.h"
44 #include "tnl/t_pipeline.h"
46 #include "drivers/common/driverfuncs.h"
49 #include "savagestate.h"
50 #include "savagetex.h"
51 #include "savagespan.h"
52 #include "savagetris.h"
53 #include "savageioctl.h"
54 #include "savage_bci.h"
56 #include "savage_dri.h"
58 #include "savagedma.h"
60 #ifdef USE_NEW_INTERFACE
61 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
62 #endif /* USE_NEW_INTERFACE */
66 /* | DEBUG_ALWAYS_SYNC */
67 /* | DEBUG_VERBOSE_RING */
68 /* | DEBUG_VERBOSE_OUTREG */
69 /* | DEBUG_VERBOSE_MSG */
70 /* | DEBUG_NO_OUTRING */
71 /* | DEBUG_NO_OUTREG */
72 /* | DEBUG_VERBOSE_API */
73 /* | DEBUG_VERBOSE_2D */
74 /* | DEBUG_VERBOSE_DRI */
75 /* | DEBUG_VALIDATE_RING */
76 /* | DEBUG_VERBOSE_IOCTL */
81 /*For time caculating test*/
82 #if defined(DEBUG_TIME) && DEBUG_TIME
83 struct timeval tv_s
,tv_f
;
84 unsigned long time_sum
=0;
85 struct timeval tv_s1
,tv_f1
;
88 /* this is first function called in dirver*/
91 savageInitDriver(__DRIscreenPrivate
*sPriv
)
93 savageScreenPrivate
*savageScreen
;
94 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
97 /* Allocate the private area */
98 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
102 savageScreen
->driScrnPriv
= sPriv
;
103 sPriv
->private = (void *)savageScreen
;
105 savageScreen
->chipset
=gDRIPriv
->chipset
;
106 savageScreen
->width
=gDRIPriv
->width
;
107 savageScreen
->height
=gDRIPriv
->height
;
108 savageScreen
->mem
=gDRIPriv
->mem
;
109 savageScreen
->cpp
=gDRIPriv
->cpp
;
110 savageScreen
->zpp
=gDRIPriv
->zpp
;
111 savageScreen
->frontPitch
=gDRIPriv
->frontPitch
;
112 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
113 savageScreen
->frontBitmapDesc
= gDRIPriv
->frontBitmapDesc
;
115 if (gDRIPriv
->cpp
== 4)
116 savageScreen
->frontFormat
= DV_PF_8888
;
118 savageScreen
->frontFormat
= DV_PF_565
;
120 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
121 savageScreen
->backBitmapDesc
= gDRIPriv
->backBitmapDesc
;
122 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
123 savageScreen
->depthBitmapDesc
= gDRIPriv
->depthBitmapDesc
;
125 savageScreen
->backPitch
= gDRIPriv
->auxPitch
;
126 savageScreen
->backPitchBits
= gDRIPriv
->auxPitchBits
;
128 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
129 gDRIPriv
->textureOffset
;
130 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
131 gDRIPriv
->textureSize
;
132 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
133 gDRIPriv
->logTextureGranularity
;
135 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
136 gDRIPriv
->agpTextures
.handle
;
137 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
138 gDRIPriv
->agpTextures
.size
;
139 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
140 gDRIPriv
->logAgpTextureGranularity
;
142 savageScreen
->back
.handle
= gDRIPriv
->backbuffer
;
143 savageScreen
->back
.size
= gDRIPriv
->backbufferSize
;
144 savageScreen
->back
.map
=
145 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->backOffset
);
147 savageScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
148 savageScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
150 savageScreen
->depth
.map
=
151 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->depthOffset
);
153 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
155 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
156 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
158 savageDDFastPathInit();
159 savageDDTrifuncInit();
165 /* Accessed by dlsym from dri_mesa_init.c
168 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
170 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
174 sPriv
->private = NULL
;
178 GLvisual
*XMesaCreateVisual(Display
*dpy
,
179 __DRIscreenPrivate
*driScrnPriv
,
180 const XVisualInfo
*visinfo
,
181 const __GLXvisualConfig
*config
)
183 /* Drivers may change the args to _mesa_create_visual() in order to
184 * setup special visuals.
186 return _mesa_create_visual( config
->rgba
,
187 config
->doubleBuffer
,
189 _mesa_bitcount(visinfo
->red_mask
),
190 _mesa_bitcount(visinfo
->green_mask
),
191 _mesa_bitcount(visinfo
->blue_mask
),
196 config
->accumRedSize
,
197 config
->accumGreenSize
,
198 config
->accumBlueSize
,
199 config
->accumAlphaSize
,
200 0 /* num samples */ );
206 savageCreateContext( const __GLcontextModes
*mesaVis
,
207 __DRIcontextPrivate
*driContextPriv
,
208 void *sharedContextPrivate
)
210 GLcontext
*ctx
, *shareCtx
;
211 savageContextPtr imesa
;
212 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
213 struct dd_function_table functions
;
214 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
215 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
216 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
217 savageScreen
->sarea_priv_offset
);
218 GLuint maxTextureSize
, minTextureSize
, maxTextureLevels
;
220 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
225 /* Init default driver functions then plug in savage-specific texture
226 * functions that are needed as early as during context creation. */
227 _mesa_init_driver_functions( &functions
);
228 savageDDInitTextureFuncs( &functions
);
230 /* Allocate the Mesa context */
231 if (sharedContextPrivate
)
232 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
235 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
240 driContextPriv
->driverPrivate
= imesa
;
242 if (savageScreen
->chipset
>= S3_SAVAGE4
)
243 ctx
->Const
.MaxTextureUnits
= 2;
245 ctx
->Const
.MaxTextureUnits
= 1;
246 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
247 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
249 /* Set the maximum texture size small enough that we can guarentee
250 * that all texture units can bind a maximal texture and have them
253 if (savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] >
254 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
]) {
255 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
256 minTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
258 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
259 minTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
261 if (ctx
->Const
.MaxTextureUnits
== 2) {
262 /* How to distribute two maximum sized textures to two texture heaps?
263 * If the smaller heap is less then half the size of the bigger one
264 * then the maximum size is half the size of the bigger heap.
265 * Otherwise it's the size of the smaller heap. */
266 if (minTextureSize
< maxTextureSize
/ 2)
267 maxTextureSize
= maxTextureSize
/ 2;
269 maxTextureSize
= minTextureSize
;
271 for (maxTextureLevels
= 1; maxTextureLevels
<= 11; ++maxTextureLevels
) {
272 GLuint size
= 1 << maxTextureLevels
;
273 size
*= size
* 4; /* 4 bytes per texel */
274 size
*= 2; /* all mipmap levels together take roughly twice the size of
276 if (size
> maxTextureSize
)
279 ctx
->Const
.MaxTextureLevels
= maxTextureLevels
;
280 assert (ctx
->Const
.MaxTextureLevels
> 6); /*spec requires at least 64x64*/
283 ctx
->Const
.MinLineWidth
= 1.0;
284 ctx
->Const
.MinLineWidthAA
= 1.0;
285 ctx
->Const
.MaxLineWidth
= 3.0;
286 ctx
->Const
.MaxLineWidthAA
= 3.0;
287 ctx
->Const
.LineWidthGranularity
= 1.0;
292 imesa
->hHWContext
= driContextPriv
->hHWContext
;
293 imesa
->driFd
= sPriv
->fd
;
294 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
296 imesa
->savageScreen
= savageScreen
;
297 imesa
->driScreen
= sPriv
;
298 imesa
->sarea
= saPriv
;
299 imesa
->glBuffer
= NULL
;
303 /*The shadow pointer*/
304 imesa
->shadowPointer
=
305 (volatile GLuint
*)((((GLuint
)(&saPriv
->shadow_status
)) + 31) & 0xffffffe0L
) ;
306 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
307 imesa
->eventTag1
= (volatile GLuint
*)(imesa
->shadowPointer
+ 6);
308 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
309 imesa
->shadowCounter
= MAX_SHADOWCOUNTER
;
310 imesa
->shadowStatus
= GL_TRUE
;/*Will judge by 2d message */
312 if (drmMap(sPriv
->fd
,
313 gDRIPriv
->registers
.handle
,
314 gDRIPriv
->registers
.size
,
315 (drmAddress
*)&(gDRIPriv
->registers
.map
)) != 0)
318 sPriv
->private = NULL
;
322 if (drmMap(sPriv
->fd
,
323 gDRIPriv
->agpTextures
.handle
,
324 gDRIPriv
->agpTextures
.size
,
325 (drmAddress
*)&(gDRIPriv
->agpTextures
.map
)) != 0)
328 sPriv
->private = NULL
;
333 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
334 (drmAddress
)(gDRIPriv
->agpTextures
.map
);
338 gDRIPriv
->BCIcmdBuf
.map
= (drmAddress
*)
339 ((unsigned int)gDRIPriv
->registers
.map
+0x00010000);
341 imesa
->MMIO_BASE
= (GLuint
)gDRIPriv
->registers
.map
;
342 imesa
->BCIBase
= (GLuint
)gDRIPriv
->BCIcmdBuf
.map
;
344 savageScreen
->aperture
.handle
= gDRIPriv
->aperture
.handle
;
345 savageScreen
->aperture
.size
= gDRIPriv
->aperture
.size
;
346 if (drmMap(sPriv
->fd
,
347 savageScreen
->aperture
.handle
,
348 savageScreen
->aperture
.size
,
349 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
352 sPriv
->private = NULL
;
362 imesa
->apertureBase
[i
] = ((GLuint
)savageScreen
->aperture
.map
+
369 volatile unsigned int * tmp
;
371 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x850C);
374 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C40);
377 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C44);
380 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C48);
386 imesa
->aperturePitch
= gDRIPriv
->aperturePitch
;
389 /* change texHeap initialize to support two kind of texture heap*/
390 /* here is some parts of initialization, others in InitDriver() */
392 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
394 /*allocate texHeap for multi-tex*/
398 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
400 imesa
->texHeap
[i
] = mmInit( 0, savageScreen
->textureSize
[i
] );
401 make_empty_list(&imesa
->TexObjList
[i
]);
404 make_empty_list(&imesa
->SwappedOut
);
407 imesa
->hw_stencil
= GL_FALSE
;
409 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
411 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
412 (1.0F
/0x10000):(1.0F
/0x1000000);
414 imesa
->vertex_dma_buffer
= NULL
;
416 /* Uninitialized vertex format. Force setting the vertex state in
419 imesa
->vertex_size
= 0;
423 imesa
->new_state
= ~0;
424 imesa
->RenderIndex
= ~0;
426 imesa
->lostContext
= GL_TRUE
;
427 imesa
->TextureMode
= ctx
->Texture
.Unit
[0].EnvMode
;
428 imesa
->CurrentTexObj
[0] = 0;
429 imesa
->CurrentTexObj
[1] = 0;
430 imesa
->texAge
[SAVAGE_CARD_HEAP
]=0;
431 imesa
->texAge
[SAVAGE_AGP_HEAP
]=0;
433 /* Initialize the software rasterizer and helper modules.
435 _swrast_CreateContext( ctx
);
436 _ac_CreateContext( ctx
);
437 _tnl_CreateContext( ctx
);
439 _swsetup_CreateContext( ctx
);
441 /* Install the customized pipeline:
444 _tnl_destroy_pipeline( ctx
);
445 _tnl_install_pipeline( ctx
, savage_pipeline
);
448 /* Configure swrast to match hardware characteristics:
450 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
451 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
452 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
453 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
455 ctx
->DriverCtx
= (void *) imesa
;
457 if (savageDMAInit(imesa
) == GL_FALSE
)
460 savageDDExtensionsInit( ctx
);
462 savageDDInitStateFuncs( ctx
);
463 savageDDInitSpanFuncs( ctx
);
464 savageDDInitDriverFuncs( ctx
);
465 savageDDInitIoctlFuncs( ctx
);
466 savageInitTriFuncs( ctx
);
468 savageDDInitState( imesa
);
470 driContextPriv
->driverPrivate
= (void *) imesa
;
476 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
478 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
480 assert (imesa
); /* should never be NULL */
482 savageTextureObjectPtr next_t
, t
;
486 /* update for multi-tex*/
489 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
490 foreach_s (t
, next_t
, &(imesa
->TexObjList
[i
]))
491 savageDestroyTexObj(imesa
, t
);
493 foreach_s (t
, next_t
, &(imesa
->SwappedOut
))
494 savageDestroyTexObj(imesa
, t
);
495 /*free the dma buffer*/
496 savageDMAClose(imesa
);
497 _swsetup_DestroyContext(imesa
->glCtx
);
498 _tnl_DestroyContext( imesa
->glCtx
);
499 _ac_DestroyContext( imesa
->glCtx
);
500 _swrast_DestroyContext( imesa
->glCtx
);
502 /* free the Mesa context */
503 imesa
->glCtx
->DriverCtx
= NULL
;
504 _mesa_destroy_context(imesa
->glCtx
);
506 /* no longer use vertex_dma_buf*/
512 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
513 __DRIdrawablePrivate
*driDrawPriv
,
514 const __GLcontextModes
*mesaVis
,
518 return GL_FALSE
; /* not implemented */
522 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
524 GLboolean swStencil
= mesaVis
->stencilBits
> 0;
526 driDrawPriv
->driverPrivate
= (void *)
527 _mesa_create_framebuffer(mesaVis
,
528 GL_FALSE
, /* software depth buffer? */
530 mesaVis
->accumRedBits
> 0,
531 mesaVis
->alphaBits
> 0 );
533 return (driDrawPriv
->driverPrivate
!= NULL
);
538 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
540 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
544 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
546 /* XXX should do swap according to the buffer, not the context! */
547 savageContextPtr imesa
= savageCtx
;
549 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
550 savageSwapBuffers(imesa
);
554 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
556 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
558 imesa
->numClipRects
= dPriv
->numClipRects
;
559 imesa
->pClipRects
= dPriv
->pClipRects
;
560 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
561 imesa
->drawX
= dPriv
->x
;
562 imesa
->drawY
= dPriv
->y
;
564 savageEmitDrawingRectangle( imesa
);
568 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
570 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
572 if (dPriv
->numBackClipRects
== 0)
576 imesa
->numClipRects
= dPriv
->numClipRects
;
577 imesa
->pClipRects
= dPriv
->pClipRects
;
578 imesa
->drawX
= dPriv
->x
;
579 imesa
->drawY
= dPriv
->y
;
583 imesa
->numClipRects
= dPriv
->numBackClipRects
;
584 imesa
->pClipRects
= dPriv
->pBackClipRects
;
585 imesa
->drawX
= dPriv
->backX
;
586 imesa
->drawY
= dPriv
->backY
;
589 savageEmitDrawingRectangle( imesa
);
590 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
596 static void savageXMesaWindowMoved( savageContextPtr imesa
)
599 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
601 switch (imesa
->glCtx
->Color
._DrawDestMask
) {
602 case DD_FRONT_LEFT_BIT
:
603 savageXMesaSetFrontClipRects( imesa
);
605 case DD_BACK_LEFT_BIT
:
606 savageXMesaSetBackClipRects( imesa
);
615 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
617 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
626 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
631 if (driContextPriv
) {
632 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
633 imesa
->IsFullScreen
= GL_TRUE
;
634 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
635 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
636 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
637 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
638 imesa
->toggle
= TARGET_BACK
;
645 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
648 if (driContextPriv
) {
649 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
651 imesa
->IsFullScreen
= GL_FALSE
;
652 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
653 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
654 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
661 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
662 __DRIdrawablePrivate
*driDrawPriv
,
663 __DRIdrawablePrivate
*driReadPriv
)
665 if (driContextPriv
) {
666 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
668 imesa
->driReadable
= driReadPriv
;
669 imesa
->driDrawable
= driDrawPriv
;
670 imesa
->mesa_drawable
= driDrawPriv
;
673 _mesa_make_current2(imesa
->glCtx
,
674 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
675 (GLframebuffer
*) driReadPriv
->driverPrivate
);
677 savageXMesaWindowMoved( imesa
);
679 if (!imesa
->glCtx
->Viewport
.Width
)
680 _mesa_set_viewport(imesa
->glCtx
, 0, 0,
681 driDrawPriv
->w
, driDrawPriv
->h
);
685 _mesa_make_current(NULL
, NULL
);
691 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
693 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
694 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
695 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
696 int me
= imesa
->hHWContext
;
697 int stamp
= dPriv
->lastStamp
;
702 /* We know there has been contention.
704 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
707 /* Note contention for throttling hint
709 imesa
->any_contend
= 1;
711 /* If the window moved, may need to set a new cliprect now.
713 * NOTE: This releases and regains the hw lock, so all state
714 * checking must be done *after* this call:
716 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
721 /* If we lost context, need to dump all registers to hardware.
722 * Note that we don't care about 2d contexts, even if they perform
723 * accelerated commands, so the DRI locking in the X server is even
724 * more broken than usual.
726 if (sarea
->ctxOwner
!= me
) {
727 imesa
->dirty
|= (SAVAGE_UPLOAD_CTX
|
728 SAVAGE_UPLOAD_CLIPRECTS
|
731 imesa
->lostContext
= GL_TRUE
;
732 sarea
->ctxOwner
= me
;
735 /* Shared texture managment - if another client has played with
736 * texture space, figure out which if any of our textures have been
737 * ejected, and update our global LRU.
739 /*frank just for compiling,texAge,texList,AGP*/
741 for(heap
= 0 ;heap
< imesa
->lastTexHeap
; heap
++)
743 if (sarea
->texAge
[heap
] != imesa
->texAge
[heap
]) {
744 int sz
= 1 << (imesa
->savageScreen
->logTextureGranularity
[heap
]);
747 /* Have to go right round from the back to ensure stuff ends up
748 * LRU in our local list...
750 for (idx
= sarea
->texList
[heap
][SAVAGE_NR_TEX_REGIONS
].prev
;
751 idx
!= SAVAGE_NR_TEX_REGIONS
&& nr
< SAVAGE_NR_TEX_REGIONS
;
752 idx
= sarea
->texList
[heap
][idx
].prev
, nr
++)
754 if (sarea
->texList
[heap
][idx
].age
> imesa
->texAge
[heap
])
756 savageTexturesGone(imesa
, heap
,idx
* sz
, sz
,
757 sarea
->texList
[heap
][idx
].in_use
);
761 if (nr
== SAVAGE_NR_TEX_REGIONS
)
763 savageTexturesGone(imesa
, heap
, 0,
764 imesa
->savageScreen
->textureSize
[heap
], 0);
765 savageResetGlobalLRU( imesa
, heap
);
768 imesa
->dirty
|= SAVAGE_UPLOAD_TEX0IMAGE
;
769 imesa
->dirty
|= SAVAGE_UPLOAD_TEX1IMAGE
;
770 imesa
->texAge
[heap
] = sarea
->texAge
[heap
];
772 } /* end of for loop */
774 if (dPriv
->lastStamp
!= stamp
)
775 savageXMesaWindowMoved( imesa
);
783 static const struct __DriverAPIRec savageAPI
= {
787 savageDestroyContext
,
797 #ifndef DRI_NEW_INTERFACE_ONLY
799 * This is the (old) bootstrap function for the driver.
800 * The __driCreateScreen name is the symbol that libGL.so fetches.
801 * Return: pointer to a __DRIscreenPrivate.
803 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
804 int numConfigs
, __GLXvisualConfig
*config
)
806 __DRIscreenPrivate
*psp
;
807 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);
810 #endif /* DRI_NEW_INTERFACE_ONLY */
814 #ifdef USE_NEW_INTERFACE
815 static __GLcontextModes
*
816 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
817 unsigned stencil_bits
, GLboolean have_back_buffer
)
819 __GLcontextModes
* modes
;
820 __GLcontextModes
* m
;
822 unsigned depth_buffer_factor
;
823 unsigned back_buffer_factor
;
827 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
828 * enough to add support. Basically, if a context is created with an
829 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
830 * will never be used.
832 * FK: What about drivers that don't use page flipping? Could they
833 * just expose GLX_SWAP_COPY_OML?
835 static const GLenum back_buffer_modes
[] = {
836 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
839 uint8_t depth_bits_array
[2];
840 uint8_t stencil_bits_array
[2];
843 depth_bits_array
[0] = depth_bits
;
844 depth_bits_array
[1] = depth_bits
;
846 /* Just like with the accumulation buffer, always provide some modes
847 * with a stencil buffer. It will be a sw fallback, but some apps won't
850 stencil_bits_array
[0] = 0;
851 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
853 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
854 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
856 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
858 if ( pixel_bits
== 16 ) {
860 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
864 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
867 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
869 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
870 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
871 back_buffer_modes
, back_buffer_factor
,
873 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
874 __func__
, __LINE__
);
878 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
879 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
880 back_buffer_modes
, back_buffer_factor
,
881 GLX_DIRECT_COLOR
) ) {
882 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
883 __func__
, __LINE__
);
887 /* Mark the visual as slow if there are "fake" stencil bits.
889 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
890 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
891 m
->visualRating
= GLX_SLOW_CONFIG
;
900 * This is the bootstrap function for the driver. libGL supplies all of the
901 * requisite information about the system, and the driver initializes itself.
902 * This routine also fills in the linked list pointed to by \c driver_modes
903 * with the \c __GLcontextModes that the driver can support for windows or
906 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
909 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
910 const __GLcontextModes
* modes
,
911 const __DRIversion
* ddx_version
,
912 const __DRIversion
* dri_version
,
913 const __DRIversion
* drm_version
,
914 const __DRIframebuffer
* frame_buffer
,
915 drmAddress pSAREA
, int fd
,
916 int internal_api_version
,
917 __GLcontextModes
** driver_modes
)
920 __DRIscreenPrivate
*psp
;
921 static const __DRIversion ddx_expected
= { 1, 0, 0 };
922 static const __DRIversion dri_expected
= { 4, 0, 0 };
923 static const __DRIversion drm_expected
= { 1, 0, 0 };
926 if ( ! driCheckDriDdxDrmVersions2( "Savage",
927 dri_version
, & dri_expected
,
928 ddx_version
, & ddx_expected
,
929 drm_version
, & drm_expected
) ) {
933 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
934 ddx_version
, dri_version
, drm_version
,
935 frame_buffer
, pSAREA
, fd
,
936 internal_api_version
, &savageAPI
);
938 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
939 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
940 if ( create_context_modes
!= NULL
) {
941 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
942 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
943 (dri_priv
->cpp
== 2) ? 16 : 24,
944 (dri_priv
->cpp
== 2) ? 0 : 8,
945 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
951 #endif /* USE_NEW_INTERFACE */