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