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