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 #define need_GL_NV_vertex_program
82 #include "extension_helper.h"
93 /***************************************
94 * Mesa's Driver Functions
95 ***************************************/
97 #define DRIVER_VERSION "4.1.3002"
99 static const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
)
101 const char * chipset
;
102 static char buffer
[128];
106 return (GLubyte
*)"Tungsten Graphics, Inc";
110 switch (intel_context(ctx
)->intelScreen
->deviceID
) {
111 case PCI_CHIP_I965_Q
:
112 chipset
= "Intel(R) 965Q"; break;
114 case PCI_CHIP_I965_G
:
115 case PCI_CHIP_I965_G_1
:
116 chipset
= "Intel(R) 965G"; break;
118 case PCI_CHIP_I946_GZ
:
119 chipset
= "Intel(R) 946GZ"; break;
122 chipset
= "Unknown Intel Chipset"; break;
125 (void) driGetRendererString( buffer
, chipset
, DRIVER_VERSION
, 0 );
126 return (GLubyte
*) buffer
;
135 * Extension strings exported by the intel driver.
138 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
139 * old i830-specific driver.
141 const struct dri_extension card_extensions
[] =
143 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
144 { "GL_ARB_multitexture", NULL
},
145 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
146 { "GL_ARB_texture_border_clamp", NULL
},
147 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
148 { "GL_ARB_texture_cube_map", NULL
},
149 { "GL_ARB_texture_env_add", NULL
},
150 { "GL_ARB_texture_env_combine", NULL
},
151 { "GL_ARB_texture_env_dot3", NULL
},
152 { "GL_ARB_texture_mirrored_repeat", NULL
},
153 { "GL_ARB_texture_rectangle", NULL
},
154 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
155 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
156 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
157 { "GL_EXT_blend_color", GL_EXT_blend_color_functions
},
158 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
159 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
160 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
161 { "GL_EXT_blend_logic_op", NULL
},
162 { "GL_EXT_blend_subtract", NULL
},
163 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
164 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
165 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
166 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
167 { "GL_EXT_stencil_wrap", NULL
},
168 { "GL_EXT_texture_edge_clamp", NULL
},
169 { "GL_EXT_texture_env_combine", NULL
},
170 { "GL_EXT_texture_env_dot3", NULL
},
171 { "GL_EXT_texture_filter_anisotropic", NULL
},
172 { "GL_EXT_texture_lod_bias", NULL
},
173 { "GL_3DFX_texture_compression_FXT1", NULL
},
174 { "GL_APPLE_client_storage", NULL
},
175 { "GL_MESA_pack_invert", NULL
},
176 { "GL_MESA_ycbcr_texture", NULL
},
177 { "GL_NV_blend_square", NULL
},
178 { "GL_NV_vertex_program", GL_NV_vertex_program_functions
},
179 { "GL_NV_vertex_program1_1", NULL
},
180 { "GL_SGIS_generate_mipmap", NULL
},
186 static const struct dri_debug_control debug_control
[] =
188 { "fall", DEBUG_FALLBACKS
},
189 { "tex", DEBUG_TEXTURE
},
190 { "ioctl", DEBUG_IOCTL
},
191 { "prim", DEBUG_PRIMS
},
192 { "vert", DEBUG_VERTS
},
193 { "state", DEBUG_STATE
},
194 { "verb", DEBUG_VERBOSE
},
195 { "dri", DEBUG_DRI
},
196 { "dma", DEBUG_DMA
},
197 { "san", DEBUG_SANITY
},
198 { "sync", DEBUG_SYNC
},
199 { "sleep", DEBUG_SLEEP
},
200 { "pix", DEBUG_PIXEL
},
201 { "buf", DEBUG_BUFMGR
},
202 { "stats", DEBUG_STATS
},
203 { "tile", DEBUG_TILE
},
204 { "sing", DEBUG_SINGLE_THREAD
},
205 { "thre", DEBUG_SINGLE_THREAD
},
211 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
213 struct intel_context
*intel
= intel_context(ctx
);
215 _swrast_InvalidateState( ctx
, new_state
);
216 _swsetup_InvalidateState( ctx
, new_state
);
217 _ac_InvalidateState( ctx
, new_state
);
218 _tnl_InvalidateState( ctx
, new_state
);
219 _tnl_invalidate_vertex_state( ctx
, new_state
);
221 intel
->NewGLState
|= new_state
;
223 if (intel
->vtbl
.invalidate_state
)
224 intel
->vtbl
.invalidate_state( intel
, new_state
);
228 void intelFlush( GLcontext
*ctx
)
230 struct intel_context
*intel
= intel_context( ctx
);
232 bmLockAndFence(intel
);
235 void intelFinish( GLcontext
*ctx
)
237 struct intel_context
*intel
= intel_context( ctx
);
239 bmFinishFence(intel
, bmLockAndFence(intel
));
243 void intelInitDriverFunctions( struct dd_function_table
*functions
)
245 _mesa_init_driver_functions( functions
);
247 functions
->Flush
= intelFlush
;
248 functions
->Finish
= intelFinish
;
249 functions
->GetString
= intelGetString
;
250 functions
->UpdateState
= intelInvalidateState
;
251 functions
->CopyColorTable
= _swrast_CopyColorTable
;
252 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
253 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
254 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
256 /* Pixel path fallbacks.
258 functions
->Accum
= _swrast_Accum
;
259 functions
->Bitmap
= _swrast_Bitmap
;
260 functions
->CopyPixels
= _swrast_CopyPixels
;
261 functions
->ReadPixels
= _swrast_ReadPixels
;
262 functions
->DrawPixels
= _swrast_DrawPixels
;
264 intelInitTextureFuncs( functions
);
265 intelInitStateFuncs( functions
);
266 intelInitBufferFuncs( functions
);
271 GLboolean
intelInitContext( struct intel_context
*intel
,
272 const __GLcontextModes
*mesaVis
,
273 __DRIcontextPrivate
*driContextPriv
,
274 void *sharedContextPrivate
,
275 struct dd_function_table
*functions
)
277 GLcontext
*ctx
= &intel
->ctx
;
278 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
279 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
280 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
281 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
282 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
284 if (!_mesa_initialize_context(&intel
->ctx
,
288 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
292 driContextPriv
->driverPrivate
= intel
;
293 intel
->intelScreen
= intelScreen
;
294 intel
->driScreen
= sPriv
;
295 intel
->sarea
= saPriv
;
298 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
300 if (getenv("INTEL_STRICT_CONFORMANCE")) {
301 intel
->strict_conformance
= 1;
304 if (intel
->strict_conformance
) {
305 ctx
->Const
.MinLineWidth
= 1.0;
306 ctx
->Const
.MinLineWidthAA
= 1.0;
307 ctx
->Const
.MaxLineWidth
= 1.0;
308 ctx
->Const
.MaxLineWidthAA
= 1.0;
309 ctx
->Const
.LineWidthGranularity
= 1.0;
312 ctx
->Const
.MinLineWidth
= 1.0;
313 ctx
->Const
.MinLineWidthAA
= 1.0;
314 ctx
->Const
.MaxLineWidth
= 5.0;
315 ctx
->Const
.MaxLineWidthAA
= 5.0;
316 ctx
->Const
.LineWidthGranularity
= 0.5;
319 ctx
->Const
.MinPointSize
= 1.0;
320 ctx
->Const
.MinPointSizeAA
= 1.0;
321 ctx
->Const
.MaxPointSize
= 255.0;
322 ctx
->Const
.MaxPointSizeAA
= 3.0;
323 ctx
->Const
.PointSizeGranularity
= 1.0;
325 /* Initialize the software rasterizer and helper modules. */
326 _swrast_CreateContext( ctx
);
327 _ac_CreateContext( ctx
);
328 _tnl_CreateContext( ctx
);
329 _swsetup_CreateContext( ctx
);
331 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
333 /* Configure swrast to match hardware characteristics: */
334 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
335 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
338 intel
->hHWContext
= driContextPriv
->hHWContext
;
339 intel
->driFd
= sPriv
->fd
;
340 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
342 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
343 intel
->hw_stipple
= 1;
345 switch(mesaVis
->depthBits
) {
346 case 0: /* what to do in this case? */
348 intel
->depth_scale
= 1.0/0xffff;
349 intel
->polygon_offset_scale
= 1.0/0xffff;
350 intel
->depth_clear_mask
= ~0;
351 intel
->ClearDepth
= 0xffff;
354 intel
->depth_scale
= 1.0/0xffffff;
355 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
356 intel
->depth_clear_mask
= 0x00ffffff;
357 intel
->stencil_clear_mask
= 0xff000000;
358 intel
->ClearDepth
= 0x00ffffff;
365 /* Initialize swrast, tnl driver tables: */
366 intelInitSpanFuncs( ctx
);
368 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
370 if (!intel
->intelScreen
->irq_active
) {
371 _mesa_printf("IRQs not active. Exiting\n");
375 _math_matrix_ctr (&intel
->ViewportMatrix
);
377 driInitExtensions( ctx
, card_extensions
,
380 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
386 intel
->bm
= bm_fake_intel_Attach( intel
);
390 intel
->intelScreen
->tex
.offset
, /* low offset */
391 intel
->intelScreen
->tex
.map
, /* low virtual */
392 intel
->intelScreen
->tex
.size
,
395 /* These are still static, but create regions for them.
397 intel
->front_region
=
398 intel_region_create_static(intel
,
400 intelScreen
->front
.offset
,
401 intelScreen
->front
.map
,
403 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
409 intel_region_create_static(intel
,
411 intelScreen
->back
.offset
,
412 intelScreen
->back
.map
,
414 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
416 (INTEL_DEBUG
& DEBUG_TILE
) ? 0 : 1);
418 /* Still assuming front.cpp == depth.cpp
420 * XXX: Setting tiling to false because Depth tiling only supports
421 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
424 intel
->depth_region
=
425 intel_region_create_static(intel
,
427 intelScreen
->depth
.offset
,
428 intelScreen
->depth
.map
,
430 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
432 (INTEL_DEBUG
& DEBUG_TILE
) ? 0 : 1);
434 intel_bufferobj_init( intel
);
435 intel
->batch
= intel_batchbuffer_alloc( intel
);
437 if (intel
->ctx
.Mesa_DXTn
) {
438 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
439 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
441 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
442 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
445 /* driInitTextureObjects( ctx, & intel->swapped, */
446 /* DRI_TEXMGR_DO_TEXTURE_1D | */
447 /* DRI_TEXMGR_DO_TEXTURE_2D | */
448 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
451 intel
->prim
.primitive
= ~0;
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
);
541 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
543 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
544 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
545 volatile drmI830Sarea
* sarea
= intel
->sarea
;
546 int me
= intel
->hHWContext
;
548 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
550 /* If the window moved, may need to set a new cliprect now.
552 * NOTE: This releases and regains the hw lock, so all state
553 * checking must be done *after* this call:
556 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
563 if (sarea
->ctxOwner
!= me
) {
564 intel
->perf_boxes
|= I830_BOX_LOST_CONTEXT
;
565 sarea
->ctxOwner
= me
;
567 /* Should also fence the frontbuffer even if ctxOwner doesn't
570 bm_fake_NotifyContendedLockTake( intel
);
575 intel
->vtbl
.lost_hardware( intel
);
578 /* Because the X server issues drawing commands without properly
579 * fencing them, we need to be paraniod about waiting for hardware
580 * rendering to finish after a contended lock.
582 intel
->flushBeforeFallback
= GL_TRUE
;
586 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
587 intelWindowMoved( intel
);
588 intel
->lastStamp
= dPriv
->lastStamp
;
590 /* This works because the lock is always grabbed before emitting
591 * commands and commands are always flushed prior to releasing
594 intel
->NewGLState
|= _NEW_WINDOW_POS
;
598 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
600 /* Lock the hardware and validate our state.
602 void LOCK_HARDWARE( struct intel_context
*intel
)
606 _glthread_LOCK_MUTEX(lockMutex
);
607 assert(!intel
->locked
);
610 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
611 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
613 intelContendedLock( intel
, 0 );
617 if (intel
->aub_wrap
) {
618 /* Should also fence the frontbuffer even if ctxOwner doesn't
621 bm_fake_NotifyContendedLockTake( intel
);
625 intel
->vtbl
.lost_hardware( intel
);
626 intel
->vtbl
.aub_wrap(intel
);
632 /* Make sure nothing has been emitted prior to getting the lock:
634 assert(intel
->batch
->map
== 0);
636 /* XXX: postpone, may not be needed:
638 intel_batchbuffer_map(intel
->batch
);
642 /* Unlock the hardware using the global current context
644 void UNLOCK_HARDWARE( struct intel_context
*intel
)
646 /* Make sure everything has been released:
648 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
650 intel_batchbuffer_unmap(intel
->batch
);
651 intel
->vtbl
.note_unlock( intel
);
656 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
657 _glthread_UNLOCK_MUTEX(lockMutex
);