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