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
= "Intel(R) IGDNG_D";
171 chipset
= "Intel(R) IGDNG_M";
174 chipset
= "Unknown Intel Chipset";
178 (void) driGetRendererString(buffer
, chipset
,
179 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
181 return (GLubyte
*) buffer
;
189 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
191 switch (rb
->Base
._ActualFormat
) {
193 case GL_DEPTH_COMPONENT16
:
197 case GL_DEPTH_COMPONENT24
:
198 case GL_DEPTH24_STENCIL8_EXT
:
199 case GL_STENCIL_INDEX8_EXT
:
207 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
209 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
210 struct intel_renderbuffer
*rb
;
211 struct intel_region
*region
, *depth_region
;
212 struct intel_context
*intel
= context
->driverPrivate
;
213 __DRIbuffer
*buffers
= NULL
;
216 unsigned int attachments
[10];
218 const char *region_name
;
220 if (INTEL_DEBUG
& DEBUG_DRI
)
221 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
223 screen
= intel
->intelScreen
->driScrnPriv
;
225 if (screen
->dri2
.loader
226 && (screen
->dri2
.loader
->base
.version
> 2)
227 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
228 struct intel_renderbuffer
*depth_rb
;
229 struct intel_renderbuffer
*stencil_rb
;
232 if ((intel
->is_front_buffer_rendering
||
233 intel
->is_front_buffer_reading
||
234 !intel_fb
->color_rb
[1])
235 && intel_fb
->color_rb
[0]) {
236 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
237 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
240 if (intel_fb
->color_rb
[1]) {
241 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
242 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
245 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
246 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
248 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
249 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
250 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
251 } else if (depth_rb
!= NULL
) {
252 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
253 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
254 } else if (stencil_rb
!= NULL
) {
255 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
256 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
260 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
265 drawable
->loaderPrivate
);
266 } else if (screen
->dri2
.loader
) {
268 if (intel_fb
->color_rb
[0])
269 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
270 if (intel_fb
->color_rb
[1])
271 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
272 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
273 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
274 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
275 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
277 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
282 drawable
->loaderPrivate
);
292 drawable
->numClipRects
= 1;
293 drawable
->pClipRects
[0].x1
= 0;
294 drawable
->pClipRects
[0].y1
= 0;
295 drawable
->pClipRects
[0].x2
= drawable
->w
;
296 drawable
->pClipRects
[0].y2
= drawable
->h
;
297 drawable
->numBackClipRects
= 1;
298 drawable
->pBackClipRects
[0].x1
= 0;
299 drawable
->pBackClipRects
[0].y1
= 0;
300 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
301 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
304 for (i
= 0; i
< count
; i
++) {
305 switch (buffers
[i
].attachment
) {
306 case __DRI_BUFFER_FRONT_LEFT
:
307 rb
= intel_fb
->color_rb
[0];
308 region_name
= "dri2 front buffer";
311 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
312 rb
= intel_fb
->color_rb
[0];
313 region_name
= "dri2 fake front buffer";
316 case __DRI_BUFFER_BACK_LEFT
:
317 rb
= intel_fb
->color_rb
[1];
318 region_name
= "dri2 back buffer";
321 case __DRI_BUFFER_DEPTH
:
322 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
323 region_name
= "dri2 depth buffer";
326 case __DRI_BUFFER_DEPTH_STENCIL
:
327 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
328 region_name
= "dri2 depth / stencil buffer";
331 case __DRI_BUFFER_STENCIL
:
332 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
333 region_name
= "dri2 stencil buffer";
336 case __DRI_BUFFER_ACCUM
:
339 "unhandled buffer attach event, attacment type %d\n",
340 buffers
[i
].attachment
);
348 dri_bo_flink(rb
->region
->buffer
, &name
);
349 if (name
== buffers
[i
].name
)
353 if (INTEL_DEBUG
& DEBUG_DRI
)
355 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
356 buffers
[i
].name
, buffers
[i
].attachment
,
357 buffers
[i
].cpp
, buffers
[i
].pitch
);
359 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
360 if (INTEL_DEBUG
& DEBUG_DRI
)
361 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
362 intel_region_reference(®ion
, depth_region
);
365 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
368 buffers
[i
].pitch
/ buffers
[i
].cpp
,
372 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
373 depth_region
= region
;
375 intel_renderbuffer_set_region(rb
, region
);
376 intel_region_release(®ion
);
378 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
379 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
381 struct intel_region
*stencil_region
= NULL
;
384 dri_bo_flink(rb
->region
->buffer
, &name
);
385 if (name
== buffers
[i
].name
)
389 intel_region_reference(&stencil_region
, region
);
390 intel_renderbuffer_set_region(rb
, stencil_region
);
391 intel_region_release(&stencil_region
);
396 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
400 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
402 struct intel_context
*intel
= intel_context(ctx
);
403 __DRIcontext
*driContext
= intel
->driContext
;
404 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
405 GLsizei w
, GLsizei h
);
407 if (!driContext
->driScreenPriv
->dri2
.enabled
)
410 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
411 /* If we're rendering to the fake front buffer, make sure all the pending
412 * drawing has landed on the real front buffer. Otherwise when we
413 * eventually get to DRI2GetBuffersWithFormat the stale real front
414 * buffer contents will get copied to the new fake front buffer.
416 if (intel
->is_front_buffer_rendering
) {
417 intel_flush(ctx
, GL_FALSE
);
420 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
421 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
422 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
425 old_viewport
= ctx
->Driver
.Viewport
;
426 ctx
->Driver
.Viewport
= NULL
;
427 intel
->driDrawable
= driContext
->driDrawablePriv
;
428 intelWindowMoved(intel
);
429 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
430 ctx
->Driver
.Viewport
= old_viewport
;
434 static const struct dri_debug_control debug_control
[] = {
435 { "tex", DEBUG_TEXTURE
},
436 { "state", DEBUG_STATE
},
437 { "ioctl", DEBUG_IOCTL
},
438 { "blit", DEBUG_BLIT
},
439 { "mip", DEBUG_MIPTREE
},
440 { "fall", DEBUG_FALLBACKS
},
441 { "verb", DEBUG_VERBOSE
},
442 { "bat", DEBUG_BATCH
},
443 { "pix", DEBUG_PIXEL
},
444 { "buf", DEBUG_BUFMGR
},
445 { "reg", DEBUG_REGION
},
447 { "lock", DEBUG_LOCK
},
448 { "sync", DEBUG_SYNC
},
449 { "prim", DEBUG_PRIMS
},
450 { "vert", DEBUG_VERTS
},
451 { "dri", DEBUG_DRI
},
452 { "dma", DEBUG_DMA
},
453 { "san", DEBUG_SANITY
},
454 { "sleep", DEBUG_SLEEP
},
455 { "stats", DEBUG_STATS
},
456 { "tile", DEBUG_TILE
},
457 { "sing", DEBUG_SINGLE_THREAD
},
458 { "thre", DEBUG_SINGLE_THREAD
},
460 { "urb", DEBUG_URB
},
467 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
469 struct intel_context
*intel
= intel_context(ctx
);
471 _swrast_InvalidateState(ctx
, new_state
);
472 _swsetup_InvalidateState(ctx
, new_state
);
473 _vbo_InvalidateState(ctx
, new_state
);
474 _tnl_InvalidateState(ctx
, new_state
);
475 _tnl_invalidate_vertex_state(ctx
, new_state
);
477 intel
->NewGLState
|= new_state
;
479 if (intel
->vtbl
.invalidate_state
)
480 intel
->vtbl
.invalidate_state( intel
, new_state
);
484 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
486 struct intel_context
*intel
= intel_context(ctx
);
491 if (!IS_965(intel
->intelScreen
->deviceID
))
492 INTEL_FIREVERTICES(intel
);
494 /* Emit a flush so that any frontbuffer rendering that might have occurred
495 * lands onscreen in a timely manner, even if the X Server doesn't trigger
499 intel_batchbuffer_emit_mi_flush(intel
->batch
);
501 if (intel
->batch
->map
!= intel
->batch
->ptr
)
502 intel_batchbuffer_flush(intel
->batch
);
504 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
505 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
507 if (screen
->dri2
.loader
&&
508 (screen
->dri2
.loader
->base
.version
>= 2)
509 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
510 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
511 intel
->driDrawable
->loaderPrivate
);
513 /* Only clear the dirty bit if front-buffer rendering is no longer
514 * enabled. This is done so that the dirty bit can only be set in
515 * glDrawBuffer. Otherwise the dirty bit would have to be set at
516 * each of N places that do rendering. This has worse performances,
517 * but it is much easier to get correct.
519 if (!intel
->is_front_buffer_rendering
) {
520 intel
->front_buffer_dirty
= GL_FALSE
;
527 intelFlush(GLcontext
* ctx
)
529 intel_flush(ctx
, GL_FALSE
);
533 intel_glFlush(GLcontext
*ctx
)
535 struct intel_context
*intel
= intel_context(ctx
);
537 intel_flush(ctx
, GL_TRUE
);
539 /* We're using glFlush as an indicator that a frame is done, which is
540 * what DRI2 does before calling SwapBuffers (and means we should catch
541 * people doing front-buffer rendering, as well)..
543 * Wait for the swapbuffers before the one we just emitted, so we don't
544 * get too many swaps outstanding for apps that are GPU-heavy but not
547 * Unfortunately, we don't have a handle to the batch containing the swap,
548 * and getting our hands on that doesn't seem worth it, so we just us the
549 * first batch we emitted after the last swap.
551 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
552 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
553 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
554 intel
->first_post_swapbuffers_batch
= NULL
;
559 intelFinish(GLcontext
* ctx
)
561 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
566 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
567 struct intel_renderbuffer
*irb
;
569 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
571 if (irb
&& irb
->region
)
572 dri_bo_wait_rendering(irb
->region
->buffer
);
574 if (fb
->_DepthBuffer
) {
575 /* XXX: Wait on buffer idle */
580 intelInitDriverFunctions(struct dd_function_table
*functions
)
582 _mesa_init_driver_functions(functions
);
584 functions
->Flush
= intel_glFlush
;
585 functions
->Finish
= intelFinish
;
586 functions
->GetString
= intelGetString
;
587 functions
->UpdateState
= intelInvalidateState
;
589 intelInitTextureFuncs(functions
);
590 intelInitTextureImageFuncs(functions
);
591 intelInitTextureSubImageFuncs(functions
);
592 intelInitTextureCopyImageFuncs(functions
);
593 intelInitStateFuncs(functions
);
594 intelInitClearFuncs(functions
);
595 intelInitBufferFuncs(functions
);
596 intelInitPixelFuncs(functions
);
597 intelInitBufferObjectFuncs(functions
);
598 intel_init_syncobj_functions(functions
);
603 intelInitContext(struct intel_context
*intel
,
604 const __GLcontextModes
* mesaVis
,
605 __DRIcontextPrivate
* driContextPriv
,
606 void *sharedContextPrivate
,
607 struct dd_function_table
*functions
)
609 GLcontext
*ctx
= &intel
->ctx
;
610 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
611 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
612 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
615 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
616 functions
, (void *) intel
)) {
617 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
621 driContextPriv
->driverPrivate
= intel
;
622 intel
->intelScreen
= intelScreen
;
623 intel
->driScreen
= sPriv
;
624 intel
->sarea
= intelScreen
->sarea
;
625 intel
->driContext
= driContextPriv
;
628 intel
->hHWContext
= driContextPriv
->hHWContext
;
629 intel
->driFd
= sPriv
->fd
;
630 intel
->driHwLock
= sPriv
->lock
;
632 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
633 intel
->driScreen
->myNum
,
634 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
635 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
636 intel
->maxBatchSize
= 4096;
638 intel
->maxBatchSize
= BATCH_SZ
;
640 intel
->bufmgr
= intelScreen
->bufmgr
;
641 intel
->ttm
= intelScreen
->ttm
;
645 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
646 switch (bo_reuse_mode
) {
647 case DRI_CONF_BO_REUSE_DISABLED
:
649 case DRI_CONF_BO_REUSE_ALL
:
650 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
655 /* This doesn't yet catch all non-conformant rendering, but it's a
658 if (getenv("INTEL_STRICT_CONFORMANCE")) {
659 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
661 intel
->conformance_mode
= value
;
664 intel
->conformance_mode
= 1;
668 if (intel
->conformance_mode
> 0) {
669 ctx
->Const
.MinLineWidth
= 1.0;
670 ctx
->Const
.MinLineWidthAA
= 1.0;
671 ctx
->Const
.MaxLineWidth
= 1.0;
672 ctx
->Const
.MaxLineWidthAA
= 1.0;
673 ctx
->Const
.LineWidthGranularity
= 1.0;
676 ctx
->Const
.MinLineWidth
= 1.0;
677 ctx
->Const
.MinLineWidthAA
= 1.0;
678 ctx
->Const
.MaxLineWidth
= 5.0;
679 ctx
->Const
.MaxLineWidthAA
= 5.0;
680 ctx
->Const
.LineWidthGranularity
= 0.5;
683 ctx
->Const
.MinPointSize
= 1.0;
684 ctx
->Const
.MinPointSizeAA
= 1.0;
685 ctx
->Const
.MaxPointSize
= 255.0;
686 ctx
->Const
.MaxPointSizeAA
= 3.0;
687 ctx
->Const
.PointSizeGranularity
= 1.0;
689 /* reinitialize the context point state.
690 * It depend on constants in __GLcontextRec::Const
692 _mesa_init_point(ctx
);
694 meta_init_metaops(ctx
, &intel
->meta
);
695 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
696 if (IS_965(intelScreen
->deviceID
)) {
697 if (MAX_WIDTH
> 8192)
698 ctx
->Const
.MaxRenderbufferSize
= 8192;
700 if (MAX_WIDTH
> 2048)
701 ctx
->Const
.MaxRenderbufferSize
= 2048;
704 /* Initialize the software rasterizer and helper modules. */
705 _swrast_CreateContext(ctx
);
706 _vbo_CreateContext(ctx
);
707 _tnl_CreateContext(ctx
);
708 _swsetup_CreateContext(ctx
);
710 /* Configure swrast to match hardware characteristics: */
711 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
712 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
714 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
715 intel
->hw_stipple
= 1;
717 /* XXX FBO: this doesn't seem to be used anywhere */
718 switch (mesaVis
->depthBits
) {
719 case 0: /* what to do in this case? */
721 intel
->polygon_offset_scale
= 1.0;
724 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
731 if (IS_965(intelScreen
->deviceID
))
732 intel
->polygon_offset_scale
/= 0xffff;
734 intel
->RenderIndex
= ~0;
736 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
737 intel
->irqsEmitted
= 0;
739 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
740 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
742 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
744 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
745 _mesa_printf("IRQs not active. Exiting\n");
749 intelInitExtensions(ctx
, GL_FALSE
);
751 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
752 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
753 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
755 if (!sPriv
->dri2
.enabled
)
756 intel_recreate_static_regions(intel
);
758 intel
->batch
= intel_batchbuffer_alloc(intel
);
760 intel_fbo_init(intel
);
762 if (intel
->ctx
.Mesa_DXTn
) {
763 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
764 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
766 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
767 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
769 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
771 if (intel
->use_texture_tiling
&&
772 !intel
->intelScreen
->kernel_exec_fencing
) {
773 fprintf(stderr
, "No kernel support for execution fencing, "
774 "disabling texture tiling\n");
775 intel
->use_texture_tiling
= GL_FALSE
;
777 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
779 intel
->prim
.primitive
= ~0;
781 /* Force all software fallbacks */
782 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
783 fprintf(stderr
, "disabling 3D rasterization\n");
787 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
788 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
789 intel
->always_flush_batch
= 1;
792 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
793 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
794 intel
->always_flush_cache
= 1;
797 /* Disable all hardware rendering (skip emitting batches and fences/waits
800 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
806 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
808 struct intel_context
*intel
=
809 (struct intel_context
*) driContextPriv
->driverPrivate
;
811 assert(intel
); /* should never be null */
813 GLboolean release_texture_heaps
;
815 INTEL_FIREVERTICES(intel
);
817 meta_destroy_metaops(&intel
->meta
);
819 intel
->vtbl
.destroy(intel
);
821 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
822 _swsetup_DestroyContext(&intel
->ctx
);
823 _tnl_DestroyContext(&intel
->ctx
);
824 _vbo_DestroyContext(&intel
->ctx
);
826 _swrast_DestroyContext(&intel
->ctx
);
827 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
829 intel_batchbuffer_free(intel
->batch
);
832 free(intel
->prim
.vb
);
833 intel
->prim
.vb
= NULL
;
834 dri_bo_unreference(intel
->prim
.vb_bo
);
835 intel
->prim
.vb_bo
= NULL
;
836 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
837 intel
->first_post_swapbuffers_batch
= NULL
;
839 if (release_texture_heaps
) {
840 /* Nothing is currently done here to free texture heaps;
841 * but we're not using the texture heap utilities, so I
842 * rather think we shouldn't. I've taken a look, and can't
843 * find any private texture data hanging around anywhere, but
844 * I'm not yet certain there isn't any at all...
846 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
847 fprintf(stderr, "do something to free texture heaps\n");
851 /* XXX In intelMakeCurrent() below, the context's static regions are
852 * referenced inside the frame buffer; it's listed as a hack,
853 * with a comment of "XXX FBO temporary fix-ups!", but
854 * as long as it's there, we should release the regions here.
855 * The do/while loop around the block is used to allow the
856 * "continue" statements inside the block to exit the block,
857 * to avoid many layers of "if" constructs.
860 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
861 struct intel_framebuffer
*intel_fb
;
862 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
864 /* We're already detached from the drawable; exit this block. */
867 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
869 /* The frame buffer is already gone; exit this block. */
872 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
873 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
875 /* If the regions of the frame buffer still match the regions
876 * of the context, release them. If they've changed somehow,
879 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
880 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
882 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
883 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
886 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
887 intel_renderbuffer_set_region(irbDepth
, NULL
);
889 /* Usually, the stencil buffer is the same as the depth buffer;
890 * but they're handled separately in MakeCurrent, so we'll
891 * handle them separately here.
893 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
894 intel_renderbuffer_set_region(irbStencil
, NULL
);
898 intel_region_release(&intel
->front_region
);
899 intel_region_release(&intel
->back_region
);
900 intel_region_release(&intel
->depth_region
);
902 driDestroyOptionCache(&intel
->optionCache
);
904 /* free the Mesa context */
905 _mesa_free_context_data(&intel
->ctx
);
908 driContextPriv
->driverPrivate
= NULL
;
913 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
915 struct intel_context
*intel
=
916 (struct intel_context
*) driContextPriv
->driverPrivate
;
918 /* Deassociate the context with the drawables.
920 intel
->driDrawable
= NULL
;
921 intel
->driReadDrawable
= NULL
;
927 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
928 __DRIdrawablePrivate
* driDrawPriv
,
929 __DRIdrawablePrivate
* driReadPriv
)
931 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
933 if (driContextPriv
) {
934 struct intel_context
*intel
=
935 (struct intel_context
*) driContextPriv
->driverPrivate
;
936 struct intel_framebuffer
*intel_fb
=
937 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
938 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
940 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
941 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
942 if (driDrawPriv
!= driReadPriv
)
943 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
945 /* XXX FBO temporary fix-ups! These are released in
946 * intelDextroyContext(), above. Changes here should be
949 /* if the renderbuffers don't have regions, init them from the context */
950 struct intel_renderbuffer
*irbDepth
951 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
952 struct intel_renderbuffer
*irbStencil
953 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
955 if (intel_fb
->color_rb
[0]) {
956 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
957 intel
->front_region
);
959 if (intel_fb
->color_rb
[1]) {
960 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
965 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
968 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
972 /* set GLframebuffer size to match window, if needed */
973 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
975 if (driReadPriv
!= driDrawPriv
) {
976 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
979 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
981 /* The drawbuffer won't always be updated by _mesa_make_current:
983 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
985 if (intel
->driReadDrawable
!= driReadPriv
)
986 intel
->driReadDrawable
= driReadPriv
;
988 if (intel
->driDrawable
!= driDrawPriv
) {
989 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
992 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
993 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
994 : VBLANK_FLAG_NO_IRQ
;
996 /* Prevent error printf if one crtc is disabled, this will
997 * be properly calculated in intelWindowMoved() next.
999 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
1001 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
1002 driDrawableInitVBlank(driDrawPriv
);
1003 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
1005 for (i
= 0; i
< 2; i
++) {
1006 if (intel_fb
->color_rb
[i
])
1007 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1010 intel
->driDrawable
= driDrawPriv
;
1011 intelWindowMoved(intel
);
1014 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1018 _mesa_make_current(NULL
, NULL
, NULL
);
1025 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1027 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1028 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1029 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1030 int me
= intel
->hHWContext
;
1032 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1034 if (INTEL_DEBUG
& DEBUG_LOCK
)
1035 _mesa_printf("%s - got contended lock\n", __progname
);
1037 /* If the window moved, may need to set a new cliprect now.
1039 * NOTE: This releases and regains the hw lock, so all state
1040 * checking must be done *after* this call:
1043 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1045 if (sarea
&& sarea
->ctxOwner
!= me
) {
1046 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1047 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1048 sarea
->ctxOwner
, me
);
1050 sarea
->ctxOwner
= me
;
1053 /* If the last consumer of the texture memory wasn't us, notify the fake
1054 * bufmgr and record the new owner. We should have the memory shared
1055 * between contexts of a single fake bufmgr, but this will at least make
1056 * things correct for now.
1058 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1059 sarea
->texAge
= intel
->hHWContext
;
1060 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1061 if (INTEL_DEBUG
& DEBUG_BATCH
)
1062 intel_decode_context_reset();
1063 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1064 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1065 sarea
->ctxOwner
, intel
->hHWContext
);
1068 /* Drawable changed?
1070 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1071 intelWindowMoved(intel
);
1072 intel
->lastStamp
= dPriv
->lastStamp
;
1077 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1079 /* Lock the hardware and validate our state.
1081 void LOCK_HARDWARE( struct intel_context
*intel
)
1083 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1084 __DRIscreen
*sPriv
= intel
->driScreen
;
1086 struct intel_framebuffer
*intel_fb
= NULL
;
1087 struct intel_renderbuffer
*intel_rb
= NULL
;
1090 if (intel
->locked
>= 2)
1093 if (!sPriv
->dri2
.enabled
)
1094 _glthread_LOCK_MUTEX(lockMutex
);
1096 if (intel
->driDrawable
) {
1097 intel_fb
= intel
->driDrawable
->driverPrivate
;
1101 intel_get_renderbuffer(&intel_fb
->Base
,
1102 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1105 if (intel_rb
&& dPriv
->vblFlags
&&
1106 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1107 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1110 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1112 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1113 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1116 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1117 drmWaitVBlank(intel
->driFd
, &vbl
);
1118 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1121 if (!sPriv
->dri2
.enabled
) {
1122 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1123 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1126 intelContendedLock( intel
, 0 );
1130 if (INTEL_DEBUG
& DEBUG_LOCK
)
1131 _mesa_printf("%s - locked\n", __progname
);
1135 /* Unlock the hardware using the global current context
1137 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1139 __DRIscreen
*sPriv
= intel
->driScreen
;
1142 if (intel
->locked
> 0)
1145 assert(intel
->locked
== 0);
1147 if (!sPriv
->dri2
.enabled
) {
1148 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1149 _glthread_UNLOCK_MUTEX(lockMutex
);
1152 if (INTEL_DEBUG
& DEBUG_LOCK
)
1153 _mesa_printf("%s - unlocked\n", __progname
);
1156 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1159 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1160 intel_batchbuffer_flush(intel
->batch
);