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