Don't initialize extensions we can't support when !ttm.
[mesa.git] / src / mesa / drivers / dri / i915tex / 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
42 #include "tnl/t_pipeline.h"
43 #include "tnl/t_vertex.h"
44
45 #include "drivers/common/driverfuncs.h"
46
47 #include "intel_screen.h"
48
49 #include "i830_dri.h"
50
51 #include "intel_buffers.h"
52 #include "intel_tex.h"
53 #include "intel_span.h"
54 #include "intel_tris.h"
55 #include "intel_ioctl.h"
56 #include "intel_batchbuffer.h"
57 #include "intel_blit.h"
58 #include "intel_pixel.h"
59 #include "intel_regions.h"
60 #include "intel_buffer_objects.h"
61 #include "intel_fbo.h"
62 #include "i915_disasm.h"
63
64 #include "drirenderbuffer.h"
65 #include "vblank.h"
66 #include "utils.h"
67 #include "xmlpool.h" /* for symbolic values of enum-type options */
68 #ifndef INTEL_DEBUG
69 int INTEL_DEBUG = (0);
70 #endif
71
72 #define need_GL_ARB_multisample
73 #define need_GL_ARB_point_parameters
74 #define need_GL_ARB_texture_compression
75 #define need_GL_ARB_vertex_buffer_object
76 #define need_GL_ARB_vertex_program
77 #define need_GL_ARB_window_pos
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_framebuffer_object
85 #define need_GL_EXT_multi_draw_arrays
86 #define need_GL_EXT_secondary_color
87 #define need_GL_NV_vertex_program
88 #include "extension_helper.h"
89
90
91 #define DRIVER_DATE "20061102"
92
93 _glthread_Mutex lockMutex;
94 static GLboolean lockMutexInit = GL_FALSE;
95
96
97 static const GLubyte *
98 intelGetString(GLcontext * ctx, GLenum name)
99 {
100 const char *chipset;
101 static char buffer[128];
102
103 switch (name) {
104 case GL_VENDOR:
105 return (GLubyte *) "Tungsten Graphics, Inc";
106 break;
107
108 case GL_RENDERER:
109 switch (intel_context(ctx)->intelScreen->deviceID) {
110 case PCI_CHIP_845_G:
111 chipset = "Intel(R) 845G";
112 break;
113 case PCI_CHIP_I830_M:
114 chipset = "Intel(R) 830M";
115 break;
116 case PCI_CHIP_I855_GM:
117 chipset = "Intel(R) 852GM/855GM";
118 break;
119 case PCI_CHIP_I865_G:
120 chipset = "Intel(R) 865G";
121 break;
122 case PCI_CHIP_I915_G:
123 chipset = "Intel(R) 915G";
124 break;
125 case PCI_CHIP_I915_GM:
126 chipset = "Intel(R) 915GM";
127 break;
128 case PCI_CHIP_I945_G:
129 chipset = "Intel(R) 945G";
130 break;
131 case PCI_CHIP_I945_GM:
132 chipset = "Intel(R) 945GM";
133 break;
134 case PCI_CHIP_I945_GME:
135 chipset = "Intel(R) 945GME";
136 break;
137 case PCI_CHIP_G33_G:
138 chipset = "Intel(R) G33";
139 break;
140 case PCI_CHIP_Q35_G:
141 chipset = "Intel(R) Q35";
142 break;
143 case PCI_CHIP_Q33_G:
144 chipset = "Intel(R) Q33";
145 break;
146 default:
147 chipset = "Unknown Intel Chipset";
148 break;
149 }
150
151 (void) driGetRendererString(buffer, chipset, DRIVER_DATE, 0);
152 return (GLubyte *) buffer;
153
154 default:
155 return NULL;
156 }
157 }
158
159
160 /**
161 * Extension strings exported by the intel driver.
162 *
163 * \note
164 * It appears that ARB_texture_env_crossbar has "disappeared" compared to the
165 * old i830-specific driver.
166 */
167 const struct dri_extension card_extensions[] = {
168 {"GL_ARB_multisample", GL_ARB_multisample_functions},
169 {"GL_ARB_multitexture", NULL},
170 {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
171 {"GL_ARB_texture_border_clamp", NULL},
172 {"GL_ARB_texture_compression", GL_ARB_texture_compression_functions},
173 {"GL_ARB_texture_cube_map", NULL},
174 {"GL_ARB_texture_env_add", NULL},
175 {"GL_ARB_texture_env_combine", NULL},
176 {"GL_ARB_texture_env_dot3", NULL},
177 {"GL_ARB_texture_mirrored_repeat", NULL},
178 {"GL_ARB_texture_rectangle", NULL},
179 {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
180 {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
181 {"GL_ARB_window_pos", GL_ARB_window_pos_functions},
182 {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
183 {"GL_EXT_blend_equation_separate",
184 GL_EXT_blend_equation_separate_functions},
185 {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
186 {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
187 {"GL_EXT_blend_subtract", NULL},
188 {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
189 {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
190 {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
191 #if 1 /* XXX FBO temporary? */
192 {"GL_EXT_packed_depth_stencil", NULL},
193 #endif
194 {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
195 {"GL_EXT_stencil_wrap", NULL},
196 {"GL_EXT_texture_edge_clamp", NULL},
197 {"GL_EXT_texture_env_combine", NULL},
198 {"GL_EXT_texture_env_dot3", NULL},
199 {"GL_EXT_texture_filter_anisotropic", NULL},
200 {"GL_EXT_texture_lod_bias", NULL},
201 {"GL_3DFX_texture_compression_FXT1", NULL},
202 {"GL_APPLE_client_storage", NULL},
203 {"GL_MESA_pack_invert", NULL},
204 {"GL_MESA_ycbcr_texture", NULL},
205 {"GL_NV_blend_square", NULL},
206 {"GL_NV_vertex_program", GL_NV_vertex_program_functions},
207 {"GL_NV_vertex_program1_1", NULL},
208 /* { "GL_SGIS_generate_mipmap", NULL }, */
209 {NULL, NULL}
210 };
211
212 const struct dri_extension ttm_extensions[] = {
213 {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
214 {"GL_ARB_pixel_buffer_object", NULL},
215 {NULL, NULL}
216 };
217
218 extern const struct tnl_pipeline_stage _intel_render_stage;
219
220 static const struct tnl_pipeline_stage *intel_pipeline[] = {
221 &_tnl_vertex_transform_stage,
222 &_tnl_vertex_cull_stage,
223 &_tnl_normal_transform_stage,
224 &_tnl_lighting_stage,
225 &_tnl_fog_coordinate_stage,
226 &_tnl_texgen_stage,
227 &_tnl_texture_transform_stage,
228 &_tnl_point_attenuation_stage,
229 &_tnl_vertex_program_stage,
230 #if 1
231 &_intel_render_stage, /* ADD: unclipped rastersetup-to-dma */
232 #endif
233 &_tnl_render_stage,
234 0,
235 };
236
237
238 static const struct dri_debug_control debug_control[] = {
239 {"tex", DEBUG_TEXTURE},
240 {"state", DEBUG_STATE},
241 {"ioctl", DEBUG_IOCTL},
242 {"blit", DEBUG_BLIT},
243 {"mip", DEBUG_MIPTREE},
244 {"fall", DEBUG_FALLBACKS},
245 {"verb", DEBUG_VERBOSE},
246 {"bat", DEBUG_BATCH},
247 {"pix", DEBUG_PIXEL},
248 {"buf", DEBUG_BUFMGR},
249 {"reg", DEBUG_REGION},
250 {"fbo", DEBUG_FBO},
251 {"lock", DEBUG_LOCK},
252 {NULL, 0}
253 };
254
255
256 static void
257 intelInvalidateState(GLcontext * ctx, GLuint new_state)
258 {
259 _swrast_InvalidateState(ctx, new_state);
260 _swsetup_InvalidateState(ctx, new_state);
261 _vbo_InvalidateState(ctx, new_state);
262 _tnl_InvalidateState(ctx, new_state);
263 _tnl_invalidate_vertex_state(ctx, new_state);
264 intel_context(ctx)->NewGLState |= new_state;
265 }
266
267
268 void
269 intelFlush(GLcontext * ctx)
270 {
271 struct intel_context *intel = intel_context(ctx);
272
273 if (intel->Fallback)
274 _swrast_flush(ctx);
275
276 INTEL_FIREVERTICES(intel);
277
278 if (intel->batch->map != intel->batch->ptr)
279 intel_batchbuffer_flush(intel->batch);
280
281 /* XXX: Need to do an MI_FLUSH here.
282 */
283 }
284
285
286 /**
287 * Check if we need to rotate/warp the front color buffer to the
288 * rotated screen. We generally need to do this when we get a glFlush
289 * or glFinish after drawing to the front color buffer.
290 */
291 static void
292 intelCheckFrontRotate(GLcontext * ctx)
293 {
294 struct intel_context *intel = intel_context(ctx);
295 if (intel->ctx.DrawBuffer->_ColorDrawBufferMask[0] ==
296 BUFFER_BIT_FRONT_LEFT) {
297 intelScreenPrivate *screen = intel->intelScreen;
298 if (screen->current_rotation != 0) {
299 __DRIdrawablePrivate *dPriv = intel->driDrawable;
300 intelRotateWindow(intel, dPriv, BUFFER_BIT_FRONT_LEFT);
301 }
302 }
303 }
304
305
306 /**
307 * Called via glFlush.
308 */
309 static void
310 intelglFlush(GLcontext * ctx)
311 {
312 intelFlush(ctx);
313 intelCheckFrontRotate(ctx);
314 }
315
316 void
317 intelFinish(GLcontext * ctx)
318 {
319 struct intel_context *intel = intel_context(ctx);
320 intelFlush(ctx);
321 if (intel->batch->last_fence) {
322 dri_fence_wait(intel->batch->last_fence);
323 dri_fence_unreference(intel->batch->last_fence);
324 intel->batch->last_fence = NULL;
325 }
326 intelCheckFrontRotate(ctx);
327 }
328
329
330 void
331 intelInitDriverFunctions(struct dd_function_table *functions)
332 {
333 _mesa_init_driver_functions(functions);
334
335 functions->Flush = intelglFlush;
336 functions->Finish = intelFinish;
337 functions->GetString = intelGetString;
338 functions->UpdateState = intelInvalidateState;
339 functions->CopyColorTable = _swrast_CopyColorTable;
340 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
341 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
342 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
343
344 intelInitTextureFuncs(functions);
345 intelInitPixelFuncs(functions);
346 intelInitStateFuncs(functions);
347 intelInitBufferFuncs(functions);
348 }
349
350
351 GLboolean
352 intelInitContext(struct intel_context *intel,
353 const __GLcontextModes * mesaVis,
354 __DRIcontextPrivate * driContextPriv,
355 void *sharedContextPrivate,
356 struct dd_function_table *functions)
357 {
358 GLcontext *ctx = &intel->ctx;
359 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
360 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
361 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
362 drmI830Sarea *saPriv = (drmI830Sarea *)
363 (((GLubyte *) sPriv->pSAREA) + intelScreen->sarea_priv_offset);
364 int fthrottle_mode;
365
366 if (!_mesa_initialize_context(&intel->ctx,
367 mesaVis, shareCtx,
368 functions, (void *) intel))
369 return GL_FALSE;
370
371 driContextPriv->driverPrivate = intel;
372 intel->intelScreen = intelScreen;
373 intel->driScreen = sPriv;
374 intel->sarea = saPriv;
375
376 intel->width = intelScreen->width;
377 intel->height = intelScreen->height;
378 intel->current_rotation = intelScreen->current_rotation;
379
380 if (!lockMutexInit) {
381 lockMutexInit = GL_TRUE;
382 _glthread_INIT_MUTEX(lockMutex);
383 }
384
385 driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
386 intel->driScreen->myNum, "i915");
387
388 ctx->Const.MaxTextureMaxAnisotropy = 2.0;
389
390 /* This doesn't yet catch all non-conformant rendering, but it's a
391 * start.
392 */
393 if (getenv("INTEL_STRICT_CONFORMANCE")) {
394 intel->strict_conformance = 1;
395 }
396
397 ctx->Const.MinLineWidth = 1.0;
398 ctx->Const.MinLineWidthAA = 1.0;
399 ctx->Const.MaxLineWidth = 3.0;
400 ctx->Const.MaxLineWidthAA = 3.0;
401 ctx->Const.LineWidthGranularity = 1.0;
402
403 ctx->Const.MinPointSize = 1.0;
404 ctx->Const.MinPointSizeAA = 1.0;
405 ctx->Const.MaxPointSize = 255.0;
406 ctx->Const.MaxPointSizeAA = 3.0;
407 ctx->Const.PointSizeGranularity = 1.0;
408
409 /* reinitialize the context point state.
410 * It depend on constants in __GLcontextRec::Const
411 */
412 _mesa_init_point(ctx);
413
414 ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */
415
416 /* Initialize the software rasterizer and helper modules. */
417 _swrast_CreateContext(ctx);
418 _vbo_CreateContext(ctx);
419 _tnl_CreateContext(ctx);
420 _swsetup_CreateContext(ctx);
421
422 /* Install the customized pipeline: */
423 _tnl_destroy_pipeline(ctx);
424 _tnl_install_pipeline(ctx, intel_pipeline);
425
426 /* Configure swrast to match hardware characteristics: */
427 _swrast_allow_pixel_fog(ctx, GL_FALSE);
428 _swrast_allow_vertex_fog(ctx, GL_TRUE);
429
430 /* Dri stuff */
431 intel->hHWContext = driContextPriv->hHWContext;
432 intel->driFd = sPriv->fd;
433 intel->driHwLock = (drmLock *) & sPriv->pSAREA->lock;
434
435 intel->hw_stipple = 1;
436
437 /* XXX FBO: this doesn't seem to be used anywhere */
438 switch (mesaVis->depthBits) {
439 case 0: /* what to do in this case? */
440 case 16:
441 intel->polygon_offset_scale = 1.0 / 0xffff;
442 break;
443 case 24:
444 intel->polygon_offset_scale = 2.0 / 0xffffff; /* req'd to pass glean */
445 break;
446 default:
447 assert(0);
448 break;
449 }
450
451 /* Initialize swrast, tnl driver tables: */
452 intelInitSpanFuncs(ctx);
453 intelInitTriFuncs(ctx);
454
455
456 intel->RenderIndex = ~0;
457
458 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
459 intel->irqsEmitted = 0;
460
461 intel->do_irqs = (intel->intelScreen->irq_active &&
462 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
463
464 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
465
466 _math_matrix_ctr(&intel->ViewportMatrix);
467
468 /* Disable imaging extension until convolution is working in
469 * teximage paths:
470 */
471 driInitExtensions(ctx, card_extensions,
472 /* GL_TRUE, */
473 GL_FALSE);
474
475 if (intelScreen->ttm)
476 driInitExtensions(ctx, ttm_extensions, GL_FALSE);
477
478
479 intel->batch = intel_batchbuffer_alloc(intel);
480 intel->last_swap_fence = NULL;
481 intel->first_swap_fence = NULL;
482
483 intel_bufferobj_init(intel);
484 intel_fbo_init(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(&intel->optionCache, "force_s3tc_enable")) {
491 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
492 }
493
494 intel->prim.primitive = ~0;
495
496
497 #if DO_DEBUG
498 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
499 #endif
500
501 if (getenv("INTEL_NO_RAST")) {
502 fprintf(stderr, "disabling 3D rasterization\n");
503 FALLBACK(intel, INTEL_FALLBACK_USER, 1);
504 }
505
506 return GL_TRUE;
507 }
508
509 void
510 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
511 {
512 struct intel_context *intel =
513 (struct intel_context *) driContextPriv->driverPrivate;
514
515 assert(intel); /* should never be null */
516 if (intel) {
517 GLboolean release_texture_heaps;
518
519 INTEL_FIREVERTICES(intel);
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
531 intel_batchbuffer_free(intel->batch);
532
533 if (intel->last_swap_fence) {
534 dri_fence_wait(intel->last_swap_fence);
535 dri_fence_unreference(intel->last_swap_fence);
536 intel->last_swap_fence = NULL;
537 }
538 if (intel->first_swap_fence) {
539 dri_fence_wait(intel->first_swap_fence);
540 dri_fence_unreference(intel->first_swap_fence);
541 intel->first_swap_fence = NULL;
542 }
543
544
545 if (release_texture_heaps) {
546 /* This share group is about to go away, free our private
547 * texture object data.
548 */
549 if (INTEL_DEBUG & DEBUG_TEXTURE)
550 fprintf(stderr, "do something to free texture heaps\n");
551 }
552
553 /* free the Mesa context */
554 _mesa_free_context_data(&intel->ctx);
555 }
556 }
557
558 GLboolean
559 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
560 {
561 return GL_TRUE;
562 }
563
564 GLboolean
565 intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
566 __DRIdrawablePrivate * driDrawPriv,
567 __DRIdrawablePrivate * driReadPriv)
568 {
569
570 if (driContextPriv) {
571 struct intel_context *intel =
572 (struct intel_context *) driContextPriv->driverPrivate;
573 struct intel_framebuffer *intel_fb =
574 (struct intel_framebuffer *) driDrawPriv->driverPrivate;
575 GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
576
577
578 /* XXX FBO temporary fix-ups! */
579 /* if the renderbuffers don't have regions, init them from the context */
580 {
581 struct intel_renderbuffer *irbDepth
582 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
583 struct intel_renderbuffer *irbStencil
584 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
585
586 if (intel_fb->color_rb[0] && !intel_fb->color_rb[0]->region) {
587 intel_region_reference(&intel_fb->color_rb[0]->region,
588 intel->intelScreen->front_region);
589 }
590 if (intel_fb->color_rb[1] && !intel_fb->color_rb[1]->region) {
591 intel_region_reference(&intel_fb->color_rb[1]->region,
592 intel->intelScreen->back_region);
593 }
594 if (intel_fb->color_rb[2] && !intel_fb->color_rb[2]->region) {
595 intel_region_reference(&intel_fb->color_rb[2]->region,
596 intel->intelScreen->third_region);
597 }
598 if (irbDepth && !irbDepth->region) {
599 intel_region_reference(&irbDepth->region, intel->intelScreen->depth_region);
600 }
601 if (irbStencil && !irbStencil->region) {
602 intel_region_reference(&irbStencil->region, intel->intelScreen->depth_region);
603 }
604 }
605
606 /* set GLframebuffer size to match window, if needed */
607 driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
608
609 if (driReadPriv != driDrawPriv) {
610 driUpdateFramebufferSize(&intel->ctx, driReadPriv);
611 }
612
613 _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
614
615 /* The drawbuffer won't always be updated by _mesa_make_current:
616 */
617 if (intel->ctx.DrawBuffer == &intel_fb->Base) {
618
619 if (intel->driDrawable != driDrawPriv) {
620 intel_fb->vblank_flags = (intel->intelScreen->irq_active != 0)
621 ? driGetDefaultVBlankFlags(&intel->optionCache)
622 : VBLANK_FLAG_NO_IRQ;
623 (*dri_interface->getUST) (&intel_fb->swap_ust);
624 driDrawableInitVBlank(driDrawPriv, intel_fb->vblank_flags,
625 &intel_fb->vbl_seq);
626 intel->driDrawable = driDrawPriv;
627 intelWindowMoved(intel);
628 }
629
630 intel_draw_buffer(&intel->ctx, &intel_fb->Base);
631 }
632 }
633 else {
634 _mesa_make_current(NULL, NULL, NULL);
635 }
636
637 return GL_TRUE;
638 }
639
640 static void
641 intelContendedLock(struct intel_context *intel, GLuint flags)
642 {
643 __DRIdrawablePrivate *dPriv = intel->driDrawable;
644 __DRIscreenPrivate *sPriv = intel->driScreen;
645 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
646 drmI830Sarea *sarea = intel->sarea;
647
648 drmGetLock(intel->driFd, intel->hHWContext, flags);
649
650 if (INTEL_DEBUG & DEBUG_LOCK)
651 _mesa_printf("%s - got contended lock\n", __progname);
652
653 /* If the window moved, may need to set a new cliprect now.
654 *
655 * NOTE: This releases and regains the hw lock, so all state
656 * checking must be done *after* this call:
657 */
658 if (dPriv)
659 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
660
661 /* If the last consumer of the texture memory wasn't us, notify the fake
662 * bufmgr and record the new owner. We should have the memory shared
663 * between contexts of a single fake bufmgr, but this will at least make
664 * things correct for now.
665 */
666 if (!intel->intelScreen->ttm && sarea->texAge != intel->hHWContext) {
667 sarea->texAge = intel->hHWContext;
668 dri_bufmgr_fake_contended_lock_take(intel->intelScreen->bufmgr);
669 if (INTEL_DEBUG & DEBUG_BATCH)
670 i915_disasm_context_reset();
671 }
672
673 if (sarea->width != intelScreen->width ||
674 sarea->height != intelScreen->height ||
675 sarea->rotation != intelScreen->current_rotation) {
676
677 intelUpdateScreenRotation(sPriv, sarea);
678 }
679
680 if (sarea->width != intel->width ||
681 sarea->height != intel->height ||
682 sarea->rotation != intel->current_rotation) {
683
684 void *batchMap = intel->batch->map;
685
686 /*
687 * FIXME: Really only need to do this when drawing to a
688 * common back- or front buffer.
689 */
690
691 /*
692 * This will drop the outstanding batchbuffer on the floor
693 */
694
695 if (batchMap != NULL) {
696 dri_bo_unmap(intel->batch->buf);
697 intel->batch->map = NULL;
698 }
699
700 intel_batchbuffer_reset(intel->batch);
701
702 if (batchMap == NULL) {
703 dri_bo_unmap(intel->batch->buf);
704 intel->batch->map = NULL;
705 }
706
707 /* lose all primitives */
708 intel->prim.primitive = ~0;
709 intel->prim.start_ptr = 0;
710 intel->prim.flush = 0;
711
712 /* re-emit all state */
713 intel->vtbl.lost_hardware(intel);
714
715 /* force window update */
716 intel->lastStamp = 0;
717
718 intel->width = sarea->width;
719 intel->height = sarea->height;
720 intel->current_rotation = sarea->rotation;
721 }
722
723 /* Drawable changed?
724 */
725 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
726 intelWindowMoved(intel);
727 intel->lastStamp = dPriv->lastStamp;
728 }
729 }
730
731
732
733 /* Lock the hardware and validate our state.
734 */
735 void LOCK_HARDWARE( struct intel_context *intel )
736 {
737 char __ret=0;
738 struct intel_framebuffer *intel_fb = NULL;
739 struct intel_renderbuffer *intel_rb = NULL;
740 _glthread_LOCK_MUTEX(lockMutex);
741 assert(!intel->locked);
742
743 if (intel->driDrawable) {
744 intel_fb = intel->driDrawable->driverPrivate;
745
746 if (intel_fb)
747 intel_rb =
748 intel_get_renderbuffer(&intel_fb->Base,
749 intel_fb->Base._ColorDrawBufferMask[0] ==
750 BUFFER_BIT_FRONT_LEFT ? BUFFER_FRONT_LEFT :
751 BUFFER_BACK_LEFT);
752 }
753
754 if (intel_rb && (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
755 drmVBlank vbl;
756
757 vbl.request.type = DRM_VBLANK_ABSOLUTE;
758
759 if ( intel_fb->vblank_flags & VBLANK_FLAG_SECONDARY ) {
760 vbl.request.type |= DRM_VBLANK_SECONDARY;
761 }
762
763 vbl.request.sequence = intel_rb->vbl_pending;
764 drmWaitVBlank(intel->driFd, &vbl);
765 intel_fb->vbl_waited = vbl.reply.sequence;
766 }
767
768 DRM_CAS(intel->driHwLock, intel->hHWContext,
769 (DRM_LOCK_HELD|intel->hHWContext), __ret);
770
771 if (__ret)
772 intelContendedLock( intel, 0 );
773
774 if (INTEL_DEBUG & DEBUG_LOCK)
775 _mesa_printf("%s - locked\n", __progname);
776
777 intel->locked = 1;
778 }
779
780
781 /* Unlock the hardware using the global current context
782 */
783 void UNLOCK_HARDWARE( struct intel_context *intel )
784 {
785 intel->locked = 0;
786
787 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
788
789 _glthread_UNLOCK_MUTEX(lockMutex);
790
791 if (INTEL_DEBUG & DEBUG_LOCK)
792 _mesa_printf("%s - unlocked\n", __progname);
793 }
794