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 "20091221 DEVELOPMENT"
72 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
75 static void intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
);
77 static const GLubyte
*
78 intelGetString(GLcontext
* ctx
, GLenum name
)
80 const struct intel_context
*const intel
= intel_context(ctx
);
82 static char buffer
[128];
86 return (GLubyte
*) "Tungsten Graphics, Inc";
90 switch (intel
->intelScreen
->deviceID
) {
92 chipset
= "Intel(R) 845G";
95 chipset
= "Intel(R) 830M";
97 case PCI_CHIP_I855_GM
:
98 chipset
= "Intel(R) 852GM/855GM";
100 case PCI_CHIP_I865_G
:
101 chipset
= "Intel(R) 865G";
103 case PCI_CHIP_I915_G
:
104 chipset
= "Intel(R) 915G";
106 case PCI_CHIP_E7221_G
:
107 chipset
= "Intel (R) E7221G (i915)";
109 case PCI_CHIP_I915_GM
:
110 chipset
= "Intel(R) 915GM";
112 case PCI_CHIP_I945_G
:
113 chipset
= "Intel(R) 945G";
115 case PCI_CHIP_I945_GM
:
116 chipset
= "Intel(R) 945GM";
118 case PCI_CHIP_I945_GME
:
119 chipset
= "Intel(R) 945GME";
122 chipset
= "Intel(R) G33";
125 chipset
= "Intel(R) Q35";
128 chipset
= "Intel(R) Q33";
130 case PCI_CHIP_IGD_GM
:
132 chipset
= "Intel(R) IGD";
134 case PCI_CHIP_I965_Q
:
135 chipset
= "Intel(R) 965Q";
137 case PCI_CHIP_I965_G
:
138 case PCI_CHIP_I965_G_1
:
139 chipset
= "Intel(R) 965G";
141 case PCI_CHIP_I946_GZ
:
142 chipset
= "Intel(R) 946GZ";
144 case PCI_CHIP_I965_GM
:
145 chipset
= "Intel(R) 965GM";
147 case PCI_CHIP_I965_GME
:
148 chipset
= "Intel(R) 965GME/GLE";
150 case PCI_CHIP_GM45_GM
:
151 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
153 case PCI_CHIP_IGD_E_G
:
154 chipset
= "Intel(R) Integrated Graphics Device";
157 chipset
= "Intel(R) G45/G43";
160 chipset
= "Intel(R) Q45/Q43";
163 chipset
= "Intel(R) G41";
166 chipset
= "Intel(R) B43";
169 chipset
= "Intel(R) IGDNG_D";
172 chipset
= "Intel(R) IGDNG_M";
175 chipset
= "Unknown Intel Chipset";
179 (void) driGetRendererString(buffer
, chipset
, DRIVER_DATE_GEM
, 0);
180 return (GLubyte
*) buffer
;
188 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
190 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
194 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
196 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
197 struct intel_renderbuffer
*rb
;
198 struct intel_region
*region
, *depth_region
;
199 struct intel_context
*intel
= context
->driverPrivate
;
200 __DRIbuffer
*buffers
= NULL
;
203 unsigned int attachments
[10];
205 const char *region_name
;
207 if (INTEL_DEBUG
& DEBUG_DRI
)
208 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
210 screen
= intel
->intelScreen
->driScrnPriv
;
212 if (screen
->dri2
.loader
213 && (screen
->dri2
.loader
->base
.version
> 2)
214 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
215 struct intel_renderbuffer
*depth_rb
;
216 struct intel_renderbuffer
*stencil_rb
;
219 if ((intel
->is_front_buffer_rendering
||
220 intel
->is_front_buffer_reading
||
221 !intel_fb
->color_rb
[1])
222 && intel_fb
->color_rb
[0]) {
223 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
224 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
227 if (intel_fb
->color_rb
[1]) {
228 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
229 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
232 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
233 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
235 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
236 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
237 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
238 } else if (depth_rb
!= NULL
) {
239 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
240 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
241 } else if (stencil_rb
!= NULL
) {
242 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
243 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
247 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
252 drawable
->loaderPrivate
);
253 } else if (screen
->dri2
.loader
) {
255 if (intel_fb
->color_rb
[0])
256 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
257 if (intel_fb
->color_rb
[1])
258 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
259 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
260 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
261 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
262 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
264 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
269 drawable
->loaderPrivate
);
279 drawable
->numClipRects
= 1;
280 drawable
->pClipRects
[0].x1
= 0;
281 drawable
->pClipRects
[0].y1
= 0;
282 drawable
->pClipRects
[0].x2
= drawable
->w
;
283 drawable
->pClipRects
[0].y2
= drawable
->h
;
284 drawable
->numBackClipRects
= 1;
285 drawable
->pBackClipRects
[0].x1
= 0;
286 drawable
->pBackClipRects
[0].y1
= 0;
287 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
288 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
291 for (i
= 0; i
< count
; i
++) {
292 switch (buffers
[i
].attachment
) {
293 case __DRI_BUFFER_FRONT_LEFT
:
294 rb
= intel_fb
->color_rb
[0];
295 region_name
= "dri2 front buffer";
298 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
299 rb
= intel_fb
->color_rb
[0];
300 region_name
= "dri2 fake front buffer";
303 case __DRI_BUFFER_BACK_LEFT
:
304 rb
= intel_fb
->color_rb
[1];
305 region_name
= "dri2 back buffer";
308 case __DRI_BUFFER_DEPTH
:
309 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
310 region_name
= "dri2 depth buffer";
313 case __DRI_BUFFER_DEPTH_STENCIL
:
314 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
315 region_name
= "dri2 depth / stencil buffer";
318 case __DRI_BUFFER_STENCIL
:
319 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
320 region_name
= "dri2 stencil buffer";
323 case __DRI_BUFFER_ACCUM
:
326 "unhandled buffer attach event, attacment type %d\n",
327 buffers
[i
].attachment
);
335 dri_bo_flink(rb
->region
->buffer
, &name
);
336 if (name
== buffers
[i
].name
)
340 if (INTEL_DEBUG
& DEBUG_DRI
)
342 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
343 buffers
[i
].name
, buffers
[i
].attachment
,
344 buffers
[i
].cpp
, buffers
[i
].pitch
);
346 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
347 if (INTEL_DEBUG
& DEBUG_DRI
)
348 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
349 intel_region_reference(®ion
, depth_region
);
352 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
355 buffers
[i
].pitch
/ buffers
[i
].cpp
,
359 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
360 depth_region
= region
;
362 intel_renderbuffer_set_region(rb
, region
);
363 intel_region_release(®ion
);
365 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
366 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
368 struct intel_region
*stencil_region
= NULL
;
371 dri_bo_flink(rb
->region
->buffer
, &name
);
372 if (name
== buffers
[i
].name
)
376 intel_region_reference(&stencil_region
, region
);
377 intel_renderbuffer_set_region(rb
, stencil_region
);
378 intel_region_release(&stencil_region
);
383 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
387 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
389 struct intel_context
*intel
= intel_context(ctx
);
390 __DRIcontext
*driContext
= intel
->driContext
;
391 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
392 GLsizei w
, GLsizei h
);
394 if (!driContext
->driScreenPriv
->dri2
.enabled
)
397 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
398 /* If we're rendering to the fake front buffer, make sure all the pending
399 * drawing has landed on the real front buffer. Otherwise when we
400 * eventually get to DRI2GetBuffersWithFormat the stale real front
401 * buffer contents will get copied to the new fake front buffer.
403 if (intel
->is_front_buffer_rendering
) {
404 intel_flush(ctx
, GL_FALSE
);
407 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
408 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
409 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
412 old_viewport
= ctx
->Driver
.Viewport
;
413 ctx
->Driver
.Viewport
= NULL
;
414 intel
->driDrawable
= driContext
->driDrawablePriv
;
415 intelWindowMoved(intel
);
416 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
417 ctx
->Driver
.Viewport
= old_viewport
;
421 static const struct dri_debug_control debug_control
[] = {
422 { "tex", DEBUG_TEXTURE
},
423 { "state", DEBUG_STATE
},
424 { "ioctl", DEBUG_IOCTL
},
425 { "blit", DEBUG_BLIT
},
426 { "mip", DEBUG_MIPTREE
},
427 { "fall", DEBUG_FALLBACKS
},
428 { "verb", DEBUG_VERBOSE
},
429 { "bat", DEBUG_BATCH
},
430 { "pix", DEBUG_PIXEL
},
431 { "buf", DEBUG_BUFMGR
},
432 { "reg", DEBUG_REGION
},
434 { "lock", DEBUG_LOCK
},
435 { "sync", DEBUG_SYNC
},
436 { "prim", DEBUG_PRIMS
},
437 { "vert", DEBUG_VERTS
},
438 { "dri", DEBUG_DRI
},
439 { "dma", DEBUG_DMA
},
440 { "san", DEBUG_SANITY
},
441 { "sleep", DEBUG_SLEEP
},
442 { "stats", DEBUG_STATS
},
443 { "tile", DEBUG_TILE
},
444 { "sing", DEBUG_SINGLE_THREAD
},
445 { "thre", DEBUG_SINGLE_THREAD
},
447 { "urb", DEBUG_URB
},
454 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
456 struct intel_context
*intel
= intel_context(ctx
);
458 _swrast_InvalidateState(ctx
, new_state
);
459 _swsetup_InvalidateState(ctx
, new_state
);
460 _vbo_InvalidateState(ctx
, new_state
);
461 _tnl_InvalidateState(ctx
, new_state
);
462 _tnl_invalidate_vertex_state(ctx
, new_state
);
464 intel
->NewGLState
|= new_state
;
466 if (intel
->vtbl
.invalidate_state
)
467 intel
->vtbl
.invalidate_state( intel
, new_state
);
471 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
473 struct intel_context
*intel
= intel_context(ctx
);
479 INTEL_FIREVERTICES(intel
);
481 /* Emit a flush so that any frontbuffer rendering that might have occurred
482 * lands onscreen in a timely manner, even if the X Server doesn't trigger
485 if (!intel
->driScreen
->dri2
.enabled
&& needs_mi_flush
)
486 intel_batchbuffer_emit_mi_flush(intel
->batch
);
488 if (intel
->batch
->map
!= intel
->batch
->ptr
)
489 intel_batchbuffer_flush(intel
->batch
);
491 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
492 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
494 if (screen
->dri2
.loader
&&
495 (screen
->dri2
.loader
->base
.version
>= 2)
496 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
497 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
498 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
499 intel
->driDrawable
->loaderPrivate
);
501 /* Only clear the dirty bit if front-buffer rendering is no longer
502 * enabled. This is done so that the dirty bit can only be set in
503 * glDrawBuffer. Otherwise the dirty bit would have to be set at
504 * each of N places that do rendering. This has worse performances,
505 * but it is much easier to get correct.
507 if (!intel
->is_front_buffer_rendering
) {
508 intel
->front_buffer_dirty
= GL_FALSE
;
515 intelFlush(GLcontext
* ctx
)
517 intel_flush(ctx
, GL_FALSE
);
521 intel_glFlush(GLcontext
*ctx
)
523 struct intel_context
*intel
= intel_context(ctx
);
525 intel_flush(ctx
, GL_TRUE
);
527 /* We're using glFlush as an indicator that a frame is done, which is
528 * what DRI2 does before calling SwapBuffers (and means we should catch
529 * people doing front-buffer rendering, as well)..
531 * Wait for the swapbuffers before the one we just emitted, so we don't
532 * get too many swaps outstanding for apps that are GPU-heavy but not
535 * Unfortunately, we don't have a handle to the batch containing the swap,
536 * and getting our hands on that doesn't seem worth it, so we just us the
537 * first batch we emitted after the last swap.
539 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
540 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
541 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
542 intel
->first_post_swapbuffers_batch
= NULL
;
547 intelFinish(GLcontext
* ctx
)
549 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
554 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
555 struct intel_renderbuffer
*irb
;
557 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
559 if (irb
&& irb
->region
)
560 dri_bo_wait_rendering(irb
->region
->buffer
);
562 if (fb
->_DepthBuffer
) {
563 /* XXX: Wait on buffer idle */
568 intelInitDriverFunctions(struct dd_function_table
*functions
)
570 _mesa_init_driver_functions(functions
);
572 functions
->Flush
= intel_glFlush
;
573 functions
->Finish
= intelFinish
;
574 functions
->GetString
= intelGetString
;
575 functions
->UpdateState
= intelInvalidateState
;
577 intelInitTextureFuncs(functions
);
578 intelInitTextureImageFuncs(functions
);
579 intelInitTextureSubImageFuncs(functions
);
580 intelInitTextureCopyImageFuncs(functions
);
581 intelInitStateFuncs(functions
);
582 intelInitClearFuncs(functions
);
583 intelInitBufferFuncs(functions
);
584 intelInitPixelFuncs(functions
);
585 intelInitBufferObjectFuncs(functions
);
586 intel_init_syncobj_functions(functions
);
591 intelInitContext(struct intel_context
*intel
,
592 const __GLcontextModes
* mesaVis
,
593 __DRIcontextPrivate
* driContextPriv
,
594 void *sharedContextPrivate
,
595 struct dd_function_table
*functions
)
597 GLcontext
*ctx
= &intel
->ctx
;
598 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
599 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
600 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
604 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
605 functions
, (void *) intel
)) {
606 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
610 driContextPriv
->driverPrivate
= intel
;
611 intel
->intelScreen
= intelScreen
;
612 intel
->driScreen
= sPriv
;
613 intel
->sarea
= intelScreen
->sarea
;
614 intel
->driContext
= driContextPriv
;
616 if (IS_965(intel
->intelScreen
->deviceID
))
618 else if (IS_9XX(intel
->intelScreen
->deviceID
))
623 if (IS_IGDNG(intel
->intelScreen
->deviceID
)) {
624 intel
->is_ironlake
= GL_TRUE
;
625 intel
->needs_ff_sync
= GL_TRUE
;
629 intel
->hHWContext
= driContextPriv
->hHWContext
;
630 intel
->driFd
= sPriv
->fd
;
631 intel
->driHwLock
= sPriv
->lock
;
633 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
634 intel
->driScreen
->myNum
,
635 (intel
->gen
>= 4) ? "i965" : "i915");
636 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
637 intel
->maxBatchSize
= 4096;
639 intel
->maxBatchSize
= BATCH_SZ
;
641 intel
->bufmgr
= intelScreen
->bufmgr
;
643 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
644 switch (bo_reuse_mode
) {
645 case DRI_CONF_BO_REUSE_DISABLED
:
647 case DRI_CONF_BO_REUSE_ALL
:
648 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
652 /* This doesn't yet catch all non-conformant rendering, but it's a
655 if (getenv("INTEL_STRICT_CONFORMANCE")) {
656 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
658 intel
->conformance_mode
= value
;
661 intel
->conformance_mode
= 1;
665 if (intel
->conformance_mode
> 0) {
666 ctx
->Const
.MinLineWidth
= 1.0;
667 ctx
->Const
.MinLineWidthAA
= 1.0;
668 ctx
->Const
.MaxLineWidth
= 1.0;
669 ctx
->Const
.MaxLineWidthAA
= 1.0;
670 ctx
->Const
.LineWidthGranularity
= 1.0;
673 ctx
->Const
.MinLineWidth
= 1.0;
674 ctx
->Const
.MinLineWidthAA
= 1.0;
675 ctx
->Const
.MaxLineWidth
= 5.0;
676 ctx
->Const
.MaxLineWidthAA
= 5.0;
677 ctx
->Const
.LineWidthGranularity
= 0.5;
680 ctx
->Const
.MinPointSize
= 1.0;
681 ctx
->Const
.MinPointSizeAA
= 1.0;
682 ctx
->Const
.MaxPointSize
= 255.0;
683 ctx
->Const
.MaxPointSizeAA
= 3.0;
684 ctx
->Const
.PointSizeGranularity
= 1.0;
686 /* reinitialize the context point state.
687 * It depend on constants in __GLcontextRec::Const
689 _mesa_init_point(ctx
);
691 meta_init_metaops(ctx
, &intel
->meta
);
692 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
693 if (intel
->gen
>= 4) {
694 if (MAX_WIDTH
> 8192)
695 ctx
->Const
.MaxRenderbufferSize
= 8192;
697 if (MAX_WIDTH
> 2048)
698 ctx
->Const
.MaxRenderbufferSize
= 2048;
701 /* Initialize the software rasterizer and helper modules. */
702 _swrast_CreateContext(ctx
);
703 _vbo_CreateContext(ctx
);
704 _tnl_CreateContext(ctx
);
705 _swsetup_CreateContext(ctx
);
707 /* Configure swrast to match hardware characteristics: */
708 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
709 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
711 _mesa_meta_init(ctx
);
713 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
714 intel
->hw_stipple
= 1;
716 /* XXX FBO: this doesn't seem to be used anywhere */
717 switch (mesaVis
->depthBits
) {
718 case 0: /* what to do in this case? */
720 intel
->polygon_offset_scale
= 1.0;
723 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
731 intel
->polygon_offset_scale
/= 0xffff;
733 intel
->RenderIndex
= ~0;
735 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
737 if (intel
->gen
>= 4 && !intel
->intelScreen
->irq_active
) {
738 _mesa_printf("IRQs not active. Exiting\n");
742 intelInitExtensions(ctx
);
744 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
745 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
746 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
748 if (!sPriv
->dri2
.enabled
)
749 intel_recreate_static_regions(intel
);
751 intel
->batch
= intel_batchbuffer_alloc(intel
);
753 intel_fbo_init(intel
);
755 if (intel
->ctx
.Mesa_DXTn
) {
756 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
757 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
759 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
760 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
762 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
764 if (intel
->use_texture_tiling
&&
765 !intel
->intelScreen
->kernel_exec_fencing
) {
766 fprintf(stderr
, "No kernel support for execution fencing, "
767 "disabling texture tiling\n");
768 intel
->use_texture_tiling
= GL_FALSE
;
770 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
772 intel
->prim
.primitive
= ~0;
774 /* Force all software fallbacks */
775 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
776 fprintf(stderr
, "disabling 3D rasterization\n");
780 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
781 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
782 intel
->always_flush_batch
= 1;
785 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
786 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
787 intel
->always_flush_cache
= 1;
790 /* Disable all hardware rendering (skip emitting batches and fences/waits
793 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
799 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
801 struct intel_context
*intel
=
802 (struct intel_context
*) driContextPriv
->driverPrivate
;
804 assert(intel
); /* should never be null */
806 GLboolean release_texture_heaps
;
808 INTEL_FIREVERTICES(intel
);
810 _mesa_meta_free(&intel
->ctx
);
812 meta_destroy_metaops(&intel
->meta
);
814 intel
->vtbl
.destroy(intel
);
816 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
817 _swsetup_DestroyContext(&intel
->ctx
);
818 _tnl_DestroyContext(&intel
->ctx
);
819 _vbo_DestroyContext(&intel
->ctx
);
821 _swrast_DestroyContext(&intel
->ctx
);
822 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
824 intel_batchbuffer_free(intel
->batch
);
827 free(intel
->prim
.vb
);
828 intel
->prim
.vb
= NULL
;
829 dri_bo_unreference(intel
->prim
.vb_bo
);
830 intel
->prim
.vb_bo
= NULL
;
831 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
832 intel
->first_post_swapbuffers_batch
= NULL
;
834 if (release_texture_heaps
) {
835 /* Nothing is currently done here to free texture heaps;
836 * but we're not using the texture heap utilities, so I
837 * rather think we shouldn't. I've taken a look, and can't
838 * find any private texture data hanging around anywhere, but
839 * I'm not yet certain there isn't any at all...
841 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
842 fprintf(stderr, "do something to free texture heaps\n");
846 /* XXX In intelMakeCurrent() below, the context's static regions are
847 * referenced inside the frame buffer; it's listed as a hack,
848 * with a comment of "XXX FBO temporary fix-ups!", but
849 * as long as it's there, we should release the regions here.
850 * The do/while loop around the block is used to allow the
851 * "continue" statements inside the block to exit the block,
852 * to avoid many layers of "if" constructs.
855 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
856 struct intel_framebuffer
*intel_fb
;
857 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
859 /* We're already detached from the drawable; exit this block. */
862 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
864 /* The frame buffer is already gone; exit this block. */
867 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
868 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
870 /* If the regions of the frame buffer still match the regions
871 * of the context, release them. If they've changed somehow,
874 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
875 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
877 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
878 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
881 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
882 intel_renderbuffer_set_region(irbDepth
, NULL
);
884 /* Usually, the stencil buffer is the same as the depth buffer;
885 * but they're handled separately in MakeCurrent, so we'll
886 * handle them separately here.
888 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
889 intel_renderbuffer_set_region(irbStencil
, NULL
);
893 intel_region_release(&intel
->front_region
);
894 intel_region_release(&intel
->back_region
);
895 intel_region_release(&intel
->depth_region
);
897 driDestroyOptionCache(&intel
->optionCache
);
899 /* free the Mesa context */
900 _mesa_free_context_data(&intel
->ctx
);
903 driContextPriv
->driverPrivate
= NULL
;
908 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
910 struct intel_context
*intel
=
911 (struct intel_context
*) driContextPriv
->driverPrivate
;
913 /* Deassociate the context with the drawables.
915 intel
->driDrawable
= NULL
;
916 intel
->driReadDrawable
= NULL
;
922 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
923 __DRIdrawablePrivate
* driDrawPriv
,
924 __DRIdrawablePrivate
* driReadPriv
)
926 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
927 struct intel_context
*intel
;
928 GET_CURRENT_CONTEXT(curCtx
);
931 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
935 /* According to the glXMakeCurrent() man page: "Pending commands to
936 * the previous context, if any, are flushed before it is released."
937 * But only flush if we're actually changing contexts.
939 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
943 if (driContextPriv
) {
944 struct intel_framebuffer
*intel_fb
=
945 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
946 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
948 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
949 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
950 if (driDrawPriv
!= driReadPriv
)
951 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
953 /* XXX FBO temporary fix-ups! These are released in
954 * intelDextroyContext(), above. Changes here should be
957 /* if the renderbuffers don't have regions, init them from the context */
958 struct intel_renderbuffer
*irbDepth
959 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
960 struct intel_renderbuffer
*irbStencil
961 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
963 if (intel_fb
->color_rb
[0]) {
964 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
965 intel
->front_region
);
967 if (intel_fb
->color_rb
[1]) {
968 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
973 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
976 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
980 /* set GLframebuffer size to match window, if needed */
981 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
983 if (driReadPriv
!= driDrawPriv
) {
984 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
987 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
989 intel
->driReadDrawable
= driReadPriv
;
991 if (intel
->driDrawable
!= driDrawPriv
) {
992 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
995 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
996 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
997 : VBLANK_FLAG_NO_IRQ
;
999 /* Prevent error printf if one crtc is disabled, this will
1000 * be properly calculated in intelWindowMoved() next.
1002 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
1004 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
1005 driDrawableInitVBlank(driDrawPriv
);
1006 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
1008 for (i
= 0; i
< 2; i
++) {
1009 if (intel_fb
->color_rb
[i
])
1010 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1013 intel
->driDrawable
= driDrawPriv
;
1014 intelWindowMoved(intel
);
1017 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1020 _mesa_make_current(NULL
, NULL
, NULL
);
1027 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1029 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1030 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1031 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1032 int me
= intel
->hHWContext
;
1034 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1036 if (INTEL_DEBUG
& DEBUG_LOCK
)
1037 _mesa_printf("%s - got contended lock\n", __progname
);
1039 /* If the window moved, may need to set a new cliprect now.
1041 * NOTE: This releases and regains the hw lock, so all state
1042 * checking must be done *after* this call:
1045 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1047 if (sarea
&& sarea
->ctxOwner
!= me
) {
1048 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1049 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1050 sarea
->ctxOwner
, me
);
1052 sarea
->ctxOwner
= me
;
1055 /* Drawable changed?
1057 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1058 intelWindowMoved(intel
);
1059 intel
->lastStamp
= dPriv
->lastStamp
;
1064 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1066 /* Lock the hardware and validate our state.
1068 void LOCK_HARDWARE( struct intel_context
*intel
)
1070 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1071 __DRIscreen
*sPriv
= intel
->driScreen
;
1073 struct intel_framebuffer
*intel_fb
= NULL
;
1074 struct intel_renderbuffer
*intel_rb
= NULL
;
1077 if (intel
->locked
>= 2)
1080 if (!sPriv
->dri2
.enabled
)
1081 _glthread_LOCK_MUTEX(lockMutex
);
1083 if (intel
->driDrawable
) {
1084 intel_fb
= intel
->driDrawable
->driverPrivate
;
1088 intel_get_renderbuffer(&intel_fb
->Base
,
1089 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1092 if (intel_rb
&& dPriv
->vblFlags
&&
1093 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1094 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1097 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1099 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1100 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1103 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1104 drmWaitVBlank(intel
->driFd
, &vbl
);
1105 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1108 if (!sPriv
->dri2
.enabled
) {
1109 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1110 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1113 intelContendedLock( intel
, 0 );
1117 if (INTEL_DEBUG
& DEBUG_LOCK
)
1118 _mesa_printf("%s - locked\n", __progname
);
1122 /* Unlock the hardware using the global current context
1124 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1126 __DRIscreen
*sPriv
= intel
->driScreen
;
1129 if (intel
->locked
> 0)
1132 assert(intel
->locked
== 0);
1134 if (!sPriv
->dri2
.enabled
) {
1135 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1136 _glthread_UNLOCK_MUTEX(lockMutex
);
1139 if (INTEL_DEBUG
& DEBUG_LOCK
)
1140 _mesa_printf("%s - unlocked\n", __progname
);
1143 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1146 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1147 intel_batchbuffer_flush(intel
->batch
);