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"
60 /* Driver-specific options
62 #define SAVAGE_ENABLE_VDMA(def) \
63 DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
64 DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
65 DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
67 #define SAVAGE_ENABLE_FASTPATH(def) \
68 DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
69 DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
70 DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
75 PUBLIC
const char __driConfigOptions
[] =
77 DRI_CONF_SECTION_QUALITY
78 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
79 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
80 DRI_CONF_FLOAT_DEPTH(false)
82 DRI_CONF_SECTION_PERFORMANCE
83 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
84 SAVAGE_ENABLE_VDMA(true)
85 SAVAGE_ENABLE_FASTPATH(true)
87 DRI_CONF_SECTION_DEBUG
88 DRI_CONF_NO_RAST(false)
91 static const GLuint __driNConfigOptions
= 7;
93 #ifdef USE_NEW_INTERFACE
94 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
95 #endif /* USE_NEW_INTERFACE */
97 static const struct dri_debug_control debug_control
[] =
99 { "fall", DEBUG_FALLBACKS
},
100 { "api", DEBUG_VERBOSE_API
},
101 { "lru", DEBUG_VERBOSE_LRU
},
102 { "verb", DEBUG_VERBOSE_MSG
},
103 { "dma", DEBUG_DMA
},
104 { "state", DEBUG_STATE
},
108 int SAVAGE_DEBUG
= 0;
112 /*For time caculating test*/
113 #if defined(DEBUG_TIME) && DEBUG_TIME
114 struct timeval tv_s
,tv_f
;
115 unsigned long time_sum
=0;
116 struct timeval tv_s1
,tv_f1
;
119 static const char *const card_extensions
[] =
121 "GL_ARB_multitexture",
122 "GL_EXT_texture_lod_bias",
123 "GL_EXT_texture_env_add",
127 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
128 extern struct tnl_pipeline_stage _savage_render_stage
;
130 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
132 &_tnl_vertex_transform_stage
,
133 &_tnl_normal_transform_stage
,
134 &_tnl_lighting_stage
,
135 &_tnl_fog_coordinate_stage
,
137 &_tnl_texture_transform_stage
,
138 &_savage_texnorm_stage
,
139 &_savage_render_stage
,
145 /* this is first function called in dirver*/
148 savageInitDriver(__DRIscreenPrivate
*sPriv
)
150 savageScreenPrivate
*savageScreen
;
151 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
153 /* Allocate the private area */
154 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
158 savageScreen
->driScrnPriv
= sPriv
;
159 sPriv
->private = (void *)savageScreen
;
161 savageScreen
->chipset
=gDRIPriv
->chipset
;
162 savageScreen
->width
=gDRIPriv
->width
;
163 savageScreen
->height
=gDRIPriv
->height
;
164 savageScreen
->mem
=gDRIPriv
->mem
;
165 savageScreen
->cpp
=gDRIPriv
->cpp
;
166 savageScreen
->zpp
=gDRIPriv
->zpp
;
168 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
170 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
172 if (gDRIPriv
->cpp
== 4)
173 savageScreen
->frontFormat
= DV_PF_8888
;
175 savageScreen
->frontFormat
= DV_PF_565
;
176 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
177 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
178 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
180 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
181 gDRIPriv
->textureOffset
;
182 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
183 gDRIPriv
->textureSize
;
184 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
185 gDRIPriv
->logTextureGranularity
;
187 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
188 gDRIPriv
->agpTextureHandle
;
189 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
190 gDRIPriv
->agpTextureSize
;
191 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
192 gDRIPriv
->logAgpTextureGranularity
;
194 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
195 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
196 if (gDRIPriv
->agpTextureSize
) {
197 if (drmMap(sPriv
->fd
,
198 savageScreen
->agpTextures
.handle
,
199 savageScreen
->agpTextures
.size
,
200 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
202 sPriv
->private = NULL
;
206 savageScreen
->agpTextures
.map
= NULL
;
208 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
209 (drmAddress
)(((unsigned int)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
210 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
211 (drmAddress
)(savageScreen
->agpTextures
.map
);
213 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
214 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
215 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
216 if (drmMap(sPriv
->fd
,
217 savageScreen
->aperture
.handle
,
218 savageScreen
->aperture
.size
,
219 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
222 sPriv
->private = NULL
;
226 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
228 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
230 /* parse information in __driConfigOptions */
231 driParseOptionInfo (&savageScreen
->optionCache
,
232 __driConfigOptions
, __driNConfigOptions
);
235 savageDDFastPathInit();
236 savageDDTrifuncInit();
242 /* Accessed by dlsym from dri_mesa_init.c
245 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
247 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
249 drmUnmapBufs(savageScreen
->bufs
);
251 /* free all option information */
252 driDestroyOptionInfo (&savageScreen
->optionCache
);
255 sPriv
->private = NULL
;
259 GLvisual
*XMesaCreateVisual(Display
*dpy
,
260 __DRIscreenPrivate
*driScrnPriv
,
261 const XVisualInfo
*visinfo
,
262 const __GLXvisualConfig
*config
)
264 /* Drivers may change the args to _mesa_create_visual() in order to
265 * setup special visuals.
267 return _mesa_create_visual( config
->rgba
,
268 config
->doubleBuffer
,
270 _mesa_bitcount(visinfo
->red_mask
),
271 _mesa_bitcount(visinfo
->green_mask
),
272 _mesa_bitcount(visinfo
->blue_mask
),
277 config
->accumRedSize
,
278 config
->accumGreenSize
,
279 config
->accumBlueSize
,
280 config
->accumAlphaSize
,
281 0 /* num samples */ );
287 savageCreateContext( const __GLcontextModes
*mesaVis
,
288 __DRIcontextPrivate
*driContextPriv
,
289 void *sharedContextPrivate
)
291 GLcontext
*ctx
, *shareCtx
;
292 savageContextPtr imesa
;
293 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
294 struct dd_function_table functions
;
295 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
296 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
297 savageScreen
->sarea_priv_offset
);
298 GLuint maxTextureSize
, minTextureSize
, maxTextureLevels
;
300 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
305 /* Init default driver functions then plug in savage-specific texture
306 * functions that are needed as early as during context creation. */
307 _mesa_init_driver_functions( &functions
);
308 savageDDInitTextureFuncs( &functions
);
310 /* Allocate the Mesa context */
311 if (sharedContextPrivate
)
312 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
315 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
320 driContextPriv
->driverPrivate
= imesa
;
322 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
323 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
324 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
325 if (!imesa
->cmdBuf
.base
)
328 /* Parse configuration files */
329 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
330 sPriv
->myNum
, "savage");
332 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
333 savageScreen
->chipset
>= S3_SAVAGE4
;
334 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
335 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
337 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
338 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
339 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
341 if (savageScreen
->chipset
>= S3_SAVAGE4
)
342 ctx
->Const
.MaxTextureUnits
= 2;
344 ctx
->Const
.MaxTextureUnits
= 1;
345 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
346 ctx
->Const
.MaxTextureUnits
)
347 ctx
->Const
.MaxTextureUnits
=
348 driQueryOptioni(&imesa
->optionCache
, "texture_units");
349 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
350 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
352 /* Set the maximum texture size small enough that we can guarentee
353 * that all texture units can bind a maximal texture and have them
356 if (savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] >
357 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
]) {
358 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
359 minTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
361 maxTextureSize
= savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
362 minTextureSize
= savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
364 if (ctx
->Const
.MaxTextureUnits
== 2) {
365 /* How to distribute two maximum sized textures to two texture heaps?
366 * If the smaller heap is less then half the size of the bigger one
367 * then the maximum size is half the size of the bigger heap.
368 * Otherwise it's the size of the smaller heap. */
369 if (minTextureSize
< maxTextureSize
/ 2)
370 maxTextureSize
= maxTextureSize
/ 2;
372 maxTextureSize
= minTextureSize
;
374 for (maxTextureLevels
= 1; maxTextureLevels
<= 11; ++maxTextureLevels
) {
375 GLuint size
= 1 << maxTextureLevels
;
376 size
*= size
* 4; /* 4 bytes per texel */
377 size
= size
* 4/3; /* all mipmap levels together take roughly
378 4/3 the size of the biggest level */
379 if (size
> maxTextureSize
)
382 ctx
->Const
.MaxTextureLevels
= maxTextureLevels
;
383 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
384 __driUtilMessage("Not enough texture memory. "
385 "Falling back to indirect rendering.");
391 ctx
->Const
.MinLineWidth
= 1.0;
392 ctx
->Const
.MinLineWidthAA
= 1.0;
393 ctx
->Const
.MaxLineWidth
= 3.0;
394 ctx
->Const
.MaxLineWidthAA
= 3.0;
395 ctx
->Const
.LineWidthGranularity
= 1.0;
400 imesa
->hHWContext
= driContextPriv
->hHWContext
;
401 imesa
->driFd
= sPriv
->fd
;
402 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
404 imesa
->savageScreen
= savageScreen
;
405 imesa
->driScreen
= sPriv
;
406 imesa
->sarea
= saPriv
;
407 imesa
->glBuffer
= NULL
;
413 imesa
->apertureBase
[i
] = ((GLuint
)savageScreen
->aperture
.map
+
417 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
419 /* change texHeap initialize to support two kind of texture heap*/
420 /* here is some parts of initialization, others in InitDriver() */
422 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
424 /*allocate texHeap for multi-tex*/
428 for(i
=0;i
<imesa
->lastTexHeap
;i
++)
430 imesa
->texHeap
[i
] = mmInit( 0, savageScreen
->textureSize
[i
] );
431 make_empty_list(&imesa
->TexObjList
[i
]);
434 make_empty_list(&imesa
->SwappedOut
);
437 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
438 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
439 (1.0F
/0xffff):(1.0F
/0xffffff);
441 imesa
->bufferSize
= savageScreen
->bufferSize
;
442 imesa
->dmaVtxBuf
.total
= 0;
443 imesa
->dmaVtxBuf
.used
= 0;
444 imesa
->dmaVtxBuf
.flushed
= 0;
446 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
447 imesa
->clientVtxBuf
.used
= 0;
448 imesa
->clientVtxBuf
.flushed
= 0;
449 imesa
->clientVtxBuf
.buf
= (u_int32_t
*)malloc(imesa
->bufferSize
);
451 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
453 imesa
->firstElt
= -1;
455 /* Uninitialized vertex format. Force setting the vertex state in
458 imesa
->vertex_size
= 0;
462 imesa
->new_state
= ~0;
463 imesa
->new_gl_state
= ~0;
464 imesa
->RenderIndex
= ~0;
466 imesa
->lostContext
= GL_TRUE
;
467 imesa
->TextureMode
= ctx
->Texture
.Unit
[0].EnvMode
;
468 imesa
->CurrentTexObj
[0] = 0;
469 imesa
->CurrentTexObj
[1] = 0;
470 imesa
->texAge
[SAVAGE_CARD_HEAP
]=0;
471 imesa
->texAge
[SAVAGE_AGP_HEAP
]=0;
473 /* Initialize the software rasterizer and helper modules.
475 _swrast_CreateContext( ctx
);
476 _ac_CreateContext( ctx
);
477 _tnl_CreateContext( ctx
);
479 _swsetup_CreateContext( ctx
);
481 /* Install the customized pipeline:
483 _tnl_destroy_pipeline( ctx
);
484 _tnl_install_pipeline( ctx
, savage_pipeline
);
485 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
486 * support was added in 2.2.0. */
487 if (sPriv
->drmMinor
< 2) {
488 imesa
->enable_fastpath
= GL_FALSE
;
490 "*** Disabling fast path because your DRM version is buggy "
491 "or doesn't\n*** support ELTS. You need at least Savage DRM "
494 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
496 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
498 /* Configure swrast to match hardware characteristics:
500 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
501 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
502 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
503 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
505 ctx
->DriverCtx
= (void *) imesa
;
509 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
513 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
515 savageDDInitStateFuncs( ctx
);
516 savageDDInitSpanFuncs( ctx
);
517 savageDDInitDriverFuncs( ctx
);
518 savageDDInitIoctlFuncs( ctx
);
519 savageInitTriFuncs( ctx
);
521 savageDDInitState( imesa
);
523 driContextPriv
->driverPrivate
= (void *) imesa
;
529 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
531 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
533 assert (imesa
); /* should never be NULL */
535 savageTextureObjectPtr next_t
, t
;
537 savageFlushVertices(imesa
);
538 savageReleaseIndexedVerts(imesa
);
539 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
542 /* update for multi-tex*/
545 for(i
=0;i
<imesa
->lastTexHeap
;i
++)
546 foreach_s (t
, next_t
, &(imesa
->TexObjList
[i
]))
547 savageDestroyTexObj(imesa
, t
);
549 foreach_s (t
, next_t
, &(imesa
->SwappedOut
))
550 savageDestroyTexObj(imesa
, t
);
552 free(imesa
->cmdBuf
.base
);
553 free(imesa
->clientVtxBuf
.buf
);
555 _swsetup_DestroyContext(imesa
->glCtx
);
556 _tnl_DestroyContext( imesa
->glCtx
);
557 _ac_DestroyContext( imesa
->glCtx
);
558 _swrast_DestroyContext( imesa
->glCtx
);
560 /* free the Mesa context */
561 imesa
->glCtx
->DriverCtx
= NULL
;
562 _mesa_destroy_context(imesa
->glCtx
);
564 /* no longer use vertex_dma_buf*/
570 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
571 __DRIdrawablePrivate
*driDrawPriv
,
572 const __GLcontextModes
*mesaVis
,
576 return GL_FALSE
; /* not implemented */
579 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
580 driDrawPriv
->driverPrivate
= (void *)
581 _mesa_create_framebuffer(mesaVis
,
582 GL_FALSE
, /* software depth buffer? */
584 mesaVis
->accumRedBits
> 0,
585 mesaVis
->alphaBits
> 0 );
587 return (driDrawPriv
->driverPrivate
!= NULL
);
592 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
594 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
598 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
600 /* XXX should do swap according to the buffer, not the context! */
601 savageContextPtr imesa
= savageCtx
;
603 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
604 savageSwapBuffers(imesa
);
608 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
610 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
612 imesa
->numClipRects
= dPriv
->numClipRects
;
613 imesa
->pClipRects
= dPriv
->pClipRects
;
614 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
615 imesa
->drawX
= dPriv
->x
;
616 imesa
->drawY
= dPriv
->y
;
618 savageEmitDrawingRectangle( imesa
);
622 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
624 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
626 if (dPriv
->numBackClipRects
== 0)
630 imesa
->numClipRects
= dPriv
->numClipRects
;
631 imesa
->pClipRects
= dPriv
->pClipRects
;
632 imesa
->drawX
= dPriv
->x
;
633 imesa
->drawY
= dPriv
->y
;
637 imesa
->numClipRects
= dPriv
->numBackClipRects
;
638 imesa
->pClipRects
= dPriv
->pBackClipRects
;
639 imesa
->drawX
= dPriv
->backX
;
640 imesa
->drawY
= dPriv
->backY
;
643 savageEmitDrawingRectangle( imesa
);
644 imesa
->dirty
|= SAVAGE_UPLOAD_CLIPRECTS
;
650 static void savageXMesaWindowMoved( savageContextPtr imesa
)
653 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
655 switch (imesa
->glCtx
->Color
._DrawDestMask
[0]) {
656 case DD_FRONT_LEFT_BIT
:
657 savageXMesaSetFrontClipRects( imesa
);
659 case DD_BACK_LEFT_BIT
:
660 savageXMesaSetBackClipRects( imesa
);
669 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
671 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
680 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
685 if (driContextPriv
) {
686 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
687 imesa
->IsFullScreen
= GL_TRUE
;
688 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
689 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
690 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
691 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
692 imesa
->toggle
= TARGET_BACK
;
699 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
702 if (driContextPriv
) {
703 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
705 imesa
->IsFullScreen
= GL_FALSE
;
706 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
707 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
708 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
715 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
716 __DRIdrawablePrivate
*driDrawPriv
,
717 __DRIdrawablePrivate
*driReadPriv
)
719 if (driContextPriv
) {
720 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
722 imesa
->driReadable
= driReadPriv
;
723 imesa
->driDrawable
= driDrawPriv
;
724 imesa
->mesa_drawable
= driDrawPriv
;
727 _mesa_make_current2(imesa
->glCtx
,
728 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
729 (GLframebuffer
*) driReadPriv
->driverPrivate
);
731 savageXMesaWindowMoved( imesa
);
735 _mesa_make_current(NULL
, NULL
);
741 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
743 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
744 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
745 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
746 int me
= imesa
->hHWContext
;
747 int stamp
= dPriv
->lastStamp
;
752 /* We know there has been contention.
754 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
757 /* Note contention for throttling hint
759 imesa
->any_contend
= 1;
761 /* If the window moved, may need to set a new cliprect now.
763 * NOTE: This releases and regains the hw lock, so all state
764 * checking must be done *after* this call:
766 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
771 /* If we lost context, need to dump all registers to hardware.
772 * Note that we don't care about 2d contexts, even if they perform
773 * accelerated commands, so the DRI locking in the X server is even
774 * more broken than usual.
776 if (sarea
->ctxOwner
!= me
) {
777 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
778 SAVAGE_UPLOAD_GLOBAL
|
779 SAVAGE_UPLOAD_FOGTBL
|
782 SAVAGE_UPLOAD_TEXGLOBAL
|
783 SAVAGE_UPLOAD_CLIPRECTS
);
784 imesa
->lostContext
= GL_TRUE
;
785 sarea
->ctxOwner
= me
;
788 /* Shared texture managment - if another client has played with
789 * texture space, figure out which if any of our textures have been
790 * ejected, and update our global LRU.
792 /*frank just for compiling,texAge,texList,AGP*/
794 for(heap
= 0 ;heap
< imesa
->lastTexHeap
; heap
++)
796 if (sarea
->texAge
[heap
] != imesa
->texAge
[heap
]) {
797 int sz
= 1 << (imesa
->savageScreen
->logTextureGranularity
[heap
]);
800 /* Have to go right round from the back to ensure stuff ends up
801 * LRU in our local list...
803 for (idx
= sarea
->texList
[heap
][SAVAGE_NR_TEX_REGIONS
].prev
;
804 idx
!= SAVAGE_NR_TEX_REGIONS
&& nr
< SAVAGE_NR_TEX_REGIONS
;
805 idx
= sarea
->texList
[heap
][idx
].prev
, nr
++)
807 if (sarea
->texList
[heap
][idx
].age
> imesa
->texAge
[heap
])
809 savageTexturesGone(imesa
, heap
,idx
* sz
, sz
,
810 sarea
->texList
[heap
][idx
].in_use
);
814 if (nr
== SAVAGE_NR_TEX_REGIONS
)
816 savageTexturesGone(imesa
, heap
, 0,
817 imesa
->savageScreen
->textureSize
[heap
], 0);
818 savageResetGlobalLRU( imesa
, heap
);
821 imesa
->texAge
[heap
] = sarea
->texAge
[heap
];
823 } /* end of for loop */
825 if (dPriv
->lastStamp
!= stamp
)
826 savageXMesaWindowMoved( imesa
);
834 static const struct __DriverAPIRec savageAPI
= {
838 savageDestroyContext
,
848 #ifndef DRI_NEW_INTERFACE_ONLY
850 * This is the (old) bootstrap function for the driver.
851 * The __driCreateScreen name is the symbol that libGL.so fetches.
852 * Return: pointer to a __DRIscreenPrivate.
854 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
855 int numConfigs
, __GLXvisualConfig
*config
)
857 __DRIscreenPrivate
*psp
;
858 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);
861 #endif /* DRI_NEW_INTERFACE_ONLY */
865 #ifdef USE_NEW_INTERFACE
866 static __GLcontextModes
*
867 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
868 unsigned stencil_bits
, GLboolean have_back_buffer
)
870 __GLcontextModes
* modes
;
871 __GLcontextModes
* m
;
873 unsigned depth_buffer_factor
;
874 unsigned back_buffer_factor
;
878 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
879 * enough to add support. Basically, if a context is created with an
880 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
881 * will never be used.
883 * FK: What about drivers that don't use page flipping? Could they
884 * just expose GLX_SWAP_COPY_OML?
886 static const GLenum back_buffer_modes
[] = {
887 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
890 u_int8_t depth_bits_array
[2];
891 u_int8_t stencil_bits_array
[2];
894 depth_bits_array
[0] = depth_bits
;
895 depth_bits_array
[1] = depth_bits
;
897 /* Just like with the accumulation buffer, always provide some modes
898 * with a stencil buffer. It will be a sw fallback, but some apps won't
901 stencil_bits_array
[0] = 0;
902 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
904 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
905 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
907 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
909 if ( pixel_bits
== 16 ) {
911 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
915 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
918 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
920 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
921 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
922 back_buffer_modes
, back_buffer_factor
,
924 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
925 __func__
, __LINE__
);
929 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
930 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
931 back_buffer_modes
, back_buffer_factor
,
932 GLX_DIRECT_COLOR
) ) {
933 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
934 __func__
, __LINE__
);
938 /* Mark the visual as slow if there are "fake" stencil bits.
940 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
941 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
942 m
->visualRating
= GLX_SLOW_CONFIG
;
951 * This is the bootstrap function for the driver. libGL supplies all of the
952 * requisite information about the system, and the driver initializes itself.
953 * This routine also fills in the linked list pointed to by \c driver_modes
954 * with the \c __GLcontextModes that the driver can support for windows or
957 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
961 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
962 const __GLcontextModes
* modes
,
963 const __DRIversion
* ddx_version
,
964 const __DRIversion
* dri_version
,
965 const __DRIversion
* drm_version
,
966 const __DRIframebuffer
* frame_buffer
,
967 drmAddress pSAREA
, int fd
,
968 int internal_api_version
,
969 __GLcontextModes
** driver_modes
)
972 __DRIscreenPrivate
*psp
;
973 static const __DRIversion ddx_expected
= { 2, 0, 0 };
974 static const __DRIversion dri_expected
= { 4, 0, 0 };
975 static const __DRIversion drm_expected
= { 2, 0, 0 };
977 if ( ! driCheckDriDdxDrmVersions2( "Savage",
978 dri_version
, & dri_expected
,
979 ddx_version
, & ddx_expected
,
980 drm_version
, & drm_expected
) ) {
984 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
985 ddx_version
, dri_version
, drm_version
,
986 frame_buffer
, pSAREA
, fd
,
987 internal_api_version
, &savageAPI
);
989 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
990 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
991 if ( create_context_modes
!= NULL
) {
992 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
993 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
994 (dri_priv
->cpp
== 2) ? 16 : 24,
995 (dri_priv
->cpp
== 2) ? 0 : 8,
996 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1000 return (void *) psp
;
1002 #endif /* USE_NEW_INTERFACE */