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.
28 #include "main/context.h"
29 #include "main/context.h"
30 #include "main/matrix.h"
31 #include "main/framebuffer.h"
32 #include "main/renderbuffer.h"
33 #include "main/simple_list.h"
37 #include "main/extensions.h"
39 #include "swrast/swrast.h"
40 #include "swrast_setup/swrast_setup.h"
44 #include "tnl/t_pipeline.h"
46 #include "drivers/common/driverfuncs.h"
49 #include "savagestate.h"
50 #include "savagetex.h"
51 #include "savagespan.h"
52 #include "savagetris.h"
53 #include "savageioctl.h"
54 #include "savage_bci.h"
56 #include "savage_dri.h"
58 #include "drirenderbuffer.h"
61 #define need_GL_EXT_secondary_color
62 #include "extension_helper.h"
66 /* Driver-specific options
68 #define SAVAGE_ENABLE_VDMA(def) \
69 DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
70 DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
71 DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
73 #define SAVAGE_ENABLE_FASTPATH(def) \
74 DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
75 DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
76 DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
78 #define SAVAGE_SYNC_FRAMES(def) \
79 DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
80 DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
81 DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
86 PUBLIC
const char __driConfigOptions
[] =
88 DRI_CONF_SECTION_QUALITY
89 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
90 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
91 DRI_CONF_FLOAT_DEPTH(false)
93 DRI_CONF_SECTION_PERFORMANCE
94 SAVAGE_ENABLE_VDMA(true)
95 SAVAGE_ENABLE_FASTPATH(true)
96 SAVAGE_SYNC_FRAMES(false)
97 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
98 DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL
)
99 DRI_CONF_FORCE_S3TC_ENABLE(false)
101 DRI_CONF_SECTION_DEBUG
102 DRI_CONF_NO_RAST(false)
105 static const GLuint __driNConfigOptions
= 10;
108 static const struct dri_debug_control debug_control
[] =
110 { "fall", DEBUG_FALLBACKS
},
111 { "api", DEBUG_VERBOSE_API
},
112 { "tex", DEBUG_VERBOSE_TEX
},
113 { "verb", DEBUG_VERBOSE_MSG
},
114 { "dma", DEBUG_DMA
},
115 { "state", DEBUG_STATE
},
119 int SAVAGE_DEBUG
= 0;
123 /*For time caculating test*/
124 #if defined(DEBUG_TIME) && DEBUG_TIME
125 struct timeval tv_s
,tv_f
;
126 unsigned long time_sum
=0;
127 struct timeval tv_s1
,tv_f1
;
130 static const struct dri_extension card_extensions
[] =
132 { "GL_ARB_multitexture", NULL
},
133 { "GL_EXT_stencil_wrap", NULL
},
134 { "GL_EXT_texture_lod_bias", NULL
},
135 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
139 static const struct dri_extension s4_extensions
[] =
141 { "GL_ARB_texture_env_add", NULL
},
142 { "GL_ARB_texture_mirrored_repeat", NULL
},
146 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
147 extern struct tnl_pipeline_stage _savage_render_stage
;
149 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
151 &_tnl_vertex_transform_stage
,
152 &_tnl_normal_transform_stage
,
153 &_tnl_lighting_stage
,
154 &_tnl_fog_coordinate_stage
,
156 &_tnl_texture_transform_stage
,
157 &_savage_texnorm_stage
,
158 &_savage_render_stage
,
164 PUBLIC
const __DRIextension
*savageScreenExtensions
[] = {
165 &driCoreExtension
.base
,
166 &driLegacyExtension
.base
,
167 &driReadDrawableExtension
,
171 savageInitDriver(__DRIscreenPrivate
*sPriv
)
173 savageScreenPrivate
*savageScreen
;
174 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
176 if (sPriv
->devPrivSize
!= sizeof(SAVAGEDRIRec
)) {
177 fprintf(stderr
,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
181 /* Allocate the private area */
182 savageScreen
= (savageScreenPrivate
*)_mesa_malloc(sizeof(savageScreenPrivate
));
186 savageScreen
->driScrnPriv
= sPriv
;
187 sPriv
->private = (void *)savageScreen
;
189 savageScreen
->chipset
=gDRIPriv
->chipset
;
190 savageScreen
->width
=gDRIPriv
->width
;
191 savageScreen
->height
=gDRIPriv
->height
;
192 savageScreen
->mem
=gDRIPriv
->mem
;
193 savageScreen
->cpp
=gDRIPriv
->cpp
;
194 savageScreen
->zpp
=gDRIPriv
->zpp
;
196 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
198 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
200 if (gDRIPriv
->cpp
== 4)
201 savageScreen
->frontFormat
= DV_PF_8888
;
203 savageScreen
->frontFormat
= DV_PF_565
;
204 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
205 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
206 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
208 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
209 gDRIPriv
->textureOffset
;
210 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
211 gDRIPriv
->textureSize
;
212 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
213 gDRIPriv
->logTextureGranularity
;
215 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
216 gDRIPriv
->agpTextureHandle
;
217 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
218 gDRIPriv
->agpTextureSize
;
219 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
220 gDRIPriv
->logAgpTextureGranularity
;
222 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
223 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
224 if (gDRIPriv
->agpTextureSize
) {
225 if (drmMap(sPriv
->fd
,
226 savageScreen
->agpTextures
.handle
,
227 savageScreen
->agpTextures
.size
,
228 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
229 _mesa_free(savageScreen
);
230 sPriv
->private = NULL
;
234 savageScreen
->agpTextures
.map
= NULL
;
236 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
237 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
238 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
239 (drmAddress
)(savageScreen
->agpTextures
.map
);
241 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
242 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
243 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
244 if (drmMap(sPriv
->fd
,
245 savageScreen
->aperture
.handle
,
246 savageScreen
->aperture
.size
,
247 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
249 _mesa_free(savageScreen
);
250 sPriv
->private = NULL
;
254 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
256 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
258 /* parse information in __driConfigOptions */
259 driParseOptionInfo (&savageScreen
->optionCache
,
260 __driConfigOptions
, __driNConfigOptions
);
262 sPriv
->extensions
= savageScreenExtensions
;
265 savageDDFastPathInit();
266 savageDDTrifuncInit();
272 /* Accessed by dlsym from dri_mesa_init.c
275 savageDestroyScreen(__DRIscreenPrivate
*sPriv
)
277 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
279 if (savageScreen
->bufs
)
280 drmUnmapBufs(savageScreen
->bufs
);
282 /* free all option information */
283 driDestroyOptionInfo (&savageScreen
->optionCache
);
285 _mesa_free(savageScreen
);
286 sPriv
->private = NULL
;
290 savageCreateContext( const __GLcontextModes
*mesaVis
,
291 __DRIcontextPrivate
*driContextPriv
,
292 void *sharedContextPrivate
)
294 GLcontext
*ctx
, *shareCtx
;
295 savageContextPtr imesa
;
296 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
297 struct dd_function_table functions
;
298 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
299 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
300 savageScreen
->sarea_priv_offset
);
301 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
303 imesa
= (savageContextPtr
)_mesa_calloc(sizeof(savageContext
));
308 /* Init default driver functions then plug in savage-specific texture
309 * functions that are needed as early as during context creation. */
310 _mesa_init_driver_functions( &functions
);
311 savageDDInitTextureFuncs( &functions
);
313 /* Allocate the Mesa context */
314 if (sharedContextPrivate
)
315 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
318 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
323 driContextPriv
->driverPrivate
= imesa
;
325 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
326 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
327 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
328 if (!imesa
->cmdBuf
.base
)
331 /* Parse configuration files */
332 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
333 sPriv
->myNum
, "savage");
335 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
336 savageScreen
->chipset
>= S3_SAVAGE4
;
337 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
340 ctx
->Const
.MinLineWidth
= 1.0;
341 ctx
->Const
.MinLineWidthAA
= 1.0;
342 ctx
->Const
.MaxLineWidth
= 3.0;
343 ctx
->Const
.MaxLineWidthAA
= 3.0;
344 ctx
->Const
.LineWidthGranularity
= 1.0;
347 ctx
->Const
.MaxDrawBuffers
= 1;
351 imesa
->hHWContext
= driContextPriv
->hHWContext
;
352 imesa
->driFd
= sPriv
->fd
;
353 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
355 imesa
->savageScreen
= savageScreen
;
356 imesa
->driScreen
= sPriv
;
357 imesa
->sarea
= saPriv
;
358 imesa
->glBuffer
= NULL
;
364 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
368 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
370 /* change texHeap initialize to support two kind of texture heap*/
371 /* here is some parts of initialization, others in InitDriver() */
373 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
374 make_empty_list( & imesa
->swapped
);
376 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
377 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
378 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
379 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
380 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
381 if (textureSize
[SAVAGE_CARD_HEAP
])
382 imesa
->lastTexHeap
= 1;
384 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
385 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
386 textureSize
[SAVAGE_CARD_HEAP
] = 0;
388 /*default: Nothing to do, use all available memory. */
391 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
392 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
395 11, /* 2^11 = 2k alignment */
396 SAVAGE_NR_TEX_REGIONS
,
397 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
398 &imesa
->sarea
->texAge
[i
],
400 sizeof( savageTexObj
),
401 (destroy_texture_object_t
*) savageDestroyTexObj
);
402 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
403 * if there is not enough card memory for a card texture heap. */
404 if (imesa
->textureHeaps
[i
])
405 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
406 & imesa
->c_textureSwaps
);
408 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
410 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
411 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
412 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
414 if (savageScreen
->chipset
>= S3_SAVAGE4
)
415 ctx
->Const
.MaxTextureUnits
= 2;
417 ctx
->Const
.MaxTextureUnits
= 1;
418 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
419 ctx
->Const
.MaxTextureUnits
)
420 ctx
->Const
.MaxTextureUnits
=
421 driQueryOptioni(&imesa
->optionCache
, "texture_units");
422 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
423 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
425 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
429 11, /* max 2D texture size is 2048x2048 */
430 0, /* 3D textures unsupported. */
431 0, /* cube textures unsupported. */
432 0, /* texture rectangles unsupported. */
436 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
437 __driUtilMessage("Not enough texture memory. "
438 "Falling back to indirect rendering.");
443 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
444 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
445 (1.0F
/0xffff):(1.0F
/0xffffff);
447 imesa
->bufferSize
= savageScreen
->bufferSize
;
448 imesa
->dmaVtxBuf
.total
= 0;
449 imesa
->dmaVtxBuf
.used
= 0;
450 imesa
->dmaVtxBuf
.flushed
= 0;
452 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
453 imesa
->clientVtxBuf
.used
= 0;
454 imesa
->clientVtxBuf
.flushed
= 0;
455 imesa
->clientVtxBuf
.buf
= (uint32_t *)malloc(imesa
->bufferSize
);
457 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
459 imesa
->firstElt
= -1;
461 /* Uninitialized vertex format. Force setting the vertex state in
464 imesa
->vertex_size
= 0;
468 imesa
->new_state
= ~0;
469 imesa
->new_gl_state
= ~0;
470 imesa
->RenderIndex
= ~0;
472 imesa
->lostContext
= GL_TRUE
;
473 imesa
->CurrentTexObj
[0] = 0;
474 imesa
->CurrentTexObj
[1] = 0;
476 /* Initialize the software rasterizer and helper modules.
478 _swrast_CreateContext( ctx
);
479 _vbo_CreateContext( ctx
);
480 _tnl_CreateContext( ctx
);
482 _swsetup_CreateContext( ctx
);
484 /* Install the customized pipeline:
486 _tnl_destroy_pipeline( ctx
);
487 _tnl_install_pipeline( ctx
, savage_pipeline
);
489 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
491 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
492 * support was added in 2.2.0. */
493 if (imesa
->enable_fastpath
&& sPriv
->drm_version
.minor
< 2) {
495 "*** Disabling fast path because your DRM version is buggy "
496 "or doesn't\n*** support ELTS. You need at least Savage DRM "
498 imesa
->enable_fastpath
= GL_FALSE
;
501 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
502 imesa
->enable_vdma
= GL_FALSE
;
504 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
506 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
508 /* Configure swrast to match hardware characteristics:
510 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
511 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
512 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
513 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
515 ctx
->DriverCtx
= (void *) imesa
;
519 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
523 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
524 if (savageScreen
->chipset
>= S3_SAVAGE4
)
525 driInitExtensions( ctx
, s4_extensions
, GL_FALSE
);
526 if (ctx
->Mesa_DXTn
||
527 driQueryOptionb (&imesa
->optionCache
, "force_s3tc_enable")) {
528 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
529 if (savageScreen
->chipset
>= S3_SAVAGE4
)
530 /* This extension needs DXT3 and DTX5 support in hardware.
531 * Not available on Savage3D/MX/IX. */
532 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
535 savageDDInitStateFuncs( ctx
);
536 savageDDInitSpanFuncs( ctx
);
537 savageDDInitDriverFuncs( ctx
);
538 savageDDInitIoctlFuncs( ctx
);
539 savageInitTriFuncs( ctx
);
541 savageDDInitState( imesa
);
543 driContextPriv
->driverPrivate
= (void *) imesa
;
549 savageDestroyContext(__DRIcontextPrivate
*driContextPriv
)
551 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
554 assert (imesa
); /* should never be NULL */
556 savageFlushVertices(imesa
);
557 savageReleaseIndexedVerts(imesa
);
558 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
559 WAIT_IDLE_EMPTY(imesa
);
561 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
562 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
564 free(imesa
->cmdBuf
.base
);
565 free(imesa
->clientVtxBuf
.buf
);
567 _swsetup_DestroyContext(imesa
->glCtx
);
568 _tnl_DestroyContext( imesa
->glCtx
);
569 _vbo_DestroyContext( imesa
->glCtx
);
570 _swrast_DestroyContext( imesa
->glCtx
);
572 /* free the Mesa context */
573 imesa
->glCtx
->DriverCtx
= NULL
;
574 _mesa_destroy_context(imesa
->glCtx
);
576 /* no longer use vertex_dma_buf*/
583 savageCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
584 __DRIdrawablePrivate
*driDrawPriv
,
585 const __GLcontextModes
*mesaVis
,
588 savageScreenPrivate
*screen
= (savageScreenPrivate
*) driScrnPriv
->private;
591 return GL_FALSE
; /* not implemented */
594 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
595 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
597 * XXX: this value needs to be set according to the config file
598 * setting. But we don't get that until we create a rendering
601 GLboolean float_depth
= GL_FALSE
;
604 driRenderbuffer
*frontRb
605 = driNewRenderbuffer(GL_RGBA
,
606 (GLubyte
*) screen
->aperture
.map
607 + 0x01000000 * TARGET_FRONT
,
609 screen
->frontOffset
, screen
->aperturePitch
,
611 savageSetSpanFunctions(frontRb
, mesaVis
, float_depth
);
612 assert(frontRb
->Base
.Data
);
613 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
616 if (mesaVis
->doubleBufferMode
) {
617 driRenderbuffer
*backRb
618 = driNewRenderbuffer(GL_RGBA
,
619 (GLubyte
*) screen
->aperture
.map
620 + 0x01000000 * TARGET_BACK
,
622 screen
->backOffset
, screen
->aperturePitch
,
624 savageSetSpanFunctions(backRb
, mesaVis
, float_depth
);
625 assert(backRb
->Base
.Data
);
626 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
629 if (mesaVis
->depthBits
== 16) {
630 driRenderbuffer
*depthRb
631 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
632 (GLubyte
*) screen
->aperture
.map
633 + 0x01000000 * TARGET_DEPTH
,
635 screen
->depthOffset
, screen
->aperturePitch
,
637 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
638 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
640 else if (mesaVis
->depthBits
== 24) {
641 driRenderbuffer
*depthRb
642 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
643 (GLubyte
*) screen
->aperture
.map
644 + 0x01000000 * TARGET_DEPTH
,
646 screen
->depthOffset
, screen
->aperturePitch
,
648 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
649 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
652 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
653 driRenderbuffer
*stencilRb
654 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
655 (GLubyte
*) screen
->aperture
.map
656 + 0x01000000 * TARGET_DEPTH
,
658 screen
->depthOffset
, screen
->aperturePitch
,
660 savageSetSpanFunctions(stencilRb
, mesaVis
, float_depth
);
661 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
664 _mesa_add_soft_renderbuffers(fb
,
665 GL_FALSE
, /* color */
666 GL_FALSE
, /* depth */
668 mesaVis
->accumRedBits
> 0,
669 GL_FALSE
, /* alpha */
671 driDrawPriv
->driverPrivate
= (void *) fb
;
673 return (driDrawPriv
->driverPrivate
!= NULL
);
678 savageDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
680 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
684 void XMesaSwapBuffers(__DRIdrawablePrivate
*driDrawPriv
)
686 /* XXX should do swap according to the buffer, not the context! */
687 savageContextPtr imesa
= savageCtx
;
689 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
690 savageSwapBuffers(imesa
);
695 void savageXMesaSetClipRects(savageContextPtr imesa
)
697 __DRIdrawablePrivate
*dPriv
= imesa
->driDrawable
;
699 if ((dPriv
->numBackClipRects
== 0)
700 || (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
)) {
701 imesa
->numClipRects
= dPriv
->numClipRects
;
702 imesa
->pClipRects
= dPriv
->pClipRects
;
703 imesa
->drawX
= dPriv
->x
;
704 imesa
->drawY
= dPriv
->y
;
706 imesa
->numClipRects
= dPriv
->numBackClipRects
;
707 imesa
->pClipRects
= dPriv
->pBackClipRects
;
708 imesa
->drawX
= dPriv
->backX
;
709 imesa
->drawY
= dPriv
->backY
;
712 savageCalcViewport( imesa
->glCtx
);
716 static void savageXMesaWindowMoved( savageContextPtr imesa
)
718 __DRIdrawablePrivate
*const drawable
= imesa
->driDrawable
;
719 __DRIdrawablePrivate
*const readable
= imesa
->driReadable
;
722 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
724 savageXMesaSetClipRects(imesa
);
726 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
727 if (drawable
!= readable
) {
728 driUpdateFramebufferSize(imesa
->glCtx
, readable
);
734 savageUnbindContext(__DRIcontextPrivate
*driContextPriv
)
736 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
745 savageOpenFullScreen(__DRIcontextPrivate
*driContextPriv
)
750 if (driContextPriv
) {
751 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
752 imesa
->IsFullScreen
= GL_TRUE
;
753 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
754 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
755 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
756 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
757 imesa
->toggle
= TARGET_BACK
;
764 savageCloseFullScreen(__DRIcontextPrivate
*driContextPriv
)
767 if (driContextPriv
) {
768 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
769 WAIT_IDLE_EMPTY(imesa
);
770 imesa
->IsFullScreen
= GL_FALSE
;
771 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
772 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
773 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
780 savageMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
781 __DRIdrawablePrivate
*driDrawPriv
,
782 __DRIdrawablePrivate
*driReadPriv
)
784 if (driContextPriv
) {
785 savageContextPtr imesa
786 = (savageContextPtr
) driContextPriv
->driverPrivate
;
787 struct gl_framebuffer
*drawBuffer
788 = (GLframebuffer
*) driDrawPriv
->driverPrivate
;
789 struct gl_framebuffer
*readBuffer
790 = (GLframebuffer
*) driReadPriv
->driverPrivate
;
791 driRenderbuffer
*frontRb
= (driRenderbuffer
*)
792 drawBuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
793 driRenderbuffer
*backRb
= (driRenderbuffer
*)
794 drawBuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
796 assert(frontRb
->Base
.Data
);
797 if (imesa
->glCtx
->Visual
.doubleBufferMode
) {
798 assert(backRb
->Base
.Data
);
801 imesa
->driReadable
= driReadPriv
;
802 imesa
->driDrawable
= driDrawPriv
;
805 _mesa_make_current(imesa
->glCtx
, drawBuffer
, readBuffer
);
807 savageXMesaWindowMoved( imesa
);
811 _mesa_make_current(NULL
, NULL
, NULL
);
817 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
819 __DRIdrawablePrivate
*const drawable
= imesa
->driDrawable
;
820 __DRIdrawablePrivate
*const readable
= imesa
->driReadable
;
821 __DRIscreenPrivate
*sPriv
= imesa
->driScreen
;
822 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
823 int me
= imesa
->hHWContext
;
824 int stamp
= drawable
->lastStamp
;
826 unsigned int timestamp
= 0;
830 /* We know there has been contention.
832 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
835 /* Note contention for throttling hint
837 imesa
->any_contend
= 1;
839 /* If the window moved, may need to set a new cliprect now.
841 * NOTE: This releases and regains the hw lock, so all state
842 * checking must be done *after* this call:
844 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, drawable
);
845 if (drawable
!= readable
) {
846 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, readable
);
850 /* If we lost context, need to dump all registers to hardware.
851 * Note that we don't care about 2d contexts, even if they perform
852 * accelerated commands, so the DRI locking in the X server is even
853 * more broken than usual.
855 if (sarea
->ctxOwner
!= me
) {
856 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
857 SAVAGE_UPLOAD_GLOBAL
|
858 SAVAGE_UPLOAD_FOGTBL
|
861 SAVAGE_UPLOAD_TEXGLOBAL
);
862 imesa
->lostContext
= GL_TRUE
;
863 sarea
->ctxOwner
= me
;
866 for (heap
= 0; heap
< imesa
->lastTexHeap
; ++heap
) {
867 /* If a heap was changed, update its timestamp. Do this before
868 * DRI_AGE_TEXTURES updates the local_age. */
869 if (imesa
->textureHeaps
[heap
] &&
870 imesa
->textureHeaps
[heap
]->global_age
[0] >
871 imesa
->textureHeaps
[heap
]->local_age
) {
873 timestamp
= savageEmitEventLocked(imesa
, 0);
874 imesa
->textureHeaps
[heap
]->timestamp
= timestamp
;
876 DRI_AGE_TEXTURES( imesa
->textureHeaps
[heap
] );
879 if (drawable
->lastStamp
!= stamp
) {
880 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
881 savageXMesaWindowMoved( imesa
);
885 static const __DRIconfig
**
886 savageFillInModes( __DRIscreenPrivate
*psp
,
887 unsigned pixel_bits
, unsigned depth_bits
,
888 unsigned stencil_bits
, GLboolean have_back_buffer
)
890 __DRIconfig
**configs
;
891 __GLcontextModes
* m
;
892 unsigned depth_buffer_factor
;
893 unsigned back_buffer_factor
;
898 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
899 * enough to add support. Basically, if a context is created with an
900 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
901 * will never be used.
903 * FK: What about drivers that don't use page flipping? Could they
904 * just expose GLX_SWAP_COPY_OML?
906 static const GLenum back_buffer_modes
[] = {
907 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
910 uint8_t depth_bits_array
[2];
911 uint8_t stencil_bits_array
[2];
912 uint8_t msaa_samples_array
[1];
914 depth_bits_array
[0] = depth_bits
;
915 depth_bits_array
[1] = depth_bits
;
917 /* Just like with the accumulation buffer, always provide some modes
918 * with a stencil buffer. It will be a sw fallback, but some apps won't
921 stencil_bits_array
[0] = 0;
922 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
924 msaa_samples_array
[0] = 0;
926 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
927 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
929 if ( pixel_bits
== 16 ) {
931 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
935 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
938 configs
= driCreateConfigs(fb_format
, fb_type
,
939 depth_bits_array
, stencil_bits_array
,
941 back_buffer_modes
, back_buffer_factor
,
942 msaa_samples_array
, 1);
943 if (configs
== NULL
) {
944 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
945 __func__
, __LINE__
);
949 /* Mark the visual as slow if there are "fake" stencil bits.
951 for (i
= 0; configs
[i
]; i
++) {
952 m
= &configs
[i
]->modes
;
953 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
954 m
->visualRating
= GLX_SLOW_CONFIG
;
958 return (const __DRIconfig
**) configs
;
963 * This is the driver specific part of the createNewScreen entry point.
965 * \todo maybe fold this into intelInitDriver
967 * \return the __GLcontextModes supported by this driver
969 static const __DRIconfig
**
970 savageInitScreen(__DRIscreenPrivate
*psp
)
972 static const __DRIversion ddx_expected
= { 2, 0, 0 };
973 static const __DRIversion dri_expected
= { 4, 0, 0 };
974 static const __DRIversion drm_expected
= { 2, 1, 0 };
975 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
977 if ( ! driCheckDriDdxDrmVersions2( "Savage",
978 &psp
->dri_version
, & dri_expected
,
979 &psp
->ddx_version
, & ddx_expected
,
980 &psp
->drm_version
, & drm_expected
) )
983 /* Calling driInitExtensions here, with a NULL context pointer,
984 * does not actually enable the extensions. It just makes sure
985 * that all the dispatch offsets for all the extensions that
986 * *might* be enables are known. This is needed because the
987 * dispatch offsets need to be known when _mesa_context_create is
988 * called, but we can't enable the extensions until we have a
991 * Hello chicken. Hello egg. How are you two today?
993 driInitExtensions( NULL
, card_extensions
, GL_FALSE
);
995 if (!savageInitDriver(psp
))
998 return savageFillInModes( psp
,
1000 (dri_priv
->cpp
== 2) ? 16 : 24,
1001 (dri_priv
->cpp
== 2) ? 0 : 8,
1002 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
1005 const struct __DriverAPIRec driDriverAPI
= {
1007 savageDestroyScreen
,
1008 savageCreateContext
,
1009 savageDestroyContext
,
1011 savageDestroyBuffer
,