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/framebuffer.h"
33 #include "main/imports.h"
34 #include "main/points.h"
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
39 #include "drivers/common/driverfuncs.h"
40 #include "drivers/common/meta.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"
58 #include "drirenderbuffer.h"
60 #include "xmlpool.h" /* for symbolic values of enum-type options */
64 int INTEL_DEBUG
= (0);
68 #define DRIVER_DATE "20091221 DEVELOPMENT"
69 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
72 static const GLubyte
*
73 intelGetString(GLcontext
* ctx
, GLenum name
)
75 const struct intel_context
*const intel
= intel_context(ctx
);
77 static char buffer
[128];
81 return (GLubyte
*) "Tungsten Graphics, Inc";
85 switch (intel
->intelScreen
->deviceID
) {
87 chipset
= "Intel(R) 845G";
90 chipset
= "Intel(R) 830M";
92 case PCI_CHIP_I855_GM
:
93 chipset
= "Intel(R) 852GM/855GM";
96 chipset
= "Intel(R) 865G";
99 chipset
= "Intel(R) 915G";
101 case PCI_CHIP_E7221_G
:
102 chipset
= "Intel (R) E7221G (i915)";
104 case PCI_CHIP_I915_GM
:
105 chipset
= "Intel(R) 915GM";
107 case PCI_CHIP_I945_G
:
108 chipset
= "Intel(R) 945G";
110 case PCI_CHIP_I945_GM
:
111 chipset
= "Intel(R) 945GM";
113 case PCI_CHIP_I945_GME
:
114 chipset
= "Intel(R) 945GME";
117 chipset
= "Intel(R) G33";
120 chipset
= "Intel(R) Q35";
123 chipset
= "Intel(R) Q33";
125 case PCI_CHIP_IGD_GM
:
127 chipset
= "Intel(R) IGD";
129 case PCI_CHIP_I965_Q
:
130 chipset
= "Intel(R) 965Q";
132 case PCI_CHIP_I965_G
:
133 case PCI_CHIP_I965_G_1
:
134 chipset
= "Intel(R) 965G";
136 case PCI_CHIP_I946_GZ
:
137 chipset
= "Intel(R) 946GZ";
139 case PCI_CHIP_I965_GM
:
140 chipset
= "Intel(R) 965GM";
142 case PCI_CHIP_I965_GME
:
143 chipset
= "Intel(R) 965GME/GLE";
145 case PCI_CHIP_GM45_GM
:
146 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
148 case PCI_CHIP_IGD_E_G
:
149 chipset
= "Intel(R) Integrated Graphics Device";
152 chipset
= "Intel(R) G45/G43";
155 chipset
= "Intel(R) Q45/Q43";
158 chipset
= "Intel(R) G41";
161 chipset
= "Intel(R) B43";
164 chipset
= "Intel(R) IGDNG_D";
167 chipset
= "Intel(R) IGDNG_M";
170 chipset
= "Unknown Intel Chipset";
174 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
175 return (GLubyte
*) buffer
;
183 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
185 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
189 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
191 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
192 struct intel_renderbuffer
*rb
;
193 struct intel_region
*region
, *depth_region
;
194 struct intel_context
*intel
= context
->driverPrivate
;
195 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
196 __DRIbuffer
*buffers
= NULL
;
199 unsigned int attachments
[10];
201 const char *region_name
;
203 if (INTEL_DEBUG
& DEBUG_DRI
)
204 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
206 screen
= intel
->intelScreen
->driScrnPriv
;
208 if (screen
->dri2
.loader
209 && (screen
->dri2
.loader
->base
.version
> 2)
210 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
212 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
213 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
214 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
215 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
218 if ((intel
->is_front_buffer_rendering
||
219 intel
->is_front_buffer_reading
||
220 !back_rb
) && front_rb
) {
221 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
222 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
226 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
227 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
230 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
231 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
232 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
233 } else if (depth_rb
!= NULL
) {
234 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
235 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
236 } else if (stencil_rb
!= NULL
) {
237 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
238 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
242 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
247 drawable
->loaderPrivate
);
248 } else if (screen
->dri2
.loader
) {
250 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
251 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
252 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
253 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
254 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
255 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
256 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
257 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
259 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
264 drawable
->loaderPrivate
);
274 drawable
->numClipRects
= 1;
275 drawable
->pClipRects
[0].x1
= 0;
276 drawable
->pClipRects
[0].y1
= 0;
277 drawable
->pClipRects
[0].x2
= drawable
->w
;
278 drawable
->pClipRects
[0].y2
= drawable
->h
;
279 drawable
->numBackClipRects
= 1;
280 drawable
->pBackClipRects
[0].x1
= 0;
281 drawable
->pBackClipRects
[0].y1
= 0;
282 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
283 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
286 for (i
= 0; i
< count
; i
++) {
287 switch (buffers
[i
].attachment
) {
288 case __DRI_BUFFER_FRONT_LEFT
:
289 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
290 region_name
= "dri2 front buffer";
293 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
294 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
295 region_name
= "dri2 fake front buffer";
298 case __DRI_BUFFER_BACK_LEFT
:
299 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
300 region_name
= "dri2 back buffer";
303 case __DRI_BUFFER_DEPTH
:
304 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
305 region_name
= "dri2 depth buffer";
308 case __DRI_BUFFER_DEPTH_STENCIL
:
309 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
310 region_name
= "dri2 depth / stencil buffer";
313 case __DRI_BUFFER_STENCIL
:
314 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
315 region_name
= "dri2 stencil buffer";
318 case __DRI_BUFFER_ACCUM
:
321 "unhandled buffer attach event, attacment type %d\n",
322 buffers
[i
].attachment
);
330 dri_bo_flink(rb
->region
->buffer
, &name
);
331 if (name
== buffers
[i
].name
)
335 if (INTEL_DEBUG
& DEBUG_DRI
)
337 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
338 buffers
[i
].name
, buffers
[i
].attachment
,
339 buffers
[i
].cpp
, buffers
[i
].pitch
);
341 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
342 if (INTEL_DEBUG
& DEBUG_DRI
)
343 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
344 intel_region_reference(®ion
, depth_region
);
347 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
350 buffers
[i
].pitch
/ buffers
[i
].cpp
,
354 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
355 depth_region
= region
;
357 intel_renderbuffer_set_region(rb
, region
);
358 intel_region_release(®ion
);
360 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
361 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
363 struct intel_region
*stencil_region
= NULL
;
366 dri_bo_flink(rb
->region
->buffer
, &name
);
367 if (name
== buffers
[i
].name
)
371 intel_region_reference(&stencil_region
, region
);
372 intel_renderbuffer_set_region(rb
, stencil_region
);
373 intel_region_release(&stencil_region
);
378 drawable
->validBuffers
= GL_TRUE
;
379 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
383 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
385 struct intel_context
*intel
= intel_context(ctx
);
386 __DRIcontext
*driContext
= intel
->driContext
;
387 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
388 GLsizei w
, GLsizei h
);
390 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
391 /* If we're rendering to the fake front buffer, make sure all the pending
392 * drawing has landed on the real front buffer. Otherwise when we
393 * eventually get to DRI2GetBuffersWithFormat the stale real front
394 * buffer contents will get copied to the new fake front buffer.
396 if (intel
->is_front_buffer_rendering
) {
397 intel_flush(ctx
, GL_FALSE
);
400 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
401 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
402 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
405 old_viewport
= ctx
->Driver
.Viewport
;
406 ctx
->Driver
.Viewport
= NULL
;
407 intel
->driDrawable
= driContext
->driDrawablePriv
;
408 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
409 ctx
->Driver
.Viewport
= old_viewport
;
413 static const struct dri_debug_control debug_control
[] = {
414 { "tex", DEBUG_TEXTURE
},
415 { "state", DEBUG_STATE
},
416 { "ioctl", DEBUG_IOCTL
},
417 { "blit", DEBUG_BLIT
},
418 { "mip", DEBUG_MIPTREE
},
419 { "fall", DEBUG_FALLBACKS
},
420 { "verb", DEBUG_VERBOSE
},
421 { "bat", DEBUG_BATCH
},
422 { "pix", DEBUG_PIXEL
},
423 { "buf", DEBUG_BUFMGR
},
424 { "reg", DEBUG_REGION
},
426 { "lock", DEBUG_LOCK
},
427 { "sync", DEBUG_SYNC
},
428 { "prim", DEBUG_PRIMS
},
429 { "vert", DEBUG_VERTS
},
430 { "dri", DEBUG_DRI
},
431 { "dma", DEBUG_DMA
},
432 { "san", DEBUG_SANITY
},
433 { "sleep", DEBUG_SLEEP
},
434 { "stats", DEBUG_STATS
},
435 { "tile", DEBUG_TILE
},
436 { "sing", DEBUG_SINGLE_THREAD
},
437 { "thre", DEBUG_SINGLE_THREAD
},
439 { "urb", DEBUG_URB
},
446 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
448 struct intel_context
*intel
= intel_context(ctx
);
450 _swrast_InvalidateState(ctx
, new_state
);
451 _swsetup_InvalidateState(ctx
, new_state
);
452 _vbo_InvalidateState(ctx
, new_state
);
453 _tnl_InvalidateState(ctx
, new_state
);
454 _tnl_invalidate_vertex_state(ctx
, new_state
);
456 intel
->NewGLState
|= new_state
;
458 if (intel
->vtbl
.invalidate_state
)
459 intel
->vtbl
.invalidate_state( intel
, new_state
);
463 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
465 struct intel_context
*intel
= intel_context(ctx
);
471 INTEL_FIREVERTICES(intel
);
473 if (intel
->batch
->map
!= intel
->batch
->ptr
)
474 intel_batchbuffer_flush(intel
->batch
);
476 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
477 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
479 if (screen
->dri2
.loader
&&
480 (screen
->dri2
.loader
->base
.version
>= 2)
481 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
482 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
483 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
484 intel
->driDrawable
->loaderPrivate
);
486 /* Only clear the dirty bit if front-buffer rendering is no longer
487 * enabled. This is done so that the dirty bit can only be set in
488 * glDrawBuffer. Otherwise the dirty bit would have to be set at
489 * each of N places that do rendering. This has worse performances,
490 * but it is much easier to get correct.
492 if (!intel
->is_front_buffer_rendering
) {
493 intel
->front_buffer_dirty
= GL_FALSE
;
500 intelFlush(GLcontext
* ctx
)
502 intel_flush(ctx
, GL_FALSE
);
506 intel_glFlush(GLcontext
*ctx
)
508 intel_flush(ctx
, GL_TRUE
);
512 intelFinish(GLcontext
* ctx
)
514 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
519 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
520 struct intel_renderbuffer
*irb
;
522 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
524 if (irb
&& irb
->region
)
525 dri_bo_wait_rendering(irb
->region
->buffer
);
527 if (fb
->_DepthBuffer
) {
528 /* XXX: Wait on buffer idle */
533 intelInitDriverFunctions(struct dd_function_table
*functions
)
535 _mesa_init_driver_functions(functions
);
537 functions
->Flush
= intel_glFlush
;
538 functions
->Finish
= intelFinish
;
539 functions
->GetString
= intelGetString
;
540 functions
->UpdateState
= intelInvalidateState
;
542 intelInitTextureFuncs(functions
);
543 intelInitTextureImageFuncs(functions
);
544 intelInitTextureSubImageFuncs(functions
);
545 intelInitTextureCopyImageFuncs(functions
);
546 intelInitStateFuncs(functions
);
547 intelInitClearFuncs(functions
);
548 intelInitBufferFuncs(functions
);
549 intelInitPixelFuncs(functions
);
550 intelInitBufferObjectFuncs(functions
);
551 intel_init_syncobj_functions(functions
);
556 intelInitContext(struct intel_context
*intel
,
557 const __GLcontextModes
* mesaVis
,
558 __DRIcontext
* driContextPriv
,
559 void *sharedContextPrivate
,
560 struct dd_function_table
*functions
)
562 GLcontext
*ctx
= &intel
->ctx
;
563 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
564 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
565 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
568 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
569 functions
, (void *) intel
)) {
570 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
574 driContextPriv
->driverPrivate
= intel
;
575 intel
->intelScreen
= intelScreen
;
576 intel
->driScreen
= sPriv
;
577 intel
->driContext
= driContextPriv
;
578 intel
->driFd
= sPriv
->fd
;
580 if (IS_965(intel
->intelScreen
->deviceID
)) {
582 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
584 if (IS_945(intel
->intelScreen
->deviceID
)) {
585 intel
->is_945
= GL_TRUE
;
591 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
592 intel
->is_ironlake
= GL_TRUE
;
593 intel
->needs_ff_sync
= GL_TRUE
;
594 intel
->has_luminance_srgb
= GL_TRUE
;
595 } else if (IS_G4X(intel
->intelScreen
->deviceID
)) {
596 intel
->has_luminance_srgb
= GL_TRUE
;
597 intel
->is_g4x
= GL_TRUE
;
600 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
601 intel
->driScreen
->myNum
,
602 (intel
->gen
>= 4) ? "i965" : "i915");
603 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
604 intel
->maxBatchSize
= 4096;
606 intel
->maxBatchSize
= BATCH_SZ
;
608 intel
->bufmgr
= intelScreen
->bufmgr
;
610 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
611 switch (bo_reuse_mode
) {
612 case DRI_CONF_BO_REUSE_DISABLED
:
614 case DRI_CONF_BO_REUSE_ALL
:
615 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
619 /* This doesn't yet catch all non-conformant rendering, but it's a
622 if (getenv("INTEL_STRICT_CONFORMANCE")) {
623 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
625 intel
->conformance_mode
= value
;
628 intel
->conformance_mode
= 1;
632 if (intel
->conformance_mode
> 0) {
633 ctx
->Const
.MinLineWidth
= 1.0;
634 ctx
->Const
.MinLineWidthAA
= 1.0;
635 ctx
->Const
.MaxLineWidth
= 1.0;
636 ctx
->Const
.MaxLineWidthAA
= 1.0;
637 ctx
->Const
.LineWidthGranularity
= 1.0;
640 ctx
->Const
.MinLineWidth
= 1.0;
641 ctx
->Const
.MinLineWidthAA
= 1.0;
642 ctx
->Const
.MaxLineWidth
= 5.0;
643 ctx
->Const
.MaxLineWidthAA
= 5.0;
644 ctx
->Const
.LineWidthGranularity
= 0.5;
647 ctx
->Const
.MinPointSize
= 1.0;
648 ctx
->Const
.MinPointSizeAA
= 1.0;
649 ctx
->Const
.MaxPointSize
= 255.0;
650 ctx
->Const
.MaxPointSizeAA
= 3.0;
651 ctx
->Const
.PointSizeGranularity
= 1.0;
653 /* reinitialize the context point state.
654 * It depend on constants in __GLcontextRec::Const
656 _mesa_init_point(ctx
);
658 meta_init_metaops(ctx
, &intel
->meta
);
659 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
660 if (intel
->gen
>= 4) {
661 if (MAX_WIDTH
> 8192)
662 ctx
->Const
.MaxRenderbufferSize
= 8192;
664 if (MAX_WIDTH
> 2048)
665 ctx
->Const
.MaxRenderbufferSize
= 2048;
668 /* Initialize the software rasterizer and helper modules. */
669 _swrast_CreateContext(ctx
);
670 _vbo_CreateContext(ctx
);
671 _tnl_CreateContext(ctx
);
672 _swsetup_CreateContext(ctx
);
674 /* Configure swrast to match hardware characteristics: */
675 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
676 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
678 _mesa_meta_init(ctx
);
680 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
681 intel
->hw_stipple
= 1;
683 /* XXX FBO: this doesn't seem to be used anywhere */
684 switch (mesaVis
->depthBits
) {
685 case 0: /* what to do in this case? */
687 intel
->polygon_offset_scale
= 1.0;
690 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
698 intel
->polygon_offset_scale
/= 0xffff;
700 intel
->RenderIndex
= ~0;
702 if (intel
->gen
>= 4 && !intel
->intelScreen
->irq_active
) {
703 _mesa_printf("IRQs not active. Exiting\n");
707 intelInitExtensions(ctx
);
709 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
710 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
711 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
713 intel
->batch
= intel_batchbuffer_alloc(intel
);
715 intel_fbo_init(intel
);
717 if (intel
->ctx
.Mesa_DXTn
) {
718 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
719 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
721 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
722 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
724 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
726 if (intel
->use_texture_tiling
&&
727 !intel
->intelScreen
->kernel_exec_fencing
) {
728 fprintf(stderr
, "No kernel support for execution fencing, "
729 "disabling texture tiling\n");
730 intel
->use_texture_tiling
= GL_FALSE
;
732 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
734 intel
->prim
.primitive
= ~0;
736 /* Force all software fallbacks */
737 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
738 fprintf(stderr
, "disabling 3D rasterization\n");
742 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
743 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
744 intel
->always_flush_batch
= 1;
747 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
748 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
749 intel
->always_flush_cache
= 1;
752 /* Disable all hardware rendering (skip emitting batches and fences/waits
755 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
761 intelDestroyContext(__DRIcontext
* driContextPriv
)
763 struct intel_context
*intel
=
764 (struct intel_context
*) driContextPriv
->driverPrivate
;
766 assert(intel
); /* should never be null */
768 GLboolean release_texture_heaps
;
770 INTEL_FIREVERTICES(intel
);
772 _mesa_meta_free(&intel
->ctx
);
774 meta_destroy_metaops(&intel
->meta
);
776 intel
->vtbl
.destroy(intel
);
778 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
779 _swsetup_DestroyContext(&intel
->ctx
);
780 _tnl_DestroyContext(&intel
->ctx
);
781 _vbo_DestroyContext(&intel
->ctx
);
783 _swrast_DestroyContext(&intel
->ctx
);
784 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
786 intel_batchbuffer_free(intel
->batch
);
789 free(intel
->prim
.vb
);
790 intel
->prim
.vb
= NULL
;
791 dri_bo_unreference(intel
->prim
.vb_bo
);
792 intel
->prim
.vb_bo
= NULL
;
793 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
794 intel
->first_post_swapbuffers_batch
= NULL
;
796 if (release_texture_heaps
) {
797 /* Nothing is currently done here to free texture heaps;
798 * but we're not using the texture heap utilities, so I
799 * rather think we shouldn't. I've taken a look, and can't
800 * find any private texture data hanging around anywhere, but
801 * I'm not yet certain there isn't any at all...
803 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
804 fprintf(stderr, "do something to free texture heaps\n");
808 driDestroyOptionCache(&intel
->optionCache
);
810 /* free the Mesa context */
811 _mesa_free_context_data(&intel
->ctx
);
814 driContextPriv
->driverPrivate
= NULL
;
819 intelUnbindContext(__DRIcontext
* driContextPriv
)
821 struct intel_context
*intel
=
822 (struct intel_context
*) driContextPriv
->driverPrivate
;
824 /* Deassociate the context with the drawables.
826 intel
->driDrawable
= NULL
;
827 intel
->driReadDrawable
= NULL
;
833 intelMakeCurrent(__DRIcontext
* driContextPriv
,
834 __DRIdrawable
* driDrawPriv
,
835 __DRIdrawable
* driReadPriv
)
837 struct intel_context
*intel
;
838 GET_CURRENT_CONTEXT(curCtx
);
841 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
845 /* According to the glXMakeCurrent() man page: "Pending commands to
846 * the previous context, if any, are flushed before it is released."
847 * But only flush if we're actually changing contexts.
849 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
853 if (driContextPriv
) {
854 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
855 struct gl_framebuffer
*readFb
= driReadPriv
->driverPrivate
;
857 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
858 if (driDrawPriv
!= driReadPriv
)
859 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
861 /* set GLframebuffer size to match window, if needed */
862 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
864 if (driReadPriv
!= driDrawPriv
) {
865 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
868 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
869 intel
->driReadDrawable
= driReadPriv
;
870 intel
->driDrawable
= driDrawPriv
;
871 intel_draw_buffer(&intel
->ctx
, fb
);
874 _mesa_make_current(NULL
, NULL
, NULL
);