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"
64 PUBLIC
const char __driConfigOptions
[] =
66 DRI_CONF_SECTION_QUALITY
67 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
68 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
70 DRI_CONF_SECTION_PERFORMANCE
71 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
74 static const GLuint __driNConfigOptions
= 3;
76 #ifdef USE_NEW_INTERFACE
77 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
78 #endif /* USE_NEW_INTERFACE */
82 /* | DEBUG_ALWAYS_SYNC */
83 /* | DEBUG_VERBOSE_RING */
84 /* | DEBUG_VERBOSE_OUTREG */
85 /* | DEBUG_VERBOSE_MSG */
86 /* | DEBUG_NO_OUTRING */
87 /* | DEBUG_NO_OUTREG */
88 /* | DEBUG_VERBOSE_API */
89 /* | DEBUG_VERBOSE_2D */
90 /* | DEBUG_VERBOSE_DRI */
91 /* | DEBUG_VALIDATE_RING */
92 /* | DEBUG_VERBOSE_IOCTL */
97 /*For time caculating test*/
98 #if defined(DEBUG_TIME) && DEBUG_TIME
99 struct timeval tv_s
,tv_f
;
100 unsigned long time_sum
=0;
101 struct timeval tv_s1
,tv_f1
;
104 static const char *const card_extensions
[] =
106 "GL_ARB_multitexture",
107 "GL_EXT_texture_lod_bias",
108 "GL_EXT_texture_env_add",
112 extern const struct tnl_pipeline_stage _savage_texnorm_stage
;
114 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
116 &_tnl_vertex_transform_stage
,
117 &_tnl_normal_transform_stage
,
118 &_tnl_lighting_stage
,
119 &_tnl_fog_coordinate_stage
,
121 &_tnl_texture_transform_stage
,
122 &_savage_texnorm_stage
,
128 /* this is first function called in dirver*/
131 savageInitDriver(__DRIscreenPrivate
*sPriv
)
133 savageScreenPrivate
*savageScreen
;
134 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
137 /* Allocate the private area */
138 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
142 savageScreen
->driScrnPriv
= sPriv
;
143 sPriv
->private = (void *)savageScreen
;
145 savageScreen
->chipset
=gDRIPriv
->chipset
;
146 savageScreen
->width
=gDRIPriv
->width
;
147 savageScreen
->height
=gDRIPriv
->height
;
148 savageScreen
->mem
=gDRIPriv
->mem
;
149 savageScreen
->cpp
=gDRIPriv
->cpp
;
150 savageScreen
->zpp
=gDRIPriv
->zpp
;
151 savageScreen
->frontPitch
=gDRIPriv
->frontPitch
;
152 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
153 savageScreen
->frontBitmapDesc
= gDRIPriv
->frontBitmapDesc
;
155 if (gDRIPriv
->cpp
== 4)
156 savageScreen
->frontFormat
= DV_PF_8888
;
158 savageScreen
->frontFormat
= DV_PF_565
;
160 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
161 savageScreen
->backBitmapDesc
= gDRIPriv
->backBitmapDesc
;
162 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
163 savageScreen
->depthBitmapDesc
= gDRIPriv
->depthBitmapDesc
;
165 savageScreen
->backPitch
= gDRIPriv
->auxPitch
;
166 savageScreen
->backPitchBits
= gDRIPriv
->auxPitchBits
;
168 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
169 gDRIPriv
->textureOffset
;
170 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
171 gDRIPriv
->textureSize
;
172 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
173 gDRIPriv
->logTextureGranularity
;
175 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
176 gDRIPriv
->agpTextures
.handle
;
177 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
178 gDRIPriv
->agpTextures
.size
;
179 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
180 gDRIPriv
->logAgpTextureGranularity
;
182 savageScreen
->back
.handle
= gDRIPriv
->backbuffer
;
183 savageScreen
->back
.size
= gDRIPriv
->backbufferSize
;
184 savageScreen
->back
.map
=
185 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->backOffset
);
187 savageScreen
->depth
.handle
= gDRIPriv
->depthbuffer
;
188 savageScreen
->depth
.size
= gDRIPriv
->depthbufferSize
;
190 savageScreen
->depth
.map
=
191 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->depthOffset
);
193 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
195 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
196 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
198 if (drmMap(sPriv
->fd
,
199 gDRIPriv
->registers
.handle
,
200 gDRIPriv
->registers
.size
,
201 (drmAddress
*)&(gDRIPriv
->registers
.map
)) != 0)
204 sPriv
->private = NULL
;
208 if (drmMap(sPriv
->fd
,
209 gDRIPriv
->agpTextures
.handle
,
210 gDRIPriv
->agpTextures
.size
,
211 (drmAddress
*)&(gDRIPriv
->agpTextures
.map
)) != 0)
214 sPriv
->private = NULL
;
219 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
220 (drmAddress
)(gDRIPriv
->agpTextures
.map
);
222 gDRIPriv
->BCIcmdBuf
.map
= (drmAddress
*)
223 ((unsigned int)gDRIPriv
->registers
.map
+0x00010000);
225 savageScreen
->aperture
.handle
= gDRIPriv
->aperture
.handle
;
226 savageScreen
->aperture
.size
= gDRIPriv
->aperture
.size
;
227 if (drmMap(sPriv
->fd
,
228 savageScreen
->aperture
.handle
,
229 savageScreen
->aperture
.size
,
230 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
233 sPriv
->private = NULL
;
237 /* parse information in __driConfigOptions */
238 driParseOptionInfo (&savageScreen
->optionCache
,
239 __driConfigOptions
, __driNConfigOptions
);
242 savageDDFastPathInit();
243 savageDDTrifuncInit();
249 /* Accessed by dlsym from dri_mesa_init.c
252 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
254 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
256 /* free all option information */
257 driDestroyOptionInfo (&savageScreen
->optionCache
);
260 sPriv
->private = NULL
;
264 GLvisual
*XMesaCreateVisual(Display
*dpy
,
265 __DRIscreenPrivate
*driScrnPriv
,
266 const XVisualInfo
*visinfo
,
267 const __GLXvisualConfig
*config
)
269 /* Drivers may change the args to _mesa_create_visual() in order to
270 * setup special visuals.
272 return _mesa_create_visual( config
->rgba
,
273 config
->doubleBuffer
,
275 _mesa_bitcount(visinfo
->red_mask
),
276 _mesa_bitcount(visinfo
->green_mask
),
277 _mesa_bitcount(visinfo
->blue_mask
),
282 config
->accumRedSize
,
283 config
->accumGreenSize
,
284 config
->accumBlueSize
,
285 config
->accumAlphaSize
,
286 0 /* num samples */ );
292 savageCreateContext( const __GLcontextModes
*mesaVis
,
293 __DRIcontextPrivate
*driContextPriv
,
294 void *sharedContextPrivate
)
296 GLcontext
*ctx
, *shareCtx
;
297 savageContextPtr imesa
;
298 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
299 struct dd_function_table functions
;
300 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
301 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
302 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
303 savageScreen
->sarea_priv_offset
);
304 GLuint maxTextureSize
, minTextureSize
, maxTextureLevels
;
306 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
311 /* Init default driver functions then plug in savage-specific texture
312 * functions that are needed as early as during context creation. */
313 _mesa_init_driver_functions( &functions
);
314 savageDDInitTextureFuncs( &functions
);
316 /* Allocate the Mesa context */
317 if (sharedContextPrivate
)
318 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
321 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
326 driContextPriv
->driverPrivate
= imesa
;
328 /* Parse configuration files */
329 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
330 sPriv
->myNum
, "savage");
332 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
334 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
335 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
336 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
338 if (savageScreen
->chipset
>= S3_SAVAGE4
)
339 ctx
->Const
.MaxTextureUnits
= 2;
341 ctx
->Const
.MaxTextureUnits
= 1;
342 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
343 ctx
->Const
.MaxTextureUnits
)
344 ctx
->Const
.MaxTextureUnits
=
345 driQueryOptioni(&imesa
->optionCache
, "texture_units");
346 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
347 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
349 /* Set the maximum texture size small enough that we can guarentee
350 * that all texture units can bind a maximal texture and have them
353 if (savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] >
354 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
]) {
355 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
356 minTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
358 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
359 minTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
361 if (ctx
->Const
.MaxTextureUnits
== 2) {
362 /* How to distribute two maximum sized textures to two texture heaps?
363 * If the smaller heap is less then half the size of the bigger one
364 * then the maximum size is half the size of the bigger heap.
365 * Otherwise it's the size of the smaller heap. */
366 if (minTextureSize
< maxTextureSize
/ 2)
367 maxTextureSize
= maxTextureSize
/ 2;
369 maxTextureSize
= minTextureSize
;
371 for (maxTextureLevels
= 1; maxTextureLevels
<= 11; ++maxTextureLevels
) {
372 GLuint size
= 1 << maxTextureLevels
;
373 size
*= size
* 4; /* 4 bytes per texel */
374 size
= size
* 4/3; /* all mipmap levels together take roughly
375 4/3 the size of the biggest level */
376 if (size
> maxTextureSize
)
379 ctx
->Const
.MaxTextureLevels
= maxTextureLevels
;
380 assert (ctx
->Const
.MaxTextureLevels
> 6); /*spec requires at least 64x64*/
383 ctx
->Const
.MinLineWidth
= 1.0;
384 ctx
->Const
.MinLineWidthAA
= 1.0;
385 ctx
->Const
.MaxLineWidth
= 3.0;
386 ctx
->Const
.MaxLineWidthAA
= 3.0;
387 ctx
->Const
.LineWidthGranularity
= 1.0;
392 imesa
->hHWContext
= driContextPriv
->hHWContext
;
393 imesa
->driFd
= sPriv
->fd
;
394 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
396 imesa
->savageScreen
= savageScreen
;
397 imesa
->driScreen
= sPriv
;
398 imesa
->sarea
= saPriv
;
399 imesa
->glBuffer
= NULL
;
403 /*The shadow pointer*/
404 imesa
->shadowPointer
=
405 (volatile GLuint
*)((((GLuint
)(&saPriv
->shadow_status
)) + 31) & 0xffffffe0L
) ;
406 /* here we use eventTag1 because eventTag0 is used by HWXvMC*/
407 imesa
->eventTag1
= (volatile GLuint
*)(imesa
->shadowPointer
+ 6);
408 /* imesa->eventTag1=(volatile GLuint *)(imesa->MMIO_BASE+0x48c04);*/
409 imesa
->shadowCounter
= MAX_SHADOWCOUNTER
;
410 imesa
->shadowStatus
= GL_TRUE
;/*Will judge by 2d message */
412 imesa
->MMIO_BASE
= (GLuint
)gDRIPriv
->registers
.map
;
413 imesa
->BCIBase
= (GLuint
)gDRIPriv
->BCIcmdBuf
.map
;
416 imesa
->apertureBase
[i
] = ((GLuint
)savageScreen
->aperture
.map
+
420 imesa
->aperturePitch
= gDRIPriv
->aperturePitch
;
423 /* change texHeap initialize to support two kind of texture heap*/
424 /* here is some parts of initialization, others in InitDriver() */
426 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
428 /*allocate texHeap for multi-tex*/
432 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
434 imesa
->texHeap
[i
] = mmInit( 0, savageScreen
->textureSize
[i
] );
435 make_empty_list(&imesa
->TexObjList
[i
]);
438 make_empty_list(&imesa
->SwappedOut
);
441 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
442 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
443 (1.0F
/0x10000):(1.0F
/0x1000000);
445 imesa
->vertex_dma_buffer
= NULL
;
447 /* Uninitialized vertex format. Force setting the vertex state in
450 imesa
->vertex_size
= 0;
454 imesa
->new_state
= ~0;
455 imesa
->RenderIndex
= ~0;
457 imesa
->lostContext
= GL_TRUE
;
458 imesa
->TextureMode
= ctx
->Texture
.Unit
[0].EnvMode
;
459 imesa
->CurrentTexObj
[0] = 0;
460 imesa
->CurrentTexObj
[1] = 0;
461 imesa
->texAge
[SAVAGE_CARD_HEAP
]=0;
462 imesa
->texAge
[SAVAGE_AGP_HEAP
]=0;
464 /* Initialize the software rasterizer and helper modules.
466 _swrast_CreateContext( ctx
);
467 _ac_CreateContext( ctx
);
468 _tnl_CreateContext( ctx
);
470 _swsetup_CreateContext( ctx
);
472 /* Install the customized pipeline:
475 _tnl_destroy_pipeline( ctx
);
476 _tnl_install_pipeline( ctx
, savage_pipeline
);
479 /* Configure swrast to match hardware characteristics:
481 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
482 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
483 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
484 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
486 ctx
->DriverCtx
= (void *) imesa
;
488 if (savageDMAInit(imesa
) == GL_FALSE
)
491 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
493 savageDDInitStateFuncs( ctx
);
494 savageDDInitSpanFuncs( ctx
);
495 savageDDInitDriverFuncs( ctx
);
496 savageDDInitIoctlFuncs( ctx
);
497 savageInitTriFuncs( ctx
);
499 savageDDInitState( imesa
);
501 driContextPriv
->driverPrivate
= (void *) imesa
;
507 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
509 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
511 assert (imesa
); /* should never be NULL */
513 savageTextureObjectPtr next_t
, t
;
517 /* update for multi-tex*/
520 for(i
=0;i
<SAVAGE_NR_TEX_HEAPS
;i
++)
521 foreach_s (t
, next_t
, &(imesa
->TexObjList
[i
]))
522 savageDestroyTexObj(imesa
, t
);
524 foreach_s (t
, next_t
, &(imesa
->SwappedOut
))
525 savageDestroyTexObj(imesa
, t
);
526 /*free the dma buffer*/
527 savageDMAClose(imesa
);
528 _swsetup_DestroyContext(imesa
->glCtx
);
529 _tnl_DestroyContext( imesa
->glCtx
);
530 _ac_DestroyContext( imesa
->glCtx
);
531 _swrast_DestroyContext( imesa
->glCtx
);
533 /* free the Mesa context */
534 imesa
->glCtx
->DriverCtx
= NULL
;
535 _mesa_destroy_context(imesa
->glCtx
);
537 /* no longer use vertex_dma_buf*/
543 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
544 __DRIdrawablePrivate
*driDrawPriv
,
545 const __GLcontextModes
*mesaVis
,
549 return GL_FALSE
; /* not implemented */
552 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
553 driDrawPriv
->driverPrivate
= (void *)
554 _mesa_create_framebuffer(mesaVis
,
555 GL_FALSE
, /* software depth buffer? */
557 mesaVis
->accumRedBits
> 0,
558 mesaVis
->alphaBits
> 0 );
560 return (driDrawPriv
->driverPrivate
!= NULL
);
565 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
567 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
571 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
573 /* XXX should do swap according to the buffer, not the context! */
574 savageContextPtr imesa
= savageCtx
;
576 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
577 savageSwapBuffers(imesa
);
581 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
583 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
585 imesa
->numClipRects
= dPriv
->numClipRects
;
586 imesa
->pClipRects
= dPriv
->pClipRects
;
587 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
588 imesa
->drawX
= dPriv
->x
;
589 imesa
->drawY
= dPriv
->y
;
591 savageEmitDrawingRectangle( imesa
);
595 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
597 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
599 if (dPriv
->numBackClipRects
== 0)
603 imesa
->numClipRects
= dPriv
->numClipRects
;
604 imesa
->pClipRects
= dPriv
->pClipRects
;
605 imesa
->drawX
= dPriv
->x
;
606 imesa
->drawY
= dPriv
->y
;
610 imesa
->numClipRects
= dPriv
->numBackClipRects
;
611 imesa
->pClipRects
= dPriv
->pBackClipRects
;
612 imesa
->drawX
= dPriv
->backX
;
613 imesa
->drawY
= dPriv
->backY
;
616 savageEmitDrawingRectangle( imesa
);
617 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
623 static void savageXMesaWindowMoved( savageContextPtr imesa
)
626 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
628 switch (imesa
->glCtx
->Color
._DrawDestMask
[0]) {
629 case DD_FRONT_LEFT_BIT
:
630 savageXMesaSetFrontClipRects( imesa
);
632 case DD_BACK_LEFT_BIT
:
633 savageXMesaSetBackClipRects( imesa
);
642 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
644 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
653 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
658 if (driContextPriv
) {
659 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
660 imesa
->IsFullScreen
= GL_TRUE
;
661 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
662 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
663 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
664 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
665 imesa
->toggle
= TARGET_BACK
;
672 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
675 if (driContextPriv
) {
676 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
678 imesa
->IsFullScreen
= GL_FALSE
;
679 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
680 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
681 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
688 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
689 __DRIdrawablePrivate
*driDrawPriv
,
690 __DRIdrawablePrivate
*driReadPriv
)
692 if (driContextPriv
) {
693 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
695 imesa
->driReadable
= driReadPriv
;
696 imesa
->driDrawable
= driDrawPriv
;
697 imesa
->mesa_drawable
= driDrawPriv
;
700 _mesa_make_current2(imesa
->glCtx
,
701 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
702 (GLframebuffer
*) driReadPriv
->driverPrivate
);
704 savageXMesaWindowMoved( imesa
);
708 _mesa_make_current(NULL
, NULL
);
714 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
716 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
717 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
718 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
719 int me
= imesa
->hHWContext
;
720 int stamp
= dPriv
->lastStamp
;
725 /* We know there has been contention.
727 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
730 /* Note contention for throttling hint
732 imesa
->any_contend
= 1;
734 /* If the window moved, may need to set a new cliprect now.
736 * NOTE: This releases and regains the hw lock, so all state
737 * checking must be done *after* this call:
739 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
744 /* If we lost context, need to dump all registers to hardware.
745 * Note that we don't care about 2d contexts, even if they perform
746 * accelerated commands, so the DRI locking in the X server is even
747 * more broken than usual.
749 if (sarea
->ctxOwner
!= me
) {
750 imesa
->dirty
|= (SAVAGE_UPLOAD_CTX
|
751 SAVAGE_UPLOAD_CLIPRECTS
|
754 imesa
->lostContext
= GL_TRUE
;
755 sarea
->ctxOwner
= me
;
758 /* Shared texture managment - if another client has played with
759 * texture space, figure out which if any of our textures have been
760 * ejected, and update our global LRU.
762 /*frank just for compiling,texAge,texList,AGP*/
764 for(heap
= 0 ;heap
< imesa
->lastTexHeap
; heap
++)
766 if (sarea
->texAge
[heap
] != imesa
->texAge
[heap
]) {
767 int sz
= 1 << (imesa
->savageScreen
->logTextureGranularity
[heap
]);
770 /* Have to go right round from the back to ensure stuff ends up
771 * LRU in our local list...
773 for (idx
= sarea
->texList
[heap
][SAVAGE_NR_TEX_REGIONS
].prev
;
774 idx
!= SAVAGE_NR_TEX_REGIONS
&& nr
< SAVAGE_NR_TEX_REGIONS
;
775 idx
= sarea
->texList
[heap
][idx
].prev
, nr
++)
777 if (sarea
->texList
[heap
][idx
].age
> imesa
->texAge
[heap
])
779 savageTexturesGone(imesa
, heap
,idx
* sz
, sz
,
780 sarea
->texList
[heap
][idx
].in_use
);
784 if (nr
== SAVAGE_NR_TEX_REGIONS
)
786 savageTexturesGone(imesa
, heap
, 0,
787 imesa
->savageScreen
->textureSize
[heap
], 0);
788 savageResetGlobalLRU( imesa
, heap
);
791 imesa
->dirty
|= SAVAGE_UPLOAD_TEX0IMAGE
;
792 imesa
->dirty
|= SAVAGE_UPLOAD_TEX1IMAGE
;
793 imesa
->texAge
[heap
] = sarea
->texAge
[heap
];
795 } /* end of for loop */
797 if (dPriv
->lastStamp
!= stamp
)
798 savageXMesaWindowMoved( imesa
);
806 static const struct __DriverAPIRec savageAPI
= {
810 savageDestroyContext
,
820 #ifndef DRI_NEW_INTERFACE_ONLY
822 * This is the (old) bootstrap function for the driver.
823 * The __driCreateScreen name is the symbol that libGL.so fetches.
824 * Return: pointer to a __DRIscreenPrivate.
826 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
827 int numConfigs
, __GLXvisualConfig
*config
)
829 __DRIscreenPrivate
*psp
;
830 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);
833 #endif /* DRI_NEW_INTERFACE_ONLY */
837 #ifdef USE_NEW_INTERFACE
838 static __GLcontextModes
*
839 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
840 unsigned stencil_bits
, GLboolean have_back_buffer
)
842 __GLcontextModes
* modes
;
843 __GLcontextModes
* m
;
845 unsigned depth_buffer_factor
;
846 unsigned back_buffer_factor
;
850 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
851 * enough to add support. Basically, if a context is created with an
852 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
853 * will never be used.
855 * FK: What about drivers that don't use page flipping? Could they
856 * just expose GLX_SWAP_COPY_OML?
858 static const GLenum back_buffer_modes
[] = {
859 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
862 u_int8_t depth_bits_array
[2];
863 u_int8_t stencil_bits_array
[2];
866 depth_bits_array
[0] = depth_bits
;
867 depth_bits_array
[1] = depth_bits
;
869 /* Just like with the accumulation buffer, always provide some modes
870 * with a stencil buffer. It will be a sw fallback, but some apps won't
873 stencil_bits_array
[0] = 0;
874 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
876 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
877 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
879 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
881 if ( pixel_bits
== 16 ) {
883 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
887 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
890 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
892 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
893 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
894 back_buffer_modes
, back_buffer_factor
,
896 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
897 __func__
, __LINE__
);
901 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
902 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
903 back_buffer_modes
, back_buffer_factor
,
904 GLX_DIRECT_COLOR
) ) {
905 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
906 __func__
, __LINE__
);
910 /* Mark the visual as slow if there are "fake" stencil bits.
912 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
913 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
914 m
->visualRating
= GLX_SLOW_CONFIG
;
923 * This is the bootstrap function for the driver. libGL supplies all of the
924 * requisite information about the system, and the driver initializes itself.
925 * This routine also fills in the linked list pointed to by \c driver_modes
926 * with the \c __GLcontextModes that the driver can support for windows or
929 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
933 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
934 const __GLcontextModes
* modes
,
935 const __DRIversion
* ddx_version
,
936 const __DRIversion
* dri_version
,
937 const __DRIversion
* drm_version
,
938 const __DRIframebuffer
* frame_buffer
,
939 drmAddress pSAREA
, int fd
,
940 int internal_api_version
,
941 __GLcontextModes
** driver_modes
)
944 __DRIscreenPrivate
*psp
;
945 static const __DRIversion ddx_expected
= { 1, 0, 0 };
946 static const __DRIversion dri_expected
= { 4, 0, 0 };
947 static const __DRIversion drm_expected
= { 1, 0, 0 };
950 if ( ! driCheckDriDdxDrmVersions2( "Savage",
951 dri_version
, & dri_expected
,
952 ddx_version
, & ddx_expected
,
953 drm_version
, & drm_expected
) ) {
957 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
958 ddx_version
, dri_version
, drm_version
,
959 frame_buffer
, pSAREA
, fd
,
960 internal_api_version
, &savageAPI
);
962 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
963 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
964 if ( create_context_modes
!= NULL
) {
965 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
966 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
967 (dri_priv
->cpp
== 2) ? 16 : 24,
968 (dri_priv
->cpp
== 2) ? 0 : 8,
969 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
975 #endif /* USE_NEW_INTERFACE */