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) IGDNG_D";
169 chipset
= "Intel(R) IGDNG_M";
172 chipset
= "Unknown Intel Chipset";
176 (void) driGetRendererString(buffer
, chipset
,
177 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
179 return (GLubyte
*) buffer
;
187 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
189 switch (rb
->Base
._ActualFormat
) {
191 case GL_DEPTH_COMPONENT16
:
195 case GL_DEPTH_COMPONENT24
:
196 case GL_DEPTH24_STENCIL8_EXT
:
197 case GL_STENCIL_INDEX8_EXT
:
205 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
207 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
208 struct intel_renderbuffer
*rb
;
209 struct intel_region
*region
, *depth_region
;
210 struct intel_context
*intel
= context
->driverPrivate
;
211 __DRIbuffer
*buffers
= NULL
;
214 unsigned int attachments
[10];
216 const char *region_name
;
218 if (INTEL_DEBUG
& DEBUG_DRI
)
219 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
221 screen
= intel
->intelScreen
->driScrnPriv
;
223 if (screen
->dri2
.loader
224 && (screen
->dri2
.loader
->base
.version
> 2)
225 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
226 struct intel_renderbuffer
*depth_rb
;
227 struct intel_renderbuffer
*stencil_rb
;
230 if ((intel
->is_front_buffer_rendering
||
231 intel
->is_front_buffer_reading
||
232 !intel_fb
->color_rb
[1])
233 && intel_fb
->color_rb
[0]) {
234 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
235 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
238 if (intel_fb
->color_rb
[1]) {
239 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
240 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
243 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
244 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
246 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
247 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
248 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
249 } else if (depth_rb
!= NULL
) {
250 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
251 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
252 } else if (stencil_rb
!= NULL
) {
253 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
254 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
258 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
263 drawable
->loaderPrivate
);
264 } else if (screen
->dri2
.loader
) {
266 if (intel_fb
->color_rb
[0])
267 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
268 if (intel_fb
->color_rb
[1])
269 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
270 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
271 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
272 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
273 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
275 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
280 drawable
->loaderPrivate
);
290 drawable
->numClipRects
= 1;
291 drawable
->pClipRects
[0].x1
= 0;
292 drawable
->pClipRects
[0].y1
= 0;
293 drawable
->pClipRects
[0].x2
= drawable
->w
;
294 drawable
->pClipRects
[0].y2
= drawable
->h
;
295 drawable
->numBackClipRects
= 1;
296 drawable
->pBackClipRects
[0].x1
= 0;
297 drawable
->pBackClipRects
[0].y1
= 0;
298 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
299 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
302 for (i
= 0; i
< count
; i
++) {
303 switch (buffers
[i
].attachment
) {
304 case __DRI_BUFFER_FRONT_LEFT
:
305 rb
= intel_fb
->color_rb
[0];
306 region_name
= "dri2 front buffer";
309 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
310 rb
= intel_fb
->color_rb
[0];
311 region_name
= "dri2 fake front buffer";
314 case __DRI_BUFFER_BACK_LEFT
:
315 rb
= intel_fb
->color_rb
[1];
316 region_name
= "dri2 back buffer";
319 case __DRI_BUFFER_DEPTH
:
320 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
321 region_name
= "dri2 depth buffer";
324 case __DRI_BUFFER_DEPTH_STENCIL
:
325 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
326 region_name
= "dri2 depth / stencil buffer";
329 case __DRI_BUFFER_STENCIL
:
330 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
331 region_name
= "dri2 stencil buffer";
334 case __DRI_BUFFER_ACCUM
:
337 "unhandled buffer attach event, attacment type %d\n",
338 buffers
[i
].attachment
);
346 dri_bo_flink(rb
->region
->buffer
, &name
);
347 if (name
== buffers
[i
].name
)
351 if (INTEL_DEBUG
& DEBUG_DRI
)
353 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
354 buffers
[i
].name
, buffers
[i
].attachment
,
355 buffers
[i
].cpp
, buffers
[i
].pitch
);
357 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
358 if (INTEL_DEBUG
& DEBUG_DRI
)
359 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
360 intel_region_reference(®ion
, depth_region
);
363 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
366 buffers
[i
].pitch
/ buffers
[i
].cpp
,
370 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
371 depth_region
= region
;
373 intel_renderbuffer_set_region(rb
, region
);
374 intel_region_release(®ion
);
376 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
377 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
379 struct intel_region
*stencil_region
= NULL
;
382 dri_bo_flink(rb
->region
->buffer
, &name
);
383 if (name
== buffers
[i
].name
)
387 intel_region_reference(&stencil_region
, region
);
388 intel_renderbuffer_set_region(rb
, stencil_region
);
389 intel_region_release(&stencil_region
);
394 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
398 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
400 struct intel_context
*intel
= intel_context(ctx
);
401 __DRIcontext
*driContext
= intel
->driContext
;
402 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
403 GLsizei w
, GLsizei h
);
405 if (!driContext
->driScreenPriv
->dri2
.enabled
)
408 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
409 /* If we're rendering to the fake front buffer, make sure all the pending
410 * drawing has landed on the real front buffer. Otherwise when we
411 * eventually get to DRI2GetBuffersWithFormat the stale real front
412 * buffer contents will get copied to the new fake front buffer.
414 if (intel
->is_front_buffer_rendering
) {
415 intel_flush(ctx
, GL_FALSE
);
418 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
419 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
420 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
423 old_viewport
= ctx
->Driver
.Viewport
;
424 ctx
->Driver
.Viewport
= NULL
;
425 intel
->driDrawable
= driContext
->driDrawablePriv
;
426 intelWindowMoved(intel
);
427 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
428 ctx
->Driver
.Viewport
= old_viewport
;
432 static const struct dri_debug_control debug_control
[] = {
433 { "tex", DEBUG_TEXTURE
},
434 { "state", DEBUG_STATE
},
435 { "ioctl", DEBUG_IOCTL
},
436 { "blit", DEBUG_BLIT
},
437 { "mip", DEBUG_MIPTREE
},
438 { "fall", DEBUG_FALLBACKS
},
439 { "verb", DEBUG_VERBOSE
},
440 { "bat", DEBUG_BATCH
},
441 { "pix", DEBUG_PIXEL
},
442 { "buf", DEBUG_BUFMGR
},
443 { "reg", DEBUG_REGION
},
445 { "lock", DEBUG_LOCK
},
446 { "sync", DEBUG_SYNC
},
447 { "prim", DEBUG_PRIMS
},
448 { "vert", DEBUG_VERTS
},
449 { "dri", DEBUG_DRI
},
450 { "dma", DEBUG_DMA
},
451 { "san", DEBUG_SANITY
},
452 { "sleep", DEBUG_SLEEP
},
453 { "stats", DEBUG_STATS
},
454 { "tile", DEBUG_TILE
},
455 { "sing", DEBUG_SINGLE_THREAD
},
456 { "thre", DEBUG_SINGLE_THREAD
},
458 { "urb", DEBUG_URB
},
465 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
467 struct intel_context
*intel
= intel_context(ctx
);
469 _swrast_InvalidateState(ctx
, new_state
);
470 _swsetup_InvalidateState(ctx
, new_state
);
471 _vbo_InvalidateState(ctx
, new_state
);
472 _tnl_InvalidateState(ctx
, new_state
);
473 _tnl_invalidate_vertex_state(ctx
, new_state
);
475 intel
->NewGLState
|= new_state
;
477 if (intel
->vtbl
.invalidate_state
)
478 intel
->vtbl
.invalidate_state( intel
, new_state
);
482 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
484 struct intel_context
*intel
= intel_context(ctx
);
489 if (!IS_965(intel
->intelScreen
->deviceID
))
490 INTEL_FIREVERTICES(intel
);
492 /* Emit a flush so that any frontbuffer rendering that might have occurred
493 * lands onscreen in a timely manner, even if the X Server doesn't trigger
497 intel_batchbuffer_emit_mi_flush(intel
->batch
);
499 if (intel
->batch
->map
!= intel
->batch
->ptr
)
500 intel_batchbuffer_flush(intel
->batch
);
502 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
503 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
505 if (screen
->dri2
.loader
&&
506 (screen
->dri2
.loader
->base
.version
>= 2)
507 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
508 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
509 intel
->driDrawable
->loaderPrivate
);
511 /* Only clear the dirty bit if front-buffer rendering is no longer
512 * enabled. This is done so that the dirty bit can only be set in
513 * glDrawBuffer. Otherwise the dirty bit would have to be set at
514 * each of N places that do rendering. This has worse performances,
515 * but it is much easier to get correct.
517 if (!intel
->is_front_buffer_rendering
) {
518 intel
->front_buffer_dirty
= GL_FALSE
;
525 intelFlush(GLcontext
* ctx
)
527 intel_flush(ctx
, GL_FALSE
);
531 intel_glFlush(GLcontext
*ctx
)
533 struct intel_context
*intel
= intel_context(ctx
);
535 intel_flush(ctx
, GL_TRUE
);
537 /* We're using glFlush as an indicator that a frame is done, which is
538 * what DRI2 does before calling SwapBuffers (and means we should catch
539 * people doing front-buffer rendering, as well)..
541 * Wait for the swapbuffers before the one we just emitted, so we don't
542 * get too many swaps outstanding for apps that are GPU-heavy but not
545 * Unfortunately, we don't have a handle to the batch containing the swap,
546 * and getting our hands on that doesn't seem worth it, so we just us the
547 * first batch we emitted after the last swap.
549 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
550 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
551 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
552 intel
->first_post_swapbuffers_batch
= NULL
;
557 intelFinish(GLcontext
* ctx
)
559 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
564 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
565 struct intel_renderbuffer
*irb
;
567 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
569 if (irb
&& irb
->region
)
570 dri_bo_wait_rendering(irb
->region
->buffer
);
572 if (fb
->_DepthBuffer
) {
573 /* XXX: Wait on buffer idle */
578 intelInitDriverFunctions(struct dd_function_table
*functions
)
580 _mesa_init_driver_functions(functions
);
582 functions
->Flush
= intel_glFlush
;
583 functions
->Finish
= intelFinish
;
584 functions
->GetString
= intelGetString
;
585 functions
->UpdateState
= intelInvalidateState
;
587 functions
->CopyColorTable
= _swrast_CopyColorTable
;
588 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
589 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
590 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
592 intelInitTextureFuncs(functions
);
593 intelInitTextureImageFuncs(functions
);
594 intelInitTextureSubImageFuncs(functions
);
595 intelInitTextureCopyImageFuncs(functions
);
596 intelInitStateFuncs(functions
);
597 intelInitClearFuncs(functions
);
598 intelInitBufferFuncs(functions
);
599 intelInitPixelFuncs(functions
);
600 intelInitBufferObjectFuncs(functions
);
605 intelInitContext(struct intel_context
*intel
,
606 const __GLcontextModes
* mesaVis
,
607 __DRIcontextPrivate
* driContextPriv
,
608 void *sharedContextPrivate
,
609 struct dd_function_table
*functions
)
611 GLcontext
*ctx
= &intel
->ctx
;
612 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
613 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
614 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
617 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
618 functions
, (void *) intel
)) {
619 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
623 driContextPriv
->driverPrivate
= intel
;
624 intel
->intelScreen
= intelScreen
;
625 intel
->driScreen
= sPriv
;
626 intel
->sarea
= intelScreen
->sarea
;
627 intel
->driContext
= driContextPriv
;
630 intel
->hHWContext
= driContextPriv
->hHWContext
;
631 intel
->driFd
= sPriv
->fd
;
632 intel
->driHwLock
= sPriv
->lock
;
634 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
635 intel
->driScreen
->myNum
,
636 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
637 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
638 intel
->maxBatchSize
= 4096;
640 intel
->maxBatchSize
= BATCH_SZ
;
642 intel
->bufmgr
= intelScreen
->bufmgr
;
643 intel
->ttm
= intelScreen
->ttm
;
647 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
648 switch (bo_reuse_mode
) {
649 case DRI_CONF_BO_REUSE_DISABLED
:
651 case DRI_CONF_BO_REUSE_ALL
:
652 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
657 /* This doesn't yet catch all non-conformant rendering, but it's a
660 if (getenv("INTEL_STRICT_CONFORMANCE")) {
661 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
663 intel
->conformance_mode
= value
;
666 intel
->conformance_mode
= 1;
670 if (intel
->conformance_mode
> 0) {
671 ctx
->Const
.MinLineWidth
= 1.0;
672 ctx
->Const
.MinLineWidthAA
= 1.0;
673 ctx
->Const
.MaxLineWidth
= 1.0;
674 ctx
->Const
.MaxLineWidthAA
= 1.0;
675 ctx
->Const
.LineWidthGranularity
= 1.0;
678 ctx
->Const
.MinLineWidth
= 1.0;
679 ctx
->Const
.MinLineWidthAA
= 1.0;
680 ctx
->Const
.MaxLineWidth
= 5.0;
681 ctx
->Const
.MaxLineWidthAA
= 5.0;
682 ctx
->Const
.LineWidthGranularity
= 0.5;
685 ctx
->Const
.MinPointSize
= 1.0;
686 ctx
->Const
.MinPointSizeAA
= 1.0;
687 ctx
->Const
.MaxPointSize
= 255.0;
688 ctx
->Const
.MaxPointSizeAA
= 3.0;
689 ctx
->Const
.PointSizeGranularity
= 1.0;
691 /* reinitialize the context point state.
692 * It depend on constants in __GLcontextRec::Const
694 _mesa_init_point(ctx
);
696 meta_init_metaops(ctx
, &intel
->meta
);
697 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
698 if (IS_965(intelScreen
->deviceID
)) {
699 if (MAX_WIDTH
> 8192)
700 ctx
->Const
.MaxRenderbufferSize
= 8192;
702 if (MAX_WIDTH
> 2048)
703 ctx
->Const
.MaxRenderbufferSize
= 2048;
706 /* Initialize the software rasterizer and helper modules. */
707 _swrast_CreateContext(ctx
);
708 _vbo_CreateContext(ctx
);
709 _tnl_CreateContext(ctx
);
710 _swsetup_CreateContext(ctx
);
712 /* Configure swrast to match hardware characteristics: */
713 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
714 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
716 _mesa_meta_init(ctx
);
718 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
719 intel
->hw_stipple
= 1;
721 /* XXX FBO: this doesn't seem to be used anywhere */
722 switch (mesaVis
->depthBits
) {
723 case 0: /* what to do in this case? */
725 intel
->polygon_offset_scale
= 1.0;
728 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
735 if (IS_965(intelScreen
->deviceID
))
736 intel
->polygon_offset_scale
/= 0xffff;
738 intel
->RenderIndex
= ~0;
740 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
741 intel
->irqsEmitted
= 0;
743 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
744 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
746 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
748 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
749 _mesa_printf("IRQs not active. Exiting\n");
753 intelInitExtensions(ctx
, GL_FALSE
);
755 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
756 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
757 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
759 if (!sPriv
->dri2
.enabled
)
760 intel_recreate_static_regions(intel
);
762 intel
->batch
= intel_batchbuffer_alloc(intel
);
764 intel_fbo_init(intel
);
766 if (intel
->ctx
.Mesa_DXTn
) {
767 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
768 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
770 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
771 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
773 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
775 if (intel
->use_texture_tiling
&&
776 !intel
->intelScreen
->kernel_exec_fencing
) {
777 fprintf(stderr
, "No kernel support for execution fencing, "
778 "disabling texture tiling\n");
779 intel
->use_texture_tiling
= GL_FALSE
;
781 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
783 intel
->prim
.primitive
= ~0;
785 /* Force all software fallbacks */
786 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
787 fprintf(stderr
, "disabling 3D rasterization\n");
791 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
792 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
793 intel
->always_flush_batch
= 1;
796 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
797 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
798 intel
->always_flush_cache
= 1;
801 /* Disable all hardware rendering (skip emitting batches and fences/waits
804 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
810 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
812 struct intel_context
*intel
=
813 (struct intel_context
*) driContextPriv
->driverPrivate
;
815 assert(intel
); /* should never be null */
817 GLboolean release_texture_heaps
;
819 INTEL_FIREVERTICES(intel
);
821 _mesa_meta_free(&intel
->ctx
);
823 meta_destroy_metaops(&intel
->meta
);
825 intel
->vtbl
.destroy(intel
);
827 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
828 _swsetup_DestroyContext(&intel
->ctx
);
829 _tnl_DestroyContext(&intel
->ctx
);
830 _vbo_DestroyContext(&intel
->ctx
);
832 _swrast_DestroyContext(&intel
->ctx
);
833 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
835 intel_batchbuffer_free(intel
->batch
);
838 free(intel
->prim
.vb
);
839 intel
->prim
.vb
= NULL
;
840 dri_bo_unreference(intel
->prim
.vb_bo
);
841 intel
->prim
.vb_bo
= NULL
;
842 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
843 intel
->first_post_swapbuffers_batch
= NULL
;
845 if (release_texture_heaps
) {
846 /* Nothing is currently done here to free texture heaps;
847 * but we're not using the texture heap utilities, so I
848 * rather think we shouldn't. I've taken a look, and can't
849 * find any private texture data hanging around anywhere, but
850 * I'm not yet certain there isn't any at all...
852 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
853 fprintf(stderr, "do something to free texture heaps\n");
857 /* XXX In intelMakeCurrent() below, the context's static regions are
858 * referenced inside the frame buffer; it's listed as a hack,
859 * with a comment of "XXX FBO temporary fix-ups!", but
860 * as long as it's there, we should release the regions here.
861 * The do/while loop around the block is used to allow the
862 * "continue" statements inside the block to exit the block,
863 * to avoid many layers of "if" constructs.
866 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
867 struct intel_framebuffer
*intel_fb
;
868 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
870 /* We're already detached from the drawable; exit this block. */
873 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
875 /* The frame buffer is already gone; exit this block. */
878 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
879 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
881 /* If the regions of the frame buffer still match the regions
882 * of the context, release them. If they've changed somehow,
885 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
886 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
888 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
889 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
892 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
893 intel_renderbuffer_set_region(irbDepth
, NULL
);
895 /* Usually, the stencil buffer is the same as the depth buffer;
896 * but they're handled separately in MakeCurrent, so we'll
897 * handle them separately here.
899 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
900 intel_renderbuffer_set_region(irbStencil
, NULL
);
904 intel_region_release(&intel
->front_region
);
905 intel_region_release(&intel
->back_region
);
906 intel_region_release(&intel
->depth_region
);
908 driDestroyOptionCache(&intel
->optionCache
);
910 /* free the Mesa context */
911 _mesa_free_context_data(&intel
->ctx
);
914 driContextPriv
->driverPrivate
= NULL
;
919 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
925 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
926 __DRIdrawablePrivate
* driDrawPriv
,
927 __DRIdrawablePrivate
* driReadPriv
)
929 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
931 if (driContextPriv
) {
932 struct intel_context
*intel
=
933 (struct intel_context
*) driContextPriv
->driverPrivate
;
934 struct intel_framebuffer
*intel_fb
=
935 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
936 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
938 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
939 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
940 if (driDrawPriv
!= driReadPriv
)
941 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
943 /* XXX FBO temporary fix-ups! These are released in
944 * intelDextroyContext(), above. Changes here should be
947 /* if the renderbuffers don't have regions, init them from the context */
948 struct intel_renderbuffer
*irbDepth
949 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
950 struct intel_renderbuffer
*irbStencil
951 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
953 if (intel_fb
->color_rb
[0]) {
954 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
955 intel
->front_region
);
957 if (intel_fb
->color_rb
[1]) {
958 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
963 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
966 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
970 /* set GLframebuffer size to match window, if needed */
971 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
973 if (driReadPriv
!= driDrawPriv
) {
974 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
977 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
979 /* The drawbuffer won't always be updated by _mesa_make_current:
981 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
983 if (intel
->driReadDrawable
!= driReadPriv
)
984 intel
->driReadDrawable
= driReadPriv
;
986 if (intel
->driDrawable
!= driDrawPriv
) {
987 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
990 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
991 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
992 : VBLANK_FLAG_NO_IRQ
;
994 /* Prevent error printf if one crtc is disabled, this will
995 * be properly calculated in intelWindowMoved() next.
997 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
999 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
1000 driDrawableInitVBlank(driDrawPriv
);
1001 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
1003 for (i
= 0; i
< 2; i
++) {
1004 if (intel_fb
->color_rb
[i
])
1005 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1008 intel
->driDrawable
= driDrawPriv
;
1009 intelWindowMoved(intel
);
1012 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1016 _mesa_make_current(NULL
, NULL
, NULL
);
1023 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1025 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1026 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1027 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1028 int me
= intel
->hHWContext
;
1030 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1032 if (INTEL_DEBUG
& DEBUG_LOCK
)
1033 _mesa_printf("%s - got contended lock\n", __progname
);
1035 /* If the window moved, may need to set a new cliprect now.
1037 * NOTE: This releases and regains the hw lock, so all state
1038 * checking must be done *after* this call:
1041 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1043 if (sarea
&& sarea
->ctxOwner
!= me
) {
1044 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1045 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1046 sarea
->ctxOwner
, me
);
1048 sarea
->ctxOwner
= me
;
1051 /* If the last consumer of the texture memory wasn't us, notify the fake
1052 * bufmgr and record the new owner. We should have the memory shared
1053 * between contexts of a single fake bufmgr, but this will at least make
1054 * things correct for now.
1056 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1057 sarea
->texAge
= intel
->hHWContext
;
1058 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1059 if (INTEL_DEBUG
& DEBUG_BATCH
)
1060 intel_decode_context_reset();
1061 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1062 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1063 sarea
->ctxOwner
, intel
->hHWContext
);
1066 /* Drawable changed?
1068 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1069 intelWindowMoved(intel
);
1070 intel
->lastStamp
= dPriv
->lastStamp
;
1075 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1077 /* Lock the hardware and validate our state.
1079 void LOCK_HARDWARE( struct intel_context
*intel
)
1081 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1082 __DRIscreen
*sPriv
= intel
->driScreen
;
1084 struct intel_framebuffer
*intel_fb
= NULL
;
1085 struct intel_renderbuffer
*intel_rb
= NULL
;
1088 if (intel
->locked
>= 2)
1091 if (!sPriv
->dri2
.enabled
)
1092 _glthread_LOCK_MUTEX(lockMutex
);
1094 if (intel
->driDrawable
) {
1095 intel_fb
= intel
->driDrawable
->driverPrivate
;
1099 intel_get_renderbuffer(&intel_fb
->Base
,
1100 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1103 if (intel_rb
&& dPriv
->vblFlags
&&
1104 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1105 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1108 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1110 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1111 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1114 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1115 drmWaitVBlank(intel
->driFd
, &vbl
);
1116 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1119 if (!sPriv
->dri2
.enabled
) {
1120 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1121 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1124 intelContendedLock( intel
, 0 );
1128 if (INTEL_DEBUG
& DEBUG_LOCK
)
1129 _mesa_printf("%s - locked\n", __progname
);
1133 /* Unlock the hardware using the global current context
1135 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1137 __DRIscreen
*sPriv
= intel
->driScreen
;
1140 if (intel
->locked
> 0)
1143 assert(intel
->locked
== 0);
1145 if (!sPriv
->dri2
.enabled
) {
1146 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1147 _glthread_UNLOCK_MUTEX(lockMutex
);
1150 if (INTEL_DEBUG
& DEBUG_LOCK
)
1151 _mesa_printf("%s - unlocked\n", __progname
);
1154 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1157 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1158 intel_batchbuffer_flush(intel
->batch
);