1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/arrayobj.h"
32 #include "main/extensions.h"
33 #include "main/framebuffer.h"
34 #include "main/imports.h"
35 #include "main/points.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "drivers/common/driverfuncs.h"
44 #include "intel_chipset.h"
45 #include "intel_buffers.h"
46 #include "intel_tex.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_clear.h"
49 #include "intel_extensions.h"
50 #include "intel_pixel.h"
51 #include "intel_regions.h"
52 #include "intel_buffer_objects.h"
53 #include "intel_fbo.h"
54 #include "intel_decode.h"
55 #include "intel_bufmgr.h"
56 #include "intel_screen.h"
57 #include "intel_swapbuffers.h"
59 #include "drirenderbuffer.h"
62 #include "xmlpool.h" /* for symbolic values of enum-type options */
66 int INTEL_DEBUG = (0);
70 #define DRIVER_DATE "20090712 2009Q2 RC3"
71 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
74 static void intel_flush(GLcontext *ctx, GLboolean needs_mi_flush);
76 static const GLubyte *
77 intelGetString(GLcontext * ctx, GLenum name)
79 const struct intel_context *const intel = intel_context(ctx);
81 static char buffer[128];
85 return (GLubyte *) "Tungsten Graphics, Inc";
89 switch (intel->intelScreen->deviceID) {
91 chipset = "Intel(R) 845G";
94 chipset = "Intel(R) 830M";
96 case PCI_CHIP_I855_GM:
97 chipset = "Intel(R) 852GM/855GM";
100 chipset = "Intel(R) 865G";
102 case PCI_CHIP_I915_G:
103 chipset = "Intel(R) 915G";
105 case PCI_CHIP_E7221_G:
106 chipset = "Intel (R) E7221G (i915)";
108 case PCI_CHIP_I915_GM:
109 chipset = "Intel(R) 915GM";
111 case PCI_CHIP_I945_G:
112 chipset = "Intel(R) 945G";
114 case PCI_CHIP_I945_GM:
115 chipset = "Intel(R) 945GM";
117 case PCI_CHIP_I945_GME:
118 chipset = "Intel(R) 945GME";
121 chipset = "Intel(R) G33";
124 chipset = "Intel(R) Q35";
127 chipset = "Intel(R) Q33";
129 case PCI_CHIP_IGD_GM:
131 chipset = "Intel(R) IGD";
133 case PCI_CHIP_I965_Q:
134 chipset = "Intel(R) 965Q";
136 case PCI_CHIP_I965_G:
137 case PCI_CHIP_I965_G_1:
138 chipset = "Intel(R) 965G";
140 case PCI_CHIP_I946_GZ:
141 chipset = "Intel(R) 946GZ";
143 case PCI_CHIP_I965_GM:
144 chipset = "Intel(R) 965GM";
146 case PCI_CHIP_I965_GME:
147 chipset = "Intel(R) 965GME/GLE";
149 case PCI_CHIP_GM45_GM:
150 chipset = "Mobile IntelĀ® GM45 Express Chipset";
152 case PCI_CHIP_IGD_E_G:
153 chipset = "Intel(R) Integrated Graphics Device";
156 chipset = "Intel(R) G45/G43";
159 chipset = "Intel(R) Q45/Q43";
162 chipset = "Intel(R) G41";
165 chipset = "Intel(R) IGDNG_D";
168 chipset = "Intel(R) IGDNG_M";
171 chipset = "Unknown Intel Chipset";
175 (void) driGetRendererString(buffer, chipset,
176 (intel->ttm) ? DRIVER_DATE_GEM : DRIVER_DATE,
178 return (GLubyte *) buffer;
186 intel_bits_per_pixel(const struct intel_renderbuffer *rb)
188 switch (rb->Base._ActualFormat) {
190 case GL_DEPTH_COMPONENT16:
194 case GL_DEPTH_COMPONENT24:
195 case GL_DEPTH24_STENCIL8_EXT:
196 case GL_STENCIL_INDEX8_EXT:
204 intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
206 struct intel_framebuffer *intel_fb = drawable->driverPrivate;
207 struct intel_renderbuffer *rb;
208 struct intel_region *region, *depth_region;
209 struct intel_context *intel = context->driverPrivate;
210 __DRIbuffer *buffers = NULL;
213 unsigned int attachments[10];
215 const char *region_name;
217 if (INTEL_DEBUG & DEBUG_DRI)
218 fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
220 screen = intel->intelScreen->driScrnPriv;
222 if (screen->dri2.loader
223 && (screen->dri2.loader->base.version > 2)
224 && (screen->dri2.loader->getBuffersWithFormat != NULL)) {
225 struct intel_renderbuffer *depth_rb;
226 struct intel_renderbuffer *stencil_rb;
229 if ((intel->is_front_buffer_rendering ||
230 intel->is_front_buffer_reading ||
231 !intel_fb->color_rb[1])
232 && intel_fb->color_rb[0]) {
233 attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
234 attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[0]);
237 if (intel_fb->color_rb[1]) {
238 attachments[i++] = __DRI_BUFFER_BACK_LEFT;
239 attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[1]);
242 depth_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
243 stencil_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
245 if ((depth_rb != NULL) && (stencil_rb != NULL)) {
246 attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
247 attachments[i++] = intel_bits_per_pixel(depth_rb);
248 } else if (depth_rb != NULL) {
249 attachments[i++] = __DRI_BUFFER_DEPTH;
250 attachments[i++] = intel_bits_per_pixel(depth_rb);
251 } else if (stencil_rb != NULL) {
252 attachments[i++] = __DRI_BUFFER_STENCIL;
253 attachments[i++] = intel_bits_per_pixel(stencil_rb);
257 (*screen->dri2.loader->getBuffersWithFormat)(drawable,
262 drawable->loaderPrivate);
263 } else if (screen->dri2.loader) {
265 if (intel_fb->color_rb[0])
266 attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
267 if (intel_fb->color_rb[1])
268 attachments[i++] = __DRI_BUFFER_BACK_LEFT;
269 if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH))
270 attachments[i++] = __DRI_BUFFER_DEPTH;
271 if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL))
272 attachments[i++] = __DRI_BUFFER_STENCIL;
274 buffers = (*screen->dri2.loader->getBuffers)(drawable,
279 drawable->loaderPrivate);
289 drawable->numClipRects = 1;
290 drawable->pClipRects[0].x1 = 0;
291 drawable->pClipRects[0].y1 = 0;
292 drawable->pClipRects[0].x2 = drawable->w;
293 drawable->pClipRects[0].y2 = drawable->h;
294 drawable->numBackClipRects = 1;
295 drawable->pBackClipRects[0].x1 = 0;
296 drawable->pBackClipRects[0].y1 = 0;
297 drawable->pBackClipRects[0].x2 = drawable->w;
298 drawable->pBackClipRects[0].y2 = drawable->h;
301 for (i = 0; i < count; i++) {
302 switch (buffers[i].attachment) {
303 case __DRI_BUFFER_FRONT_LEFT:
304 rb = intel_fb->color_rb[0];
305 region_name = "dri2 front buffer";
308 case __DRI_BUFFER_FAKE_FRONT_LEFT:
309 rb = intel_fb->color_rb[0];
310 region_name = "dri2 fake front buffer";
313 case __DRI_BUFFER_BACK_LEFT:
314 rb = intel_fb->color_rb[1];
315 region_name = "dri2 back buffer";
318 case __DRI_BUFFER_DEPTH:
319 rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
320 region_name = "dri2 depth buffer";
323 case __DRI_BUFFER_DEPTH_STENCIL:
324 rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
325 region_name = "dri2 depth / stencil buffer";
328 case __DRI_BUFFER_STENCIL:
329 rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
330 region_name = "dri2 stencil buffer";
333 case __DRI_BUFFER_ACCUM:
336 "unhandled buffer attach event, attacment type %d\n",
337 buffers[i].attachment);
345 dri_bo_flink(rb->region->buffer, &name);
346 if (name == buffers[i].name)
350 if (INTEL_DEBUG & DEBUG_DRI)
352 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
353 buffers[i].name, buffers[i].attachment,
354 buffers[i].cpp, buffers[i].pitch);
356 if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_region) {
357 if (INTEL_DEBUG & DEBUG_DRI)
358 fprintf(stderr, "(reusing depth buffer as stencil)\n");
359 intel_region_reference(®ion, depth_region);
362 region = intel_region_alloc_for_handle(intel, buffers[i].cpp,
365 buffers[i].pitch / buffers[i].cpp,
369 if (buffers[i].attachment == __DRI_BUFFER_DEPTH)
370 depth_region = region;
372 intel_renderbuffer_set_region(rb, region);
373 intel_region_release(®ion);
375 if (buffers[i].attachment == __DRI_BUFFER_DEPTH_STENCIL) {
376 rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
378 struct intel_region *stencil_region = NULL;
381 dri_bo_flink(rb->region->buffer, &name);
382 if (name == buffers[i].name)
386 intel_region_reference(&stencil_region, region);
387 intel_renderbuffer_set_region(rb, stencil_region);
388 intel_region_release(&stencil_region);
393 driUpdateFramebufferSize(&intel->ctx, drawable);
397 intel_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
399 struct intel_context *intel = intel_context(ctx);
400 __DRIcontext *driContext = intel->driContext;
401 void (*old_viewport)(GLcontext *ctx, GLint x, GLint y,
402 GLsizei w, GLsizei h);
404 if (!driContext->driScreenPriv->dri2.enabled)
407 if (!intel->meta.internal_viewport_call && ctx->DrawBuffer->Name == 0) {
408 /* If we're rendering to the fake front buffer, make sure all the pending
409 * drawing has landed on the real front buffer. Otherwise when we
410 * eventually get to DRI2GetBuffersWithFormat the stale real front
411 * buffer contents will get copied to the new fake front buffer.
413 if (intel->is_front_buffer_rendering) {
414 intel_flush(ctx, GL_FALSE);
417 intel_update_renderbuffers(driContext, driContext->driDrawablePriv);
418 if (driContext->driDrawablePriv != driContext->driReadablePriv)
419 intel_update_renderbuffers(driContext, driContext->driReadablePriv);
422 old_viewport = ctx->Driver.Viewport;
423 ctx->Driver.Viewport = NULL;
424 intel->driDrawable = driContext->driDrawablePriv;
425 intelWindowMoved(intel);
426 intel_draw_buffer(ctx, intel->ctx.DrawBuffer);
427 ctx->Driver.Viewport = old_viewport;
431 static const struct dri_debug_control debug_control[] = {
432 { "tex", DEBUG_TEXTURE},
433 { "state", DEBUG_STATE},
434 { "ioctl", DEBUG_IOCTL},
435 { "blit", DEBUG_BLIT},
436 { "mip", DEBUG_MIPTREE},
437 { "fall", DEBUG_FALLBACKS},
438 { "verb", DEBUG_VERBOSE},
439 { "bat", DEBUG_BATCH},
440 { "pix", DEBUG_PIXEL},
441 { "buf", DEBUG_BUFMGR},
442 { "reg", DEBUG_REGION},
444 { "lock", DEBUG_LOCK},
445 { "sync", DEBUG_SYNC},
446 { "prim", DEBUG_PRIMS },
447 { "vert", DEBUG_VERTS },
448 { "dri", DEBUG_DRI },
449 { "dma", DEBUG_DMA },
450 { "san", DEBUG_SANITY },
451 { "sleep", DEBUG_SLEEP },
452 { "stats", DEBUG_STATS },
453 { "tile", DEBUG_TILE },
454 { "sing", DEBUG_SINGLE_THREAD },
455 { "thre", DEBUG_SINGLE_THREAD },
457 { "urb", DEBUG_URB },
464 intelInvalidateState(GLcontext * ctx, GLuint new_state)
466 struct intel_context *intel = intel_context(ctx);
468 _swrast_InvalidateState(ctx, new_state);
469 _swsetup_InvalidateState(ctx, new_state);
470 _vbo_InvalidateState(ctx, new_state);
471 _tnl_InvalidateState(ctx, new_state);
472 _tnl_invalidate_vertex_state(ctx, new_state);
474 intel->NewGLState |= new_state;
476 if (intel->vtbl.invalidate_state)
477 intel->vtbl.invalidate_state( intel, new_state );
481 intel_flush(GLcontext *ctx, GLboolean needs_mi_flush)
483 struct intel_context *intel = intel_context(ctx);
488 if (!IS_965(intel->intelScreen->deviceID))
489 INTEL_FIREVERTICES(intel);
491 /* Emit a flush so that any frontbuffer rendering that might have occurred
492 * lands onscreen in a timely manner, even if the X Server doesn't trigger
496 intel_batchbuffer_emit_mi_flush(intel->batch);
498 if (intel->batch->map != intel->batch->ptr)
499 intel_batchbuffer_flush(intel->batch);
501 if ((ctx->DrawBuffer->Name == 0) && intel->front_buffer_dirty) {
502 __DRIscreen *const screen = intel->intelScreen->driScrnPriv;
504 if (screen->dri2.loader &&
505 (screen->dri2.loader->base.version >= 2)
506 && (screen->dri2.loader->flushFrontBuffer != NULL)) {
507 (*screen->dri2.loader->flushFrontBuffer)(intel->driDrawable,
508 intel->driDrawable->loaderPrivate);
510 /* Only clear the dirty bit if front-buffer rendering is no longer
511 * enabled. This is done so that the dirty bit can only be set in
512 * glDrawBuffer. Otherwise the dirty bit would have to be set at
513 * each of N places that do rendering. This has worse performances,
514 * but it is much easier to get correct.
516 if (intel->is_front_buffer_rendering) {
517 intel->front_buffer_dirty = GL_FALSE;
524 intelFlush(GLcontext * ctx)
526 intel_flush(ctx, GL_FALSE);
530 intel_glFlush(GLcontext *ctx)
532 intel_flush(ctx, GL_TRUE);
536 intelFinish(GLcontext * ctx)
538 struct gl_framebuffer *fb = ctx->DrawBuffer;
543 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
544 struct intel_renderbuffer *irb;
546 irb = intel_renderbuffer(fb->_ColorDrawBuffers[i]);
548 if (irb && irb->region)
549 dri_bo_wait_rendering(irb->region->buffer);
551 if (fb->_DepthBuffer) {
552 /* XXX: Wait on buffer idle */
557 intelInitDriverFunctions(struct dd_function_table *functions)
559 _mesa_init_driver_functions(functions);
561 functions->Flush = intel_glFlush;
562 functions->Finish = intelFinish;
563 functions->GetString = intelGetString;
564 functions->UpdateState = intelInvalidateState;
566 functions->CopyColorTable = _swrast_CopyColorTable;
567 functions->CopyColorSubTable = _swrast_CopyColorSubTable;
568 functions->CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
569 functions->CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
571 intelInitTextureFuncs(functions);
572 intelInitTextureImageFuncs(functions);
573 intelInitTextureSubImageFuncs(functions);
574 intelInitTextureCopyImageFuncs(functions);
575 intelInitStateFuncs(functions);
576 intelInitClearFuncs(functions);
577 intelInitBufferFuncs(functions);
578 intelInitPixelFuncs(functions);
579 intelInitBufferObjectFuncs(functions);
584 intelInitContext(struct intel_context *intel,
585 const __GLcontextModes * mesaVis,
586 __DRIcontextPrivate * driContextPriv,
587 void *sharedContextPrivate,
588 struct dd_function_table *functions)
590 GLcontext *ctx = &intel->ctx;
591 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
592 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
593 intelScreenPrivate *intelScreen = (intelScreenPrivate *) sPriv->private;
596 if (!_mesa_initialize_context(&intel->ctx, mesaVis, shareCtx,
597 functions, (void *) intel)) {
598 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__);
602 driContextPriv->driverPrivate = intel;
603 intel->intelScreen = intelScreen;
604 intel->driScreen = sPriv;
605 intel->sarea = intelScreen->sarea;
606 intel->driContext = driContextPriv;
609 intel->hHWContext = driContextPriv->hHWContext;
610 intel->driFd = sPriv->fd;
611 intel->driHwLock = sPriv->lock;
613 driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
614 intel->driScreen->myNum,
615 IS_965(intelScreen->deviceID) ? "i965" : "i915");
616 if (intelScreen->deviceID == PCI_CHIP_I865_G)
617 intel->maxBatchSize = 4096;
619 intel->maxBatchSize = BATCH_SZ;
621 intel->bufmgr = intelScreen->bufmgr;
622 intel->ttm = intelScreen->ttm;
626 bo_reuse_mode = driQueryOptioni(&intel->optionCache, "bo_reuse");
627 switch (bo_reuse_mode) {
628 case DRI_CONF_BO_REUSE_DISABLED:
630 case DRI_CONF_BO_REUSE_ALL:
631 intel_bufmgr_gem_enable_reuse(intel->bufmgr);
636 /* This doesn't yet catch all non-conformant rendering, but it's a
639 if (getenv("INTEL_STRICT_CONFORMANCE")) {
640 unsigned int value = atoi(getenv("INTEL_STRICT_CONFORMANCE"));
642 intel->conformance_mode = value;
645 intel->conformance_mode = 1;
649 if (intel->conformance_mode > 0) {
650 ctx->Const.MinLineWidth = 1.0;
651 ctx->Const.MinLineWidthAA = 1.0;
652 ctx->Const.MaxLineWidth = 1.0;
653 ctx->Const.MaxLineWidthAA = 1.0;
654 ctx->Const.LineWidthGranularity = 1.0;
657 ctx->Const.MinLineWidth = 1.0;
658 ctx->Const.MinLineWidthAA = 1.0;
659 ctx->Const.MaxLineWidth = 5.0;
660 ctx->Const.MaxLineWidthAA = 5.0;
661 ctx->Const.LineWidthGranularity = 0.5;
664 ctx->Const.MinPointSize = 1.0;
665 ctx->Const.MinPointSizeAA = 1.0;
666 ctx->Const.MaxPointSize = 255.0;
667 ctx->Const.MaxPointSizeAA = 3.0;
668 ctx->Const.PointSizeGranularity = 1.0;
670 /* reinitialize the context point state.
671 * It depend on constants in __GLcontextRec::Const
673 _mesa_init_point(ctx);
675 meta_init_metaops(ctx, &intel->meta);
676 ctx->Const.MaxColorAttachments = 4; /* XXX FBO: review this */
677 if (IS_965(intelScreen->deviceID)) {
678 if (MAX_WIDTH > 8192)
679 ctx->Const.MaxRenderbufferSize = 8192;
681 if (MAX_WIDTH > 2048)
682 ctx->Const.MaxRenderbufferSize = 2048;
685 /* Initialize the software rasterizer and helper modules. */
686 _swrast_CreateContext(ctx);
687 _vbo_CreateContext(ctx);
688 _tnl_CreateContext(ctx);
689 _swsetup_CreateContext(ctx);
691 /* Configure swrast to match hardware characteristics: */
692 _swrast_allow_pixel_fog(ctx, GL_FALSE);
693 _swrast_allow_vertex_fog(ctx, GL_TRUE);
695 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
696 intel->hw_stipple = 1;
698 /* XXX FBO: this doesn't seem to be used anywhere */
699 switch (mesaVis->depthBits) {
700 case 0: /* what to do in this case? */
702 intel->polygon_offset_scale = 1.0;
705 intel->polygon_offset_scale = 2.0; /* req'd to pass glean */
712 if (IS_965(intelScreen->deviceID))
713 intel->polygon_offset_scale /= 0xffff;
715 intel->RenderIndex = ~0;
717 fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode");
718 intel->irqsEmitted = 0;
720 intel->do_irqs = (intel->intelScreen->irq_active &&
721 fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS);
723 intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
725 if (IS_965(intelScreen->deviceID) && !intel->intelScreen->irq_active) {
726 _mesa_printf("IRQs not active. Exiting\n");
730 intelInitExtensions(ctx, GL_FALSE);
732 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
733 if (INTEL_DEBUG & DEBUG_BUFMGR)
734 dri_bufmgr_set_debug(intel->bufmgr, GL_TRUE);
736 if (!sPriv->dri2.enabled)
737 intel_recreate_static_regions(intel);
739 intel->batch = intel_batchbuffer_alloc(intel);
741 intel_fbo_init(intel);
743 if (intel->ctx.Mesa_DXTn) {
744 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
745 _mesa_enable_extension(ctx, "GL_S3_s3tc");
747 else if (driQueryOptionb(&intel->optionCache, "force_s3tc_enable")) {
748 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
750 intel->use_texture_tiling = driQueryOptionb(&intel->optionCache,
752 if (intel->use_texture_tiling &&
753 !intel->intelScreen->kernel_exec_fencing) {
754 fprintf(stderr, "No kernel support for execution fencing, "
755 "disabling texture tiling");
756 intel->use_texture_tiling = GL_FALSE;
758 intel->use_early_z = driQueryOptionb(&intel->optionCache, "early_z");
760 intel->prim.primitive = ~0;
762 /* Force all software fallbacks */
763 if (driQueryOptionb(&intel->optionCache, "no_rast")) {
764 fprintf(stderr, "disabling 3D rasterization\n");
768 if (driQueryOptionb(&intel->optionCache, "always_flush_batch")) {
769 fprintf(stderr, "flushing batchbuffer before/after each draw call\n");
770 intel->always_flush_batch = 1;
773 if (driQueryOptionb(&intel->optionCache, "always_flush_cache")) {
774 fprintf(stderr, "flushing GPU caches before/after each draw call\n");
775 intel->always_flush_cache = 1;
778 /* Disable all hardware rendering (skip emitting batches and fences/waits
781 intel->no_hw = getenv("INTEL_NO_HW") != NULL;
787 intelDestroyContext(__DRIcontextPrivate * driContextPriv)
789 struct intel_context *intel =
790 (struct intel_context *) driContextPriv->driverPrivate;
792 assert(intel); /* should never be null */
794 GLboolean release_texture_heaps;
796 INTEL_FIREVERTICES(intel);
798 meta_destroy_metaops(&intel->meta);
800 intel->vtbl.destroy(intel);
802 release_texture_heaps = (intel->ctx.Shared->RefCount == 1);
803 _swsetup_DestroyContext(&intel->ctx);
804 _tnl_DestroyContext(&intel->ctx);
805 _vbo_DestroyContext(&intel->ctx);
807 _swrast_DestroyContext(&intel->ctx);
808 intel->Fallback = 0; /* don't call _swrast_Flush later */
810 intel_batchbuffer_free(intel->batch);
813 free(intel->prim.vb);
814 intel->prim.vb = NULL;
815 dri_bo_unreference(intel->prim.vb_bo);
816 intel->prim.vb_bo = NULL;
818 if (release_texture_heaps) {
819 /* Nothing is currently done here to free texture heaps;
820 * but we're not using the texture heap utilities, so I
821 * rather think we shouldn't. I've taken a look, and can't
822 * find any private texture data hanging around anywhere, but
823 * I'm not yet certain there isn't any at all...
825 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
826 fprintf(stderr, "do something to free texture heaps\n");
830 /* XXX In intelMakeCurrent() below, the context's static regions are
831 * referenced inside the frame buffer; it's listed as a hack,
832 * with a comment of "XXX FBO temporary fix-ups!", but
833 * as long as it's there, we should release the regions here.
834 * The do/while loop around the block is used to allow the
835 * "continue" statements inside the block to exit the block,
836 * to avoid many layers of "if" constructs.
839 __DRIdrawablePrivate * driDrawPriv = intel->driDrawable;
840 struct intel_framebuffer *intel_fb;
841 struct intel_renderbuffer *irbDepth, *irbStencil;
843 /* We're already detached from the drawable; exit this block. */
846 intel_fb = (struct intel_framebuffer *) driDrawPriv->driverPrivate;
848 /* The frame buffer is already gone; exit this block. */
851 irbDepth = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
852 irbStencil = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
854 /* If the regions of the frame buffer still match the regions
855 * of the context, release them. If they've changed somehow,
858 if (intel_fb->color_rb[0] && intel_fb->color_rb[0]->region == intel->front_region) {
859 intel_renderbuffer_set_region(intel_fb->color_rb[0], NULL);
861 if (intel_fb->color_rb[1] && intel_fb->color_rb[1]->region == intel->back_region) {
862 intel_renderbuffer_set_region(intel_fb->color_rb[1], NULL);
865 if (irbDepth && irbDepth->region == intel->depth_region) {
866 intel_renderbuffer_set_region(irbDepth, NULL);
868 /* Usually, the stencil buffer is the same as the depth buffer;
869 * but they're handled separately in MakeCurrent, so we'll
870 * handle them separately here.
872 if (irbStencil && irbStencil->region == intel->depth_region) {
873 intel_renderbuffer_set_region(irbStencil, NULL);
877 intel_region_release(&intel->front_region);
878 intel_region_release(&intel->back_region);
879 intel_region_release(&intel->depth_region);
881 driDestroyOptionCache(&intel->optionCache);
883 /* free the Mesa context */
884 _mesa_free_context_data(&intel->ctx);
887 driContextPriv->driverPrivate = NULL;
892 intelUnbindContext(__DRIcontextPrivate * driContextPriv)
898 intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
899 __DRIdrawablePrivate * driDrawPriv,
900 __DRIdrawablePrivate * driReadPriv)
902 __DRIscreenPrivate *psp = driDrawPriv->driScreenPriv;
904 if (driContextPriv) {
905 struct intel_context *intel =
906 (struct intel_context *) driContextPriv->driverPrivate;
907 struct intel_framebuffer *intel_fb =
908 (struct intel_framebuffer *) driDrawPriv->driverPrivate;
909 GLframebuffer *readFb = (GLframebuffer *) driReadPriv->driverPrivate;
911 if (driContextPriv->driScreenPriv->dri2.enabled) {
912 intel_update_renderbuffers(driContextPriv, driDrawPriv);
913 if (driDrawPriv != driReadPriv)
914 intel_update_renderbuffers(driContextPriv, driReadPriv);
916 /* XXX FBO temporary fix-ups! These are released in
917 * intelDextroyContext(), above. Changes here should be
920 /* if the renderbuffers don't have regions, init them from the context */
921 struct intel_renderbuffer *irbDepth
922 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
923 struct intel_renderbuffer *irbStencil
924 = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
926 if (intel_fb->color_rb[0]) {
927 intel_renderbuffer_set_region(intel_fb->color_rb[0],
928 intel->front_region);
930 if (intel_fb->color_rb[1]) {
931 intel_renderbuffer_set_region(intel_fb->color_rb[1],
936 intel_renderbuffer_set_region(irbDepth, intel->depth_region);
939 intel_renderbuffer_set_region(irbStencil, intel->depth_region);
943 /* set GLframebuffer size to match window, if needed */
944 driUpdateFramebufferSize(&intel->ctx, driDrawPriv);
946 if (driReadPriv != driDrawPriv) {
947 driUpdateFramebufferSize(&intel->ctx, driReadPriv);
950 _mesa_make_current(&intel->ctx, &intel_fb->Base, readFb);
952 /* The drawbuffer won't always be updated by _mesa_make_current:
954 if (intel->ctx.DrawBuffer == &intel_fb->Base) {
956 if (intel->driReadDrawable != driReadPriv)
957 intel->driReadDrawable = driReadPriv;
959 if (intel->driDrawable != driDrawPriv) {
960 if (driDrawPriv->swap_interval == (unsigned)-1) {
963 driDrawPriv->vblFlags = (intel->intelScreen->irq_active != 0)
964 ? driGetDefaultVBlankFlags(&intel->optionCache)
965 : VBLANK_FLAG_NO_IRQ;
967 /* Prevent error printf if one crtc is disabled, this will
968 * be properly calculated in intelWindowMoved() next.
970 driDrawPriv->vblFlags = intelFixupVblank(intel, driDrawPriv);
972 (*psp->systemTime->getUST) (&intel_fb->swap_ust);
973 driDrawableInitVBlank(driDrawPriv);
974 intel_fb->vbl_waited = driDrawPriv->vblSeq;
976 for (i = 0; i < 2; i++) {
977 if (intel_fb->color_rb[i])
978 intel_fb->color_rb[i]->vbl_pending = driDrawPriv->vblSeq;
981 intel->driDrawable = driDrawPriv;
982 intelWindowMoved(intel);
985 intel_draw_buffer(&intel->ctx, &intel_fb->Base);
989 _mesa_make_current(NULL, NULL, NULL);
996 intelContendedLock(struct intel_context *intel, GLuint flags)
998 __DRIdrawablePrivate *dPriv = intel->driDrawable;
999 __DRIscreenPrivate *sPriv = intel->driScreen;
1000 volatile drm_i915_sarea_t *sarea = intel->sarea;
1001 int me = intel->hHWContext;
1003 drmGetLock(intel->driFd, intel->hHWContext, flags);
1005 if (INTEL_DEBUG & DEBUG_LOCK)
1006 _mesa_printf("%s - got contended lock\n", __progname);
1008 /* If the window moved, may need to set a new cliprect now.
1010 * NOTE: This releases and regains the hw lock, so all state
1011 * checking must be done *after* this call:
1014 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
1016 if (sarea && sarea->ctxOwner != me) {
1017 if (INTEL_DEBUG & DEBUG_BUFMGR) {
1018 fprintf(stderr, "Lost Context: sarea->ctxOwner %x me %x\n",
1019 sarea->ctxOwner, me);
1021 sarea->ctxOwner = me;
1024 /* If the last consumer of the texture memory wasn't us, notify the fake
1025 * bufmgr and record the new owner. We should have the memory shared
1026 * between contexts of a single fake bufmgr, but this will at least make
1027 * things correct for now.
1029 if (!intel->ttm && sarea->texAge != intel->hHWContext) {
1030 sarea->texAge = intel->hHWContext;
1031 intel_bufmgr_fake_contended_lock_take(intel->bufmgr);
1032 if (INTEL_DEBUG & DEBUG_BATCH)
1033 intel_decode_context_reset();
1034 if (INTEL_DEBUG & DEBUG_BUFMGR)
1035 fprintf(stderr, "Lost Textures: sarea->texAge %x hw context %x\n",
1036 sarea->ctxOwner, intel->hHWContext);
1039 /* Drawable changed?
1041 if (dPriv && intel->lastStamp != dPriv->lastStamp) {
1042 intelWindowMoved(intel);
1043 intel->lastStamp = dPriv->lastStamp;
1048 _glthread_DECLARE_STATIC_MUTEX(lockMutex);
1050 /* Lock the hardware and validate our state.
1052 void LOCK_HARDWARE( struct intel_context *intel )
1054 __DRIdrawable *dPriv = intel->driDrawable;
1055 __DRIscreen *sPriv = intel->driScreen;
1057 struct intel_framebuffer *intel_fb = NULL;
1058 struct intel_renderbuffer *intel_rb = NULL;
1061 if (intel->locked >= 2)
1064 if (!sPriv->dri2.enabled)
1065 _glthread_LOCK_MUTEX(lockMutex);
1067 if (intel->driDrawable) {
1068 intel_fb = intel->driDrawable->driverPrivate;
1072 intel_get_renderbuffer(&intel_fb->Base,
1073 intel_fb->Base._ColorDrawBufferIndexes[0]);
1076 if (intel_rb && dPriv->vblFlags &&
1077 !(dPriv->vblFlags & VBLANK_FLAG_NO_IRQ) &&
1078 (intel_fb->vbl_waited - intel_rb->vbl_pending) > (1<<23)) {
1081 vbl.request.type = DRM_VBLANK_ABSOLUTE;
1083 if ( dPriv->vblFlags & VBLANK_FLAG_SECONDARY ) {
1084 vbl.request.type |= DRM_VBLANK_SECONDARY;
1087 vbl.request.sequence = intel_rb->vbl_pending;
1088 drmWaitVBlank(intel->driFd, &vbl);
1089 intel_fb->vbl_waited = vbl.reply.sequence;
1092 if (!sPriv->dri2.enabled) {
1093 DRM_CAS(intel->driHwLock, intel->hHWContext,
1094 (DRM_LOCK_HELD|intel->hHWContext), __ret);
1097 intelContendedLock( intel, 0 );
1101 if (INTEL_DEBUG & DEBUG_LOCK)
1102 _mesa_printf("%s - locked\n", __progname);
1106 /* Unlock the hardware using the global current context
1108 void UNLOCK_HARDWARE( struct intel_context *intel )
1110 __DRIscreen *sPriv = intel->driScreen;
1113 if (intel->locked > 0)
1116 assert(intel->locked == 0);
1118 if (!sPriv->dri2.enabled) {
1119 DRM_UNLOCK(intel->driFd, intel->driHwLock, intel->hHWContext);
1120 _glthread_UNLOCK_MUTEX(lockMutex);
1123 if (INTEL_DEBUG & DEBUG_LOCK)
1124 _mesa_printf("%s - unlocked\n", __progname);
1127 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1130 if (intel->batch->cliprect_mode == REFERENCES_CLIPRECTS)
1131 intel_batchbuffer_flush(intel->batch);