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 "20090114"
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
= "Unknown Intel Chipset";
169 (void) driGetRendererString(buffer
, chipset
,
170 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
172 return (GLubyte
*) buffer
;
180 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
182 switch (rb
->Base
._ActualFormat
) {
184 case GL_DEPTH_COMPONENT16
:
188 case GL_DEPTH_COMPONENT24
:
189 case GL_DEPTH24_STENCIL8_EXT
:
190 case GL_STENCIL_INDEX8_EXT
:
198 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
200 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
201 struct intel_renderbuffer
*rb
;
202 struct intel_region
*region
, *depth_region
;
203 struct intel_context
*intel
= context
->driverPrivate
;
204 __DRIbuffer
*buffers
= NULL
;
207 unsigned int attachments
[10];
209 const char *region_name
;
211 if (INTEL_DEBUG
& DEBUG_DRI
)
212 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
214 screen
= intel
->intelScreen
->driScrnPriv
;
216 if (screen
->dri2
.loader
217 && (screen
->dri2
.loader
->base
.version
> 2)
218 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
219 struct intel_renderbuffer
*depth_rb
;
220 struct intel_renderbuffer
*stencil_rb
;
223 if ((intel
->is_front_buffer_rendering
||
224 intel
->is_front_buffer_reading
||
225 !intel_fb
->color_rb
[1])
226 && intel_fb
->color_rb
[0]) {
227 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
228 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
231 if (intel_fb
->color_rb
[1]) {
232 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
233 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
236 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
237 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
239 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
240 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
241 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
242 } else if (depth_rb
!= NULL
) {
243 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
244 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
245 } else if (stencil_rb
!= NULL
) {
246 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
247 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
251 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
256 drawable
->loaderPrivate
);
257 } else if (screen
->dri2
.loader
) {
259 if (intel_fb
->color_rb
[0])
260 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
261 if (intel_fb
->color_rb
[1])
262 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
263 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
264 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
265 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
266 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
268 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
273 drawable
->loaderPrivate
);
283 drawable
->numClipRects
= 1;
284 drawable
->pClipRects
[0].x1
= 0;
285 drawable
->pClipRects
[0].y1
= 0;
286 drawable
->pClipRects
[0].x2
= drawable
->w
;
287 drawable
->pClipRects
[0].y2
= drawable
->h
;
288 drawable
->numBackClipRects
= 1;
289 drawable
->pBackClipRects
[0].x1
= 0;
290 drawable
->pBackClipRects
[0].y1
= 0;
291 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
292 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
295 for (i
= 0; i
< count
; i
++) {
296 switch (buffers
[i
].attachment
) {
297 case __DRI_BUFFER_FRONT_LEFT
:
298 rb
= intel_fb
->color_rb
[0];
299 region_name
= "dri2 front buffer";
302 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
303 rb
= intel_fb
->color_rb
[0];
304 region_name
= "dri2 fake front buffer";
307 case __DRI_BUFFER_BACK_LEFT
:
308 rb
= intel_fb
->color_rb
[1];
309 region_name
= "dri2 back buffer";
312 case __DRI_BUFFER_DEPTH
:
313 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
314 region_name
= "dri2 depth buffer";
317 case __DRI_BUFFER_DEPTH_STENCIL
:
318 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
319 region_name
= "dri2 depth / stencil buffer";
322 case __DRI_BUFFER_STENCIL
:
323 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
324 region_name
= "dri2 stencil buffer";
327 case __DRI_BUFFER_ACCUM
:
330 "unhandled buffer attach event, attacment type %d\n",
331 buffers
[i
].attachment
);
339 dri_bo_flink(rb
->region
->buffer
, &name
);
340 if (name
== buffers
[i
].name
)
344 if (INTEL_DEBUG
& DEBUG_DRI
)
346 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
347 buffers
[i
].name
, buffers
[i
].attachment
,
348 buffers
[i
].cpp
, buffers
[i
].pitch
);
350 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
351 if (INTEL_DEBUG
& DEBUG_DRI
)
352 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
353 intel_region_reference(®ion
, depth_region
);
356 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
359 buffers
[i
].pitch
/ buffers
[i
].cpp
,
363 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
364 depth_region
= region
;
366 intel_renderbuffer_set_region(rb
, region
);
367 intel_region_release(®ion
);
369 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
370 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
372 struct intel_region
*stencil_region
= NULL
;
375 dri_bo_flink(rb
->region
->buffer
, &name
);
376 if (name
== buffers
[i
].name
)
380 intel_region_reference(&stencil_region
, region
);
381 intel_renderbuffer_set_region(rb
, stencil_region
);
382 intel_region_release(&stencil_region
);
387 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
391 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
393 struct intel_context
*intel
= intel_context(ctx
);
394 __DRIcontext
*driContext
= intel
->driContext
;
395 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
396 GLsizei w
, GLsizei h
);
398 if (!driContext
->driScreenPriv
->dri2
.enabled
)
401 if (!intel
->internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
402 /* If we're rendering to the fake front buffer, make sure all the pending
403 * drawing has landed on the real front buffer. Otherwise when we
404 * eventually get to DRI2GetBuffersWithFormat the stale real front
405 * buffer contents will get copied to the new fake front buffer.
407 if (intel
->is_front_buffer_rendering
) {
408 intel_flush(ctx
, GL_FALSE
);
411 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
412 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
413 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
416 old_viewport
= ctx
->Driver
.Viewport
;
417 ctx
->Driver
.Viewport
= NULL
;
418 intel
->driDrawable
= driContext
->driDrawablePriv
;
419 intelWindowMoved(intel
);
420 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
421 ctx
->Driver
.Viewport
= old_viewport
;
425 static const struct dri_debug_control debug_control
[] = {
426 { "tex", DEBUG_TEXTURE
},
427 { "state", DEBUG_STATE
},
428 { "ioctl", DEBUG_IOCTL
},
429 { "blit", DEBUG_BLIT
},
430 { "mip", DEBUG_MIPTREE
},
431 { "fall", DEBUG_FALLBACKS
},
432 { "verb", DEBUG_VERBOSE
},
433 { "bat", DEBUG_BATCH
},
434 { "pix", DEBUG_PIXEL
},
435 { "buf", DEBUG_BUFMGR
},
436 { "reg", DEBUG_REGION
},
438 { "lock", DEBUG_LOCK
},
439 { "sync", DEBUG_SYNC
},
440 { "prim", DEBUG_PRIMS
},
441 { "vert", DEBUG_VERTS
},
442 { "dri", DEBUG_DRI
},
443 { "dma", DEBUG_DMA
},
444 { "san", DEBUG_SANITY
},
445 { "sleep", DEBUG_SLEEP
},
446 { "stats", DEBUG_STATS
},
447 { "tile", DEBUG_TILE
},
448 { "sing", DEBUG_SINGLE_THREAD
},
449 { "thre", DEBUG_SINGLE_THREAD
},
451 { "urb", DEBUG_URB
},
458 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
460 struct intel_context
*intel
= intel_context(ctx
);
462 _swrast_InvalidateState(ctx
, new_state
);
463 _swsetup_InvalidateState(ctx
, new_state
);
464 _vbo_InvalidateState(ctx
, new_state
);
465 _tnl_InvalidateState(ctx
, new_state
);
466 _tnl_invalidate_vertex_state(ctx
, new_state
);
468 intel
->NewGLState
|= new_state
;
470 if (intel
->vtbl
.invalidate_state
)
471 intel
->vtbl
.invalidate_state( intel
, new_state
);
475 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
477 struct intel_context
*intel
= intel_context(ctx
);
482 if (!IS_965(intel
->intelScreen
->deviceID
))
483 INTEL_FIREVERTICES(intel
);
485 /* Emit a flush so that any frontbuffer rendering that might have occurred
486 * lands onscreen in a timely manner, even if the X Server doesn't trigger
490 intel_batchbuffer_emit_mi_flush(intel
->batch
);
492 if (intel
->batch
->map
!= intel
->batch
->ptr
)
493 intel_batchbuffer_flush(intel
->batch
);
495 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
496 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
498 if (screen
->dri2
.loader
&&
499 (screen
->dri2
.loader
->base
.version
>= 2)
500 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
501 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
502 intel
->driDrawable
->loaderPrivate
);
504 /* Only clear the dirty bit if front-buffer rendering is no longer
505 * enabled. This is done so that the dirty bit can only be set in
506 * glDrawBuffer. Otherwise the dirty bit would have to be set at
507 * each of N places that do rendering. This has worse performances,
508 * but it is much easier to get correct.
510 if (intel
->is_front_buffer_rendering
) {
511 intel
->front_buffer_dirty
= GL_FALSE
;
518 intelFlush(GLcontext
* ctx
)
520 intel_flush(ctx
, GL_FALSE
);
524 intel_glFlush(GLcontext
*ctx
)
526 intel_flush(ctx
, GL_TRUE
);
530 intelFinish(GLcontext
* ctx
)
532 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
537 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
538 struct intel_renderbuffer
*irb
;
540 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
543 dri_bo_wait_rendering(irb
->region
->buffer
);
545 if (fb
->_DepthBuffer
) {
546 /* XXX: Wait on buffer idle */
551 intelInitDriverFunctions(struct dd_function_table
*functions
)
553 _mesa_init_driver_functions(functions
);
555 functions
->Flush
= intel_glFlush
;
556 functions
->Finish
= intelFinish
;
557 functions
->GetString
= intelGetString
;
558 functions
->UpdateState
= intelInvalidateState
;
560 functions
->CopyColorTable
= _swrast_CopyColorTable
;
561 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
562 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
563 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
565 intelInitTextureFuncs(functions
);
566 intelInitTextureImageFuncs(functions
);
567 intelInitTextureSubImageFuncs(functions
);
568 intelInitTextureCopyImageFuncs(functions
);
569 intelInitStateFuncs(functions
);
570 intelInitClearFuncs(functions
);
571 intelInitBufferFuncs(functions
);
572 intelInitPixelFuncs(functions
);
573 intelInitBufferObjectFuncs(functions
);
578 intelInitContext(struct intel_context
*intel
,
579 const __GLcontextModes
* mesaVis
,
580 __DRIcontextPrivate
* driContextPriv
,
581 void *sharedContextPrivate
,
582 struct dd_function_table
*functions
)
584 GLcontext
*ctx
= &intel
->ctx
;
585 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
586 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
587 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
590 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
591 functions
, (void *) intel
)) {
592 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
596 driContextPriv
->driverPrivate
= intel
;
597 intel
->intelScreen
= intelScreen
;
598 intel
->driScreen
= sPriv
;
599 intel
->sarea
= intelScreen
->sarea
;
600 intel
->driContext
= driContextPriv
;
603 intel
->hHWContext
= driContextPriv
->hHWContext
;
604 intel
->driFd
= sPriv
->fd
;
605 intel
->driHwLock
= sPriv
->lock
;
607 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
608 intel
->driScreen
->myNum
,
609 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
610 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
611 intel
->maxBatchSize
= 4096;
613 intel
->maxBatchSize
= BATCH_SZ
;
615 intel
->bufmgr
= intelScreen
->bufmgr
;
616 intel
->ttm
= intelScreen
->ttm
;
620 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
621 switch (bo_reuse_mode
) {
622 case DRI_CONF_BO_REUSE_DISABLED
:
624 case DRI_CONF_BO_REUSE_ALL
:
625 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
630 /* This doesn't yet catch all non-conformant rendering, but it's a
633 if (getenv("INTEL_STRICT_CONFORMANCE")) {
634 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
636 intel
->conformance_mode
= value
;
639 intel
->conformance_mode
= 1;
643 if (intel
->conformance_mode
> 0) {
644 ctx
->Const
.MinLineWidth
= 1.0;
645 ctx
->Const
.MinLineWidthAA
= 1.0;
646 ctx
->Const
.MaxLineWidth
= 1.0;
647 ctx
->Const
.MaxLineWidthAA
= 1.0;
648 ctx
->Const
.LineWidthGranularity
= 1.0;
651 ctx
->Const
.MinLineWidth
= 1.0;
652 ctx
->Const
.MinLineWidthAA
= 1.0;
653 ctx
->Const
.MaxLineWidth
= 5.0;
654 ctx
->Const
.MaxLineWidthAA
= 5.0;
655 ctx
->Const
.LineWidthGranularity
= 0.5;
658 ctx
->Const
.MinPointSize
= 1.0;
659 ctx
->Const
.MinPointSizeAA
= 1.0;
660 ctx
->Const
.MaxPointSize
= 255.0;
661 ctx
->Const
.MaxPointSizeAA
= 3.0;
662 ctx
->Const
.PointSizeGranularity
= 1.0;
664 /* reinitialize the context point state.
665 * It depend on constants in __GLcontextRec::Const
667 _mesa_init_point(ctx
);
669 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
670 if (IS_965(intelScreen
->deviceID
)) {
671 if (MAX_WIDTH
> 8192)
672 ctx
->Const
.MaxRenderbufferSize
= 8192;
674 if (MAX_WIDTH
> 2048)
675 ctx
->Const
.MaxRenderbufferSize
= 2048;
678 /* Initialize the software rasterizer and helper modules. */
679 _swrast_CreateContext(ctx
);
680 _vbo_CreateContext(ctx
);
681 _tnl_CreateContext(ctx
);
682 _swsetup_CreateContext(ctx
);
684 /* Configure swrast to match hardware characteristics: */
685 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
686 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
688 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
689 intel
->hw_stipple
= 1;
691 /* XXX FBO: this doesn't seem to be used anywhere */
692 switch (mesaVis
->depthBits
) {
693 case 0: /* what to do in this case? */
695 intel
->polygon_offset_scale
= 1.0;
698 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
705 if (IS_965(intelScreen
->deviceID
))
706 intel
->polygon_offset_scale
/= 0xffff;
708 intel
->RenderIndex
= ~0;
710 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
711 intel
->irqsEmitted
= 0;
713 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
714 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
716 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
718 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
719 _mesa_printf("IRQs not active. Exiting\n");
723 intelInitExtensions(ctx
, GL_FALSE
);
725 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
726 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
727 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
729 if (!sPriv
->dri2
.enabled
)
730 intel_recreate_static_regions(intel
);
732 intel
->batch
= intel_batchbuffer_alloc(intel
);
734 intel_fbo_init(intel
);
736 if (intel
->ctx
.Mesa_DXTn
) {
737 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
738 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
740 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
741 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
743 intel
->use_texture_tiling
= driQueryOptionb(&intel
->optionCache
,
745 if (intel
->use_texture_tiling
&&
746 !intel
->intelScreen
->kernel_exec_fencing
) {
747 fprintf(stderr
, "No kernel support for execution fencing, "
748 "disabling texture tiling");
749 intel
->use_texture_tiling
= GL_FALSE
;
751 intel
->use_early_z
= driQueryOptionb(&intel
->optionCache
, "early_z");
753 intel
->prim
.primitive
= ~0;
755 /* Force all software fallbacks */
756 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
757 fprintf(stderr
, "disabling 3D rasterization\n");
761 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
762 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
763 intel
->always_flush_batch
= 1;
766 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
767 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
768 intel
->always_flush_cache
= 1;
771 /* Disable all hardware rendering (skip emitting batches and fences/waits
774 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
780 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
782 struct intel_context
*intel
=
783 (struct intel_context
*) driContextPriv
->driverPrivate
;
785 assert(intel
); /* should never be null */
787 GLboolean release_texture_heaps
;
789 INTEL_FIREVERTICES(intel
);
791 if (intel
->clear
.arrayObj
)
792 _mesa_delete_array_object(&intel
->ctx
, intel
->clear
.arrayObj
);
794 intel
->vtbl
.destroy(intel
);
796 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
797 _swsetup_DestroyContext(&intel
->ctx
);
798 _tnl_DestroyContext(&intel
->ctx
);
799 _vbo_DestroyContext(&intel
->ctx
);
801 _swrast_DestroyContext(&intel
->ctx
);
802 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
804 intel_batchbuffer_free(intel
->batch
);
807 free(intel
->prim
.vb
);
808 intel
->prim
.vb
= NULL
;
809 dri_bo_unreference(intel
->prim
.vb_bo
);
810 intel
->prim
.vb_bo
= NULL
;
812 if (release_texture_heaps
) {
813 /* Nothing is currently done here to free texture heaps;
814 * but we're not using the texture heap utilities, so I
815 * rather think we shouldn't. I've taken a look, and can't
816 * find any private texture data hanging around anywhere, but
817 * I'm not yet certain there isn't any at all...
819 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
820 fprintf(stderr, "do something to free texture heaps\n");
824 /* XXX In intelMakeCurrent() below, the context's static regions are
825 * referenced inside the frame buffer; it's listed as a hack,
826 * with a comment of "XXX FBO temporary fix-ups!", but
827 * as long as it's there, we should release the regions here.
828 * The do/while loop around the block is used to allow the
829 * "continue" statements inside the block to exit the block,
830 * to avoid many layers of "if" constructs.
833 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
834 struct intel_framebuffer
*intel_fb
;
835 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
837 /* We're already detached from the drawable; exit this block. */
840 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
842 /* The frame buffer is already gone; exit this block. */
845 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
846 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
848 /* If the regions of the frame buffer still match the regions
849 * of the context, release them. If they've changed somehow,
852 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
853 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
855 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
856 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
859 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
860 intel_renderbuffer_set_region(irbDepth
, NULL
);
862 /* Usually, the stencil buffer is the same as the depth buffer;
863 * but they're handled separately in MakeCurrent, so we'll
864 * handle them separately here.
866 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
867 intel_renderbuffer_set_region(irbStencil
, NULL
);
871 intel_region_release(&intel
->front_region
);
872 intel_region_release(&intel
->back_region
);
873 intel_region_release(&intel
->depth_region
);
875 driDestroyOptionCache(&intel
->optionCache
);
877 /* free the Mesa context */
878 _mesa_free_context_data(&intel
->ctx
);
885 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
891 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
892 __DRIdrawablePrivate
* driDrawPriv
,
893 __DRIdrawablePrivate
* driReadPriv
)
895 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
897 if (driContextPriv
) {
898 struct intel_context
*intel
=
899 (struct intel_context
*) driContextPriv
->driverPrivate
;
900 struct intel_framebuffer
*intel_fb
=
901 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
902 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
904 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
905 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
906 if (driDrawPriv
!= driReadPriv
)
907 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
909 /* XXX FBO temporary fix-ups! These are released in
910 * intelDextroyContext(), above. Changes here should be
913 /* if the renderbuffers don't have regions, init them from the context */
914 struct intel_renderbuffer
*irbDepth
915 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
916 struct intel_renderbuffer
*irbStencil
917 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
919 if (intel_fb
->color_rb
[0]) {
920 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
921 intel
->front_region
);
923 if (intel_fb
->color_rb
[1]) {
924 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
929 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
932 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
936 /* set GLframebuffer size to match window, if needed */
937 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
939 if (driReadPriv
!= driDrawPriv
) {
940 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
943 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
945 /* The drawbuffer won't always be updated by _mesa_make_current:
947 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
949 if (intel
->driReadDrawable
!= driReadPriv
)
950 intel
->driReadDrawable
= driReadPriv
;
952 if (intel
->driDrawable
!= driDrawPriv
) {
953 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
956 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
957 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
958 : VBLANK_FLAG_NO_IRQ
;
960 /* Prevent error printf if one crtc is disabled, this will
961 * be properly calculated in intelWindowMoved() next.
963 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
965 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
966 driDrawableInitVBlank(driDrawPriv
);
967 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
969 for (i
= 0; i
< 2; i
++) {
970 if (intel_fb
->color_rb
[i
])
971 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
974 intel
->driDrawable
= driDrawPriv
;
975 intelWindowMoved(intel
);
978 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
982 _mesa_make_current(NULL
, NULL
, NULL
);
989 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
991 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
992 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
993 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
994 int me
= intel
->hHWContext
;
996 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
998 if (INTEL_DEBUG
& DEBUG_LOCK
)
999 _mesa_printf("%s - got contended lock\n", __progname
);
1001 /* If the window moved, may need to set a new cliprect now.
1003 * NOTE: This releases and regains the hw lock, so all state
1004 * checking must be done *after* this call:
1007 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
1009 if (sarea
&& sarea
->ctxOwner
!= me
) {
1010 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
1011 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
1012 sarea
->ctxOwner
, me
);
1014 sarea
->ctxOwner
= me
;
1017 /* If the last consumer of the texture memory wasn't us, notify the fake
1018 * bufmgr and record the new owner. We should have the memory shared
1019 * between contexts of a single fake bufmgr, but this will at least make
1020 * things correct for now.
1022 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
1023 sarea
->texAge
= intel
->hHWContext
;
1024 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1025 if (INTEL_DEBUG
& DEBUG_BATCH
)
1026 intel_decode_context_reset();
1027 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1028 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1029 sarea
->ctxOwner
, intel
->hHWContext
);
1032 /* Drawable changed?
1034 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1035 intelWindowMoved(intel
);
1036 intel
->lastStamp
= dPriv
->lastStamp
;
1041 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1043 /* Lock the hardware and validate our state.
1045 void LOCK_HARDWARE( struct intel_context
*intel
)
1047 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1048 __DRIscreen
*sPriv
= intel
->driScreen
;
1050 struct intel_framebuffer
*intel_fb
= NULL
;
1051 struct intel_renderbuffer
*intel_rb
= NULL
;
1054 if (intel
->locked
>= 2)
1057 if (!sPriv
->dri2
.enabled
)
1058 _glthread_LOCK_MUTEX(lockMutex
);
1060 if (intel
->driDrawable
) {
1061 intel_fb
= intel
->driDrawable
->driverPrivate
;
1065 intel_get_renderbuffer(&intel_fb
->Base
,
1066 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1069 if (intel_rb
&& dPriv
->vblFlags
&&
1070 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1071 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1074 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1076 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1077 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1080 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1081 drmWaitVBlank(intel
->driFd
, &vbl
);
1082 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1085 if (!sPriv
->dri2
.enabled
) {
1086 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1087 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1090 intelContendedLock( intel
, 0 );
1094 if (INTEL_DEBUG
& DEBUG_LOCK
)
1095 _mesa_printf("%s - locked\n", __progname
);
1099 /* Unlock the hardware using the global current context
1101 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1103 __DRIscreen
*sPriv
= intel
->driScreen
;
1106 if (intel
->locked
> 0)
1109 assert(intel
->locked
== 0);
1111 if (!sPriv
->dri2
.enabled
) {
1112 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1113 _glthread_UNLOCK_MUTEX(lockMutex
);
1116 if (INTEL_DEBUG
& DEBUG_LOCK
)
1117 _mesa_printf("%s - unlocked\n", __progname
);
1120 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1123 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1124 intel_batchbuffer_flush(intel
->batch
);