1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include "simple_list.h"
33 #include "extensions.h"
34 #include "framebuffer.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "array_cache/acache.h"
42 #include "tnl/t_pipeline.h"
43 #include "tnl/t_vertex.h"
45 #include "drivers/common/driverfuncs.h"
47 #include "intel_screen.h"
50 #include "i830_common.h"
52 #include "intel_tex.h"
53 #include "intel_span.h"
54 #include "intel_ioctl.h"
55 #include "intel_batchbuffer.h"
56 #include "intel_blit.h"
57 #include "intel_regions.h"
58 #include "intel_buffer_objects.h"
64 int INTEL_DEBUG
= (0);
67 #define need_GL_ARB_multisample
68 #define need_GL_ARB_point_parameters
69 #define need_GL_ARB_texture_compression
70 #define need_GL_ARB_vertex_buffer_object
71 #define need_GL_ARB_vertex_program
72 #define need_GL_ARB_window_pos
73 #define need_GL_EXT_blend_color
74 #define need_GL_EXT_blend_equation_separate
75 #define need_GL_EXT_blend_func_separate
76 #define need_GL_EXT_blend_minmax
77 #define need_GL_EXT_cull_vertex
78 #define need_GL_EXT_fog_coord
79 #define need_GL_EXT_multi_draw_arrays
80 #define need_GL_EXT_secondary_color
81 #include "extension_helper.h"
92 /***************************************
93 * Mesa's Driver Functions
94 ***************************************/
96 #define DRIVER_VERSION "4.1.3002"
98 static const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
)
100 const char * chipset
;
101 static char buffer
[128];
105 return (GLubyte
*)"Tungsten Graphics, Inc";
109 switch (intel_context(ctx
)->intelScreen
->deviceID
) {
110 case PCI_CHIP_I965_Q
:
111 chipset
= "Intel(R) 965Q"; break;
113 case PCI_CHIP_I965_G
:
114 case PCI_CHIP_I965_G_1
:
115 chipset
= "Intel(R) 965G"; break;
117 case PCI_CHIP_I946_GZ
:
118 chipset
= "Intel(R) 946GZ"; break;
121 chipset
= "Unknown Intel Chipset"; break;
124 (void) driGetRendererString( buffer
, chipset
, DRIVER_VERSION
, 0 );
125 return (GLubyte
*) buffer
;
134 * Extension strings exported by the intel driver.
137 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
138 * old i830-specific driver.
140 const struct dri_extension card_extensions
[] =
142 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
143 { "GL_ARB_multitexture", NULL
},
144 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
145 { "GL_ARB_texture_border_clamp", NULL
},
146 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
147 { "GL_ARB_texture_cube_map", NULL
},
148 { "GL_ARB_texture_env_add", NULL
},
149 { "GL_ARB_texture_env_combine", NULL
},
150 { "GL_ARB_texture_env_dot3", NULL
},
151 { "GL_ARB_texture_mirrored_repeat", NULL
},
152 { "GL_ARB_texture_rectangle", NULL
},
153 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
154 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
155 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
156 { "GL_EXT_blend_color", GL_EXT_blend_color_functions
},
157 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
158 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
159 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
160 { "GL_EXT_blend_logic_op", NULL
},
161 { "GL_EXT_blend_subtract", NULL
},
162 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
163 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
164 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
165 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
166 { "GL_EXT_stencil_wrap", NULL
},
167 { "GL_EXT_texture_edge_clamp", NULL
},
168 { "GL_EXT_texture_env_combine", NULL
},
169 { "GL_EXT_texture_env_dot3", NULL
},
170 { "GL_EXT_texture_filter_anisotropic", NULL
},
171 { "GL_EXT_texture_lod_bias", NULL
},
172 { "GL_3DFX_texture_compression_FXT1", NULL
},
173 { "GL_APPLE_client_storage", NULL
},
174 { "GL_MESA_pack_invert", NULL
},
175 { "GL_MESA_ycbcr_texture", NULL
},
176 { "GL_NV_blend_square", NULL
},
177 { "GL_SGIS_generate_mipmap", NULL
},
183 static const struct dri_debug_control debug_control
[] =
185 { "fall", DEBUG_FALLBACKS
},
186 { "tex", DEBUG_TEXTURE
},
187 { "ioctl", DEBUG_IOCTL
},
188 { "prim", DEBUG_PRIMS
},
189 { "vert", DEBUG_VERTS
},
190 { "state", DEBUG_STATE
},
191 { "verb", DEBUG_VERBOSE
},
192 { "dri", DEBUG_DRI
},
193 { "dma", DEBUG_DMA
},
194 { "san", DEBUG_SANITY
},
195 { "sync", DEBUG_SYNC
},
196 { "sleep", DEBUG_SLEEP
},
197 { "pix", DEBUG_PIXEL
},
198 { "buf", DEBUG_BUFMGR
},
199 { "stats", DEBUG_STATS
},
200 { "tile", DEBUG_TILE
},
201 { "sing", DEBUG_SINGLE_THREAD
},
202 { "thre", DEBUG_SINGLE_THREAD
},
209 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
211 struct intel_context
*intel
= intel_context(ctx
);
213 _swrast_InvalidateState( ctx
, new_state
);
214 _swsetup_InvalidateState( ctx
, new_state
);
215 _ac_InvalidateState( ctx
, new_state
);
216 _tnl_InvalidateState( ctx
, new_state
);
217 _tnl_invalidate_vertex_state( ctx
, new_state
);
219 intel
->NewGLState
|= new_state
;
221 if (intel
->vtbl
.invalidate_state
)
222 intel
->vtbl
.invalidate_state( intel
, new_state
);
226 void intelFlush( GLcontext
*ctx
)
228 struct intel_context
*intel
= intel_context( ctx
);
230 bmLockAndFence(intel
);
233 void intelFinish( GLcontext
*ctx
)
235 struct intel_context
*intel
= intel_context( ctx
);
237 bmFinishFence(intel
, bmLockAndFence(intel
));
241 void intelInitDriverFunctions( struct dd_function_table
*functions
)
243 _mesa_init_driver_functions( functions
);
245 functions
->Flush
= intelFlush
;
246 functions
->Finish
= intelFinish
;
247 functions
->GetString
= intelGetString
;
248 functions
->UpdateState
= intelInvalidateState
;
249 functions
->CopyColorTable
= _swrast_CopyColorTable
;
250 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
251 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
252 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
254 /* Pixel path fallbacks.
256 functions
->Accum
= _swrast_Accum
;
257 functions
->Bitmap
= _swrast_Bitmap
;
258 functions
->ReadPixels
= _swrast_ReadPixels
;
259 functions
->DrawPixels
= _swrast_DrawPixels
;
261 /* CopyPixels can be accelerated even with the current memory
264 functions
->CopyPixels
= intelCopyPixels
;
266 intelInitTextureFuncs( functions
);
267 intelInitStateFuncs( functions
);
268 intelInitBufferFuncs( functions
);
273 GLboolean
intelInitContext( struct intel_context
*intel
,
274 const __GLcontextModes
*mesaVis
,
275 __DRIcontextPrivate
*driContextPriv
,
276 void *sharedContextPrivate
,
277 struct dd_function_table
*functions
)
279 GLcontext
*ctx
= &intel
->ctx
;
280 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
281 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
282 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
283 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
284 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
286 if (!_mesa_initialize_context(&intel
->ctx
,
290 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
294 driContextPriv
->driverPrivate
= intel
;
295 intel
->intelScreen
= intelScreen
;
296 intel
->driScreen
= sPriv
;
297 intel
->sarea
= saPriv
;
300 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
302 if (getenv("INTEL_STRICT_CONFORMANCE")) {
303 intel
->strict_conformance
= 1;
306 if (intel
->strict_conformance
) {
307 ctx
->Const
.MinLineWidth
= 1.0;
308 ctx
->Const
.MinLineWidthAA
= 1.0;
309 ctx
->Const
.MaxLineWidth
= 1.0;
310 ctx
->Const
.MaxLineWidthAA
= 1.0;
311 ctx
->Const
.LineWidthGranularity
= 1.0;
314 ctx
->Const
.MinLineWidth
= 1.0;
315 ctx
->Const
.MinLineWidthAA
= 1.0;
316 ctx
->Const
.MaxLineWidth
= 5.0;
317 ctx
->Const
.MaxLineWidthAA
= 5.0;
318 ctx
->Const
.LineWidthGranularity
= 0.5;
321 ctx
->Const
.MinPointSize
= 1.0;
322 ctx
->Const
.MinPointSizeAA
= 1.0;
323 ctx
->Const
.MaxPointSize
= 255.0;
324 ctx
->Const
.MaxPointSizeAA
= 3.0;
325 ctx
->Const
.PointSizeGranularity
= 1.0;
327 /* Initialize the software rasterizer and helper modules. */
328 _swrast_CreateContext( ctx
);
329 _ac_CreateContext( ctx
);
330 _tnl_CreateContext( ctx
);
331 _swsetup_CreateContext( ctx
);
333 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
335 /* Configure swrast to match hardware characteristics: */
336 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
337 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
340 intel
->hHWContext
= driContextPriv
->hHWContext
;
341 intel
->driFd
= sPriv
->fd
;
342 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
344 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
345 intel
->hw_stipple
= 1;
347 switch(mesaVis
->depthBits
) {
348 case 0: /* what to do in this case? */
350 intel
->depth_scale
= 1.0/0xffff;
351 intel
->polygon_offset_scale
= 1.0/0xffff;
352 intel
->depth_clear_mask
= ~0;
353 intel
->ClearDepth
= 0xffff;
356 intel
->depth_scale
= 1.0/0xffffff;
357 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
358 intel
->depth_clear_mask
= 0x00ffffff;
359 intel
->stencil_clear_mask
= 0xff000000;
360 intel
->ClearDepth
= 0x00ffffff;
367 /* Initialize swrast, tnl driver tables: */
368 intelInitSpanFuncs( ctx
);
370 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
372 if (!intel
->intelScreen
->irq_active
) {
373 _mesa_printf("IRQs not active. Exiting\n");
377 _math_matrix_ctr (&intel
->ViewportMatrix
);
379 driInitExtensions( ctx
, card_extensions
,
382 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
388 intel
->bm
= bm_fake_intel_Attach( intel
);
392 intel
->intelScreen
->tex
.offset
, /* low offset */
393 intel
->intelScreen
->tex
.map
, /* low virtual */
394 intel
->intelScreen
->tex
.size
,
397 /* These are still static, but create regions for them.
399 intel
->front_region
=
400 intel_region_create_static(intel
,
402 intelScreen
->front
.offset
,
403 intelScreen
->front
.map
,
405 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
411 intel_region_create_static(intel
,
413 intelScreen
->back
.offset
,
414 intelScreen
->back
.map
,
416 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
418 (INTEL_DEBUG
& DEBUG_TILE
) ? 0 : 1);
420 /* Still assuming front.cpp == depth.cpp
422 * XXX: Setting tiling to false because Depth tiling only supports
423 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
426 intel
->depth_region
=
427 intel_region_create_static(intel
,
429 intelScreen
->depth
.offset
,
430 intelScreen
->depth
.map
,
432 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
434 (INTEL_DEBUG
& DEBUG_TILE
) ? 0 : 1);
436 intel_bufferobj_init( intel
);
437 intel
->batch
= intel_batchbuffer_alloc( intel
);
439 if (intel
->ctx
.Mesa_DXTn
) {
440 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
441 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
443 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
444 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
447 /* driInitTextureObjects( ctx, & intel->swapped, */
448 /* DRI_TEXMGR_DO_TEXTURE_1D | */
449 /* DRI_TEXMGR_DO_TEXTURE_2D | */
450 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
453 if (getenv("INTEL_NO_RAST")) {
454 fprintf(stderr
, "disabling 3D rasterization\n");
462 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
464 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
466 assert(intel
); /* should never be null */
468 GLboolean release_texture_heaps
;
471 intel
->vtbl
.destroy( intel
);
473 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
474 _swsetup_DestroyContext (&intel
->ctx
);
475 _tnl_DestroyContext (&intel
->ctx
);
476 _ac_DestroyContext (&intel
->ctx
);
478 _swrast_DestroyContext (&intel
->ctx
);
479 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
480 intel_batchbuffer_free(intel
->batch
);
484 if ( release_texture_heaps
) {
485 /* This share group is about to go away, free our private
486 * texture object data.
489 /* XXX: destroy the shared bufmgr struct here?
493 /* Free the regions created to describe front/back/depth
497 intel_region_release(intel
, &intel
->front_region
);
498 intel_region_release(intel
, &intel
->back_region
);
499 intel_region_release(intel
, &intel
->depth_region
);
500 intel_region_release(intel
, &intel
->draw_region
);
503 /* free the Mesa context */
504 _mesa_destroy_context(&intel
->ctx
);
507 driContextPriv
->driverPrivate
= NULL
;
510 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
515 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
516 __DRIdrawablePrivate
*driDrawPriv
,
517 __DRIdrawablePrivate
*driReadPriv
)
520 if (driContextPriv
) {
521 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
523 if ( intel
->driDrawable
!= driDrawPriv
) {
524 /* Shouldn't the readbuffer be stored also? */
525 intel
->driDrawable
= driDrawPriv
;
526 intelWindowMoved( intel
);
529 _mesa_make_current(&intel
->ctx
,
530 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
531 (GLframebuffer
*) driReadPriv
->driverPrivate
);
533 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
535 _mesa_make_current(NULL
, NULL
, NULL
);
542 static void lost_hardware( struct intel_context
*intel
)
544 bm_fake_NotifyContendedLockTake( intel
);
545 intel
->vtbl
.lost_hardware( intel
);
548 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
550 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
551 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
552 volatile drmI830Sarea
* sarea
= intel
->sarea
;
553 int me
= intel
->hHWContext
;
555 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
557 /* If the window moved, may need to set a new cliprect now.
559 * NOTE: This releases and regains the hw lock, so all state
560 * checking must be done *after* this call:
563 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
570 if (sarea
->ctxOwner
!= me
) {
571 sarea
->ctxOwner
= me
;
572 lost_hardware(intel
);
577 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
578 intelWindowMoved( intel
);
579 intel
->lastStamp
= dPriv
->lastStamp
;
581 /* This works because the lock is always grabbed before emitting
582 * commands and commands are always flushed prior to releasing
585 intel
->NewGLState
|= _NEW_WINDOW_POS
;
589 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
591 /* Lock the hardware and validate our state.
593 void LOCK_HARDWARE( struct intel_context
*intel
)
597 _glthread_LOCK_MUTEX(lockMutex
);
598 assert(!intel
->locked
);
601 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
602 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
604 intelContendedLock( intel
, 0 );
608 if (intel
->aub_wrap
) {
609 bm_fake_NotifyContendedLockTake( intel
);
610 intel
->vtbl
.lost_hardware( intel
);
611 intel
->vtbl
.aub_wrap(intel
);
615 if (bmError(intel
)) {
617 intel
->vtbl
.lost_hardware( intel
);
620 /* Make sure nothing has been emitted prior to getting the lock:
622 assert(intel
->batch
->map
== 0);
624 /* XXX: postpone, may not be needed:
626 if (!intel_batchbuffer_map(intel
->batch
)) {
628 intel
->vtbl
.lost_hardware( intel
);
630 /* This could only fail if the batchbuffer was greater in size
631 * than the available texture memory:
633 if (!intel_batchbuffer_map(intel
->batch
)) {
634 _mesa_printf("double failure to map batchbuffer\n");
641 /* Unlock the hardware using the global current context
643 void UNLOCK_HARDWARE( struct intel_context
*intel
)
645 /* Make sure everything has been released:
647 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
649 intel_batchbuffer_unmap(intel
->batch
);
650 intel
->vtbl
.note_unlock( intel
);
655 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
656 _glthread_UNLOCK_MUTEX(lockMutex
);