2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
33 * Nicolai Haehnle <prefect_@gmx.net>
36 #include "api_arrayelt.h"
38 #include "simple_list.h"
41 #include "extensions.h"
44 #include "swrast/swrast.h"
45 #include "swrast_setup/swrast_setup.h"
46 #include "array_cache/acache.h"
49 #include "tnl/t_pipeline.h"
51 #include "drivers/common/driverfuncs.h"
53 #include "radeon_ioctl.h"
54 #include "radeon_span.h"
55 #include "r300_context.h"
56 #include "r300_cmdbuf.h"
57 #include "r300_state.h"
58 #include "r300_ioctl.h"
63 #include "xmlpool.h" /* for symbolic values of enum-type options */
65 /* hw_tcl_on derives from future_hw_tcl_on when its safe to change it. */
66 int future_hw_tcl_on
=0;
69 /* Extension strings exported by the R300 driver.
71 static const char *const card_extensions
[] = {
73 "GL_ARB_multitexture",
74 "GL_ARB_texture_border_clamp",
75 "GL_ARB_texture_compression",
76 /* disable until we support it, fixes a few things in ut2004 */
77 // "GL_ARB_texture_cube_map",
78 "GL_ARB_texture_env_add",
79 "GL_ARB_texture_env_combine",
80 "GL_ARB_texture_env_dot3",
81 "GL_ARB_texture_mirrored_repeat",
82 "GL_ARB_vertex_buffer_object",
83 "GL_ARB_vertex_program",
85 "GL_ARB_fragment_program",
87 "GL_EXT_blend_equation_separate",
88 "GL_EXT_blend_func_separate",
89 "GL_EXT_blend_minmax",
90 "GL_EXT_blend_subtract",
91 "GL_EXT_secondary_color",
92 "GL_EXT_stencil_wrap",
93 "GL_EXT_texture_edge_clamp",
94 "GL_EXT_texture_env_combine",
95 "GL_EXT_texture_env_dot3",
96 "GL_EXT_texture_filter_anisotropic",
97 "GL_EXT_texture_lod_bias",
98 "GL_EXT_texture_mirror_clamp",
99 "GL_EXT_texture_rectangle",
100 "GL_ATI_texture_env_combine3",
101 "GL_ATI_texture_mirror_once",
102 "GL_MESA_pack_invert",
103 "GL_MESA_ycbcr_texture",
104 "GL_NV_blend_square",
105 "GL_NV_vertex_program",
106 "GL_SGIS_generate_mipmap",
107 "GL_ARB_texture_env_crossbar",
111 extern struct tnl_pipeline_stage _r300_render_stage
;
112 extern struct tnl_pipeline_stage _r300_tcl_stage
;
114 static const struct tnl_pipeline_stage
*r300_pipeline
[] = {
116 /* Try and go straight to t&l
120 /* Catch any t&l fallbacks
122 &_tnl_vertex_transform_stage
,
123 &_tnl_normal_transform_stage
,
124 &_tnl_lighting_stage
,
125 &_tnl_fog_coordinate_stage
,
127 &_tnl_texture_transform_stage
,
128 &_tnl_vertex_program_stage
,
130 /* Try again to go to tcl?
131 * - no good for asymmetric-twoside (do with multipass)
132 * - no good for asymmetric-unfilled (do with multipass)
133 * - good for material
135 * - need to manipulate a bit of state
137 * - worth it/not worth it?
140 /* Else do them here.
143 &_tnl_render_stage
, /* FALLBACK */
147 void r300BufferData(GLcontext
*ctx
, GLenum target
, GLsizeiptrARB size
,
148 const GLvoid
*data
, GLenum usage
, struct gl_buffer_object
*obj
)
150 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
151 drm_radeon_mem_alloc_t alloc
;
154 alloc
.region
= RADEON_MEM_REGION_GART
;
157 alloc
.region_offset
= &offset
;
159 ret
= drmCommandWriteRead( rmesa
->radeon
.dri
.fd
, DRM_RADEON_ALLOC
, &alloc
, sizeof(alloc
));
161 WARN_ONCE("Ran out of GART memory!\n");
162 _mesa_buffer_data(ctx
, target
, size
, data
, usage
, obj
);
165 obj
->Data
= ((char *)rmesa
->radeon
.radeonScreen
->gartTextures
.map
) + offset
;
166 memcpy(obj
->Data
, data
, size
);
170 fprintf(stderr
, "allocated %d bytes at %p, offset=%d\n", size
, obj
->Data
, offset
);
174 void r300DeleteBuffer(GLcontext
*ctx
, struct gl_buffer_object
*obj
)
176 r300ContextPtr rmesa
= R300_CONTEXT(ctx
);
178 if(r300IsGartMemory(rmesa
, obj
->Data
, obj
->Size
)){
179 drm_radeon_mem_free_t memfree
;
182 memfree
.region
= RADEON_MEM_REGION_GART
;
183 memfree
.region_offset
= (char *)obj
->Data
- (char *)rmesa
->radeon
.radeonScreen
->gartTextures
.map
;
185 ret
= drmCommandWrite(rmesa
->radeon
.radeonScreen
->driScreen
->fd
,
186 DRM_RADEON_FREE
, &memfree
, sizeof(memfree
));
189 WARN_ONCE("Failed to free GART memroy!\n");
193 _mesa_delete_buffer_object(ctx
, obj
);
196 /* Create the device specific rendering context.
198 GLboolean
r300CreateContext(const __GLcontextModes
* glVisual
,
199 __DRIcontextPrivate
* driContextPriv
,
200 void *sharedContextPrivate
)
202 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
203 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
204 struct dd_function_table functions
;
210 assert(driContextPriv
);
213 /* Allocate the R300 context */
214 r300
= (r300ContextPtr
)CALLOC(sizeof(*r300
));
218 /* Parse configuration files.
219 * Do this here so that initialMaxAnisotropy is set before we create
220 * the default textures.
222 driParseConfigFiles(&r300
->radeon
.optionCache
, &screen
->optionCache
,
223 screen
->driScreen
->myNum
, "r300");
225 /* Init default driver functions then plug in our R300-specific functions
226 * (the texture functions are especially important)
228 _mesa_init_driver_functions(&functions
);
229 r300InitIoctlFuncs(&functions
);
230 r300InitStateFuncs(&functions
);
231 r300InitTextureFuncs(&functions
);
232 r300InitShaderFuncs(&functions
);
234 functions
.BufferData
= r300BufferData
;
235 functions
.DeleteBuffer
= r300DeleteBuffer
;
238 if (!radeonInitContext(&r300
->radeon
, &functions
,
239 glVisual
, driContextPriv
, sharedContextPrivate
)) {
244 /* Init r300 context data */
245 r300
->dma
.buf0_address
= r300
->radeon
.radeonScreen
->buffers
->list
[0].address
;
247 (void)memset(r300
->texture_heaps
, 0, sizeof(r300
->texture_heaps
));
248 make_empty_list(&r300
->swapped
);
250 r300
->nr_heaps
= 1 /* screen->numTexHeaps */ ;
251 assert(r300
->nr_heaps
< R200_NR_TEX_HEAPS
);
252 for (i
= 0; i
< r300
->nr_heaps
; i
++) {
253 r300
->texture_heaps
[i
] = driCreateTextureHeap(i
, r300
,
256 RADEON_NR_TEX_REGIONS
,
257 (drmTextureRegionPtr
)
260 &r300
->radeon
.sarea
->
265 (destroy_texture_object_t
269 r300
->texture_depth
= driQueryOptioni(&r300
->radeon
.optionCache
,
271 if (r300
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
272 r300
->texture_depth
= (screen
->cpp
== 4) ?
273 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
275 /* Set the maximum texture size small enough that we can guarentee that
276 * all texture units can bind a maximal texture and have them both in
277 * texturable memory at once.
280 ctx
= r300
->radeon
.glCtx
;
282 ctx
->Const
.MaxTextureImageUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
283 "texture_image_units");
284 ctx
->Const
.MaxTextureCoordUnits
= driQueryOptioni(&r300
->radeon
.optionCache
,
285 "texture_coord_units");
286 ctx
->Const
.MaxTextureUnits
= MIN2(ctx
->Const
.MaxTextureImageUnits
,
287 ctx
->Const
.MaxTextureCoordUnits
);
288 ctx
->Const
.MaxTextureMaxAnisotropy
= 16.0;
290 ctx
->Const
.MinPointSize
= 1.0;
291 ctx
->Const
.MinPointSizeAA
= 1.0;
292 ctx
->Const
.MaxPointSize
= R300_POINTSIZE_MAX
;
293 ctx
->Const
.MaxPointSizeAA
= R300_POINTSIZE_MAX
;
295 ctx
->Const
.MinLineWidth
= 1.0;
296 ctx
->Const
.MinLineWidthAA
= 1.0;
297 ctx
->Const
.MaxLineWidth
= R300_LINESIZE_MAX
;
298 ctx
->Const
.MaxLineWidthAA
= R300_LINESIZE_MAX
;
300 /* Initialize the software rasterizer and helper modules.
302 _swrast_CreateContext(ctx
);
303 _ac_CreateContext(ctx
);
304 _tnl_CreateContext(ctx
);
305 _swsetup_CreateContext(ctx
);
306 _swsetup_Wakeup(ctx
);
307 _ae_create_context(ctx
);
309 /* Install the customized pipeline:
311 _tnl_destroy_pipeline(ctx
);
312 _tnl_install_pipeline(ctx
, r300_pipeline
);
314 /* Try and keep materials and vertices separate:
316 _tnl_isolate_materials(ctx
, GL_TRUE
);
318 /* Configure swrast and TNL to match hardware characteristics:
320 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
321 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
322 _tnl_allow_pixel_fog(ctx
, GL_FALSE
);
323 _tnl_allow_vertex_fog(ctx
, GL_TRUE
);
325 /* currently bogus data */
326 ctx
->Const
.MaxVertexProgramInstructions
=VSF_MAX_FRAGMENT_LENGTH
;
327 ctx
->Const
.MaxVertexProgramAttribs
=16; // r420
328 ctx
->Const
.MaxVertexProgramTemps
=VSF_MAX_FRAGMENT_TEMPS
;
329 ctx
->Const
.MaxVertexProgramLocalParams
=256; // r420
330 ctx
->Const
.MaxVertexProgramEnvParams
=256; // r420
331 ctx
->Const
.MaxVertexProgramAddressRegs
=1;
334 ctx
->Const
.MaxFragmentProgramTemps
= PFS_NUM_TEMP_REGS
;
335 ctx
->Const
.MaxFragmentProgramAttribs
= 11; /* copy i915... */
336 ctx
->Const
.MaxFragmentProgramLocalParams
= PFS_NUM_CONST_REGS
;
337 ctx
->Const
.MaxFragmentProgramEnvParams
= PFS_NUM_CONST_REGS
;
338 ctx
->Const
.MaxFragmentProgramAluInstructions
= PFS_MAX_ALU_INST
;
339 ctx
->Const
.MaxFragmentProgramTexInstructions
= PFS_MAX_TEX_INST
;
340 ctx
->Const
.MaxFragmentProgramInstructions
= PFS_MAX_ALU_INST
+PFS_MAX_TEX_INST
;
341 ctx
->Const
.MaxFragmentProgramTexIndirections
= PFS_MAX_TEX_INDIRECT
;
342 ctx
->Const
.MaxFragmentProgramAddressRegs
= 0; /* and these are?? */
343 ctx
->_MaintainTexEnvProgram
= GL_TRUE
;
346 driInitExtensions(ctx
, card_extensions
, GL_TRUE
);
348 radeonInitSpanFuncs(ctx
);
349 r300InitCmdBuf(r300
);
353 /* plug in a few more device driver functions */
354 /* XXX these should really go right after _mesa_init_driver_functions() */
355 r300InitPixelFuncs(ctx
);
358 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
360 tcl_mode
= driQueryOptioni(&r300
->radeon
.optionCache
, "tcl_mode");
361 if (driQueryOptionb(&r300
->radeon
.optionCache
, "no_rast")) {
362 fprintf(stderr
, "disabling 3D acceleration\n");
364 FALLBACK(&r300
->radeon
, RADEON_FALLBACK_DISABLE
, 1);
367 if (tcl_mode
== DRI_CONF_TCL_SW
||
368 !(r300
->radeon
.radeonScreen
->chipset
& RADEON_CHIPSET_TCL
)) {
369 if (r300
->radeon
.radeonScreen
->chipset
& RADEON_CHIPSET_TCL
) {
370 r300
->radeon
.radeonScreen
->chipset
&= ~RADEON_CHIPSET_TCL
;
371 fprintf(stderr
, "Disabling HW TCL support\n");
373 TCL_FALLBACK(r300
->radeon
.glCtx
, RADEON_TCL_FALLBACK_TCL_DISABLE
, 1);
379 /* Destroy the device specific context.
381 void r300DestroyContext(__DRIcontextPrivate
* driContextPriv
)
383 GET_CURRENT_CONTEXT(ctx
);
384 r300ContextPtr r300
= (r300ContextPtr
) driContextPriv
->driverPrivate
;
385 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
387 if (RADEON_DEBUG
& DEBUG_DRI
) {
388 fprintf(stderr
, "Destroying context !\n");
391 /* check if we're deleting the currently bound context */
392 if (&r300
->radeon
== current
) {
393 radeonFlush(r300
->radeon
.glCtx
);
394 _mesa_make_current(NULL
, NULL
, NULL
);
397 /* Free r300 context resources */
398 assert(r300
); /* should never be null */
401 GLboolean release_texture_heaps
;
403 release_texture_heaps
= (r300
->radeon
.glCtx
->Shared
->RefCount
== 1);
404 _swsetup_DestroyContext(r300
->radeon
.glCtx
);
405 _tnl_DestroyContext(r300
->radeon
.glCtx
);
406 _ac_DestroyContext(r300
->radeon
.glCtx
);
407 _swrast_DestroyContext(r300
->radeon
.glCtx
);
409 r300DestroyCmdBuf(r300
);
411 radeonCleanupContext(&r300
->radeon
);
413 /* free the option cache */
414 driDestroyOptionCache(&r300
->radeon
.optionCache
);