1 /**************************************************************************
3 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Kevin E. Martin <martin@valinux.com>
31 * Gareth Hughes <gareth@valinux.com>
35 #include "main/glheader.h"
36 #include "main/context.h"
37 #include "main/simple_list.h"
38 #include "main/imports.h"
39 #include "main/matrix.h"
40 #include "main/extensions.h"
42 #include "swrast/swrast.h"
43 #include "swrast_setup/swrast_setup.h"
47 #include "tnl/t_pipeline.h"
49 #include "drivers/common/driverfuncs.h"
51 #include "r128_context.h"
52 #include "r128_ioctl.h"
54 #include "r128_state.h"
55 #include "r128_span.h"
57 #include "r128_tris.h"
62 #include "xmlpool.h" /* for symbolic values of enum-type options */
68 #define need_GL_EXT_blend_minmax
69 #define need_GL_EXT_fog_coord
70 #define need_GL_EXT_secondary_color
71 #include "main/remap_helper.h"
73 static const struct dri_extension card_extensions
[] =
75 { "GL_ARB_multitexture", NULL
},
76 { "GL_ARB_texture_env_add", NULL
},
77 { "GL_ARB_texture_mirrored_repeat", NULL
},
78 { "GL_EXT_blend_subtract", GL_EXT_blend_minmax_functions
},
79 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
80 { "GL_EXT_texture_edge_clamp", NULL
},
81 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
82 { "GL_EXT_stencil_wrap", NULL
},
83 { "GL_MESA_ycbcr_texture", NULL
},
84 { "GL_NV_blend_square", NULL
},
85 { "GL_SGIS_generate_mipmap", NULL
},
89 static const struct dri_debug_control debug_control
[] =
91 { "ioctl", DEBUG_VERBOSE_IOCTL
},
92 { "verb", DEBUG_VERBOSE_MSG
},
93 { "dri", DEBUG_VERBOSE_DRI
},
94 { "2d", DEBUG_VERBOSE_2D
},
95 { "sync", DEBUG_ALWAYS_SYNC
},
96 { "api", DEBUG_VERBOSE_API
},
97 { "fall", DEBUG_VERBOSE_FALL
},
101 /* Create the device specific context.
103 GLboolean
r128CreateContext( const __GLcontextModes
*glVisual
,
104 __DRIcontextPrivate
*driContextPriv
,
105 void *sharedContextPrivate
)
107 GLcontext
*ctx
, *shareCtx
;
108 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
109 struct dd_function_table functions
;
110 r128ContextPtr rmesa
;
111 r128ScreenPtr r128scrn
;
114 /* Allocate the r128 context */
115 rmesa
= (r128ContextPtr
) CALLOC( sizeof(*rmesa
) );
119 /* Init default driver functions then plug in our Radeon-specific functions
120 * (the texture functions are especially important)
122 _mesa_init_driver_functions( &functions
);
123 r128InitDriverFuncs( &functions
);
124 r128InitIoctlFuncs( &functions
);
125 r128InitTextureFuncs( &functions
);
127 /* Allocate the Mesa context */
128 if (sharedContextPrivate
)
129 shareCtx
= ((r128ContextPtr
) sharedContextPrivate
)->glCtx
;
132 rmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
133 &functions
, (void *) rmesa
);
138 driContextPriv
->driverPrivate
= rmesa
;
141 rmesa
->driContext
= driContextPriv
;
142 rmesa
->driScreen
= sPriv
;
143 rmesa
->driDrawable
= NULL
;
144 rmesa
->hHWContext
= driContextPriv
->hHWContext
;
145 rmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
146 rmesa
->driFd
= sPriv
->fd
;
148 r128scrn
= rmesa
->r128Screen
= (r128ScreenPtr
)(sPriv
->private);
150 /* Parse configuration files */
151 driParseConfigFiles (&rmesa
->optionCache
, &r128scrn
->optionCache
,
152 r128scrn
->driScreen
->myNum
, "r128");
154 rmesa
->sarea
= (drm_r128_sarea_t
*)((char *)sPriv
->pSAREA
+
155 r128scrn
->sarea_priv_offset
);
157 rmesa
->CurrentTexObj
[0] = NULL
;
158 rmesa
->CurrentTexObj
[1] = NULL
;
160 (void) memset( rmesa
->texture_heaps
, 0, sizeof( rmesa
->texture_heaps
) );
161 make_empty_list( & rmesa
->swapped
);
163 rmesa
->nr_heaps
= r128scrn
->numTexHeaps
;
164 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
165 rmesa
->texture_heaps
[i
] = driCreateTextureHeap( i
, rmesa
,
166 r128scrn
->texSize
[i
],
169 (drmTextureRegionPtr
)rmesa
->sarea
->tex_list
[i
],
170 &rmesa
->sarea
->tex_age
[i
],
172 sizeof( r128TexObj
),
173 (destroy_texture_object_t
*) r128DestroyTexObj
);
175 driSetTextureSwapCounterLocation( rmesa
->texture_heaps
[i
],
176 & rmesa
->c_textureSwaps
);
178 rmesa
->texture_depth
= driQueryOptioni (&rmesa
->optionCache
,
180 if (rmesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
181 rmesa
->texture_depth
= ( r128scrn
->cpp
== 4 ) ?
182 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
185 rmesa
->RenderIndex
= -1; /* Impossible value */
186 rmesa
->vert_buf
= NULL
;
187 rmesa
->num_verts
= 0;
188 RENDERINPUTS_ONES( rmesa
->tnl_state_bitset
);
190 /* Set the maximum texture size small enough that we can guarentee that
191 * all texture units can bind a maximal texture and have them both in
192 * texturable memory at once.
195 ctx
->Const
.MaxTextureUnits
= 2;
196 ctx
->Const
.MaxTextureImageUnits
= 2;
197 ctx
->Const
.MaxTextureCoordUnits
= 2;
199 driCalculateMaxTextureLevels( rmesa
->texture_heaps
,
203 10, /* max 2D texture size is 1024x1024 */
204 0, /* 3D textures unsupported. */
205 0, /* cube textures unsupported. */
206 0, /* texture rectangles unsupported. */
213 ctx
->Const
.MinPointSize
= 1.0;
214 ctx
->Const
.MinPointSizeAA
= 1.0;
215 ctx
->Const
.MaxPointSize
= 1.0;
216 ctx
->Const
.MaxPointSizeAA
= 1.0;
220 ctx
->Const
.MinLineWidth
= 1.0;
221 ctx
->Const
.MinLineWidthAA
= 1.0;
222 ctx
->Const
.MaxLineWidth
= 1.0;
223 ctx
->Const
.MaxLineWidthAA
= 1.0;
224 ctx
->Const
.LineWidthGranularity
= 1.0;
226 ctx
->Const
.MaxDrawBuffers
= 1;
228 #if ENABLE_PERF_BOXES
229 rmesa
->boxes
= driQueryOptionb(&rmesa
->optionCache
, "performance_boxes");
232 /* Initialize the software rasterizer and helper modules.
234 _swrast_CreateContext( ctx
);
235 _vbo_CreateContext( ctx
);
236 _tnl_CreateContext( ctx
);
237 _swsetup_CreateContext( ctx
);
239 /* Install the customized pipeline:
241 /* _tnl_destroy_pipeline( ctx ); */
242 /* _tnl_install_pipeline( ctx, r128_pipeline ); */
244 /* Configure swrast and T&L to match hardware characteristics:
246 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
247 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
248 _tnl_allow_pixel_fog( ctx
, GL_FALSE
);
249 _tnl_allow_vertex_fog( ctx
, GL_TRUE
);
251 driInitExtensions( ctx
, card_extensions
, GL_TRUE
);
252 if (sPriv
->drm_version
.minor
>= 4)
253 _mesa_enable_extension( ctx
, "GL_MESA_ycbcr_texture" );
255 r128InitTriFuncs( ctx
);
256 r128DDInitStateFuncs( ctx
);
257 r128DDInitSpanFuncs( ctx
);
258 r128DDInitState( rmesa
);
260 driContextPriv
->driverPrivate
= (void *)rmesa
;
263 R128_DEBUG
= driParseDebugString( getenv( "R128_DEBUG" ),
267 if (driQueryOptionb(&rmesa
->optionCache
, "no_rast")) {
268 fprintf(stderr
, "disabling 3D acceleration\n");
269 FALLBACK(rmesa
, R128_FALLBACK_DISABLE
, 1);
275 /* Destroy the device specific context.
277 void r128DestroyContext( __DRIcontextPrivate
*driContextPriv
)
279 r128ContextPtr rmesa
= (r128ContextPtr
) driContextPriv
->driverPrivate
;
281 assert(rmesa
); /* should never be null */
283 GLboolean release_texture_heaps
;
286 release_texture_heaps
= (rmesa
->glCtx
->Shared
->RefCount
== 1);
288 _swsetup_DestroyContext( rmesa
->glCtx
);
289 _tnl_DestroyContext( rmesa
->glCtx
);
290 _vbo_DestroyContext( rmesa
->glCtx
);
291 _swrast_DestroyContext( rmesa
->glCtx
);
293 if ( release_texture_heaps
) {
294 /* This share group is about to go away, free our private
295 * texture object data.
299 for ( i
= 0 ; i
< rmesa
->nr_heaps
; i
++ ) {
300 driDestroyTextureHeap( rmesa
->texture_heaps
[ i
] );
301 rmesa
->texture_heaps
[ i
] = NULL
;
304 assert( is_empty_list( & rmesa
->swapped
) );
307 /* free the Mesa context */
308 rmesa
->glCtx
->DriverCtx
= NULL
;
309 _mesa_destroy_context(rmesa
->glCtx
);
311 /* free the option cache */
312 driDestroyOptionCache (&rmesa
->optionCache
);
318 /* Use this to force shared object profiling. */
324 /* Force the context `c' to be the current context and associate with it
328 r128MakeCurrent( __DRIcontextPrivate
*driContextPriv
,
329 __DRIdrawablePrivate
*driDrawPriv
,
330 __DRIdrawablePrivate
*driReadPriv
)
332 if ( driContextPriv
) {
333 GET_CURRENT_CONTEXT(ctx
);
334 r128ContextPtr oldR128Ctx
= ctx
? R128_CONTEXT(ctx
) : NULL
;
335 r128ContextPtr newR128Ctx
= (r128ContextPtr
) driContextPriv
->driverPrivate
;
337 if ( newR128Ctx
!= oldR128Ctx
) {
338 newR128Ctx
->new_state
|= R128_NEW_CONTEXT
;
339 newR128Ctx
->dirty
= R128_UPLOAD_ALL
;
342 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
343 driDrawPriv
->vblFlags
= (newR128Ctx
->r128Screen
->irq
!= 0)
344 ? driGetDefaultVBlankFlags(&newR128Ctx
->optionCache
)
345 : VBLANK_FLAG_NO_IRQ
;
347 driDrawableInitVBlank( driDrawPriv
);
349 newR128Ctx
->driDrawable
= driDrawPriv
;
351 _mesa_make_current( newR128Ctx
->glCtx
,
352 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
353 (GLframebuffer
*) driReadPriv
->driverPrivate
);
355 newR128Ctx
->new_state
|= R128_NEW_WINDOW
| R128_NEW_CLIP
;
357 _mesa_make_current( NULL
, NULL
, NULL
);
364 /* Force the context `c' to be unbound from its buffer.
367 r128UnbindContext( __DRIcontextPrivate
*driContextPriv
)