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 static const char *const card_extensions
[] =
90 "GL_ARB_multitexture",
91 "GL_EXT_texture_lod_bias",
92 "GL_EXT_texture_env_add",
96 /* this is first function called in dirver*/
99 savageInitDriver(__DRIscreenPrivate
*sPriv
)
101 savageScreenPrivate
*savageScreen
;
102 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
105 /* Allocate the private area */
106 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
110 savageScreen
->driScrnPriv
= sPriv
;
111 sPriv
->private = (void *)savageScreen
;
113 savageScreen
->chipset
=gDRIPriv
->chipset
;
114 savageScreen
->width
=gDRIPriv
->width
;
115 savageScreen
->height
=gDRIPriv
->height
;
116 savageScreen
->mem
=gDRIPriv
->mem
;
117 savageScreen
->cpp
=gDRIPriv
->cpp
;
118 savageScreen
->zpp
=gDRIPriv
->zpp
;
119 savageScreen
->frontPitch
=gDRIPriv
->frontPitch
;
120 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
121 savageScreen
->frontBitmapDesc
= gDRIPriv
->frontBitmapDesc
;
123 if (gDRIPriv
->cpp
== 4)
124 savageScreen
->frontFormat
= DV_PF_8888
;
126 savageScreen
->frontFormat
= DV_PF_565
;
128 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
129 savageScreen
->backBitmapDesc
= gDRIPriv
->backBitmapDesc
;
130 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
131 savageScreen
->depthBitmapDesc
= gDRIPriv
->depthBitmapDesc
;
133 savageScreen
->backPitch
= gDRIPriv
->auxPitch
;
134 savageScreen
->backPitchBits
= gDRIPriv
->auxPitchBits
;
136 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
137 gDRIPriv
->textureOffset
;
138 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
139 gDRIPriv
->textureSize
;
140 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
141 gDRIPriv
->logTextureGranularity
;
143 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
144 gDRIPriv
->agpTextures
.handle
;
145 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
146 gDRIPriv
->agpTextures
.size
;
147 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
148 gDRIPriv
->logAgpTextureGranularity
;
150 savageScreen
->back
.handle
= gDRIPriv
->backbuffer
;
151 savageScreen
->back
.size
= gDRIPriv
->backbufferSize
;
152 savageScreen
->back
.map
=
153 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->backOffset
);
155 savageScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
156 savageScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
158 savageScreen
->depth
.map
=
159 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->depthOffset
);
161 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
163 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
164 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
166 savageDDFastPathInit();
167 savageDDTrifuncInit();
173 /* Accessed by dlsym from dri_mesa_init.c
176 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
178 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
182 sPriv
->private = NULL
;
186 GLvisual
*XMesaCreateVisual(Display
*dpy
,
187 __DRIscreenPrivate
*driScrnPriv
,
188 const XVisualInfo
*visinfo
,
189 const __GLXvisualConfig
*config
)
191 /* Drivers may change the args to _mesa_create_visual() in order to
192 * setup special visuals.
194 return _mesa_create_visual( config
->rgba
,
195 config
->doubleBuffer
,
197 _mesa_bitcount(visinfo
->red_mask
),
198 _mesa_bitcount(visinfo
->green_mask
),
199 _mesa_bitcount(visinfo
->blue_mask
),
204 config
->accumRedSize
,
205 config
->accumGreenSize
,
206 config
->accumBlueSize
,
207 config
->accumAlphaSize
,
208 0 /* num samples */ );
214 savageCreateContext( const __GLcontextModes
*mesaVis
,
215 __DRIcontextPrivate
*driContextPriv
,
216 void *sharedContextPrivate
)
218 GLcontext
*ctx
, *shareCtx
;
219 savageContextPtr imesa
;
220 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
221 struct dd_function_table functions
;
222 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
223 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
224 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
225 savageScreen
->sarea_priv_offset
);
226 GLuint maxTextureSize
, minTextureSize
, maxTextureLevels
;
228 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
233 /* Init default driver functions then plug in savage-specific texture
234 * functions that are needed as early as during context creation. */
235 _mesa_init_driver_functions( &functions
);
236 savageDDInitTextureFuncs( &functions
);
238 /* Allocate the Mesa context */
239 if (sharedContextPrivate
)
240 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
243 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
248 driContextPriv
->driverPrivate
= imesa
;
250 if (savageScreen
->chipset
>= S3_SAVAGE4
)
251 ctx
->Const
.MaxTextureUnits
= 2;
253 ctx
->Const
.MaxTextureUnits
= 1;
254 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
255 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
257 /* Set the maximum texture size small enough that we can guarentee
258 * that all texture units can bind a maximal texture and have them
261 if (savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] >
262 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
]) {
263 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
264 minTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
266 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
267 minTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
269 if (ctx
->Const
.MaxTextureUnits
== 2) {
270 /* How to distribute two maximum sized textures to two texture heaps?
271 * If the smaller heap is less then half the size of the bigger one
272 * then the maximum size is half the size of the bigger heap.
273 * Otherwise it's the size of the smaller heap. */
274 if (minTextureSize
< maxTextureSize
/ 2)
275 maxTextureSize
= maxTextureSize
/ 2;
277 maxTextureSize
= minTextureSize
;
279 for (maxTextureLevels
= 1; maxTextureLevels
<= 11; ++maxTextureLevels
) {
280 GLuint size
= 1 << maxTextureLevels
;
281 size
*= size
* 4; /* 4 bytes per texel */
282 size
*= 2; /* all mipmap levels together take roughly twice the size of
284 if (size
> maxTextureSize
)
287 ctx
->Const
.MaxTextureLevels
= maxTextureLevels
;
288 assert (ctx
->Const
.MaxTextureLevels
> 6); /*spec requires at least 64x64*/
291 ctx
->Const
.MinLineWidth
= 1.0;
292 ctx
->Const
.MinLineWidthAA
= 1.0;
293 ctx
->Const
.MaxLineWidth
= 3.0;
294 ctx
->Const
.MaxLineWidthAA
= 3.0;
295 ctx
->Const
.LineWidthGranularity
= 1.0;
300 imesa
->hHWContext
= driContextPriv
->hHWContext
;
301 imesa
->driFd
= sPriv
->fd
;
302 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
304 imesa
->savageScreen
= savageScreen
;
305 imesa
->driScreen
= sPriv
;
306 imesa
->sarea
= saPriv
;
307 imesa
->glBuffer
= NULL
;
311 /*The shadow pointer*/
312 imesa
->shadowPointer
=
313 (volatile GLuint
*)((((GLuint
)(&saPriv
->shadow_status
)) + 31) & 0xffffffe0L
) ;
314 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
315 imesa
->eventTag1
= (volatile GLuint
*)(imesa
->shadowPointer
+ 6);
316 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
317 imesa
->shadowCounter
= MAX_SHADOWCOUNTER
;
318 imesa
->shadowStatus
= GL_TRUE
;/*Will judge by 2d message */
320 if (drmMap(sPriv
->fd
,
321 gDRIPriv
->registers
.handle
,
322 gDRIPriv
->registers
.size
,
323 (drmAddress
*)&(gDRIPriv
->registers
.map
)) != 0)
326 sPriv
->private = NULL
;
330 if (drmMap(sPriv
->fd
,
331 gDRIPriv
->agpTextures
.handle
,
332 gDRIPriv
->agpTextures
.size
,
333 (drmAddress
*)&(gDRIPriv
->agpTextures
.map
)) != 0)
336 sPriv
->private = NULL
;
341 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
342 (drmAddress
)(gDRIPriv
->agpTextures
.map
);
346 gDRIPriv
->BCIcmdBuf
.map
= (drmAddress
*)
347 ((unsigned int)gDRIPriv
->registers
.map
+0x00010000);
349 imesa
->MMIO_BASE
= (GLuint
)gDRIPriv
->registers
.map
;
350 imesa
->BCIBase
= (GLuint
)gDRIPriv
->BCIcmdBuf
.map
;
352 savageScreen
->aperture
.handle
= gDRIPriv
->aperture
.handle
;
353 savageScreen
->aperture
.size
= gDRIPriv
->aperture
.size
;
354 if (drmMap(sPriv
->fd
,
355 savageScreen
->aperture
.handle
,
356 savageScreen
->aperture
.size
,
357 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
360 sPriv
->private = NULL
;
370 imesa
->apertureBase
[i
] = ((GLuint
)savageScreen
->aperture
.map
+
377 volatile unsigned int * tmp
;
379 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x850C);
382 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C40);
385 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C44);
388 tmp
=(volatile unsigned int *)(imesa
->MMIO_BASE
+ 0x48C48);
394 imesa
->aperturePitch
= gDRIPriv
->aperturePitch
;
397 /* change texHeap initialize to support two kind of texture heap*/
398 /* here is some parts of initialization, others in InitDriver() */
400 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
402 /*allocate texHeap for multi-tex*/
406 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
408 imesa
->texHeap
[i
] = mmInit( 0, savageScreen
->textureSize
[i
] );
409 make_empty_list(&imesa
->TexObjList
[i
]);
412 make_empty_list(&imesa
->SwappedOut
);
415 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
416 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
417 (1.0F
/0x10000):(1.0F
/0x1000000);
419 imesa
->vertex_dma_buffer
= NULL
;
421 /* Uninitialized vertex format. Force setting the vertex state in
424 imesa
->vertex_size
= 0;
428 imesa
->new_state
= ~0;
429 imesa
->RenderIndex
= ~0;
431 imesa
->lostContext
= GL_TRUE
;
432 imesa
->TextureMode
= ctx
->Texture
.Unit
[0].EnvMode
;
433 imesa
->CurrentTexObj
[0] = 0;
434 imesa
->CurrentTexObj
[1] = 0;
435 imesa
->texAge
[SAVAGE_CARD_HEAP
]=0;
436 imesa
->texAge
[SAVAGE_AGP_HEAP
]=0;
438 /* Initialize the software rasterizer and helper modules.
440 _swrast_CreateContext( ctx
);
441 _ac_CreateContext( ctx
);
442 _tnl_CreateContext( ctx
);
444 _swsetup_CreateContext( ctx
);
446 /* Install the customized pipeline:
449 _tnl_destroy_pipeline( ctx
);
450 _tnl_install_pipeline( ctx
, savage_pipeline
);
453 /* Configure swrast to match hardware characteristics:
455 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
456 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
457 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
458 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
460 ctx
->DriverCtx
= (void *) imesa
;
462 if (savageDMAInit(imesa
) == GL_FALSE
)
465 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
467 savageDDInitStateFuncs( ctx
);
468 savageDDInitSpanFuncs( ctx
);
469 savageDDInitDriverFuncs( ctx
);
470 savageDDInitIoctlFuncs( ctx
);
471 savageInitTriFuncs( ctx
);
473 savageDDInitState( imesa
);
475 driContextPriv
->driverPrivate
= (void *) imesa
;
481 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
483 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
485 assert (imesa
); /* should never be NULL */
487 savageTextureObjectPtr next_t
, t
;
491 /* update for multi-tex*/
494 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
495 foreach_s (t
, next_t
, &(imesa
->TexObjList
[i
]))
496 savageDestroyTexObj(imesa
, t
);
498 foreach_s (t
, next_t
, &(imesa
->SwappedOut
))
499 savageDestroyTexObj(imesa
, t
);
500 /*free the dma buffer*/
501 savageDMAClose(imesa
);
502 _swsetup_DestroyContext(imesa
->glCtx
);
503 _tnl_DestroyContext( imesa
->glCtx
);
504 _ac_DestroyContext( imesa
->glCtx
);
505 _swrast_DestroyContext( imesa
->glCtx
);
507 /* free the Mesa context */
508 imesa
->glCtx
->DriverCtx
= NULL
;
509 _mesa_destroy_context(imesa
->glCtx
);
511 /* no longer use vertex_dma_buf*/
517 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
518 __DRIdrawablePrivate
*driDrawPriv
,
519 const __GLcontextModes
*mesaVis
,
523 return GL_FALSE
; /* not implemented */
526 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
527 driDrawPriv
->driverPrivate
= (void *)
528 _mesa_create_framebuffer(mesaVis
,
529 GL_FALSE
, /* software depth buffer? */
531 mesaVis
->accumRedBits
> 0,
532 mesaVis
->alphaBits
> 0 );
534 return (driDrawPriv
->driverPrivate
!= NULL
);
539 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
541 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
545 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
547 /* XXX should do swap according to the buffer, not the context! */
548 savageContextPtr imesa
= savageCtx
;
550 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
551 savageSwapBuffers(imesa
);
555 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
557 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
559 imesa
->numClipRects
= dPriv
->numClipRects
;
560 imesa
->pClipRects
= dPriv
->pClipRects
;
561 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
562 imesa
->drawX
= dPriv
->x
;
563 imesa
->drawY
= dPriv
->y
;
565 savageEmitDrawingRectangle( imesa
);
569 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
571 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
573 if (dPriv
->numBackClipRects
== 0)
577 imesa
->numClipRects
= dPriv
->numClipRects
;
578 imesa
->pClipRects
= dPriv
->pClipRects
;
579 imesa
->drawX
= dPriv
->x
;
580 imesa
->drawY
= dPriv
->y
;
584 imesa
->numClipRects
= dPriv
->numBackClipRects
;
585 imesa
->pClipRects
= dPriv
->pBackClipRects
;
586 imesa
->drawX
= dPriv
->backX
;
587 imesa
->drawY
= dPriv
->backY
;
590 savageEmitDrawingRectangle( imesa
);
591 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
597 static void savageXMesaWindowMoved( savageContextPtr imesa
)
600 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
602 switch (imesa
->glCtx
->Color
._DrawDestMask
[0]) {
603 case DD_FRONT_LEFT_BIT
:
604 savageXMesaSetFrontClipRects( imesa
);
606 case DD_BACK_LEFT_BIT
:
607 savageXMesaSetBackClipRects( imesa
);
616 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
618 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
627 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
632 if (driContextPriv
) {
633 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
634 imesa
->IsFullScreen
= GL_TRUE
;
635 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
636 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
637 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
638 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
639 imesa
->toggle
= TARGET_BACK
;
646 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
649 if (driContextPriv
) {
650 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
652 imesa
->IsFullScreen
= GL_FALSE
;
653 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
654 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
655 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
662 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
663 __DRIdrawablePrivate
*driDrawPriv
,
664 __DRIdrawablePrivate
*driReadPriv
)
666 if (driContextPriv
) {
667 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
669 imesa
->driReadable
= driReadPriv
;
670 imesa
->driDrawable
= driDrawPriv
;
671 imesa
->mesa_drawable
= driDrawPriv
;
674 _mesa_make_current2(imesa
->glCtx
,
675 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
676 (GLframebuffer
*) driReadPriv
->driverPrivate
);
678 savageXMesaWindowMoved( imesa
);
682 _mesa_make_current(NULL
, NULL
);
688 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
690 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
691 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
692 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
693 int me
= imesa
->hHWContext
;
694 int stamp
= dPriv
->lastStamp
;
699 /* We know there has been contention.
701 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
704 /* Note contention for throttling hint
706 imesa
->any_contend
= 1;
708 /* If the window moved, may need to set a new cliprect now.
710 * NOTE: This releases and regains the hw lock, so all state
711 * checking must be done *after* this call:
713 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
718 /* If we lost context, need to dump all registers to hardware.
719 * Note that we don't care about 2d contexts, even if they perform
720 * accelerated commands, so the DRI locking in the X server is even
721 * more broken than usual.
723 if (sarea
->ctxOwner
!= me
) {
724 imesa
->dirty
|= (SAVAGE_UPLOAD_CTX
|
725 SAVAGE_UPLOAD_CLIPRECTS
|
728 imesa
->lostContext
= GL_TRUE
;
729 sarea
->ctxOwner
= me
;
732 /* Shared texture managment - if another client has played with
733 * texture space, figure out which if any of our textures have been
734 * ejected, and update our global LRU.
736 /*frank just for compiling,texAge,texList,AGP*/
738 for(heap
= 0 ;heap
< imesa
->lastTexHeap
; heap
++)
740 if (sarea
->texAge
[heap
] != imesa
->texAge
[heap
]) {
741 int sz
= 1 << (imesa
->savageScreen
->logTextureGranularity
[heap
]);
744 /* Have to go right round from the back to ensure stuff ends up
745 * LRU in our local list...
747 for (idx
= sarea
->texList
[heap
][SAVAGE_NR_TEX_REGIONS
].prev
;
748 idx
!= SAVAGE_NR_TEX_REGIONS
&& nr
< SAVAGE_NR_TEX_REGIONS
;
749 idx
= sarea
->texList
[heap
][idx
].prev
, nr
++)
751 if (sarea
->texList
[heap
][idx
].age
> imesa
->texAge
[heap
])
753 savageTexturesGone(imesa
, heap
,idx
* sz
, sz
,
754 sarea
->texList
[heap
][idx
].in_use
);
758 if (nr
== SAVAGE_NR_TEX_REGIONS
)
760 savageTexturesGone(imesa
, heap
, 0,
761 imesa
->savageScreen
->textureSize
[heap
], 0);
762 savageResetGlobalLRU( imesa
, heap
);
765 imesa
->dirty
|= SAVAGE_UPLOAD_TEX0IMAGE
;
766 imesa
->dirty
|= SAVAGE_UPLOAD_TEX1IMAGE
;
767 imesa
->texAge
[heap
] = sarea
->texAge
[heap
];
769 } /* end of for loop */
771 if (dPriv
->lastStamp
!= stamp
)
772 savageXMesaWindowMoved( imesa
);
780 static const struct __DriverAPIRec savageAPI
= {
784 savageDestroyContext
,
794 #ifndef DRI_NEW_INTERFACE_ONLY
796 * This is the (old) bootstrap function for the driver.
797 * The __driCreateScreen name is the symbol that libGL.so fetches.
798 * Return: pointer to a __DRIscreenPrivate.
800 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
801 int numConfigs
, __GLXvisualConfig
*config
)
803 __DRIscreenPrivate
*psp
;
804 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);
807 #endif /* DRI_NEW_INTERFACE_ONLY */
811 #ifdef USE_NEW_INTERFACE
812 static __GLcontextModes
*
813 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
814 unsigned stencil_bits
, GLboolean have_back_buffer
)
816 __GLcontextModes
* modes
;
817 __GLcontextModes
* m
;
819 unsigned depth_buffer_factor
;
820 unsigned back_buffer_factor
;
824 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
825 * enough to add support. Basically, if a context is created with an
826 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
827 * will never be used.
829 * FK: What about drivers that don't use page flipping? Could they
830 * just expose GLX_SWAP_COPY_OML?
832 static const GLenum back_buffer_modes
[] = {
833 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
836 uint8_t depth_bits_array
[2];
837 uint8_t stencil_bits_array
[2];
840 depth_bits_array
[0] = depth_bits
;
841 depth_bits_array
[1] = depth_bits
;
843 /* Just like with the accumulation buffer, always provide some modes
844 * with a stencil buffer. It will be a sw fallback, but some apps won't
847 stencil_bits_array
[0] = 0;
848 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
850 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
851 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
853 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
855 if ( pixel_bits
== 16 ) {
857 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
861 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
864 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
866 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
867 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
868 back_buffer_modes
, back_buffer_factor
,
870 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
871 __func__
, __LINE__
);
875 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
876 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
877 back_buffer_modes
, back_buffer_factor
,
878 GLX_DIRECT_COLOR
) ) {
879 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
880 __func__
, __LINE__
);
884 /* Mark the visual as slow if there are "fake" stencil bits.
886 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
887 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
888 m
->visualRating
= GLX_SLOW_CONFIG
;
897 * This is the bootstrap function for the driver. libGL supplies all of the
898 * requisite information about the system, and the driver initializes itself.
899 * This routine also fills in the linked list pointed to by \c driver_modes
900 * with the \c __GLcontextModes that the driver can support for windows or
903 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
906 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
907 const __GLcontextModes
* modes
,
908 const __DRIversion
* ddx_version
,
909 const __DRIversion
* dri_version
,
910 const __DRIversion
* drm_version
,
911 const __DRIframebuffer
* frame_buffer
,
912 drmAddress pSAREA
, int fd
,
913 int internal_api_version
,
914 __GLcontextModes
** driver_modes
)
917 __DRIscreenPrivate
*psp
;
918 static const __DRIversion ddx_expected
= { 1, 0, 0 };
919 static const __DRIversion dri_expected
= { 4, 0, 0 };
920 static const __DRIversion drm_expected
= { 1, 0, 0 };
923 if ( ! driCheckDriDdxDrmVersions2( "Savage",
924 dri_version
, & dri_expected
,
925 ddx_version
, & ddx_expected
,
926 drm_version
, & drm_expected
) ) {
930 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
931 ddx_version
, dri_version
, drm_version
,
932 frame_buffer
, pSAREA
, fd
,
933 internal_api_version
, &savageAPI
);
935 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
936 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
937 if ( create_context_modes
!= NULL
) {
938 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
939 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
940 (dri_priv
->cpp
== 2) ? 16 : 24,
941 (dri_priv
->cpp
== 2) ? 0 : 8,
942 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
948 #endif /* USE_NEW_INTERFACE */