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"
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"
57 #include "intel_swapbuffers.h"
59 #include "drirenderbuffer.h"
62 #include "xmlpool.h" /* for symbolic values of enum-type options */
66 int INTEL_DEBUG
= (0);
70 #define DRIVER_DATE "20090712 2009Q2 RC3"
71 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
74 static void intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
);
76 static const GLubyte
*
77 intelGetString(GLcontext
* ctx
, GLenum name
)
79 const struct intel_context
*const intel
= intel_context(ctx
);
81 static char buffer
[128];
85 return (GLubyte
*) "Tungsten Graphics, Inc";
89 switch (intel
->intelScreen
->deviceID
) {
91 chipset
= "Intel(R) 845G";
94 chipset
= "Intel(R) 830M";
96 case PCI_CHIP_I855_GM
:
97 chipset
= "Intel(R) 852GM/855GM";
100 chipset
= "Intel(R) 865G";
102 case PCI_CHIP_I915_G
:
103 chipset
= "Intel(R) 915G";
105 case PCI_CHIP_E7221_G
:
106 chipset
= "Intel (R) E7221G (i915)";
108 case PCI_CHIP_I915_GM
:
109 chipset
= "Intel(R) 915GM";
111 case PCI_CHIP_I945_G
:
112 chipset
= "Intel(R) 945G";
114 case PCI_CHIP_I945_GM
:
115 chipset
= "Intel(R) 945GM";
117 case PCI_CHIP_I945_GME
:
118 chipset
= "Intel(R) 945GME";
121 chipset
= "Intel(R) G33";
124 chipset
= "Intel(R) Q35";
127 chipset
= "Intel(R) Q33";
129 case PCI_CHIP_IGD_GM
:
131 chipset
= "Intel(R) IGD";
133 case PCI_CHIP_I965_Q
:
134 chipset
= "Intel(R) 965Q";
136 case PCI_CHIP_I965_G
:
137 case PCI_CHIP_I965_G_1
:
138 chipset
= "Intel(R) 965G";
140 case PCI_CHIP_I946_GZ
:
141 chipset
= "Intel(R) 946GZ";
143 case PCI_CHIP_I965_GM
:
144 chipset
= "Intel(R) 965GM";
146 case PCI_CHIP_I965_GME
:
147 chipset
= "Intel(R) 965GME/GLE";
149 case PCI_CHIP_GM45_GM
:
150 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
152 case PCI_CHIP_IGD_E_G
:
153 chipset
= "Intel(R) Integrated Graphics Device";
156 chipset
= "Intel(R) G45/G43";
159 chipset
= "Intel(R) Q45/Q43";
162 chipset
= "Intel(R) G41";
165 chipset
= "Intel(R) B43";
168 chipset
= "Unknown Intel Chipset";
172 (void) driGetRendererString(buffer
, chipset
,
173 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
175 return (GLubyte
*) buffer
;
183 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
185 switch (rb
->Base
._ActualFormat
) {
187 case GL_DEPTH_COMPONENT16
:
191 case GL_DEPTH_COMPONENT24
:
192 case GL_DEPTH24_STENCIL8_EXT
:
193 case GL_STENCIL_INDEX8_EXT
:
201 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
203 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
204 struct intel_renderbuffer
*rb
;
205 struct intel_region
*region
, *depth_region
;
206 struct intel_context
*intel
= context
->driverPrivate
;
207 __DRIbuffer
*buffers
= NULL
;
210 unsigned int attachments
[10];
212 const char *region_name
;
214 if (INTEL_DEBUG
& DEBUG_DRI
)
215 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
217 screen
= intel
->intelScreen
->driScrnPriv
;
219 if (screen
->dri2
.loader
220 && (screen
->dri2
.loader
->base
.version
> 2)
221 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
222 struct intel_renderbuffer
*depth_rb
;
223 struct intel_renderbuffer
*stencil_rb
;
226 if ((intel
->is_front_buffer_rendering
||
227 intel
->is_front_buffer_reading
||
228 !intel_fb
->color_rb
[1])
229 && intel_fb
->color_rb
[0]) {
230 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
231 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
234 if (intel_fb
->color_rb
[1]) {
235 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
236 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
239 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
240 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
242 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
243 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
244 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
245 } else if (depth_rb
!= NULL
) {
246 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
247 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
248 } else if (stencil_rb
!= NULL
) {
249 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
250 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
254 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
259 drawable
->loaderPrivate
);
260 } else if (screen
->dri2
.loader
) {
262 if (intel_fb
->color_rb
[0])
263 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
264 if (intel_fb
->color_rb
[1])
265 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
266 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
267 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
268 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
269 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
271 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
276 drawable
->loaderPrivate
);
286 drawable
->numClipRects
= 1;
287 drawable
->pClipRects
[0].x1
= 0;
288 drawable
->pClipRects
[0].y1
= 0;
289 drawable
->pClipRects
[0].x2
= drawable
->w
;
290 drawable
->pClipRects
[0].y2
= drawable
->h
;
291 drawable
->numBackClipRects
= 1;
292 drawable
->pBackClipRects
[0].x1
= 0;
293 drawable
->pBackClipRects
[0].y1
= 0;
294 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
295 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
298 for (i
= 0; i
< count
; i
++) {
299 switch (buffers
[i
].attachment
) {
300 case __DRI_BUFFER_FRONT_LEFT
:
301 rb
= intel_fb
->color_rb
[0];
302 region_name
= "dri2 front buffer";
305 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
306 rb
= intel_fb
->color_rb
[0];
307 region_name
= "dri2 fake front buffer";
310 case __DRI_BUFFER_BACK_LEFT
:
311 rb
= intel_fb
->color_rb
[1];
312 region_name
= "dri2 back buffer";
315 case __DRI_BUFFER_DEPTH
:
316 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
317 region_name
= "dri2 depth buffer";
320 case __DRI_BUFFER_DEPTH_STENCIL
:
321 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
322 region_name
= "dri2 depth / stencil buffer";
325 case __DRI_BUFFER_STENCIL
:
326 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
327 region_name
= "dri2 stencil buffer";
330 case __DRI_BUFFER_ACCUM
:
333 "unhandled buffer attach event, attacment type %d\n",
334 buffers
[i
].attachment
);
342 dri_bo_flink(rb
->region
->buffer
, &name
);
343 if (name
== buffers
[i
].name
)
347 if (INTEL_DEBUG
& DEBUG_DRI
)
349 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
350 buffers
[i
].name
, buffers
[i
].attachment
,
351 buffers
[i
].cpp
, buffers
[i
].pitch
);
353 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
354 if (INTEL_DEBUG
& DEBUG_DRI
)
355 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
356 intel_region_reference(®ion
, depth_region
);
359 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
362 buffers
[i
].pitch
/ buffers
[i
].cpp
,
366 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
367 depth_region
= region
;
369 intel_renderbuffer_set_region(rb
, region
);
370 intel_region_release(®ion
);
372 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
373 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
375 struct intel_region
*stencil_region
= NULL
;
378 dri_bo_flink(rb
->region
->buffer
, &name
);
379 if (name
== buffers
[i
].name
)
383 intel_region_reference(&stencil_region
, region
);
384 intel_renderbuffer_set_region(rb
, stencil_region
);
385 intel_region_release(&stencil_region
);
390 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
394 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
396 struct intel_context
*intel
= intel_context(ctx
);
397 __DRIcontext
*driContext
= intel
->driContext
;
398 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
399 GLsizei w
, GLsizei h
);
401 if (!driContext
->driScreenPriv
->dri2
.enabled
)
404 if (!intel
->internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
405 /* If we're rendering to the fake front buffer, make sure all the pending
406 * drawing has landed on the real front buffer. Otherwise when we
407 * eventually get to DRI2GetBuffersWithFormat the stale real front
408 * buffer contents will get copied to the new fake front buffer.
410 if (intel
->is_front_buffer_rendering
) {
411 intel_flush(ctx
, GL_FALSE
);
414 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
415 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
416 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
419 old_viewport
= ctx
->Driver
.Viewport
;
420 ctx
->Driver
.Viewport
= NULL
;
421 intel
->driDrawable
= driContext
->driDrawablePriv
;
422 intelWindowMoved(intel
);
423 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
424 ctx
->Driver
.Viewport
= old_viewport
;
428 static const struct dri_debug_control debug_control
[] = {
429 { "tex", DEBUG_TEXTURE
},
430 { "state", DEBUG_STATE
},
431 { "ioctl", DEBUG_IOCTL
},
432 { "blit", DEBUG_BLIT
},
433 { "mip", DEBUG_MIPTREE
},
434 { "fall", DEBUG_FALLBACKS
},
435 { "verb", DEBUG_VERBOSE
},
436 { "bat", DEBUG_BATCH
},
437 { "pix", DEBUG_PIXEL
},
438 { "buf", DEBUG_BUFMGR
},
439 { "reg", DEBUG_REGION
},
441 { "lock", DEBUG_LOCK
},
442 { "sync", DEBUG_SYNC
},
443 { "prim", DEBUG_PRIMS
},
444 { "vert", DEBUG_VERTS
},
445 { "dri", DEBUG_DRI
},
446 { "dma", DEBUG_DMA
},
447 { "san", DEBUG_SANITY
},
448 { "sleep", DEBUG_SLEEP
},
449 { "stats", DEBUG_STATS
},
450 { "tile", DEBUG_TILE
},
451 { "sing", DEBUG_SINGLE_THREAD
},
452 { "thre", DEBUG_SINGLE_THREAD
},
454 { "urb", DEBUG_URB
},
461 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
463 struct intel_context
*intel
= intel_context(ctx
);
465 _swrast_InvalidateState(ctx
, new_state
);
466 _swsetup_InvalidateState(ctx
, new_state
);
467 _vbo_InvalidateState(ctx
, new_state
);
468 _tnl_InvalidateState(ctx
, new_state
);
469 _tnl_invalidate_vertex_state(ctx
, new_state
);
471 intel
->NewGLState
|= new_state
;
473 if (intel
->vtbl
.invalidate_state
)
474 intel
->vtbl
.invalidate_state( intel
, new_state
);
478 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
480 struct intel_context
*intel
= intel_context(ctx
);
485 if (!IS_965(intel
->intelScreen
->deviceID
))
486 INTEL_FIREVERTICES(intel
);
488 /* Emit a flush so that any frontbuffer rendering that might have occurred
489 * lands onscreen in a timely manner, even if the X Server doesn't trigger
493 intel_batchbuffer_emit_mi_flush(intel
->batch
);
495 if (intel
->batch
->map
!= intel
->batch
->ptr
)
496 intel_batchbuffer_flush(intel
->batch
);
498 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
499 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
501 if (screen
->dri2
.loader
&&
502 (screen
->dri2
.loader
->base
.version
>= 2)
503 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
504 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
505 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
506 intel
->driDrawable
->loaderPrivate
);
508 /* Only clear the dirty bit if front-buffer rendering is no longer
509 * enabled. This is done so that the dirty bit can only be set in
510 * glDrawBuffer. Otherwise the dirty bit would have to be set at
511 * each of N places that do rendering. This has worse performances,
512 * but it is much easier to get correct.
514 if (!intel
->is_front_buffer_rendering
) {
515 intel
->front_buffer_dirty
= GL_FALSE
;
522 intelFlush(GLcontext
* ctx
)
524 intel_flush(ctx
, GL_FALSE
);
528 intel_glFlush(GLcontext
*ctx
)
530 struct intel_context
*intel
= intel_context(ctx
);
532 intel_flush(ctx
, GL_TRUE
);
534 /* We're using glFlush as an indicator that a frame is done, which is
535 * what DRI2 does before calling SwapBuffers (and means we should catch
536 * people doing front-buffer rendering, as well)..
538 * Wait for the swapbuffers before the one we just emitted, so we don't
539 * get too many swaps outstanding for apps that are GPU-heavy but not
542 * Unfortunately, we don't have a handle to the batch containing the swap,
543 * and getting our hands on that doesn't seem worth it, so we just us the
544 * first batch we emitted after the last swap.
546 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
547 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
548 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
549 intel
->first_post_swapbuffers_batch
= NULL
;
554 intelFinish(GLcontext
* ctx
)
556 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
561 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
562 struct intel_renderbuffer
*irb
;
564 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
566 if (irb
&& irb
->region
)
567 dri_bo_wait_rendering(irb
->region
->buffer
);
569 if (fb
->_DepthBuffer
) {
570 /* XXX: Wait on buffer idle */
575 intelInitDriverFunctions(struct dd_function_table
*functions
)
577 _mesa_init_driver_functions(functions
);
579 functions
->Flush
= intel_glFlush
;
580 functions
->Finish
= intelFinish
;
581 functions
->GetString
= intelGetString
;
582 functions
->UpdateState
= intelInvalidateState
;
584 functions
->CopyColorTable
= _swrast_CopyColorTable
;
585 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
586 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
587 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
589 intelInitTextureFuncs(functions
);
590 intelInitStateFuncs(functions
);
591 intelInitClearFuncs(functions
);
592 intelInitBufferFuncs(functions
);
593 intelInitPixelFuncs(functions
);
598 intelInitContext(struct intel_context
*intel
,
599 const __GLcontextModes
* mesaVis
,
600 __DRIcontextPrivate
* driContextPriv
,
601 void *sharedContextPrivate
,
602 struct dd_function_table
*functions
)
604 GLcontext
*ctx
= &intel
->ctx
;
605 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
606 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
607 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
610 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
611 functions
, (void *) intel
)) {
612 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
616 driContextPriv
->driverPrivate
= intel
;
617 intel
->intelScreen
= intelScreen
;
618 intel
->driScreen
= sPriv
;
619 intel
->sarea
= intelScreen
->sarea
;
620 intel
->driContext
= driContextPriv
;
623 intel
->hHWContext
= driContextPriv
->hHWContext
;
624 intel
->driFd
= sPriv
->fd
;
625 intel
->driHwLock
= sPriv
->lock
;
627 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
628 intel
->driScreen
->myNum
,
629 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
630 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
631 intel
->maxBatchSize
= 4096;
633 intel
->maxBatchSize
= BATCH_SZ
;
635 intel
->bufmgr
= intelScreen
->bufmgr
;
636 intel
->ttm
= intelScreen
->ttm
;
640 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
641 switch (bo_reuse_mode
) {
642 case DRI_CONF_BO_REUSE_DISABLED
:
644 case DRI_CONF_BO_REUSE_ALL
:
645 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
650 /* This doesn't yet catch all non-conformant rendering, but it's a
653 if (getenv("INTEL_STRICT_CONFORMANCE")) {
654 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
656 intel
->conformance_mode
= value
;
659 intel
->conformance_mode
= 1;
663 if (intel
->conformance_mode
> 0) {
664 ctx
->Const
.MinLineWidth
= 1.0;
665 ctx
->Const
.MinLineWidthAA
= 1.0;
666 ctx
->Const
.MaxLineWidth
= 1.0;
667 ctx
->Const
.MaxLineWidthAA
= 1.0;
668 ctx
->Const
.LineWidthGranularity
= 1.0;
671 ctx
->Const
.MinLineWidth
= 1.0;
672 ctx
->Const
.MinLineWidthAA
= 1.0;
673 ctx
->Const
.MaxLineWidth
= 5.0;
674 ctx
->Const
.MaxLineWidthAA
= 5.0;
675 ctx
->Const
.LineWidthGranularity
= 0.5;
678 ctx
->Const
.MinPointSize
= 1.0;
679 ctx
->Const
.MinPointSizeAA
= 1.0;
680 ctx
->Const
.MaxPointSize
= 255.0;
681 ctx
->Const
.MaxPointSizeAA
= 3.0;
682 ctx
->Const
.PointSizeGranularity
= 1.0;
684 /* reinitialize the context point state.
685 * It depend on constants in __GLcontextRec::Const
687 _mesa_init_point(ctx
);
689 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
691 /* Initialize the software rasterizer and helper modules. */
692 _swrast_CreateContext(ctx
);
693 _vbo_CreateContext(ctx
);
694 _tnl_CreateContext(ctx
);
695 _swsetup_CreateContext(ctx
);
697 /* Configure swrast to match hardware characteristics: */
698 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
699 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
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 */
718 if (IS_965(intelScreen
->deviceID
))
719 intel
->polygon_offset_scale
/= 0xffff;
721 intel
->RenderIndex
= ~0;
723 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
724 intel
->irqsEmitted
= 0;
726 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
727 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
729 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
731 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
732 _mesa_printf("IRQs not active. Exiting\n");
736 intelInitExtensions(ctx
, GL_FALSE
);
738 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
739 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
740 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
742 if (!sPriv
->dri2
.enabled
)
743 intel_recreate_static_regions(intel
);
745 intel
->batch
= intel_batchbuffer_alloc(intel
);
747 intel_bufferobj_init(intel
);
748 intel_fbo_init(intel
);
750 if (intel
->ctx
.Mesa_DXTn
) {
751 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
752 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
754 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
755 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
758 intel
->prim
.primitive
= ~0;
760 /* Force all software fallbacks */
761 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
762 fprintf(stderr
, "disabling 3D rasterization\n");
766 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
767 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
768 intel
->always_flush_batch
= 1;
771 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
772 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
773 intel
->always_flush_cache
= 1;
776 /* Disable all hardware rendering (skip emitting batches and fences/waits
779 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
785 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
787 struct intel_context
*intel
=
788 (struct intel_context
*) driContextPriv
->driverPrivate
;
790 assert(intel
); /* should never be null */
792 GLboolean release_texture_heaps
;
794 INTEL_FIREVERTICES(intel
);
796 if (intel
->clear
.arrayObj
)
797 _mesa_delete_array_object(&intel
->ctx
, intel
->clear
.arrayObj
);
799 intel
->vtbl
.destroy(intel
);
801 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
802 _swsetup_DestroyContext(&intel
->ctx
);
803 _tnl_DestroyContext(&intel
->ctx
);
804 _vbo_DestroyContext(&intel
->ctx
);
806 _swrast_DestroyContext(&intel
->ctx
);
807 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
809 intel_batchbuffer_free(intel
->batch
);
812 free(intel
->prim
.vb
);
813 intel
->prim
.vb
= NULL
;
814 dri_bo_unreference(intel
->prim
.vb_bo
);
815 intel
->prim
.vb_bo
= NULL
;
816 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
817 intel
->first_post_swapbuffers_batch
= NULL
;
819 if (release_texture_heaps
) {
820 /* This share group is about to go away, free our private
821 * texture object data.
823 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
824 fprintf(stderr
, "do something to free texture heaps\n");
827 intel_region_release(&intel
->front_region
);
828 intel_region_release(&intel
->back_region
);
829 intel_region_release(&intel
->depth_region
);
831 driDestroyOptionCache(&intel
->optionCache
);
833 /* free the Mesa context */
834 _mesa_free_context_data(&intel
->ctx
);
837 driContextPriv
->driverPrivate
= NULL
;
842 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
844 struct intel_context
*intel
=
845 (struct intel_context
*) driContextPriv
->driverPrivate
;
847 /* Deassociate the context with the drawables.
849 intel
->driDrawable
= NULL
;
850 intel
->driReadDrawable
= NULL
;
856 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
857 __DRIdrawablePrivate
* driDrawPriv
,
858 __DRIdrawablePrivate
* driReadPriv
)
860 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
862 if (driContextPriv
) {
863 struct intel_context
*intel
=
864 (struct intel_context
*) driContextPriv
->driverPrivate
;
865 struct intel_framebuffer
*intel_fb
=
866 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
867 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
869 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
870 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
871 if (driDrawPriv
!= driReadPriv
)
872 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
874 /* XXX FBO temporary fix-ups! */
875 /* if the renderbuffers don't have regions, init them from the context */
876 struct intel_renderbuffer
*irbDepth
877 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
878 struct intel_renderbuffer
*irbStencil
879 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
881 if (intel_fb
->color_rb
[0]) {
882 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
883 intel
->front_region
);
885 if (intel_fb
->color_rb
[1]) {
886 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
891 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
894 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
898 /* set GLframebuffer size to match window, if needed */
899 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
901 if (driReadPriv
!= driDrawPriv
) {
902 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
905 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
907 /* The drawbuffer won't always be updated by _mesa_make_current:
909 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
911 if (intel
->driReadDrawable
!= driReadPriv
)
912 intel
->driReadDrawable
= driReadPriv
;
914 if (intel
->driDrawable
!= driDrawPriv
) {
915 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
918 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
919 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
920 : VBLANK_FLAG_NO_IRQ
;
922 /* Prevent error printf if one crtc is disabled, this will
923 * be properly calculated in intelWindowMoved() next.
925 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
927 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
928 driDrawableInitVBlank(driDrawPriv
);
929 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
931 for (i
= 0; i
< 2; i
++) {
932 if (intel_fb
->color_rb
[i
])
933 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
936 intel
->driDrawable
= driDrawPriv
;
937 intelWindowMoved(intel
);
940 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
944 _mesa_make_current(NULL
, NULL
, NULL
);
951 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
953 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
954 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
955 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
956 int me
= intel
->hHWContext
;
958 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
961 if (INTEL_DEBUG
& DEBUG_LOCK
)
962 _mesa_printf("%s - got contended lock\n", __progname
);
964 /* If the window moved, may need to set a new cliprect now.
966 * NOTE: This releases and regains the hw lock, so all state
967 * checking must be done *after* this call:
970 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
972 if (sarea
&& sarea
->ctxOwner
!= me
) {
973 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
974 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
975 sarea
->ctxOwner
, me
);
977 sarea
->ctxOwner
= me
;
980 /* If the last consumer of the texture memory wasn't us, notify the fake
981 * bufmgr and record the new owner. We should have the memory shared
982 * between contexts of a single fake bufmgr, but this will at least make
983 * things correct for now.
985 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
986 sarea
->texAge
= intel
->hHWContext
;
987 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
988 if (INTEL_DEBUG
& DEBUG_BATCH
)
989 intel_decode_context_reset();
990 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
991 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
992 sarea
->ctxOwner
, intel
->hHWContext
);
997 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
998 intelWindowMoved(intel
);
999 intel
->lastStamp
= dPriv
->lastStamp
;
1004 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1006 /* Lock the hardware and validate our state.
1008 void LOCK_HARDWARE( struct intel_context
*intel
)
1010 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1011 __DRIscreen
*sPriv
= intel
->driScreen
;
1013 struct intel_framebuffer
*intel_fb
= NULL
;
1014 struct intel_renderbuffer
*intel_rb
= NULL
;
1016 _glthread_LOCK_MUTEX(lockMutex
);
1017 assert(!intel
->locked
);
1020 if (intel
->driDrawable
) {
1021 intel_fb
= intel
->driDrawable
->driverPrivate
;
1025 intel_get_renderbuffer(&intel_fb
->Base
,
1026 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1029 if (intel_rb
&& dPriv
->vblFlags
&&
1030 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1031 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1034 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1036 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1037 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1040 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1041 drmWaitVBlank(intel
->driFd
, &vbl
);
1042 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1045 if (!sPriv
->dri2
.enabled
) {
1046 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1047 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1050 intelContendedLock( intel
, 0 );
1054 if (INTEL_DEBUG
& DEBUG_LOCK
)
1055 _mesa_printf("%s - locked\n", __progname
);
1059 /* Unlock the hardware using the global current context
1061 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1063 __DRIscreen
*sPriv
= intel
->driScreen
;
1065 intel
->vtbl
.note_unlock( intel
);
1068 if (!sPriv
->dri2
.enabled
)
1069 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1071 _glthread_UNLOCK_MUTEX(lockMutex
);
1073 if (INTEL_DEBUG
& DEBUG_LOCK
)
1074 _mesa_printf("%s - unlocked\n", __progname
);
1077 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1080 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1081 intel_batchbuffer_flush(intel
->batch
);