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/framebuffer.h"
30 #include "main/renderbuffer.h"
31 #include "main/simple_list.h"
35 #include "main/extensions.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
42 #include "tnl/t_pipeline.h"
44 #include "drivers/common/driverfuncs.h"
45 #include "drivers/common/meta.h"
48 #include "savagestate.h"
49 #include "savagetex.h"
50 #include "savagespan.h"
51 #include "savagetris.h"
52 #include "savageioctl.h"
54 #include "savage_dri.h"
56 #include "drirenderbuffer.h"
59 #define need_GL_EXT_secondary_color
60 #include "main/remap_helper.h"
64 /* Driver-specific options
66 #define SAVAGE_ENABLE_VDMA(def) \
67 DRI_CONF_OPT_BEGIN(enable_vdma,bool,def) \
68 DRI_CONF_DESC(en,"Use DMA for vertex transfers") \
69 DRI_CONF_DESC(de,"Benutze DMA für Vertextransfers") \
71 #define SAVAGE_ENABLE_FASTPATH(def) \
72 DRI_CONF_OPT_BEGIN(enable_fastpath,bool,def) \
73 DRI_CONF_DESC(en,"Use fast path for unclipped primitives") \
74 DRI_CONF_DESC(de,"Schneller Codepfad für ungeschnittene Polygone") \
76 #define SAVAGE_SYNC_FRAMES(def) \
77 DRI_CONF_OPT_BEGIN(sync_frames,bool,def) \
78 DRI_CONF_DESC(en,"Synchronize with graphics hardware after each frame") \
79 DRI_CONF_DESC(de,"Synchronisiere nach jedem Frame mit Grafikhardware") \
84 PUBLIC
const char __driConfigOptions
[] =
86 DRI_CONF_SECTION_QUALITY
87 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
88 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER
)
89 DRI_CONF_FLOAT_DEPTH(false)
91 DRI_CONF_SECTION_PERFORMANCE
92 SAVAGE_ENABLE_VDMA(true)
93 SAVAGE_ENABLE_FASTPATH(true)
94 SAVAGE_SYNC_FRAMES(false)
95 DRI_CONF_MAX_TEXTURE_UNITS(2,1,2)
96 DRI_CONF_TEXTURE_HEAPS(DRI_CONF_TEXTURE_HEAPS_ALL
)
97 DRI_CONF_FORCE_S3TC_ENABLE(false)
99 DRI_CONF_SECTION_DEBUG
100 DRI_CONF_NO_RAST(false)
103 static const GLuint __driNConfigOptions
= 10;
106 static const struct dri_debug_control debug_control
[] =
108 { "fall", DEBUG_FALLBACKS
},
109 { "api", DEBUG_VERBOSE_API
},
110 { "tex", DEBUG_VERBOSE_TEX
},
111 { "verb", DEBUG_VERBOSE_MSG
},
112 { "dma", DEBUG_DMA
},
113 { "state", DEBUG_STATE
},
117 int SAVAGE_DEBUG
= 0;
121 /*For time caculating test*/
122 #if defined(DEBUG_TIME) && DEBUG_TIME
123 struct timeval tv_s
,tv_f
;
124 unsigned long time_sum
=0;
125 struct timeval tv_s1
,tv_f1
;
128 static const struct dri_extension card_extensions
[] =
130 { "GL_ARB_multitexture", NULL
},
131 { "GL_EXT_stencil_wrap", NULL
},
132 { "GL_EXT_texture_lod_bias", NULL
},
133 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
137 static const struct dri_extension s4_extensions
[] =
139 { "GL_ARB_texture_env_add", NULL
},
140 { "GL_ARB_texture_mirrored_repeat", NULL
},
144 extern struct tnl_pipeline_stage _savage_texnorm_stage
;
145 extern struct tnl_pipeline_stage _savage_render_stage
;
147 static const struct tnl_pipeline_stage
*savage_pipeline
[] = {
149 &_tnl_vertex_transform_stage
,
150 &_tnl_normal_transform_stage
,
151 &_tnl_lighting_stage
,
152 &_tnl_fog_coordinate_stage
,
154 &_tnl_texture_transform_stage
,
155 &_savage_texnorm_stage
,
156 &_savage_render_stage
,
162 PUBLIC
const __DRIextension
*savageScreenExtensions
[] = {
163 &driCoreExtension
.base
,
164 &driLegacyExtension
.base
,
165 &driReadDrawableExtension
,
169 savageInitDriver(__DRIscreen
*sPriv
)
171 savageScreenPrivate
*savageScreen
;
172 SAVAGEDRIPtr gDRIPriv
= (SAVAGEDRIPtr
)sPriv
->pDevPriv
;
174 if (sPriv
->devPrivSize
!= sizeof(SAVAGEDRIRec
)) {
175 fprintf(stderr
,"\nERROR! sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
179 /* Allocate the private area */
180 savageScreen
= (savageScreenPrivate
*)malloc(sizeof(savageScreenPrivate
));
184 savageScreen
->driScrnPriv
= sPriv
;
185 sPriv
->private = (void *)savageScreen
;
187 savageScreen
->chipset
=gDRIPriv
->chipset
;
188 savageScreen
->width
=gDRIPriv
->width
;
189 savageScreen
->height
=gDRIPriv
->height
;
190 savageScreen
->mem
=gDRIPriv
->mem
;
191 savageScreen
->cpp
=gDRIPriv
->cpp
;
192 savageScreen
->zpp
=gDRIPriv
->zpp
;
194 savageScreen
->agpMode
=gDRIPriv
->agpMode
;
196 savageScreen
->bufferSize
=gDRIPriv
->bufferSize
;
198 if (gDRIPriv
->cpp
== 4)
199 savageScreen
->frontFormat
= DV_PF_8888
;
201 savageScreen
->frontFormat
= DV_PF_565
;
202 savageScreen
->frontOffset
=gDRIPriv
->frontOffset
;
203 savageScreen
->backOffset
= gDRIPriv
->backOffset
;
204 savageScreen
->depthOffset
=gDRIPriv
->depthOffset
;
206 savageScreen
->textureOffset
[SAVAGE_CARD_HEAP
] =
207 gDRIPriv
->textureOffset
;
208 savageScreen
->textureSize
[SAVAGE_CARD_HEAP
] =
209 gDRIPriv
->textureSize
;
210 savageScreen
->logTextureGranularity
[SAVAGE_CARD_HEAP
] =
211 gDRIPriv
->logTextureGranularity
;
213 savageScreen
->textureOffset
[SAVAGE_AGP_HEAP
] =
214 gDRIPriv
->agpTextureHandle
;
215 savageScreen
->textureSize
[SAVAGE_AGP_HEAP
] =
216 gDRIPriv
->agpTextureSize
;
217 savageScreen
->logTextureGranularity
[SAVAGE_AGP_HEAP
] =
218 gDRIPriv
->logAgpTextureGranularity
;
220 savageScreen
->agpTextures
.handle
= gDRIPriv
->agpTextureHandle
;
221 savageScreen
->agpTextures
.size
= gDRIPriv
->agpTextureSize
;
222 if (gDRIPriv
->agpTextureSize
) {
223 if (drmMap(sPriv
->fd
,
224 savageScreen
->agpTextures
.handle
,
225 savageScreen
->agpTextures
.size
,
226 (drmAddress
*)&(savageScreen
->agpTextures
.map
)) != 0) {
228 sPriv
->private = NULL
;
232 savageScreen
->agpTextures
.map
= NULL
;
234 savageScreen
->texVirtual
[SAVAGE_CARD_HEAP
] =
235 (drmAddress
)(((GLubyte
*)sPriv
->pFB
)+gDRIPriv
->textureOffset
);
236 savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] =
237 (drmAddress
)(savageScreen
->agpTextures
.map
);
239 savageScreen
->aperture
.handle
= gDRIPriv
->apertureHandle
;
240 savageScreen
->aperture
.size
= gDRIPriv
->apertureSize
;
241 savageScreen
->aperturePitch
= gDRIPriv
->aperturePitch
;
242 if (drmMap(sPriv
->fd
,
243 savageScreen
->aperture
.handle
,
244 savageScreen
->aperture
.size
,
245 (drmAddress
*)&savageScreen
->aperture
.map
) != 0)
248 sPriv
->private = NULL
;
252 savageScreen
->bufs
= drmMapBufs(sPriv
->fd
);
254 savageScreen
->sarea_priv_offset
= gDRIPriv
->sarea_priv_offset
;
256 /* parse information in __driConfigOptions */
257 driParseOptionInfo (&savageScreen
->optionCache
,
258 __driConfigOptions
, __driNConfigOptions
);
260 sPriv
->extensions
= savageScreenExtensions
;
263 savageDDFastPathInit();
264 savageDDTrifuncInit();
270 /* Accessed by dlsym from dri_mesa_init.c
273 savageDestroyScreen(__DRIscreen
*sPriv
)
275 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
277 if (savageScreen
->bufs
)
278 drmUnmapBufs(savageScreen
->bufs
);
280 /* free all option information */
281 driDestroyOptionInfo (&savageScreen
->optionCache
);
284 sPriv
->private = NULL
;
288 savageCreateContext( gl_api api
,
289 const struct gl_config
*mesaVis
,
290 __DRIcontext
*driContextPriv
,
291 void *sharedContextPrivate
)
293 struct gl_context
*ctx
, *shareCtx
;
294 savageContextPtr imesa
;
295 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
296 struct dd_function_table functions
;
297 savageScreenPrivate
*savageScreen
= (savageScreenPrivate
*)sPriv
->private;
298 drm_savage_sarea_t
*saPriv
=(drm_savage_sarea_t
*)(((char*)sPriv
->pSAREA
)+
299 savageScreen
->sarea_priv_offset
);
300 int textureSize
[SAVAGE_NR_TEX_HEAPS
];
302 imesa
= (savageContextPtr
)calloc(1, sizeof(savageContext
));
307 /* Init default driver functions then plug in savage-specific texture
308 * functions that are needed as early as during context creation. */
309 _mesa_init_driver_functions( &functions
);
310 savageDDInitTextureFuncs( &functions
);
312 /* Allocate the Mesa context */
313 if (sharedContextPrivate
)
314 shareCtx
= ((savageContextPtr
) sharedContextPrivate
)->glCtx
;
317 ctx
= _mesa_create_context(mesaVis
, shareCtx
, &functions
, imesa
);
322 driContextPriv
->driverPrivate
= imesa
;
324 imesa
->cmdBuf
.size
= SAVAGE_CMDBUF_SIZE
;
325 imesa
->cmdBuf
.base
= imesa
->cmdBuf
.write
=
326 malloc(SAVAGE_CMDBUF_SIZE
* sizeof(drm_savage_cmd_header_t
));
327 if (!imesa
->cmdBuf
.base
)
330 /* Parse configuration files */
331 driParseConfigFiles (&imesa
->optionCache
, &savageScreen
->optionCache
,
332 sPriv
->myNum
, "savage");
334 imesa
->float_depth
= driQueryOptionb(&imesa
->optionCache
, "float_depth") &&
335 savageScreen
->chipset
>= S3_SAVAGE4
;
336 imesa
->no_rast
= driQueryOptionb(&imesa
->optionCache
, "no_rast");
339 ctx
->Const
.MinLineWidth
= 1.0;
340 ctx
->Const
.MinLineWidthAA
= 1.0;
341 ctx
->Const
.MaxLineWidth
= 3.0;
342 ctx
->Const
.MaxLineWidthAA
= 3.0;
343 ctx
->Const
.LineWidthGranularity
= 1.0;
346 ctx
->Const
.MaxDrawBuffers
= 1;
350 imesa
->hHWContext
= driContextPriv
->hHWContext
;
351 imesa
->driFd
= sPriv
->fd
;
352 imesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
354 imesa
->savageScreen
= savageScreen
;
355 imesa
->driScreen
= sPriv
;
356 imesa
->sarea
= saPriv
;
357 imesa
->glBuffer
= NULL
;
363 imesa
->apertureBase
[i
] = (GLubyte
*)savageScreen
->aperture
.map
+
367 imesa
->aperturePitch
= savageScreen
->aperturePitch
;
369 /* change texHeap initialize to support two kind of texture heap*/
370 /* here is some parts of initialization, others in InitDriver() */
372 (void) memset( imesa
->textureHeaps
, 0, sizeof( imesa
->textureHeaps
) );
373 make_empty_list( & imesa
->swapped
);
375 textureSize
[SAVAGE_CARD_HEAP
] = savageScreen
->textureSize
[SAVAGE_CARD_HEAP
];
376 textureSize
[SAVAGE_AGP_HEAP
] = savageScreen
->textureSize
[SAVAGE_AGP_HEAP
];
377 imesa
->lastTexHeap
= savageScreen
->texVirtual
[SAVAGE_AGP_HEAP
] ? 2 : 1;
378 switch(driQueryOptioni (&imesa
->optionCache
, "texture_heaps")) {
379 case DRI_CONF_TEXTURE_HEAPS_CARD
: /* only use card memory, if available */
380 if (textureSize
[SAVAGE_CARD_HEAP
])
381 imesa
->lastTexHeap
= 1;
383 case DRI_CONF_TEXTURE_HEAPS_GART
: /* only use gart memory, if available */
384 if (imesa
->lastTexHeap
== 2 && textureSize
[SAVAGE_AGP_HEAP
])
385 textureSize
[SAVAGE_CARD_HEAP
] = 0;
387 /*default: Nothing to do, use all available memory. */
390 for (i
= 0; i
< imesa
->lastTexHeap
; i
++) {
391 imesa
->textureHeaps
[i
] = driCreateTextureHeap(
394 11, /* 2^11 = 2k alignment */
395 SAVAGE_NR_TEX_REGIONS
,
396 (drmTextureRegionPtr
)imesa
->sarea
->texList
[i
],
397 &imesa
->sarea
->texAge
[i
],
399 sizeof( savageTexObj
),
400 (destroy_texture_object_t
*) savageDestroyTexObj
);
401 /* If textureSize[i] == 0 textureHeaps[i] is NULL. This can happen
402 * if there is not enough card memory for a card texture heap. */
403 if (imesa
->textureHeaps
[i
])
404 driSetTextureSwapCounterLocation( imesa
->textureHeaps
[i
],
405 & imesa
->c_textureSwaps
);
407 imesa
->texture_depth
= driQueryOptioni (&imesa
->optionCache
,
409 if (imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
410 imesa
->texture_depth
= ( savageScreen
->cpp
== 4 ) ?
411 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
413 if (savageScreen
->chipset
>= S3_SAVAGE4
)
414 ctx
->Const
.MaxTextureUnits
= 2;
416 ctx
->Const
.MaxTextureUnits
= 1;
417 if (driQueryOptioni(&imesa
->optionCache
, "texture_units") <
418 ctx
->Const
.MaxTextureUnits
)
419 ctx
->Const
.MaxTextureUnits
=
420 driQueryOptioni(&imesa
->optionCache
, "texture_units");
421 ctx
->Const
.MaxTextureImageUnits
= ctx
->Const
.MaxTextureUnits
;
422 ctx
->Const
.MaxTextureCoordUnits
= ctx
->Const
.MaxTextureUnits
;
424 driCalculateMaxTextureLevels( imesa
->textureHeaps
,
428 11, /* max 2D texture size is 2048x2048 */
429 0, /* 3D textures unsupported. */
430 0, /* cube textures unsupported. */
431 0, /* texture rectangles unsupported. */
435 if (ctx
->Const
.MaxTextureLevels
<= 6) { /*spec requires at least 64x64*/
436 __driUtilMessage("Not enough texture memory. "
437 "Falling back to indirect rendering.");
442 imesa
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
443 imesa
->depth_scale
= (imesa
->savageScreen
->zpp
== 2) ?
444 (1.0F
/0xffff):(1.0F
/0xffffff);
446 imesa
->bufferSize
= savageScreen
->bufferSize
;
447 imesa
->dmaVtxBuf
.total
= 0;
448 imesa
->dmaVtxBuf
.used
= 0;
449 imesa
->dmaVtxBuf
.flushed
= 0;
451 imesa
->clientVtxBuf
.total
= imesa
->bufferSize
/ 4;
452 imesa
->clientVtxBuf
.used
= 0;
453 imesa
->clientVtxBuf
.flushed
= 0;
454 imesa
->clientVtxBuf
.buf
= (uint32_t *)malloc(imesa
->bufferSize
);
456 imesa
->vtxBuf
= &imesa
->clientVtxBuf
;
458 imesa
->firstElt
= -1;
460 /* Uninitialized vertex format. Force setting the vertex state in
463 imesa
->vertex_size
= 0;
467 imesa
->new_state
= ~0;
468 imesa
->new_gl_state
= ~0;
469 imesa
->RenderIndex
= ~0;
471 imesa
->lostContext
= GL_TRUE
;
472 imesa
->CurrentTexObj
[0] = 0;
473 imesa
->CurrentTexObj
[1] = 0;
475 _mesa_meta_init( ctx
);
477 /* Initialize the software rasterizer and helper modules.
479 _swrast_CreateContext( ctx
);
480 _vbo_CreateContext( ctx
);
481 _tnl_CreateContext( ctx
);
483 _swsetup_CreateContext( ctx
);
485 /* Install the customized pipeline:
487 _tnl_destroy_pipeline( ctx
);
488 _tnl_install_pipeline( ctx
, savage_pipeline
);
490 imesa
->enable_fastpath
= driQueryOptionb(&imesa
->optionCache
,
492 /* DRM versions before 2.1.3 would only render triangle lists. ELTS
493 * support was added in 2.2.0. */
494 if (imesa
->enable_fastpath
&& sPriv
->drm_version
.minor
< 2) {
496 "*** Disabling fast path because your DRM version is buggy "
497 "or doesn't\n*** support ELTS. You need at least Savage DRM "
499 imesa
->enable_fastpath
= GL_FALSE
;
502 if (!savageScreen
->bufs
|| savageScreen
->chipset
== S3_SUPERSAVAGE
)
503 imesa
->enable_vdma
= GL_FALSE
;
505 imesa
->enable_vdma
= driQueryOptionb(&imesa
->optionCache
, "enable_vdma");
507 imesa
->sync_frames
= driQueryOptionb(&imesa
->optionCache
, "sync_frames");
509 /* Configure swrast to match hardware characteristics:
511 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
512 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
513 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
514 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
516 ctx
->DriverCtx
= (void *) imesa
;
520 SAVAGE_DEBUG
= driParseDebugString( getenv( "SAVAGE_DEBUG" ),
524 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
525 if (savageScreen
->chipset
>= S3_SAVAGE4
)
526 driInitExtensions( ctx
, s4_extensions
, GL_FALSE
);
527 if (ctx
->Mesa_DXTn
||
528 driQueryOptionb (&imesa
->optionCache
, "force_s3tc_enable")) {
529 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
530 if (savageScreen
->chipset
>= S3_SAVAGE4
)
531 /* This extension needs DXT3 and DTX5 support in hardware.
532 * Not available on Savage3D/MX/IX. */
533 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
536 savageDDInitStateFuncs( ctx
);
537 savageDDInitSpanFuncs( ctx
);
538 savageDDInitDriverFuncs( ctx
);
539 savageDDInitIoctlFuncs( ctx
);
540 savageInitTriFuncs( ctx
);
542 savageDDInitState( imesa
);
544 driContextPriv
->driverPrivate
= (void *) imesa
;
550 savageDestroyContext(__DRIcontext
*driContextPriv
)
552 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
555 assert (imesa
); /* should never be NULL */
557 savageFlushVertices(imesa
);
558 savageReleaseIndexedVerts(imesa
);
559 savageFlushCmdBuf(imesa
, GL_TRUE
); /* release DMA buffer */
560 WAIT_IDLE_EMPTY(imesa
);
562 for (i
= 0; i
< imesa
->lastTexHeap
; i
++)
563 driDestroyTextureHeap(imesa
->textureHeaps
[i
]);
565 free(imesa
->cmdBuf
.base
);
566 free(imesa
->clientVtxBuf
.buf
);
568 _mesa_meta_free( imesa
->glCtx
);
570 _swsetup_DestroyContext(imesa
->glCtx
);
571 _tnl_DestroyContext( imesa
->glCtx
);
572 _vbo_DestroyContext( imesa
->glCtx
);
573 _swrast_DestroyContext( imesa
->glCtx
);
575 /* free the Mesa context */
576 imesa
->glCtx
->DriverCtx
= NULL
;
577 _mesa_destroy_context(imesa
->glCtx
);
579 /* no longer use vertex_dma_buf*/
586 savageCreateBuffer( __DRIscreen
*driScrnPriv
,
587 __DRIdrawable
*driDrawPriv
,
588 const struct gl_config
*mesaVis
,
591 savageScreenPrivate
*screen
= (savageScreenPrivate
*) driScrnPriv
->private;
594 return GL_FALSE
; /* not implemented */
597 GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
598 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
600 * XXX: this value needs to be set according to the config file
601 * setting. But we don't get that until we create a rendering
604 GLboolean float_depth
= GL_FALSE
;
607 driRenderbuffer
*frontRb
608 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
609 (GLubyte
*) screen
->aperture
.map
610 + 0x01000000 * TARGET_FRONT
,
612 screen
->frontOffset
, screen
->aperturePitch
,
614 savageSetSpanFunctions(frontRb
, mesaVis
, float_depth
);
615 assert(frontRb
->Base
.Data
);
616 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
619 if (mesaVis
->doubleBufferMode
) {
620 driRenderbuffer
*backRb
621 = driNewRenderbuffer(MESA_FORMAT_ARGB8888
,
622 (GLubyte
*) screen
->aperture
.map
623 + 0x01000000 * TARGET_BACK
,
625 screen
->backOffset
, screen
->aperturePitch
,
627 savageSetSpanFunctions(backRb
, mesaVis
, float_depth
);
628 assert(backRb
->Base
.Data
);
629 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
632 if (mesaVis
->depthBits
== 16) {
633 driRenderbuffer
*depthRb
634 = driNewRenderbuffer(MESA_FORMAT_Z16
,
635 (GLubyte
*) screen
->aperture
.map
636 + 0x01000000 * TARGET_DEPTH
,
638 screen
->depthOffset
, screen
->aperturePitch
,
640 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
641 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
643 else if (mesaVis
->depthBits
== 24) {
644 driRenderbuffer
*depthRb
645 = driNewRenderbuffer(MESA_FORMAT_S8_Z24
,
646 (GLubyte
*) screen
->aperture
.map
647 + 0x01000000 * TARGET_DEPTH
,
649 screen
->depthOffset
, screen
->aperturePitch
,
651 savageSetSpanFunctions(depthRb
, mesaVis
, float_depth
);
652 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
655 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
656 driRenderbuffer
*stencilRb
657 = driNewRenderbuffer(MESA_FORMAT_S8
,
658 (GLubyte
*) screen
->aperture
.map
659 + 0x01000000 * TARGET_DEPTH
,
661 screen
->depthOffset
, screen
->aperturePitch
,
663 savageSetSpanFunctions(stencilRb
, mesaVis
, float_depth
);
664 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
667 _mesa_add_soft_renderbuffers(fb
,
668 GL_FALSE
, /* color */
669 GL_FALSE
, /* depth */
671 mesaVis
->accumRedBits
> 0,
672 GL_FALSE
, /* alpha */
674 driDrawPriv
->driverPrivate
= (void *) fb
;
676 return (driDrawPriv
->driverPrivate
!= NULL
);
681 savageDestroyBuffer(__DRIdrawable
*driDrawPriv
)
683 _mesa_reference_framebuffer((struct gl_framebuffer
**)(&(driDrawPriv
->driverPrivate
)), NULL
);
687 void XMesaSwapBuffers(__DRIdrawable
*driDrawPriv
)
689 /* XXX should do swap according to the buffer, not the context! */
690 savageContextPtr imesa
= savageCtx
;
692 FLUSH_VB( imesa
->glCtx
, "swap buffers" );
693 savageSwapBuffers(imesa
);
698 void savageXMesaSetClipRects(savageContextPtr imesa
)
700 __DRIdrawable
*dPriv
= imesa
->driDrawable
;
702 if ((dPriv
->numBackClipRects
== 0)
703 || (imesa
->glCtx
->DrawBuffer
->_ColorDrawBufferIndexes
[0] == BUFFER_FRONT_LEFT
)) {
704 imesa
->numClipRects
= dPriv
->numClipRects
;
705 imesa
->pClipRects
= dPriv
->pClipRects
;
706 imesa
->drawX
= dPriv
->x
;
707 imesa
->drawY
= dPriv
->y
;
709 imesa
->numClipRects
= dPriv
->numBackClipRects
;
710 imesa
->pClipRects
= dPriv
->pBackClipRects
;
711 imesa
->drawX
= dPriv
->backX
;
712 imesa
->drawY
= dPriv
->backY
;
715 savageCalcViewport( imesa
->glCtx
);
719 static void savageXMesaWindowMoved( savageContextPtr imesa
)
721 __DRIdrawable
*const drawable
= imesa
->driDrawable
;
722 __DRIdrawable
*const readable
= imesa
->driReadable
;
725 fprintf(stderr
, "savageXMesaWindowMoved\n\n");
727 savageXMesaSetClipRects(imesa
);
729 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
730 if (drawable
!= readable
) {
731 driUpdateFramebufferSize(imesa
->glCtx
, readable
);
737 savageUnbindContext(__DRIcontext
*driContextPriv
)
739 savageContextPtr savage
= (savageContextPtr
) driContextPriv
->driverPrivate
;
748 savageOpenFullScreen(__DRIcontext
*driContextPriv
)
753 if (driContextPriv
) {
754 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
755 imesa
->IsFullScreen
= GL_TRUE
;
756 imesa
->backup_frontOffset
= imesa
->savageScreen
->frontOffset
;
757 imesa
->backup_backOffset
= imesa
->savageScreen
->backOffset
;
758 imesa
->backup_frontBitmapDesc
= imesa
->savageScreen
->frontBitmapDesc
;
759 imesa
->savageScreen
->frontBitmapDesc
= imesa
->savageScreen
->backBitmapDesc
;
760 imesa
->toggle
= TARGET_BACK
;
767 savageCloseFullScreen(__DRIcontext
*driContextPriv
)
770 if (driContextPriv
) {
771 savageContextPtr imesa
= (savageContextPtr
) driContextPriv
->driverPrivate
;
772 WAIT_IDLE_EMPTY(imesa
);
773 imesa
->IsFullScreen
= GL_FALSE
;
774 imesa
->savageScreen
->frontOffset
= imesa
->backup_frontOffset
;
775 imesa
->savageScreen
->backOffset
= imesa
->backup_backOffset
;
776 imesa
->savageScreen
->frontBitmapDesc
= imesa
->backup_frontBitmapDesc
;
783 savageMakeCurrent(__DRIcontext
*driContextPriv
,
784 __DRIdrawable
*driDrawPriv
,
785 __DRIdrawable
*driReadPriv
)
787 if (driContextPriv
) {
788 savageContextPtr imesa
789 = (savageContextPtr
) driContextPriv
->driverPrivate
;
790 struct gl_framebuffer
*drawBuffer
791 = (struct gl_framebuffer
*) driDrawPriv
->driverPrivate
;
792 struct gl_framebuffer
*readBuffer
793 = (struct gl_framebuffer
*) driReadPriv
->driverPrivate
;
794 driRenderbuffer
*frontRb
= (driRenderbuffer
*)
795 drawBuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
796 driRenderbuffer
*backRb
= (driRenderbuffer
*)
797 drawBuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
;
799 assert(frontRb
->Base
.Data
);
800 if (imesa
->glCtx
->Visual
.doubleBufferMode
) {
801 assert(backRb
->Base
.Data
);
804 imesa
->driReadable
= driReadPriv
;
805 imesa
->driDrawable
= driDrawPriv
;
808 _mesa_make_current(imesa
->glCtx
, drawBuffer
, readBuffer
);
810 savageXMesaWindowMoved( imesa
);
814 _mesa_make_current(NULL
, NULL
, NULL
);
820 void savageGetLock( savageContextPtr imesa
, GLuint flags
)
822 __DRIdrawable
*const drawable
= imesa
->driDrawable
;
823 __DRIdrawable
*const readable
= imesa
->driReadable
;
824 __DRIscreen
*sPriv
= imesa
->driScreen
;
825 drm_savage_sarea_t
*sarea
= imesa
->sarea
;
826 int me
= imesa
->hHWContext
;
827 int stamp
= drawable
->lastStamp
;
829 unsigned int timestamp
= 0;
833 /* We know there has been contention.
835 drmGetLock(imesa
->driFd
, imesa
->hHWContext
, flags
);
838 /* Note contention for throttling hint
840 imesa
->any_contend
= 1;
842 /* If the window moved, may need to set a new cliprect now.
844 * NOTE: This releases and regains the hw lock, so all state
845 * checking must be done *after* this call:
847 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, drawable
);
848 if (drawable
!= readable
) {
849 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, readable
);
853 /* If we lost context, need to dump all registers to hardware.
854 * Note that we don't care about 2d contexts, even if they perform
855 * accelerated commands, so the DRI locking in the X server is even
856 * more broken than usual.
858 if (sarea
->ctxOwner
!= me
) {
859 imesa
->dirty
|= (SAVAGE_UPLOAD_LOCAL
|
860 SAVAGE_UPLOAD_GLOBAL
|
861 SAVAGE_UPLOAD_FOGTBL
|
864 SAVAGE_UPLOAD_TEXGLOBAL
);
865 imesa
->lostContext
= GL_TRUE
;
866 sarea
->ctxOwner
= me
;
869 for (heap
= 0; heap
< imesa
->lastTexHeap
; ++heap
) {
870 /* If a heap was changed, update its timestamp. Do this before
871 * DRI_AGE_TEXTURES updates the local_age. */
872 if (imesa
->textureHeaps
[heap
] &&
873 imesa
->textureHeaps
[heap
]->global_age
[0] >
874 imesa
->textureHeaps
[heap
]->local_age
) {
876 timestamp
= savageEmitEventLocked(imesa
, 0);
877 imesa
->textureHeaps
[heap
]->timestamp
= timestamp
;
879 DRI_AGE_TEXTURES( imesa
->textureHeaps
[heap
] );
882 if (drawable
->lastStamp
!= stamp
) {
883 driUpdateFramebufferSize(imesa
->glCtx
, drawable
);
884 savageXMesaWindowMoved( imesa
);
888 static const __DRIconfig
**
889 savageFillInModes( __DRIscreen
*psp
,
890 unsigned pixel_bits
, unsigned depth_bits
,
891 unsigned stencil_bits
, GLboolean have_back_buffer
)
893 __DRIconfig
**configs
;
894 struct gl_config
* m
;
895 unsigned depth_buffer_factor
;
896 unsigned back_buffer_factor
;
901 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
902 * enough to add support. Basically, if a context is created with an
903 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
904 * will never be used.
906 * FK: What about drivers that don't use page flipping? Could they
907 * just expose GLX_SWAP_COPY_OML?
909 static const GLenum back_buffer_modes
[] = {
910 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
913 uint8_t depth_bits_array
[2];
914 uint8_t stencil_bits_array
[2];
915 uint8_t msaa_samples_array
[1];
917 depth_bits_array
[0] = depth_bits
;
918 depth_bits_array
[1] = depth_bits
;
920 /* Just like with the accumulation buffer, always provide some modes
921 * with a stencil buffer. It will be a sw fallback, but some apps won't
924 stencil_bits_array
[0] = 0;
925 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
927 msaa_samples_array
[0] = 0;
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 msaa_samples_array
, 1, GL_TRUE
);
946 if (configs
== NULL
) {
947 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
948 __func__
, __LINE__
);
952 /* Mark the visual as slow if there are "fake" stencil bits.
954 for (i
= 0; configs
[i
]; i
++) {
955 m
= &configs
[i
]->modes
;
956 if ((m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
)) {
957 m
->visualRating
= GLX_SLOW_CONFIG
;
961 return (const __DRIconfig
**) configs
;
966 * This is the driver specific part of the createNewScreen entry point.
968 * \todo maybe fold this into intelInitDriver
970 * \return the struct gl_config supported by this driver
972 static const __DRIconfig
**
973 savageInitScreen(__DRIscreen
*psp
)
975 static const __DRIversion ddx_expected
= { 2, 0, 0 };
976 static const __DRIversion dri_expected
= { 4, 0, 0 };
977 static const __DRIversion drm_expected
= { 2, 1, 0 };
978 SAVAGEDRIPtr dri_priv
= (SAVAGEDRIPtr
)psp
->pDevPriv
;
980 if ( ! driCheckDriDdxDrmVersions2( "Savage",
981 &psp
->dri_version
, & dri_expected
,
982 &psp
->ddx_version
, & ddx_expected
,
983 &psp
->drm_version
, & drm_expected
) )
986 if (!savageInitDriver(psp
))
989 return savageFillInModes( psp
,
991 (dri_priv
->cpp
== 2) ? 16 : 24,
992 (dri_priv
->cpp
== 2) ? 0 : 8,
993 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
996 const struct __DriverAPIRec driDriverAPI
= {
1000 savageDestroyContext
,
1002 savageDestroyBuffer
,
1008 /* This is the table of extensions that the loader will dlsym() for. */
1009 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
1010 &driCoreExtension
.base
,
1011 &driLegacyExtension
.base
,