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 #include <X11/Xlibint.h>
29 #include "savagecontext.h"
33 #include "simple_list.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "array_cache/acache.h"
42 #include "tnl/t_pipeline.h"
44 #include "drivers/common/driverfuncs.h"
47 #include "savagestate.h"
48 #include "savagetex.h"
49 #include "savagespan.h"
50 #include "savagetris.h"
51 #include "savageioctl.h"
52 #include "savage_bci.h"
54 #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") \
72 #define SAVAGE_SYNC_FRAMES(def) \
73 DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
74 DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
75 DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
80 PUBLIC
const char __driConfigOptions
[] =
82 DRI_CONF_SECTION_QUALITY
83 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
84 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
85 DRI_CONF_FLOAT_DEPTH(false)
87 DRI_CONF_SECTION_PERFORMANCE
88 SAVAGE_ENABLE_VDMA(true)
89 SAVAGE_ENABLE_FASTPATH(true)
90 SAVAGE_SYNC_FRAMES(false)
91 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
92 DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL
)
94 DRI_CONF_SECTION_DEBUG
95 DRI_CONF_NO_RAST(false)
98 static const GLuint __driNConfigOptions
= 9;
100 #ifdef USE_NEW_INTERFACE
101 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
102 #endif /* USE_NEW_INTERFACE */
104 static const struct dri_debug_control debug_control
[] =
106 { "fall", DEBUG_FALLBACKS
},
107 { "api", DEBUG_VERBOSE_API
},
108 { "tex", DEBUG_VERBOSE_TEX
},
109 { "verb", DEBUG_VERBOSE_MSG
},
110 { "dma", DEBUG_DMA
},
111 { "state", DEBUG_STATE
},
115 int SAVAGE_DEBUG
= 0;
119 /*For time caculating test*/
120 #if defined(DEBUG_TIME) && DEBUG_TIME
121 struct timeval tv_s
,tv_f
;
122 unsigned long time_sum
=0;
123 struct timeval tv_s1
,tv_f1
;
126 static const char *const card_extensions
[] =
128 "GL_ARB_multitexture",
129 "GL_EXT_texture_lod_bias",
130 "GL_EXT_texture_env_add",
134 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
135 extern struct tnl_pipeline_stage _savage_render_stage
;
137 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
139 &_tnl_vertex_transform_stage
,
140 &_tnl_normal_transform_stage
,
141 &_tnl_lighting_stage
,
142 &_tnl_fog_coordinate_stage
,
144 &_tnl_texture_transform_stage
,
145 &_savage_texnorm_stage
,
146 &_savage_render_stage
,
152 /* this is first function called in dirver*/
155 savageInitDriver(__DRIscreenPrivate
*sPriv
)
157 savageScreenPrivate
*savageScreen
;
158 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
160 /* Allocate the private area */
161 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
165 savageScreen
->driScrnPriv
= sPriv
;
166 sPriv
->private = (void *)savageScreen
;
168 savageScreen
->chipset
=gDRIPriv
->chipset
;
169 savageScreen
->width
=gDRIPriv
->width
;
170 savageScreen
->height
=gDRIPriv
->height
;
171 savageScreen
->mem
=gDRIPriv
->mem
;
172 savageScreen
->cpp
=gDRIPriv
->cpp
;
173 savageScreen
->zpp
=gDRIPriv
->zpp
;
175 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
177 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
179 if (gDRIPriv
->cpp
== 4)
180 savageScreen
->frontFormat
= DV_PF_8888
;
182 savageScreen
->frontFormat
= DV_PF_565
;
183 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
184 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
185 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
187 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
188 gDRIPriv
->textureOffset
;
189 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
190 gDRIPriv
->textureSize
;
191 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
192 gDRIPriv
->logTextureGranularity
;
194 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
195 gDRIPriv
->agpTextureHandle
;
196 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
197 gDRIPriv
->agpTextureSize
;
198 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
199 gDRIPriv
->logAgpTextureGranularity
;
201 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
202 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
203 if (gDRIPriv
->agpTextureSize
) {
204 if (drmMap(sPriv
->fd
,
205 savageScreen
->agpTextures
.handle
,
206 savageScreen
->agpTextures
.size
,
207 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
209 sPriv
->private = NULL
;
213 savageScreen
->agpTextures
.map
= NULL
;
215 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
216 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
217 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
218 (drmAddress
)(savageScreen
->agpTextures
.map
);
220 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
221 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
222 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
223 if (drmMap(sPriv
->fd
,
224 savageScreen
->aperture
.handle
,
225 savageScreen
->aperture
.size
,
226 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
229 sPriv
->private = NULL
;
233 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
235 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
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 if (savageScreen
->bufs
)
257 drmUnmapBufs(savageScreen
->bufs
);
259 /* free all option information */
260 driDestroyOptionInfo (&savageScreen
->optionCache
);
263 sPriv
->private = NULL
;
267 GLvisual
*XMesaCreateVisual(Display
*dpy
,
268 __DRIscreenPrivate
*driScrnPriv
,
269 const XVisualInfo
*visinfo
,
270 const __GLXvisualConfig
*config
)
272 /* Drivers may change the args to _mesa_create_visual() in order to
273 * setup special visuals.
275 return _mesa_create_visual( config
->rgba
,
276 config
->doubleBuffer
,
278 _mesa_bitcount(visinfo
->red_mask
),
279 _mesa_bitcount(visinfo
->green_mask
),
280 _mesa_bitcount(visinfo
->blue_mask
),
285 config
->accumRedSize
,
286 config
->accumGreenSize
,
287 config
->accumBlueSize
,
288 config
->accumAlphaSize
,
289 0 /* num samples */ );
295 savageCreateContext( const __GLcontextModes
*mesaVis
,
296 __DRIcontextPrivate
*driContextPriv
,
297 void *sharedContextPrivate
)
299 GLcontext
*ctx
, *shareCtx
;
300 savageContextPtr imesa
;
301 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
302 struct dd_function_table functions
;
303 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
304 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
305 savageScreen
->sarea_priv_offset
);
306 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
308 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
313 /* Init default driver functions then plug in savage-specific texture
314 * functions that are needed as early as during context creation. */
315 _mesa_init_driver_functions( &functions
);
316 savageDDInitTextureFuncs( &functions
);
318 /* Allocate the Mesa context */
319 if (sharedContextPrivate
)
320 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
323 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
328 driContextPriv
->driverPrivate
= imesa
;
330 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
331 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
332 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
333 if (!imesa
->cmdBuf
.base
)
336 /* Parse configuration files */
337 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
338 sPriv
->myNum
, "savage");
340 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
341 savageScreen
->chipset
>= S3_SAVAGE4
;
342 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
345 ctx
->Const
.MinLineWidth
= 1.0;
346 ctx
->Const
.MinLineWidthAA
= 1.0;
347 ctx
->Const
.MaxLineWidth
= 3.0;
348 ctx
->Const
.MaxLineWidthAA
= 3.0;
349 ctx
->Const
.LineWidthGranularity
= 1.0;
354 imesa
->hHWContext
= driContextPriv
->hHWContext
;
355 imesa
->driFd
= sPriv
->fd
;
356 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
358 imesa
->savageScreen
= savageScreen
;
359 imesa
->driScreen
= sPriv
;
360 imesa
->sarea
= saPriv
;
361 imesa
->glBuffer
= NULL
;
367 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
371 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
373 /* change texHeap initialize to support two kind of texture heap*/
374 /* here is some parts of initialization, others in InitDriver() */
376 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
377 make_empty_list( & imesa
->swapped
);
379 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
380 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
381 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
382 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
383 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
384 if (textureSize
[SAVAGE_CARD_HEAP
])
385 imesa
->lastTexHeap
= 1;
387 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
388 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
389 textureSize
[SAVAGE_CARD_HEAP
] = 0;
391 /*default: Nothing to do, use all available memory. */
394 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
395 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
398 11, /* 2^11 = 2k alignment */
399 SAVAGE_NR_TEX_REGIONS
,
400 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
401 &imesa
->sarea
->texAge
[i
],
403 sizeof( savageTexObj
),
404 (destroy_texture_object_t
*) savageDestroyTexObj
);
405 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
406 * if there is not enough card memory for a card texture heap. */
407 if (imesa
->textureHeaps
[i
])
408 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
409 & imesa
->c_textureSwaps
);
411 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
413 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
414 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
415 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
417 if (savageScreen
->chipset
>= S3_SAVAGE4
)
418 ctx
->Const
.MaxTextureUnits
= 2;
420 ctx
->Const
.MaxTextureUnits
= 1;
421 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
422 ctx
->Const
.MaxTextureUnits
)
423 ctx
->Const
.MaxTextureUnits
=
424 driQueryOptioni(&imesa
->optionCache
, "texture_units");
425 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
426 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
428 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
432 11, /* max 2D texture size is 2048x2048 */
433 0, /* 3D textures unsupported. */
434 0, /* cube textures unsupported. */
435 0, /* texture rectangles unsupported. */
438 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
439 __driUtilMessage("Not enough texture memory. "
440 "Falling back to indirect rendering.");
445 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
446 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
447 (1.0F
/0xffff):(1.0F
/0xffffff);
449 imesa
->bufferSize
= savageScreen
->bufferSize
;
450 imesa
->dmaVtxBuf
.total
= 0;
451 imesa
->dmaVtxBuf
.used
= 0;
452 imesa
->dmaVtxBuf
.flushed
= 0;
454 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
455 imesa
->clientVtxBuf
.used
= 0;
456 imesa
->clientVtxBuf
.flushed
= 0;
457 imesa
->clientVtxBuf
.buf
= (u_int32_t
*)malloc(imesa
->bufferSize
);
459 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
461 imesa
->firstElt
= -1;
463 /* Uninitialized vertex format. Force setting the vertex state in
466 imesa
->vertex_size
= 0;
470 imesa
->new_state
= ~0;
471 imesa
->new_gl_state
= ~0;
472 imesa
->RenderIndex
= ~0;
474 imesa
->lostContext
= GL_TRUE
;
475 imesa
->CurrentTexObj
[0] = 0;
476 imesa
->CurrentTexObj
[1] = 0;
478 /* Initialize the software rasterizer and helper modules.
480 _swrast_CreateContext( ctx
);
481 _ac_CreateContext( ctx
);
482 _tnl_CreateContext( ctx
);
484 _swsetup_CreateContext( ctx
);
486 /* Install the customized pipeline:
488 _tnl_destroy_pipeline( ctx
);
489 _tnl_install_pipeline( ctx
, savage_pipeline
);
491 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
493 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
494 * support was added in 2.2.0. */
495 if (imesa
->enable_fastpath
&& sPriv
->drmMinor
< 2) {
497 "*** Disabling fast path because your DRM version is buggy "
498 "or doesn't\n*** support ELTS. You need at least Savage DRM "
500 imesa
->enable_fastpath
= GL_FALSE
;
503 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
504 imesa
->enable_vdma
= GL_FALSE
;
506 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
508 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
510 /* Configure swrast to match hardware characteristics:
512 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
513 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
514 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
515 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
517 ctx
->DriverCtx
= (void *) imesa
;
521 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
525 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
527 savageDDInitStateFuncs( ctx
);
528 savageDDInitSpanFuncs( ctx
);
529 savageDDInitDriverFuncs( ctx
);
530 savageDDInitIoctlFuncs( ctx
);
531 savageInitTriFuncs( ctx
);
533 savageDDInitState( imesa
);
535 driContextPriv
->driverPrivate
= (void *) imesa
;
541 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
543 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
546 assert (imesa
); /* should never be NULL */
548 savageFlushVertices(imesa
);
549 savageReleaseIndexedVerts(imesa
);
550 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
551 WAIT_IDLE_EMPTY(imesa
);
553 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
554 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
556 free(imesa
->cmdBuf
.base
);
557 free(imesa
->clientVtxBuf
.buf
);
559 _swsetup_DestroyContext(imesa
->glCtx
);
560 _tnl_DestroyContext( imesa
->glCtx
);
561 _ac_DestroyContext( imesa
->glCtx
);
562 _swrast_DestroyContext( imesa
->glCtx
);
564 /* free the Mesa context */
565 imesa
->glCtx
->DriverCtx
= NULL
;
566 _mesa_destroy_context(imesa
->glCtx
);
568 /* no longer use vertex_dma_buf*/
574 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
575 __DRIdrawablePrivate
*driDrawPriv
,
576 const __GLcontextModes
*mesaVis
,
580 return GL_FALSE
; /* not implemented */
583 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
584 driDrawPriv
->driverPrivate
= (void *)
585 _mesa_create_framebuffer(mesaVis
,
586 GL_FALSE
, /* software depth buffer? */
588 mesaVis
->accumRedBits
> 0,
589 mesaVis
->alphaBits
> 0 );
591 return (driDrawPriv
->driverPrivate
!= NULL
);
596 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
598 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
602 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
604 /* XXX should do swap according to the buffer, not the context! */
605 savageContextPtr imesa
= savageCtx
;
607 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
608 savageSwapBuffers(imesa
);
612 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
614 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
616 imesa
->numClipRects
= dPriv
->numClipRects
;
617 imesa
->pClipRects
= dPriv
->pClipRects
;
618 imesa
->drawX
= dPriv
->x
;
619 imesa
->drawY
= dPriv
->y
;
621 savageCalcViewport( imesa
->glCtx
);
625 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
627 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
629 if (dPriv
->numBackClipRects
== 0)
633 imesa
->numClipRects
= dPriv
->numClipRects
;
634 imesa
->pClipRects
= dPriv
->pClipRects
;
635 imesa
->drawX
= dPriv
->x
;
636 imesa
->drawY
= dPriv
->y
;
640 imesa
->numClipRects
= dPriv
->numBackClipRects
;
641 imesa
->pClipRects
= dPriv
->pBackClipRects
;
642 imesa
->drawX
= dPriv
->backX
;
643 imesa
->drawY
= dPriv
->backY
;
646 savageCalcViewport( imesa
->glCtx
);
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
;
704 WAIT_IDLE_EMPTY(imesa
);
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
;
749 unsigned int timestamp
= 0;
753 /* We know there has been contention.
755 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
758 /* Note contention for throttling hint
760 imesa
->any_contend
= 1;
762 /* If the window moved, may need to set a new cliprect now.
764 * NOTE: This releases and regains the hw lock, so all state
765 * checking must be done *after* this call:
767 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
772 /* If we lost context, need to dump all registers to hardware.
773 * Note that we don't care about 2d contexts, even if they perform
774 * accelerated commands, so the DRI locking in the X server is even
775 * more broken than usual.
777 if (sarea
->ctxOwner
!= me
) {
778 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
779 SAVAGE_UPLOAD_GLOBAL
|
780 SAVAGE_UPLOAD_FOGTBL
|
783 SAVAGE_UPLOAD_TEXGLOBAL
);
784 imesa
->lostContext
= GL_TRUE
;
785 sarea
->ctxOwner
= me
;
788 for (heap
= 0; heap
< imesa
->lastTexHeap
; ++heap
) {
789 /* If a heap was changed, update its timestamp. Do this before
790 * DRI_AGE_TEXTURES updates the local_age. */
791 if (imesa
->textureHeaps
[heap
] &&
792 imesa
->textureHeaps
[heap
]->global_age
[0] >
793 imesa
->textureHeaps
[heap
]->local_age
) {
795 timestamp
= savageEmitEventLocked(imesa
, 0);
796 imesa
->textureHeaps
[heap
]->timestamp
= timestamp
;
798 DRI_AGE_TEXTURES( imesa
->textureHeaps
[heap
] );
801 if (dPriv
->lastStamp
!= stamp
)
802 savageXMesaWindowMoved( imesa
);
810 static const struct __DriverAPIRec savageAPI
= {
814 savageDestroyContext
,
824 #ifndef DRI_NEW_INTERFACE_ONLY
826 * This is the (old) bootstrap function for the driver.
827 * The __driCreateScreen name is the symbol that libGL.so fetches.
828 * Return: pointer to a __DRIscreenPrivate.
830 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
831 int numConfigs
, __GLXvisualConfig
*config
)
833 __DRIscreenPrivate
*psp
;
834 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &savageAPI
);
837 #endif /* DRI_NEW_INTERFACE_ONLY */
841 #ifdef USE_NEW_INTERFACE
842 static __GLcontextModes
*
843 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
844 unsigned stencil_bits
, GLboolean have_back_buffer
)
846 __GLcontextModes
* modes
;
847 __GLcontextModes
* m
;
849 unsigned depth_buffer_factor
;
850 unsigned back_buffer_factor
;
854 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
855 * enough to add support. Basically, if a context is created with an
856 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
857 * will never be used.
859 * FK: What about drivers that don't use page flipping? Could they
860 * just expose GLX_SWAP_COPY_OML?
862 static const GLenum back_buffer_modes
[] = {
863 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
866 u_int8_t depth_bits_array
[2];
867 u_int8_t stencil_bits_array
[2];
870 depth_bits_array
[0] = depth_bits
;
871 depth_bits_array
[1] = depth_bits
;
873 /* Just like with the accumulation buffer, always provide some modes
874 * with a stencil buffer. It will be a sw fallback, but some apps won't
877 stencil_bits_array
[0] = 0;
878 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
880 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
881 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
883 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
885 if ( pixel_bits
== 16 ) {
887 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
891 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
894 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
896 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
897 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
898 back_buffer_modes
, back_buffer_factor
,
900 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
901 __func__
, __LINE__
);
905 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
906 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
907 back_buffer_modes
, back_buffer_factor
,
908 GLX_DIRECT_COLOR
) ) {
909 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
910 __func__
, __LINE__
);
914 /* Mark the visual as slow if there are "fake" stencil bits.
916 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
917 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
918 m
->visualRating
= GLX_SLOW_CONFIG
;
927 * This is the bootstrap function for the driver. libGL supplies all of the
928 * requisite information about the system, and the driver initializes itself.
929 * This routine also fills in the linked list pointed to by \c driver_modes
930 * with the \c __GLcontextModes that the driver can support for windows or
933 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
937 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
938 const __GLcontextModes
* modes
,
939 const __DRIversion
* ddx_version
,
940 const __DRIversion
* dri_version
,
941 const __DRIversion
* drm_version
,
942 const __DRIframebuffer
* frame_buffer
,
943 drmAddress pSAREA
, int fd
,
944 int internal_api_version
,
945 __GLcontextModes
** driver_modes
)
948 __DRIscreenPrivate
*psp
;
949 static const __DRIversion ddx_expected
= { 2, 0, 0 };
950 static const __DRIversion dri_expected
= { 4, 0, 0 };
951 static const __DRIversion drm_expected
= { 2, 1, 0 };
953 if ( ! driCheckDriDdxDrmVersions2( "Savage",
954 dri_version
, & dri_expected
,
955 ddx_version
, & ddx_expected
,
956 drm_version
, & drm_expected
) ) {
960 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
961 ddx_version
, dri_version
, drm_version
,
962 frame_buffer
, pSAREA
, fd
,
963 internal_api_version
, &savageAPI
);
965 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
966 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
967 if ( create_context_modes
!= NULL
) {
968 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
969 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
970 (dri_priv
->cpp
== 2) ? 16 : 24,
971 (dri_priv
->cpp
== 2) ? 0 : 8,
972 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
978 #endif /* USE_NEW_INTERFACE */