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 const struct dri_extension arb_oc_extension
=
188 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
};
190 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
)
192 struct intel_context
*intel
= ctx
?intel_context(ctx
):NULL
;
193 driInitExtensions(ctx
, card_extensions
, enable_imaging
);
194 if (!ctx
|| intel
->intelScreen
->drmMinor
>= 8)
195 driInitSingleExtension (ctx
, &arb_oc_extension
);
198 static const struct dri_debug_control debug_control
[] =
200 { "fall", DEBUG_FALLBACKS
},
201 { "tex", DEBUG_TEXTURE
},
202 { "ioctl", DEBUG_IOCTL
},
203 { "prim", DEBUG_PRIMS
},
204 { "vert", DEBUG_VERTS
},
205 { "state", DEBUG_STATE
},
206 { "verb", DEBUG_VERBOSE
},
207 { "dri", DEBUG_DRI
},
208 { "dma", DEBUG_DMA
},
209 { "san", DEBUG_SANITY
},
210 { "sync", DEBUG_SYNC
},
211 { "sleep", DEBUG_SLEEP
},
212 { "pix", DEBUG_PIXEL
},
213 { "buf", DEBUG_BUFMGR
},
214 { "stats", DEBUG_STATS
},
215 { "tile", DEBUG_TILE
},
216 { "sing", DEBUG_SINGLE_THREAD
},
217 { "thre", DEBUG_SINGLE_THREAD
},
224 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
226 struct intel_context
*intel
= intel_context(ctx
);
228 _swrast_InvalidateState( ctx
, new_state
);
229 _swsetup_InvalidateState( ctx
, new_state
);
230 _ac_InvalidateState( ctx
, new_state
);
231 _tnl_InvalidateState( ctx
, new_state
);
232 _tnl_invalidate_vertex_state( ctx
, new_state
);
234 intel
->NewGLState
|= new_state
;
236 if (intel
->vtbl
.invalidate_state
)
237 intel
->vtbl
.invalidate_state( intel
, new_state
);
241 void intelFlush( GLcontext
*ctx
)
243 struct intel_context
*intel
= intel_context( ctx
);
245 bmLockAndFence(intel
);
248 void intelFinish( GLcontext
*ctx
)
250 struct intel_context
*intel
= intel_context( ctx
);
252 bmFinishFence(intel
, bmLockAndFence(intel
));
256 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
258 struct intel_context
*intel
= intel_context( ctx
);
260 .read_write
= MMIO_WRITE
,
261 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
264 intel
->stats_wm
= GL_TRUE
;
265 intelFinish(&intel
->ctx
);
266 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
270 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
272 struct intel_context
*intel
= intel_context( ctx
);
275 .read_write
= MMIO_READ
,
276 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
279 intelFinish(&intel
->ctx
);
280 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
281 q
->Result
= tmp
- q
->Result
;
283 intel
->stats_wm
= GL_FALSE
;
287 void intelInitDriverFunctions( struct dd_function_table
*functions
)
289 _mesa_init_driver_functions( functions
);
291 functions
->Flush
= intelFlush
;
292 functions
->Finish
= intelFinish
;
293 functions
->GetString
= intelGetString
;
294 functions
->UpdateState
= intelInvalidateState
;
295 functions
->BeginQuery
= intelBeginQuery
;
296 functions
->EndQuery
= intelEndQuery
;
298 /* CopyPixels can be accelerated even with the current memory
301 if (!getenv("INTEL_NO_BLIT")) {
302 functions
->CopyPixels
= intelCopyPixels
;
303 functions
->Bitmap
= intelBitmap
;
306 intelInitTextureFuncs( functions
);
307 intelInitStateFuncs( functions
);
308 intelInitBufferFuncs( functions
);
313 GLboolean
intelInitContext( struct intel_context
*intel
,
314 const __GLcontextModes
*mesaVis
,
315 __DRIcontextPrivate
*driContextPriv
,
316 void *sharedContextPrivate
,
317 struct dd_function_table
*functions
)
319 GLcontext
*ctx
= &intel
->ctx
;
320 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
321 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
322 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
323 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
324 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
326 if (!_mesa_initialize_context(&intel
->ctx
,
330 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
334 driContextPriv
->driverPrivate
= intel
;
335 intel
->intelScreen
= intelScreen
;
336 intel
->driScreen
= sPriv
;
337 intel
->sarea
= saPriv
;
340 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
342 if (getenv("INTEL_STRICT_CONFORMANCE")) {
343 intel
->strict_conformance
= 1;
346 if (intel
->strict_conformance
) {
347 ctx
->Const
.MinLineWidth
= 1.0;
348 ctx
->Const
.MinLineWidthAA
= 1.0;
349 ctx
->Const
.MaxLineWidth
= 1.0;
350 ctx
->Const
.MaxLineWidthAA
= 1.0;
351 ctx
->Const
.LineWidthGranularity
= 1.0;
354 ctx
->Const
.MinLineWidth
= 1.0;
355 ctx
->Const
.MinLineWidthAA
= 1.0;
356 ctx
->Const
.MaxLineWidth
= 5.0;
357 ctx
->Const
.MaxLineWidthAA
= 5.0;
358 ctx
->Const
.LineWidthGranularity
= 0.5;
361 ctx
->Const
.MinPointSize
= 1.0;
362 ctx
->Const
.MinPointSizeAA
= 1.0;
363 ctx
->Const
.MaxPointSize
= 255.0;
364 ctx
->Const
.MaxPointSizeAA
= 3.0;
365 ctx
->Const
.PointSizeGranularity
= 1.0;
367 /* reinitialize the context point state.
368 * It depend on constants in __GLcontextRec::Const
370 _mesa_init_point(ctx
);
372 /* Initialize the software rasterizer and helper modules. */
373 _swrast_CreateContext( ctx
);
374 _ac_CreateContext( ctx
);
375 _tnl_CreateContext( ctx
);
376 _swsetup_CreateContext( ctx
);
378 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
380 /* Configure swrast to match hardware characteristics: */
381 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
382 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
385 intel
->hHWContext
= driContextPriv
->hHWContext
;
386 intel
->driFd
= sPriv
->fd
;
387 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
389 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
390 intel
->hw_stipple
= 1;
392 switch(mesaVis
->depthBits
) {
393 case 0: /* what to do in this case? */
395 intel
->depth_scale
= 1.0/0xffff;
396 intel
->polygon_offset_scale
= 1.0/0xffff;
397 intel
->depth_clear_mask
= ~0;
398 intel
->ClearDepth
= 0xffff;
401 intel
->depth_scale
= 1.0/0xffffff;
402 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
403 intel
->depth_clear_mask
= 0x00ffffff;
404 intel
->stencil_clear_mask
= 0xff000000;
405 intel
->ClearDepth
= 0x00ffffff;
412 /* Initialize swrast, tnl driver tables: */
413 intelInitSpanFuncs( ctx
);
415 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
417 if (!intel
->intelScreen
->irq_active
) {
418 _mesa_printf("IRQs not active. Exiting\n");
421 intelInitExtensions(ctx
, GL_TRUE
);
423 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
429 intel
->bm
= bm_fake_intel_Attach( intel
);
433 intel
->intelScreen
->tex
.offset
, /* low offset */
434 intel
->intelScreen
->tex
.map
, /* low virtual */
435 intel
->intelScreen
->tex
.size
,
438 /* These are still static, but create regions for them.
440 intel
->front_region
=
441 intel_region_create_static(intel
,
443 intelScreen
->front
.offset
,
444 intelScreen
->front
.map
,
446 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
448 intelScreen
->front
.tiled
!= 0); /* 0: LINEAR */
452 intel_region_create_static(intel
,
454 intelScreen
->back
.offset
,
455 intelScreen
->back
.map
,
457 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
459 intelScreen
->back
.tiled
!= 0);
461 /* Still assuming front.cpp == depth.cpp
463 * XXX: Setting tiling to false because Depth tiling only supports
464 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
467 intel
->depth_region
=
468 intel_region_create_static(intel
,
470 intelScreen
->depth
.offset
,
471 intelScreen
->depth
.map
,
473 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
475 intelScreen
->depth
.tiled
!= 0);
477 intel_bufferobj_init( intel
);
478 intel
->batch
= intel_batchbuffer_alloc( intel
);
480 if (intel
->ctx
.Mesa_DXTn
) {
481 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
482 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
484 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
485 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
488 /* driInitTextureObjects( ctx, & intel->swapped, */
489 /* DRI_TEXMGR_DO_TEXTURE_1D | */
490 /* DRI_TEXMGR_DO_TEXTURE_2D | */
491 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
494 if (getenv("INTEL_NO_RAST")) {
495 fprintf(stderr
, "disabling 3D rasterization\n");
503 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
505 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
507 assert(intel
); /* should never be null */
509 GLboolean release_texture_heaps
;
512 intel
->vtbl
.destroy( intel
);
514 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
515 _swsetup_DestroyContext (&intel
->ctx
);
516 _tnl_DestroyContext (&intel
->ctx
);
517 _ac_DestroyContext (&intel
->ctx
);
519 _swrast_DestroyContext (&intel
->ctx
);
520 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
521 intel_batchbuffer_free(intel
->batch
);
525 if ( release_texture_heaps
) {
526 /* This share group is about to go away, free our private
527 * texture object data.
530 /* XXX: destroy the shared bufmgr struct here?
534 /* Free the regions created to describe front/back/depth
538 intel_region_release(intel
, &intel
->front_region
);
539 intel_region_release(intel
, &intel
->back_region
);
540 intel_region_release(intel
, &intel
->depth_region
);
541 intel_region_release(intel
, &intel
->draw_region
);
544 /* free the Mesa context */
545 _mesa_destroy_context(&intel
->ctx
);
548 driContextPriv
->driverPrivate
= NULL
;
551 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
556 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
557 __DRIdrawablePrivate
*driDrawPriv
,
558 __DRIdrawablePrivate
*driReadPriv
)
561 if (driContextPriv
) {
562 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
564 if ( intel
->driDrawable
!= driDrawPriv
) {
565 /* Shouldn't the readbuffer be stored also? */
566 intel
->driDrawable
= driDrawPriv
;
567 intelWindowMoved( intel
);
570 _mesa_make_current(&intel
->ctx
,
571 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
572 (GLframebuffer
*) driReadPriv
->driverPrivate
);
574 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
576 _mesa_make_current(NULL
, NULL
, NULL
);
583 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
585 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
586 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
587 volatile drmI830Sarea
* sarea
= intel
->sarea
;
588 int me
= intel
->hHWContext
;
589 int my_bufmgr
= bmCtxId(intel
);
591 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
593 /* If the window moved, may need to set a new cliprect now.
595 * NOTE: This releases and regains the hw lock, so all state
596 * checking must be done *after* this call:
599 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
603 intel
->need_flush
= 1;
607 if (sarea
->ctxOwner
!= me
) {
608 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea
->ctxOwner
, me
);
609 sarea
->ctxOwner
= me
;
610 intel
->vtbl
.lost_hardware( intel
);
613 /* As above, but don't evict the texture data on transitions
614 * between contexts which all share a local buffer manager.
616 if (sarea
->texAge
!= my_bufmgr
) {
617 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea
->ctxOwner
, my_bufmgr
);
618 sarea
->texAge
= my_bufmgr
;
619 bm_fake_NotifyContendedLockTake( intel
);
624 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
625 intelWindowMoved( intel
);
626 intel
->lastStamp
= dPriv
->lastStamp
;
630 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
632 /* Lock the hardware and validate our state.
634 void LOCK_HARDWARE( struct intel_context
*intel
)
638 _glthread_LOCK_MUTEX(lockMutex
);
639 assert(!intel
->locked
);
642 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
643 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
645 intelContendedLock( intel
, 0 );
649 if (intel
->aub_wrap
) {
650 bm_fake_NotifyContendedLockTake( intel
);
651 intel
->vtbl
.lost_hardware( intel
);
652 intel
->vtbl
.aub_wrap(intel
);
656 if (bmError(intel
)) {
658 intel
->vtbl
.lost_hardware( intel
);
661 /* Make sure nothing has been emitted prior to getting the lock:
663 assert(intel
->batch
->map
== 0);
665 /* XXX: postpone, may not be needed:
667 if (!intel_batchbuffer_map(intel
->batch
)) {
669 intel
->vtbl
.lost_hardware( intel
);
671 /* This could only fail if the batchbuffer was greater in size
672 * than the available texture memory:
674 if (!intel_batchbuffer_map(intel
->batch
)) {
675 _mesa_printf("double failure to map batchbuffer\n");
682 /* Unlock the hardware using the global current context
684 void UNLOCK_HARDWARE( struct intel_context
*intel
)
686 /* Make sure everything has been released:
688 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
690 intel_batchbuffer_unmap(intel
->batch
);
691 intel
->vtbl
.note_unlock( intel
);
696 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
697 _glthread_UNLOCK_MUTEX(lockMutex
);