1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/arrayobj.h"
32 #include "main/extensions.h"
33 #include "main/framebuffer.h"
34 #include "main/imports.h"
35 #include "main/points.h"
37 #include "swrast/swrast.h"
38 #include "swrast_setup/swrast_setup.h"
40 #include "drivers/common/driverfuncs.h"
41 #include "drivers/common/meta.h"
45 #include "intel_chipset.h"
46 #include "intel_buffers.h"
47 #include "intel_tex.h"
48 #include "intel_batchbuffer.h"
49 #include "intel_clear.h"
50 #include "intel_extensions.h"
51 #include "intel_pixel.h"
52 #include "intel_regions.h"
53 #include "intel_buffer_objects.h"
54 #include "intel_fbo.h"
55 #include "intel_decode.h"
56 #include "intel_bufmgr.h"
57 #include "intel_screen.h"
58 #include "intel_swapbuffers.h"
60 #include "drirenderbuffer.h"
63 #include "xmlpool.h" /* for symbolic values of enum-type options */
67 int INTEL_DEBUG
= (0);
71 #define DRIVER_DATE "20090712 2009Q2 RC3"
72 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
75 static void intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
);
77 static const GLubyte
*
78 intelGetString(GLcontext
* ctx
, GLenum name
)
80 const struct intel_context
*const intel
= intel_context(ctx
);
82 static char buffer
[128];
86 return (GLubyte
*) "Tungsten Graphics, Inc";
90 switch (intel
->intelScreen
->deviceID
) {
92 chipset
= "Intel(R) 845G";
95 chipset
= "Intel(R) 830M";
97 case PCI_CHIP_I855_GM
:
98 chipset
= "Intel(R) 852GM/855GM";
100 case PCI_CHIP_I865_G
:
101 chipset
= "Intel(R) 865G";
103 case PCI_CHIP_I915_G
:
104 chipset
= "Intel(R) 915G";
106 case PCI_CHIP_E7221_G
:
107 chipset
= "Intel (R) E7221G (i915)";
109 case PCI_CHIP_I915_GM
:
110 chipset
= "Intel(R) 915GM";
112 case PCI_CHIP_I945_G
:
113 chipset
= "Intel(R) 945G";
115 case PCI_CHIP_I945_GM
:
116 chipset
= "Intel(R) 945GM";
118 case PCI_CHIP_I945_GME
:
119 chipset
= "Intel(R) 945GME";
122 chipset
= "Intel(R) G33";
125 chipset
= "Intel(R) Q35";
128 chipset
= "Intel(R) Q33";
130 case PCI_CHIP_IGD_GM
:
132 chipset
= "Intel(R) IGD";
134 case PCI_CHIP_I965_Q
:
135 chipset
= "Intel(R) 965Q";
137 case PCI_CHIP_I965_G
:
138 case PCI_CHIP_I965_G_1
:
139 chipset
= "Intel(R) 965G";
141 case PCI_CHIP_I946_GZ
:
142 chipset
= "Intel(R) 946GZ";
144 case PCI_CHIP_I965_GM
:
145 chipset
= "Intel(R) 965GM";
147 case PCI_CHIP_I965_GME
:
148 chipset
= "Intel(R) 965GME/GLE";
150 case PCI_CHIP_GM45_GM
:
151 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
153 case PCI_CHIP_IGD_E_G
:
154 chipset
= "Intel(R) Integrated Graphics Device";
157 chipset
= "Intel(R) G45/G43";
160 chipset
= "Intel(R) Q45/Q43";
163 chipset
= "Intel(R) G41";
166 chipset
= "Intel(R) B43";
169 chipset
= "Intel(R) IGDNG_D";
172 chipset
= "Intel(R) IGDNG_M";
175 chipset
= "Unknown Intel Chipset";
179 (void) driGetRendererString(buffer
, chipset
,
180 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
182 return (GLubyte
*) buffer
;
190 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
192 return _mesa_get_format_bytes(rb
->Base
.Format
) * 8;
196 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
198 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
199 struct intel_renderbuffer
*rb
;
200 struct intel_region
*region
, *depth_region
;
201 struct intel_context
*intel
= context
->driverPrivate
;
202 __DRIbuffer
*buffers
= NULL
;
205 unsigned int attachments
[10];
207 const char *region_name
;
209 if (INTEL_DEBUG
& DEBUG_DRI
)
210 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
212 screen
= intel
->intelScreen
->driScrnPriv
;
214 if (screen
->dri2
.loader
215 && (screen
->dri2
.loader
->base
.version
> 2)
216 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
217 struct intel_renderbuffer
*depth_rb
;
218 struct intel_renderbuffer
*stencil_rb
;
221 if ((intel
->is_front_buffer_rendering
||
222 intel
->is_front_buffer_reading
||
223 !intel_fb
->color_rb
[1])
224 && intel_fb
->color_rb
[0]) {
225 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
226 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
229 if (intel_fb
->color_rb
[1]) {
230 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
231 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
234 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
235 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
237 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
238 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
239 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
240 } else if (depth_rb
!= NULL
) {
241 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
242 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
243 } else if (stencil_rb
!= NULL
) {
244 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
245 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
249 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
254 drawable
->loaderPrivate
);
255 } else if (screen
->dri2
.loader
) {
257 if (intel_fb
->color_rb
[0])
258 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
259 if (intel_fb
->color_rb
[1])
260 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
261 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
262 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
263 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
264 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
266 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
271 drawable
->loaderPrivate
);
281 drawable
->numClipRects
= 1;
282 drawable
->pClipRects
[0].x1
= 0;
283 drawable
->pClipRects
[0].y1
= 0;
284 drawable
->pClipRects
[0].x2
= drawable
->w
;
285 drawable
->pClipRects
[0].y2
= drawable
->h
;
286 drawable
->numBackClipRects
= 1;
287 drawable
->pBackClipRects
[0].x1
= 0;
288 drawable
->pBackClipRects
[0].y1
= 0;
289 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
290 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
293 for (i
= 0; i
< count
; i
++) {
294 switch (buffers
[i
].attachment
) {
295 case __DRI_BUFFER_FRONT_LEFT
:
296 rb
= intel_fb
->color_rb
[0];
297 region_name
= "dri2 front buffer";
300 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
301 rb
= intel_fb
->color_rb
[0];
302 region_name
= "dri2 fake front buffer";
305 case __DRI_BUFFER_BACK_LEFT
:
306 rb
= intel_fb
->color_rb
[1];
307 region_name
= "dri2 back buffer";
310 case __DRI_BUFFER_DEPTH
:
311 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
312 region_name
= "dri2 depth buffer";
315 case __DRI_BUFFER_DEPTH_STENCIL
:
316 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
317 region_name
= "dri2 depth / stencil buffer";
320 case __DRI_BUFFER_STENCIL
:
321 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
322 region_name
= "dri2 stencil buffer";
325 case __DRI_BUFFER_ACCUM
:
328 "unhandled buffer attach event, attacment type %d\n",
329 buffers
[i
].attachment
);
337 dri_bo_flink(rb
->region
->buffer
, &name
);
338 if (name
== buffers
[i
].name
)
342 if (INTEL_DEBUG
& DEBUG_DRI
)
344 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
345 buffers
[i
].name
, buffers
[i
].attachment
,
346 buffers
[i
].cpp
, buffers
[i
].pitch
);
348 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
349 if (INTEL_DEBUG
& DEBUG_DRI
)
350 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
351 intel_region_reference(®ion
, depth_region
);
354 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
357 buffers
[i
].pitch
/ buffers
[i
].cpp
,
361 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
362 depth_region
= region
;
364 intel_renderbuffer_set_region(rb
, region
);
365 intel_region_release(®ion
);
367 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
368 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
370 struct intel_region
*stencil_region
= NULL
;
373 dri_bo_flink(rb
->region
->buffer
, &name
);
374 if (name
== buffers
[i
].name
)
378 intel_region_reference(&stencil_region
, region
);
379 intel_renderbuffer_set_region(rb
, stencil_region
);
380 intel_region_release(&stencil_region
);
385 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
389 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
391 struct intel_context
*intel
= intel_context(ctx
);
392 __DRIcontext
*driContext
= intel
->driContext
;
393 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
394 GLsizei w
, GLsizei h
);
396 if (!driContext
->driScreenPriv
->dri2
.enabled
)
399 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
400 /* If we're rendering to the fake front buffer, make sure all the pending
401 * drawing has landed on the real front buffer. Otherwise when we
402 * eventually get to DRI2GetBuffersWithFormat the stale real front
403 * buffer contents will get copied to the new fake front buffer.
405 if (intel
->is_front_buffer_rendering
) {
406 intel_flush(ctx
, GL_FALSE
);
409 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
410 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
411 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
414 old_viewport
= ctx
->Driver
.Viewport
;
415 ctx
->Driver
.Viewport
= NULL
;
416 intel
->driDrawable
= driContext
->driDrawablePriv
;
417 intelWindowMoved(intel
);
418 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
419 ctx
->Driver
.Viewport
= old_viewport
;
423 static const struct dri_debug_control debug_control
[] = {
424 { "tex", DEBUG_TEXTURE
},
425 { "state", DEBUG_STATE
},
426 { "ioctl", DEBUG_IOCTL
},
427 { "blit", DEBUG_BLIT
},
428 { "mip", DEBUG_MIPTREE
},
429 { "fall", DEBUG_FALLBACKS
},
430 { "verb", DEBUG_VERBOSE
},
431 { "bat", DEBUG_BATCH
},
432 { "pix", DEBUG_PIXEL
},
433 { "buf", DEBUG_BUFMGR
},
434 { "reg", DEBUG_REGION
},
436 { "lock", DEBUG_LOCK
},
437 { "sync", DEBUG_SYNC
},
438 { "prim", DEBUG_PRIMS
},
439 { "vert", DEBUG_VERTS
},
440 { "dri", DEBUG_DRI
},
441 { "dma", DEBUG_DMA
},
442 { "san", DEBUG_SANITY
},
443 { "sleep", DEBUG_SLEEP
},
444 { "stats", DEBUG_STATS
},
445 { "tile", DEBUG_TILE
},
446 { "sing", DEBUG_SINGLE_THREAD
},
447 { "thre", DEBUG_SINGLE_THREAD
},
449 { "urb", DEBUG_URB
},
456 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
458 struct intel_context
*intel
= intel_context(ctx
);
460 _swrast_InvalidateState(ctx
, new_state
);
461 _swsetup_InvalidateState(ctx
, new_state
);
462 _vbo_InvalidateState(ctx
, new_state
);
463 _tnl_InvalidateState(ctx
, new_state
);
464 _tnl_invalidate_vertex_state(ctx
, new_state
);
466 intel
->NewGLState
|= new_state
;
468 if (intel
->vtbl
.invalidate_state
)
469 intel
->vtbl
.invalidate_state( intel
, new_state
);
473 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
475 struct intel_context
*intel
= intel_context(ctx
);
481 INTEL_FIREVERTICES(intel
);
483 /* Emit a flush so that any frontbuffer rendering that might have occurred
484 * lands onscreen in a timely manner, even if the X Server doesn't trigger
487 if (!intel
->driScreen
->dri2
.enabled
&& needs_mi_flush
)
488 intel_batchbuffer_emit_mi_flush(intel
->batch
);
490 if (intel
->batch
->map
!= intel
->batch
->ptr
)
491 intel_batchbuffer_flush(intel
->batch
);
493 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
494 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
496 if (screen
->dri2
.loader
&&
497 (screen
->dri2
.loader
->base
.version
>= 2)
498 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
) &&
499 intel
->driDrawable
&& intel
->driDrawable
->loaderPrivate
) {
500 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
501 intel
->driDrawable
->loaderPrivate
);
503 /* Only clear the dirty bit if front-buffer rendering is no longer
504 * enabled. This is done so that the dirty bit can only be set in
505 * glDrawBuffer. Otherwise the dirty bit would have to be set at
506 * each of N places that do rendering. This has worse performances,
507 * but it is much easier to get correct.
509 if (!intel
->is_front_buffer_rendering
) {
510 intel
->front_buffer_dirty
= GL_FALSE
;
517 intelFlush(GLcontext
* ctx
)
519 intel_flush(ctx
, GL_FALSE
);
523 intel_glFlush(GLcontext
*ctx
)
525 struct intel_context
*intel
= intel_context(ctx
);
527 intel_flush(ctx
, GL_TRUE
);
529 /* We're using glFlush as an indicator that a frame is done, which is
530 * what DRI2 does before calling SwapBuffers (and means we should catch
531 * people doing front-buffer rendering, as well)..
533 * Wait for the swapbuffers before the one we just emitted, so we don't
534 * get too many swaps outstanding for apps that are GPU-heavy but not
537 * Unfortunately, we don't have a handle to the batch containing the swap,
538 * and getting our hands on that doesn't seem worth it, so we just us the
539 * first batch we emitted after the last swap.
541 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
542 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
543 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
544 intel
->first_post_swapbuffers_batch
= NULL
;
549 intelFinish(GLcontext
* ctx
)
551 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
556 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
557 struct intel_renderbuffer
*irb
;
559 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
561 if (irb
&& irb
->region
)
562 dri_bo_wait_rendering(irb
->region
->buffer
);
564 if (fb
->_DepthBuffer
) {
565 /* XXX: Wait on buffer idle */
570 intelInitDriverFunctions(struct dd_function_table
*functions
)
572 _mesa_init_driver_functions(functions
);
574 functions
->Flush
= intel_glFlush
;
575 functions
->Finish
= intelFinish
;
576 functions
->GetString
= intelGetString
;
577 functions
->UpdateState
= intelInvalidateState
;
579 intelInitTextureFuncs(functions
);
580 intelInitTextureImageFuncs(functions
);
581 intelInitTextureSubImageFuncs(functions
);
582 intelInitTextureCopyImageFuncs(functions
);
583 intelInitStateFuncs(functions
);
584 intelInitClearFuncs(functions
);
585 intelInitBufferFuncs(functions
);
586 intelInitPixelFuncs(functions
);
587 intelInitBufferObjectFuncs(functions
);
588 intel_init_syncobj_functions(functions
);
593 intelInitContext(struct intel_context
*intel
,
594 const __GLcontextModes
* mesaVis
,
595 __DRIcontextPrivate
* driContextPriv
,
596 void *sharedContextPrivate
,
597 struct dd_function_table
*functions
)
599 GLcontext
*ctx
= &intel
->ctx
;
600 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
601 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
602 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
605 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
606 functions
, (void *) intel
)) {
607 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
611 driContextPriv
->driverPrivate
= intel
;
612 intel
->intelScreen
= intelScreen
;
613 intel
->driScreen
= sPriv
;
614 intel
->sarea
= intelScreen
->sarea
;
615 intel
->driContext
= driContextPriv
;
617 if (IS_965(intel
->intelScreen
->deviceID
))
619 else if (IS_9XX(intel
->intelScreen
->deviceID
))
625 intel
->hHWContext
= driContextPriv
->hHWContext
;
626 intel
->driFd
= sPriv
->fd
;
627 intel
->driHwLock
= sPriv
->lock
;
629 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
630 intel
->driScreen
->myNum
,
631 (intel
->gen
>= 4) ? "i965" : "i915");
632 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
633 intel
->maxBatchSize
= 4096;
635 intel
->maxBatchSize
= BATCH_SZ
;
637 intel
->bufmgr
= intelScreen
->bufmgr
;
638 intel
->ttm
= intelScreen
->ttm
;
642 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
643 switch (bo_reuse_mode
) {
644 case DRI_CONF_BO_REUSE_DISABLED
:
646 case DRI_CONF_BO_REUSE_ALL
:
647 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");
736 intel
->irqsEmitted
= 0;
738 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
739 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
741 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
743 if (intel
->gen
>= 4 && !intel
->intelScreen
->irq_active
) {
744 _mesa_printf("IRQs not active. Exiting\n");
748 intelInitExtensions(ctx
);
750 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
751 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
752 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
754 if (!sPriv
->dri2
.enabled
)
755 intel_recreate_static_regions(intel
);
757 intel
->batch
= intel_batchbuffer_alloc(intel
);
759 intel_fbo_init(intel
);
761 if (intel
->ctx
.Mesa_DXTn
) {
762 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
763 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
765 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
766 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
768 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
770 if (intel
->use_texture_tiling
&&
771 !intel
->intelScreen
->kernel_exec_fencing
) {
772 fprintf(stderr
, "No kernel support for execution fencing, "
773 "disabling texture tiling\n");
774 intel
->use_texture_tiling
= GL_FALSE
;
776 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
778 intel
->prim
.primitive
= ~0;
780 /* Force all software fallbacks */
781 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
782 fprintf(stderr
, "disabling 3D rasterization\n");
786 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
787 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
788 intel
->always_flush_batch
= 1;
791 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
792 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
793 intel
->always_flush_cache
= 1;
796 /* Disable all hardware rendering (skip emitting batches and fences/waits
799 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
805 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
807 struct intel_context
*intel
=
808 (struct intel_context
*) driContextPriv
->driverPrivate
;
810 assert(intel
); /* should never be null */
812 GLboolean release_texture_heaps
;
814 INTEL_FIREVERTICES(intel
);
816 _mesa_meta_free(&intel
->ctx
);
818 meta_destroy_metaops(&intel
->meta
);
820 intel
->vtbl
.destroy(intel
);
822 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
823 _swsetup_DestroyContext(&intel
->ctx
);
824 _tnl_DestroyContext(&intel
->ctx
);
825 _vbo_DestroyContext(&intel
->ctx
);
827 _swrast_DestroyContext(&intel
->ctx
);
828 intel
->Fallback
= 0x0; /* don't call _swrast_Flush later */
830 intel_batchbuffer_free(intel
->batch
);
833 free(intel
->prim
.vb
);
834 intel
->prim
.vb
= NULL
;
835 dri_bo_unreference(intel
->prim
.vb_bo
);
836 intel
->prim
.vb_bo
= NULL
;
837 dri_bo_unreference(intel
->first_post_swapbuffers_batch
);
838 intel
->first_post_swapbuffers_batch
= NULL
;
840 if (release_texture_heaps
) {
841 /* Nothing is currently done here to free texture heaps;
842 * but we're not using the texture heap utilities, so I
843 * rather think we shouldn't. I've taken a look, and can't
844 * find any private texture data hanging around anywhere, but
845 * I'm not yet certain there isn't any at all...
847 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
848 fprintf(stderr, "do something to free texture heaps\n");
852 /* XXX In intelMakeCurrent() below, the context's static regions are
853 * referenced inside the frame buffer; it's listed as a hack,
854 * with a comment of "XXX FBO temporary fix-ups!", but
855 * as long as it's there, we should release the regions here.
856 * The do/while loop around the block is used to allow the
857 * "continue" statements inside the block to exit the block,
858 * to avoid many layers of "if" constructs.
861 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
862 struct intel_framebuffer
*intel_fb
;
863 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
865 /* We're already detached from the drawable; exit this block. */
868 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
870 /* The frame buffer is already gone; exit this block. */
873 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
874 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
876 /* If the regions of the frame buffer still match the regions
877 * of the context, release them. If they've changed somehow,
880 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
881 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
883 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
884 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
887 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
888 intel_renderbuffer_set_region(irbDepth
, NULL
);
890 /* Usually, the stencil buffer is the same as the depth buffer;
891 * but they're handled separately in MakeCurrent, so we'll
892 * handle them separately here.
894 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
895 intel_renderbuffer_set_region(irbStencil
, NULL
);
899 intel_region_release(&intel
->front_region
);
900 intel_region_release(&intel
->back_region
);
901 intel_region_release(&intel
->depth_region
);
903 driDestroyOptionCache(&intel
->optionCache
);
905 /* free the Mesa context */
906 _mesa_free_context_data(&intel
->ctx
);
909 driContextPriv
->driverPrivate
= NULL
;
914 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
916 struct intel_context
*intel
=
917 (struct intel_context
*) driContextPriv
->driverPrivate
;
919 /* Deassociate the context with the drawables.
921 intel
->driDrawable
= NULL
;
922 intel
->driReadDrawable
= NULL
;
928 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
929 __DRIdrawablePrivate
* driDrawPriv
,
930 __DRIdrawablePrivate
* driReadPriv
)
932 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
933 struct intel_context
*intel
;
934 GET_CURRENT_CONTEXT(curCtx
);
937 intel
= (struct intel_context
*) driContextPriv
->driverPrivate
;
941 /* According to the glXMakeCurrent() man page: "Pending commands to
942 * the previous context, if any, are flushed before it is released."
943 * But only flush if we're actually changing contexts.
945 if (intel_context(curCtx
) && intel_context(curCtx
) != intel
) {
949 if (driContextPriv
) {
950 struct intel_framebuffer
*intel_fb
=
951 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
952 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
954 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
955 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
956 if (driDrawPriv
!= driReadPriv
)
957 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
959 /* XXX FBO temporary fix-ups! These are released in
960 * intelDextroyContext(), above. Changes here should be
963 /* if the renderbuffers don't have regions, init them from the context */
964 struct intel_renderbuffer
*irbDepth
965 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
966 struct intel_renderbuffer
*irbStencil
967 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
969 if (intel_fb
->color_rb
[0]) {
970 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
971 intel
->front_region
);
973 if (intel_fb
->color_rb
[1]) {
974 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
979 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
982 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
986 /* set GLframebuffer size to match window, if needed */
987 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
989 if (driReadPriv
!= driDrawPriv
) {
990 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
993 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
995 intel
->driReadDrawable
= driReadPriv
;
997 if (intel
->driDrawable
!= driDrawPriv
) {
998 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
1001 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
1002 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
1003 : VBLANK_FLAG_NO_IRQ
;
1005 /* Prevent error printf if one crtc is disabled, this will
1006 * be properly calculated in intelWindowMoved() next.
1008 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
1010 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
1011 driDrawableInitVBlank(driDrawPriv
);
1012 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
1014 for (i
= 0; i
< 2; i
++) {
1015 if (intel_fb
->color_rb
[i
])
1016 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1019 intel
->driDrawable
= driDrawPriv
;
1020 intelWindowMoved(intel
);
1023 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1026 _mesa_make_current(NULL
, NULL
, NULL
);
1033 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1035 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1036 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1037 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1038 int me
= intel
->hHWContext
;
1040 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1042 if (INTEL_DEBUG
& DEBUG_LOCK
)
1043 _mesa_printf("%s - got contended lock\n", __progname
);
1045 /* If the window moved, may need to set a new cliprect now.
1047 * NOTE: This releases and regains the hw lock, so all state
1048 * checking must be done *after* this call:
1051 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1053 if (sarea
&& sarea
->ctxOwner
!= me
) {
1054 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1055 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1056 sarea
->ctxOwner
, me
);
1058 sarea
->ctxOwner
= me
;
1061 /* If the last consumer of the texture memory wasn't us, notify the fake
1062 * bufmgr and record the new owner. We should have the memory shared
1063 * between contexts of a single fake bufmgr, but this will at least make
1064 * things correct for now.
1066 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1067 sarea
->texAge
= intel
->hHWContext
;
1068 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1069 if (INTEL_DEBUG
& DEBUG_BATCH
)
1070 intel_decode_context_reset();
1071 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1072 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1073 sarea
->ctxOwner
, intel
->hHWContext
);
1076 /* Drawable changed?
1078 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1079 intelWindowMoved(intel
);
1080 intel
->lastStamp
= dPriv
->lastStamp
;
1085 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1087 /* Lock the hardware and validate our state.
1089 void LOCK_HARDWARE( struct intel_context
*intel
)
1091 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1092 __DRIscreen
*sPriv
= intel
->driScreen
;
1094 struct intel_framebuffer
*intel_fb
= NULL
;
1095 struct intel_renderbuffer
*intel_rb
= NULL
;
1098 if (intel
->locked
>= 2)
1101 if (!sPriv
->dri2
.enabled
)
1102 _glthread_LOCK_MUTEX(lockMutex
);
1104 if (intel
->driDrawable
) {
1105 intel_fb
= intel
->driDrawable
->driverPrivate
;
1109 intel_get_renderbuffer(&intel_fb
->Base
,
1110 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1113 if (intel_rb
&& dPriv
->vblFlags
&&
1114 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1115 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1118 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1120 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1121 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1124 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1125 drmWaitVBlank(intel
->driFd
, &vbl
);
1126 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1129 if (!sPriv
->dri2
.enabled
) {
1130 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1131 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1134 intelContendedLock( intel
, 0 );
1138 if (INTEL_DEBUG
& DEBUG_LOCK
)
1139 _mesa_printf("%s - locked\n", __progname
);
1143 /* Unlock the hardware using the global current context
1145 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1147 __DRIscreen
*sPriv
= intel
->driScreen
;
1150 if (intel
->locked
> 0)
1153 assert(intel
->locked
== 0);
1155 if (!sPriv
->dri2
.enabled
) {
1156 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1157 _glthread_UNLOCK_MUTEX(lockMutex
);
1160 if (INTEL_DEBUG
& DEBUG_LOCK
)
1161 _mesa_printf("%s - unlocked\n", __progname
);
1164 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1167 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1168 intel_batchbuffer_flush(intel
->batch
);