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 void intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
);
75 static const GLubyte
*
76 intelGetString(GLcontext
* ctx
, GLenum name
)
78 const struct intel_context
*const intel
= intel_context(ctx
);
80 static char buffer
[128];
84 return (GLubyte
*) "Tungsten Graphics, Inc";
88 switch (intel
->intelScreen
->deviceID
) {
90 chipset
= "Intel(R) 845G";
93 chipset
= "Intel(R) 830M";
95 case PCI_CHIP_I855_GM
:
96 chipset
= "Intel(R) 852GM/855GM";
99 chipset
= "Intel(R) 865G";
101 case PCI_CHIP_I915_G
:
102 chipset
= "Intel(R) 915G";
104 case PCI_CHIP_E7221_G
:
105 chipset
= "Intel (R) E7221G (i915)";
107 case PCI_CHIP_I915_GM
:
108 chipset
= "Intel(R) 915GM";
110 case PCI_CHIP_I945_G
:
111 chipset
= "Intel(R) 945G";
113 case PCI_CHIP_I945_GM
:
114 chipset
= "Intel(R) 945GM";
116 case PCI_CHIP_I945_GME
:
117 chipset
= "Intel(R) 945GME";
120 chipset
= "Intel(R) G33";
123 chipset
= "Intel(R) Q35";
126 chipset
= "Intel(R) Q33";
128 case PCI_CHIP_IGD_GM
:
130 chipset
= "Intel(R) IGD";
132 case PCI_CHIP_I965_Q
:
133 chipset
= "Intel(R) 965Q";
135 case PCI_CHIP_I965_G
:
136 case PCI_CHIP_I965_G_1
:
137 chipset
= "Intel(R) 965G";
139 case PCI_CHIP_I946_GZ
:
140 chipset
= "Intel(R) 946GZ";
142 case PCI_CHIP_I965_GM
:
143 chipset
= "Intel(R) 965GM";
145 case PCI_CHIP_I965_GME
:
146 chipset
= "Intel(R) 965GME/GLE";
148 case PCI_CHIP_GM45_GM
:
149 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
151 case PCI_CHIP_IGD_E_G
:
152 chipset
= "Intel(R) Integrated Graphics Device";
155 chipset
= "Intel(R) G45/G43";
158 chipset
= "Intel(R) Q45/Q43";
161 chipset
= "Intel(R) G41";
164 chipset
= "Intel(R) B43";
167 chipset
= "Intel(R) IGDNG_D";
170 chipset
= "Intel(R) IGDNG_M";
173 chipset
= "Unknown Intel Chipset";
177 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
178 return (GLubyte
*) buffer
;
186 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
188 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
192 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
194 struct gl_framebuffer
*fb
= drawable
->driverPrivate
;
195 struct intel_renderbuffer
*rb
;
196 struct intel_region
*region
, *depth_region
;
197 struct intel_context
*intel
= context
->driverPrivate
;
198 struct intel_renderbuffer
*front_rb
, *back_rb
, *depth_rb
, *stencil_rb
;
199 __DRIbuffer
*buffers
= NULL
;
202 unsigned int attachments
[10];
204 const char *region_name
;
206 if (INTEL_DEBUG
& DEBUG_DRI
)
207 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
209 screen
= intel
->intelScreen
->driScrnPriv
;
211 if (screen
->dri2
.loader
212 && (screen
->dri2
.loader
->base
.version
> 2)
213 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
215 front_rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
216 back_rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
217 depth_rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
218 stencil_rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
221 if ((intel
->is_front_buffer_rendering
||
222 intel
->is_front_buffer_reading
||
223 !back_rb
) && front_rb
) {
224 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
225 attachments
[i
++] = intel_bits_per_pixel(front_rb
);
229 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
230 attachments
[i
++] = intel_bits_per_pixel(back_rb
);
233 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
234 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
235 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
236 } else if (depth_rb
!= NULL
) {
237 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
238 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
239 } else if (stencil_rb
!= NULL
) {
240 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
241 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
245 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
250 drawable
->loaderPrivate
);
251 } else if (screen
->dri2
.loader
) {
253 if (intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
))
254 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
255 if (intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
))
256 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
257 if (intel_get_renderbuffer(fb
, BUFFER_DEPTH
))
258 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
259 if (intel_get_renderbuffer(fb
, BUFFER_STENCIL
))
260 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
262 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
267 drawable
->loaderPrivate
);
277 drawable
->numClipRects
= 1;
278 drawable
->pClipRects
[0].x1
= 0;
279 drawable
->pClipRects
[0].y1
= 0;
280 drawable
->pClipRects
[0].x2
= drawable
->w
;
281 drawable
->pClipRects
[0].y2
= drawable
->h
;
282 drawable
->numBackClipRects
= 1;
283 drawable
->pBackClipRects
[0].x1
= 0;
284 drawable
->pBackClipRects
[0].y1
= 0;
285 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
286 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
289 for (i
= 0; i
< count
; i
++) {
290 switch (buffers
[i
].attachment
) {
291 case __DRI_BUFFER_FRONT_LEFT
:
292 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
293 region_name
= "dri2 front buffer";
296 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
297 rb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
298 region_name
= "dri2 fake front buffer";
301 case __DRI_BUFFER_BACK_LEFT
:
302 rb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
303 region_name
= "dri2 back buffer";
306 case __DRI_BUFFER_DEPTH
:
307 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
308 region_name
= "dri2 depth buffer";
311 case __DRI_BUFFER_DEPTH_STENCIL
:
312 rb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
313 region_name
= "dri2 depth / stencil buffer";
316 case __DRI_BUFFER_STENCIL
:
317 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
318 region_name
= "dri2 stencil buffer";
321 case __DRI_BUFFER_ACCUM
:
324 "unhandled buffer attach event, attacment type %d\n",
325 buffers
[i
].attachment
);
333 dri_bo_flink(rb
->region
->buffer
, &name
);
334 if (name
== buffers
[i
].name
)
338 if (INTEL_DEBUG
& DEBUG_DRI
)
340 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
341 buffers
[i
].name
, buffers
[i
].attachment
,
342 buffers
[i
].cpp
, buffers
[i
].pitch
);
344 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
345 if (INTEL_DEBUG
& DEBUG_DRI
)
346 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
347 intel_region_reference(®ion
, depth_region
);
350 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
353 buffers
[i
].pitch
/ buffers
[i
].cpp
,
357 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
358 depth_region
= region
;
360 intel_renderbuffer_set_region(rb
, region
);
361 intel_region_release(®ion
);
363 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
364 rb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
366 struct intel_region
*stencil_region
= NULL
;
369 dri_bo_flink(rb
->region
->buffer
, &name
);
370 if (name
== buffers
[i
].name
)
374 intel_region_reference(&stencil_region
, region
);
375 intel_renderbuffer_set_region(rb
, stencil_region
);
376 intel_region_release(&stencil_region
);
381 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
385 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
387 struct intel_context
*intel
= intel_context(ctx
);
388 __DRIcontext
*driContext
= intel
->driContext
;
389 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
390 GLsizei w
, GLsizei h
);
392 if (!driContext
->driScreenPriv
->dri2
.enabled
)
395 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
396 /* If we're rendering to the fake front buffer, make sure all the pending
397 * drawing has landed on the real front buffer. Otherwise when we
398 * eventually get to DRI2GetBuffersWithFormat the stale real front
399 * buffer contents will get copied to the new fake front buffer.
401 if (intel
->is_front_buffer_rendering
) {
402 intel_flush(ctx
, GL_FALSE
);
405 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
406 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
407 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
410 old_viewport
= ctx
->Driver
.Viewport
;
411 ctx
->Driver
.Viewport
= NULL
;
412 intel
->driDrawable
= driContext
->driDrawablePriv
;
413 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
414 ctx
->Driver
.Viewport
= old_viewport
;
418 static const struct dri_debug_control debug_control
[] = {
419 { "tex", DEBUG_TEXTURE
},
420 { "state", DEBUG_STATE
},
421 { "ioctl", DEBUG_IOCTL
},
422 { "blit", DEBUG_BLIT
},
423 { "mip", DEBUG_MIPTREE
},
424 { "fall", DEBUG_FALLBACKS
},
425 { "verb", DEBUG_VERBOSE
},
426 { "bat", DEBUG_BATCH
},
427 { "pix", DEBUG_PIXEL
},
428 { "buf", DEBUG_BUFMGR
},
429 { "reg", DEBUG_REGION
},
431 { "lock", DEBUG_LOCK
},
432 { "sync", DEBUG_SYNC
},
433 { "prim", DEBUG_PRIMS
},
434 { "vert", DEBUG_VERTS
},
435 { "dri", DEBUG_DRI
},
436 { "dma", DEBUG_DMA
},
437 { "san", DEBUG_SANITY
},
438 { "sleep", DEBUG_SLEEP
},
439 { "stats", DEBUG_STATS
},
440 { "tile", DEBUG_TILE
},
441 { "sing", DEBUG_SINGLE_THREAD
},
442 { "thre", DEBUG_SINGLE_THREAD
},
444 { "urb", DEBUG_URB
},
451 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
453 struct intel_context
*intel
= intel_context(ctx
);
455 _swrast_InvalidateState(ctx
, new_state
);
456 _swsetup_InvalidateState(ctx
, new_state
);
457 _vbo_InvalidateState(ctx
, new_state
);
458 _tnl_InvalidateState(ctx
, new_state
);
459 _tnl_invalidate_vertex_state(ctx
, new_state
);
461 intel
->NewGLState
|= new_state
;
463 if (intel
->vtbl
.invalidate_state
)
464 intel
->vtbl
.invalidate_state( intel
, new_state
);
468 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
470 struct intel_context
*intel
= intel_context(ctx
);
476 INTEL_FIREVERTICES(intel
);
478 /* Emit a flush so that any frontbuffer rendering that might have occurred
479 * lands onscreen in a timely manner, even if the X Server doesn't trigger
482 if (!intel
->driScreen
->dri2
.enabled
&& needs_mi_flush
)
483 intel_batchbuffer_emit_mi_flush(intel
->batch
);
485 if (intel
->batch
->map
!= intel
->batch
->ptr
)
486 intel_batchbuffer_flush(intel
->batch
);
488 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
489 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
491 if (screen
->dri2
.loader
&&
492 (screen
->dri2
.loader
->base
.version
>= 2)
493 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
494 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
495 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
496 intel
->driDrawable
->loaderPrivate
);
498 /* Only clear the dirty bit if front-buffer rendering is no longer
499 * enabled. This is done so that the dirty bit can only be set in
500 * glDrawBuffer. Otherwise the dirty bit would have to be set at
501 * each of N places that do rendering. This has worse performances,
502 * but it is much easier to get correct.
504 if (!intel
->is_front_buffer_rendering
) {
505 intel
->front_buffer_dirty
= GL_FALSE
;
512 intelFlush(GLcontext
* ctx
)
514 intel_flush(ctx
, GL_FALSE
);
518 intel_glFlush(GLcontext
*ctx
)
520 struct intel_context
*intel
= intel_context(ctx
);
522 intel_flush(ctx
, GL_TRUE
);
524 /* We're using glFlush as an indicator that a frame is done, which is
525 * what DRI2 does before calling SwapBuffers (and means we should catch
526 * people doing front-buffer rendering, as well)..
528 * Wait for the swapbuffers before the one we just emitted, so we don't
529 * get too many swaps outstanding for apps that are GPU-heavy but not
532 * Unfortunately, we don't have a handle to the batch containing the swap,
533 * and getting our hands on that doesn't seem worth it, so we just us the
534 * first batch we emitted after the last swap.
536 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
537 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
538 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
539 intel
->first_post_swapbuffers_batch
= NULL
;
544 intelFinish(GLcontext
* ctx
)
546 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
551 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
552 struct intel_renderbuffer
*irb
;
554 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
556 if (irb
&& irb
->region
)
557 dri_bo_wait_rendering(irb
->region
->buffer
);
559 if (fb
->_DepthBuffer
) {
560 /* XXX: Wait on buffer idle */
565 intelInitDriverFunctions(struct dd_function_table
*functions
)
567 _mesa_init_driver_functions(functions
);
569 functions
->Flush
= intel_glFlush
;
570 functions
->Finish
= intelFinish
;
571 functions
->GetString
= intelGetString
;
572 functions
->UpdateState
= intelInvalidateState
;
574 intelInitTextureFuncs(functions
);
575 intelInitTextureImageFuncs(functions
);
576 intelInitTextureSubImageFuncs(functions
);
577 intelInitTextureCopyImageFuncs(functions
);
578 intelInitStateFuncs(functions
);
579 intelInitClearFuncs(functions
);
580 intelInitBufferFuncs(functions
);
581 intelInitPixelFuncs(functions
);
582 intelInitBufferObjectFuncs(functions
);
583 intel_init_syncobj_functions(functions
);
588 intelInitContext(struct intel_context
*intel
,
589 const __GLcontextModes
* mesaVis
,
590 __DRIcontext
* driContextPriv
,
591 void *sharedContextPrivate
,
592 struct dd_function_table
*functions
)
594 GLcontext
*ctx
= &intel
->ctx
;
595 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
596 __DRIscreen
*sPriv
= driContextPriv
->driScreenPriv
;
597 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
600 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
601 functions
, (void *) intel
)) {
602 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
606 driContextPriv
->driverPrivate
= intel
;
607 intel
->intelScreen
= intelScreen
;
608 intel
->driScreen
= sPriv
;
609 intel
->driContext
= driContextPriv
;
610 intel
->driFd
= sPriv
->fd
;
612 if (IS_965(intel
->intelScreen
->deviceID
)) {
614 } else if (IS_9XX(intel
->intelScreen
->deviceID
)) {
616 if (IS_945(intel
->intelScreen
->deviceID
)) {
617 intel
->is_945
= GL_TRUE
;
623 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
624 intel
->is_ironlake
= GL_TRUE
;
625 intel
->needs_ff_sync
= GL_TRUE
;
626 intel
->has_luminance_srgb
= GL_TRUE
;
627 } else if (IS_G4X(intel
->intelScreen
->deviceID
)) {
628 intel
->has_luminance_srgb
= GL_TRUE
;
629 intel
->is_g4x
= GL_TRUE
;
632 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
633 intel
->driScreen
->myNum
,
634 (intel
->gen
>= 4) ? "i965" : "i915");
635 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
636 intel
->maxBatchSize
= 4096;
638 intel
->maxBatchSize
= BATCH_SZ
;
640 intel
->bufmgr
= intelScreen
->bufmgr
;
642 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
643 switch (bo_reuse_mode
) {
644 case DRI_CONF_BO_REUSE_DISABLED
:
646 case DRI_CONF_BO_REUSE_ALL
:
647 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
651 /* This doesn't yet catch all non-conformant rendering, but it's a
654 if (getenv("INTEL_STRICT_CONFORMANCE")) {
655 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
657 intel
->conformance_mode
= value
;
660 intel
->conformance_mode
= 1;
664 if (intel
->conformance_mode
> 0) {
665 ctx
->Const
.MinLineWidth
= 1.0;
666 ctx
->Const
.MinLineWidthAA
= 1.0;
667 ctx
->Const
.MaxLineWidth
= 1.0;
668 ctx
->Const
.MaxLineWidthAA
= 1.0;
669 ctx
->Const
.LineWidthGranularity
= 1.0;
672 ctx
->Const
.MinLineWidth
= 1.0;
673 ctx
->Const
.MinLineWidthAA
= 1.0;
674 ctx
->Const
.MaxLineWidth
= 5.0;
675 ctx
->Const
.MaxLineWidthAA
= 5.0;
676 ctx
->Const
.LineWidthGranularity
= 0.5;
679 ctx
->Const
.MinPointSize
= 1.0;
680 ctx
->Const
.MinPointSizeAA
= 1.0;
681 ctx
->Const
.MaxPointSize
= 255.0;
682 ctx
->Const
.MaxPointSizeAA
= 3.0;
683 ctx
->Const
.PointSizeGranularity
= 1.0;
685 /* reinitialize the context point state.
686 * It depend on constants in __GLcontextRec::Const
688 _mesa_init_point(ctx
);
690 meta_init_metaops(ctx
, &intel
->meta
);
691 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
692 if (intel
->gen
>= 4) {
693 if (MAX_WIDTH
> 8192)
694 ctx
->Const
.MaxRenderbufferSize
= 8192;
696 if (MAX_WIDTH
> 2048)
697 ctx
->Const
.MaxRenderbufferSize
= 2048;
700 /* Initialize the software rasterizer and helper modules. */
701 _swrast_CreateContext(ctx
);
702 _vbo_CreateContext(ctx
);
703 _tnl_CreateContext(ctx
);
704 _swsetup_CreateContext(ctx
);
706 /* Configure swrast to match hardware characteristics: */
707 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
708 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
710 _mesa_meta_init(ctx
);
712 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
713 intel
->hw_stipple
= 1;
715 /* XXX FBO: this doesn't seem to be used anywhere */
716 switch (mesaVis
->depthBits
) {
717 case 0: /* what to do in this case? */
719 intel
->polygon_offset_scale
= 1.0;
722 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
730 intel
->polygon_offset_scale
/= 0xffff;
732 intel
->RenderIndex
= ~0;
734 if (intel
->gen
>= 4 && !intel
->intelScreen
->irq_active
) {
735 _mesa_printf("IRQs not active. Exiting\n");
739 intelInitExtensions(ctx
);
741 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
742 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
743 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
745 intel
->batch
= intel_batchbuffer_alloc(intel
);
747 intel_fbo_init(intel
);
749 if (intel
->ctx
.Mesa_DXTn
) {
750 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
751 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
753 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
754 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
756 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
758 if (intel
->use_texture_tiling
&&
759 !intel
->intelScreen
->kernel_exec_fencing
) {
760 fprintf(stderr
, "No kernel support for execution fencing, "
761 "disabling texture tiling\n");
762 intel
->use_texture_tiling
= GL_FALSE
;
764 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
766 intel
->prim
.primitive
= ~0;
768 /* Force all software fallbacks */
769 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
770 fprintf(stderr
, "disabling 3D rasterization\n");
774 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
775 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
776 intel
->always_flush_batch
= 1;
779 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
780 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
781 intel
->always_flush_cache
= 1;
784 /* Disable all hardware rendering (skip emitting batches and fences/waits
787 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
793 intelDestroyContext(__DRIcontext
* driContextPriv
)
795 struct intel_context
*intel
=
796 (struct intel_context
*) driContextPriv
->driverPrivate
;
798 assert(intel
); /* should never be null */
800 GLboolean release_texture_heaps
;
802 INTEL_FIREVERTICES(intel
);
804 _mesa_meta_free(&intel
->ctx
);
806 meta_destroy_metaops(&intel
->meta
);
808 intel
->vtbl
.destroy(intel
);
810 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
811 _swsetup_DestroyContext(&intel
->ctx
);
812 _tnl_DestroyContext(&intel
->ctx
);
813 _vbo_DestroyContext(&intel
->ctx
);
815 _swrast_DestroyContext(&intel
->ctx
);
816 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
818 intel_batchbuffer_free(intel
->batch
);
821 free(intel
->prim
.vb
);
822 intel
->prim
.vb
= NULL
;
823 dri_bo_unreference(intel
->prim
.vb_bo
);
824 intel
->prim
.vb_bo
= NULL
;
825 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
826 intel
->first_post_swapbuffers_batch
= NULL
;
828 if (release_texture_heaps
) {
829 /* Nothing is currently done here to free texture heaps;
830 * but we're not using the texture heap utilities, so I
831 * rather think we shouldn't. I've taken a look, and can't
832 * find any private texture data hanging around anywhere, but
833 * I'm not yet certain there isn't any at all...
835 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
836 fprintf(stderr, "do something to free texture heaps\n");
840 driDestroyOptionCache(&intel
->optionCache
);
842 /* free the Mesa context */
843 _mesa_free_context_data(&intel
->ctx
);
846 driContextPriv
->driverPrivate
= NULL
;
851 intelUnbindContext(__DRIcontext
* driContextPriv
)
853 struct intel_context
*intel
=
854 (struct intel_context
*) driContextPriv
->driverPrivate
;
856 /* Deassociate the context with the drawables.
858 intel
->driDrawable
= NULL
;
859 intel
->driReadDrawable
= NULL
;
865 intelMakeCurrent(__DRIcontext
* driContextPriv
,
866 __DRIdrawable
* driDrawPriv
,
867 __DRIdrawable
* driReadPriv
)
869 struct intel_context
*intel
;
870 GET_CURRENT_CONTEXT(curCtx
);
873 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
877 /* According to the glXMakeCurrent() man page: "Pending commands to
878 * the previous context, if any, are flushed before it is released."
879 * But only flush if we're actually changing contexts.
881 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
885 if (driContextPriv
) {
886 struct gl_framebuffer
*fb
= driDrawPriv
->driverPrivate
;
887 struct gl_framebuffer
*readFb
= driReadPriv
->driverPrivate
;
889 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
890 if (driDrawPriv
!= driReadPriv
)
891 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
893 /* set GLframebuffer size to match window, if needed */
894 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
896 if (driReadPriv
!= driDrawPriv
) {
897 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
900 _mesa_make_current(&intel
->ctx
, fb
, readFb
);
901 intel
->driReadDrawable
= driReadPriv
;
902 intel
->driDrawable
= driDrawPriv
;
903 intel_draw_buffer(&intel
->ctx
, fb
);
906 _mesa_make_current(NULL
, NULL
, NULL
);