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