a5d8be838653fbe535d97c3ea483e6a889eb9176
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "glheader.h"
30 #include "context.h"
31 #include "matrix.h"
32 #include "simple_list.h"
33 #include "extensions.h"
34 #include "framebuffer.h"
35 #include "imports.h"
36 #include "points.h"
37
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
40 #include "tnl/tnl.h"
41 #include "vbo/vbo.h"
42
43 #include "tnl/t_pipeline.h"
44 #include "tnl/t_vertex.h"
45
46 #include "drivers/common/driverfuncs.h"
47
48 #include "intel_screen.h"
49
50 #include "i830_dri.h"
51 #include "i830_common.h"
52
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"
60
61 #include "bufmgr.h"
62
63 #include "utils.h"
64 #include "vblank.h"
65 #ifndef INTEL_DEBUG
66 int INTEL_DEBUG = (0);
67 #endif
68
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 #define need_GL_VERSION_2_0
85 #define need_GL_VERSION_2_1
86 #define need_GL_ARB_shader_objects
87 #define need_GL_ARB_vertex_shader
88
89 #include "extension_helper.h"
90
91 #ifndef VERBOSE
92 int VERBOSE = 0;
93 #endif
94
95 /***************************************
96 * Mesa's Driver Functions
97 ***************************************/
98
99 #define DRIVER_VERSION "4.1.3002"
100
101 static const GLubyte *intelGetString( GLcontext *ctx, GLenum name )
102 {
103 const char * chipset;
104 static char buffer[128];
105
106 switch (name) {
107 case GL_VENDOR:
108 return (GLubyte *)"Tungsten Graphics, Inc";
109 break;
110
111 case GL_RENDERER:
112 switch (intel_context(ctx)->intelScreen->deviceID) {
113 case PCI_CHIP_I965_Q:
114 chipset = "Intel(R) 965Q";
115 break;
116 case PCI_CHIP_I965_G:
117 case PCI_CHIP_I965_G_1:
118 chipset = "Intel(R) 965G";
119 break;
120 case PCI_CHIP_I946_GZ:
121 chipset = "Intel(R) 946GZ";
122 break;
123 case PCI_CHIP_I965_GM:
124 chipset = "Intel(R) 965GM";
125 break;
126 case PCI_CHIP_I965_GME:
127 chipset = "Intel(R) 965GME/GLE";
128 break;
129 default:
130 chipset = "Unknown Intel Chipset";
131 }
132
133 (void) driGetRendererString( buffer, chipset, DRIVER_VERSION, 0 );
134 return (GLubyte *) buffer;
135
136 default:
137 return NULL;
138 }
139 }
140
141
142 /**
143 * Extension strings exported by the intel driver.
144 *
145 * \note
146 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
147 * old i830-specific driver.
148 */
149 const struct dri_extension card_extensions[] =
150 {
151 { "GL_ARB_multisample", GL_ARB_multisample_functions },
152 { "GL_ARB_multitexture", NULL },
153 { "GL_ARB_point_parameters", GL_ARB_point_parameters_functions },
154 { "GL_ARB_texture_border_clamp", NULL },
155 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
156 { "GL_ARB_texture_cube_map", NULL },
157 { "GL_ARB_texture_env_add", NULL },
158 { "GL_ARB_texture_env_combine", NULL },
159 { "GL_ARB_texture_env_dot3", NULL },
160 { "GL_ARB_texture_mirrored_repeat", NULL },
161 { "GL_ARB_texture_non_power_of_two", NULL },
162 { "GL_ARB_texture_rectangle", NULL },
163 { "GL_NV_texture_rectangle", NULL },
164 { "GL_EXT_texture_rectangle", NULL },
165 { "GL_ARB_texture_rectangle", NULL },
166 { "GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
167 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
168 { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
169 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
170 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
171 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
172 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
173 { "GL_EXT_blend_logic_op", NULL },
174 { "GL_EXT_blend_subtract", NULL },
175 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions },
176 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
177 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
178 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
179 { "GL_EXT_stencil_wrap", NULL },
180 { "GL_EXT_texture_edge_clamp", NULL },
181 { "GL_EXT_texture_env_combine", NULL },
182 { "GL_EXT_texture_env_dot3", NULL },
183 { "GL_EXT_texture_filter_anisotropic", NULL },
184 { "GL_EXT_texture_lod_bias", NULL },
185 { "GL_3DFX_texture_compression_FXT1", NULL },
186 { "GL_APPLE_client_storage", NULL },
187 { "GL_MESA_pack_invert", NULL },
188 { "GL_MESA_ycbcr_texture", NULL },
189 { "GL_NV_blend_square", NULL },
190 { "GL_SGIS_generate_mipmap", NULL },
191 { "GL_ARB_shading_language_100", GL_VERSION_2_0_functions},
192 { "GL_ARB_shading_language_120", GL_VERSION_2_1_functions},
193 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions},
194 { "GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions},
195 { "GL_ARB_fragment_shader", NULL },
196 /* XXX not implement yet, to compile builtin glsl lib */
197 { "GL_ARB_draw_buffers", NULL },
198 { NULL, NULL }
199 };
200
201 const struct dri_extension arb_oc_extension =
202 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions};
203
204 void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging)
205 {
206 struct intel_context *intel = ctx?intel_context(ctx):NULL;
207 driInitExtensions(ctx, card_extensions, enable_imaging);
208 if (!ctx || intel->intelScreen->drmMinor >= 8)
209 driInitSingleExtension (ctx, &arb_oc_extension);
210 }
211
212 static const struct dri_debug_control debug_control[] =
213 {
214 { "fall", DEBUG_FALLBACKS },
215 { "tex", DEBUG_TEXTURE },
216 { "ioctl", DEBUG_IOCTL },
217 { "prim", DEBUG_PRIMS },
218 { "vert", DEBUG_VERTS },
219 { "state", DEBUG_STATE },
220 { "verb", DEBUG_VERBOSE },
221 { "dri", DEBUG_DRI },
222 { "dma", DEBUG_DMA },
223 { "san", DEBUG_SANITY },
224 { "sync", DEBUG_SYNC },
225 { "sleep", DEBUG_SLEEP },
226 { "pix", DEBUG_PIXEL },
227 { "buf", DEBUG_BUFMGR },
228 { "stats", DEBUG_STATS },
229 { "tile", DEBUG_TILE },
230 { "sing", DEBUG_SINGLE_THREAD },
231 { "thre", DEBUG_SINGLE_THREAD },
232 { "wm", DEBUG_WM },
233 { "vs", DEBUG_VS },
234 { NULL, 0 }
235 };
236
237
238 static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
239 {
240 struct intel_context *intel = intel_context(ctx);
241
242 _swrast_InvalidateState( ctx, new_state );
243 _swsetup_InvalidateState( ctx, new_state );
244 _vbo_InvalidateState( ctx, new_state );
245 _tnl_InvalidateState( ctx, new_state );
246 _tnl_invalidate_vertex_state( ctx, new_state );
247
248 intel->NewGLState |= new_state;
249
250 if (intel->vtbl.invalidate_state)
251 intel->vtbl.invalidate_state( intel, new_state );
252 }
253
254
255 void intelFlush( GLcontext *ctx )
256 {
257 struct intel_context *intel = intel_context( ctx );
258
259 bmLockAndFence(intel);
260 }
261
262 void intelFinish( GLcontext *ctx )
263 {
264 struct intel_context *intel = intel_context( ctx );
265
266 bmFinishFence(intel, bmLockAndFence(intel));
267 }
268
269 static void
270 intelBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
271 {
272 struct intel_context *intel = intel_context( ctx );
273 drmI830MMIO io = {
274 .read_write = MMIO_READ,
275 .reg = MMIO_REGS_PS_DEPTH_COUNT,
276 .data = &q->Result
277 };
278 intel->stats_wm++;
279 intelFinish(&intel->ctx);
280 drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
281 }
282
283 static void
284 intelEndQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
285 {
286 struct intel_context *intel = intel_context( ctx );
287 GLuint64EXT tmp;
288 drmI830MMIO io = {
289 .read_write = MMIO_READ,
290 .reg = MMIO_REGS_PS_DEPTH_COUNT,
291 .data = &tmp
292 };
293 intelFinish(&intel->ctx);
294 drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
295 q->Result = tmp - q->Result;
296 q->Ready = GL_TRUE;
297 intel->stats_wm--;
298 }
299
300
301 void intelInitDriverFunctions( struct dd_function_table *functions )
302 {
303 _mesa_init_driver_functions( functions );
304
305 functions->Flush = intelFlush;
306 functions->Finish = intelFinish;
307 functions->GetString = intelGetString;
308 functions->UpdateState = intelInvalidateState;
309 functions->BeginQuery = intelBeginQuery;
310 functions->EndQuery = intelEndQuery;
311
312 /* CopyPixels can be accelerated even with the current memory
313 * manager:
314 */
315 if (!getenv("INTEL_NO_BLIT")) {
316 functions->CopyPixels = intelCopyPixels;
317 functions->Bitmap = intelBitmap;
318 }
319
320 intelInitTextureFuncs( functions );
321 intelInitStateFuncs( functions );
322 intelInitBufferFuncs( functions );
323 }
324
325
326
327 GLboolean intelInitContext( struct intel_context *intel,
328 const __GLcontextModes *mesaVis,
329 __DRIcontextPrivate *driContextPriv,
330 void *sharedContextPrivate,
331 struct dd_function_table *functions )
332 {
333 GLcontext *ctx = &intel->ctx;
334 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
335 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
336 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
337 volatile drmI830Sarea *saPriv = (volatile drmI830Sarea *)
338 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
339
340 if (!_mesa_initialize_context(&intel->ctx,
341 mesaVis, shareCtx,
342 functions,
343 (void*) intel)) {
344 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__);
345 return GL_FALSE;
346 }
347
348 driContextPriv->driverPrivate = intel;
349 intel->intelScreen = intelScreen;
350 intel->driScreen = sPriv;
351 intel->sarea = saPriv;
352
353 driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
354 intel->driScreen->myNum, "i965");
355
356 intel->vblank_flags = (intel->intelScreen->irq_active != 0)
357 ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
358
359 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
360
361 if (getenv("INTEL_STRICT_CONFORMANCE")) {
362 intel->strict_conformance = 1;
363 }
364
365 if (intel->strict_conformance) {
366 ctx->Const.MinLineWidth = 1.0;
367 ctx->Const.MinLineWidthAA = 1.0;
368 ctx->Const.MaxLineWidth = 1.0;
369 ctx->Const.MaxLineWidthAA = 1.0;
370 ctx->Const.LineWidthGranularity = 1.0;
371 }
372 else {
373 ctx->Const.MinLineWidth = 1.0;
374 ctx->Const.MinLineWidthAA = 1.0;
375 ctx->Const.MaxLineWidth = 5.0;
376 ctx->Const.MaxLineWidthAA = 5.0;
377 ctx->Const.LineWidthGranularity = 0.5;
378 }
379
380 ctx->Const.MinPointSize = 1.0;
381 ctx->Const.MinPointSizeAA = 1.0;
382 ctx->Const.MaxPointSize = 255.0;
383 ctx->Const.MaxPointSizeAA = 3.0;
384 ctx->Const.PointSizeGranularity = 1.0;
385
386 /* reinitialize the context point state.
387 * It depend on constants in __GLcontextRec::Const
388 */
389 _mesa_init_point(ctx);
390
391 /* Initialize the software rasterizer and helper modules. */
392 _swrast_CreateContext( ctx );
393 _vbo_CreateContext( ctx );
394 _tnl_CreateContext( ctx );
395 _swsetup_CreateContext( ctx );
396
397 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
398
399 /* Configure swrast to match hardware characteristics: */
400 _swrast_allow_pixel_fog( ctx, GL_FALSE );
401 _swrast_allow_vertex_fog( ctx, GL_TRUE );
402
403 /* Dri stuff */
404 intel->hHWContext = driContextPriv->hHWContext;
405 intel->driFd = sPriv->fd;
406 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
407
408 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
409 intel->hw_stipple = 1;
410
411 switch(mesaVis->depthBits) {
412 case 0: /* what to do in this case? */
413 case 16:
414 intel->depth_scale = 1.0/0xffff;
415 intel->polygon_offset_scale = 1.0/0xffff;
416 intel->depth_clear_mask = ~0;
417 intel->ClearDepth = 0xffff;
418 break;
419 case 24:
420 intel->depth_scale = 1.0/0xffffff;
421 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
422 intel->depth_clear_mask = 0x00ffffff;
423 intel->stencil_clear_mask = 0xff000000;
424 intel->ClearDepth = 0x00ffffff;
425 break;
426 default:
427 assert(0);
428 break;
429 }
430
431 /* Initialize swrast, tnl driver tables: */
432 intelInitSpanFuncs( ctx );
433
434 intel->no_hw = getenv("INTEL_NO_HW") != NULL;
435
436 if (!intel->intelScreen->irq_active) {
437 _mesa_printf("IRQs not active. Exiting\n");
438 exit(1);
439 }
440 intelInitExtensions(ctx, GL_TRUE);
441
442 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
443 debug_control );
444
445
446 /* Buffer manager:
447 */
448 intel->bm = bm_fake_intel_Attach( intel );
449
450
451 bmInitPool(intel,
452 intel->intelScreen->tex.offset, /* low offset */
453 intel->intelScreen->tex.map, /* low virtual */
454 intel->intelScreen->tex.size,
455 BM_MEM_AGP);
456
457 /* These are still static, but create regions for them.
458 */
459 intel->front_region =
460 intel_region_create_static(intel,
461 BM_MEM_AGP,
462 intelScreen->front.offset,
463 intelScreen->front.map,
464 intelScreen->cpp,
465 intelScreen->front.pitch / intelScreen->cpp,
466 intelScreen->height,
467 intelScreen->front.size,
468 intelScreen->front.tiled != 0);
469
470 intel->back_region =
471 intel_region_create_static(intel,
472 BM_MEM_AGP,
473 intelScreen->back.offset,
474 intelScreen->back.map,
475 intelScreen->cpp,
476 intelScreen->back.pitch / intelScreen->cpp,
477 intelScreen->height,
478 intelScreen->back.size,
479 intelScreen->back.tiled != 0);
480
481 /* Still assuming front.cpp == depth.cpp
482 *
483 * XXX: Setting tiling to false because Depth tiling only supports
484 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
485 * resolve later.
486 */
487 intel->depth_region =
488 intel_region_create_static(intel,
489 BM_MEM_AGP,
490 intelScreen->depth.offset,
491 intelScreen->depth.map,
492 intelScreen->cpp,
493 intelScreen->depth.pitch / intelScreen->cpp,
494 intelScreen->height,
495 intelScreen->depth.size,
496 intelScreen->depth.tiled != 0);
497
498 intel_bufferobj_init( intel );
499 intel->batch = intel_batchbuffer_alloc( intel );
500
501 if (intel->ctx.Mesa_DXTn) {
502 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
503 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
504 }
505 else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) {
506 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
507 }
508
509 /* driInitTextureObjects( ctx, & intel->swapped, */
510 /* DRI_TEXMGR_DO_TEXTURE_1D | */
511 /* DRI_TEXMGR_DO_TEXTURE_2D | */
512 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
513
514
515 if (getenv("INTEL_NO_RAST")) {
516 fprintf(stderr, "disabling 3D rasterization\n");
517 intel->no_rast = 1;
518 }
519
520
521 return GL_TRUE;
522 }
523
524 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
525 {
526 struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
527
528 assert(intel); /* should never be null */
529 if (intel) {
530 GLboolean release_texture_heaps;
531
532
533 intel->vtbl.destroy( intel );
534
535 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
536 _swsetup_DestroyContext (&intel->ctx);
537 _tnl_DestroyContext (&intel->ctx);
538 _vbo_DestroyContext (&intel->ctx);
539
540 _swrast_DestroyContext (&intel->ctx);
541 intel->Fallback = 0; /* don't call _swrast_Flush later */
542 intel_batchbuffer_free(intel->batch);
543 intel->batch = NULL;
544
545
546 if ( release_texture_heaps ) {
547 /* This share group is about to go away, free our private
548 * texture object data.
549 */
550
551 /* XXX: destroy the shared bufmgr struct here?
552 */
553 }
554
555 /* Free the regions created to describe front/back/depth
556 * buffers:
557 */
558 #if 0
559 intel_region_release(intel, &intel->front_region);
560 intel_region_release(intel, &intel->back_region);
561 intel_region_release(intel, &intel->depth_region);
562 intel_region_release(intel, &intel->draw_region);
563 #endif
564
565 /* free the Mesa context */
566 intel->ctx.VertexProgram.Current = NULL;
567 intel->ctx.FragmentProgram.Current = NULL;
568 _mesa_destroy_context(&intel->ctx);
569 }
570
571 driContextPriv->driverPrivate = NULL;
572 }
573
574 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
575 {
576 return GL_TRUE;
577 }
578
579 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
580 __DRIdrawablePrivate *driDrawPriv,
581 __DRIdrawablePrivate *driReadPriv)
582 {
583
584 if (driContextPriv) {
585 struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
586
587 if ( intel->driDrawable != driDrawPriv ) {
588 /* Shouldn't the readbuffer be stored also? */
589 driDrawableInitVBlank( driDrawPriv, intel->vblank_flags,
590 &intel->vbl_seq );
591
592 intel->driDrawable = driDrawPriv;
593 intelWindowMoved( intel );
594 }
595
596 _mesa_make_current(&intel->ctx,
597 (GLframebuffer *) driDrawPriv->driverPrivate,
598 (GLframebuffer *) driReadPriv->driverPrivate);
599
600 intel->ctx.Driver.DrawBuffer( &intel->ctx, intel->ctx.Color.DrawBuffer[0] );
601 } else {
602 _mesa_make_current(NULL, NULL, NULL);
603 }
604
605 return GL_TRUE;
606 }
607
608
609 static void intelContendedLock( struct intel_context *intel, GLuint flags )
610 {
611 __DRIdrawablePrivate *dPriv = intel->driDrawable;
612 __DRIscreenPrivate *sPriv = intel->driScreen;
613 volatile drmI830Sarea * sarea = intel->sarea;
614 int me = intel->hHWContext;
615 int my_bufmgr = bmCtxId(intel);
616
617 drmGetLock(intel->driFd, intel->hHWContext, flags);
618
619 /* If the window moved, may need to set a new cliprect now.
620 *
621 * NOTE: This releases and regains the hw lock, so all state
622 * checking must be done *after* this call:
623 */
624 if (dPriv)
625 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
626
627
628 intel->locked = 1;
629 intel->need_flush = 1;
630
631 /* Lost context?
632 */
633 if (sarea->ctxOwner != me) {
634 DBG("Lost Context: sarea->ctxOwner %x me %x\n", sarea->ctxOwner, me);
635 sarea->ctxOwner = me;
636 intel->vtbl.lost_hardware( intel );
637 }
638
639 /* As above, but don't evict the texture data on transitions
640 * between contexts which all share a local buffer manager.
641 */
642 if (sarea->texAge != my_bufmgr) {
643 DBG("Lost Textures: sarea->texAge %x my_bufmgr %x\n", sarea->ctxOwner, my_bufmgr);
644 sarea->texAge = my_bufmgr;
645 bm_fake_NotifyContendedLockTake( intel );
646 }
647
648 /* Drawable changed?
649 */
650 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
651 intelWindowMoved( intel );
652 intel->lastStamp = dPriv->lastStamp;
653 }
654 }
655
656 _glthread_DECLARE_STATIC_MUTEX(lockMutex);
657
658 /* Lock the hardware and validate our state.
659 */
660 void LOCK_HARDWARE( struct intel_context *intel )
661 {
662 char __ret=0;
663
664 _glthread_LOCK_MUTEX(lockMutex);
665 assert(!intel->locked);
666
667
668 DRM_CAS(intel->driHwLock, intel->hHWContext,
669 (DRM_LOCK_HELD|intel->hHWContext), __ret);
670 if (__ret)
671 intelContendedLock( intel, 0 );
672
673 intel->locked = 1;
674
675 if (intel->aub_wrap) {
676 bm_fake_NotifyContendedLockTake( intel );
677 intel->vtbl.lost_hardware( intel );
678 intel->vtbl.aub_wrap(intel);
679 intel->aub_wrap = 0;
680 }
681
682 if (bmError(intel)) {
683 bmEvictAll(intel);
684 intel->vtbl.lost_hardware( intel );
685 }
686
687 /* Make sure nothing has been emitted prior to getting the lock:
688 */
689 assert(intel->batch->map == 0);
690
691 /* XXX: postpone, may not be needed:
692 */
693 if (!intel_batchbuffer_map(intel->batch)) {
694 bmEvictAll(intel);
695 intel->vtbl.lost_hardware( intel );
696
697 /* This could only fail if the batchbuffer was greater in size
698 * than the available texture memory:
699 */
700 if (!intel_batchbuffer_map(intel->batch)) {
701 _mesa_printf("double failure to map batchbuffer\n");
702 assert(0);
703 }
704 }
705 }
706
707
708 /* Unlock the hardware using the global current context
709 */
710 void UNLOCK_HARDWARE( struct intel_context *intel )
711 {
712 /* Make sure everything has been released:
713 */
714 assert(intel->batch->ptr == intel->batch->map + intel->batch->offset);
715
716 intel_batchbuffer_unmap(intel->batch);
717 intel->vtbl.note_unlock( intel );
718 intel->locked = 0;
719
720
721
722 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
723 _glthread_UNLOCK_MUTEX(lockMutex);
724 }
725
726