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"
58 #include "intel_swapbuffers.h"
60 #include "drirenderbuffer.h"
63 #include "xmlpool.h" /* for symbolic values of enum-type options */
67 int INTEL_DEBUG
= (0);
71 #define DRIVER_DATE "20090712 2009Q2 RC3"
72 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
75 static void intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
);
77 static const GLubyte
*
78 intelGetString(GLcontext
* ctx
, GLenum name
)
80 const struct intel_context
*const intel
= intel_context(ctx
);
82 static char buffer
[128];
86 return (GLubyte
*) "Tungsten Graphics, Inc";
90 switch (intel
->intelScreen
->deviceID
) {
92 chipset
= "Intel(R) 845G";
95 chipset
= "Intel(R) 830M";
97 case PCI_CHIP_I855_GM
:
98 chipset
= "Intel(R) 852GM/855GM";
100 case PCI_CHIP_I865_G
:
101 chipset
= "Intel(R) 865G";
103 case PCI_CHIP_I915_G
:
104 chipset
= "Intel(R) 915G";
106 case PCI_CHIP_E7221_G
:
107 chipset
= "Intel (R) E7221G (i915)";
109 case PCI_CHIP_I915_GM
:
110 chipset
= "Intel(R) 915GM";
112 case PCI_CHIP_I945_G
:
113 chipset
= "Intel(R) 945G";
115 case PCI_CHIP_I945_GM
:
116 chipset
= "Intel(R) 945GM";
118 case PCI_CHIP_I945_GME
:
119 chipset
= "Intel(R) 945GME";
122 chipset
= "Intel(R) G33";
125 chipset
= "Intel(R) Q35";
128 chipset
= "Intel(R) Q33";
130 case PCI_CHIP_IGD_GM
:
132 chipset
= "Intel(R) IGD";
134 case PCI_CHIP_I965_Q
:
135 chipset
= "Intel(R) 965Q";
137 case PCI_CHIP_I965_G
:
138 case PCI_CHIP_I965_G_1
:
139 chipset
= "Intel(R) 965G";
141 case PCI_CHIP_I946_GZ
:
142 chipset
= "Intel(R) 946GZ";
144 case PCI_CHIP_I965_GM
:
145 chipset
= "Intel(R) 965GM";
147 case PCI_CHIP_I965_GME
:
148 chipset
= "Intel(R) 965GME/GLE";
150 case PCI_CHIP_GM45_GM
:
151 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
153 case PCI_CHIP_IGD_E_G
:
154 chipset
= "Intel(R) Integrated Graphics Device";
157 chipset
= "Intel(R) G45/G43";
160 chipset
= "Intel(R) Q45/Q43";
163 chipset
= "Intel(R) G41";
166 chipset
= "Intel(R) B43";
169 chipset
= "Intel(R) IGDNG_D";
172 chipset
= "Intel(R) IGDNG_M";
175 chipset
= "Unknown Intel Chipset";
179 (void) driGetRendererString(buffer
, chipset
,
180 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
182 return (GLubyte
*) buffer
;
190 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
192 switch (rb
->Base
._ActualFormat
) {
194 case GL_DEPTH_COMPONENT16
:
198 case GL_DEPTH_COMPONENT24
:
199 case GL_DEPTH24_STENCIL8_EXT
:
200 case GL_STENCIL_INDEX8_EXT
:
208 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
210 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
211 struct intel_renderbuffer
*rb
;
212 struct intel_region
*region
, *depth_region
;
213 struct intel_context
*intel
= context
->driverPrivate
;
214 __DRIbuffer
*buffers
= NULL
;
217 unsigned int attachments
[10];
219 const char *region_name
;
221 if (INTEL_DEBUG
& DEBUG_DRI
)
222 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
224 screen
= intel
->intelScreen
->driScrnPriv
;
226 if (screen
->dri2
.loader
227 && (screen
->dri2
.loader
->base
.version
> 2)
228 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
229 struct intel_renderbuffer
*depth_rb
;
230 struct intel_renderbuffer
*stencil_rb
;
233 if ((intel
->is_front_buffer_rendering
||
234 intel
->is_front_buffer_reading
||
235 !intel_fb
->color_rb
[1])
236 && intel_fb
->color_rb
[0]) {
237 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
238 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
241 if (intel_fb
->color_rb
[1]) {
242 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
243 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
246 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
247 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
249 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
250 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
251 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
252 } else if (depth_rb
!= NULL
) {
253 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
254 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
255 } else if (stencil_rb
!= NULL
) {
256 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
257 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
261 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
266 drawable
->loaderPrivate
);
267 } else if (screen
->dri2
.loader
) {
269 if (intel_fb
->color_rb
[0])
270 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
271 if (intel_fb
->color_rb
[1])
272 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
273 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
274 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
275 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
276 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
278 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
283 drawable
->loaderPrivate
);
293 drawable
->numClipRects
= 1;
294 drawable
->pClipRects
[0].x1
= 0;
295 drawable
->pClipRects
[0].y1
= 0;
296 drawable
->pClipRects
[0].x2
= drawable
->w
;
297 drawable
->pClipRects
[0].y2
= drawable
->h
;
298 drawable
->numBackClipRects
= 1;
299 drawable
->pBackClipRects
[0].x1
= 0;
300 drawable
->pBackClipRects
[0].y1
= 0;
301 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
302 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
305 for (i
= 0; i
< count
; i
++) {
306 switch (buffers
[i
].attachment
) {
307 case __DRI_BUFFER_FRONT_LEFT
:
308 rb
= intel_fb
->color_rb
[0];
309 region_name
= "dri2 front buffer";
312 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
313 rb
= intel_fb
->color_rb
[0];
314 region_name
= "dri2 fake front buffer";
317 case __DRI_BUFFER_BACK_LEFT
:
318 rb
= intel_fb
->color_rb
[1];
319 region_name
= "dri2 back buffer";
322 case __DRI_BUFFER_DEPTH
:
323 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
324 region_name
= "dri2 depth buffer";
327 case __DRI_BUFFER_DEPTH_STENCIL
:
328 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
329 region_name
= "dri2 depth / stencil buffer";
332 case __DRI_BUFFER_STENCIL
:
333 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
334 region_name
= "dri2 stencil buffer";
337 case __DRI_BUFFER_ACCUM
:
340 "unhandled buffer attach event, attacment type %d\n",
341 buffers
[i
].attachment
);
349 dri_bo_flink(rb
->region
->buffer
, &name
);
350 if (name
== buffers
[i
].name
)
354 if (INTEL_DEBUG
& DEBUG_DRI
)
356 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
357 buffers
[i
].name
, buffers
[i
].attachment
,
358 buffers
[i
].cpp
, buffers
[i
].pitch
);
360 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
361 if (INTEL_DEBUG
& DEBUG_DRI
)
362 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
363 intel_region_reference(®ion
, depth_region
);
366 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
369 buffers
[i
].pitch
/ buffers
[i
].cpp
,
373 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
374 depth_region
= region
;
376 intel_renderbuffer_set_region(rb
, region
);
377 intel_region_release(®ion
);
379 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
380 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
382 struct intel_region
*stencil_region
= NULL
;
385 dri_bo_flink(rb
->region
->buffer
, &name
);
386 if (name
== buffers
[i
].name
)
390 intel_region_reference(&stencil_region
, region
);
391 intel_renderbuffer_set_region(rb
, stencil_region
);
392 intel_region_release(&stencil_region
);
397 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
401 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
403 struct intel_context
*intel
= intel_context(ctx
);
404 __DRIcontext
*driContext
= intel
->driContext
;
405 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
406 GLsizei w
, GLsizei h
);
408 if (!driContext
->driScreenPriv
->dri2
.enabled
)
411 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
412 /* If we're rendering to the fake front buffer, make sure all the pending
413 * drawing has landed on the real front buffer. Otherwise when we
414 * eventually get to DRI2GetBuffersWithFormat the stale real front
415 * buffer contents will get copied to the new fake front buffer.
417 if (intel
->is_front_buffer_rendering
) {
418 intel_flush(ctx
, GL_FALSE
);
421 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
422 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
423 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
426 old_viewport
= ctx
->Driver
.Viewport
;
427 ctx
->Driver
.Viewport
= NULL
;
428 intel
->driDrawable
= driContext
->driDrawablePriv
;
429 intelWindowMoved(intel
);
430 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
431 ctx
->Driver
.Viewport
= old_viewport
;
435 static const struct dri_debug_control debug_control
[] = {
436 { "tex", DEBUG_TEXTURE
},
437 { "state", DEBUG_STATE
},
438 { "ioctl", DEBUG_IOCTL
},
439 { "blit", DEBUG_BLIT
},
440 { "mip", DEBUG_MIPTREE
},
441 { "fall", DEBUG_FALLBACKS
},
442 { "verb", DEBUG_VERBOSE
},
443 { "bat", DEBUG_BATCH
},
444 { "pix", DEBUG_PIXEL
},
445 { "buf", DEBUG_BUFMGR
},
446 { "reg", DEBUG_REGION
},
448 { "lock", DEBUG_LOCK
},
449 { "sync", DEBUG_SYNC
},
450 { "prim", DEBUG_PRIMS
},
451 { "vert", DEBUG_VERTS
},
452 { "dri", DEBUG_DRI
},
453 { "dma", DEBUG_DMA
},
454 { "san", DEBUG_SANITY
},
455 { "sleep", DEBUG_SLEEP
},
456 { "stats", DEBUG_STATS
},
457 { "tile", DEBUG_TILE
},
458 { "sing", DEBUG_SINGLE_THREAD
},
459 { "thre", DEBUG_SINGLE_THREAD
},
461 { "urb", DEBUG_URB
},
468 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
470 struct intel_context
*intel
= intel_context(ctx
);
472 _swrast_InvalidateState(ctx
, new_state
);
473 _swsetup_InvalidateState(ctx
, new_state
);
474 _vbo_InvalidateState(ctx
, new_state
);
475 _tnl_InvalidateState(ctx
, new_state
);
476 _tnl_invalidate_vertex_state(ctx
, new_state
);
478 intel
->NewGLState
|= new_state
;
480 if (intel
->vtbl
.invalidate_state
)
481 intel
->vtbl
.invalidate_state( intel
, new_state
);
485 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
487 struct intel_context
*intel
= intel_context(ctx
);
492 if (!IS_965(intel
->intelScreen
->deviceID
))
493 INTEL_FIREVERTICES(intel
);
495 /* Emit a flush so that any frontbuffer rendering that might have occurred
496 * lands onscreen in a timely manner, even if the X Server doesn't trigger
500 intel_batchbuffer_emit_mi_flush(intel
->batch
);
502 if (intel
->batch
->map
!= intel
->batch
->ptr
)
503 intel_batchbuffer_flush(intel
->batch
);
505 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
506 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
508 if (screen
->dri2
.loader
&&
509 (screen
->dri2
.loader
->base
.version
>= 2)
510 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
511 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
512 intel
->driDrawable
->loaderPrivate
);
514 /* Only clear the dirty bit if front-buffer rendering is no longer
515 * enabled. This is done so that the dirty bit can only be set in
516 * glDrawBuffer. Otherwise the dirty bit would have to be set at
517 * each of N places that do rendering. This has worse performances,
518 * but it is much easier to get correct.
520 if (!intel
->is_front_buffer_rendering
) {
521 intel
->front_buffer_dirty
= GL_FALSE
;
528 intelFlush(GLcontext
* ctx
)
530 intel_flush(ctx
, GL_FALSE
);
534 intel_glFlush(GLcontext
*ctx
)
536 struct intel_context
*intel
= intel_context(ctx
);
538 intel_flush(ctx
, GL_TRUE
);
540 /* We're using glFlush as an indicator that a frame is done, which is
541 * what DRI2 does before calling SwapBuffers (and means we should catch
542 * people doing front-buffer rendering, as well)..
544 * Wait for the swapbuffers before the one we just emitted, so we don't
545 * get too many swaps outstanding for apps that are GPU-heavy but not
548 * Unfortunately, we don't have a handle to the batch containing the swap,
549 * and getting our hands on that doesn't seem worth it, so we just us the
550 * first batch we emitted after the last swap.
552 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
553 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
554 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
555 intel
->first_post_swapbuffers_batch
= NULL
;
560 intelFinish(GLcontext
* ctx
)
562 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
567 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
568 struct intel_renderbuffer
*irb
;
570 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
572 if (irb
&& irb
->region
)
573 dri_bo_wait_rendering(irb
->region
->buffer
);
575 if (fb
->_DepthBuffer
) {
576 /* XXX: Wait on buffer idle */
581 intelInitDriverFunctions(struct dd_function_table
*functions
)
583 _mesa_init_driver_functions(functions
);
585 functions
->Flush
= intel_glFlush
;
586 functions
->Finish
= intelFinish
;
587 functions
->GetString
= intelGetString
;
588 functions
->UpdateState
= intelInvalidateState
;
590 functions
->CopyColorTable
= _swrast_CopyColorTable
;
591 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
592 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
593 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
595 intelInitTextureFuncs(functions
);
596 intelInitTextureImageFuncs(functions
);
597 intelInitTextureSubImageFuncs(functions
);
598 intelInitTextureCopyImageFuncs(functions
);
599 intelInitStateFuncs(functions
);
600 intelInitClearFuncs(functions
);
601 intelInitBufferFuncs(functions
);
602 intelInitPixelFuncs(functions
);
603 intelInitBufferObjectFuncs(functions
);
604 intel_init_syncobj_functions(functions
);
609 intelInitContext(struct intel_context
*intel
,
610 const __GLcontextModes
* mesaVis
,
611 __DRIcontextPrivate
* driContextPriv
,
612 void *sharedContextPrivate
,
613 struct dd_function_table
*functions
)
615 GLcontext
*ctx
= &intel
->ctx
;
616 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
617 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
618 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
621 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
622 functions
, (void *) intel
)) {
623 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
627 driContextPriv
->driverPrivate
= intel
;
628 intel
->intelScreen
= intelScreen
;
629 intel
->driScreen
= sPriv
;
630 intel
->sarea
= intelScreen
->sarea
;
631 intel
->driContext
= driContextPriv
;
634 intel
->hHWContext
= driContextPriv
->hHWContext
;
635 intel
->driFd
= sPriv
->fd
;
636 intel
->driHwLock
= sPriv
->lock
;
638 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
639 intel
->driScreen
->myNum
,
640 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
641 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
642 intel
->maxBatchSize
= 4096;
644 intel
->maxBatchSize
= BATCH_SZ
;
646 intel
->bufmgr
= intelScreen
->bufmgr
;
648 if (0) /* for debug */
649 drm_intel_bufmgr_set_debug(intel
->bufmgr
, 1);
651 intel
->ttm
= intelScreen
->ttm
;
655 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
656 switch (bo_reuse_mode
) {
657 case DRI_CONF_BO_REUSE_DISABLED
:
659 case DRI_CONF_BO_REUSE_ALL
:
660 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
665 /* This doesn't yet catch all non-conformant rendering, but it's a
668 if (getenv("INTEL_STRICT_CONFORMANCE")) {
669 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
671 intel
->conformance_mode
= value
;
674 intel
->conformance_mode
= 1;
678 if (intel
->conformance_mode
> 0) {
679 ctx
->Const
.MinLineWidth
= 1.0;
680 ctx
->Const
.MinLineWidthAA
= 1.0;
681 ctx
->Const
.MaxLineWidth
= 1.0;
682 ctx
->Const
.MaxLineWidthAA
= 1.0;
683 ctx
->Const
.LineWidthGranularity
= 1.0;
686 ctx
->Const
.MinLineWidth
= 1.0;
687 ctx
->Const
.MinLineWidthAA
= 1.0;
688 ctx
->Const
.MaxLineWidth
= 5.0;
689 ctx
->Const
.MaxLineWidthAA
= 5.0;
690 ctx
->Const
.LineWidthGranularity
= 0.5;
693 ctx
->Const
.MinPointSize
= 1.0;
694 ctx
->Const
.MinPointSizeAA
= 1.0;
695 ctx
->Const
.MaxPointSize
= 255.0;
696 ctx
->Const
.MaxPointSizeAA
= 3.0;
697 ctx
->Const
.PointSizeGranularity
= 1.0;
699 /* reinitialize the context point state.
700 * It depend on constants in __GLcontextRec::Const
702 _mesa_init_point(ctx
);
704 meta_init_metaops(ctx
, &intel
->meta
);
705 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
706 if (IS_965(intelScreen
->deviceID
)) {
707 if (MAX_WIDTH
> 8192)
708 ctx
->Const
.MaxRenderbufferSize
= 8192;
710 if (MAX_WIDTH
> 2048)
711 ctx
->Const
.MaxRenderbufferSize
= 2048;
714 /* Initialize the software rasterizer and helper modules. */
715 _swrast_CreateContext(ctx
);
716 _vbo_CreateContext(ctx
);
717 _tnl_CreateContext(ctx
);
718 _swsetup_CreateContext(ctx
);
720 /* Configure swrast to match hardware characteristics: */
721 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
722 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
724 _mesa_meta_init(ctx
);
726 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
727 intel
->hw_stipple
= 1;
729 /* XXX FBO: this doesn't seem to be used anywhere */
730 switch (mesaVis
->depthBits
) {
731 case 0: /* what to do in this case? */
733 intel
->polygon_offset_scale
= 1.0;
736 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
743 if (IS_965(intelScreen
->deviceID
))
744 intel
->polygon_offset_scale
/= 0xffff;
746 intel
->RenderIndex
= ~0;
748 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
749 intel
->irqsEmitted
= 0;
751 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
752 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
754 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
756 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
757 _mesa_printf("IRQs not active. Exiting\n");
761 intelInitExtensions(ctx
, GL_FALSE
);
763 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
764 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
765 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
767 if (!sPriv
->dri2
.enabled
)
768 intel_recreate_static_regions(intel
);
770 intel
->batch
= intel_batchbuffer_alloc(intel
);
772 intel_fbo_init(intel
);
774 if (intel
->ctx
.Mesa_DXTn
) {
775 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
776 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
778 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
779 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
781 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
783 if (intel
->use_texture_tiling
&&
784 !intel
->intelScreen
->kernel_exec_fencing
) {
785 fprintf(stderr
, "No kernel support for execution fencing, "
786 "disabling texture tiling\n");
787 intel
->use_texture_tiling
= GL_FALSE
;
789 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
791 intel
->prim
.primitive
= ~0;
793 /* Force all software fallbacks */
794 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
795 fprintf(stderr
, "disabling 3D rasterization\n");
799 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
800 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
801 intel
->always_flush_batch
= 1;
804 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
805 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
806 intel
->always_flush_cache
= 1;
809 /* Disable all hardware rendering (skip emitting batches and fences/waits
812 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
818 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
820 struct intel_context
*intel
=
821 (struct intel_context
*) driContextPriv
->driverPrivate
;
823 assert(intel
); /* should never be null */
825 GLboolean release_texture_heaps
;
827 INTEL_FIREVERTICES(intel
);
829 _mesa_meta_free(&intel
->ctx
);
831 meta_destroy_metaops(&intel
->meta
);
833 intel
->vtbl
.destroy(intel
);
835 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
836 _swsetup_DestroyContext(&intel
->ctx
);
837 _tnl_DestroyContext(&intel
->ctx
);
838 _vbo_DestroyContext(&intel
->ctx
);
840 _swrast_DestroyContext(&intel
->ctx
);
841 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
843 intel_batchbuffer_free(intel
->batch
);
846 free(intel
->prim
.vb
);
847 intel
->prim
.vb
= NULL
;
848 dri_bo_unreference(intel
->prim
.vb_bo
);
849 intel
->prim
.vb_bo
= NULL
;
850 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
851 intel
->first_post_swapbuffers_batch
= NULL
;
853 if (release_texture_heaps
) {
854 /* Nothing is currently done here to free texture heaps;
855 * but we're not using the texture heap utilities, so I
856 * rather think we shouldn't. I've taken a look, and can't
857 * find any private texture data hanging around anywhere, but
858 * I'm not yet certain there isn't any at all...
860 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
861 fprintf(stderr, "do something to free texture heaps\n");
865 /* XXX In intelMakeCurrent() below, the context's static regions are
866 * referenced inside the frame buffer; it's listed as a hack,
867 * with a comment of "XXX FBO temporary fix-ups!", but
868 * as long as it's there, we should release the regions here.
869 * The do/while loop around the block is used to allow the
870 * "continue" statements inside the block to exit the block,
871 * to avoid many layers of "if" constructs.
874 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
875 struct intel_framebuffer
*intel_fb
;
876 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
878 /* We're already detached from the drawable; exit this block. */
881 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
883 /* The frame buffer is already gone; exit this block. */
886 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
887 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
889 /* If the regions of the frame buffer still match the regions
890 * of the context, release them. If they've changed somehow,
893 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
894 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
896 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
897 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
900 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
901 intel_renderbuffer_set_region(irbDepth
, NULL
);
903 /* Usually, the stencil buffer is the same as the depth buffer;
904 * but they're handled separately in MakeCurrent, so we'll
905 * handle them separately here.
907 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
908 intel_renderbuffer_set_region(irbStencil
, NULL
);
912 intel_region_release(&intel
->front_region
);
913 intel_region_release(&intel
->back_region
);
914 intel_region_release(&intel
->depth_region
);
916 driDestroyOptionCache(&intel
->optionCache
);
918 /* free the Mesa context */
919 _mesa_free_context_data(&intel
->ctx
);
922 driContextPriv
->driverPrivate
= NULL
;
927 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
929 struct intel_context
*intel
=
930 (struct intel_context
*) driContextPriv
->driverPrivate
;
932 /* Deassociate the context with the drawables.
934 intel
->driDrawable
= NULL
;
935 intel
->driReadDrawable
= NULL
;
941 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
942 __DRIdrawablePrivate
* driDrawPriv
,
943 __DRIdrawablePrivate
* driReadPriv
)
945 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
947 if (driContextPriv
) {
948 struct intel_context
*intel
=
949 (struct intel_context
*) driContextPriv
->driverPrivate
;
950 struct intel_framebuffer
*intel_fb
=
951 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
952 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
954 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
955 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
956 if (driDrawPriv
!= driReadPriv
)
957 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
959 /* XXX FBO temporary fix-ups! These are released in
960 * intelDextroyContext(), above. Changes here should be
963 /* if the renderbuffers don't have regions, init them from the context */
964 struct intel_renderbuffer
*irbDepth
965 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
966 struct intel_renderbuffer
*irbStencil
967 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
969 if (intel_fb
->color_rb
[0]) {
970 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
971 intel
->front_region
);
973 if (intel_fb
->color_rb
[1]) {
974 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
979 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
982 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
986 /* set GLframebuffer size to match window, if needed */
987 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
989 if (driReadPriv
!= driDrawPriv
) {
990 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
993 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
995 /* The drawbuffer won't always be updated by _mesa_make_current:
997 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
999 if (intel
->driReadDrawable
!= driReadPriv
)
1000 intel
->driReadDrawable
= driReadPriv
;
1002 if (intel
->driDrawable
!= driDrawPriv
) {
1003 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
1006 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
1007 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
1008 : VBLANK_FLAG_NO_IRQ
;
1010 /* Prevent error printf if one crtc is disabled, this will
1011 * be properly calculated in intelWindowMoved() next.
1013 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
1015 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
1016 driDrawableInitVBlank(driDrawPriv
);
1017 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
1019 for (i
= 0; i
< 2; i
++) {
1020 if (intel_fb
->color_rb
[i
])
1021 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1024 intel
->driDrawable
= driDrawPriv
;
1025 intelWindowMoved(intel
);
1028 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1032 _mesa_make_current(NULL
, NULL
, NULL
);
1039 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1041 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1042 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1043 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1044 int me
= intel
->hHWContext
;
1046 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1048 if (INTEL_DEBUG
& DEBUG_LOCK
)
1049 _mesa_printf("%s - got contended lock\n", __progname
);
1051 /* If the window moved, may need to set a new cliprect now.
1053 * NOTE: This releases and regains the hw lock, so all state
1054 * checking must be done *after* this call:
1057 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1059 if (sarea
&& sarea
->ctxOwner
!= me
) {
1060 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1061 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1062 sarea
->ctxOwner
, me
);
1064 sarea
->ctxOwner
= me
;
1067 /* If the last consumer of the texture memory wasn't us, notify the fake
1068 * bufmgr and record the new owner. We should have the memory shared
1069 * between contexts of a single fake bufmgr, but this will at least make
1070 * things correct for now.
1072 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1073 sarea
->texAge
= intel
->hHWContext
;
1074 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1075 if (INTEL_DEBUG
& DEBUG_BATCH
)
1076 intel_decode_context_reset();
1077 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1078 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1079 sarea
->ctxOwner
, intel
->hHWContext
);
1082 /* Drawable changed?
1084 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1085 intelWindowMoved(intel
);
1086 intel
->lastStamp
= dPriv
->lastStamp
;
1091 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1093 /* Lock the hardware and validate our state.
1095 void LOCK_HARDWARE( struct intel_context
*intel
)
1097 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1098 __DRIscreen
*sPriv
= intel
->driScreen
;
1100 struct intel_framebuffer
*intel_fb
= NULL
;
1101 struct intel_renderbuffer
*intel_rb
= NULL
;
1104 if (intel
->locked
>= 2)
1107 if (!sPriv
->dri2
.enabled
)
1108 _glthread_LOCK_MUTEX(lockMutex
);
1110 if (intel
->driDrawable
) {
1111 intel_fb
= intel
->driDrawable
->driverPrivate
;
1115 intel_get_renderbuffer(&intel_fb
->Base
,
1116 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1119 if (intel_rb
&& dPriv
->vblFlags
&&
1120 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1121 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1124 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1126 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1127 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1130 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1131 drmWaitVBlank(intel
->driFd
, &vbl
);
1132 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1135 if (!sPriv
->dri2
.enabled
) {
1136 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1137 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1140 intelContendedLock( intel
, 0 );
1144 if (INTEL_DEBUG
& DEBUG_LOCK
)
1145 _mesa_printf("%s - locked\n", __progname
);
1149 /* Unlock the hardware using the global current context
1151 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1153 __DRIscreen
*sPriv
= intel
->driScreen
;
1156 if (intel
->locked
> 0)
1159 assert(intel
->locked
== 0);
1161 if (!sPriv
->dri2
.enabled
) {
1162 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1163 _glthread_UNLOCK_MUTEX(lockMutex
);
1166 if (INTEL_DEBUG
& DEBUG_LOCK
)
1167 _mesa_printf("%s - unlocked\n", __progname
);
1170 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1173 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1174 intel_batchbuffer_flush(intel
->batch
);