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_ARB_occlusion_query
74 #define need_GL_EXT_blend_color
75 #define need_GL_EXT_blend_equation_separate
76 #define need_GL_EXT_blend_func_separate
77 #define need_GL_EXT_blend_minmax
78 #define need_GL_EXT_cull_vertex
79 #define need_GL_EXT_fog_coord
80 #define need_GL_EXT_multi_draw_arrays
81 #define need_GL_EXT_secondary_color
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;
121 case PCI_CHIP_CRESTLINE
:
122 chipset
= "Intel(R) Crestline"; break;
125 chipset
= "Unknown Intel Chipset"; break;
128 (void) driGetRendererString( buffer
, chipset
, DRIVER_VERSION
, 0 );
129 return (GLubyte
*) buffer
;
138 * Extension strings exported by the intel driver.
141 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
142 * old i830-specific driver.
144 const struct dri_extension card_extensions
[] =
146 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
147 { "GL_ARB_multitexture", NULL
},
148 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
149 { "GL_ARB_texture_border_clamp", NULL
},
150 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
151 { "GL_ARB_texture_cube_map", NULL
},
152 { "GL_ARB_texture_env_add", NULL
},
153 { "GL_ARB_texture_env_combine", NULL
},
154 { "GL_ARB_texture_env_dot3", NULL
},
155 { "GL_ARB_texture_mirrored_repeat", NULL
},
156 { "GL_ARB_texture_non_power_of_two", NULL
},
157 { "GL_ARB_texture_rectangle", NULL
},
158 { "GL_NV_texture_rectangle", NULL
},
159 { "GL_EXT_texture_rectangle", NULL
},
160 { "GL_ARB_texture_rectangle", NULL
},
161 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
162 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
163 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
164 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
},
165 { "GL_EXT_blend_color", GL_EXT_blend_color_functions
},
166 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
167 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
168 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
169 { "GL_EXT_blend_logic_op", NULL
},
170 { "GL_EXT_blend_subtract", NULL
},
171 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
172 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
173 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
174 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
175 { "GL_EXT_stencil_wrap", NULL
},
176 { "GL_EXT_texture_edge_clamp", NULL
},
177 { "GL_EXT_texture_env_combine", NULL
},
178 { "GL_EXT_texture_env_dot3", NULL
},
179 { "GL_EXT_texture_filter_anisotropic", NULL
},
180 { "GL_EXT_texture_lod_bias", NULL
},
181 { "GL_3DFX_texture_compression_FXT1", NULL
},
182 { "GL_APPLE_client_storage", NULL
},
183 { "GL_MESA_pack_invert", NULL
},
184 { "GL_MESA_ycbcr_texture", NULL
},
185 { "GL_NV_blend_square", NULL
},
186 { "GL_SGIS_generate_mipmap", NULL
},
192 static const struct dri_debug_control debug_control
[] =
194 { "fall", DEBUG_FALLBACKS
},
195 { "tex", DEBUG_TEXTURE
},
196 { "ioctl", DEBUG_IOCTL
},
197 { "prim", DEBUG_PRIMS
},
198 { "vert", DEBUG_VERTS
},
199 { "state", DEBUG_STATE
},
200 { "verb", DEBUG_VERBOSE
},
201 { "dri", DEBUG_DRI
},
202 { "dma", DEBUG_DMA
},
203 { "san", DEBUG_SANITY
},
204 { "sync", DEBUG_SYNC
},
205 { "sleep", DEBUG_SLEEP
},
206 { "pix", DEBUG_PIXEL
},
207 { "buf", DEBUG_BUFMGR
},
208 { "stats", DEBUG_STATS
},
209 { "tile", DEBUG_TILE
},
210 { "sing", DEBUG_SINGLE_THREAD
},
211 { "thre", DEBUG_SINGLE_THREAD
},
218 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
220 struct intel_context
*intel
= intel_context(ctx
);
222 _swrast_InvalidateState( ctx
, new_state
);
223 _swsetup_InvalidateState( ctx
, new_state
);
224 _ac_InvalidateState( ctx
, new_state
);
225 _tnl_InvalidateState( ctx
, new_state
);
226 _tnl_invalidate_vertex_state( ctx
, new_state
);
228 intel
->NewGLState
|= new_state
;
230 if (intel
->vtbl
.invalidate_state
)
231 intel
->vtbl
.invalidate_state( intel
, new_state
);
235 void intelFlush( GLcontext
*ctx
)
237 struct intel_context
*intel
= intel_context( ctx
);
239 bmLockAndFence(intel
);
242 void intelFinish( GLcontext
*ctx
)
244 struct intel_context
*intel
= intel_context( ctx
);
246 bmFinishFence(intel
, bmLockAndFence(intel
));
250 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
252 struct intel_context
*intel
= intel_context( ctx
);
255 .read_write
= MMIO_WRITE
,
256 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
259 intel
->stats_wm
= GL_TRUE
;
260 intelFinish(&intel
->ctx
);
261 drmCommandWrite(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
265 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
267 struct intel_context
*intel
= intel_context( ctx
);
269 .read_write
= MMIO_READ
,
270 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
273 intelFinish(&intel
->ctx
);
274 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
276 intel
->stats_wm
= GL_FALSE
;
280 void intelInitDriverFunctions( struct dd_function_table
*functions
)
282 _mesa_init_driver_functions( functions
);
284 functions
->Flush
= intelFlush
;
285 functions
->Finish
= intelFinish
;
286 functions
->GetString
= intelGetString
;
287 functions
->UpdateState
= intelInvalidateState
;
288 functions
->BeginQuery
= intelBeginQuery
;
289 functions
->EndQuery
= intelEndQuery
;
291 /* CopyPixels can be accelerated even with the current memory
294 if (!getenv("INTEL_NO_BLIT")) {
295 functions
->CopyPixels
= intelCopyPixels
;
296 functions
->Bitmap
= intelBitmap
;
299 intelInitTextureFuncs( functions
);
300 intelInitStateFuncs( functions
);
301 intelInitBufferFuncs( functions
);
306 GLboolean
intelInitContext( struct intel_context
*intel
,
307 const __GLcontextModes
*mesaVis
,
308 __DRIcontextPrivate
*driContextPriv
,
309 void *sharedContextPrivate
,
310 struct dd_function_table
*functions
)
312 GLcontext
*ctx
= &intel
->ctx
;
313 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
314 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
315 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
316 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
317 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
319 if (!_mesa_initialize_context(&intel
->ctx
,
323 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
327 driContextPriv
->driverPrivate
= intel
;
328 intel
->intelScreen
= intelScreen
;
329 intel
->driScreen
= sPriv
;
330 intel
->sarea
= saPriv
;
333 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
335 if (getenv("INTEL_STRICT_CONFORMANCE")) {
336 intel
->strict_conformance
= 1;
339 if (intel
->strict_conformance
) {
340 ctx
->Const
.MinLineWidth
= 1.0;
341 ctx
->Const
.MinLineWidthAA
= 1.0;
342 ctx
->Const
.MaxLineWidth
= 1.0;
343 ctx
->Const
.MaxLineWidthAA
= 1.0;
344 ctx
->Const
.LineWidthGranularity
= 1.0;
347 ctx
->Const
.MinLineWidth
= 1.0;
348 ctx
->Const
.MinLineWidthAA
= 1.0;
349 ctx
->Const
.MaxLineWidth
= 5.0;
350 ctx
->Const
.MaxLineWidthAA
= 5.0;
351 ctx
->Const
.LineWidthGranularity
= 0.5;
354 ctx
->Const
.MinPointSize
= 1.0;
355 ctx
->Const
.MinPointSizeAA
= 1.0;
356 ctx
->Const
.MaxPointSize
= 255.0;
357 ctx
->Const
.MaxPointSizeAA
= 3.0;
358 ctx
->Const
.PointSizeGranularity
= 1.0;
360 /* reinitialize the context point state.
361 * It depend on constants in __GLcontextRec::Const
363 _mesa_init_point(ctx
);
365 /* Initialize the software rasterizer and helper modules. */
366 _swrast_CreateContext( ctx
);
367 _ac_CreateContext( ctx
);
368 _tnl_CreateContext( ctx
);
369 _swsetup_CreateContext( ctx
);
371 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
373 /* Configure swrast to match hardware characteristics: */
374 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
375 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
378 intel
->hHWContext
= driContextPriv
->hHWContext
;
379 intel
->driFd
= sPriv
->fd
;
380 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
382 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
383 intel
->hw_stipple
= 1;
385 switch(mesaVis
->depthBits
) {
386 case 0: /* what to do in this case? */
388 intel
->depth_scale
= 1.0/0xffff;
389 intel
->polygon_offset_scale
= 1.0/0xffff;
390 intel
->depth_clear_mask
= ~0;
391 intel
->ClearDepth
= 0xffff;
394 intel
->depth_scale
= 1.0/0xffffff;
395 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
396 intel
->depth_clear_mask
= 0x00ffffff;
397 intel
->stencil_clear_mask
= 0xff000000;
398 intel
->ClearDepth
= 0x00ffffff;
405 /* Initialize swrast, tnl driver tables: */
406 intelInitSpanFuncs( ctx
);
408 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
410 if (!intel
->intelScreen
->irq_active
) {
411 _mesa_printf("IRQs not active. Exiting\n");
415 driInitExtensions( ctx
, card_extensions
,
418 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
424 intel
->bm
= bm_fake_intel_Attach( intel
);
428 intel
->intelScreen
->tex
.offset
, /* low offset */
429 intel
->intelScreen
->tex
.map
, /* low virtual */
430 intel
->intelScreen
->tex
.size
,
433 /* These are still static, but create regions for them.
435 intel
->front_region
=
436 intel_region_create_static(intel
,
438 intelScreen
->front
.offset
,
439 intelScreen
->front
.map
,
441 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
443 intelScreen
->front
.tiled
!= 0); /* 0: LINEAR */
447 intel_region_create_static(intel
,
449 intelScreen
->back
.offset
,
450 intelScreen
->back
.map
,
452 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
454 intelScreen
->back
.tiled
!= 0);
456 /* Still assuming front.cpp == depth.cpp
458 * XXX: Setting tiling to false because Depth tiling only supports
459 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
462 intel
->depth_region
=
463 intel_region_create_static(intel
,
465 intelScreen
->depth
.offset
,
466 intelScreen
->depth
.map
,
468 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
470 intelScreen
->depth
.tiled
!= 0);
472 intel_bufferobj_init( intel
);
473 intel
->batch
= intel_batchbuffer_alloc( intel
);
475 if (intel
->ctx
.Mesa_DXTn
) {
476 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
477 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
479 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
480 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
483 /* driInitTextureObjects( ctx, & intel->swapped, */
484 /* DRI_TEXMGR_DO_TEXTURE_1D | */
485 /* DRI_TEXMGR_DO_TEXTURE_2D | */
486 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
489 if (getenv("INTEL_NO_RAST")) {
490 fprintf(stderr
, "disabling 3D rasterization\n");
498 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
500 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
502 assert(intel
); /* should never be null */
504 GLboolean release_texture_heaps
;
507 intel
->vtbl
.destroy( intel
);
509 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
510 _swsetup_DestroyContext (&intel
->ctx
);
511 _tnl_DestroyContext (&intel
->ctx
);
512 _ac_DestroyContext (&intel
->ctx
);
514 _swrast_DestroyContext (&intel
->ctx
);
515 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
516 intel_batchbuffer_free(intel
->batch
);
520 if ( release_texture_heaps
) {
521 /* This share group is about to go away, free our private
522 * texture object data.
525 /* XXX: destroy the shared bufmgr struct here?
529 /* Free the regions created to describe front/back/depth
533 intel_region_release(intel
, &intel
->front_region
);
534 intel_region_release(intel
, &intel
->back_region
);
535 intel_region_release(intel
, &intel
->depth_region
);
536 intel_region_release(intel
, &intel
->draw_region
);
539 /* free the Mesa context */
540 _mesa_destroy_context(&intel
->ctx
);
543 driContextPriv
->driverPrivate
= NULL
;
546 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
551 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
552 __DRIdrawablePrivate
*driDrawPriv
,
553 __DRIdrawablePrivate
*driReadPriv
)
556 if (driContextPriv
) {
557 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
559 if ( intel
->driDrawable
!= driDrawPriv
) {
560 /* Shouldn't the readbuffer be stored also? */
561 intel
->driDrawable
= driDrawPriv
;
562 intelWindowMoved( intel
);
565 _mesa_make_current(&intel
->ctx
,
566 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
567 (GLframebuffer
*) driReadPriv
->driverPrivate
);
569 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
571 _mesa_make_current(NULL
, NULL
, NULL
);
578 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
580 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
581 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
582 volatile drmI830Sarea
* sarea
= intel
->sarea
;
583 int me
= intel
->hHWContext
;
584 int my_bufmgr
= bmCtxId(intel
);
586 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
588 /* If the window moved, may need to set a new cliprect now.
590 * NOTE: This releases and regains the hw lock, so all state
591 * checking must be done *after* this call:
594 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
598 intel
->need_flush
= 1;
602 if (sarea
->ctxOwner
!= me
) {
603 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea
->ctxOwner
, me
);
604 sarea
->ctxOwner
= me
;
605 intel
->vtbl
.lost_hardware( intel
);
608 /* As above, but don't evict the texture data on transitions
609 * between contexts which all share a local buffer manager.
611 if (sarea
->texAge
!= my_bufmgr
) {
612 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea
->ctxOwner
, my_bufmgr
);
613 sarea
->texAge
= my_bufmgr
;
614 bm_fake_NotifyContendedLockTake( intel
);
619 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
620 intelWindowMoved( intel
);
621 intel
->lastStamp
= dPriv
->lastStamp
;
625 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
627 /* Lock the hardware and validate our state.
629 void LOCK_HARDWARE( struct intel_context
*intel
)
633 _glthread_LOCK_MUTEX(lockMutex
);
634 assert(!intel
->locked
);
637 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
638 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
640 intelContendedLock( intel
, 0 );
644 if (intel
->aub_wrap
) {
645 bm_fake_NotifyContendedLockTake( intel
);
646 intel
->vtbl
.lost_hardware( intel
);
647 intel
->vtbl
.aub_wrap(intel
);
651 if (bmError(intel
)) {
653 intel
->vtbl
.lost_hardware( intel
);
656 /* Make sure nothing has been emitted prior to getting the lock:
658 assert(intel
->batch
->map
== 0);
660 /* XXX: postpone, may not be needed:
662 if (!intel_batchbuffer_map(intel
->batch
)) {
664 intel
->vtbl
.lost_hardware( intel
);
666 /* This could only fail if the batchbuffer was greater in size
667 * than the available texture memory:
669 if (!intel_batchbuffer_map(intel
->batch
)) {
670 _mesa_printf("double failure to map batchbuffer\n");
677 /* Unlock the hardware using the global current context
679 void UNLOCK_HARDWARE( struct intel_context
*intel
)
681 /* Make sure everything has been released:
683 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
685 intel_batchbuffer_unmap(intel
->batch
);
686 intel
->vtbl
.note_unlock( intel
);
691 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
692 _glthread_UNLOCK_MUTEX(lockMutex
);