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"
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"; break;
111 case PCI_CHIP_I965_G
:
112 case PCI_CHIP_I965_G_1
:
113 chipset
= "Intel(R) 965G"; break;
115 case PCI_CHIP_I946_GZ
:
116 chipset
= "Intel(R) 946GZ"; break;
119 chipset
= "Unknown Intel Chipset"; break;
122 (void) driGetRendererString( buffer
, chipset
, DRIVER_VERSION
, 0 );
123 return (GLubyte
*) buffer
;
132 * Extension strings exported by the intel driver.
135 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
136 * old i830-specific driver.
138 const struct dri_extension card_extensions
[] =
140 { "GL_ARB_multisample", GL_ARB_multisample_functions
},
141 { "GL_ARB_multitexture", NULL
},
142 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions
},
143 { "GL_ARB_texture_border_clamp", NULL
},
144 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions
},
145 { "GL_ARB_texture_cube_map", NULL
},
146 { "GL_ARB_texture_env_add", NULL
},
147 { "GL_ARB_texture_env_combine", NULL
},
148 { "GL_ARB_texture_env_dot3", NULL
},
149 { "GL_ARB_texture_mirrored_repeat", NULL
},
150 { "GL_ARB_texture_non_power_of_two", NULL
},
151 { "GL_ARB_texture_rectangle", NULL
},
152 { "GL_NV_texture_rectangle", NULL
},
153 { "GL_EXT_texture_rectangle", NULL
},
154 { "GL_ARB_texture_rectangle", NULL
},
155 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions
},
156 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions
},
157 { "GL_ARB_window_pos", GL_ARB_window_pos_functions
},
158 { "GL_EXT_blend_color", GL_EXT_blend_color_functions
},
159 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions
},
160 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions
},
161 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions
},
162 { "GL_EXT_blend_logic_op", NULL
},
163 { "GL_EXT_blend_subtract", NULL
},
164 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions
},
165 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions
},
166 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions
},
167 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions
},
168 { "GL_EXT_stencil_wrap", NULL
},
169 { "GL_EXT_texture_edge_clamp", NULL
},
170 { "GL_EXT_texture_env_combine", NULL
},
171 { "GL_EXT_texture_env_dot3", NULL
},
172 { "GL_EXT_texture_filter_anisotropic", NULL
},
173 { "GL_EXT_texture_lod_bias", NULL
},
174 { "GL_3DFX_texture_compression_FXT1", NULL
},
175 { "GL_APPLE_client_storage", NULL
},
176 { "GL_MESA_pack_invert", NULL
},
177 { "GL_MESA_ycbcr_texture", NULL
},
178 { "GL_NV_blend_square", NULL
},
179 { "GL_SGIS_generate_mipmap", NULL
},
183 const struct dri_extension arb_oc_extension
=
184 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions
};
186 void intelInitExtensions(GLcontext
*ctx
, GLboolean enable_imaging
)
188 struct intel_context
*intel
= ctx
?intel_context(ctx
):NULL
;
189 driInitExtensions(ctx
, card_extensions
, enable_imaging
);
190 if (!ctx
|| intel
->intelScreen
->drmMinor
>= 8)
191 driInitSingleExtension (ctx
, &arb_oc_extension
);
194 static const struct dri_debug_control debug_control
[] =
196 { "fall", DEBUG_FALLBACKS
},
197 { "tex", DEBUG_TEXTURE
},
198 { "ioctl", DEBUG_IOCTL
},
199 { "prim", DEBUG_PRIMS
},
200 { "vert", DEBUG_VERTS
},
201 { "state", DEBUG_STATE
},
202 { "verb", DEBUG_VERBOSE
},
203 { "dri", DEBUG_DRI
},
204 { "dma", DEBUG_DMA
},
205 { "san", DEBUG_SANITY
},
206 { "sync", DEBUG_SYNC
},
207 { "sleep", DEBUG_SLEEP
},
208 { "pix", DEBUG_PIXEL
},
209 { "buf", DEBUG_BUFMGR
},
210 { "stats", DEBUG_STATS
},
211 { "tile", DEBUG_TILE
},
212 { "sing", DEBUG_SINGLE_THREAD
},
213 { "thre", DEBUG_SINGLE_THREAD
},
220 static void intelInvalidateState( GLcontext
*ctx
, GLuint new_state
)
222 struct intel_context
*intel
= intel_context(ctx
);
224 _swrast_InvalidateState( ctx
, new_state
);
225 _swsetup_InvalidateState( ctx
, new_state
);
226 _ac_InvalidateState( ctx
, new_state
);
227 _tnl_InvalidateState( ctx
, new_state
);
228 _tnl_invalidate_vertex_state( ctx
, new_state
);
230 intel
->NewGLState
|= new_state
;
232 if (intel
->vtbl
.invalidate_state
)
233 intel
->vtbl
.invalidate_state( intel
, new_state
);
237 void intelFlush( GLcontext
*ctx
)
239 struct intel_context
*intel
= intel_context( ctx
);
241 bmLockAndFence(intel
);
244 void intelFinish( GLcontext
*ctx
)
246 struct intel_context
*intel
= intel_context( ctx
);
248 bmFinishFence(intel
, bmLockAndFence(intel
));
252 intelBeginQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
254 struct intel_context
*intel
= intel_context( ctx
);
256 .read_write
= MMIO_READ
,
257 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
261 intelFinish(&intel
->ctx
);
262 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
266 intelEndQuery(GLcontext
*ctx
, GLenum target
, struct gl_query_object
*q
)
268 struct intel_context
*intel
= intel_context( ctx
);
271 .read_write
= MMIO_READ
,
272 .reg
= MMIO_REGS_PS_DEPTH_COUNT
,
275 intelFinish(&intel
->ctx
);
276 drmCommandRead(intel
->driFd
, DRM_I830_MMIO
, &io
, sizeof(io
));
277 q
->Result
= tmp
- q
->Result
;
283 void intelInitDriverFunctions( struct dd_function_table
*functions
)
285 _mesa_init_driver_functions( functions
);
287 functions
->Flush
= intelFlush
;
288 functions
->Finish
= intelFinish
;
289 functions
->GetString
= intelGetString
;
290 functions
->UpdateState
= intelInvalidateState
;
291 functions
->BeginQuery
= intelBeginQuery
;
292 functions
->EndQuery
= intelEndQuery
;
294 /* CopyPixels can be accelerated even with the current memory
297 if (!getenv("INTEL_NO_BLIT")) {
298 functions
->CopyPixels
= intelCopyPixels
;
299 functions
->Bitmap
= intelBitmap
;
302 intelInitTextureFuncs( functions
);
303 intelInitStateFuncs( functions
);
304 intelInitBufferFuncs( functions
);
309 GLboolean
intelInitContext( struct intel_context
*intel
,
310 const __GLcontextModes
*mesaVis
,
311 __DRIcontextPrivate
*driContextPriv
,
312 void *sharedContextPrivate
,
313 struct dd_function_table
*functions
)
315 GLcontext
*ctx
= &intel
->ctx
;
316 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
317 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
318 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*)sPriv
->private;
319 volatile drmI830Sarea
*saPriv
= (volatile drmI830Sarea
*)
320 (((GLubyte
*)sPriv
->pSAREA
)+intelScreen
->sarea_priv_offset
);
322 if (!_mesa_initialize_context(&intel
->ctx
,
326 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
330 driContextPriv
->driverPrivate
= intel
;
331 intel
->intelScreen
= intelScreen
;
332 intel
->driScreen
= sPriv
;
333 intel
->sarea
= saPriv
;
335 driParseConfigFiles (&intel
->optionCache
, &intelScreen
->optionCache
,
336 intel
->driScreen
->myNum
, "i965");
338 intel
->vblank_flags
= (intel
->intelScreen
->irq_active
!= 0)
339 ? driGetDefaultVBlankFlags(&intel
->optionCache
) : VBLANK_FLAG_NO_IRQ
;
341 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
343 if (getenv("INTEL_STRICT_CONFORMANCE")) {
344 intel
->strict_conformance
= 1;
347 if (intel
->strict_conformance
) {
348 ctx
->Const
.MinLineWidth
= 1.0;
349 ctx
->Const
.MinLineWidthAA
= 1.0;
350 ctx
->Const
.MaxLineWidth
= 1.0;
351 ctx
->Const
.MaxLineWidthAA
= 1.0;
352 ctx
->Const
.LineWidthGranularity
= 1.0;
355 ctx
->Const
.MinLineWidth
= 1.0;
356 ctx
->Const
.MinLineWidthAA
= 1.0;
357 ctx
->Const
.MaxLineWidth
= 5.0;
358 ctx
->Const
.MaxLineWidthAA
= 5.0;
359 ctx
->Const
.LineWidthGranularity
= 0.5;
362 ctx
->Const
.MinPointSize
= 1.0;
363 ctx
->Const
.MinPointSizeAA
= 1.0;
364 ctx
->Const
.MaxPointSize
= 255.0;
365 ctx
->Const
.MaxPointSizeAA
= 3.0;
366 ctx
->Const
.PointSizeGranularity
= 1.0;
368 /* reinitialize the context point state.
369 * It depend on constants in __GLcontextRec::Const
371 _mesa_init_point(ctx
);
373 /* Initialize the software rasterizer and helper modules. */
374 _swrast_CreateContext( ctx
);
375 _ac_CreateContext( ctx
);
376 _tnl_CreateContext( ctx
);
377 _swsetup_CreateContext( ctx
);
379 TNL_CONTEXT(ctx
)->Driver
.RunPipeline
= _tnl_run_pipeline
;
381 /* Configure swrast to match hardware characteristics: */
382 _swrast_allow_pixel_fog( ctx
, GL_FALSE
);
383 _swrast_allow_vertex_fog( ctx
, GL_TRUE
);
386 intel
->hHWContext
= driContextPriv
->hHWContext
;
387 intel
->driFd
= sPriv
->fd
;
388 intel
->driHwLock
= (drmLock
*) &sPriv
->pSAREA
->lock
;
390 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
391 intel
->hw_stipple
= 1;
393 switch(mesaVis
->depthBits
) {
394 case 0: /* what to do in this case? */
396 intel
->depth_scale
= 1.0/0xffff;
397 intel
->polygon_offset_scale
= 1.0/0xffff;
398 intel
->depth_clear_mask
= ~0;
399 intel
->ClearDepth
= 0xffff;
402 intel
->depth_scale
= 1.0/0xffffff;
403 intel
->polygon_offset_scale
= 2.0/0xffffff; /* req'd to pass glean */
404 intel
->depth_clear_mask
= 0x00ffffff;
405 intel
->stencil_clear_mask
= 0xff000000;
406 intel
->ClearDepth
= 0x00ffffff;
413 /* Initialize swrast, tnl driver tables: */
414 intelInitSpanFuncs( ctx
);
416 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
418 if (!intel
->intelScreen
->irq_active
) {
419 _mesa_printf("IRQs not active. Exiting\n");
422 intelInitExtensions(ctx
, GL_TRUE
);
424 INTEL_DEBUG
= driParseDebugString( getenv( "INTEL_DEBUG" ),
430 intel
->bm
= bm_fake_intel_Attach( intel
);
434 intel
->intelScreen
->tex
.offset
, /* low offset */
435 intel
->intelScreen
->tex
.map
, /* low virtual */
436 intel
->intelScreen
->tex
.size
,
439 /* These are still static, but create regions for them.
441 intel
->front_region
=
442 intel_region_create_static(intel
,
444 intelScreen
->front
.offset
,
445 intelScreen
->front
.map
,
447 intelScreen
->front
.pitch
/ intelScreen
->cpp
,
449 intelScreen
->front
.tiled
!= 0); /* 0: LINEAR */
453 intel_region_create_static(intel
,
455 intelScreen
->back
.offset
,
456 intelScreen
->back
.map
,
458 intelScreen
->back
.pitch
/ intelScreen
->cpp
,
460 intelScreen
->back
.tiled
!= 0);
462 /* Still assuming front.cpp == depth.cpp
464 * XXX: Setting tiling to false because Depth tiling only supports
465 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
468 intel
->depth_region
=
469 intel_region_create_static(intel
,
471 intelScreen
->depth
.offset
,
472 intelScreen
->depth
.map
,
474 intelScreen
->depth
.pitch
/ intelScreen
->cpp
,
476 intelScreen
->depth
.tiled
!= 0);
478 intel_bufferobj_init( intel
);
479 intel
->batch
= intel_batchbuffer_alloc( intel
);
481 if (intel
->ctx
.Mesa_DXTn
) {
482 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
483 _mesa_enable_extension( ctx
, "GL_S3_s3tc" );
485 else if (driQueryOptionb (&intelScreen
->optionCache
, "force_s3tc_enable")) {
486 _mesa_enable_extension( ctx
, "GL_EXT_texture_compression_s3tc" );
489 /* driInitTextureObjects( ctx, & intel->swapped, */
490 /* DRI_TEXMGR_DO_TEXTURE_1D | */
491 /* DRI_TEXMGR_DO_TEXTURE_2D | */
492 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
495 if (getenv("INTEL_NO_RAST")) {
496 fprintf(stderr
, "disabling 3D rasterization\n");
504 void intelDestroyContext(__DRIcontextPrivate
*driContextPriv
)
506 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
508 assert(intel
); /* should never be null */
510 GLboolean release_texture_heaps
;
513 intel
->vtbl
.destroy( intel
);
515 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
516 _swsetup_DestroyContext (&intel
->ctx
);
517 _tnl_DestroyContext (&intel
->ctx
);
518 _ac_DestroyContext (&intel
->ctx
);
520 _swrast_DestroyContext (&intel
->ctx
);
521 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
522 intel_batchbuffer_free(intel
->batch
);
526 if ( release_texture_heaps
) {
527 /* This share group is about to go away, free our private
528 * texture object data.
531 /* XXX: destroy the shared bufmgr struct here?
535 /* Free the regions created to describe front/back/depth
539 intel_region_release(intel
, &intel
->front_region
);
540 intel_region_release(intel
, &intel
->back_region
);
541 intel_region_release(intel
, &intel
->depth_region
);
542 intel_region_release(intel
, &intel
->draw_region
);
545 /* free the Mesa context */
546 _mesa_destroy_context(&intel
->ctx
);
549 driContextPriv
->driverPrivate
= NULL
;
552 GLboolean
intelUnbindContext(__DRIcontextPrivate
*driContextPriv
)
557 GLboolean
intelMakeCurrent(__DRIcontextPrivate
*driContextPriv
,
558 __DRIdrawablePrivate
*driDrawPriv
,
559 __DRIdrawablePrivate
*driReadPriv
)
562 if (driContextPriv
) {
563 struct intel_context
*intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
565 if ( intel
->driDrawable
!= driDrawPriv
) {
566 /* Shouldn't the readbuffer be stored also? */
567 driDrawableInitVBlank( driDrawPriv
, intel
->vblank_flags
,
570 intel
->driDrawable
= driDrawPriv
;
571 intelWindowMoved( intel
);
574 _mesa_make_current(&intel
->ctx
,
575 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
576 (GLframebuffer
*) driReadPriv
->driverPrivate
);
578 intel
->ctx
.Driver
.DrawBuffer( &intel
->ctx
, intel
->ctx
.Color
.DrawBuffer
[0] );
580 _mesa_make_current(NULL
, NULL
, NULL
);
587 static void intelContendedLock( struct intel_context
*intel
, GLuint flags
)
589 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
590 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
591 volatile drmI830Sarea
* sarea
= intel
->sarea
;
592 int me
= intel
->hHWContext
;
593 int my_bufmgr
= bmCtxId(intel
);
595 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
597 /* If the window moved, may need to set a new cliprect now.
599 * NOTE: This releases and regains the hw lock, so all state
600 * checking must be done *after* this call:
603 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
607 intel
->need_flush
= 1;
611 if (sarea
->ctxOwner
!= me
) {
612 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea
->ctxOwner
, me
);
613 sarea
->ctxOwner
= me
;
614 intel
->vtbl
.lost_hardware( intel
);
617 /* As above, but don't evict the texture data on transitions
618 * between contexts which all share a local buffer manager.
620 if (sarea
->texAge
!= my_bufmgr
) {
621 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea
->ctxOwner
, my_bufmgr
);
622 sarea
->texAge
= my_bufmgr
;
623 bm_fake_NotifyContendedLockTake( intel
);
628 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
629 intelWindowMoved( intel
);
630 intel
->lastStamp
= dPriv
->lastStamp
;
634 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
636 /* Lock the hardware and validate our state.
638 void LOCK_HARDWARE( struct intel_context
*intel
)
642 _glthread_LOCK_MUTEX(lockMutex
);
643 assert(!intel
->locked
);
646 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
647 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
649 intelContendedLock( intel
, 0 );
653 if (intel
->aub_wrap
) {
654 bm_fake_NotifyContendedLockTake( intel
);
655 intel
->vtbl
.lost_hardware( intel
);
656 intel
->vtbl
.aub_wrap(intel
);
660 if (bmError(intel
)) {
662 intel
->vtbl
.lost_hardware( intel
);
665 /* Make sure nothing has been emitted prior to getting the lock:
667 assert(intel
->batch
->map
== 0);
669 /* XXX: postpone, may not be needed:
671 if (!intel_batchbuffer_map(intel
->batch
)) {
673 intel
->vtbl
.lost_hardware( intel
);
675 /* This could only fail if the batchbuffer was greater in size
676 * than the available texture memory:
678 if (!intel_batchbuffer_map(intel
->batch
)) {
679 _mesa_printf("double failure to map batchbuffer\n");
686 /* Unlock the hardware using the global current context
688 void UNLOCK_HARDWARE( struct intel_context
*intel
)
690 /* Make sure everything has been released:
692 assert(intel
->batch
->ptr
== intel
->batch
->map
+ intel
->batch
->offset
);
694 intel_batchbuffer_unmap(intel
->batch
);
695 intel
->vtbl
.note_unlock( intel
);
700 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
701 _glthread_UNLOCK_MUTEX(lockMutex
);