1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_context.c,v 1.8 2002/10/30 12:51:38 alanh 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 * Kevin E. Martin <martin@valinux.com>
32 * Gareth Hughes <gareth@valinux.com>
38 #include "simple_list.h"
41 #include "extensions.h"
43 #include "swrast/swrast.h"
44 #include "swrast_setup/swrast_setup.h"
45 #include "array_cache/acache.h"
48 #include "tnl/t_pipeline.h"
50 #include "drivers/common/driverfuncs.h"
52 #include "r128_context.h"
53 #include "r128_ioctl.h"
55 #include "r128_state.h"
56 #include "r128_span.h"
58 #include "r128_tris.h"
63 #include "xmlpool.h" /* for symbolic values of enum-type options */
69 #define need_GL_ARB_multisample
70 #define need_GL_ARB_texture_compression
71 #define need_GL_EXT_blend_minmax
72 #define need_GL_EXT_fog_coord
73 #define need_GL_EXT_secondary_color
74 #include "extension_helper.h"
76 const struct dri_extension card_extensions
[] =
78 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
79 { "GL_ARB_multitexture", NULL
},
80 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
81 { "GL_ARB_texture_env_add", NULL
},
82 { "GL_ARB_texture_mirrored_repeat", NULL
},
83 { "GL_EXT_blend_subtract", GL_EXT_blend_minmax_functions
},
84 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
85 { "GL_EXT_texture_edge_clamp", NULL
},
86 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
87 { "GL_EXT_stencil_wrap", NULL
},
88 { "GL_MESA_ycbcr_texture", NULL
},
89 { "GL_NV_blend_square", NULL
},
90 { "GL_SGIS_generate_mipmap", NULL
},
94 static const struct dri_debug_control debug_control
[] =
96 { "ioctl", DEBUG_VERBOSE_IOCTL
},
97 { "verb", DEBUG_VERBOSE_MSG
},
98 { "dri", DEBUG_VERBOSE_DRI
},
99 { "2d", DEBUG_VERBOSE_2D
},
100 { "sync", DEBUG_ALWAYS_SYNC
},
101 { "api", DEBUG_VERBOSE_API
},
102 { "fall", DEBUG_VERBOSE_FALL
},
106 /* Create the device specific context.
108 GLboolean
r128CreateContext( const __GLcontextModes
*glVisual
,
109 __DRIcontextPrivate
*driContextPriv
,
110 void *sharedContextPrivate
)
112 GLcontext
*ctx
, *shareCtx
;
113 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
114 struct dd_function_table functions
;
115 r128ContextPtr rmesa
;
116 r128ScreenPtr r128scrn
;
119 /* Allocate the r128 context */
120 rmesa
= (r128ContextPtr
) CALLOC( sizeof(*rmesa
) );
124 /* Init default driver functions then plug in our Radeon-specific functions
125 * (the texture functions are especially important)
127 _mesa_init_driver_functions( &functions
);
128 r128InitDriverFuncs( &functions
);
129 r128InitIoctlFuncs( &functions
);
130 r128InitTextureFuncs( &functions
);
132 /* Allocate the Mesa context */
133 if (sharedContextPrivate
)
134 shareCtx
= ((r128ContextPtr
) sharedContextPrivate
)->glCtx
;
137 rmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
138 &functions
, (void *) rmesa
);
143 driContextPriv
->driverPrivate
= rmesa
;
146 rmesa
->driContext
= driContextPriv
;
147 rmesa
->driScreen
= sPriv
;
148 rmesa
->driDrawable
= NULL
;
149 rmesa
->hHWContext
= driContextPriv
->hHWContext
;
150 rmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
151 rmesa
->driFd
= sPriv
->fd
;
153 r128scrn
= rmesa
->r128Screen
= (r128ScreenPtr
)(sPriv
->private);
155 /* Parse configuration files */
156 driParseConfigFiles (&rmesa
->optionCache
, &r128scrn
->optionCache
,
157 r128scrn
->driScreen
->myNum
, "r128");
159 rmesa
->sarea
= (drm_r128_sarea_t
*)((char *)sPriv
->pSAREA
+
160 r128scrn
->sarea_priv_offset
);
162 rmesa
->CurrentTexObj
[0] = NULL
;
163 rmesa
->CurrentTexObj
[1] = NULL
;
165 (void) memset( rmesa
->texture_heaps
, 0, sizeof( rmesa
->texture_heaps
) );
166 make_empty_list( & rmesa
->swapped
);
168 rmesa
->nr_heaps
= r128scrn
->numTexHeaps
;
169 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
170 rmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, rmesa
,
171 r128scrn
->texSize
[i
],
174 (drmTextureRegionPtr
)rmesa
->sarea
->tex_list
[i
],
175 &rmesa
->sarea
->tex_age
[i
],
177 sizeof( r128TexObj
),
178 (destroy_texture_object_t
*) r128DestroyTexObj
);
180 driSetTextureSwapCounterLocation( rmesa
->texture_heaps
[i
],
181 & rmesa
->c_textureSwaps
);
183 rmesa
->texture_depth
= driQueryOptioni (&rmesa
->optionCache
,
185 if (rmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
186 rmesa
->texture_depth
= ( r128scrn
->cpp
== 4 ) ?
187 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
190 rmesa
->RenderIndex
= -1; /* Impossible value */
191 rmesa
->vert_buf
= NULL
;
192 rmesa
->num_verts
= 0;
193 rmesa
->tnl_state
= ~0;
195 /* Set the maximum texture size small enough that we can guarentee that
196 * all texture units can bind a maximal texture and have them both in
197 * texturable memory at once.
200 ctx
->Const
.MaxTextureUnits
= 2;
201 ctx
->Const
.MaxTextureImageUnits
= 2;
202 ctx
->Const
.MaxTextureCoordUnits
= 2;
204 driCalculateMaxTextureLevels( rmesa
->texture_heaps
,
208 10, /* max 2D texture size is 1024x1024 */
209 0, /* 3D textures unsupported. */
210 0, /* cube textures unsupported. */
211 0, /* texture rectangles unsupported. */
217 ctx
->Const
.MinPointSize
= 1.0;
218 ctx
->Const
.MinPointSizeAA
= 1.0;
219 ctx
->Const
.MaxPointSize
= 1.0;
220 ctx
->Const
.MaxPointSizeAA
= 1.0;
224 ctx
->Const
.MinLineWidth
= 1.0;
225 ctx
->Const
.MinLineWidthAA
= 1.0;
226 ctx
->Const
.MaxLineWidth
= 1.0;
227 ctx
->Const
.MaxLineWidthAA
= 1.0;
228 ctx
->Const
.LineWidthGranularity
= 1.0;
230 #if ENABLE_PERF_BOXES
231 rmesa
->boxes
= driQueryOptionb(&rmesa
->optionCache
, "performance_boxes");
234 /* Initialize the software rasterizer and helper modules.
236 _swrast_CreateContext( ctx
);
237 _ac_CreateContext( ctx
);
238 _tnl_CreateContext( ctx
);
239 _swsetup_CreateContext( ctx
);
241 /* Install the customized pipeline:
243 /* _tnl_destroy_pipeline( ctx ); */
244 /* _tnl_install_pipeline( ctx, r128_pipeline ); */
246 /* Configure swrast and T&L to match hardware characteristics:
248 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
249 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
250 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
251 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
253 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
254 if (sPriv
->drmMinor
>= 4)
255 _mesa_enable_extension( ctx
, "GL_MESA_ycbcr_texture" );
257 r128InitTriFuncs( ctx
);
258 r128DDInitStateFuncs( ctx
);
259 r128DDInitSpanFuncs( ctx
);
260 r128DDInitState( rmesa
);
262 rmesa
->vblank_flags
= (rmesa
->r128Screen
->irq
!= 0)
263 ? driGetDefaultVBlankFlags(&rmesa
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
265 driContextPriv
->driverPrivate
= (void *)rmesa
;
268 R128_DEBUG
= driParseDebugString( getenv( "R128_DEBUG" ),
272 if (driQueryOptionb(&rmesa
->optionCache
, "no_rast")) {
273 fprintf(stderr
, "disabling 3D acceleration\n");
274 FALLBACK(rmesa
, R128_FALLBACK_DISABLE
, 1);
280 /* Destroy the device specific context.
282 void r128DestroyContext( __DRIcontextPrivate
*driContextPriv
)
284 r128ContextPtr rmesa
= (r128ContextPtr
) driContextPriv
->driverPrivate
;
286 assert(rmesa
); /* should never be null */
288 GLboolean release_texture_heaps
;
291 release_texture_heaps
= (rmesa
->glCtx
->Shared
->RefCount
== 1);
293 _swsetup_DestroyContext( rmesa
->glCtx
);
294 _tnl_DestroyContext( rmesa
->glCtx
);
295 _ac_DestroyContext( rmesa
->glCtx
);
296 _swrast_DestroyContext( rmesa
->glCtx
);
298 /* free the Mesa context */
299 rmesa
->glCtx
->DriverCtx
= NULL
;
300 _mesa_destroy_context(rmesa
->glCtx
);
302 if ( release_texture_heaps
) {
303 /* This share group is about to go away, free our private
304 * texture object data.
308 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
309 driDestroyTextureHeap( rmesa
->texture_heaps
[ i
] );
310 rmesa
->texture_heaps
[ i
] = NULL
;
313 assert( is_empty_list( & rmesa
->swapped
) );
316 /* free the option cache */
317 driDestroyOptionCache (&rmesa
->optionCache
);
323 /* Use this to force shared object profiling. */
329 /* Force the context `c' to be the current context and associate with it
333 r128MakeCurrent( __DRIcontextPrivate
*driContextPriv
,
334 __DRIdrawablePrivate
*driDrawPriv
,
335 __DRIdrawablePrivate
*driReadPriv
)
337 if ( driContextPriv
) {
338 GET_CURRENT_CONTEXT(ctx
);
339 r128ContextPtr oldR128Ctx
= ctx
? R128_CONTEXT(ctx
) : NULL
;
340 r128ContextPtr newR128Ctx
= (r128ContextPtr
) driContextPriv
->driverPrivate
;
342 if ( newR128Ctx
!= oldR128Ctx
) {
343 newR128Ctx
->new_state
|= R128_NEW_CONTEXT
;
344 newR128Ctx
->dirty
= R128_UPLOAD_ALL
;
347 driDrawableInitVBlank( driDrawPriv
, newR128Ctx
->vblank_flags
);
348 newR128Ctx
->driDrawable
= driDrawPriv
;
350 _mesa_make_current( newR128Ctx
->glCtx
,
351 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
352 (GLframebuffer
*) driReadPriv
->driverPrivate
);
354 newR128Ctx
->new_state
|= R128_NEW_WINDOW
| R128_NEW_CLIP
;
356 _mesa_make_current( NULL
, NULL
, NULL
);
363 /* Force the context `c' to be unbound from its buffer.
366 r128UnbindContext( __DRIcontextPrivate
*driContextPriv
)