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"
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"
59 #include "drirenderbuffer.h"
62 #define need_GL_ARB_multisample
63 #define need_GL_ARB_texture_compression
64 #define need_GL_ARB_vertex_buffer_object
65 #define need_GL_EXT_secondary_color
66 #include "extension_helper.h"
70 /* Driver-specific options
72 #define SAVAGE_ENABLE_VDMA(def) \
73 DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
74 DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
75 DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
77 #define SAVAGE_ENABLE_FASTPATH(def) \
78 DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
79 DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
80 DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
82 #define SAVAGE_SYNC_FRAMES(def) \
83 DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
84 DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
85 DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
90 PUBLIC
const char __driConfigOptions
[] =
92 DRI_CONF_SECTION_QUALITY
93 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
94 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
95 DRI_CONF_FLOAT_DEPTH(false)
97 DRI_CONF_SECTION_PERFORMANCE
98 SAVAGE_ENABLE_VDMA(true)
99 SAVAGE_ENABLE_FASTPATH(true)
100 SAVAGE_SYNC_FRAMES(false)
101 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
102 DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL
)
103 DRI_CONF_FORCE_S3TC_ENABLE(false)
105 DRI_CONF_SECTION_DEBUG
106 DRI_CONF_NO_RAST(false)
109 static const GLuint __driNConfigOptions
= 10;
112 static const struct dri_debug_control debug_control
[] =
114 { "fall", DEBUG_FALLBACKS
},
115 { "api", DEBUG_VERBOSE_API
},
116 { "tex", DEBUG_VERBOSE_TEX
},
117 { "verb", DEBUG_VERBOSE_MSG
},
118 { "dma", DEBUG_DMA
},
119 { "state", DEBUG_STATE
},
123 int SAVAGE_DEBUG
= 0;
127 /*For time caculating test*/
128 #if defined(DEBUG_TIME) && DEBUG_TIME
129 struct timeval tv_s
,tv_f
;
130 unsigned long time_sum
=0;
131 struct timeval tv_s1
,tv_f1
;
134 static const struct dri_extension card_extensions
[] =
136 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
137 { "GL_ARB_multitexture", NULL
},
138 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
139 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
140 { "GL_EXT_stencil_wrap", NULL
},
141 { "GL_EXT_texture_lod_bias", NULL
},
142 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
146 static const struct dri_extension s4_extensions
[] =
148 { "GL_ARB_texture_env_add", NULL
},
149 { "GL_ARB_texture_mirrored_repeat", NULL
},
153 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
154 extern struct tnl_pipeline_stage _savage_render_stage
;
156 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
158 &_tnl_vertex_transform_stage
,
159 &_tnl_normal_transform_stage
,
160 &_tnl_lighting_stage
,
161 &_tnl_fog_coordinate_stage
,
163 &_tnl_texture_transform_stage
,
164 &_savage_texnorm_stage
,
165 &_savage_render_stage
,
171 PUBLIC
const __DRIextension
*savageScreenExtensions
[] = {
172 &driCoreExtension
.base
,
173 &driLegacyExtension
.base
,
174 &driReadDrawableExtension
,
178 savageInitDriver(__DRIscreenPrivate
*sPriv
)
180 savageScreenPrivate
*savageScreen
;
181 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
183 if (sPriv
->devPrivSize
!= sizeof(SAVAGEDRIRec
)) {
184 fprintf(stderr
,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
188 /* Allocate the private area */
189 savageScreen
= (savageScreenPrivate
*)Xmalloc(sizeof(savageScreenPrivate
));
193 savageScreen
->driScrnPriv
= sPriv
;
194 sPriv
->private = (void *)savageScreen
;
196 savageScreen
->chipset
=gDRIPriv
->chipset
;
197 savageScreen
->width
=gDRIPriv
->width
;
198 savageScreen
->height
=gDRIPriv
->height
;
199 savageScreen
->mem
=gDRIPriv
->mem
;
200 savageScreen
->cpp
=gDRIPriv
->cpp
;
201 savageScreen
->zpp
=gDRIPriv
->zpp
;
203 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
205 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
207 if (gDRIPriv
->cpp
== 4)
208 savageScreen
->frontFormat
= DV_PF_8888
;
210 savageScreen
->frontFormat
= DV_PF_565
;
211 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
212 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
213 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
215 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
216 gDRIPriv
->textureOffset
;
217 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
218 gDRIPriv
->textureSize
;
219 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
220 gDRIPriv
->logTextureGranularity
;
222 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
223 gDRIPriv
->agpTextureHandle
;
224 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
225 gDRIPriv
->agpTextureSize
;
226 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
227 gDRIPriv
->logAgpTextureGranularity
;
229 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
230 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
231 if (gDRIPriv
->agpTextureSize
) {
232 if (drmMap(sPriv
->fd
,
233 savageScreen
->agpTextures
.handle
,
234 savageScreen
->agpTextures
.size
,
235 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
237 sPriv
->private = NULL
;
241 savageScreen
->agpTextures
.map
= NULL
;
243 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
244 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
245 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
246 (drmAddress
)(savageScreen
->agpTextures
.map
);
248 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
249 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
250 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
251 if (drmMap(sPriv
->fd
,
252 savageScreen
->aperture
.handle
,
253 savageScreen
->aperture
.size
,
254 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
257 sPriv
->private = NULL
;
261 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
263 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
265 /* parse information in __driConfigOptions */
266 driParseOptionInfo (&savageScreen
->optionCache
,
267 __driConfigOptions
, __driNConfigOptions
);
269 sPriv
->extensions
= savageScreenExtensions
;
272 savageDDFastPathInit();
273 savageDDTrifuncInit();
279 /* Accessed by dlsym from dri_mesa_init.c
282 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
284 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
286 if (savageScreen
->bufs
)
287 drmUnmapBufs(savageScreen
->bufs
);
289 /* free all option information */
290 driDestroyOptionInfo (&savageScreen
->optionCache
);
293 sPriv
->private = NULL
;
297 savageCreateContext( const __GLcontextModes
*mesaVis
,
298 __DRIcontextPrivate
*driContextPriv
,
299 void *sharedContextPrivate
)
301 GLcontext
*ctx
, *shareCtx
;
302 savageContextPtr imesa
;
303 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
304 struct dd_function_table functions
;
305 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
306 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
307 savageScreen
->sarea_priv_offset
);
308 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
310 imesa
= (savageContextPtr
)Xcalloc(sizeof(savageContext
), 1);
315 /* Init default driver functions then plug in savage-specific texture
316 * functions that are needed as early as during context creation. */
317 _mesa_init_driver_functions( &functions
);
318 savageDDInitTextureFuncs( &functions
);
320 /* Allocate the Mesa context */
321 if (sharedContextPrivate
)
322 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
325 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
330 driContextPriv
->driverPrivate
= imesa
;
332 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
333 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
334 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
335 if (!imesa
->cmdBuf
.base
)
338 /* Parse configuration files */
339 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
340 sPriv
->myNum
, "savage");
342 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
343 savageScreen
->chipset
>= S3_SAVAGE4
;
344 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
347 ctx
->Const
.MinLineWidth
= 1.0;
348 ctx
->Const
.MinLineWidthAA
= 1.0;
349 ctx
->Const
.MaxLineWidth
= 3.0;
350 ctx
->Const
.MaxLineWidthAA
= 3.0;
351 ctx
->Const
.LineWidthGranularity
= 1.0;
356 imesa
->hHWContext
= driContextPriv
->hHWContext
;
357 imesa
->driFd
= sPriv
->fd
;
358 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
360 imesa
->savageScreen
= savageScreen
;
361 imesa
->driScreen
= sPriv
;
362 imesa
->sarea
= saPriv
;
363 imesa
->glBuffer
= NULL
;
369 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
373 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
375 /* change texHeap initialize to support two kind of texture heap*/
376 /* here is some parts of initialization, others in InitDriver() */
378 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
379 make_empty_list( & imesa
->swapped
);
381 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
382 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
383 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
384 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
385 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
386 if (textureSize
[SAVAGE_CARD_HEAP
])
387 imesa
->lastTexHeap
= 1;
389 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
390 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
391 textureSize
[SAVAGE_CARD_HEAP
] = 0;
393 /*default: Nothing to do, use all available memory. */
396 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
397 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
400 11, /* 2^11 = 2k alignment */
401 SAVAGE_NR_TEX_REGIONS
,
402 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
403 &imesa
->sarea
->texAge
[i
],
405 sizeof( savageTexObj
),
406 (destroy_texture_object_t
*) savageDestroyTexObj
);
407 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
408 * if there is not enough card memory for a card texture heap. */
409 if (imesa
->textureHeaps
[i
])
410 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
411 & imesa
->c_textureSwaps
);
413 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
415 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
416 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
417 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
419 if (savageScreen
->chipset
>= S3_SAVAGE4
)
420 ctx
->Const
.MaxTextureUnits
= 2;
422 ctx
->Const
.MaxTextureUnits
= 1;
423 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
424 ctx
->Const
.MaxTextureUnits
)
425 ctx
->Const
.MaxTextureUnits
=
426 driQueryOptioni(&imesa
->optionCache
, "texture_units");
427 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
428 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
430 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
434 11, /* max 2D texture size is 2048x2048 */
435 0, /* 3D textures unsupported. */
436 0, /* cube textures unsupported. */
437 0, /* texture rectangles unsupported. */
441 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
442 __driUtilMessage("Not enough texture memory. "
443 "Falling back to indirect rendering.");
448 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
449 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
450 (1.0F
/0xffff):(1.0F
/0xffffff);
452 imesa
->bufferSize
= savageScreen
->bufferSize
;
453 imesa
->dmaVtxBuf
.total
= 0;
454 imesa
->dmaVtxBuf
.used
= 0;
455 imesa
->dmaVtxBuf
.flushed
= 0;
457 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
458 imesa
->clientVtxBuf
.used
= 0;
459 imesa
->clientVtxBuf
.flushed
= 0;
460 imesa
->clientVtxBuf
.buf
= (uint32_t *)malloc(imesa
->bufferSize
);
462 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
464 imesa
->firstElt
= -1;
466 /* Uninitialized vertex format. Force setting the vertex state in
469 imesa
->vertex_size
= 0;
473 imesa
->new_state
= ~0;
474 imesa
->new_gl_state
= ~0;
475 imesa
->RenderIndex
= ~0;
477 imesa
->lostContext
= GL_TRUE
;
478 imesa
->CurrentTexObj
[0] = 0;
479 imesa
->CurrentTexObj
[1] = 0;
481 /* Initialize the software rasterizer and helper modules.
483 _swrast_CreateContext( ctx
);
484 _vbo_CreateContext( ctx
);
485 _tnl_CreateContext( ctx
);
487 _swsetup_CreateContext( ctx
);
489 /* Install the customized pipeline:
491 _tnl_destroy_pipeline( ctx
);
492 _tnl_install_pipeline( ctx
, savage_pipeline
);
494 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
496 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
497 * support was added in 2.2.0. */
498 if (imesa
->enable_fastpath
&& sPriv
->drm_version
.minor
< 2) {
500 "*** Disabling fast path because your DRM version is buggy "
501 "or doesn't\n*** support ELTS. You need at least Savage DRM "
503 imesa
->enable_fastpath
= GL_FALSE
;
506 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
507 imesa
->enable_vdma
= GL_FALSE
;
509 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
511 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
513 /* Configure swrast to match hardware characteristics:
515 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
516 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
517 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
518 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
520 ctx
->DriverCtx
= (void *) imesa
;
524 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
528 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
529 if (savageScreen
->chipset
>= S3_SAVAGE4
)
530 driInitExtensions( ctx
, s4_extensions
, GL_FALSE
);
531 if (ctx
->Mesa_DXTn
||
532 driQueryOptionb (&imesa
->optionCache
, "force_s3tc_enable")) {
533 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
534 if (savageScreen
->chipset
>= S3_SAVAGE4
)
535 /* This extension needs DXT3 and DTX5 support in hardware.
536 * Not available on Savage3D/MX/IX. */
537 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
540 savageDDInitStateFuncs( ctx
);
541 savageDDInitSpanFuncs( ctx
);
542 savageDDInitDriverFuncs( ctx
);
543 savageDDInitIoctlFuncs( ctx
);
544 savageInitTriFuncs( ctx
);
546 savageDDInitState( imesa
);
548 driContextPriv
->driverPrivate
= (void *) imesa
;
554 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
556 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
559 assert (imesa
); /* should never be NULL */
561 savageFlushVertices(imesa
);
562 savageReleaseIndexedVerts(imesa
);
563 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
564 WAIT_IDLE_EMPTY(imesa
);
566 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
567 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
569 free(imesa
->cmdBuf
.base
);
570 free(imesa
->clientVtxBuf
.buf
);
572 _swsetup_DestroyContext(imesa
->glCtx
);
573 _tnl_DestroyContext( imesa
->glCtx
);
574 _vbo_DestroyContext( imesa
->glCtx
);
575 _swrast_DestroyContext( imesa
->glCtx
);
577 /* free the Mesa context */
578 imesa
->glCtx
->DriverCtx
= NULL
;
579 _mesa_destroy_context(imesa
->glCtx
);
581 /* no longer use vertex_dma_buf*/
588 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
589 __DRIdrawablePrivate
*driDrawPriv
,
590 const __GLcontextModes
*mesaVis
,
593 savageScreenPrivate
*screen
= (savageScreenPrivate
*) driScrnPriv
->private;
596 return GL_FALSE
; /* not implemented */
599 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
600 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
602 * XXX: this value needs to be set according to the config file
603 * setting. But we don't get that until we create a rendering
606 GLboolean float_depth
= GL_FALSE
;
609 driRenderbuffer
*frontRb
610 = driNewRenderbuffer(GL_RGBA
,
611 (GLubyte
*) screen
->aperture
.map
612 + 0x01000000 * TARGET_FRONT
,
614 screen
->frontOffset
, screen
->aperturePitch
,
616 savageSetSpanFunctions(frontRb
, mesaVis
, float_depth
);
617 assert(frontRb
->Base
.Data
);
618 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
621 if (mesaVis
->doubleBufferMode
) {
622 driRenderbuffer
*backRb
623 = driNewRenderbuffer(GL_RGBA
,
624 (GLubyte
*) screen
->aperture
.map
625 + 0x01000000 * TARGET_BACK
,
627 screen
->backOffset
, screen
->aperturePitch
,
629 savageSetSpanFunctions(backRb
, mesaVis
, float_depth
);
630 assert(backRb
->Base
.Data
);
631 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
634 if (mesaVis
->depthBits
== 16) {
635 driRenderbuffer
*depthRb
636 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
637 (GLubyte
*) screen
->aperture
.map
638 + 0x01000000 * TARGET_DEPTH
,
640 screen
->depthOffset
, screen
->aperturePitch
,
642 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
643 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
645 else if (mesaVis
->depthBits
== 24) {
646 driRenderbuffer
*depthRb
647 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
648 (GLubyte
*) screen
->aperture
.map
649 + 0x01000000 * TARGET_DEPTH
,
651 screen
->depthOffset
, screen
->aperturePitch
,
653 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
654 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
657 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
658 driRenderbuffer
*stencilRb
659 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
660 (GLubyte
*) screen
->aperture
.map
661 + 0x01000000 * TARGET_DEPTH
,
663 screen
->depthOffset
, screen
->aperturePitch
,
665 savageSetSpanFunctions(stencilRb
, mesaVis
, float_depth
);
666 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
669 _mesa_add_soft_renderbuffers(fb
,
670 GL_FALSE
, /* color */
671 GL_FALSE
, /* depth */
673 mesaVis
->accumRedBits
> 0,
674 GL_FALSE
, /* alpha */
676 driDrawPriv
->driverPrivate
= (void *) fb
;
678 return (driDrawPriv
->driverPrivate
!= NULL
);
683 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
685 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
689 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
691 /* XXX should do swap according to the buffer, not the context! */
692 savageContextPtr imesa
= savageCtx
;
694 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
695 savageSwapBuffers(imesa
);
700 void savageXMesaSetClipRects(savageContextPtr imesa
)
702 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
704 if ((dPriv
->numBackClipRects
== 0)
705 || (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
)) {
706 imesa
->numClipRects
= dPriv
->numClipRects
;
707 imesa
->pClipRects
= dPriv
->pClipRects
;
708 imesa
->drawX
= dPriv
->x
;
709 imesa
->drawY
= dPriv
->y
;
711 imesa
->numClipRects
= dPriv
->numBackClipRects
;
712 imesa
->pClipRects
= dPriv
->pBackClipRects
;
713 imesa
->drawX
= dPriv
->backX
;
714 imesa
->drawY
= dPriv
->backY
;
717 savageCalcViewport( imesa
->glCtx
);
721 static void savageXMesaWindowMoved( savageContextPtr imesa
)
723 __DRIdrawablePrivate
*const drawable
= imesa
->driDrawable
;
724 __DRIdrawablePrivate
*const readable
= imesa
->driReadable
;
727 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
729 savageXMesaSetClipRects(imesa
);
731 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
732 if (drawable
!= readable
) {
733 driUpdateFramebufferSize(imesa
->glCtx
, readable
);
739 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
741 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
750 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
755 if (driContextPriv
) {
756 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
757 imesa
->IsFullScreen
= GL_TRUE
;
758 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
759 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
760 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
761 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
762 imesa
->toggle
= TARGET_BACK
;
769 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
772 if (driContextPriv
) {
773 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
774 WAIT_IDLE_EMPTY(imesa
);
775 imesa
->IsFullScreen
= GL_FALSE
;
776 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
777 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
778 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
785 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
786 __DRIdrawablePrivate
*driDrawPriv
,
787 __DRIdrawablePrivate
*driReadPriv
)
789 if (driContextPriv
) {
790 savageContextPtr imesa
791 = (savageContextPtr
) driContextPriv
->driverPrivate
;
792 struct gl_framebuffer
*drawBuffer
793 = (GLframebuffer
*) driDrawPriv
->driverPrivate
;
794 struct gl_framebuffer
*readBuffer
795 = (GLframebuffer
*) driReadPriv
->driverPrivate
;
796 driRenderbuffer
*frontRb
= (driRenderbuffer
*)
797 drawBuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
798 driRenderbuffer
*backRb
= (driRenderbuffer
*)
799 drawBuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
801 assert(frontRb
->Base
.Data
);
802 if (imesa
->glCtx
->Visual
.doubleBufferMode
) {
803 assert(backRb
->Base
.Data
);
806 imesa
->driReadable
= driReadPriv
;
807 imesa
->driDrawable
= driDrawPriv
;
810 _mesa_make_current(imesa
->glCtx
, drawBuffer
, readBuffer
);
812 savageXMesaWindowMoved( imesa
);
816 _mesa_make_current(NULL
, NULL
, NULL
);
822 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
824 __DRIdrawablePrivate
*const drawable
= imesa
->driDrawable
;
825 __DRIdrawablePrivate
*const readable
= imesa
->driReadable
;
826 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
827 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
828 int me
= imesa
->hHWContext
;
829 int stamp
= drawable
->lastStamp
;
831 unsigned int timestamp
= 0;
835 /* We know there has been contention.
837 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
840 /* Note contention for throttling hint
842 imesa
->any_contend
= 1;
844 /* If the window moved, may need to set a new cliprect now.
846 * NOTE: This releases and regains the hw lock, so all state
847 * checking must be done *after* this call:
849 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, drawable
);
850 if (drawable
!= readable
) {
851 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, readable
);
855 /* If we lost context, need to dump all registers to hardware.
856 * Note that we don't care about 2d contexts, even if they perform
857 * accelerated commands, so the DRI locking in the X server is even
858 * more broken than usual.
860 if (sarea
->ctxOwner
!= me
) {
861 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
862 SAVAGE_UPLOAD_GLOBAL
|
863 SAVAGE_UPLOAD_FOGTBL
|
866 SAVAGE_UPLOAD_TEXGLOBAL
);
867 imesa
->lostContext
= GL_TRUE
;
868 sarea
->ctxOwner
= me
;
871 for (heap
= 0; heap
< imesa
->lastTexHeap
; ++heap
) {
872 /* If a heap was changed, update its timestamp. Do this before
873 * DRI_AGE_TEXTURES updates the local_age. */
874 if (imesa
->textureHeaps
[heap
] &&
875 imesa
->textureHeaps
[heap
]->global_age
[0] >
876 imesa
->textureHeaps
[heap
]->local_age
) {
878 timestamp
= savageEmitEventLocked(imesa
, 0);
879 imesa
->textureHeaps
[heap
]->timestamp
= timestamp
;
881 DRI_AGE_TEXTURES( imesa
->textureHeaps
[heap
] );
884 if (drawable
->lastStamp
!= stamp
) {
885 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
886 savageXMesaWindowMoved( imesa
);
890 static const __DRIconfig
**
891 savageFillInModes( __DRIscreenPrivate
*psp
,
892 unsigned pixel_bits
, unsigned depth_bits
,
893 unsigned stencil_bits
, GLboolean have_back_buffer
)
895 __DRIconfig
**configs
;
896 __GLcontextModes
* m
;
897 unsigned depth_buffer_factor
;
898 unsigned back_buffer_factor
;
903 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
904 * enough to add support. Basically, if a context is created with an
905 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
906 * will never be used.
908 * FK: What about drivers that don't use page flipping? Could they
909 * just expose GLX_SWAP_COPY_OML?
911 static const GLenum back_buffer_modes
[] = {
912 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
915 uint8_t depth_bits_array
[2];
916 uint8_t stencil_bits_array
[2];
919 depth_bits_array
[0] = depth_bits
;
920 depth_bits_array
[1] = depth_bits
;
922 /* Just like with the accumulation buffer, always provide some modes
923 * with a stencil buffer. It will be a sw fallback, but some apps won't
926 stencil_bits_array
[0] = 0;
927 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
929 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
930 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
932 if ( pixel_bits
== 16 ) {
934 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
938 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
941 configs
= driCreateConfigs(fb_format
, fb_type
,
942 depth_bits_array
, stencil_bits_array
,
944 back_buffer_modes
, back_buffer_factor
);
945 if (configs
== NULL
) {
946 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
947 __func__
, __LINE__
);
951 /* Mark the visual as slow if there are "fake" stencil bits.
953 for (i
= 0; configs
[i
]; i
++) {
954 m
= &configs
[i
]->modes
;
955 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
956 m
->visualRating
= GLX_SLOW_CONFIG
;
960 return (const __DRIconfig
**) configs
;
965 * This is the driver specific part of the createNewScreen entry point.
967 * \todo maybe fold this into intelInitDriver
969 * \return the __GLcontextModes supported by this driver
971 static const __DRIconfig
**
972 savageInitScreen(__DRIscreenPrivate
*psp
)
974 static const __DRIversion ddx_expected
= { 2, 0, 0 };
975 static const __DRIversion dri_expected
= { 4, 0, 0 };
976 static const __DRIversion drm_expected
= { 2, 1, 0 };
977 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
979 if ( ! driCheckDriDdxDrmVersions2( "Savage",
980 &psp
->dri_version
, & dri_expected
,
981 &psp
->ddx_version
, & ddx_expected
,
982 &psp
->drm_version
, & drm_expected
) )
985 /* Calling driInitExtensions here, with a NULL context pointer,
986 * does not actually enable the extensions. It just makes sure
987 * that all the dispatch offsets for all the extensions that
988 * *might* be enables are known. This is needed because the
989 * dispatch offsets need to be known when _mesa_context_create is
990 * called, but we can't enable the extensions until we have a
993 * Hello chicken. Hello egg. How are you two today?
995 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
997 if (!savageInitDriver(psp
))
1000 return savageFillInModes( psp
,
1002 (dri_priv
->cpp
== 2) ? 16 : 24,
1003 (dri_priv
->cpp
== 2) ? 0 : 8,
1004 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1007 const struct __DriverAPIRec driDriverAPI
= {
1009 savageDestroyScreen
,
1010 savageCreateContext
,
1011 savageDestroyContext
,
1013 savageDestroyBuffer
,