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 const GLubyte
*
75 intelGetString(GLcontext
* ctx
, GLenum name
)
77 const struct intel_context
*const intel
= intel_context(ctx
);
79 static char buffer
[128];
83 return (GLubyte
*) "Tungsten Graphics, Inc";
87 switch (intel
->intelScreen
->deviceID
) {
89 chipset
= "Intel(R) 845G";
92 chipset
= "Intel(R) 830M";
94 case PCI_CHIP_I855_GM
:
95 chipset
= "Intel(R) 852GM/855GM";
98 chipset
= "Intel(R) 865G";
100 case PCI_CHIP_I915_G
:
101 chipset
= "Intel(R) 915G";
103 case PCI_CHIP_E7221_G
:
104 chipset
= "Intel (R) E7221G (i915)";
106 case PCI_CHIP_I915_GM
:
107 chipset
= "Intel(R) 915GM";
109 case PCI_CHIP_I945_G
:
110 chipset
= "Intel(R) 945G";
112 case PCI_CHIP_I945_GM
:
113 chipset
= "Intel(R) 945GM";
115 case PCI_CHIP_I945_GME
:
116 chipset
= "Intel(R) 945GME";
119 chipset
= "Intel(R) G33";
122 chipset
= "Intel(R) Q35";
125 chipset
= "Intel(R) Q33";
127 case PCI_CHIP_IGD_GM
:
129 chipset
= "Intel(R) IGD";
131 case PCI_CHIP_I965_Q
:
132 chipset
= "Intel(R) 965Q";
134 case PCI_CHIP_I965_G
:
135 case PCI_CHIP_I965_G_1
:
136 chipset
= "Intel(R) 965G";
138 case PCI_CHIP_I946_GZ
:
139 chipset
= "Intel(R) 946GZ";
141 case PCI_CHIP_I965_GM
:
142 chipset
= "Intel(R) 965GM";
144 case PCI_CHIP_I965_GME
:
145 chipset
= "Intel(R) 965GME/GLE";
147 case PCI_CHIP_GM45_GM
:
148 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
150 case PCI_CHIP_IGD_E_G
:
151 chipset
= "Intel(R) Integrated Graphics Device";
154 chipset
= "Intel(R) G45/G43";
157 chipset
= "Intel(R) Q45/Q43";
160 chipset
= "Intel(R) G41";
163 chipset
= "Unknown Intel Chipset";
167 (void) driGetRendererString(buffer
, chipset
,
168 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
170 return (GLubyte
*) buffer
;
178 intel_bits_per_pixel(const struct intel_renderbuffer
*rb
)
180 switch (rb
->Base
._ActualFormat
) {
182 case GL_DEPTH_COMPONENT16
:
186 case GL_DEPTH_COMPONENT24
:
187 case GL_DEPTH24_STENCIL8_EXT
:
188 case GL_STENCIL_INDEX8_EXT
:
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
|| !intel_fb
->color_rb
[1])
222 && intel_fb
->color_rb
[0]) {
223 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
224 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[0]);
227 if (intel_fb
->color_rb
[1]) {
228 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
229 attachments
[i
++] = intel_bits_per_pixel(intel_fb
->color_rb
[1]);
232 depth_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
233 stencil_rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
235 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
236 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
237 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
238 } else if (depth_rb
!= NULL
) {
239 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
240 attachments
[i
++] = intel_bits_per_pixel(depth_rb
);
241 } else if (stencil_rb
!= NULL
) {
242 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
243 attachments
[i
++] = intel_bits_per_pixel(stencil_rb
);
247 (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
252 drawable
->loaderPrivate
);
253 } else if (screen
->dri2
.loader
) {
255 if (intel_fb
->color_rb
[0])
256 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
257 if (intel_fb
->color_rb
[1])
258 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
259 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
260 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
261 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
262 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
264 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
269 drawable
->loaderPrivate
);
279 drawable
->numClipRects
= 1;
280 drawable
->pClipRects
[0].x1
= 0;
281 drawable
->pClipRects
[0].y1
= 0;
282 drawable
->pClipRects
[0].x2
= drawable
->w
;
283 drawable
->pClipRects
[0].y2
= drawable
->h
;
284 drawable
->numBackClipRects
= 1;
285 drawable
->pBackClipRects
[0].x1
= 0;
286 drawable
->pBackClipRects
[0].y1
= 0;
287 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
288 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
291 for (i
= 0; i
< count
; i
++) {
292 switch (buffers
[i
].attachment
) {
293 case __DRI_BUFFER_FRONT_LEFT
:
294 rb
= intel_fb
->color_rb
[0];
295 region_name
= "dri2 front buffer";
298 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
299 rb
= intel_fb
->color_rb
[0];
300 region_name
= "dri2 fake front buffer";
303 case __DRI_BUFFER_BACK_LEFT
:
304 rb
= intel_fb
->color_rb
[1];
305 region_name
= "dri2 back buffer";
308 case __DRI_BUFFER_DEPTH
:
309 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
310 region_name
= "dri2 depth buffer";
313 case __DRI_BUFFER_DEPTH_STENCIL
:
314 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
315 region_name
= "dri2 depth / stencil buffer";
318 case __DRI_BUFFER_STENCIL
:
319 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
320 region_name
= "dri2 stencil buffer";
323 case __DRI_BUFFER_ACCUM
:
326 "unhandled buffer attach event, attacment type %d\n",
327 buffers
[i
].attachment
);
335 dri_bo_flink(rb
->region
->buffer
, &name
);
336 if (name
== buffers
[i
].name
)
340 if (INTEL_DEBUG
& DEBUG_DRI
)
342 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
343 buffers
[i
].name
, buffers
[i
].attachment
,
344 buffers
[i
].cpp
, buffers
[i
].pitch
);
346 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
347 if (INTEL_DEBUG
& DEBUG_DRI
)
348 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
349 intel_region_reference(®ion
, depth_region
);
352 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
355 buffers
[i
].pitch
/ buffers
[i
].cpp
,
359 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
360 depth_region
= region
;
362 intel_renderbuffer_set_region(rb
, region
);
363 intel_region_release(®ion
);
365 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
366 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
368 struct intel_region
*stencil_region
= NULL
;
371 dri_bo_flink(rb
->region
->buffer
, &name
);
372 if (name
== buffers
[i
].name
)
376 intel_region_reference(&stencil_region
, region
);
377 intel_renderbuffer_set_region(rb
, stencil_region
);
378 intel_region_release(&stencil_region
);
383 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
387 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
389 struct intel_context
*intel
= intel_context(ctx
);
390 __DRIcontext
*driContext
= intel
->driContext
;
391 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
392 GLsizei w
, GLsizei h
);
394 if (!driContext
->driScreenPriv
->dri2
.enabled
)
397 if (!intel
->internal_viewport_call
&& ctx
->DrawBuffer
->Name
== 0) {
398 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
399 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
400 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
403 old_viewport
= ctx
->Driver
.Viewport
;
404 ctx
->Driver
.Viewport
= NULL
;
405 intel
->driDrawable
= driContext
->driDrawablePriv
;
406 intelWindowMoved(intel
);
407 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
408 ctx
->Driver
.Viewport
= old_viewport
;
412 static const struct dri_debug_control debug_control
[] = {
413 { "tex", DEBUG_TEXTURE
},
414 { "state", DEBUG_STATE
},
415 { "ioctl", DEBUG_IOCTL
},
416 { "blit", DEBUG_BLIT
},
417 { "mip", DEBUG_MIPTREE
},
418 { "fall", DEBUG_FALLBACKS
},
419 { "verb", DEBUG_VERBOSE
},
420 { "bat", DEBUG_BATCH
},
421 { "pix", DEBUG_PIXEL
},
422 { "buf", DEBUG_BUFMGR
},
423 { "reg", DEBUG_REGION
},
425 { "lock", DEBUG_LOCK
},
426 { "sync", DEBUG_SYNC
},
427 { "prim", DEBUG_PRIMS
},
428 { "vert", DEBUG_VERTS
},
429 { "dri", DEBUG_DRI
},
430 { "dma", DEBUG_DMA
},
431 { "san", DEBUG_SANITY
},
432 { "sleep", DEBUG_SLEEP
},
433 { "stats", DEBUG_STATS
},
434 { "tile", DEBUG_TILE
},
435 { "sing", DEBUG_SINGLE_THREAD
},
436 { "thre", DEBUG_SINGLE_THREAD
},
438 { "urb", DEBUG_URB
},
445 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
447 struct intel_context
*intel
= intel_context(ctx
);
449 _swrast_InvalidateState(ctx
, new_state
);
450 _swsetup_InvalidateState(ctx
, new_state
);
451 _vbo_InvalidateState(ctx
, new_state
);
452 _tnl_InvalidateState(ctx
, new_state
);
453 _tnl_invalidate_vertex_state(ctx
, new_state
);
455 intel
->NewGLState
|= new_state
;
457 if (intel
->vtbl
.invalidate_state
)
458 intel
->vtbl
.invalidate_state( intel
, new_state
);
462 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
464 struct intel_context
*intel
= intel_context(ctx
);
469 if (!IS_965(intel
->intelScreen
->deviceID
))
470 INTEL_FIREVERTICES(intel
);
472 /* Emit a flush so that any frontbuffer rendering that might have occurred
473 * lands onscreen in a timely manner, even if the X Server doesn't trigger
477 intel_batchbuffer_emit_mi_flush(intel
->batch
);
479 if (intel
->batch
->map
!= intel
->batch
->ptr
)
480 intel_batchbuffer_flush(intel
->batch
);
482 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
483 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
485 if (screen
->dri2
.loader
&&
486 (screen
->dri2
.loader
->base
.version
>= 2)
487 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
488 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
489 intel
->driDrawable
->loaderPrivate
);
491 /* Only clear the dirty bit if front-buffer rendering is no longer
492 * enabled. This is done so that the dirty bit can only be set in
493 * glDrawBuffer. Otherwise the dirty bit would have to be set at
494 * each of N places that do rendering. This has worse performances,
495 * but it is much easier to get correct.
497 if (intel
->is_front_buffer_rendering
) {
498 intel
->front_buffer_dirty
= GL_FALSE
;
505 intelFlush(GLcontext
* ctx
)
507 intel_flush(ctx
, GL_FALSE
);
511 intel_glFlush(GLcontext
*ctx
)
513 intel_flush(ctx
, GL_TRUE
);
517 intelFinish(GLcontext
* ctx
)
519 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
524 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
525 struct intel_renderbuffer
*irb
;
527 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
530 dri_bo_wait_rendering(irb
->region
->buffer
);
532 if (fb
->_DepthBuffer
) {
533 /* XXX: Wait on buffer idle */
538 intelInitDriverFunctions(struct dd_function_table
*functions
)
540 _mesa_init_driver_functions(functions
);
542 functions
->Flush
= intel_glFlush
;
543 functions
->Finish
= intelFinish
;
544 functions
->GetString
= intelGetString
;
545 functions
->UpdateState
= intelInvalidateState
;
547 functions
->CopyColorTable
= _swrast_CopyColorTable
;
548 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
549 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
550 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
552 intelInitTextureFuncs(functions
);
553 intelInitStateFuncs(functions
);
554 intelInitClearFuncs(functions
);
555 intelInitBufferFuncs(functions
);
556 intelInitPixelFuncs(functions
);
561 intelInitContext(struct intel_context
*intel
,
562 const __GLcontextModes
* mesaVis
,
563 __DRIcontextPrivate
* driContextPriv
,
564 void *sharedContextPrivate
,
565 struct dd_function_table
*functions
)
567 GLcontext
*ctx
= &intel
->ctx
;
568 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
569 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
570 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
573 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
574 functions
, (void *) intel
)) {
575 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
579 driContextPriv
->driverPrivate
= intel
;
580 intel
->intelScreen
= intelScreen
;
581 intel
->driScreen
= sPriv
;
582 intel
->sarea
= intelScreen
->sarea
;
583 intel
->driContext
= driContextPriv
;
586 intel
->hHWContext
= driContextPriv
->hHWContext
;
587 intel
->driFd
= sPriv
->fd
;
588 intel
->driHwLock
= sPriv
->lock
;
590 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
591 intel
->driScreen
->myNum
,
592 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
593 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
594 intel
->maxBatchSize
= 4096;
596 intel
->maxBatchSize
= BATCH_SZ
;
598 intel
->bufmgr
= intelScreen
->bufmgr
;
599 intel
->ttm
= intelScreen
->ttm
;
603 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
604 switch (bo_reuse_mode
) {
605 case DRI_CONF_BO_REUSE_DISABLED
:
607 case DRI_CONF_BO_REUSE_ALL
:
608 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
613 /* This doesn't yet catch all non-conformant rendering, but it's a
616 if (getenv("INTEL_STRICT_CONFORMANCE")) {
617 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
619 intel
->conformance_mode
= value
;
622 intel
->conformance_mode
= 1;
626 if (intel
->conformance_mode
> 0) {
627 ctx
->Const
.MinLineWidth
= 1.0;
628 ctx
->Const
.MinLineWidthAA
= 1.0;
629 ctx
->Const
.MaxLineWidth
= 1.0;
630 ctx
->Const
.MaxLineWidthAA
= 1.0;
631 ctx
->Const
.LineWidthGranularity
= 1.0;
634 ctx
->Const
.MinLineWidth
= 1.0;
635 ctx
->Const
.MinLineWidthAA
= 1.0;
636 ctx
->Const
.MaxLineWidth
= 5.0;
637 ctx
->Const
.MaxLineWidthAA
= 5.0;
638 ctx
->Const
.LineWidthGranularity
= 0.5;
641 ctx
->Const
.MinPointSize
= 1.0;
642 ctx
->Const
.MinPointSizeAA
= 1.0;
643 ctx
->Const
.MaxPointSize
= 255.0;
644 ctx
->Const
.MaxPointSizeAA
= 3.0;
645 ctx
->Const
.PointSizeGranularity
= 1.0;
647 /* reinitialize the context point state.
648 * It depend on constants in __GLcontextRec::Const
650 _mesa_init_point(ctx
);
652 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
653 if (IS_965(intelScreen
->deviceID
)) {
654 if (MAX_WIDTH
> 8192)
655 ctx
->Const
.MaxRenderbufferSize
= 8192;
657 if (MAX_WIDTH
> 2048)
658 ctx
->Const
.MaxRenderbufferSize
= 2048;
661 /* Initialize the software rasterizer and helper modules. */
662 _swrast_CreateContext(ctx
);
663 _vbo_CreateContext(ctx
);
664 _tnl_CreateContext(ctx
);
665 _swsetup_CreateContext(ctx
);
667 /* Configure swrast to match hardware characteristics: */
668 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
669 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
671 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
672 intel
->hw_stipple
= 1;
674 /* XXX FBO: this doesn't seem to be used anywhere */
675 switch (mesaVis
->depthBits
) {
676 case 0: /* what to do in this case? */
678 intel
->polygon_offset_scale
= 1.0;
681 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
688 if (IS_965(intelScreen
->deviceID
))
689 intel
->polygon_offset_scale
/= 0xffff;
691 intel
->RenderIndex
= ~0;
693 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
694 intel
->irqsEmitted
= 0;
696 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
697 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
699 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
701 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
702 _mesa_printf("IRQs not active. Exiting\n");
706 intelInitExtensions(ctx
, GL_FALSE
);
708 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
709 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
710 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
712 if (!sPriv
->dri2
.enabled
)
713 intel_recreate_static_regions(intel
);
715 intel
->batch
= intel_batchbuffer_alloc(intel
);
717 intel_bufferobj_init(intel
);
718 intel_fbo_init(intel
);
720 if (intel
->ctx
.Mesa_DXTn
) {
721 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
722 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
724 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
725 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
728 intel
->prim
.primitive
= ~0;
730 /* Force all software fallbacks */
731 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
732 fprintf(stderr
, "disabling 3D rasterization\n");
736 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
737 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
738 intel
->always_flush_batch
= 1;
741 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
742 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
743 intel
->always_flush_cache
= 1;
746 /* Disable all hardware rendering (skip emitting batches and fences/waits
749 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
755 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
757 struct intel_context
*intel
=
758 (struct intel_context
*) driContextPriv
->driverPrivate
;
760 assert(intel
); /* should never be null */
762 GLboolean release_texture_heaps
;
764 INTEL_FIREVERTICES(intel
);
766 if (intel
->clear
.arrayObj
)
767 _mesa_delete_array_object(&intel
->ctx
, intel
->clear
.arrayObj
);
769 intel
->vtbl
.destroy(intel
);
771 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
772 _swsetup_DestroyContext(&intel
->ctx
);
773 _tnl_DestroyContext(&intel
->ctx
);
774 _vbo_DestroyContext(&intel
->ctx
);
776 _swrast_DestroyContext(&intel
->ctx
);
777 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
779 intel_batchbuffer_free(intel
->batch
);
782 free(intel
->prim
.vb
);
783 intel
->prim
.vb
= NULL
;
784 dri_bo_unreference(intel
->prim
.vb_bo
);
785 intel
->prim
.vb_bo
= NULL
;
787 if (release_texture_heaps
) {
788 /* Nothing is currently done here to free texture heaps;
789 * but we're not using the texture heap utilities, so I
790 * rather think we shouldn't. I've taken a look, and can't
791 * find any private texture data hanging around anywhere, but
792 * I'm not yet certain there isn't any at all...
794 /* if (INTEL_DEBUG & DEBUG_TEXTURE)
795 fprintf(stderr, "do something to free texture heaps\n");
799 /* XXX In intelMakeCurrent() below, the context's static regions are
800 * referenced inside the frame buffer; it's listed as a hack,
801 * with a comment of "XXX FBO temporary fix-ups!", but
802 * as long as it's there, we should release the regions here.
803 * The do/while loop around the block is used to allow the
804 * "continue" statements inside the block to exit the block,
805 * to avoid many layers of "if" constructs.
808 __DRIdrawablePrivate
* driDrawPriv
= intel
->driDrawable
;
809 struct intel_framebuffer
*intel_fb
;
810 struct intel_renderbuffer
*irbDepth
, *irbStencil
;
812 /* We're already detached from the drawable; exit this block. */
815 intel_fb
= (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
817 /* The frame buffer is already gone; exit this block. */
820 irbDepth
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
821 irbStencil
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
823 /* If the regions of the frame buffer still match the regions
824 * of the context, release them. If they've changed somehow,
827 if (intel_fb
->color_rb
[0] && intel_fb
->color_rb
[0]->region
== intel
->front_region
) {
828 intel_renderbuffer_set_region(intel_fb
->color_rb
[0], NULL
);
830 if (intel_fb
->color_rb
[1] && intel_fb
->color_rb
[1]->region
== intel
->back_region
) {
831 intel_renderbuffer_set_region(intel_fb
->color_rb
[1], NULL
);
834 if (irbDepth
&& irbDepth
->region
== intel
->depth_region
) {
835 intel_renderbuffer_set_region(irbDepth
, NULL
);
837 /* Usually, the stencil buffer is the same as the depth buffer;
838 * but they're handled separately in MakeCurrent, so we'll
839 * handle them separately here.
841 if (irbStencil
&& irbStencil
->region
== intel
->depth_region
) {
842 intel_renderbuffer_set_region(irbStencil
, NULL
);
846 intel_region_release(&intel
->front_region
);
847 intel_region_release(&intel
->back_region
);
848 intel_region_release(&intel
->depth_region
);
850 driDestroyOptionCache(&intel
->optionCache
);
852 /* free the Mesa context */
853 _mesa_free_context_data(&intel
->ctx
);
860 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
866 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
867 __DRIdrawablePrivate
* driDrawPriv
,
868 __DRIdrawablePrivate
* driReadPriv
)
870 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
872 if (driContextPriv
) {
873 struct intel_context
*intel
=
874 (struct intel_context
*) driContextPriv
->driverPrivate
;
875 struct intel_framebuffer
*intel_fb
=
876 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
877 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
879 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
880 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
881 if (driDrawPriv
!= driReadPriv
)
882 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
884 /* XXX FBO temporary fix-ups! These are released in
885 * intelDextroyContext(), above. Changes here should be
888 /* if the renderbuffers don't have regions, init them from the context */
889 struct intel_renderbuffer
*irbDepth
890 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
891 struct intel_renderbuffer
*irbStencil
892 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
894 if (intel_fb
->color_rb
[0]) {
895 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
896 intel
->front_region
);
898 if (intel_fb
->color_rb
[1]) {
899 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
904 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
907 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
911 /* set GLframebuffer size to match window, if needed */
912 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
914 if (driReadPriv
!= driDrawPriv
) {
915 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
918 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
920 /* The drawbuffer won't always be updated by _mesa_make_current:
922 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
924 if (intel
->driReadDrawable
!= driReadPriv
)
925 intel
->driReadDrawable
= driReadPriv
;
927 if (intel
->driDrawable
!= driDrawPriv
) {
928 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
931 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
932 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
933 : VBLANK_FLAG_NO_IRQ
;
935 /* Prevent error printf if one crtc is disabled, this will
936 * be properly calculated in intelWindowMoved() next.
938 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
940 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
941 driDrawableInitVBlank(driDrawPriv
);
942 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
944 for (i
= 0; i
< 2; i
++) {
945 if (intel_fb
->color_rb
[i
])
946 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
949 intel
->driDrawable
= driDrawPriv
;
950 intelWindowMoved(intel
);
953 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
957 _mesa_make_current(NULL
, NULL
, NULL
);
964 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
966 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
967 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
968 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
969 int me
= intel
->hHWContext
;
971 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
974 if (INTEL_DEBUG
& DEBUG_LOCK
)
975 _mesa_printf("%s - got contended lock\n", __progname
);
977 /* If the window moved, may need to set a new cliprect now.
979 * NOTE: This releases and regains the hw lock, so all state
980 * checking must be done *after* this call:
983 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
985 if (sarea
&& sarea
->ctxOwner
!= me
) {
986 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
987 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
988 sarea
->ctxOwner
, me
);
990 sarea
->ctxOwner
= me
;
993 /* If the last consumer of the texture memory wasn't us, notify the fake
994 * bufmgr and record the new owner. We should have the memory shared
995 * between contexts of a single fake bufmgr, but this will at least make
996 * things correct for now.
998 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
999 sarea
->texAge
= intel
->hHWContext
;
1000 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
1001 if (INTEL_DEBUG
& DEBUG_BATCH
)
1002 intel_decode_context_reset();
1003 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
1004 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
1005 sarea
->ctxOwner
, intel
->hHWContext
);
1008 /* Drawable changed?
1010 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
1011 intelWindowMoved(intel
);
1012 intel
->lastStamp
= dPriv
->lastStamp
;
1017 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
1019 /* Lock the hardware and validate our state.
1021 void LOCK_HARDWARE( struct intel_context
*intel
)
1023 __DRIdrawable
*dPriv
= intel
->driDrawable
;
1024 __DRIscreen
*sPriv
= intel
->driScreen
;
1026 struct intel_framebuffer
*intel_fb
= NULL
;
1027 struct intel_renderbuffer
*intel_rb
= NULL
;
1029 _glthread_LOCK_MUTEX(lockMutex
);
1030 assert(!intel
->locked
);
1033 if (intel
->driDrawable
) {
1034 intel_fb
= intel
->driDrawable
->driverPrivate
;
1038 intel_get_renderbuffer(&intel_fb
->Base
,
1039 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
1042 if (intel_rb
&& dPriv
->vblFlags
&&
1043 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
1044 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
1047 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
1049 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
1050 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
1053 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
1054 drmWaitVBlank(intel
->driFd
, &vbl
);
1055 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
1058 if (!sPriv
->dri2
.enabled
) {
1059 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
1060 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
1063 intelContendedLock( intel
, 0 );
1067 if (INTEL_DEBUG
& DEBUG_LOCK
)
1068 _mesa_printf("%s - locked\n", __progname
);
1072 /* Unlock the hardware using the global current context
1074 void UNLOCK_HARDWARE( struct intel_context
*intel
)
1076 __DRIscreen
*sPriv
= intel
->driScreen
;
1078 intel
->vtbl
.note_unlock( intel
);
1081 if (!sPriv
->dri2
.enabled
)
1082 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
1084 _glthread_UNLOCK_MUTEX(lockMutex
);
1086 if (INTEL_DEBUG
& DEBUG_LOCK
)
1087 _mesa_printf("%s - unlocked\n", __progname
);
1090 * Nothing should be left in batch outside of LOCK/UNLOCK which references
1093 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
1094 intel_batchbuffer_flush(intel
->batch
);