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) IGDNG_D";
168 chipset
= "Intel(R) IGDNG_M";
171 chipset
= "Unknown Intel Chipset";
175 (void) driGetRendererString(buffer
, chipset
,
176 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
178 return (GLubyte
*) buffer
;
186 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
188 switch (rb
->Base
._ActualFormat
) {
190 case GL_DEPTH_COMPONENT16
:
194 case GL_DEPTH_COMPONENT24
:
195 case GL_DEPTH24_STENCIL8_EXT
:
196 case GL_STENCIL_INDEX8_EXT
:
204 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
206 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
207 struct intel_renderbuffer
*rb
;
208 struct intel_region
*region
, *depth_region
;
209 struct intel_context
*intel
= context
->driverPrivate
;
210 __DRIbuffer
*buffers
= NULL
;
213 unsigned int attachments
[10];
215 const char *region_name
;
217 if (INTEL_DEBUG
& DEBUG_DRI
)
218 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
220 screen
= intel
->intelScreen
->driScrnPriv
;
222 if (screen
->dri2
.loader
223 && (screen
->dri2
.loader
->base
.version
> 2)
224 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
225 struct intel_renderbuffer
*depth_rb
;
226 struct intel_renderbuffer
*stencil_rb
;
229 if ((intel
->is_front_buffer_rendering
||
230 intel
->is_front_buffer_reading
||
231 !intel_fb
->color_rb
[1])
232 && intel_fb
->color_rb
[0]) {
233 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
234 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
237 if (intel_fb
->color_rb
[1]) {
238 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
239 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
242 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
243 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
245 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
246 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
247 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
248 } else if (depth_rb
!= NULL
) {
249 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
250 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
251 } else if (stencil_rb
!= NULL
) {
252 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
253 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
257 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
262 drawable
->loaderPrivate
);
263 } else if (screen
->dri2
.loader
) {
265 if (intel_fb
->color_rb
[0])
266 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
267 if (intel_fb
->color_rb
[1])
268 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
269 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
270 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
271 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
272 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
274 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
279 drawable
->loaderPrivate
);
289 drawable
->numClipRects
= 1;
290 drawable
->pClipRects
[0].x1
= 0;
291 drawable
->pClipRects
[0].y1
= 0;
292 drawable
->pClipRects
[0].x2
= drawable
->w
;
293 drawable
->pClipRects
[0].y2
= drawable
->h
;
294 drawable
->numBackClipRects
= 1;
295 drawable
->pBackClipRects
[0].x1
= 0;
296 drawable
->pBackClipRects
[0].y1
= 0;
297 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
298 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
301 for (i
= 0; i
< count
; i
++) {
302 switch (buffers
[i
].attachment
) {
303 case __DRI_BUFFER_FRONT_LEFT
:
304 rb
= intel_fb
->color_rb
[0];
305 region_name
= "dri2 front buffer";
308 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
309 rb
= intel_fb
->color_rb
[0];
310 region_name
= "dri2 fake front buffer";
313 case __DRI_BUFFER_BACK_LEFT
:
314 rb
= intel_fb
->color_rb
[1];
315 region_name
= "dri2 back buffer";
318 case __DRI_BUFFER_DEPTH
:
319 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
320 region_name
= "dri2 depth buffer";
323 case __DRI_BUFFER_DEPTH_STENCIL
:
324 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
325 region_name
= "dri2 depth / stencil buffer";
328 case __DRI_BUFFER_STENCIL
:
329 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
330 region_name
= "dri2 stencil buffer";
333 case __DRI_BUFFER_ACCUM
:
336 "unhandled buffer attach event, attacment type %d\n",
337 buffers
[i
].attachment
);
345 dri_bo_flink(rb
->region
->buffer
, &name
);
346 if (name
== buffers
[i
].name
)
350 if (INTEL_DEBUG
& DEBUG_DRI
)
352 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
353 buffers
[i
].name
, buffers
[i
].attachment
,
354 buffers
[i
].cpp
, buffers
[i
].pitch
);
356 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
357 if (INTEL_DEBUG
& DEBUG_DRI
)
358 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
359 intel_region_reference(®ion
, depth_region
);
362 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
365 buffers
[i
].pitch
/ buffers
[i
].cpp
,
369 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
370 depth_region
= region
;
372 intel_renderbuffer_set_region(rb
, region
);
373 intel_region_release(®ion
);
375 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
376 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
378 struct intel_region
*stencil_region
= NULL
;
381 dri_bo_flink(rb
->region
->buffer
, &name
);
382 if (name
== buffers
[i
].name
)
386 intel_region_reference(&stencil_region
, region
);
387 intel_renderbuffer_set_region(rb
, stencil_region
);
388 intel_region_release(&stencil_region
);
393 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
397 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
399 struct intel_context
*intel
= intel_context(ctx
);
400 __DRIcontext
*driContext
= intel
->driContext
;
401 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
402 GLsizei w
, GLsizei h
);
404 if (!driContext
->driScreenPriv
->dri2
.enabled
)
407 if (!intel
->meta
.internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
408 /* If we're rendering to the fake front buffer, make sure all the pending
409 * drawing has landed on the real front buffer. Otherwise when we
410 * eventually get to DRI2GetBuffersWithFormat the stale real front
411 * buffer contents will get copied to the new fake front buffer.
413 if (intel
->is_front_buffer_rendering
) {
414 intel_flush(ctx
, GL_FALSE
);
417 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
418 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
419 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
422 old_viewport
= ctx
->Driver
.Viewport
;
423 ctx
->Driver
.Viewport
= NULL
;
424 intel
->driDrawable
= driContext
->driDrawablePriv
;
425 intelWindowMoved(intel
);
426 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
427 ctx
->Driver
.Viewport
= old_viewport
;
431 static const struct dri_debug_control debug_control
[] = {
432 { "tex", DEBUG_TEXTURE
},
433 { "state", DEBUG_STATE
},
434 { "ioctl", DEBUG_IOCTL
},
435 { "blit", DEBUG_BLIT
},
436 { "mip", DEBUG_MIPTREE
},
437 { "fall", DEBUG_FALLBACKS
},
438 { "verb", DEBUG_VERBOSE
},
439 { "bat", DEBUG_BATCH
},
440 { "pix", DEBUG_PIXEL
},
441 { "buf", DEBUG_BUFMGR
},
442 { "reg", DEBUG_REGION
},
444 { "lock", DEBUG_LOCK
},
445 { "sync", DEBUG_SYNC
},
446 { "prim", DEBUG_PRIMS
},
447 { "vert", DEBUG_VERTS
},
448 { "dri", DEBUG_DRI
},
449 { "dma", DEBUG_DMA
},
450 { "san", DEBUG_SANITY
},
451 { "sleep", DEBUG_SLEEP
},
452 { "stats", DEBUG_STATS
},
453 { "tile", DEBUG_TILE
},
454 { "sing", DEBUG_SINGLE_THREAD
},
455 { "thre", DEBUG_SINGLE_THREAD
},
457 { "urb", DEBUG_URB
},
464 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
466 struct intel_context
*intel
= intel_context(ctx
);
468 _swrast_InvalidateState(ctx
, new_state
);
469 _swsetup_InvalidateState(ctx
, new_state
);
470 _vbo_InvalidateState(ctx
, new_state
);
471 _tnl_InvalidateState(ctx
, new_state
);
472 _tnl_invalidate_vertex_state(ctx
, new_state
);
474 intel
->NewGLState
|= new_state
;
476 if (intel
->vtbl
.invalidate_state
)
477 intel
->vtbl
.invalidate_state( intel
, new_state
);
481 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
483 struct intel_context
*intel
= intel_context(ctx
);
488 if (!IS_965(intel
->intelScreen
->deviceID
))
489 INTEL_FIREVERTICES(intel
);
491 /* Emit a flush so that any frontbuffer rendering that might have occurred
492 * lands onscreen in a timely manner, even if the X Server doesn't trigger
496 intel_batchbuffer_emit_mi_flush(intel
->batch
);
498 if (intel
->batch
->map
!= intel
->batch
->ptr
)
499 intel_batchbuffer_flush(intel
->batch
);
501 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
502 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
504 if (screen
->dri2
.loader
&&
505 (screen
->dri2
.loader
->base
.version
>= 2)
506 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
507 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
508 intel
->driDrawable
->loaderPrivate
);
510 /* Only clear the dirty bit if front-buffer rendering is no longer
511 * enabled. This is done so that the dirty bit can only be set in
512 * glDrawBuffer. Otherwise the dirty bit would have to be set at
513 * each of N places that do rendering. This has worse performances,
514 * but it is much easier to get correct.
516 if (intel
->is_front_buffer_rendering
) {
517 intel
->front_buffer_dirty
= GL_FALSE
;
524 intelFlush(GLcontext
* ctx
)
526 intel_flush(ctx
, GL_FALSE
);
530 intel_glFlush(GLcontext
*ctx
)
532 struct intel_context
*intel
= intel_context(ctx
);
534 intel_flush(ctx
, GL_TRUE
);
536 /* We're using glFlush as an indicator that a frame is done, which is
537 * what DRI2 does before calling SwapBuffers (and means we should catch
538 * people doing front-buffer rendering, as well)..
540 * Wait for the swapbuffers before the one we just emitted, so we don't
541 * get too many swaps outstanding for apps that are GPU-heavy but not
544 * Unfortunately, we don't have a handle to the batch containing the swap,
545 * and getting our hands on that doesn't seem worth it, so we just us the
546 * first batch we emitted after the last swap.
548 if (intel
->first_post_swapbuffers_batch
!= NULL
) {
549 drm_intel_bo_wait_rendering(intel
->first_post_swapbuffers_batch
);
550 drm_intel_bo_unreference(intel
->first_post_swapbuffers_batch
);
551 intel
->first_post_swapbuffers_batch
= NULL
;
556 intelFinish(GLcontext
* ctx
)
558 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
563 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
564 struct intel_renderbuffer
*irb
;
566 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
568 if (irb
&& irb
->region
)
569 dri_bo_wait_rendering(irb
->region
->buffer
);
571 if (fb
->_DepthBuffer
) {
572 /* XXX: Wait on buffer idle */
577 intelInitDriverFunctions(struct dd_function_table
*functions
)
579 _mesa_init_driver_functions(functions
);
581 functions
->Flush
= intel_glFlush
;
582 functions
->Finish
= intelFinish
;
583 functions
->GetString
= intelGetString
;
584 functions
->UpdateState
= intelInvalidateState
;
586 functions
->CopyColorTable
= _swrast_CopyColorTable
;
587 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
588 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
589 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
591 intelInitTextureFuncs(functions
);
592 intelInitTextureImageFuncs(functions
);
593 intelInitTextureSubImageFuncs(functions
);
594 intelInitTextureCopyImageFuncs(functions
);
595 intelInitStateFuncs(functions
);
596 intelInitClearFuncs(functions
);
597 intelInitBufferFuncs(functions
);
598 intelInitPixelFuncs(functions
);
599 intelInitBufferObjectFuncs(functions
);
604 intelInitContext(struct intel_context
*intel
,
605 const __GLcontextModes
* mesaVis
,
606 __DRIcontextPrivate
* driContextPriv
,
607 void *sharedContextPrivate
,
608 struct dd_function_table
*functions
)
610 GLcontext
*ctx
= &intel
->ctx
;
611 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
612 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
613 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
616 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
617 functions
, (void *) intel
)) {
618 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
622 driContextPriv
->driverPrivate
= intel
;
623 intel
->intelScreen
= intelScreen
;
624 intel
->driScreen
= sPriv
;
625 intel
->sarea
= intelScreen
->sarea
;
626 intel
->driContext
= driContextPriv
;
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 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
636 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
637 intel
->maxBatchSize
= 4096;
639 intel
->maxBatchSize
= BATCH_SZ
;
641 intel
->bufmgr
= intelScreen
->bufmgr
;
642 intel
->ttm
= intelScreen
->ttm
;
646 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
647 switch (bo_reuse_mode
) {
648 case DRI_CONF_BO_REUSE_DISABLED
:
650 case DRI_CONF_BO_REUSE_ALL
:
651 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
656 /* This doesn't yet catch all non-conformant rendering, but it's a
659 if (getenv("INTEL_STRICT_CONFORMANCE")) {
660 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
662 intel
->conformance_mode
= value
;
665 intel
->conformance_mode
= 1;
669 if (intel
->conformance_mode
> 0) {
670 ctx
->Const
.MinLineWidth
= 1.0;
671 ctx
->Const
.MinLineWidthAA
= 1.0;
672 ctx
->Const
.MaxLineWidth
= 1.0;
673 ctx
->Const
.MaxLineWidthAA
= 1.0;
674 ctx
->Const
.LineWidthGranularity
= 1.0;
677 ctx
->Const
.MinLineWidth
= 1.0;
678 ctx
->Const
.MinLineWidthAA
= 1.0;
679 ctx
->Const
.MaxLineWidth
= 5.0;
680 ctx
->Const
.MaxLineWidthAA
= 5.0;
681 ctx
->Const
.LineWidthGranularity
= 0.5;
684 ctx
->Const
.MinPointSize
= 1.0;
685 ctx
->Const
.MinPointSizeAA
= 1.0;
686 ctx
->Const
.MaxPointSize
= 255.0;
687 ctx
->Const
.MaxPointSizeAA
= 3.0;
688 ctx
->Const
.PointSizeGranularity
= 1.0;
690 /* reinitialize the context point state.
691 * It depend on constants in __GLcontextRec::Const
693 _mesa_init_point(ctx
);
695 meta_init_metaops(ctx
, &intel
->meta
);
696 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
697 if (IS_965(intelScreen
->deviceID
)) {
698 if (MAX_WIDTH
> 8192)
699 ctx
->Const
.MaxRenderbufferSize
= 8192;
701 if (MAX_WIDTH
> 2048)
702 ctx
->Const
.MaxRenderbufferSize
= 2048;
705 /* Initialize the software rasterizer and helper modules. */
706 _swrast_CreateContext(ctx
);
707 _vbo_CreateContext(ctx
);
708 _tnl_CreateContext(ctx
);
709 _swsetup_CreateContext(ctx
);
711 /* Configure swrast to match hardware characteristics: */
712 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
713 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
715 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
716 intel
->hw_stipple
= 1;
718 /* XXX FBO: this doesn't seem to be used anywhere */
719 switch (mesaVis
->depthBits
) {
720 case 0: /* what to do in this case? */
722 intel
->polygon_offset_scale
= 1.0;
725 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
732 if (IS_965(intelScreen
->deviceID
))
733 intel
->polygon_offset_scale
/= 0xffff;
735 intel
->RenderIndex
= ~0;
737 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
738 intel
->irqsEmitted
= 0;
740 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
741 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
743 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
745 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
746 _mesa_printf("IRQs not active. Exiting\n");
750 intelInitExtensions(ctx
, GL_FALSE
);
752 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
753 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
754 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
756 if (!sPriv
->dri2
.enabled
)
757 intel_recreate_static_regions(intel
);
759 intel
->batch
= intel_batchbuffer_alloc(intel
);
761 intel_fbo_init(intel
);
763 if (intel
->ctx
.Mesa_DXTn
) {
764 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
765 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
767 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
768 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
770 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
772 if (intel
->use_texture_tiling
&&
773 !intel
->intelScreen
->kernel_exec_fencing
) {
774 fprintf(stderr
, "No kernel support for execution fencing, "
775 "disabling texture tiling");
776 intel
->use_texture_tiling
= GL_FALSE
;
778 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
780 intel
->prim
.primitive
= ~0;
782 /* Force all software fallbacks */
783 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
784 fprintf(stderr
, "disabling 3D rasterization\n");
788 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
789 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
790 intel
->always_flush_batch
= 1;
793 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
794 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
795 intel
->always_flush_cache
= 1;
798 /* Disable all hardware rendering (skip emitting batches and fences/waits
801 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
807 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
809 struct intel_context
*intel
=
810 (struct intel_context
*) driContextPriv
->driverPrivate
;
812 assert(intel
); /* should never be null */
814 GLboolean release_texture_heaps
;
816 INTEL_FIREVERTICES(intel
);
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
= 0; /* 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
)
920 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
921 __DRIdrawablePrivate
* driDrawPriv
,
922 __DRIdrawablePrivate
* driReadPriv
)
924 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
926 if (driContextPriv
) {
927 struct intel_context
*intel
=
928 (struct intel_context
*) driContextPriv
->driverPrivate
;
929 struct intel_framebuffer
*intel_fb
=
930 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
931 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
933 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
934 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
935 if (driDrawPriv
!= driReadPriv
)
936 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
938 /* XXX FBO temporary fix-ups! These are released in
939 * intelDextroyContext(), above. Changes here should be
942 /* if the renderbuffers don't have regions, init them from the context */
943 struct intel_renderbuffer
*irbDepth
944 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
945 struct intel_renderbuffer
*irbStencil
946 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
948 if (intel_fb
->color_rb
[0]) {
949 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
950 intel
->front_region
);
952 if (intel_fb
->color_rb
[1]) {
953 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
958 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
961 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
965 /* set GLframebuffer size to match window, if needed */
966 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
968 if (driReadPriv
!= driDrawPriv
) {
969 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
972 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
974 /* The drawbuffer won't always be updated by _mesa_make_current:
976 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
978 if (intel
->driReadDrawable
!= driReadPriv
)
979 intel
->driReadDrawable
= driReadPriv
;
981 if (intel
->driDrawable
!= driDrawPriv
) {
982 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
985 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
986 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
987 : VBLANK_FLAG_NO_IRQ
;
989 /* Prevent error printf if one crtc is disabled, this will
990 * be properly calculated in intelWindowMoved() next.
992 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
994 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
995 driDrawableInitVBlank(driDrawPriv
);
996 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
998 for (i
= 0; i
< 2; i
++) {
999 if (intel_fb
->color_rb
[i
])
1000 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
1003 intel
->driDrawable
= driDrawPriv
;
1004 intelWindowMoved(intel
);
1007 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
1011 _mesa_make_current(NULL
, NULL
, NULL
);
1018 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
1020 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
1021 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
1022 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
1023 int me
= intel
->hHWContext
;
1025 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
1027 if (INTEL_DEBUG
& DEBUG_LOCK
)
1028 _mesa_printf("%s - got contended lock\n", __progname
);
1030 /* If the window moved, may need to set a new cliprect now.
1032 * NOTE: This releases and regains the hw lock, so all state
1033 * checking must be done *after* this call:
1036 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1038 if (sarea
&& sarea
->ctxOwner
!= me
) {
1039 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1040 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1041 sarea
->ctxOwner
, me
);
1043 sarea
->ctxOwner
= me
;
1046 /* If the last consumer of the texture memory wasn't us, notify the fake
1047 * bufmgr and record the new owner. We should have the memory shared
1048 * between contexts of a single fake bufmgr, but this will at least make
1049 * things correct for now.
1051 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1052 sarea
->texAge
= intel
->hHWContext
;
1053 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1054 if (INTEL_DEBUG
& DEBUG_BATCH
)
1055 intel_decode_context_reset();
1056 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1057 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1058 sarea
->ctxOwner
, intel
->hHWContext
);
1061 /* Drawable changed?
1063 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1064 intelWindowMoved(intel
);
1065 intel
->lastStamp
= dPriv
->lastStamp
;
1070 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1072 /* Lock the hardware and validate our state.
1074 void LOCK_HARDWARE( struct intel_context
*intel
)
1076 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1077 __DRIscreen
*sPriv
= intel
->driScreen
;
1079 struct intel_framebuffer
*intel_fb
= NULL
;
1080 struct intel_renderbuffer
*intel_rb
= NULL
;
1083 if (intel
->locked
>= 2)
1086 if (!sPriv
->dri2
.enabled
)
1087 _glthread_LOCK_MUTEX(lockMutex
);
1089 if (intel
->driDrawable
) {
1090 intel_fb
= intel
->driDrawable
->driverPrivate
;
1094 intel_get_renderbuffer(&intel_fb
->Base
,
1095 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1098 if (intel_rb
&& dPriv
->vblFlags
&&
1099 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1100 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1103 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1105 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1106 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1109 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1110 drmWaitVBlank(intel
->driFd
, &vbl
);
1111 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1114 if (!sPriv
->dri2
.enabled
) {
1115 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1116 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1119 intelContendedLock( intel
, 0 );
1123 if (INTEL_DEBUG
& DEBUG_LOCK
)
1124 _mesa_printf("%s - locked\n", __progname
);
1128 /* Unlock the hardware using the global current context
1130 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1132 __DRIscreen
*sPriv
= intel
->driScreen
;
1135 if (intel
->locked
> 0)
1138 assert(intel
->locked
== 0);
1140 if (!sPriv
->dri2
.enabled
) {
1141 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1142 _glthread_UNLOCK_MUTEX(lockMutex
);
1145 if (INTEL_DEBUG
& DEBUG_LOCK
)
1146 _mesa_printf("%s - unlocked\n", __progname
);
1149 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1152 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1153 intel_batchbuffer_flush(intel
->batch
);