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"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
41 #include "array_cache/acache.h"
43 #include "tnl/t_pipeline.h"
44 #include "tnl/t_vertex.h"
46 #include "drivers/common/driverfuncs.h"
48 #include "intel_screen.h"
51 #include "i830_common.h"
53 #include "intel_tex.h"
54 #include "intel_span.h"
55 #include "intel_ioctl.h"
56 #include "intel_batchbuffer.h"
57 #include "intel_blit.h"
58 #include "intel_regions.h"
59 #include "intel_buffer_objects.h"
65 int INTEL_DEBUG
= (0);
68 #define need_GL_ARB_multisample
69 #define need_GL_ARB_point_parameters
70 #define need_GL_ARB_texture_compression
71 #define need_GL_ARB_vertex_buffer_object
72 #define need_GL_ARB_vertex_program
73 #define need_GL_ARB_window_pos
74 #define need_GL_ARB_occlusion_query
75 #define need_GL_EXT_blend_color
76 #define need_GL_EXT_blend_equation_separate
77 #define need_GL_EXT_blend_func_separate
78 #define need_GL_EXT_blend_minmax
79 #define need_GL_EXT_cull_vertex
80 #define need_GL_EXT_fog_coord
81 #define need_GL_EXT_multi_draw_arrays
82 #define need_GL_EXT_secondary_color
83 #include "extension_helper.h"
94 /***************************************
95 * Mesa's Driver Functions
96 ***************************************/
98 #define DRIVER_VERSION "4.1.3002"
100 static const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
)
102 const char * chipset
;
103 static char buffer
[128];
107 return (GLubyte
*)"Tungsten Graphics, Inc";
111 switch (intel_context(ctx
)->intelScreen
->deviceID
) {
112 case PCI_CHIP_I965_Q
:
113 chipset
= "Intel(R) 965Q"; break;
115 case PCI_CHIP_I965_G
:
116 case PCI_CHIP_I965_G_1
:
117 chipset
= "Intel(R) 965G"; break;
119 case PCI_CHIP_I946_GZ
:
120 chipset
= "Intel(R) 946GZ"; break;
123 chipset
= "Unknown Intel Chipset"; break;
126 (void) driGetRendererString( buffer
, chipset
, DRIVER_VERSION
, 0 );
127 return (GLubyte
*) buffer
;
136 * Extension strings exported by the intel driver.
139 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
140 * old i830-specific driver.
142 const struct dri_extension card_extensions
[] =
144 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
145 { "GL_ARB_multitexture", NULL
},
146 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
147 { "GL_ARB_texture_border_clamp", NULL
},
148 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
149 { "GL_ARB_texture_cube_map", NULL
},
150 { "GL_ARB_texture_env_add", NULL
},
151 { "GL_ARB_texture_env_combine", NULL
},
152 { "GL_ARB_texture_env_dot3", NULL
},
153 { "GL_ARB_texture_mirrored_repeat", NULL
},
154 { "GL_ARB_texture_non_power_of_two", NULL
},
155 { "GL_ARB_texture_rectangle", NULL
},
156 { "GL_NV_texture_rectangle", NULL
},
157 { "GL_EXT_texture_rectangle", NULL
},
158 { "GL_ARB_texture_rectangle", NULL
},
159 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
160 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
161 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
162 { "GL_EXT_blend_color", GL_EXT_blend_color_functions
},
163 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
164 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
165 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
166 { "GL_EXT_blend_logic_op", NULL
},
167 { "GL_EXT_blend_subtract", NULL
},
168 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
169 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
170 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
171 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
172 { "GL_EXT_stencil_wrap", NULL
},
173 { "GL_EXT_texture_edge_clamp", NULL
},
174 { "GL_EXT_texture_env_combine", NULL
},
175 { "GL_EXT_texture_env_dot3", NULL
},
176 { "GL_EXT_texture_filter_anisotropic", NULL
},
177 { "GL_EXT_texture_lod_bias", NULL
},
178 { "GL_3DFX_texture_compression_FXT1", NULL
},
179 { "GL_APPLE_client_storage", NULL
},
180 { "GL_MESA_pack_invert", NULL
},
181 { "GL_MESA_ycbcr_texture", NULL
},
182 { "GL_NV_blend_square", NULL
},
183 { "GL_SGIS_generate_mipmap", NULL
},
187 static const struct dri_extension arb_oc_extension
=
188 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
};
190 static const struct dri_debug_control debug_control
[] =
192 { "fall", DEBUG_FALLBACKS
},
193 { "tex", DEBUG_TEXTURE
},
194 { "ioctl", DEBUG_IOCTL
},
195 { "prim", DEBUG_PRIMS
},
196 { "vert", DEBUG_VERTS
},
197 { "state", DEBUG_STATE
},
198 { "verb", DEBUG_VERBOSE
},
199 { "dri", DEBUG_DRI
},
200 { "dma", DEBUG_DMA
},
201 { "san", DEBUG_SANITY
},
202 { "sync", DEBUG_SYNC
},
203 { "sleep", DEBUG_SLEEP
},
204 { "pix", DEBUG_PIXEL
},
205 { "buf", DEBUG_BUFMGR
},
206 { "stats", DEBUG_STATS
},
207 { "tile", DEBUG_TILE
},
208 { "sing", DEBUG_SINGLE_THREAD
},
209 { "thre", DEBUG_SINGLE_THREAD
},
216 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
218 struct intel_context
*intel
= intel_context(ctx
);
220 _swrast_InvalidateState( ctx
, new_state
);
221 _swsetup_InvalidateState( ctx
, new_state
);
222 _ac_InvalidateState( ctx
, new_state
);
223 _tnl_InvalidateState( ctx
, new_state
);
224 _tnl_invalidate_vertex_state( ctx
, new_state
);
226 intel
->NewGLState
|= new_state
;
228 if (intel
->vtbl
.invalidate_state
)
229 intel
->vtbl
.invalidate_state( intel
, new_state
);
233 void intelFlush( GLcontext
*ctx
)
235 struct intel_context
*intel
= intel_context( ctx
);
237 bmLockAndFence(intel
);
240 void intelFinish( GLcontext
*ctx
)
242 struct intel_context
*intel
= intel_context( ctx
);
244 bmFinishFence(intel
, bmLockAndFence(intel
));
248 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
250 struct intel_context
*intel
= intel_context( ctx
);
253 .read_write
= MMIO_WRITE
,
254 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
257 intel
->stats_wm
= GL_TRUE
;
258 intelFinish(&intel
->ctx
);
259 drmCommandWrite(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
263 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
265 struct intel_context
*intel
= intel_context( ctx
);
267 .read_write
= MMIO_READ
,
268 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
271 intelFinish(&intel
->ctx
);
272 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
274 intel
->stats_wm
= GL_FALSE
;
278 void intelInitDriverFunctions( struct dd_function_table
*functions
)
280 _mesa_init_driver_functions( functions
);
282 functions
->Flush
= intelFlush
;
283 functions
->Finish
= intelFinish
;
284 functions
->GetString
= intelGetString
;
285 functions
->UpdateState
= intelInvalidateState
;
286 functions
->BeginQuery
= intelBeginQuery
;
287 functions
->EndQuery
= intelEndQuery
;
289 /* CopyPixels can be accelerated even with the current memory
292 if (!getenv("INTEL_NO_BLIT")) {
293 functions
->CopyPixels
= intelCopyPixels
;
294 functions
->Bitmap
= intelBitmap
;
297 intelInitTextureFuncs( functions
);
298 intelInitStateFuncs( functions
);
299 intelInitBufferFuncs( functions
);
304 GLboolean
intelInitContext( struct intel_context
*intel
,
305 const __GLcontextModes
*mesaVis
,
306 __DRIcontextPrivate
*driContextPriv
,
307 void *sharedContextPrivate
,
308 struct dd_function_table
*functions
)
310 GLcontext
*ctx
= &intel
->ctx
;
311 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
312 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
313 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
314 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
315 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
317 if (!_mesa_initialize_context(&intel
->ctx
,
321 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
325 driContextPriv
->driverPrivate
= intel
;
326 intel
->intelScreen
= intelScreen
;
327 intel
->driScreen
= sPriv
;
328 intel
->sarea
= saPriv
;
331 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
333 if (getenv("INTEL_STRICT_CONFORMANCE")) {
334 intel
->strict_conformance
= 1;
337 if (intel
->strict_conformance
) {
338 ctx
->Const
.MinLineWidth
= 1.0;
339 ctx
->Const
.MinLineWidthAA
= 1.0;
340 ctx
->Const
.MaxLineWidth
= 1.0;
341 ctx
->Const
.MaxLineWidthAA
= 1.0;
342 ctx
->Const
.LineWidthGranularity
= 1.0;
345 ctx
->Const
.MinLineWidth
= 1.0;
346 ctx
->Const
.MinLineWidthAA
= 1.0;
347 ctx
->Const
.MaxLineWidth
= 5.0;
348 ctx
->Const
.MaxLineWidthAA
= 5.0;
349 ctx
->Const
.LineWidthGranularity
= 0.5;
352 ctx
->Const
.MinPointSize
= 1.0;
353 ctx
->Const
.MinPointSizeAA
= 1.0;
354 ctx
->Const
.MaxPointSize
= 255.0;
355 ctx
->Const
.MaxPointSizeAA
= 3.0;
356 ctx
->Const
.PointSizeGranularity
= 1.0;
358 /* reinitialize the context point state.
359 * It depend on constants in __GLcontextRec::Const
361 _mesa_init_point(ctx
);
363 /* Initialize the software rasterizer and helper modules. */
364 _swrast_CreateContext( ctx
);
365 _ac_CreateContext( ctx
);
366 _tnl_CreateContext( ctx
);
367 _swsetup_CreateContext( ctx
);
369 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
371 /* Configure swrast to match hardware characteristics: */
372 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
373 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
376 intel
->hHWContext
= driContextPriv
->hHWContext
;
377 intel
->driFd
= sPriv
->fd
;
378 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
380 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
381 intel
->hw_stipple
= 1;
383 switch(mesaVis
->depthBits
) {
384 case 0: /* what to do in this case? */
386 intel
->depth_scale
= 1.0/0xffff;
387 intel
->polygon_offset_scale
= 1.0/0xffff;
388 intel
->depth_clear_mask
= ~0;
389 intel
->ClearDepth
= 0xffff;
392 intel
->depth_scale
= 1.0/0xffffff;
393 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
394 intel
->depth_clear_mask
= 0x00ffffff;
395 intel
->stencil_clear_mask
= 0xff000000;
396 intel
->ClearDepth
= 0x00ffffff;
403 /* Initialize swrast, tnl driver tables: */
404 intelInitSpanFuncs( ctx
);
406 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
408 if (!intel
->intelScreen
->irq_active
) {
409 _mesa_printf("IRQs not active. Exiting\n");
413 driInitExtensions( ctx
, card_extensions
,
416 if (intel
->intelScreen
->drmMinor
>= 8)
417 driInitSingleExtension (ctx
, &arb_oc_extension
);
419 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
425 intel
->bm
= bm_fake_intel_Attach( intel
);
429 intel
->intelScreen
->tex
.offset
, /* low offset */
430 intel
->intelScreen
->tex
.map
, /* low virtual */
431 intel
->intelScreen
->tex
.size
,
434 /* These are still static, but create regions for them.
436 intel
->front_region
=
437 intel_region_create_static(intel
,
439 intelScreen
->front
.offset
,
440 intelScreen
->front
.map
,
442 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
444 intelScreen
->front
.tiled
!= 0); /* 0: LINEAR */
448 intel_region_create_static(intel
,
450 intelScreen
->back
.offset
,
451 intelScreen
->back
.map
,
453 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
455 intelScreen
->back
.tiled
!= 0);
457 /* Still assuming front.cpp == depth.cpp
459 * XXX: Setting tiling to false because Depth tiling only supports
460 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
463 intel
->depth_region
=
464 intel_region_create_static(intel
,
466 intelScreen
->depth
.offset
,
467 intelScreen
->depth
.map
,
469 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
471 intelScreen
->depth
.tiled
!= 0);
473 intel_bufferobj_init( intel
);
474 intel
->batch
= intel_batchbuffer_alloc( intel
);
476 if (intel
->ctx
.Mesa_DXTn
) {
477 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
478 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
480 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
481 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
484 /* driInitTextureObjects( ctx, & intel->swapped, */
485 /* DRI_TEXMGR_DO_TEXTURE_1D | */
486 /* DRI_TEXMGR_DO_TEXTURE_2D | */
487 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
490 if (getenv("INTEL_NO_RAST")) {
491 fprintf(stderr
, "disabling 3D rasterization\n");
499 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
501 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
503 assert(intel
); /* should never be null */
505 GLboolean release_texture_heaps
;
508 intel
->vtbl
.destroy( intel
);
510 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
511 _swsetup_DestroyContext (&intel
->ctx
);
512 _tnl_DestroyContext (&intel
->ctx
);
513 _ac_DestroyContext (&intel
->ctx
);
515 _swrast_DestroyContext (&intel
->ctx
);
516 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
517 intel_batchbuffer_free(intel
->batch
);
521 if ( release_texture_heaps
) {
522 /* This share group is about to go away, free our private
523 * texture object data.
526 /* XXX: destroy the shared bufmgr struct here?
530 /* Free the regions created to describe front/back/depth
534 intel_region_release(intel
, &intel
->front_region
);
535 intel_region_release(intel
, &intel
->back_region
);
536 intel_region_release(intel
, &intel
->depth_region
);
537 intel_region_release(intel
, &intel
->draw_region
);
540 /* free the Mesa context */
541 _mesa_destroy_context(&intel
->ctx
);
544 driContextPriv
->driverPrivate
= NULL
;
547 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
552 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
553 __DRIdrawablePrivate
*driDrawPriv
,
554 __DRIdrawablePrivate
*driReadPriv
)
557 if (driContextPriv
) {
558 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
560 if ( intel
->driDrawable
!= driDrawPriv
) {
561 /* Shouldn't the readbuffer be stored also? */
562 intel
->driDrawable
= driDrawPriv
;
563 intelWindowMoved( intel
);
566 _mesa_make_current(&intel
->ctx
,
567 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
568 (GLframebuffer
*) driReadPriv
->driverPrivate
);
570 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
572 _mesa_make_current(NULL
, NULL
, NULL
);
579 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
581 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
582 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
583 volatile drmI830Sarea
* sarea
= intel
->sarea
;
584 int me
= intel
->hHWContext
;
585 int my_bufmgr
= bmCtxId(intel
);
587 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
589 /* If the window moved, may need to set a new cliprect now.
591 * NOTE: This releases and regains the hw lock, so all state
592 * checking must be done *after* this call:
595 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
599 intel
->need_flush
= 1;
603 if (sarea
->ctxOwner
!= me
) {
604 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea
->ctxOwner
, me
);
605 sarea
->ctxOwner
= me
;
606 intel
->vtbl
.lost_hardware( intel
);
609 /* As above, but don't evict the texture data on transitions
610 * between contexts which all share a local buffer manager.
612 if (sarea
->texAge
!= my_bufmgr
) {
613 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea
->ctxOwner
, my_bufmgr
);
614 sarea
->texAge
= my_bufmgr
;
615 bm_fake_NotifyContendedLockTake( intel
);
620 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
621 intelWindowMoved( intel
);
622 intel
->lastStamp
= dPriv
->lastStamp
;
626 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
628 /* Lock the hardware and validate our state.
630 void LOCK_HARDWARE( struct intel_context
*intel
)
634 _glthread_LOCK_MUTEX(lockMutex
);
635 assert(!intel
->locked
);
638 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
639 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
641 intelContendedLock( intel
, 0 );
645 if (intel
->aub_wrap
) {
646 bm_fake_NotifyContendedLockTake( intel
);
647 intel
->vtbl
.lost_hardware( intel
);
648 intel
->vtbl
.aub_wrap(intel
);
652 if (bmError(intel
)) {
654 intel
->vtbl
.lost_hardware( intel
);
657 /* Make sure nothing has been emitted prior to getting the lock:
659 assert(intel
->batch
->map
== 0);
661 /* XXX: postpone, may not be needed:
663 if (!intel_batchbuffer_map(intel
->batch
)) {
665 intel
->vtbl
.lost_hardware( intel
);
667 /* This could only fail if the batchbuffer was greater in size
668 * than the available texture memory:
670 if (!intel_batchbuffer_map(intel
->batch
)) {
671 _mesa_printf("double failure to map batchbuffer\n");
678 /* Unlock the hardware using the global current context
680 void UNLOCK_HARDWARE( struct intel_context
*intel
)
682 /* Make sure everything has been released:
684 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
686 intel_batchbuffer_unmap(intel
->batch
);
687 intel
->vtbl
.note_unlock( intel
);
692 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
693 _glthread_UNLOCK_MUTEX(lockMutex
);