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"
32 #include "framebuffer.h"
33 #include "renderbuffer.h"
34 #include "simple_list.h"
38 #include "extensions.h"
40 #include "swrast/swrast.h"
41 #include "swrast_setup/swrast_setup.h"
43 #include "array_cache/acache.h"
45 #include "tnl/t_pipeline.h"
47 #include "drivers/common/driverfuncs.h"
50 #include "savagestate.h"
51 #include "savagetex.h"
52 #include "savagespan.h"
53 #include "savagetris.h"
54 #include "savageioctl.h"
55 #include "savage_bci.h"
57 #include "savage_dri.h"
61 #define need_GL_ARB_multisample
62 #define need_GL_ARB_texture_compression
63 #include "extension_helper.h"
67 /* Driver-specific options
69 #define SAVAGE_ENABLE_VDMA(def) \
70 DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
71 DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
72 DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
74 #define SAVAGE_ENABLE_FASTPATH(def) \
75 DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
76 DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
77 DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
79 #define SAVAGE_SYNC_FRAMES(def) \
80 DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
81 DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
82 DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
87 PUBLIC
const char __driConfigOptions
[] =
89 DRI_CONF_SECTION_QUALITY
90 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
91 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
92 DRI_CONF_FLOAT_DEPTH(false)
94 DRI_CONF_SECTION_PERFORMANCE
95 SAVAGE_ENABLE_VDMA(true)
96 SAVAGE_ENABLE_FASTPATH(true)
97 SAVAGE_SYNC_FRAMES(false)
98 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
99 DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL
)
100 DRI_CONF_FORCE_S3TC_ENABLE(false)
102 DRI_CONF_SECTION_DEBUG
103 DRI_CONF_NO_RAST(false)
106 static const GLuint __driNConfigOptions
= 10;
109 static const struct dri_debug_control debug_control
[] =
111 { "fall", DEBUG_FALLBACKS
},
112 { "api", DEBUG_VERBOSE_API
},
113 { "tex", DEBUG_VERBOSE_TEX
},
114 { "verb", DEBUG_VERBOSE_MSG
},
115 { "dma", DEBUG_DMA
},
116 { "state", DEBUG_STATE
},
120 int SAVAGE_DEBUG
= 0;
124 /*For time caculating test*/
125 #if defined(DEBUG_TIME) && DEBUG_TIME
126 struct timeval tv_s
,tv_f
;
127 unsigned long time_sum
=0;
128 struct timeval tv_s1
,tv_f1
;
131 static const struct dri_extension card_extensions
[] =
133 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
134 { "GL_ARB_multitexture", NULL
},
135 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
136 { "GL_EXT_stencil_wrap", NULL
},
137 { "GL_EXT_texture_lod_bias", NULL
},
141 static const struct dri_extension s4_extensions
[] =
143 { "GL_ARB_texture_env_add", NULL
},
147 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
148 extern struct tnl_pipeline_stage _savage_render_stage
;
150 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
152 &_tnl_vertex_transform_stage
,
153 &_tnl_normal_transform_stage
,
154 &_tnl_lighting_stage
,
155 &_tnl_fog_coordinate_stage
,
157 &_tnl_texture_transform_stage
,
158 &_savage_texnorm_stage
,
159 &_savage_render_stage
,
165 /* this is first function called in dirver*/
168 savageInitDriver(__DRIscreenPrivate
*sPriv
)
170 savageScreenPrivate
*savageScreen
;
171 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
173 if (sPriv
->devPrivSize
!= sizeof(SAVAGEDRIRec
)) {
174 fprintf(stderr
,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
178 /* Allocate the private area */
179 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
183 savageScreen
->driScrnPriv
= sPriv
;
184 sPriv
->private = (void *)savageScreen
;
186 savageScreen
->chipset
=gDRIPriv
->chipset
;
187 savageScreen
->width
=gDRIPriv
->width
;
188 savageScreen
->height
=gDRIPriv
->height
;
189 savageScreen
->mem
=gDRIPriv
->mem
;
190 savageScreen
->cpp
=gDRIPriv
->cpp
;
191 savageScreen
->zpp
=gDRIPriv
->zpp
;
193 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
195 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
197 if (gDRIPriv
->cpp
== 4)
198 savageScreen
->frontFormat
= DV_PF_8888
;
200 savageScreen
->frontFormat
= DV_PF_565
;
201 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
202 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
203 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
205 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
206 gDRIPriv
->textureOffset
;
207 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
208 gDRIPriv
->textureSize
;
209 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
210 gDRIPriv
->logTextureGranularity
;
212 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
213 gDRIPriv
->agpTextureHandle
;
214 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
215 gDRIPriv
->agpTextureSize
;
216 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
217 gDRIPriv
->logAgpTextureGranularity
;
219 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
220 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
221 if (gDRIPriv
->agpTextureSize
) {
222 if (drmMap(sPriv
->fd
,
223 savageScreen
->agpTextures
.handle
,
224 savageScreen
->agpTextures
.size
,
225 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
227 sPriv
->private = NULL
;
231 savageScreen
->agpTextures
.map
= NULL
;
233 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
234 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
235 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
236 (drmAddress
)(savageScreen
->agpTextures
.map
);
238 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
239 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
240 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
241 if (drmMap(sPriv
->fd
,
242 savageScreen
->aperture
.handle
,
243 savageScreen
->aperture
.size
,
244 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
247 sPriv
->private = NULL
;
251 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
253 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
255 /* parse information in __driConfigOptions */
256 driParseOptionInfo (&savageScreen
->optionCache
,
257 __driConfigOptions
, __driNConfigOptions
);
260 savageDDFastPathInit();
261 savageDDTrifuncInit();
267 /* Accessed by dlsym from dri_mesa_init.c
270 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
272 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
274 if (savageScreen
->bufs
)
275 drmUnmapBufs(savageScreen
->bufs
);
277 /* free all option information */
278 driDestroyOptionInfo (&savageScreen
->optionCache
);
281 sPriv
->private = NULL
;
285 GLvisual
*XMesaCreateVisual(Display
*dpy
,
286 __DRIscreenPrivate
*driScrnPriv
,
287 const XVisualInfo
*visinfo
,
288 const __GLXvisualConfig
*config
)
290 /* Drivers may change the args to _mesa_create_visual() in order to
291 * setup special visuals.
293 return _mesa_create_visual( config
->rgba
,
294 config
->doubleBuffer
,
296 _mesa_bitcount(visinfo
->red_mask
),
297 _mesa_bitcount(visinfo
->green_mask
),
298 _mesa_bitcount(visinfo
->blue_mask
),
303 config
->accumRedSize
,
304 config
->accumGreenSize
,
305 config
->accumBlueSize
,
306 config
->accumAlphaSize
,
307 0 /* num samples */ );
313 savageCreateContext( const __GLcontextModes
*mesaVis
,
314 __DRIcontextPrivate
*driContextPriv
,
315 void *sharedContextPrivate
)
317 GLcontext
*ctx
, *shareCtx
;
318 savageContextPtr imesa
;
319 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
320 struct dd_function_table functions
;
321 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
322 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
323 savageScreen
->sarea_priv_offset
);
324 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
326 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
331 /* Init default driver functions then plug in savage-specific texture
332 * functions that are needed as early as during context creation. */
333 _mesa_init_driver_functions( &functions
);
334 savageDDInitTextureFuncs( &functions
);
336 /* Allocate the Mesa context */
337 if (sharedContextPrivate
)
338 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
341 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
346 driContextPriv
->driverPrivate
= imesa
;
348 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
349 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
350 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
351 if (!imesa
->cmdBuf
.base
)
354 /* Parse configuration files */
355 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
356 sPriv
->myNum
, "savage");
358 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
359 savageScreen
->chipset
>= S3_SAVAGE4
;
360 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
363 ctx
->Const
.MinLineWidth
= 1.0;
364 ctx
->Const
.MinLineWidthAA
= 1.0;
365 ctx
->Const
.MaxLineWidth
= 3.0;
366 ctx
->Const
.MaxLineWidthAA
= 3.0;
367 ctx
->Const
.LineWidthGranularity
= 1.0;
372 imesa
->hHWContext
= driContextPriv
->hHWContext
;
373 imesa
->driFd
= sPriv
->fd
;
374 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
376 imesa
->savageScreen
= savageScreen
;
377 imesa
->driScreen
= sPriv
;
378 imesa
->sarea
= saPriv
;
379 imesa
->glBuffer
= NULL
;
385 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
389 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
391 /* change texHeap initialize to support two kind of texture heap*/
392 /* here is some parts of initialization, others in InitDriver() */
394 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
395 make_empty_list( & imesa
->swapped
);
397 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
398 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
399 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
400 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
401 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
402 if (textureSize
[SAVAGE_CARD_HEAP
])
403 imesa
->lastTexHeap
= 1;
405 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
406 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
407 textureSize
[SAVAGE_CARD_HEAP
] = 0;
409 /*default: Nothing to do, use all available memory. */
412 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
413 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
416 11, /* 2^11 = 2k alignment */
417 SAVAGE_NR_TEX_REGIONS
,
418 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
419 &imesa
->sarea
->texAge
[i
],
421 sizeof( savageTexObj
),
422 (destroy_texture_object_t
*) savageDestroyTexObj
);
423 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
424 * if there is not enough card memory for a card texture heap. */
425 if (imesa
->textureHeaps
[i
])
426 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
427 & imesa
->c_textureSwaps
);
429 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
431 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
432 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
433 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
435 if (savageScreen
->chipset
>= S3_SAVAGE4
)
436 ctx
->Const
.MaxTextureUnits
= 2;
438 ctx
->Const
.MaxTextureUnits
= 1;
439 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
440 ctx
->Const
.MaxTextureUnits
)
441 ctx
->Const
.MaxTextureUnits
=
442 driQueryOptioni(&imesa
->optionCache
, "texture_units");
443 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
444 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
446 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
450 11, /* max 2D texture size is 2048x2048 */
451 0, /* 3D textures unsupported. */
452 0, /* cube textures unsupported. */
453 0, /* texture rectangles unsupported. */
456 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
457 __driUtilMessage("Not enough texture memory. "
458 "Falling back to indirect rendering.");
463 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
464 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
465 (1.0F
/0xffff):(1.0F
/0xffffff);
467 imesa
->bufferSize
= savageScreen
->bufferSize
;
468 imesa
->dmaVtxBuf
.total
= 0;
469 imesa
->dmaVtxBuf
.used
= 0;
470 imesa
->dmaVtxBuf
.flushed
= 0;
472 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
473 imesa
->clientVtxBuf
.used
= 0;
474 imesa
->clientVtxBuf
.flushed
= 0;
475 imesa
->clientVtxBuf
.buf
= (u_int32_t
*)malloc(imesa
->bufferSize
);
477 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
479 imesa
->firstElt
= -1;
481 /* Uninitialized vertex format. Force setting the vertex state in
484 imesa
->vertex_size
= 0;
488 imesa
->new_state
= ~0;
489 imesa
->new_gl_state
= ~0;
490 imesa
->RenderIndex
= ~0;
492 imesa
->lostContext
= GL_TRUE
;
493 imesa
->CurrentTexObj
[0] = 0;
494 imesa
->CurrentTexObj
[1] = 0;
496 /* Initialize the software rasterizer and helper modules.
498 _swrast_CreateContext( ctx
);
499 _ac_CreateContext( ctx
);
500 _tnl_CreateContext( ctx
);
502 _swsetup_CreateContext( ctx
);
504 /* Install the customized pipeline:
506 _tnl_destroy_pipeline( ctx
);
507 _tnl_install_pipeline( ctx
, savage_pipeline
);
509 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
511 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
512 * support was added in 2.2.0. */
513 if (imesa
->enable_fastpath
&& sPriv
->drmMinor
< 2) {
515 "*** Disabling fast path because your DRM version is buggy "
516 "or doesn't\n*** support ELTS. You need at least Savage DRM "
518 imesa
->enable_fastpath
= GL_FALSE
;
521 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
522 imesa
->enable_vdma
= GL_FALSE
;
524 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
526 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
528 /* Configure swrast to match hardware characteristics:
530 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
531 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
532 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
533 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
535 ctx
->DriverCtx
= (void *) imesa
;
539 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
543 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
544 if (savageScreen
->chipset
>= S3_SAVAGE4
)
545 driInitExtensions( ctx
, s4_extensions
, GL_FALSE
);
546 if (ctx
->Mesa_DXTn
||
547 driQueryOptionb (&imesa
->optionCache
, "force_s3tc_enable")) {
548 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
549 if (savageScreen
->chipset
>= S3_SAVAGE4
)
550 /* This extension needs DXT3 and DTX5 support in hardware.
551 * Not available on Savage3D/MX/IX. */
552 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
555 savageDDInitStateFuncs( ctx
);
556 savageDDInitSpanFuncs( ctx
);
557 savageDDInitDriverFuncs( ctx
);
558 savageDDInitIoctlFuncs( ctx
);
559 savageInitTriFuncs( ctx
);
561 savageDDInitState( imesa
);
563 driContextPriv
->driverPrivate
= (void *) imesa
;
569 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
571 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
574 assert (imesa
); /* should never be NULL */
576 savageFlushVertices(imesa
);
577 savageReleaseIndexedVerts(imesa
);
578 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
579 WAIT_IDLE_EMPTY(imesa
);
581 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
582 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
584 free(imesa
->cmdBuf
.base
);
585 free(imesa
->clientVtxBuf
.buf
);
587 _swsetup_DestroyContext(imesa
->glCtx
);
588 _tnl_DestroyContext( imesa
->glCtx
);
589 _ac_DestroyContext( imesa
->glCtx
);
590 _swrast_DestroyContext( imesa
->glCtx
);
592 /* free the Mesa context */
593 imesa
->glCtx
->DriverCtx
= NULL
;
594 _mesa_destroy_context(imesa
->glCtx
);
596 /* no longer use vertex_dma_buf*/
603 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
604 __DRIdrawablePrivate
*driDrawPriv
,
605 const __GLcontextModes
*mesaVis
,
608 savageScreenPrivate
*screen
= (savageScreenPrivate
*) driScrnPriv
->private;
611 return GL_FALSE
; /* not implemented */
614 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
615 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
617 * XXX: this value needs to be set according to the config file
618 * setting. But we don't get that until we create a rendering
621 GLboolean float_depth
= GL_FALSE
;
624 driRenderbuffer
*frontRb
625 = driNewRenderbuffer(GL_RGBA
,
626 (GLubyte
*) screen
->aperture
.map
627 + 0x01000000 * TARGET_FRONT
,
629 screen
->frontOffset
, screen
->aperturePitch
,
631 savageSetSpanFunctions(frontRb
, mesaVis
, float_depth
);
632 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
635 if (mesaVis
->doubleBufferMode
) {
636 driRenderbuffer
*backRb
637 = driNewRenderbuffer(GL_RGBA
,
638 (GLubyte
*) screen
->aperture
.map
639 + 0x01000000 * TARGET_BACK
,
641 screen
->backOffset
, screen
->aperturePitch
,
643 savageSetSpanFunctions(backRb
, mesaVis
, float_depth
);
644 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
647 if (mesaVis
->depthBits
== 16) {
648 driRenderbuffer
*depthRb
649 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
650 (GLubyte
*) screen
->aperture
.map
651 + 0x01000000 * TARGET_DEPTH
,
653 screen
->depthOffset
, screen
->aperturePitch
,
655 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
656 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
658 else if (mesaVis
->depthBits
== 24) {
659 driRenderbuffer
*depthRb
660 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
661 (GLubyte
*) screen
->aperture
.map
662 + 0x01000000 * TARGET_DEPTH
,
664 screen
->depthOffset
, screen
->aperturePitch
,
666 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
667 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
670 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
671 driRenderbuffer
*stencilRb
672 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
673 (GLubyte
*) screen
->aperture
.map
674 + 0x01000000 * TARGET_DEPTH
,
676 screen
->depthOffset
, screen
->aperturePitch
,
678 savageSetSpanFunctions(stencilRb
, mesaVis
, float_depth
);
679 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
682 _mesa_add_soft_renderbuffers(fb
,
683 GL_FALSE
, /* color */
684 GL_FALSE
, /* depth */
686 mesaVis
->accumRedBits
> 0,
687 GL_FALSE
, /* alpha */
689 driDrawPriv
->driverPrivate
= (void *) fb
;
691 return (driDrawPriv
->driverPrivate
!= NULL
);
696 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
698 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
702 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
704 /* XXX should do swap according to the buffer, not the context! */
705 savageContextPtr imesa
= savageCtx
;
707 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
708 savageSwapBuffers(imesa
);
712 void savageXMesaSetFrontClipRects( savageContextPtr imesa
)
714 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
716 imesa
->numClipRects
= dPriv
->numClipRects
;
717 imesa
->pClipRects
= dPriv
->pClipRects
;
718 imesa
->drawX
= dPriv
->x
;
719 imesa
->drawY
= dPriv
->y
;
721 savageCalcViewport( imesa
->glCtx
);
725 void savageXMesaSetBackClipRects( savageContextPtr imesa
)
727 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
729 if (dPriv
->numBackClipRects
== 0)
733 imesa
->numClipRects
= dPriv
->numClipRects
;
734 imesa
->pClipRects
= dPriv
->pClipRects
;
735 imesa
->drawX
= dPriv
->x
;
736 imesa
->drawY
= dPriv
->y
;
740 imesa
->numClipRects
= dPriv
->numBackClipRects
;
741 imesa
->pClipRects
= dPriv
->pBackClipRects
;
742 imesa
->drawX
= dPriv
->backX
;
743 imesa
->drawY
= dPriv
->backY
;
746 savageCalcViewport( imesa
->glCtx
);
750 static void savageXMesaWindowMoved( savageContextPtr imesa
)
753 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
755 switch (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferMask
[0]) {
756 case BUFFER_BIT_FRONT_LEFT
:
757 savageXMesaSetFrontClipRects( imesa
);
759 case BUFFER_BIT_BACK_LEFT
:
760 savageXMesaSetBackClipRects( imesa
);
769 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
771 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
780 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
785 if (driContextPriv
) {
786 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
787 imesa
->IsFullScreen
= GL_TRUE
;
788 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
789 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
790 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
791 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
792 imesa
->toggle
= TARGET_BACK
;
799 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
802 if (driContextPriv
) {
803 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
804 WAIT_IDLE_EMPTY(imesa
);
805 imesa
->IsFullScreen
= GL_FALSE
;
806 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
807 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
808 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
815 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
816 __DRIdrawablePrivate
*driDrawPriv
,
817 __DRIdrawablePrivate
*driReadPriv
)
819 if (driContextPriv
) {
820 savageContextPtr imesa
821 = (savageContextPtr
) driContextPriv
->driverPrivate
;
822 struct gl_framebuffer
*drawBuffer
823 = (GLframebuffer
*) driDrawPriv
->driverPrivate
;
824 struct gl_framebuffer
*readBuffer
825 = (GLframebuffer
*) driReadPriv
->driverPrivate
;
826 driRenderbuffer
*frontRb
= (driRenderbuffer
*)
827 drawBuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
828 driRenderbuffer
*backRb
= (driRenderbuffer
*)
829 drawBuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
831 assert(frontRb
->Base
.Data
);
832 assert(backRb
->Base
.Data
);
834 imesa
->driReadable
= driReadPriv
;
835 imesa
->driDrawable
= driDrawPriv
;
838 _mesa_make_current(imesa
->glCtx
, drawBuffer
, readBuffer
);
840 savageXMesaWindowMoved( imesa
);
844 _mesa_make_current(NULL
, NULL
, NULL
);
850 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
852 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
853 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
854 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
855 int me
= imesa
->hHWContext
;
856 int stamp
= dPriv
->lastStamp
;
858 unsigned int timestamp
= 0;
862 /* We know there has been contention.
864 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
867 /* Note contention for throttling hint
869 imesa
->any_contend
= 1;
871 /* If the window moved, may need to set a new cliprect now.
873 * NOTE: This releases and regains the hw lock, so all state
874 * checking must be done *after* this call:
876 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
881 /* If we lost context, need to dump all registers to hardware.
882 * Note that we don't care about 2d contexts, even if they perform
883 * accelerated commands, so the DRI locking in the X server is even
884 * more broken than usual.
886 if (sarea
->ctxOwner
!= me
) {
887 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
888 SAVAGE_UPLOAD_GLOBAL
|
889 SAVAGE_UPLOAD_FOGTBL
|
892 SAVAGE_UPLOAD_TEXGLOBAL
);
893 imesa
->lostContext
= GL_TRUE
;
894 sarea
->ctxOwner
= me
;
897 for (heap
= 0; heap
< imesa
->lastTexHeap
; ++heap
) {
898 /* If a heap was changed, update its timestamp. Do this before
899 * DRI_AGE_TEXTURES updates the local_age. */
900 if (imesa
->textureHeaps
[heap
] &&
901 imesa
->textureHeaps
[heap
]->global_age
[0] >
902 imesa
->textureHeaps
[heap
]->local_age
) {
904 timestamp
= savageEmitEventLocked(imesa
, 0);
905 imesa
->textureHeaps
[heap
]->timestamp
= timestamp
;
907 DRI_AGE_TEXTURES( imesa
->textureHeaps
[heap
] );
910 if (dPriv
->lastStamp
!= stamp
)
911 savageXMesaWindowMoved( imesa
);
919 static const struct __DriverAPIRec savageAPI
= {
923 savageDestroyContext
,
932 static __GLcontextModes
*
933 savageFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
934 unsigned stencil_bits
, GLboolean have_back_buffer
)
936 __GLcontextModes
* modes
;
937 __GLcontextModes
* m
;
939 unsigned depth_buffer_factor
;
940 unsigned back_buffer_factor
;
944 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
945 * enough to add support. Basically, if a context is created with an
946 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
947 * will never be used.
949 * FK: What about drivers that don't use page flipping? Could they
950 * just expose GLX_SWAP_COPY_OML?
952 static const GLenum back_buffer_modes
[] = {
953 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
956 u_int8_t depth_bits_array
[2];
957 u_int8_t stencil_bits_array
[2];
960 depth_bits_array
[0] = depth_bits
;
961 depth_bits_array
[1] = depth_bits
;
963 /* Just like with the accumulation buffer, always provide some modes
964 * with a stencil buffer. It will be a sw fallback, but some apps won't
967 stencil_bits_array
[0] = 0;
968 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
970 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
971 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
973 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
975 if ( pixel_bits
== 16 ) {
977 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
981 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
984 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
986 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
987 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
988 back_buffer_modes
, back_buffer_factor
,
990 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
991 __func__
, __LINE__
);
995 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
996 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
997 back_buffer_modes
, back_buffer_factor
,
998 GLX_DIRECT_COLOR
) ) {
999 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
1000 __func__
, __LINE__
);
1004 /* Mark the visual as slow if there are "fake" stencil bits.
1006 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
1007 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
1008 m
->visualRating
= GLX_SLOW_CONFIG
;
1017 * This is the bootstrap function for the driver. libGL supplies all of the
1018 * requisite information about the system, and the driver initializes itself.
1019 * This routine also fills in the linked list pointed to by \c driver_modes
1020 * with the \c __GLcontextModes that the driver can support for windows or
1023 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
1027 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
1028 const __GLcontextModes
* modes
,
1029 const __DRIversion
* ddx_version
,
1030 const __DRIversion
* dri_version
,
1031 const __DRIversion
* drm_version
,
1032 const __DRIframebuffer
* frame_buffer
,
1033 drmAddress pSAREA
, int fd
,
1034 int internal_api_version
,
1035 const __DRIinterfaceMethods
* interface
,
1036 __GLcontextModes
** driver_modes
)
1039 __DRIscreenPrivate
*psp
;
1040 static const __DRIversion ddx_expected
= { 2, 0, 0 };
1041 static const __DRIversion dri_expected
= { 4, 0, 0 };
1042 static const __DRIversion drm_expected
= { 2, 1, 0 };
1044 dri_interface
= interface
;
1046 if ( ! driCheckDriDdxDrmVersions2( "Savage",
1047 dri_version
, & dri_expected
,
1048 ddx_version
, & ddx_expected
,
1049 drm_version
, & drm_expected
) ) {
1053 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
1054 ddx_version
, dri_version
, drm_version
,
1055 frame_buffer
, pSAREA
, fd
,
1056 internal_api_version
, &savageAPI
);
1057 if ( psp
!= NULL
) {
1058 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
1059 *driver_modes
= savageFillInModes( dri_priv
->cpp
*8,
1060 (dri_priv
->cpp
== 2) ? 16 : 24,
1061 (dri_priv
->cpp
== 2) ? 0 : 8,
1062 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1064 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
1065 * enable the extensions. It just makes sure that all the dispatch offsets for all
1066 * the extensions that *might* be enables are known. This is needed because the
1067 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
1068 * enable the extensions until we have a context pointer.
1070 * Hello chicken. Hello egg. How are you two today?
1072 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
1075 return (void *) psp
;