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