ARB_shader_object ARB_vertex_shader ARB_fragment_shader in 965-glsl branch
[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 #define need_GL_VERSION_2_0
85 #define need_GL_ARB_shader_objects
86 #define need_GL_ARB_vertex_shader
87
88 #include "extension_helper.h"
89
90 #ifndef VERBOSE
91 int VERBOSE = 0;
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";
114 break;
115 case PCI_CHIP_I965_G:
116 case PCI_CHIP_I965_G_1:
117 chipset = "Intel(R) 965G";
118 break;
119 case PCI_CHIP_I946_GZ:
120 chipset = "Intel(R) 946GZ";
121 break;
122 case PCI_CHIP_I965_GM:
123 chipset = "Intel(R) 965GM";
124 break;
125 case PCI_CHIP_I965_GME:
126 chipset = "Intel(R) 965GME/GLE";
127 break;
128 default:
129 chipset = "Unknown Intel Chipset";
130 }
131
132 (void) driGetRendererString( buffer, chipset, DRIVER_VERSION, 0 );
133 return (GLubyte *) buffer;
134
135 default:
136 return NULL;
137 }
138 }
139
140
141 /**
142 * Extension strings exported by the intel driver.
143 *
144 * \note
145 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
146 * old i830-specific driver.
147 */
148 const struct dri_extension card_extensions[] =
149 {
150 { "GL_ARB_multisample", GL_ARB_multisample_functions },
151 { "GL_ARB_multitexture", NULL },
152 { "GL_ARB_point_parameters", GL_ARB_point_parameters_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_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions },
166 { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions },
167 { "GL_ARB_window_pos", GL_ARB_window_pos_functions },
168 { "GL_EXT_blend_color", GL_EXT_blend_color_functions },
169 { "GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions },
170 { "GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions },
171 { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions },
172 { "GL_EXT_blend_logic_op", NULL },
173 { "GL_EXT_blend_subtract", NULL },
174 { "GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions },
175 { "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },
176 { "GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions },
177 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
178 { "GL_EXT_stencil_wrap", NULL },
179 { "GL_EXT_texture_edge_clamp", NULL },
180 { "GL_EXT_texture_env_combine", NULL },
181 { "GL_EXT_texture_env_dot3", NULL },
182 { "GL_EXT_texture_filter_anisotropic", NULL },
183 { "GL_EXT_texture_lod_bias", NULL },
184 { "GL_3DFX_texture_compression_FXT1", NULL },
185 { "GL_APPLE_client_storage", NULL },
186 { "GL_MESA_pack_invert", NULL },
187 { "GL_MESA_ycbcr_texture", NULL },
188 { "GL_NV_blend_square", NULL },
189 { "GL_SGIS_generate_mipmap", NULL },
190 { "GL_ARB_shading_language_100", GL_VERSION_2_0_functions},
191 { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions},
192 { "GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions},
193 { "GL_ARB_fragment_shader", NULL },
194 /* XXX not implement yet, to compile builtin glsl lib */
195 { "GL_ARB_draw_buffers", NULL },
196 { NULL, NULL }
197 };
198
199 const struct dri_extension arb_oc_extension =
200 { "GL_ARB_occlusion_query", GL_ARB_occlusion_query_functions};
201
202 void intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging)
203 {
204 struct intel_context *intel = ctx?intel_context(ctx):NULL;
205 driInitExtensions(ctx, card_extensions, enable_imaging);
206 if (!ctx || intel->intelScreen->drmMinor >= 8)
207 driInitSingleExtension (ctx, &arb_oc_extension);
208 }
209
210 static const struct dri_debug_control debug_control[] =
211 {
212 { "fall", DEBUG_FALLBACKS },
213 { "tex", DEBUG_TEXTURE },
214 { "ioctl", DEBUG_IOCTL },
215 { "prim", DEBUG_PRIMS },
216 { "vert", DEBUG_VERTS },
217 { "state", DEBUG_STATE },
218 { "verb", DEBUG_VERBOSE },
219 { "dri", DEBUG_DRI },
220 { "dma", DEBUG_DMA },
221 { "san", DEBUG_SANITY },
222 { "sync", DEBUG_SYNC },
223 { "sleep", DEBUG_SLEEP },
224 { "pix", DEBUG_PIXEL },
225 { "buf", DEBUG_BUFMGR },
226 { "stats", DEBUG_STATS },
227 { "tile", DEBUG_TILE },
228 { "sing", DEBUG_SINGLE_THREAD },
229 { "thre", DEBUG_SINGLE_THREAD },
230 { "wm", DEBUG_WM },
231 { "vs", DEBUG_VS },
232 { NULL, 0 }
233 };
234
235
236 static void intelInvalidateState( GLcontext *ctx, GLuint new_state )
237 {
238 struct intel_context *intel = intel_context(ctx);
239
240 _swrast_InvalidateState( ctx, new_state );
241 _swsetup_InvalidateState( ctx, new_state );
242 _vbo_InvalidateState( ctx, new_state );
243 _tnl_InvalidateState( ctx, new_state );
244 _tnl_invalidate_vertex_state( ctx, new_state );
245
246 intel->NewGLState |= new_state;
247
248 if (intel->vtbl.invalidate_state)
249 intel->vtbl.invalidate_state( intel, new_state );
250 }
251
252
253 void intelFlush( GLcontext *ctx )
254 {
255 struct intel_context *intel = intel_context( ctx );
256
257 bmLockAndFence(intel);
258 }
259
260 void intelFinish( GLcontext *ctx )
261 {
262 struct intel_context *intel = intel_context( ctx );
263
264 bmFinishFence(intel, bmLockAndFence(intel));
265 }
266
267 static void
268 intelBeginQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
269 {
270 struct intel_context *intel = intel_context( ctx );
271 drmI830MMIO io = {
272 .read_write = MMIO_READ,
273 .reg = MMIO_REGS_PS_DEPTH_COUNT,
274 .data = &q->Result
275 };
276 intel->stats_wm++;
277 intelFinish(&intel->ctx);
278 drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
279 }
280
281 static void
282 intelEndQuery(GLcontext *ctx, GLenum target, struct gl_query_object *q)
283 {
284 struct intel_context *intel = intel_context( ctx );
285 GLuint64EXT tmp;
286 drmI830MMIO io = {
287 .read_write = MMIO_READ,
288 .reg = MMIO_REGS_PS_DEPTH_COUNT,
289 .data = &tmp
290 };
291 intelFinish(&intel->ctx);
292 drmCommandRead(intel->driFd, DRM_I830_MMIO, &io, sizeof(io));
293 q->Result = tmp - q->Result;
294 q->Ready = GL_TRUE;
295 intel->stats_wm--;
296 }
297
298
299 void intelInitDriverFunctions( struct dd_function_table *functions )
300 {
301 _mesa_init_driver_functions( functions );
302
303 functions->Flush = intelFlush;
304 functions->Finish = intelFinish;
305 functions->GetString = intelGetString;
306 functions->UpdateState = intelInvalidateState;
307 functions->BeginQuery = intelBeginQuery;
308 functions->EndQuery = intelEndQuery;
309
310 /* CopyPixels can be accelerated even with the current memory
311 * manager:
312 */
313 if (!getenv("INTEL_NO_BLIT")) {
314 functions->CopyPixels = intelCopyPixels;
315 functions->Bitmap = intelBitmap;
316 }
317
318 intelInitTextureFuncs( functions );
319 intelInitStateFuncs( functions );
320 intelInitBufferFuncs( functions );
321 }
322
323
324
325 GLboolean intelInitContext( struct intel_context *intel,
326 const __GLcontextModes *mesaVis,
327 __DRIcontextPrivate *driContextPriv,
328 void *sharedContextPrivate,
329 struct dd_function_table *functions )
330 {
331 GLcontext *ctx = &intel->ctx;
332 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
333 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
334 intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private;
335 volatile drmI830Sarea *saPriv = (volatile drmI830Sarea *)
336 (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset);
337
338 if (!_mesa_initialize_context(&intel->ctx,
339 mesaVis, shareCtx,
340 functions,
341 (void*) intel)) {
342 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__);
343 return GL_FALSE;
344 }
345
346 driContextPriv->driverPrivate = intel;
347 intel->intelScreen = intelScreen;
348 intel->driScreen = sPriv;
349 intel->sarea = saPriv;
350
351 driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache,
352 intel->driScreen->myNum, "i965");
353
354 intel->vblank_flags = (intel->intelScreen->irq_active != 0)
355 ? driGetDefaultVBlankFlags(&intel->optionCache) : VBLANK_FLAG_NO_IRQ;
356
357 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
358
359 if (getenv("INTEL_STRICT_CONFORMANCE")) {
360 intel->strict_conformance = 1;
361 }
362
363 if (intel->strict_conformance) {
364 ctx->Const.MinLineWidth = 1.0;
365 ctx->Const.MinLineWidthAA = 1.0;
366 ctx->Const.MaxLineWidth = 1.0;
367 ctx->Const.MaxLineWidthAA = 1.0;
368 ctx->Const.LineWidthGranularity = 1.0;
369 }
370 else {
371 ctx->Const.MinLineWidth = 1.0;
372 ctx->Const.MinLineWidthAA = 1.0;
373 ctx->Const.MaxLineWidth = 5.0;
374 ctx->Const.MaxLineWidthAA = 5.0;
375 ctx->Const.LineWidthGranularity = 0.5;
376 }
377
378 ctx->Const.MinPointSize = 1.0;
379 ctx->Const.MinPointSizeAA = 1.0;
380 ctx->Const.MaxPointSize = 255.0;
381 ctx->Const.MaxPointSizeAA = 3.0;
382 ctx->Const.PointSizeGranularity = 1.0;
383
384 /* reinitialize the context point state.
385 * It depend on constants in __GLcontextRec::Const
386 */
387 _mesa_init_point(ctx);
388
389 /* Initialize the software rasterizer and helper modules. */
390 _swrast_CreateContext( ctx );
391 _vbo_CreateContext( ctx );
392 _tnl_CreateContext( ctx );
393 _swsetup_CreateContext( ctx );
394
395 TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
396
397 /* Configure swrast to match hardware characteristics: */
398 _swrast_allow_pixel_fog( ctx, GL_FALSE );
399 _swrast_allow_vertex_fog( ctx, GL_TRUE );
400
401 /* Dri stuff */
402 intel->hHWContext = driContextPriv->hHWContext;
403 intel->driFd = sPriv->fd;
404 intel->driHwLock = (drmLock *) &sPriv->pSAREA->lock;
405
406 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
407 intel->hw_stipple = 1;
408
409 switch(mesaVis->depthBits) {
410 case 0: /* what to do in this case? */
411 case 16:
412 intel->depth_scale = 1.0/0xffff;
413 intel->polygon_offset_scale = 1.0/0xffff;
414 intel->depth_clear_mask = ~0;
415 intel->ClearDepth = 0xffff;
416 break;
417 case 24:
418 intel->depth_scale = 1.0/0xffffff;
419 intel->polygon_offset_scale = 2.0/0xffffff; /* req'd to pass glean */
420 intel->depth_clear_mask = 0x00ffffff;
421 intel->stencil_clear_mask = 0xff000000;
422 intel->ClearDepth = 0x00ffffff;
423 break;
424 default:
425 assert(0);
426 break;
427 }
428
429 /* Initialize swrast, tnl driver tables: */
430 intelInitSpanFuncs( ctx );
431
432 intel->no_hw = getenv("INTEL_NO_HW") != NULL;
433
434 if (!intel->intelScreen->irq_active) {
435 _mesa_printf("IRQs not active. Exiting\n");
436 exit(1);
437 }
438 intelInitExtensions(ctx, GL_TRUE);
439
440 INTEL_DEBUG = driParseDebugString( getenv( "INTEL_DEBUG" ),
441 debug_control );
442
443
444 /* Buffer manager:
445 */
446 intel->bm = bm_fake_intel_Attach( intel );
447
448
449 bmInitPool(intel,
450 intel->intelScreen->tex.offset, /* low offset */
451 intel->intelScreen->tex.map, /* low virtual */
452 intel->intelScreen->tex.size,
453 BM_MEM_AGP);
454
455 /* These are still static, but create regions for them.
456 */
457 intel->front_region =
458 intel_region_create_static(intel,
459 BM_MEM_AGP,
460 intelScreen->front.offset,
461 intelScreen->front.map,
462 intelScreen->cpp,
463 intelScreen->front.pitch / intelScreen->cpp,
464 intelScreen->height,
465 intelScreen->front.size,
466 intelScreen->front.tiled != 0);
467
468 intel->back_region =
469 intel_region_create_static(intel,
470 BM_MEM_AGP,
471 intelScreen->back.offset,
472 intelScreen->back.map,
473 intelScreen->cpp,
474 intelScreen->back.pitch / intelScreen->cpp,
475 intelScreen->height,
476 intelScreen->back.size,
477 intelScreen->back.tiled != 0);
478
479 /* Still assuming front.cpp == depth.cpp
480 *
481 * XXX: Setting tiling to false because Depth tiling only supports
482 * YMAJOR but the blitter only supports XMAJOR tiling. Have to
483 * resolve later.
484 */
485 intel->depth_region =
486 intel_region_create_static(intel,
487 BM_MEM_AGP,
488 intelScreen->depth.offset,
489 intelScreen->depth.map,
490 intelScreen->cpp,
491 intelScreen->depth.pitch / intelScreen->cpp,
492 intelScreen->height,
493 intelScreen->depth.size,
494 intelScreen->depth.tiled != 0);
495
496 intel_bufferobj_init( intel );
497 intel->batch = intel_batchbuffer_alloc( intel );
498
499 if (intel->ctx.Mesa_DXTn) {
500 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
501 _mesa_enable_extension( ctx, "GL_S3_s3tc" );
502 }
503 else if (driQueryOptionb (&intelScreen->optionCache, "force_s3tc_enable")) {
504 _mesa_enable_extension( ctx, "GL_EXT_texture_compression_s3tc" );
505 }
506
507 /* driInitTextureObjects( ctx, & intel->swapped, */
508 /* DRI_TEXMGR_DO_TEXTURE_1D | */
509 /* DRI_TEXMGR_DO_TEXTURE_2D | */
510 /* DRI_TEXMGR_DO_TEXTURE_RECT ); */
511
512
513 if (getenv("INTEL_NO_RAST")) {
514 fprintf(stderr, "disabling 3D rasterization\n");
515 intel->no_rast = 1;
516 }
517
518
519 return GL_TRUE;
520 }
521
522 void intelDestroyContext(__DRIcontextPrivate *driContextPriv)
523 {
524 struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
525
526 assert(intel); /* should never be null */
527 if (intel) {
528 GLboolean release_texture_heaps;
529
530
531 intel->vtbl.destroy( intel );
532
533 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
534 _swsetup_DestroyContext (&intel->ctx);
535 _tnl_DestroyContext (&intel->ctx);
536 _vbo_DestroyContext (&intel->ctx);
537
538 _swrast_DestroyContext (&intel->ctx);
539 intel->Fallback = 0; /* don't call _swrast_Flush later */
540 intel_batchbuffer_free(intel->batch);
541 intel->batch = NULL;
542
543
544 if ( release_texture_heaps ) {
545 /* This share group is about to go away, free our private
546 * texture object data.
547 */
548
549 /* XXX: destroy the shared bufmgr struct here?
550 */
551 }
552
553 /* Free the regions created to describe front/back/depth
554 * buffers:
555 */
556 #if 0
557 intel_region_release(intel, &intel->front_region);
558 intel_region_release(intel, &intel->back_region);
559 intel_region_release(intel, &intel->depth_region);
560 intel_region_release(intel, &intel->draw_region);
561 #endif
562
563 /* free the Mesa context */
564 intel->ctx.VertexProgram.Current = NULL;
565 intel->ctx.FragmentProgram.Current = NULL;
566 _mesa_destroy_context(&intel->ctx);
567 }
568
569 driContextPriv->driverPrivate = NULL;
570 }
571
572 GLboolean intelUnbindContext(__DRIcontextPrivate *driContextPriv)
573 {
574 return GL_TRUE;
575 }
576
577 GLboolean intelMakeCurrent(__DRIcontextPrivate *driContextPriv,
578 __DRIdrawablePrivate *driDrawPriv,
579 __DRIdrawablePrivate *driReadPriv)
580 {
581
582 if (driContextPriv) {
583 struct intel_context *intel = (struct intel_context *) driContextPriv->driverPrivate;
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 (intel->aub_wrap) {
674 bm_fake_NotifyContendedLockTake( intel );
675 intel->vtbl.lost_hardware( intel );
676 intel->vtbl.aub_wrap(intel);
677 intel->aub_wrap = 0;
678 }
679
680 if (bmError(intel)) {
681 bmEvictAll(intel);
682 intel->vtbl.lost_hardware( intel );
683 }
684
685 /* Make sure nothing has been emitted prior to getting the lock:
686 */
687 assert(intel->batch->map == 0);
688
689 /* XXX: postpone, may not be needed:
690 */
691 if (!intel_batchbuffer_map(intel->batch)) {
692 bmEvictAll(intel);
693 intel->vtbl.lost_hardware( intel );
694
695 /* This could only fail if the batchbuffer was greater in size
696 * than the available texture memory:
697 */
698 if (!intel_batchbuffer_map(intel->batch)) {
699 _mesa_printf("double failure to map batchbuffer\n");
700 assert(0);
701 }
702 }
703 }
704
705
706 /* Unlock the hardware using the global current context
707 */
708 void UNLOCK_HARDWARE( struct intel_context *intel )
709 {
710 /* Make sure everything has been released:
711 */
712 assert(intel->batch->ptr == intel->batch->map + intel->batch->offset);
713
714 intel_batchbuffer_unmap(intel->batch);
715 intel->vtbl.note_unlock( intel );
716 intel->locked = 0;
717
718
719
720 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
721 _glthread_UNLOCK_MUTEX(lockMutex);
722 }
723
724