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