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"
47 #include "drivers/common/meta.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_EXT_secondary_color
63 #include "main/remap_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_multitexture", NULL
},
134 { "GL_EXT_stencil_wrap", NULL
},
135 { "GL_EXT_texture_lod_bias", NULL
},
136 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
140 static const struct dri_extension s4_extensions
[] =
142 { "GL_ARB_texture_env_add", NULL
},
143 { "GL_ARB_texture_mirrored_repeat", 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 PUBLIC
const __DRIextension
*savageScreenExtensions
[] = {
166 &driCoreExtension
.base
,
167 &driLegacyExtension
.base
,
168 &driReadDrawableExtension
,
172 savageInitDriver(__DRIscreen
*sPriv
)
174 savageScreenPrivate
*savageScreen
;
175 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
177 if (sPriv
->devPrivSize
!= sizeof(SAVAGEDRIRec
)) {
178 fprintf(stderr
,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
182 /* Allocate the private area */
183 savageScreen
= (savageScreenPrivate
*)malloc(sizeof(savageScreenPrivate
));
187 savageScreen
->driScrnPriv
= sPriv
;
188 sPriv
->private = (void *)savageScreen
;
190 savageScreen
->chipset
=gDRIPriv
->chipset
;
191 savageScreen
->width
=gDRIPriv
->width
;
192 savageScreen
->height
=gDRIPriv
->height
;
193 savageScreen
->mem
=gDRIPriv
->mem
;
194 savageScreen
->cpp
=gDRIPriv
->cpp
;
195 savageScreen
->zpp
=gDRIPriv
->zpp
;
197 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
199 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
201 if (gDRIPriv
->cpp
== 4)
202 savageScreen
->frontFormat
= DV_PF_8888
;
204 savageScreen
->frontFormat
= DV_PF_565
;
205 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
206 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
207 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
209 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
210 gDRIPriv
->textureOffset
;
211 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
212 gDRIPriv
->textureSize
;
213 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
214 gDRIPriv
->logTextureGranularity
;
216 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
217 gDRIPriv
->agpTextureHandle
;
218 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
219 gDRIPriv
->agpTextureSize
;
220 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
221 gDRIPriv
->logAgpTextureGranularity
;
223 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
224 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
225 if (gDRIPriv
->agpTextureSize
) {
226 if (drmMap(sPriv
->fd
,
227 savageScreen
->agpTextures
.handle
,
228 savageScreen
->agpTextures
.size
,
229 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
231 sPriv
->private = NULL
;
235 savageScreen
->agpTextures
.map
= NULL
;
237 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
238 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
239 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
240 (drmAddress
)(savageScreen
->agpTextures
.map
);
242 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
243 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
244 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
245 if (drmMap(sPriv
->fd
,
246 savageScreen
->aperture
.handle
,
247 savageScreen
->aperture
.size
,
248 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
251 sPriv
->private = NULL
;
255 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
257 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
259 /* parse information in __driConfigOptions */
260 driParseOptionInfo (&savageScreen
->optionCache
,
261 __driConfigOptions
, __driNConfigOptions
);
263 sPriv
->extensions
= savageScreenExtensions
;
266 savageDDFastPathInit();
267 savageDDTrifuncInit();
273 /* Accessed by dlsym from dri_mesa_init.c
276 savageDestroyScreen(__DRIscreen
*sPriv
)
278 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
280 if (savageScreen
->bufs
)
281 drmUnmapBufs(savageScreen
->bufs
);
283 /* free all option information */
284 driDestroyOptionInfo (&savageScreen
->optionCache
);
287 sPriv
->private = NULL
;
291 savageCreateContext( const __GLcontextModes
*mesaVis
,
292 __DRIcontext
*driContextPriv
,
293 void *sharedContextPrivate
)
295 GLcontext
*ctx
, *shareCtx
;
296 savageContextPtr imesa
;
297 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
298 struct dd_function_table functions
;
299 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
300 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
301 savageScreen
->sarea_priv_offset
);
302 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
304 imesa
= (savageContextPtr
)calloc(1, sizeof(savageContext
));
309 /* Init default driver functions then plug in savage-specific texture
310 * functions that are needed as early as during context creation. */
311 _mesa_init_driver_functions( &functions
);
312 savageDDInitTextureFuncs( &functions
);
314 /* Allocate the Mesa context */
315 if (sharedContextPrivate
)
316 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
319 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
324 driContextPriv
->driverPrivate
= imesa
;
326 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
327 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
328 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
329 if (!imesa
->cmdBuf
.base
)
332 /* Parse configuration files */
333 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
334 sPriv
->myNum
, "savage");
336 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
337 savageScreen
->chipset
>= S3_SAVAGE4
;
338 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
341 ctx
->Const
.MinLineWidth
= 1.0;
342 ctx
->Const
.MinLineWidthAA
= 1.0;
343 ctx
->Const
.MaxLineWidth
= 3.0;
344 ctx
->Const
.MaxLineWidthAA
= 3.0;
345 ctx
->Const
.LineWidthGranularity
= 1.0;
348 ctx
->Const
.MaxDrawBuffers
= 1;
352 imesa
->hHWContext
= driContextPriv
->hHWContext
;
353 imesa
->driFd
= sPriv
->fd
;
354 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
356 imesa
->savageScreen
= savageScreen
;
357 imesa
->driScreen
= sPriv
;
358 imesa
->sarea
= saPriv
;
359 imesa
->glBuffer
= NULL
;
365 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
369 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
371 /* change texHeap initialize to support two kind of texture heap*/
372 /* here is some parts of initialization, others in InitDriver() */
374 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
375 make_empty_list( & imesa
->swapped
);
377 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
378 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
379 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
380 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
381 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
382 if (textureSize
[SAVAGE_CARD_HEAP
])
383 imesa
->lastTexHeap
= 1;
385 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
386 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
387 textureSize
[SAVAGE_CARD_HEAP
] = 0;
389 /*default: Nothing to do, use all available memory. */
392 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
393 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
396 11, /* 2^11 = 2k alignment */
397 SAVAGE_NR_TEX_REGIONS
,
398 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
399 &imesa
->sarea
->texAge
[i
],
401 sizeof( savageTexObj
),
402 (destroy_texture_object_t
*) savageDestroyTexObj
);
403 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
404 * if there is not enough card memory for a card texture heap. */
405 if (imesa
->textureHeaps
[i
])
406 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
407 & imesa
->c_textureSwaps
);
409 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
411 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
412 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
413 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
415 if (savageScreen
->chipset
>= S3_SAVAGE4
)
416 ctx
->Const
.MaxTextureUnits
= 2;
418 ctx
->Const
.MaxTextureUnits
= 1;
419 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
420 ctx
->Const
.MaxTextureUnits
)
421 ctx
->Const
.MaxTextureUnits
=
422 driQueryOptioni(&imesa
->optionCache
, "texture_units");
423 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
424 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
426 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
430 11, /* max 2D texture size is 2048x2048 */
431 0, /* 3D textures unsupported. */
432 0, /* cube textures unsupported. */
433 0, /* texture rectangles unsupported. */
437 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
438 __driUtilMessage("Not enough texture memory. "
439 "Falling back to indirect rendering.");
444 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
445 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
446 (1.0F
/0xffff):(1.0F
/0xffffff);
448 imesa
->bufferSize
= savageScreen
->bufferSize
;
449 imesa
->dmaVtxBuf
.total
= 0;
450 imesa
->dmaVtxBuf
.used
= 0;
451 imesa
->dmaVtxBuf
.flushed
= 0;
453 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
454 imesa
->clientVtxBuf
.used
= 0;
455 imesa
->clientVtxBuf
.flushed
= 0;
456 imesa
->clientVtxBuf
.buf
= (uint32_t *)malloc(imesa
->bufferSize
);
458 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
460 imesa
->firstElt
= -1;
462 /* Uninitialized vertex format. Force setting the vertex state in
465 imesa
->vertex_size
= 0;
469 imesa
->new_state
= ~0;
470 imesa
->new_gl_state
= ~0;
471 imesa
->RenderIndex
= ~0;
473 imesa
->lostContext
= GL_TRUE
;
474 imesa
->CurrentTexObj
[0] = 0;
475 imesa
->CurrentTexObj
[1] = 0;
477 _mesa_meta_init( ctx
);
479 /* Initialize the software rasterizer and helper modules.
481 _swrast_CreateContext( ctx
);
482 _vbo_CreateContext( ctx
);
483 _tnl_CreateContext( ctx
);
485 _swsetup_CreateContext( ctx
);
487 /* Install the customized pipeline:
489 _tnl_destroy_pipeline( ctx
);
490 _tnl_install_pipeline( ctx
, savage_pipeline
);
492 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
494 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
495 * support was added in 2.2.0. */
496 if (imesa
->enable_fastpath
&& sPriv
->drm_version
.minor
< 2) {
498 "*** Disabling fast path because your DRM version is buggy "
499 "or doesn't\n*** support ELTS. You need at least Savage DRM "
501 imesa
->enable_fastpath
= GL_FALSE
;
504 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
505 imesa
->enable_vdma
= GL_FALSE
;
507 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
509 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
511 /* Configure swrast to match hardware characteristics:
513 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
514 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
515 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
516 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
518 ctx
->DriverCtx
= (void *) imesa
;
522 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
526 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
527 if (savageScreen
->chipset
>= S3_SAVAGE4
)
528 driInitExtensions( ctx
, s4_extensions
, GL_FALSE
);
529 if (ctx
->Mesa_DXTn
||
530 driQueryOptionb (&imesa
->optionCache
, "force_s3tc_enable")) {
531 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
532 if (savageScreen
->chipset
>= S3_SAVAGE4
)
533 /* This extension needs DXT3 and DTX5 support in hardware.
534 * Not available on Savage3D/MX/IX. */
535 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
538 savageDDInitStateFuncs( ctx
);
539 savageDDInitSpanFuncs( ctx
);
540 savageDDInitDriverFuncs( ctx
);
541 savageDDInitIoctlFuncs( ctx
);
542 savageInitTriFuncs( ctx
);
544 savageDDInitState( imesa
);
546 driContextPriv
->driverPrivate
= (void *) imesa
;
552 savageDestroyContext(__DRIcontext
*driContextPriv
)
554 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
557 assert (imesa
); /* should never be NULL */
559 savageFlushVertices(imesa
);
560 savageReleaseIndexedVerts(imesa
);
561 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
562 WAIT_IDLE_EMPTY(imesa
);
564 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
565 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
567 free(imesa
->cmdBuf
.base
);
568 free(imesa
->clientVtxBuf
.buf
);
570 _mesa_meta_free( imesa
->glCtx
);
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( __DRIscreen
*driScrnPriv
,
589 __DRIdrawable
*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(MESA_FORMAT_ARGB8888
,
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(MESA_FORMAT_ARGB8888
,
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(MESA_FORMAT_Z16
,
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(MESA_FORMAT_S8_Z24
,
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(MESA_FORMAT_S8
,
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(__DRIdrawable
*driDrawPriv
)
685 _mesa_reference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
689 void XMesaSwapBuffers(__DRIdrawable
*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 __DRIdrawable
*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 __DRIdrawable
*const drawable
= imesa
->driDrawable
;
724 __DRIdrawable
*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(__DRIcontext
*driContextPriv
)
741 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
750 savageOpenFullScreen(__DRIcontext
*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(__DRIcontext
*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(__DRIcontext
*driContextPriv
,
786 __DRIdrawable
*driDrawPriv
,
787 __DRIdrawable
*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 __DRIdrawable
*const drawable
= imesa
->driDrawable
;
825 __DRIdrawable
*const readable
= imesa
->driReadable
;
826 __DRIscreen
*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( __DRIscreen
*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];
917 uint8_t msaa_samples_array
[1];
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 msaa_samples_array
[0] = 0;
931 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
932 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
934 if ( pixel_bits
== 16 ) {
936 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
940 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
943 configs
= driCreateConfigs(fb_format
, fb_type
,
944 depth_bits_array
, stencil_bits_array
,
946 back_buffer_modes
, back_buffer_factor
,
947 msaa_samples_array
, 1, GL_TRUE
);
948 if (configs
== NULL
) {
949 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
950 __func__
, __LINE__
);
954 /* Mark the visual as slow if there are "fake" stencil bits.
956 for (i
= 0; configs
[i
]; i
++) {
957 m
= &configs
[i
]->modes
;
958 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
959 m
->visualRating
= GLX_SLOW_CONFIG
;
963 return (const __DRIconfig
**) configs
;
968 * This is the driver specific part of the createNewScreen entry point.
970 * \todo maybe fold this into intelInitDriver
972 * \return the __GLcontextModes supported by this driver
974 static const __DRIconfig
**
975 savageInitScreen(__DRIscreen
*psp
)
977 static const __DRIversion ddx_expected
= { 2, 0, 0 };
978 static const __DRIversion dri_expected
= { 4, 0, 0 };
979 static const __DRIversion drm_expected
= { 2, 1, 0 };
980 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
982 if ( ! driCheckDriDdxDrmVersions2( "Savage",
983 &psp
->dri_version
, & dri_expected
,
984 &psp
->ddx_version
, & ddx_expected
,
985 &psp
->drm_version
, & drm_expected
) )
988 if (!savageInitDriver(psp
))
991 return savageFillInModes( psp
,
993 (dri_priv
->cpp
== 2) ? 16 : 24,
994 (dri_priv
->cpp
== 2) ? 0 : 8,
995 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
998 const struct __DriverAPIRec driDriverAPI
= {
1000 savageDestroyScreen
,
1001 savageCreateContext
,
1002 savageDestroyContext
,
1004 savageDestroyBuffer
,
1010 /* This is the table of extensions that the loader will dlsym() for. */
1011 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1012 &driCoreExtension
.base
,
1013 &driLegacyExtension
.base
,