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"
41 #include "drivers/common/meta.h"
45 #include "intel_chipset.h"
46 #include "intel_buffers.h"
47 #include "intel_tex.h"
48 #include "intel_batchbuffer.h"
49 #include "intel_clear.h"
50 #include "intel_extensions.h"
51 #include "intel_pixel.h"
52 #include "intel_regions.h"
53 #include "intel_buffer_objects.h"
54 #include "intel_fbo.h"
55 #include "intel_decode.h"
56 #include "intel_bufmgr.h"
57 #include "intel_screen.h"
59 #include "drirenderbuffer.h"
61 #include "xmlpool.h" /* for symbolic values of enum-type options */
65 int INTEL_DEBUG
= (0);
69 #define DRIVER_DATE "20091221 DEVELOPMENT"
70 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
73 static const GLubyte
*
74 intelGetString(GLcontext
* ctx
, GLenum name
)
76 const struct intel_context
*const intel
= intel_context(ctx
);
78 static char buffer
[128];
82 return (GLubyte
*) "Tungsten Graphics, Inc";
86 switch (intel
->intelScreen
->deviceID
) {
88 chipset
= "Intel(R) 845G";
91 chipset
= "Intel(R) 830M";
93 case PCI_CHIP_I855_GM
:
94 chipset
= "Intel(R) 852GM/855GM";
97 chipset
= "Intel(R) 865G";
100 chipset
= "Intel(R) 915G";
102 case PCI_CHIP_E7221_G
:
103 chipset
= "Intel (R) E7221G (i915)";
105 case PCI_CHIP_I915_GM
:
106 chipset
= "Intel(R) 915GM";
108 case PCI_CHIP_I945_G
:
109 chipset
= "Intel(R) 945G";
111 case PCI_CHIP_I945_GM
:
112 chipset
= "Intel(R) 945GM";
114 case PCI_CHIP_I945_GME
:
115 chipset
= "Intel(R) 945GME";
118 chipset
= "Intel(R) G33";
121 chipset
= "Intel(R) Q35";
124 chipset
= "Intel(R) Q33";
126 case PCI_CHIP_IGD_GM
:
128 chipset
= "Intel(R) IGD";
130 case PCI_CHIP_I965_Q
:
131 chipset
= "Intel(R) 965Q";
133 case PCI_CHIP_I965_G
:
134 case PCI_CHIP_I965_G_1
:
135 chipset
= "Intel(R) 965G";
137 case PCI_CHIP_I946_GZ
:
138 chipset
= "Intel(R) 946GZ";
140 case PCI_CHIP_I965_GM
:
141 chipset
= "Intel(R) 965GM";
143 case PCI_CHIP_I965_GME
:
144 chipset
= "Intel(R) 965GME/GLE";
146 case PCI_CHIP_GM45_GM
:
147 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
149 case PCI_CHIP_IGD_E_G
:
150 chipset
= "Intel(R) Integrated Graphics Device";
153 chipset
= "Intel(R) G45/G43";
156 chipset
= "Intel(R) Q45/Q43";
159 chipset
= "Intel(R) G41";
162 chipset
= "Intel(R) B43";
165 chipset
= "Intel(R) IGDNG_D";
168 chipset
= "Intel(R) IGDNG_M";
171 chipset
= "Unknown Intel Chipset";
175 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
176 return (GLubyte
*) buffer
;
184 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
186 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
190 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
192 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
193 struct intel_renderbuffer
*rb
;
194 struct intel_region
*region
, *depth_region
;
195 struct intel_context
*intel
= context
->driverPrivate
;
196 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
197 __DRIbuffer
*buffers
= NULL
;
200 unsigned int attachments
[10];
202 const char *region_name
;
204 if (INTEL_DEBUG
& DEBUG_DRI
)
205 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
207 screen
= intel
->intelScreen
->driScrnPriv
;
209 if (screen
->dri2
.loader
210 && (screen
->dri2
.loader
->base
.version
> 2)
211 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
213 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
214 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
215 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
216 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
219 if ((intel
->is_front_buffer_rendering
||
220 intel
->is_front_buffer_reading
||
221 !back_rb
) && front_rb
) {
222 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
223 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
227 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
228 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
231 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
232 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
233 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
234 } else if (depth_rb
!= NULL
) {
235 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
236 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
237 } else if (stencil_rb
!= NULL
) {
238 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
239 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
243 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
248 drawable
->loaderPrivate
);
249 } else if (screen
->dri2
.loader
) {
251 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
252 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
253 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
254 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
255 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
256 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
257 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
258 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
260 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
265 drawable
->loaderPrivate
);
275 drawable
->numClipRects
= 1;
276 drawable
->pClipRects
[0].x1
= 0;
277 drawable
->pClipRects
[0].y1
= 0;
278 drawable
->pClipRects
[0].x2
= drawable
->w
;
279 drawable
->pClipRects
[0].y2
= drawable
->h
;
280 drawable
->numBackClipRects
= 1;
281 drawable
->pBackClipRects
[0].x1
= 0;
282 drawable
->pBackClipRects
[0].y1
= 0;
283 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
284 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
287 for (i
= 0; i
< count
; i
++) {
288 switch (buffers
[i
].attachment
) {
289 case __DRI_BUFFER_FRONT_LEFT
:
290 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
291 region_name
= "dri2 front buffer";
294 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
295 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
296 region_name
= "dri2 fake front buffer";
299 case __DRI_BUFFER_BACK_LEFT
:
300 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
301 region_name
= "dri2 back buffer";
304 case __DRI_BUFFER_DEPTH
:
305 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
306 region_name
= "dri2 depth buffer";
309 case __DRI_BUFFER_DEPTH_STENCIL
:
310 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
311 region_name
= "dri2 depth / stencil buffer";
314 case __DRI_BUFFER_STENCIL
:
315 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
316 region_name
= "dri2 stencil buffer";
319 case __DRI_BUFFER_ACCUM
:
322 "unhandled buffer attach event, attacment type %d\n",
323 buffers
[i
].attachment
);
331 dri_bo_flink(rb
->region
->buffer
, &name
);
332 if (name
== buffers
[i
].name
)
336 if (INTEL_DEBUG
& DEBUG_DRI
)
338 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
339 buffers
[i
].name
, buffers
[i
].attachment
,
340 buffers
[i
].cpp
, buffers
[i
].pitch
);
342 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
343 if (INTEL_DEBUG
& DEBUG_DRI
)
344 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
345 intel_region_reference(®ion
, depth_region
);
348 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
351 buffers
[i
].pitch
/ buffers
[i
].cpp
,
355 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
356 depth_region
= region
;
358 intel_renderbuffer_set_region(rb
, region
);
359 intel_region_release(®ion
);
361 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
362 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
364 struct intel_region
*stencil_region
= NULL
;
367 dri_bo_flink(rb
->region
->buffer
, &name
);
368 if (name
== buffers
[i
].name
)
372 intel_region_reference(&stencil_region
, region
);
373 intel_renderbuffer_set_region(rb
, stencil_region
);
374 intel_region_release(&stencil_region
);
379 drawable
->validBuffers
= GL_TRUE
;
380 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
384 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
386 struct intel_context
*intel
= intel_context(ctx
);
387 __DRIcontext
*driContext
= intel
->driContext
;
388 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
389 GLsizei w
, GLsizei h
);
391 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
392 /* If we're rendering to the fake front buffer, make sure all the pending
393 * drawing has landed on the real front buffer. Otherwise when we
394 * eventually get to DRI2GetBuffersWithFormat the stale real front
395 * buffer contents will get copied to the new fake front buffer.
397 if (intel
->is_front_buffer_rendering
) {
398 intel_flush(ctx
, GL_FALSE
);
401 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
402 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
403 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
406 old_viewport
= ctx
->Driver
.Viewport
;
407 ctx
->Driver
.Viewport
= NULL
;
408 intel
->driDrawable
= driContext
->driDrawablePriv
;
409 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
410 ctx
->Driver
.Viewport
= old_viewport
;
414 static const struct dri_debug_control debug_control
[] = {
415 { "tex", DEBUG_TEXTURE
},
416 { "state", DEBUG_STATE
},
417 { "ioctl", DEBUG_IOCTL
},
418 { "blit", DEBUG_BLIT
},
419 { "mip", DEBUG_MIPTREE
},
420 { "fall", DEBUG_FALLBACKS
},
421 { "verb", DEBUG_VERBOSE
},
422 { "bat", DEBUG_BATCH
},
423 { "pix", DEBUG_PIXEL
},
424 { "buf", DEBUG_BUFMGR
},
425 { "reg", DEBUG_REGION
},
427 { "lock", DEBUG_LOCK
},
428 { "sync", DEBUG_SYNC
},
429 { "prim", DEBUG_PRIMS
},
430 { "vert", DEBUG_VERTS
},
431 { "dri", DEBUG_DRI
},
432 { "dma", DEBUG_DMA
},
433 { "san", DEBUG_SANITY
},
434 { "sleep", DEBUG_SLEEP
},
435 { "stats", DEBUG_STATS
},
436 { "tile", DEBUG_TILE
},
437 { "sing", DEBUG_SINGLE_THREAD
},
438 { "thre", DEBUG_SINGLE_THREAD
},
440 { "urb", DEBUG_URB
},
447 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
449 struct intel_context
*intel
= intel_context(ctx
);
451 _swrast_InvalidateState(ctx
, new_state
);
452 _swsetup_InvalidateState(ctx
, new_state
);
453 _vbo_InvalidateState(ctx
, new_state
);
454 _tnl_InvalidateState(ctx
, new_state
);
455 _tnl_invalidate_vertex_state(ctx
, new_state
);
457 intel
->NewGLState
|= new_state
;
459 if (intel
->vtbl
.invalidate_state
)
460 intel
->vtbl
.invalidate_state( intel
, new_state
);
464 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
466 struct intel_context
*intel
= intel_context(ctx
);
472 INTEL_FIREVERTICES(intel
);
474 if (intel
->batch
->map
!= intel
->batch
->ptr
)
475 intel_batchbuffer_flush(intel
->batch
);
477 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
478 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
480 if (screen
->dri2
.loader
&&
481 (screen
->dri2
.loader
->base
.version
>= 2)
482 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
483 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
484 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
485 intel
->driDrawable
->loaderPrivate
);
487 /* Only clear the dirty bit if front-buffer rendering is no longer
488 * enabled. This is done so that the dirty bit can only be set in
489 * glDrawBuffer. Otherwise the dirty bit would have to be set at
490 * each of N places that do rendering. This has worse performances,
491 * but it is much easier to get correct.
493 if (!intel
->is_front_buffer_rendering
) {
494 intel
->front_buffer_dirty
= GL_FALSE
;
501 intelFlush(GLcontext
* ctx
)
503 intel_flush(ctx
, GL_FALSE
);
507 intel_glFlush(GLcontext
*ctx
)
509 struct intel_context
*intel
= intel_context(ctx
);
511 intel_flush(ctx
, GL_TRUE
);
513 /* We're using glFlush as an indicator that a frame is done, which is
514 * what DRI2 does before calling SwapBuffers (and means we should catch
515 * people doing front-buffer rendering, as well)..
517 * Wait for the swapbuffers before the one we just emitted, so we don't
518 * get too many swaps outstanding for apps that are GPU-heavy but not
521 * Unfortunately, we don't have a handle to the batch containing the swap,
522 * and getting our hands on that doesn't seem worth it, so we just us the
523 * first batch we emitted after the last swap.
525 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
526 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
527 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
528 intel
->first_post_swapbuffers_batch
= NULL
;
533 intelFinish(GLcontext
* ctx
)
535 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
540 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
541 struct intel_renderbuffer
*irb
;
543 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
545 if (irb
&& irb
->region
)
546 dri_bo_wait_rendering(irb
->region
->buffer
);
548 if (fb
->_DepthBuffer
) {
549 /* XXX: Wait on buffer idle */
554 intelInitDriverFunctions(struct dd_function_table
*functions
)
556 _mesa_init_driver_functions(functions
);
558 functions
->Flush
= intel_glFlush
;
559 functions
->Finish
= intelFinish
;
560 functions
->GetString
= intelGetString
;
561 functions
->UpdateState
= intelInvalidateState
;
563 intelInitTextureFuncs(functions
);
564 intelInitTextureImageFuncs(functions
);
565 intelInitTextureSubImageFuncs(functions
);
566 intelInitTextureCopyImageFuncs(functions
);
567 intelInitStateFuncs(functions
);
568 intelInitClearFuncs(functions
);
569 intelInitBufferFuncs(functions
);
570 intelInitPixelFuncs(functions
);
571 intelInitBufferObjectFuncs(functions
);
572 intel_init_syncobj_functions(functions
);
577 intelInitContext(struct intel_context
*intel
,
578 const __GLcontextModes
* mesaVis
,
579 __DRIcontext
* driContextPriv
,
580 void *sharedContextPrivate
,
581 struct dd_function_table
*functions
)
583 GLcontext
*ctx
= &intel
->ctx
;
584 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
585 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
586 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
589 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
590 functions
, (void *) intel
)) {
591 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
595 driContextPriv
->driverPrivate
= intel
;
596 intel
->intelScreen
= intelScreen
;
597 intel
->driScreen
= sPriv
;
598 intel
->driContext
= driContextPriv
;
599 intel
->driFd
= sPriv
->fd
;
601 if (IS_965(intel
->intelScreen
->deviceID
)) {
603 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
605 if (IS_945(intel
->intelScreen
->deviceID
)) {
606 intel
->is_945
= GL_TRUE
;
612 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
613 intel
->is_ironlake
= GL_TRUE
;
614 intel
->needs_ff_sync
= GL_TRUE
;
615 intel
->has_luminance_srgb
= GL_TRUE
;
616 } else if (IS_G4X(intel
->intelScreen
->deviceID
)) {
617 intel
->has_luminance_srgb
= GL_TRUE
;
618 intel
->is_g4x
= GL_TRUE
;
621 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
622 intel
->driScreen
->myNum
,
623 (intel
->gen
>= 4) ? "i965" : "i915");
624 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
625 intel
->maxBatchSize
= 4096;
627 intel
->maxBatchSize
= BATCH_SZ
;
629 intel
->bufmgr
= intelScreen
->bufmgr
;
631 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
632 switch (bo_reuse_mode
) {
633 case DRI_CONF_BO_REUSE_DISABLED
:
635 case DRI_CONF_BO_REUSE_ALL
:
636 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
640 /* This doesn't yet catch all non-conformant rendering, but it's a
643 if (getenv("INTEL_STRICT_CONFORMANCE")) {
644 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
646 intel
->conformance_mode
= value
;
649 intel
->conformance_mode
= 1;
653 if (intel
->conformance_mode
> 0) {
654 ctx
->Const
.MinLineWidth
= 1.0;
655 ctx
->Const
.MinLineWidthAA
= 1.0;
656 ctx
->Const
.MaxLineWidth
= 1.0;
657 ctx
->Const
.MaxLineWidthAA
= 1.0;
658 ctx
->Const
.LineWidthGranularity
= 1.0;
661 ctx
->Const
.MinLineWidth
= 1.0;
662 ctx
->Const
.MinLineWidthAA
= 1.0;
663 ctx
->Const
.MaxLineWidth
= 5.0;
664 ctx
->Const
.MaxLineWidthAA
= 5.0;
665 ctx
->Const
.LineWidthGranularity
= 0.5;
668 ctx
->Const
.MinPointSize
= 1.0;
669 ctx
->Const
.MinPointSizeAA
= 1.0;
670 ctx
->Const
.MaxPointSize
= 255.0;
671 ctx
->Const
.MaxPointSizeAA
= 3.0;
672 ctx
->Const
.PointSizeGranularity
= 1.0;
674 /* reinitialize the context point state.
675 * It depend on constants in __GLcontextRec::Const
677 _mesa_init_point(ctx
);
679 meta_init_metaops(ctx
, &intel
->meta
);
680 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
681 if (intel
->gen
>= 4) {
682 if (MAX_WIDTH
> 8192)
683 ctx
->Const
.MaxRenderbufferSize
= 8192;
685 if (MAX_WIDTH
> 2048)
686 ctx
->Const
.MaxRenderbufferSize
= 2048;
689 /* Initialize the software rasterizer and helper modules. */
690 _swrast_CreateContext(ctx
);
691 _vbo_CreateContext(ctx
);
692 _tnl_CreateContext(ctx
);
693 _swsetup_CreateContext(ctx
);
695 /* Configure swrast to match hardware characteristics: */
696 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
697 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
699 _mesa_meta_init(ctx
);
701 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
702 intel
->hw_stipple
= 1;
704 /* XXX FBO: this doesn't seem to be used anywhere */
705 switch (mesaVis
->depthBits
) {
706 case 0: /* what to do in this case? */
708 intel
->polygon_offset_scale
= 1.0;
711 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
719 intel
->polygon_offset_scale
/= 0xffff;
721 intel
->RenderIndex
= ~0;
723 if (intel
->gen
>= 4 && !intel
->intelScreen
->irq_active
) {
724 _mesa_printf("IRQs not active. Exiting\n");
728 intelInitExtensions(ctx
);
730 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
731 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
732 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
734 intel
->batch
= intel_batchbuffer_alloc(intel
);
736 intel_fbo_init(intel
);
738 if (intel
->ctx
.Mesa_DXTn
) {
739 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
740 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
742 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
743 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
745 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
747 if (intel
->use_texture_tiling
&&
748 !intel
->intelScreen
->kernel_exec_fencing
) {
749 fprintf(stderr
, "No kernel support for execution fencing, "
750 "disabling texture tiling\n");
751 intel
->use_texture_tiling
= GL_FALSE
;
753 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
755 intel
->prim
.primitive
= ~0;
757 /* Force all software fallbacks */
758 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
759 fprintf(stderr
, "disabling 3D rasterization\n");
763 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
764 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
765 intel
->always_flush_batch
= 1;
768 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
769 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
770 intel
->always_flush_cache
= 1;
773 /* Disable all hardware rendering (skip emitting batches and fences/waits
776 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
782 intelDestroyContext(__DRIcontext
* driContextPriv
)
784 struct intel_context
*intel
=
785 (struct intel_context
*) driContextPriv
->driverPrivate
;
787 assert(intel
); /* should never be null */
789 GLboolean release_texture_heaps
;
791 INTEL_FIREVERTICES(intel
);
793 _mesa_meta_free(&intel
->ctx
);
795 meta_destroy_metaops(&intel
->meta
);
797 intel
->vtbl
.destroy(intel
);
799 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
800 _swsetup_DestroyContext(&intel
->ctx
);
801 _tnl_DestroyContext(&intel
->ctx
);
802 _vbo_DestroyContext(&intel
->ctx
);
804 _swrast_DestroyContext(&intel
->ctx
);
805 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
807 intel_batchbuffer_free(intel
->batch
);
810 free(intel
->prim
.vb
);
811 intel
->prim
.vb
= NULL
;
812 dri_bo_unreference(intel
->prim
.vb_bo
);
813 intel
->prim
.vb_bo
= NULL
;
814 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
815 intel
->first_post_swapbuffers_batch
= NULL
;
817 if (release_texture_heaps
) {
818 /* Nothing is currently done here to free texture heaps;
819 * but we're not using the texture heap utilities, so I
820 * rather think we shouldn't. I've taken a look, and can't
821 * find any private texture data hanging around anywhere, but
822 * I'm not yet certain there isn't any at all...
824 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
825 fprintf(stderr, "do something to free texture heaps\n");
829 driDestroyOptionCache(&intel
->optionCache
);
831 /* free the Mesa context */
832 _mesa_free_context_data(&intel
->ctx
);
835 driContextPriv
->driverPrivate
= NULL
;
840 intelUnbindContext(__DRIcontext
* driContextPriv
)
842 struct intel_context
*intel
=
843 (struct intel_context
*) driContextPriv
->driverPrivate
;
845 /* Deassociate the context with the drawables.
847 intel
->driDrawable
= NULL
;
848 intel
->driReadDrawable
= NULL
;
854 intelMakeCurrent(__DRIcontext
* driContextPriv
,
855 __DRIdrawable
* driDrawPriv
,
856 __DRIdrawable
* driReadPriv
)
858 struct intel_context
*intel
;
859 GET_CURRENT_CONTEXT(curCtx
);
862 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
866 /* According to the glXMakeCurrent() man page: "Pending commands to
867 * the previous context, if any, are flushed before it is released."
868 * But only flush if we're actually changing contexts.
870 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
874 if (driContextPriv
) {
875 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
876 struct gl_framebuffer
*readFb
= driReadPriv
->driverPrivate
;
878 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
879 if (driDrawPriv
!= driReadPriv
)
880 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
882 /* set GLframebuffer size to match window, if needed */
883 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
885 if (driReadPriv
!= driDrawPriv
) {
886 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
889 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
890 intel
->driReadDrawable
= driReadPriv
;
891 intel
->driDrawable
= driDrawPriv
;
892 intel_draw_buffer(&intel
->ctx
, fb
);
895 _mesa_make_current(NULL
, NULL
, NULL
);