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