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/extensions.h"
32 #include "main/fbobject.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"
41 #include "drivers/common/meta.h"
43 #include "intel_chipset.h"
44 #include "intel_buffers.h"
45 #include "intel_tex.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_clear.h"
48 #include "intel_extensions.h"
49 #include "intel_pixel.h"
50 #include "intel_regions.h"
51 #include "intel_buffer_objects.h"
52 #include "intel_fbo.h"
53 #include "intel_bufmgr.h"
54 #include "intel_screen.h"
56 #include "drirenderbuffer.h"
61 int INTEL_DEBUG = (0);
65 #define DRIVER_DATE "20100330 DEVELOPMENT"
66 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
69 static const GLubyte *
70 intelGetString(GLcontext * ctx, GLenum name)
72 const struct intel_context *const intel = intel_context(ctx);
74 static char buffer[128];
78 return (GLubyte *) "Tungsten Graphics, Inc";
82 switch (intel->intelScreen->deviceID) {
84 chipset = "Intel(R) 845G";
87 chipset = "Intel(R) 830M";
89 case PCI_CHIP_I855_GM:
90 chipset = "Intel(R) 852GM/855GM";
93 chipset = "Intel(R) 865G";
96 chipset = "Intel(R) 915G";
98 case PCI_CHIP_E7221_G:
99 chipset = "Intel (R) E7221G (i915)";
101 case PCI_CHIP_I915_GM:
102 chipset = "Intel(R) 915GM";
104 case PCI_CHIP_I945_G:
105 chipset = "Intel(R) 945G";
107 case PCI_CHIP_I945_GM:
108 chipset = "Intel(R) 945GM";
110 case PCI_CHIP_I945_GME:
111 chipset = "Intel(R) 945GME";
114 chipset = "Intel(R) G33";
117 chipset = "Intel(R) Q35";
120 chipset = "Intel(R) Q33";
122 case PCI_CHIP_IGD_GM:
124 chipset = "Intel(R) IGD";
126 case PCI_CHIP_I965_Q:
127 chipset = "Intel(R) 965Q";
129 case PCI_CHIP_I965_G:
130 case PCI_CHIP_I965_G_1:
131 chipset = "Intel(R) 965G";
133 case PCI_CHIP_I946_GZ:
134 chipset = "Intel(R) 946GZ";
136 case PCI_CHIP_I965_GM:
137 chipset = "Intel(R) 965GM";
139 case PCI_CHIP_I965_GME:
140 chipset = "Intel(R) 965GME/GLE";
142 case PCI_CHIP_GM45_GM:
143 chipset = "Mobile IntelĀ® GM45 Express Chipset";
145 case PCI_CHIP_IGD_E_G:
146 chipset = "Intel(R) Integrated Graphics Device";
149 chipset = "Intel(R) G45/G43";
152 chipset = "Intel(R) Q45/Q43";
155 chipset = "Intel(R) G41";
158 chipset = "Intel(R) B43";
161 chipset = "Intel(R) Ironlake Desktop";
164 chipset = "Intel(R) Ironlake Mobile";
167 chipset = "Unknown Intel Chipset";
171 (void) driGetRendererString(buffer, chipset, DRIVER_DATE_GEM, 0);
172 return (GLubyte *) buffer;
180 intel_flush_front(GLcontext *ctx)
182 struct intel_context *intel = intel_context(ctx);
183 __DRIcontext *driContext = intel->driContext;
184 __DRIscreen *const screen = intel->intelScreen->driScrnPriv;
186 if ((ctx->DrawBuffer->Name == 0) && intel->front_buffer_dirty) {
187 if (screen->dri2.loader &&
188 (screen->dri2.loader->base.version >= 2)
189 && (screen->dri2.loader->flushFrontBuffer != NULL) &&
190 driContext->driDrawablePriv &&
191 driContext->driDrawablePriv->loaderPrivate) {
192 (*screen->dri2.loader->flushFrontBuffer)(driContext->driDrawablePriv,
193 driContext->driDrawablePriv->loaderPrivate);
195 /* We set the dirty bit in intel_prepare_render() if we're
196 * front buffer rendering once we get there.
198 intel->front_buffer_dirty = GL_FALSE;
204 intel_bits_per_pixel(const struct intel_renderbuffer *rb)
206 return _mesa_get_format_bytes(rb->Base.Format) * 8;
210 intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
212 struct gl_framebuffer *fb = drawable->driverPrivate;
213 struct intel_renderbuffer *rb;
214 struct intel_region *region, *depth_region;
215 struct intel_context *intel = context->driverPrivate;
216 struct intel_renderbuffer *front_rb, *back_rb, *depth_rb, *stencil_rb;
217 __DRIbuffer *buffers = NULL;
220 unsigned int attachments[10];
221 const char *region_name;
223 /* If we're rendering to the fake front buffer, make sure all the
224 * pending drawing has landed on the real front buffer. Otherwise
225 * when we eventually get to DRI2GetBuffersWithFormat the stale
226 * real front buffer contents will get copied to the new fake front
229 if (intel->is_front_buffer_rendering) {
230 intel_flush(&intel->ctx);
231 intel_flush_front(&intel->ctx);
234 /* Set this up front, so that in case our buffers get invalidated
235 * while we're getting new buffers, we don't clobber the stamp and
236 * thus ignore the invalidate. */
237 drawable->lastStamp = drawable->dri2.stamp;
239 if (INTEL_DEBUG & DEBUG_DRI)
240 fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
242 screen = intel->intelScreen->driScrnPriv;
244 if (screen->dri2.loader
245 && (screen->dri2.loader->base.version > 2)
246 && (screen->dri2.loader->getBuffersWithFormat != NULL)) {
248 front_rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
249 back_rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
250 depth_rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
251 stencil_rb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
254 if ((intel->is_front_buffer_rendering ||
255 intel->is_front_buffer_reading ||
256 !back_rb) && front_rb) {
257 attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
258 attachments[i++] = intel_bits_per_pixel(front_rb);
262 attachments[i++] = __DRI_BUFFER_BACK_LEFT;
263 attachments[i++] = intel_bits_per_pixel(back_rb);
266 if ((depth_rb != NULL) && (stencil_rb != NULL)) {
267 attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
268 attachments[i++] = intel_bits_per_pixel(depth_rb);
269 } else if (depth_rb != NULL) {
270 attachments[i++] = __DRI_BUFFER_DEPTH;
271 attachments[i++] = intel_bits_per_pixel(depth_rb);
272 } else if (stencil_rb != NULL) {
273 attachments[i++] = __DRI_BUFFER_STENCIL;
274 attachments[i++] = intel_bits_per_pixel(stencil_rb);
278 (*screen->dri2.loader->getBuffersWithFormat)(drawable,
283 drawable->loaderPrivate);
284 } else if (screen->dri2.loader) {
286 if (intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT))
287 attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
288 if (intel_get_renderbuffer(fb, BUFFER_BACK_LEFT))
289 attachments[i++] = __DRI_BUFFER_BACK_LEFT;
290 if (intel_get_renderbuffer(fb, BUFFER_DEPTH))
291 attachments[i++] = __DRI_BUFFER_DEPTH;
292 if (intel_get_renderbuffer(fb, BUFFER_STENCIL))
293 attachments[i++] = __DRI_BUFFER_STENCIL;
295 buffers = (*screen->dri2.loader->getBuffers)(drawable,
300 drawable->loaderPrivate);
310 drawable->numClipRects = 1;
311 drawable->pClipRects[0].x1 = 0;
312 drawable->pClipRects[0].y1 = 0;
313 drawable->pClipRects[0].x2 = drawable->w;
314 drawable->pClipRects[0].y2 = drawable->h;
315 drawable->numBackClipRects = 1;
316 drawable->pBackClipRects[0].x1 = 0;
317 drawable->pBackClipRects[0].y1 = 0;
318 drawable->pBackClipRects[0].x2 = drawable->w;
319 drawable->pBackClipRects[0].y2 = drawable->h;
322 for (i = 0; i < count; i++) {
323 switch (buffers[i].attachment) {
324 case __DRI_BUFFER_FRONT_LEFT:
325 rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
326 region_name = "dri2 front buffer";
329 case __DRI_BUFFER_FAKE_FRONT_LEFT:
330 rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
331 region_name = "dri2 fake front buffer";
334 case __DRI_BUFFER_BACK_LEFT:
335 rb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
336 region_name = "dri2 back buffer";
339 case __DRI_BUFFER_DEPTH:
340 rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
341 region_name = "dri2 depth buffer";
344 case __DRI_BUFFER_DEPTH_STENCIL:
345 rb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
346 region_name = "dri2 depth / stencil buffer";
349 case __DRI_BUFFER_STENCIL:
350 rb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
351 region_name = "dri2 stencil buffer";
354 case __DRI_BUFFER_ACCUM:
357 "unhandled buffer attach event, attacment type %d\n",
358 buffers[i].attachment);
365 if (rb->region && rb->region->name == buffers[i].name)
368 if (INTEL_DEBUG & DEBUG_DRI)
370 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
371 buffers[i].name, buffers[i].attachment,
372 buffers[i].cpp, buffers[i].pitch);
374 if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_region) {
375 if (INTEL_DEBUG & DEBUG_DRI)
376 fprintf(stderr, "(reusing depth buffer as stencil)\n");
377 intel_region_reference(®ion, depth_region);
380 region = intel_region_alloc_for_handle(intel, buffers[i].cpp,
383 buffers[i].pitch / buffers[i].cpp,
387 if (buffers[i].attachment == __DRI_BUFFER_DEPTH)
388 depth_region = region;
390 intel_renderbuffer_set_region(intel, rb, region);
391 intel_region_release(®ion);
393 if (buffers[i].attachment == __DRI_BUFFER_DEPTH_STENCIL) {
394 rb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
396 struct intel_region *stencil_region = NULL;
398 if (rb->region && rb->region->name == buffers[i].name)
401 intel_region_reference(&stencil_region, region);
402 intel_renderbuffer_set_region(intel, rb, stencil_region);
403 intel_region_release(&stencil_region);
408 driUpdateFramebufferSize(&intel->ctx, drawable);
412 * intel_prepare_render should be called anywhere that curent read/drawbuffer
416 intel_prepare_render(struct intel_context *intel)
418 __DRIcontext *driContext = intel->driContext;
419 __DRIdrawable *drawable;
421 drawable = driContext->driDrawablePriv;
422 if (drawable && drawable->dri2.stamp != driContext->dri2.draw_stamp) {
423 if (drawable->lastStamp != drawable->dri2.stamp)
424 intel_update_renderbuffers(driContext, drawable);
425 intel_draw_buffer(&intel->ctx, intel->ctx.DrawBuffer);
426 driContext->dri2.draw_stamp = drawable->dri2.stamp;
429 drawable = driContext->driReadablePriv;
430 if (drawable && drawable->dri2.stamp != driContext->dri2.read_stamp) {
431 if (drawable->lastStamp != drawable->dri2.stamp)
432 intel_update_renderbuffers(driContext, drawable);
433 driContext->dri2.read_stamp = drawable->dri2.stamp;
436 /* If we're currently rendering to the front buffer, the rendering
437 * that will happen next will probably dirty the front buffer. So
438 * mark it as dirty here.
440 if (intel->is_front_buffer_rendering)
441 intel->front_buffer_dirty = GL_TRUE;
443 /* Wait for the swapbuffers before the one we just emitted, so we
444 * don't get too many swaps outstanding for apps that are GPU-heavy
447 * We're using intelDRI2Flush (called from the loader before
448 * swapbuffer) and glFlush (for front buffer rendering) as the
449 * indicator that a frame is done and then throttle when we get
450 * here as we prepare to render the next frame. At this point for
451 * round trips for swap/copy and getting new buffers are done and
452 * we'll spend less time waiting on the GPU.
454 * Unfortunately, we don't have a handle to the batch containing
455 * the swap, and getting our hands on that doesn't seem worth it,
456 * so we just us the first batch we emitted after the last swap.
458 if (intel->need_throttle && intel->first_post_swapbuffers_batch) {
459 drm_intel_bo_wait_rendering(intel->first_post_swapbuffers_batch);
460 drm_intel_bo_unreference(intel->first_post_swapbuffers_batch);
461 intel->first_post_swapbuffers_batch = NULL;
462 intel->need_throttle = GL_FALSE;
467 intel_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
469 struct intel_context *intel = intel_context(ctx);
470 __DRIcontext *driContext = intel->driContext;
472 if (intel->saved_viewport)
473 intel->saved_viewport(ctx, x, y, w, h);
475 if (!intel->meta.internal_viewport_call && ctx->DrawBuffer->Name == 0) {
476 dri2InvalidateDrawable(driContext->driDrawablePriv);
477 dri2InvalidateDrawable(driContext->driReadablePriv);
481 static const struct dri_debug_control debug_control[] = {
482 { "tex", DEBUG_TEXTURE},
483 { "state", DEBUG_STATE},
484 { "ioctl", DEBUG_IOCTL},
485 { "blit", DEBUG_BLIT},
486 { "mip", DEBUG_MIPTREE},
487 { "fall", DEBUG_FALLBACKS},
488 { "verb", DEBUG_VERBOSE},
489 { "bat", DEBUG_BATCH},
490 { "pix", DEBUG_PIXEL},
491 { "buf", DEBUG_BUFMGR},
492 { "reg", DEBUG_REGION},
495 { "sync", DEBUG_SYNC},
496 { "prim", DEBUG_PRIMS },
497 { "vert", DEBUG_VERTS },
498 { "dri", DEBUG_DRI },
500 { "san", DEBUG_SANITY },
501 { "sleep", DEBUG_SLEEP },
502 { "stats", DEBUG_STATS },
503 { "tile", DEBUG_TILE },
504 { "sing", DEBUG_SINGLE_THREAD },
505 { "thre", DEBUG_SINGLE_THREAD },
507 { "glsl_force", DEBUG_GLSL_FORCE },
508 { "urb", DEBUG_URB },
510 { "clip", DEBUG_CLIP },
516 intelInvalidateState(GLcontext * ctx, GLuint new_state)
518 struct intel_context *intel = intel_context(ctx);
520 _swrast_InvalidateState(ctx, new_state);
521 _swsetup_InvalidateState(ctx, new_state);
522 _vbo_InvalidateState(ctx, new_state);
523 _tnl_InvalidateState(ctx, new_state);
524 _tnl_invalidate_vertex_state(ctx, new_state);
526 intel->NewGLState |= new_state;
528 if (intel->vtbl.invalidate_state)
529 intel->vtbl.invalidate_state( intel, new_state );
533 intel_flush(GLcontext *ctx)
535 struct intel_context *intel = intel_context(ctx);
541 INTEL_FIREVERTICES(intel);
543 if (intel->batch->map != intel->batch->ptr)
544 intel_batchbuffer_flush(intel->batch);
548 intel_glFlush(GLcontext *ctx)
550 struct intel_context *intel = intel_context(ctx);
553 intel_flush_front(ctx);
554 intel->need_throttle = GL_TRUE;
558 intelFinish(GLcontext * ctx)
560 struct gl_framebuffer *fb = ctx->DrawBuffer;
564 intel_flush_front(ctx);
566 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
567 struct intel_renderbuffer *irb;
569 irb = intel_renderbuffer(fb->_ColorDrawBuffers[i]);
571 if (irb && irb->region)
572 drm_intel_bo_wait_rendering(irb->region->buffer);
574 if (fb->_DepthBuffer) {
575 /* XXX: Wait on buffer idle */
580 intelInitDriverFunctions(struct dd_function_table *functions)
582 _mesa_init_driver_functions(functions);
584 functions->Flush = intel_glFlush;
585 functions->Finish = intelFinish;
586 functions->GetString = intelGetString;
587 functions->UpdateState = intelInvalidateState;
589 intelInitTextureFuncs(functions);
590 intelInitTextureImageFuncs(functions);
591 intelInitTextureSubImageFuncs(functions);
592 intelInitTextureCopyImageFuncs(functions);
593 intelInitStateFuncs(functions);
594 intelInitClearFuncs(functions);
595 intelInitBufferFuncs(functions);
596 intelInitPixelFuncs(functions);
597 intelInitBufferObjectFuncs(functions);
598 intel_init_syncobj_functions(functions);
603 intelInitContext(struct intel_context *intel,
605 const __GLcontextModes * mesaVis,
606 __DRIcontext * driContextPriv,
607 void *sharedContextPrivate,
608 struct dd_function_table *functions)
610 GLcontext *ctx = &intel->ctx;
611 GLcontext *shareCtx = (GLcontext *) sharedContextPrivate;
612 __DRIscreen *sPriv = driContextPriv->driScreenPriv;
613 struct intel_screen *intelScreen = sPriv->private;
615 __GLcontextModes visual;
617 /* we can't do anything without a connection to the device */
618 if (intelScreen->bufmgr == NULL)
621 /* Can't rely on invalidate events, fall back to glViewport hack */
622 if (!driContextPriv->driScreenPriv->dri2.useInvalidate) {
623 intel->saved_viewport = functions->Viewport;
624 functions->Viewport = intel_viewport;
627 if (mesaVis == NULL) {
628 memset(&visual, 0, sizeof visual);
632 if (!_mesa_initialize_context_for_api(&intel->ctx, api, mesaVis, shareCtx,
633 functions, (void *) intel)) {
634 printf("%s: failed to init mesa context\n", __FUNCTION__);
638 driContextPriv->driverPrivate = intel;
639 intel->intelScreen = intelScreen;
640 intel->driContext = driContextPriv;
641 intel->driFd = sPriv->fd;
643 intel->has_xrgb_textures = GL_TRUE;
644 if (IS_GEN6(intel->intelScreen->deviceID)) {
646 intel->needs_ff_sync = GL_TRUE;
647 intel->has_luminance_srgb = GL_TRUE;
648 } else if (IS_GEN5(intel->intelScreen->deviceID)) {
650 intel->needs_ff_sync = GL_TRUE;
651 intel->has_luminance_srgb = GL_TRUE;
652 } else if (IS_965(intel->intelScreen->deviceID)) {
654 if (IS_G4X(intel->intelScreen->deviceID)) {
655 intel->has_luminance_srgb = GL_TRUE;
656 intel->is_g4x = GL_TRUE;
658 } else if (IS_9XX(intel->intelScreen->deviceID)) {
660 if (IS_945(intel->intelScreen->deviceID)) {
661 intel->is_945 = GL_TRUE;
665 if (intel->intelScreen->deviceID == PCI_CHIP_I830_M ||
666 intel->intelScreen->deviceID == PCI_CHIP_845_G) {
667 intel->has_xrgb_textures = GL_FALSE;
671 driParseConfigFiles(&intel->optionCache, &intelScreen->optionCache,
672 sPriv->myNum, (intel->gen >= 4) ? "i965" : "i915");
673 if (intelScreen->deviceID == PCI_CHIP_I865_G)
674 intel->maxBatchSize = 4096;
676 intel->maxBatchSize = BATCH_SZ;
678 intel->bufmgr = intelScreen->bufmgr;
680 bo_reuse_mode = driQueryOptioni(&intel->optionCache, "bo_reuse");
681 switch (bo_reuse_mode) {
682 case DRI_CONF_BO_REUSE_DISABLED:
684 case DRI_CONF_BO_REUSE_ALL:
685 intel_bufmgr_gem_enable_reuse(intel->bufmgr);
689 /* This doesn't yet catch all non-conformant rendering, but it's a
692 if (getenv("INTEL_STRICT_CONFORMANCE")) {
693 unsigned int value = atoi(getenv("INTEL_STRICT_CONFORMANCE"));
695 intel->conformance_mode = value;
698 intel->conformance_mode = 1;
702 if (intel->conformance_mode > 0) {
703 ctx->Const.MinLineWidth = 1.0;
704 ctx->Const.MinLineWidthAA = 1.0;
705 ctx->Const.MaxLineWidth = 1.0;
706 ctx->Const.MaxLineWidthAA = 1.0;
707 ctx->Const.LineWidthGranularity = 1.0;
710 ctx->Const.MinLineWidth = 1.0;
711 ctx->Const.MinLineWidthAA = 1.0;
712 ctx->Const.MaxLineWidth = 5.0;
713 ctx->Const.MaxLineWidthAA = 5.0;
714 ctx->Const.LineWidthGranularity = 0.5;
717 ctx->Const.MinPointSize = 1.0;
718 ctx->Const.MinPointSizeAA = 1.0;
719 ctx->Const.MaxPointSize = 255.0;
720 ctx->Const.MaxPointSizeAA = 3.0;
721 ctx->Const.PointSizeGranularity = 1.0;
723 /* reinitialize the context point state.
724 * It depend on constants in __GLcontextRec::Const
726 _mesa_init_point(ctx);
728 meta_init_metaops(ctx, &intel->meta);
729 if (intel->gen >= 4) {
730 if (MAX_WIDTH > 8192)
731 ctx->Const.MaxRenderbufferSize = 8192;
733 if (MAX_WIDTH > 2048)
734 ctx->Const.MaxRenderbufferSize = 2048;
737 /* Initialize the software rasterizer and helper modules. */
738 _swrast_CreateContext(ctx);
739 _vbo_CreateContext(ctx);
740 _tnl_CreateContext(ctx);
741 _swsetup_CreateContext(ctx);
743 /* Configure swrast to match hardware characteristics: */
744 _swrast_allow_pixel_fog(ctx, GL_FALSE);
745 _swrast_allow_vertex_fog(ctx, GL_TRUE);
747 _mesa_meta_init(ctx);
749 intel->hw_stencil = mesaVis->stencilBits && mesaVis->depthBits == 24;
750 intel->hw_stipple = 1;
752 /* XXX FBO: this doesn't seem to be used anywhere */
753 switch (mesaVis->depthBits) {
754 case 0: /* what to do in this case? */
756 intel->polygon_offset_scale = 1.0;
759 intel->polygon_offset_scale = 2.0; /* req'd to pass glean */
767 intel->polygon_offset_scale /= 0xffff;
769 intel->RenderIndex = ~0;
773 intelInitExtensions(ctx);
778 intelInitExtensionsES2(ctx);
782 INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
783 if (INTEL_DEBUG & DEBUG_BUFMGR)
784 dri_bufmgr_set_debug(intel->bufmgr, GL_TRUE);
786 intel->batch = intel_batchbuffer_alloc(intel);
788 intel_fbo_init(intel);
790 if (intel->ctx.Mesa_DXTn) {
791 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
792 _mesa_enable_extension(ctx, "GL_S3_s3tc");
794 else if (driQueryOptionb(&intel->optionCache, "force_s3tc_enable")) {
795 _mesa_enable_extension(ctx, "GL_EXT_texture_compression_s3tc");
797 intel->use_texture_tiling = driQueryOptionb(&intel->optionCache,
799 intel->use_early_z = driQueryOptionb(&intel->optionCache, "early_z");
801 intel->prim.primitive = ~0;
803 /* Force all software fallbacks */
804 if (driQueryOptionb(&intel->optionCache, "no_rast")) {
805 fprintf(stderr, "disabling 3D rasterization\n");
809 if (driQueryOptionb(&intel->optionCache, "always_flush_batch")) {
810 fprintf(stderr, "flushing batchbuffer before/after each draw call\n");
811 intel->always_flush_batch = 1;
814 if (driQueryOptionb(&intel->optionCache, "always_flush_cache")) {
815 fprintf(stderr, "flushing GPU caches before/after each draw call\n");
816 intel->always_flush_cache = 1;
819 /* Disable all hardware rendering (skip emitting batches and fences/waits
822 intel->no_hw = getenv("INTEL_NO_HW") != NULL;
828 intelDestroyContext(__DRIcontext * driContextPriv)
830 struct intel_context *intel =
831 (struct intel_context *) driContextPriv->driverPrivate;
833 assert(intel); /* should never be null */
835 INTEL_FIREVERTICES(intel);
837 _mesa_meta_free(&intel->ctx);
839 meta_destroy_metaops(&intel->meta);
841 intel->vtbl.destroy(intel);
843 _swsetup_DestroyContext(&intel->ctx);
844 _tnl_DestroyContext(&intel->ctx);
845 _vbo_DestroyContext(&intel->ctx);
847 _swrast_DestroyContext(&intel->ctx);
848 intel->Fallback = 0x0; /* don't call _swrast_Flush later */
850 intel_batchbuffer_free(intel->batch);
853 free(intel->prim.vb);
854 intel->prim.vb = NULL;
855 drm_intel_bo_unreference(intel->prim.vb_bo);
856 intel->prim.vb_bo = NULL;
857 drm_intel_bo_unreference(intel->first_post_swapbuffers_batch);
858 intel->first_post_swapbuffers_batch = NULL;
860 driDestroyOptionCache(&intel->optionCache);
862 /* free the Mesa context */
863 _mesa_free_context_data(&intel->ctx);
866 driContextPriv->driverPrivate = NULL;
871 intelUnbindContext(__DRIcontext * driContextPriv)
877 intelMakeCurrent(__DRIcontext * driContextPriv,
878 __DRIdrawable * driDrawPriv,
879 __DRIdrawable * driReadPriv)
881 struct intel_context *intel;
882 GET_CURRENT_CONTEXT(curCtx);
885 intel = (struct intel_context *) driContextPriv->driverPrivate;
889 /* According to the glXMakeCurrent() man page: "Pending commands to
890 * the previous context, if any, are flushed before it is released."
891 * But only flush if we're actually changing contexts.
893 if (intel_context(curCtx) && intel_context(curCtx) != intel) {
897 if (driContextPriv) {
898 struct gl_framebuffer *fb, *readFb;
900 if (driDrawPriv == NULL && driReadPriv == NULL) {
901 fb = _mesa_get_incomplete_framebuffer();
902 readFb = _mesa_get_incomplete_framebuffer();
904 fb = driDrawPriv->driverPrivate;
905 readFb = driReadPriv->driverPrivate;
906 driContextPriv->dri2.draw_stamp = driDrawPriv->dri2.stamp - 1;
907 driContextPriv->dri2.read_stamp = driReadPriv->dri2.stamp - 1;
910 intel_prepare_render(intel);
911 _mesa_make_current(&intel->ctx, fb, readFb);
913 /* We do this in intel_prepare_render() too, but intel->ctx.DrawBuffer
914 * is NULL at that point. We can't call _mesa_makecurrent()
915 * first, since we need the buffer size for the initial
916 * viewport. So just call intel_draw_buffer() again here. */
917 intel_draw_buffer(&intel->ctx, intel->ctx.DrawBuffer);
920 _mesa_make_current(NULL, NULL, NULL);