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"
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"
66 int INTEL_DEBUG
= (0);
69 #define need_GL_ARB_multisample
70 #define need_GL_ARB_point_parameters
71 #define need_GL_ARB_texture_compression
72 #define need_GL_ARB_vertex_buffer_object
73 #define need_GL_ARB_vertex_program
74 #define need_GL_ARB_window_pos
75 #define need_GL_ARB_occlusion_query
76 #define need_GL_EXT_blend_color
77 #define need_GL_EXT_blend_equation_separate
78 #define need_GL_EXT_blend_func_separate
79 #define need_GL_EXT_blend_minmax
80 #define need_GL_EXT_cull_vertex
81 #define need_GL_EXT_fog_coord
82 #define need_GL_EXT_multi_draw_arrays
83 #define need_GL_EXT_secondary_color
84 #include "extension_helper.h"
90 /***************************************
91 * Mesa's Driver Functions
92 ***************************************/
94 #define DRIVER_VERSION "4.1.3002"
96 static const GLubyte
*intelGetString( GLcontext
*ctx
, GLenum name
)
99 static char buffer
[128];
103 return (GLubyte
*)"Tungsten Graphics, Inc";
107 switch (intel_context(ctx
)->intelScreen
->deviceID
) {
108 case PCI_CHIP_I965_Q
:
109 chipset
= "Intel(R) 965Q";
111 case PCI_CHIP_I965_G
:
112 case PCI_CHIP_I965_G_1
:
113 chipset
= "Intel(R) 965G";
115 case PCI_CHIP_I946_GZ
:
116 chipset
= "Intel(R) 946GZ";
118 case PCI_CHIP_I965_GM
:
119 chipset
= "Intel(R) 965GM";
121 case PCI_CHIP_I965_GME
:
122 chipset
= "Intel(R) 965GME/GLE";
125 chipset
= "Unknown Intel Chipset";
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_EXT_blend_color", GL_EXT_blend_color_functions
},
165 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
166 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
167 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
168 { "GL_EXT_blend_logic_op", NULL
},
169 { "GL_EXT_blend_subtract", NULL
},
170 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
171 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
172 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
173 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
174 { "GL_EXT_stencil_wrap", NULL
},
175 { "GL_EXT_texture_edge_clamp", NULL
},
176 { "GL_EXT_texture_env_combine", NULL
},
177 { "GL_EXT_texture_env_dot3", NULL
},
178 { "GL_EXT_texture_filter_anisotropic", NULL
},
179 { "GL_EXT_texture_lod_bias", NULL
},
180 { "GL_3DFX_texture_compression_FXT1", NULL
},
181 { "GL_APPLE_client_storage", NULL
},
182 { "GL_MESA_pack_invert", NULL
},
183 { "GL_MESA_ycbcr_texture", NULL
},
184 { "GL_NV_blend_square", NULL
},
185 { "GL_SGIS_generate_mipmap", NULL
},
189 const struct dri_extension arb_oc_extension
=
190 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
};
192 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
)
194 struct intel_context
*intel
= ctx
?intel_context(ctx
):NULL
;
195 driInitExtensions(ctx
, card_extensions
, enable_imaging
);
196 if (!ctx
|| intel
->intelScreen
->drmMinor
>= 8)
197 driInitSingleExtension (ctx
, &arb_oc_extension
);
200 static const struct dri_debug_control debug_control
[] =
202 { "fall", DEBUG_FALLBACKS
},
203 { "tex", DEBUG_TEXTURE
},
204 { "ioctl", DEBUG_IOCTL
},
205 { "prim", DEBUG_PRIMS
},
206 { "vert", DEBUG_VERTS
},
207 { "state", DEBUG_STATE
},
208 { "verb", DEBUG_VERBOSE
},
209 { "dri", DEBUG_DRI
},
210 { "dma", DEBUG_DMA
},
211 { "san", DEBUG_SANITY
},
212 { "sync", DEBUG_SYNC
},
213 { "sleep", DEBUG_SLEEP
},
214 { "pix", DEBUG_PIXEL
},
215 { "buf", DEBUG_BUFMGR
},
216 { "stats", DEBUG_STATS
},
217 { "tile", DEBUG_TILE
},
218 { "sing", DEBUG_SINGLE_THREAD
},
219 { "thre", DEBUG_SINGLE_THREAD
},
226 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
228 struct intel_context
*intel
= intel_context(ctx
);
230 _swrast_InvalidateState( ctx
, new_state
);
231 _swsetup_InvalidateState( ctx
, new_state
);
232 _vbo_InvalidateState( ctx
, new_state
);
233 _tnl_InvalidateState( ctx
, new_state
);
234 _tnl_invalidate_vertex_state( ctx
, new_state
);
236 intel
->NewGLState
|= new_state
;
238 if (intel
->vtbl
.invalidate_state
)
239 intel
->vtbl
.invalidate_state( intel
, new_state
);
243 void intelFlush( GLcontext
*ctx
)
245 struct intel_context
*intel
= intel_context( ctx
);
247 bmLockAndFence(intel
);
250 void intelFinish( GLcontext
*ctx
)
252 struct intel_context
*intel
= intel_context( ctx
);
254 bmFinishFence(intel
, bmLockAndFence(intel
));
258 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
260 struct intel_context
*intel
= intel_context( ctx
);
262 .read_write
= MMIO_READ
,
263 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
267 intelFinish(&intel
->ctx
);
268 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
272 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
274 struct intel_context
*intel
= intel_context( ctx
);
277 .read_write
= MMIO_READ
,
278 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
281 intelFinish(&intel
->ctx
);
282 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
283 q
->Result
= tmp
- q
->Result
;
289 void intelInitDriverFunctions( struct dd_function_table
*functions
)
291 _mesa_init_driver_functions( functions
);
293 functions
->Flush
= intelFlush
;
294 functions
->Finish
= intelFinish
;
295 functions
->GetString
= intelGetString
;
296 functions
->UpdateState
= intelInvalidateState
;
297 functions
->BeginQuery
= intelBeginQuery
;
298 functions
->EndQuery
= intelEndQuery
;
300 /* CopyPixels can be accelerated even with the current memory
303 if (!getenv("INTEL_NO_BLIT")) {
304 functions
->CopyPixels
= intelCopyPixels
;
305 functions
->Bitmap
= intelBitmap
;
308 intelInitTextureFuncs( functions
);
309 intelInitStateFuncs( functions
);
310 intelInitBufferFuncs( functions
);
315 GLboolean
intelInitContext( struct intel_context
*intel
,
316 const __GLcontextModes
*mesaVis
,
317 __DRIcontextPrivate
*driContextPriv
,
318 void *sharedContextPrivate
,
319 struct dd_function_table
*functions
)
321 GLcontext
*ctx
= &intel
->ctx
;
322 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
323 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
324 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
325 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
326 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
328 if (!_mesa_initialize_context(&intel
->ctx
,
332 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
336 driContextPriv
->driverPrivate
= intel
;
337 intel
->intelScreen
= intelScreen
;
338 intel
->driScreen
= sPriv
;
339 intel
->sarea
= saPriv
;
341 driParseConfigFiles (&intel
->optionCache
, &intelScreen
->optionCache
,
342 intel
->driScreen
->myNum
, "i965");
344 intel
->vblank_flags
= (intel
->intelScreen
->irq_active
!= 0)
345 ? driGetDefaultVBlankFlags(&intel
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
347 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
349 if (getenv("INTEL_STRICT_CONFORMANCE")) {
350 intel
->strict_conformance
= 1;
353 if (intel
->strict_conformance
) {
354 ctx
->Const
.MinLineWidth
= 1.0;
355 ctx
->Const
.MinLineWidthAA
= 1.0;
356 ctx
->Const
.MaxLineWidth
= 1.0;
357 ctx
->Const
.MaxLineWidthAA
= 1.0;
358 ctx
->Const
.LineWidthGranularity
= 1.0;
361 ctx
->Const
.MinLineWidth
= 1.0;
362 ctx
->Const
.MinLineWidthAA
= 1.0;
363 ctx
->Const
.MaxLineWidth
= 5.0;
364 ctx
->Const
.MaxLineWidthAA
= 5.0;
365 ctx
->Const
.LineWidthGranularity
= 0.5;
368 ctx
->Const
.MinPointSize
= 1.0;
369 ctx
->Const
.MinPointSizeAA
= 1.0;
370 ctx
->Const
.MaxPointSize
= 255.0;
371 ctx
->Const
.MaxPointSizeAA
= 3.0;
372 ctx
->Const
.PointSizeGranularity
= 1.0;
374 /* reinitialize the context point state.
375 * It depend on constants in __GLcontextRec::Const
377 _mesa_init_point(ctx
);
379 /* Initialize the software rasterizer and helper modules. */
380 _swrast_CreateContext( ctx
);
381 _vbo_CreateContext( ctx
);
382 _tnl_CreateContext( ctx
);
383 _swsetup_CreateContext( ctx
);
385 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
387 /* Configure swrast to match hardware characteristics: */
388 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
389 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
392 intel
->hHWContext
= driContextPriv
->hHWContext
;
393 intel
->driFd
= sPriv
->fd
;
394 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
396 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
397 intel
->hw_stipple
= 1;
399 switch(mesaVis
->depthBits
) {
400 case 0: /* what to do in this case? */
402 intel
->depth_scale
= 1.0/0xffff;
403 intel
->polygon_offset_scale
= 1.0/0xffff;
404 intel
->depth_clear_mask
= ~0;
405 intel
->ClearDepth
= 0xffff;
408 intel
->depth_scale
= 1.0/0xffffff;
409 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
410 intel
->depth_clear_mask
= 0x00ffffff;
411 intel
->stencil_clear_mask
= 0xff000000;
412 intel
->ClearDepth
= 0x00ffffff;
419 /* Initialize swrast, tnl driver tables: */
420 intelInitSpanFuncs( ctx
);
422 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
424 if (!intel
->intelScreen
->irq_active
) {
425 _mesa_printf("IRQs not active. Exiting\n");
428 intelInitExtensions(ctx
, GL_TRUE
);
430 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
436 intel
->bm
= bm_fake_intel_Attach( intel
);
440 intel
->intelScreen
->tex
.offset
, /* low offset */
441 intel
->intelScreen
->tex
.map
, /* low virtual */
442 intel
->intelScreen
->tex
.size
,
445 /* These are still static, but create regions for them.
447 intel
->front_region
=
448 intel_region_create_static(intel
,
450 intelScreen
->front
.offset
,
451 intelScreen
->front
.map
,
453 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
455 intelScreen
->front
.size
,
456 intelScreen
->front
.tiled
!= 0);
459 intel_region_create_static(intel
,
461 intelScreen
->back
.offset
,
462 intelScreen
->back
.map
,
464 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
466 intelScreen
->back
.size
,
467 intelScreen
->back
.tiled
!= 0);
469 /* Still assuming front.cpp == depth.cpp
471 * XXX: Setting tiling to false because Depth tiling only supports
472 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
475 intel
->depth_region
=
476 intel_region_create_static(intel
,
478 intelScreen
->depth
.offset
,
479 intelScreen
->depth
.map
,
481 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
483 intelScreen
->depth
.size
,
484 intelScreen
->depth
.tiled
!= 0);
486 intel_bufferobj_init( intel
);
487 intel
->batch
= intel_batchbuffer_alloc( intel
);
489 if (intel
->ctx
.Mesa_DXTn
) {
490 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
491 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
493 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
494 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
497 /* driInitTextureObjects( ctx, & intel->swapped, */
498 /* DRI_TEXMGR_DO_TEXTURE_1D | */
499 /* DRI_TEXMGR_DO_TEXTURE_2D | */
500 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
503 if (getenv("INTEL_NO_RAST")) {
504 fprintf(stderr
, "disabling 3D rasterization\n");
512 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
514 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
516 assert(intel
); /* should never be null */
518 GLboolean release_texture_heaps
;
521 intel
->vtbl
.destroy( intel
);
523 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
524 _swsetup_DestroyContext (&intel
->ctx
);
525 _tnl_DestroyContext (&intel
->ctx
);
526 _vbo_DestroyContext (&intel
->ctx
);
528 _swrast_DestroyContext (&intel
->ctx
);
529 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
530 intel_batchbuffer_free(intel
->batch
);
534 if ( release_texture_heaps
) {
535 /* This share group is about to go away, free our private
536 * texture object data.
539 /* XXX: destroy the shared bufmgr struct here?
543 /* Free the regions created to describe front/back/depth
547 intel_region_release(intel
, &intel
->front_region
);
548 intel_region_release(intel
, &intel
->back_region
);
549 intel_region_release(intel
, &intel
->depth_region
);
550 intel_region_release(intel
, &intel
->draw_region
);
553 /* free the Mesa context */
554 _mesa_destroy_context(&intel
->ctx
);
557 driContextPriv
->driverPrivate
= NULL
;
560 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
565 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
566 __DRIdrawablePrivate
*driDrawPriv
,
567 __DRIdrawablePrivate
*driReadPriv
)
570 if (driContextPriv
) {
571 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
573 if ( intel
->driDrawable
!= driDrawPriv
) {
574 /* Shouldn't the readbuffer be stored also? */
575 driDrawableInitVBlank( driDrawPriv
, intel
->vblank_flags
,
578 intel
->driDrawable
= driDrawPriv
;
579 intelWindowMoved( intel
);
582 _mesa_make_current(&intel
->ctx
,
583 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
584 (GLframebuffer
*) driReadPriv
->driverPrivate
);
586 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
588 _mesa_make_current(NULL
, NULL
, NULL
);
595 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
597 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
598 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
599 volatile drmI830Sarea
* sarea
= intel
->sarea
;
600 int me
= intel
->hHWContext
;
601 int my_bufmgr
= bmCtxId(intel
);
603 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
605 /* If the window moved, may need to set a new cliprect now.
607 * NOTE: This releases and regains the hw lock, so all state
608 * checking must be done *after* this call:
611 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
615 intel
->need_flush
= 1;
619 if (sarea
->ctxOwner
!= me
) {
620 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea
->ctxOwner
, me
);
621 sarea
->ctxOwner
= me
;
622 intel
->vtbl
.lost_hardware( intel
);
625 /* As above, but don't evict the texture data on transitions
626 * between contexts which all share a local buffer manager.
628 if (sarea
->texAge
!= my_bufmgr
) {
629 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea
->ctxOwner
, my_bufmgr
);
630 sarea
->texAge
= my_bufmgr
;
631 bm_fake_NotifyContendedLockTake( intel
);
636 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
637 intelWindowMoved( intel
);
638 intel
->lastStamp
= dPriv
->lastStamp
;
642 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
644 /* Lock the hardware and validate our state.
646 void LOCK_HARDWARE( struct intel_context
*intel
)
650 _glthread_LOCK_MUTEX(lockMutex
);
651 assert(!intel
->locked
);
654 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
655 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
657 intelContendedLock( intel
, 0 );
661 if (intel
->aub_wrap
) {
662 bm_fake_NotifyContendedLockTake( intel
);
663 intel
->vtbl
.lost_hardware( intel
);
664 intel
->vtbl
.aub_wrap(intel
);
668 if (bmError(intel
)) {
670 intel
->vtbl
.lost_hardware( intel
);
673 /* Make sure nothing has been emitted prior to getting the lock:
675 assert(intel
->batch
->map
== 0);
677 /* XXX: postpone, may not be needed:
679 if (!intel_batchbuffer_map(intel
->batch
)) {
681 intel
->vtbl
.lost_hardware( intel
);
683 /* This could only fail if the batchbuffer was greater in size
684 * than the available texture memory:
686 if (!intel_batchbuffer_map(intel
->batch
)) {
687 _mesa_printf("double failure to map batchbuffer\n");
694 /* Unlock the hardware using the global current context
696 void UNLOCK_HARDWARE( struct intel_context
*intel
)
698 /* Make sure everything has been released:
700 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
702 intel_batchbuffer_unmap(intel
->batch
);
703 intel
->vtbl
.note_unlock( intel
);
708 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
709 _glthread_UNLOCK_MUTEX(lockMutex
);