1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_screen.c,v 1.9 2003/03/26 20:43:49 tsi Exp $ */
2 /**************************************************************************
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Gareth Hughes <gareth@valinux.com>
32 * Kevin E. Martin <martin@valinux.com>
38 #include "r128_context.h"
39 #include "r128_ioctl.h"
40 #include "r128_tris.h"
50 #include "GL/internal/dri_interface.h"
57 const char __driConfigOptions
[] =
59 DRI_CONF_SECTION_PERFORMANCE
60 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0
)
62 DRI_CONF_SECTION_QUALITY
63 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB
)
66 DRI_CONF_SECTION_DEBUG
67 DRI_CONF_PERFORMANCE_BOXES(false)
72 static const GLuint __driNConfigOptions
= 3;
74 static const GLuint __driNConfigOptions
= 2;
78 /* Including xf86PciInfo.h introduces a bunch of errors...
80 #define PCI_CHIP_RAGE128LE 0x4C45
81 #define PCI_CHIP_RAGE128LF 0x4C46
82 #define PCI_CHIP_RAGE128PF 0x5046
83 #define PCI_CHIP_RAGE128PR 0x5052
84 #define PCI_CHIP_RAGE128RE 0x5245
85 #define PCI_CHIP_RAGE128RF 0x5246
86 #define PCI_CHIP_RAGE128RK 0x524B
87 #define PCI_CHIP_RAGE128RL 0x524C
90 #ifdef USE_NEW_INTERFACE
91 static PFNGLXCREATECONTEXTMODES create_context_modes
= NULL
;
92 #endif /* USE_NEW_INTERFACE */
94 /* Create the device specific screen private data struct.
97 r128CreateScreen( __DRIscreenPrivate
*sPriv
)
99 r128ScreenPtr r128Screen
;
100 R128DRIPtr r128DRIPriv
= (R128DRIPtr
)sPriv
->pDevPriv
;
103 /* Allocate the private area */
104 r128Screen
= (r128ScreenPtr
) CALLOC( sizeof(*r128Screen
) );
105 if ( !r128Screen
) return NULL
;
107 /* parse information in __driConfigOptions */
108 driParseOptionInfo (&r128Screen
->optionCache
,
109 __driConfigOptions
, __driNConfigOptions
);
111 /* This is first since which regions we map depends on whether or
112 * not we are using a PCI card.
114 r128Screen
->IsPCI
= r128DRIPriv
->IsPCI
;
115 r128Screen
->sarea_priv_offset
= r128DRIPriv
->sarea_priv_offset
;
117 if (sPriv
->drmMinor
>= 3) {
118 drm_r128_getparam_t gp
;
121 gp
.param
= R128_PARAM_IRQ_NR
;
122 gp
.value
= &r128Screen
->irq
;
124 ret
= drmCommandWriteRead( sPriv
->fd
, DRM_R128_GETPARAM
,
127 fprintf(stderr
, "drmR128GetParam (R128_PARAM_IRQ_NR): %d\n", ret
);
133 r128Screen
->mmio
.handle
= r128DRIPriv
->registerHandle
;
134 r128Screen
->mmio
.size
= r128DRIPriv
->registerSize
;
135 if ( drmMap( sPriv
->fd
,
136 r128Screen
->mmio
.handle
,
137 r128Screen
->mmio
.size
,
138 (drmAddressPtr
)&r128Screen
->mmio
.map
) ) {
143 r128Screen
->buffers
= drmMapBufs( sPriv
->fd
);
144 if ( !r128Screen
->buffers
) {
145 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
150 if ( !r128Screen
->IsPCI
) {
151 r128Screen
->agpTextures
.handle
= r128DRIPriv
->agpTexHandle
;
152 r128Screen
->agpTextures
.size
= r128DRIPriv
->agpTexMapSize
;
153 if ( drmMap( sPriv
->fd
,
154 r128Screen
->agpTextures
.handle
,
155 r128Screen
->agpTextures
.size
,
156 (drmAddressPtr
)&r128Screen
->agpTextures
.map
) ) {
157 drmUnmapBufs( r128Screen
->buffers
);
158 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
164 switch ( r128DRIPriv
->deviceID
) {
165 case PCI_CHIP_RAGE128RE
:
166 case PCI_CHIP_RAGE128RF
:
167 case PCI_CHIP_RAGE128RK
:
168 case PCI_CHIP_RAGE128RL
:
169 r128Screen
->chipset
= R128_CARD_TYPE_R128
;
171 case PCI_CHIP_RAGE128PF
:
172 r128Screen
->chipset
= R128_CARD_TYPE_R128_PRO
;
174 case PCI_CHIP_RAGE128LE
:
175 case PCI_CHIP_RAGE128LF
:
176 r128Screen
->chipset
= R128_CARD_TYPE_R128_MOBILITY
;
179 r128Screen
->chipset
= R128_CARD_TYPE_R128
;
183 r128Screen
->cpp
= r128DRIPriv
->bpp
/ 8;
184 r128Screen
->AGPMode
= r128DRIPriv
->AGPMode
;
186 r128Screen
->frontOffset
= r128DRIPriv
->frontOffset
;
187 r128Screen
->frontPitch
= r128DRIPriv
->frontPitch
;
188 r128Screen
->backOffset
= r128DRIPriv
->backOffset
;
189 r128Screen
->backPitch
= r128DRIPriv
->backPitch
;
190 r128Screen
->depthOffset
= r128DRIPriv
->depthOffset
;
191 r128Screen
->depthPitch
= r128DRIPriv
->depthPitch
;
192 r128Screen
->spanOffset
= r128DRIPriv
->spanOffset
;
194 r128Screen
->texOffset
[R128_LOCAL_TEX_HEAP
] = r128DRIPriv
->textureOffset
;
195 r128Screen
->texSize
[R128_LOCAL_TEX_HEAP
] = r128DRIPriv
->textureSize
;
196 r128Screen
->logTexGranularity
[R128_LOCAL_TEX_HEAP
] = r128DRIPriv
->log2TexGran
;
198 if ( r128Screen
->IsPCI
) {
199 r128Screen
->numTexHeaps
= R128_NR_TEX_HEAPS
- 1;
200 r128Screen
->texOffset
[R128_AGP_TEX_HEAP
] = 0;
201 r128Screen
->texSize
[R128_AGP_TEX_HEAP
] = 0;
202 r128Screen
->logTexGranularity
[R128_AGP_TEX_HEAP
] = 0;
204 r128Screen
->numTexHeaps
= R128_NR_TEX_HEAPS
;
205 r128Screen
->texOffset
[R128_AGP_TEX_HEAP
] =
206 r128DRIPriv
->agpTexOffset
+ R128_AGP_TEX_OFFSET
;
207 r128Screen
->texSize
[R128_AGP_TEX_HEAP
] = r128DRIPriv
->agpTexMapSize
;
208 r128Screen
->logTexGranularity
[R128_AGP_TEX_HEAP
] =
209 r128DRIPriv
->log2AGPTexGran
;
212 r128Screen
->driScreen
= sPriv
;
214 if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
215 PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension
=
216 (PFNGLXSCRENABLEEXTENSIONPROC
) glXGetProcAddress( (const GLubyte
*) "__glXScrEnableExtension" );
217 void * const psc
= sPriv
->psc
->screenConfigs
;
219 if ( glx_enable_extension
!= NULL
) {
220 if ( r128Screen
->irq
!= 0 ) {
221 (*glx_enable_extension
)( psc
, "GLX_SGI_swap_control" );
222 (*glx_enable_extension
)( psc
, "GLX_SGI_video_sync" );
223 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_control" );
226 (*glx_enable_extension
)( psc
, "GLX_MESA_swap_frame_usage" );
233 /* Destroy the device specific screen private data struct.
236 r128DestroyScreen( __DRIscreenPrivate
*sPriv
)
238 r128ScreenPtr r128Screen
= (r128ScreenPtr
)sPriv
->private;
243 if ( !r128Screen
->IsPCI
) {
244 drmUnmap( (drmAddress
)r128Screen
->agpTextures
.map
,
245 r128Screen
->agpTextures
.size
);
247 drmUnmapBufs( r128Screen
->buffers
);
248 drmUnmap( (drmAddress
)r128Screen
->mmio
.map
, r128Screen
->mmio
.size
);
250 /* free all option information */
251 driDestroyOptionInfo (&r128Screen
->optionCache
);
254 sPriv
->private = NULL
;
258 /* Create and initialize the Mesa and driver specific pixmap buffer
262 r128CreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
263 __DRIdrawablePrivate
*driDrawPriv
,
264 const __GLcontextModes
*mesaVis
,
268 return GL_FALSE
; /* not implemented */
271 driDrawPriv
->driverPrivate
= (void *)
272 _mesa_create_framebuffer( mesaVis
,
273 GL_FALSE
, /* software depth buffer? */
274 mesaVis
->stencilBits
> 0,
275 mesaVis
->accumRedBits
> 0,
276 mesaVis
->alphaBits
> 0 );
277 return (driDrawPriv
->driverPrivate
!= NULL
);
283 r128DestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
285 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
289 /* Copy the back color buffer to the front color buffer */
291 r128SwapBuffers(__DRIdrawablePrivate
*dPriv
)
293 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
294 r128ContextPtr rmesa
;
296 rmesa
= (r128ContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
298 if (ctx
->Visual
.doubleBufferMode
) {
299 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
300 if ( rmesa
->doPageFlip
) {
301 r128PageFlip( dPriv
);
304 r128CopyBuffer( dPriv
);
309 /* XXX this shouldn't be an error but we can't handle it for now */
310 _mesa_problem(NULL
, "%s: drawable has no context!", __FUNCTION__
);
315 /* Initialize the driver specific screen private data.
318 r128InitDriver( __DRIscreenPrivate
*sPriv
)
320 sPriv
->private = (void *) r128CreateScreen( sPriv
);
322 if ( !sPriv
->private ) {
323 r128DestroyScreen( sPriv
);
331 static struct __DriverAPIRec r128API
= {
332 .InitDriver
= r128InitDriver
,
333 .DestroyScreen
= r128DestroyScreen
,
334 .CreateContext
= r128CreateContext
,
335 .DestroyContext
= r128DestroyContext
,
336 .CreateBuffer
= r128CreateBuffer
,
337 .DestroyBuffer
= r128DestroyBuffer
,
338 .SwapBuffers
= r128SwapBuffers
,
339 .MakeCurrent
= r128MakeCurrent
,
340 .UnbindContext
= r128UnbindContext
,
342 .GetMSC
= driGetMSC32
,
343 .WaitForMSC
= driWaitForMSC32
,
345 .SwapBuffersMSC
= NULL
350 #ifndef DRI_NEW_INTERFACE_ONLY
352 * This is the bootstrap function for the driver.
353 * The __driCreateScreen name is the symbol that libGL.so fetches.
354 * Return: pointer to a __DRIscreenPrivate.
357 void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
358 int numConfigs
, __GLXvisualConfig
*config
)
360 __DRIscreenPrivate
*psp
;
361 psp
= __driUtilCreateScreen(dpy
, scrn
, psc
, numConfigs
, config
, &r128API
);
365 void *__driCreateScreen(struct DRIDriverRec
*driver
,
366 struct DRIDriverContextRec
*driverContext
)
368 __DRIscreenPrivate
*psp
;
369 psp
= __driUtilCreateScreen(driver
, driverContext
, &r128API
);
373 #endif /* DRI_NEW_INTERFACE_ONLY */
376 #ifdef USE_NEW_INTERFACE
377 static __GLcontextModes
*
378 r128FillInModes( unsigned pixel_bits
, unsigned depth_bits
,
379 unsigned stencil_bits
, GLboolean have_back_buffer
)
381 __GLcontextModes
* modes
;
382 __GLcontextModes
* m
;
384 unsigned depth_buffer_factor
;
385 unsigned back_buffer_factor
;
389 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
390 * enough to add support. Basically, if a context is created with an
391 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
392 * will never be used.
394 static const GLenum back_buffer_modes
[] = {
395 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
398 uint8_t depth_bits_array
[2];
399 uint8_t stencil_bits_array
[2];
402 depth_bits_array
[0] = depth_bits
;
403 depth_bits_array
[1] = depth_bits
;
405 /* Just like with the accumulation buffer, always provide some modes
406 * with a stencil buffer. It will be a sw fallback, but some apps won't
409 stencil_bits_array
[0] = 0;
410 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
412 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
413 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
415 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
417 if ( pixel_bits
== 16 ) {
419 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
423 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
426 modes
= (*create_context_modes
)( num_modes
, sizeof( __GLcontextModes
) );
428 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
429 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
430 back_buffer_modes
, back_buffer_factor
,
432 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
433 __func__
, __LINE__
);
437 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
438 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
439 back_buffer_modes
, back_buffer_factor
,
440 GLX_DIRECT_COLOR
) ) {
441 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
442 __func__
, __LINE__
);
446 /* Mark the visual as slow if there are "fake" stencil bits.
448 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
449 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
450 m
->visualRating
= GLX_SLOW_CONFIG
;
459 * This is the bootstrap function for the driver. libGL supplies all of the
460 * requisite information about the system, and the driver initializes itself.
461 * This routine also fills in the linked list pointed to by \c driver_modes
462 * with the \c __GLcontextModes that the driver can support for windows or
465 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
468 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
469 const __GLcontextModes
* modes
,
470 const __DRIversion
* ddx_version
,
471 const __DRIversion
* dri_version
,
472 const __DRIversion
* drm_version
,
473 const __DRIframebuffer
* frame_buffer
,
474 drmAddress pSAREA
, int fd
,
475 int internal_api_version
,
476 __GLcontextModes
** driver_modes
)
479 __DRIscreenPrivate
*psp
;
480 static const __DRIversion ddx_expected
= { 4, 0, 0 };
481 static const __DRIversion dri_expected
= { 4, 0, 0 };
482 static const __DRIversion drm_expected
= { 2, 2, 0 };
485 if ( ! driCheckDriDdxDrmVersions2( "Rage128",
486 dri_version
, & dri_expected
,
487 ddx_version
, & ddx_expected
,
488 drm_version
, & drm_expected
) ) {
492 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
493 ddx_version
, dri_version
, drm_version
,
494 frame_buffer
, pSAREA
, fd
,
495 internal_api_version
, &r128API
);
497 create_context_modes
= (PFNGLXCREATECONTEXTMODES
)
498 glXGetProcAddress( (const GLubyte
*) "__glXCreateContextModes" );
499 if ( create_context_modes
!= NULL
) {
500 R128DRIPtr dri_priv
= (R128DRIPtr
) psp
->pDevPriv
;
501 *driver_modes
= r128FillInModes( dri_priv
->bpp
,
502 (dri_priv
->bpp
== 16) ? 16 : 24,
503 (dri_priv
->bpp
== 16) ? 0 : 8,
504 (dri_priv
->backOffset
!= dri_priv
->depthOffset
) );
510 #endif /* USE_NEW_INTERFACE */