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/extensions.h"
32 #include "main/framebuffer.h"
33 #include "main/imports.h"
34 #include "main/points.h"
36 #include "swrast/swrast.h"
37 #include "swrast_setup/swrast_setup.h"
39 #include "drivers/common/driverfuncs.h"
43 #include "intel_chipset.h"
44 #include "intel_buffers.h"
45 #include "intel_tex.h"
46 #include "intel_batchbuffer.h"
47 #include "intel_clear.h"
48 #include "intel_extensions.h"
49 #include "intel_pixel.h"
50 #include "intel_regions.h"
51 #include "intel_buffer_objects.h"
52 #include "intel_fbo.h"
53 #include "intel_decode.h"
54 #include "intel_bufmgr.h"
55 #include "intel_screen.h"
56 #include "intel_swapbuffers.h"
58 #include "drirenderbuffer.h"
61 #include "xmlpool.h" /* for symbolic values of enum-type options */
65 int INTEL_DEBUG
= (0);
69 #define DRIVER_DATE "20090114"
70 #define DRIVER_DATE_GEM "GEM " DRIVER_DATE
73 static const GLubyte
*
74 intelGetString(GLcontext
* ctx
, GLenum name
)
76 const struct intel_context
*const intel
= intel_context(ctx
);
78 static char buffer
[128];
82 return (GLubyte
*) "Tungsten Graphics, Inc";
86 switch (intel
->intelScreen
->deviceID
) {
88 chipset
= "Intel(R) 845G";
91 chipset
= "Intel(R) 830M";
93 case PCI_CHIP_I855_GM
:
94 chipset
= "Intel(R) 852GM/855GM";
97 chipset
= "Intel(R) 865G";
100 chipset
= "Intel(R) 915G";
102 case PCI_CHIP_E7221_G
:
103 chipset
= "Intel (R) E7221G (i915)";
105 case PCI_CHIP_I915_GM
:
106 chipset
= "Intel(R) 915GM";
108 case PCI_CHIP_I945_G
:
109 chipset
= "Intel(R) 945G";
111 case PCI_CHIP_I945_GM
:
112 chipset
= "Intel(R) 945GM";
114 case PCI_CHIP_I945_GME
:
115 chipset
= "Intel(R) 945GME";
118 chipset
= "Intel(R) G33";
121 chipset
= "Intel(R) Q35";
124 chipset
= "Intel(R) Q33";
126 case PCI_CHIP_IGD_GM
:
128 chipset
= "Intel(R) IGD";
130 case PCI_CHIP_I965_Q
:
131 chipset
= "Intel(R) 965Q";
133 case PCI_CHIP_I965_G
:
134 case PCI_CHIP_I965_G_1
:
135 chipset
= "Intel(R) 965G";
137 case PCI_CHIP_I946_GZ
:
138 chipset
= "Intel(R) 946GZ";
140 case PCI_CHIP_I965_GM
:
141 chipset
= "Intel(R) 965GM";
143 case PCI_CHIP_I965_GME
:
144 chipset
= "Intel(R) 965GME/GLE";
146 case PCI_CHIP_GM45_GM
:
147 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
149 case PCI_CHIP_IGD_E_G
:
150 chipset
= "Intel(R) Integrated Graphics Device";
153 chipset
= "Intel(R) G45/G43";
156 chipset
= "Intel(R) Q45/Q43";
159 chipset
= "Intel(R) G41";
162 chipset
= "Unknown Intel Chipset";
166 (void) driGetRendererString(buffer
, chipset
,
167 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
169 return (GLubyte
*) buffer
;
177 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
179 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
180 struct intel_renderbuffer
*rb
;
181 struct intel_region
*region
, *depth_region
;
182 struct intel_context
*intel
= context
->driverPrivate
;
183 __DRIbuffer
*buffers
;
186 unsigned int attachments
[10];
188 const char *region_name
;
190 if (INTEL_DEBUG
& DEBUG_DRI
)
191 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
193 screen
= intel
->intelScreen
->driScrnPriv
;
196 if (intel_fb
->color_rb
[0])
197 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
198 if (intel_fb
->color_rb
[1])
199 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
200 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
201 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
202 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
203 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
205 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
210 drawable
->loaderPrivate
);
219 drawable
->numClipRects
= 1;
220 drawable
->pClipRects
[0].x1
= 0;
221 drawable
->pClipRects
[0].y1
= 0;
222 drawable
->pClipRects
[0].x2
= drawable
->w
;
223 drawable
->pClipRects
[0].y2
= drawable
->h
;
224 drawable
->numBackClipRects
= 1;
225 drawable
->pBackClipRects
[0].x1
= 0;
226 drawable
->pBackClipRects
[0].y1
= 0;
227 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
228 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
231 for (i
= 0; i
< count
; i
++) {
232 switch (buffers
[i
].attachment
) {
233 case __DRI_BUFFER_FRONT_LEFT
:
234 rb
= intel_fb
->color_rb
[0];
235 region_name
= "dri2 front buffer";
238 case __DRI_BUFFER_BACK_LEFT
:
239 rb
= intel_fb
->color_rb
[1];
240 region_name
= "dri2 back buffer";
243 case __DRI_BUFFER_DEPTH
:
244 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
245 region_name
= "dri2 depth buffer";
248 case __DRI_BUFFER_STENCIL
:
249 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
250 region_name
= "dri2 stencil buffer";
253 case __DRI_BUFFER_ACCUM
:
256 "unhandled buffer attach event, attacment type %d\n",
257 buffers
[i
].attachment
);
265 dri_bo_flink(rb
->region
->buffer
, &name
);
266 if (name
== buffers
[i
].name
)
270 if (INTEL_DEBUG
& DEBUG_DRI
)
272 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
273 buffers
[i
].name
, buffers
[i
].attachment
,
274 buffers
[i
].cpp
, buffers
[i
].pitch
);
276 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
277 if (INTEL_DEBUG
& DEBUG_DRI
)
278 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
279 intel_region_reference(®ion
, depth_region
);
282 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
285 buffers
[i
].pitch
/ buffers
[i
].cpp
,
289 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
290 depth_region
= region
;
292 intel_renderbuffer_set_region(rb
, region
);
293 intel_region_release(®ion
);
296 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
300 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
302 struct intel_context
*intel
= intel_context(ctx
);
303 __DRIcontext
*driContext
= intel
->driContext
;
304 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
305 GLsizei w
, GLsizei h
);
307 if (!driContext
->driScreenPriv
->dri2
.enabled
)
310 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
311 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
312 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
314 old_viewport
= ctx
->Driver
.Viewport
;
315 ctx
->Driver
.Viewport
= NULL
;
316 intel
->driDrawable
= driContext
->driDrawablePriv
;
317 intelWindowMoved(intel
);
318 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
319 ctx
->Driver
.Viewport
= old_viewport
;
323 static const struct dri_debug_control debug_control
[] = {
324 { "tex", DEBUG_TEXTURE
},
325 { "state", DEBUG_STATE
},
326 { "ioctl", DEBUG_IOCTL
},
327 { "blit", DEBUG_BLIT
},
328 { "mip", DEBUG_MIPTREE
},
329 { "fall", DEBUG_FALLBACKS
},
330 { "verb", DEBUG_VERBOSE
},
331 { "bat", DEBUG_BATCH
},
332 { "pix", DEBUG_PIXEL
},
333 { "buf", DEBUG_BUFMGR
},
334 { "reg", DEBUG_REGION
},
336 { "lock", DEBUG_LOCK
},
337 { "sync", DEBUG_SYNC
},
338 { "prim", DEBUG_PRIMS
},
339 { "vert", DEBUG_VERTS
},
340 { "dri", DEBUG_DRI
},
341 { "dma", DEBUG_DMA
},
342 { "san", DEBUG_SANITY
},
343 { "sleep", DEBUG_SLEEP
},
344 { "stats", DEBUG_STATS
},
345 { "tile", DEBUG_TILE
},
346 { "sing", DEBUG_SINGLE_THREAD
},
347 { "thre", DEBUG_SINGLE_THREAD
},
349 { "urb", DEBUG_URB
},
356 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
358 struct intel_context
*intel
= intel_context(ctx
);
360 _swrast_InvalidateState(ctx
, new_state
);
361 _swsetup_InvalidateState(ctx
, new_state
);
362 _vbo_InvalidateState(ctx
, new_state
);
363 _tnl_InvalidateState(ctx
, new_state
);
364 _tnl_invalidate_vertex_state(ctx
, new_state
);
366 intel
->NewGLState
|= new_state
;
368 if (intel
->vtbl
.invalidate_state
)
369 intel
->vtbl
.invalidate_state( intel
, new_state
);
373 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
375 struct intel_context
*intel
= intel_context(ctx
);
380 if (!IS_965(intel
->intelScreen
->deviceID
))
381 INTEL_FIREVERTICES(intel
);
383 /* Emit a flush so that any frontbuffer rendering that might have occurred
384 * lands onscreen in a timely manner, even if the X Server doesn't trigger
388 intel_batchbuffer_emit_mi_flush(intel
->batch
);
390 if (intel
->batch
->map
!= intel
->batch
->ptr
)
391 intel_batchbuffer_flush(intel
->batch
);
395 intelFlush(GLcontext
* ctx
)
397 intel_flush(ctx
, GL_FALSE
);
401 intel_glFlush(GLcontext
*ctx
)
403 intel_flush(ctx
, GL_TRUE
);
407 intelFinish(GLcontext
* ctx
)
409 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
414 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
415 struct intel_renderbuffer
*irb
;
417 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
420 dri_bo_wait_rendering(irb
->region
->buffer
);
422 if (fb
->_DepthBuffer
) {
423 /* XXX: Wait on buffer idle */
428 intelInitDriverFunctions(struct dd_function_table
*functions
)
430 _mesa_init_driver_functions(functions
);
432 functions
->Flush
= intel_glFlush
;
433 functions
->Finish
= intelFinish
;
434 functions
->GetString
= intelGetString
;
435 functions
->UpdateState
= intelInvalidateState
;
437 functions
->CopyColorTable
= _swrast_CopyColorTable
;
438 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
439 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
440 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
442 intelInitTextureFuncs(functions
);
443 intelInitStateFuncs(functions
);
444 intelInitClearFuncs(functions
);
445 intelInitBufferFuncs(functions
);
446 intelInitPixelFuncs(functions
);
451 intelInitContext(struct intel_context
*intel
,
452 const __GLcontextModes
* mesaVis
,
453 __DRIcontextPrivate
* driContextPriv
,
454 void *sharedContextPrivate
,
455 struct dd_function_table
*functions
)
457 GLcontext
*ctx
= &intel
->ctx
;
458 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
459 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
460 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
463 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
464 functions
, (void *) intel
)) {
465 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
469 driContextPriv
->driverPrivate
= intel
;
470 intel
->intelScreen
= intelScreen
;
471 intel
->driScreen
= sPriv
;
472 intel
->sarea
= intelScreen
->sarea
;
473 intel
->driContext
= driContextPriv
;
476 intel
->hHWContext
= driContextPriv
->hHWContext
;
477 intel
->driFd
= sPriv
->fd
;
478 intel
->driHwLock
= sPriv
->lock
;
480 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
481 intel
->driScreen
->myNum
,
482 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
483 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
484 intel
->maxBatchSize
= 4096;
486 intel
->maxBatchSize
= BATCH_SZ
;
488 intel
->bufmgr
= intelScreen
->bufmgr
;
489 intel
->ttm
= intelScreen
->ttm
;
493 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
494 switch (bo_reuse_mode
) {
495 case DRI_CONF_BO_REUSE_DISABLED
:
497 case DRI_CONF_BO_REUSE_ALL
:
498 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
503 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
505 /* This doesn't yet catch all non-conformant rendering, but it's a
508 if (getenv("INTEL_STRICT_CONFORMANCE")) {
509 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
511 intel
->conformance_mode
= value
;
514 intel
->conformance_mode
= 1;
518 if (intel
->conformance_mode
> 0) {
519 ctx
->Const
.MinLineWidth
= 1.0;
520 ctx
->Const
.MinLineWidthAA
= 1.0;
521 ctx
->Const
.MaxLineWidth
= 1.0;
522 ctx
->Const
.MaxLineWidthAA
= 1.0;
523 ctx
->Const
.LineWidthGranularity
= 1.0;
526 ctx
->Const
.MinLineWidth
= 1.0;
527 ctx
->Const
.MinLineWidthAA
= 1.0;
528 ctx
->Const
.MaxLineWidth
= 5.0;
529 ctx
->Const
.MaxLineWidthAA
= 5.0;
530 ctx
->Const
.LineWidthGranularity
= 0.5;
533 ctx
->Const
.MinPointSize
= 1.0;
534 ctx
->Const
.MinPointSizeAA
= 1.0;
535 ctx
->Const
.MaxPointSize
= 255.0;
536 ctx
->Const
.MaxPointSizeAA
= 3.0;
537 ctx
->Const
.PointSizeGranularity
= 1.0;
539 /* reinitialize the context point state.
540 * It depend on constants in __GLcontextRec::Const
542 _mesa_init_point(ctx
);
544 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
546 /* Initialize the software rasterizer and helper modules. */
547 _swrast_CreateContext(ctx
);
548 _vbo_CreateContext(ctx
);
549 _tnl_CreateContext(ctx
);
550 _swsetup_CreateContext(ctx
);
552 /* Configure swrast to match hardware characteristics: */
553 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
554 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
556 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
557 intel
->hw_stipple
= 1;
559 /* XXX FBO: this doesn't seem to be used anywhere */
560 switch (mesaVis
->depthBits
) {
561 case 0: /* what to do in this case? */
563 intel
->polygon_offset_scale
= 1.0;
566 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
573 if (IS_965(intelScreen
->deviceID
))
574 intel
->polygon_offset_scale
/= 0xffff;
576 intel
->RenderIndex
= ~0;
578 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
579 intel
->irqsEmitted
= 0;
581 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
582 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
584 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
586 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
587 _mesa_printf("IRQs not active. Exiting\n");
591 intelInitExtensions(ctx
, GL_FALSE
);
593 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
594 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
595 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
597 if (!sPriv
->dri2
.enabled
)
598 intel_recreate_static_regions(intel
);
600 intel
->batch
= intel_batchbuffer_alloc(intel
);
602 intel_bufferobj_init(intel
);
603 intel_fbo_init(intel
);
605 if (intel
->ctx
.Mesa_DXTn
) {
606 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
607 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
609 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
610 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
613 intel
->prim
.primitive
= ~0;
615 /* Force all software fallbacks */
616 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
617 fprintf(stderr
, "disabling 3D rasterization\n");
621 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
622 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
623 intel
->always_flush_batch
= 1;
626 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
627 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
628 intel
->always_flush_cache
= 1;
631 /* Disable all hardware rendering (skip emitting batches and fences/waits
634 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
640 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
642 struct intel_context
*intel
=
643 (struct intel_context
*) driContextPriv
->driverPrivate
;
645 assert(intel
); /* should never be null */
647 GLboolean release_texture_heaps
;
649 INTEL_FIREVERTICES(intel
);
651 intel
->vtbl
.destroy(intel
);
653 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
654 _swsetup_DestroyContext(&intel
->ctx
);
655 _tnl_DestroyContext(&intel
->ctx
);
656 _vbo_DestroyContext(&intel
->ctx
);
658 _swrast_DestroyContext(&intel
->ctx
);
659 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
661 intel_batchbuffer_free(intel
->batch
);
664 free(intel
->prim
.vb
);
665 intel
->prim
.vb
= NULL
;
666 dri_bo_unreference(intel
->prim
.vb_bo
);
667 intel
->prim
.vb_bo
= NULL
;
669 if (release_texture_heaps
) {
670 /* This share group is about to go away, free our private
671 * texture object data.
673 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
674 fprintf(stderr
, "do something to free texture heaps\n");
677 intel_region_release(&intel
->front_region
);
678 intel_region_release(&intel
->back_region
);
679 intel_region_release(&intel
->depth_region
);
681 driDestroyOptionCache(&intel
->optionCache
);
683 /* free the Mesa context */
684 _mesa_free_context_data(&intel
->ctx
);
689 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
695 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
696 __DRIdrawablePrivate
* driDrawPriv
,
697 __DRIdrawablePrivate
* driReadPriv
)
699 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
701 if (driContextPriv
) {
702 struct intel_context
*intel
=
703 (struct intel_context
*) driContextPriv
->driverPrivate
;
704 struct intel_framebuffer
*intel_fb
=
705 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
706 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
708 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
709 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
710 if (driDrawPriv
!= driReadPriv
)
711 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
713 /* XXX FBO temporary fix-ups! */
714 /* if the renderbuffers don't have regions, init them from the context */
715 struct intel_renderbuffer
*irbDepth
716 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
717 struct intel_renderbuffer
*irbStencil
718 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
720 if (intel_fb
->color_rb
[0]) {
721 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
722 intel
->front_region
);
724 if (intel_fb
->color_rb
[1]) {
725 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
730 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
733 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
737 /* set GLframebuffer size to match window, if needed */
738 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
740 if (driReadPriv
!= driDrawPriv
) {
741 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
744 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
746 /* The drawbuffer won't always be updated by _mesa_make_current:
748 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
750 if (intel
->driReadDrawable
!= driReadPriv
)
751 intel
->driReadDrawable
= driReadPriv
;
753 if (intel
->driDrawable
!= driDrawPriv
) {
754 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
757 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
758 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
759 : VBLANK_FLAG_NO_IRQ
;
761 /* Prevent error printf if one crtc is disabled, this will
762 * be properly calculated in intelWindowMoved() next.
764 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
766 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
767 driDrawableInitVBlank(driDrawPriv
);
768 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
770 for (i
= 0; i
< 2; i
++) {
771 if (intel_fb
->color_rb
[i
])
772 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
775 intel
->driDrawable
= driDrawPriv
;
776 intelWindowMoved(intel
);
779 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
783 _mesa_make_current(NULL
, NULL
, NULL
);
790 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
792 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
793 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
794 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
795 int me
= intel
->hHWContext
;
797 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
800 if (INTEL_DEBUG
& DEBUG_LOCK
)
801 _mesa_printf("%s - got contended lock\n", __progname
);
803 /* If the window moved, may need to set a new cliprect now.
805 * NOTE: This releases and regains the hw lock, so all state
806 * checking must be done *after* this call:
809 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
811 if (sarea
&& sarea
->ctxOwner
!= me
) {
812 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
813 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
814 sarea
->ctxOwner
, me
);
816 sarea
->ctxOwner
= me
;
819 /* If the last consumer of the texture memory wasn't us, notify the fake
820 * bufmgr and record the new owner. We should have the memory shared
821 * between contexts of a single fake bufmgr, but this will at least make
822 * things correct for now.
824 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
825 sarea
->texAge
= intel
->hHWContext
;
826 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
827 if (INTEL_DEBUG
& DEBUG_BATCH
)
828 intel_decode_context_reset();
829 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
830 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
831 sarea
->ctxOwner
, intel
->hHWContext
);
836 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
837 intelWindowMoved(intel
);
838 intel
->lastStamp
= dPriv
->lastStamp
;
843 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
845 /* Lock the hardware and validate our state.
847 void LOCK_HARDWARE( struct intel_context
*intel
)
849 __DRIdrawable
*dPriv
= intel
->driDrawable
;
850 __DRIscreen
*sPriv
= intel
->driScreen
;
852 struct intel_framebuffer
*intel_fb
= NULL
;
853 struct intel_renderbuffer
*intel_rb
= NULL
;
855 _glthread_LOCK_MUTEX(lockMutex
);
856 assert(!intel
->locked
);
859 if (intel
->driDrawable
) {
860 intel_fb
= intel
->driDrawable
->driverPrivate
;
864 intel_get_renderbuffer(&intel_fb
->Base
,
865 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
868 if (intel_rb
&& dPriv
->vblFlags
&&
869 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
870 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
873 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
875 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
876 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
879 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
880 drmWaitVBlank(intel
->driFd
, &vbl
);
881 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
884 if (!sPriv
->dri2
.enabled
) {
885 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
886 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
889 intelContendedLock( intel
, 0 );
893 if (INTEL_DEBUG
& DEBUG_LOCK
)
894 _mesa_printf("%s - locked\n", __progname
);
898 /* Unlock the hardware using the global current context
900 void UNLOCK_HARDWARE( struct intel_context
*intel
)
902 __DRIscreen
*sPriv
= intel
->driScreen
;
904 intel
->vtbl
.note_unlock( intel
);
907 if (!sPriv
->dri2
.enabled
)
908 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
910 _glthread_UNLOCK_MUTEX(lockMutex
);
912 if (INTEL_DEBUG
& DEBUG_LOCK
)
913 _mesa_printf("%s - unlocked\n", __progname
);
916 * Nothing should be left in batch outside of LOCK/UNLOCK which references
919 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
920 intel_batchbuffer_flush(intel
->batch
);