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 intel
->strict_conformance
= 1;
512 if (intel
->strict_conformance
) {
513 ctx
->Const
.MinLineWidth
= 1.0;
514 ctx
->Const
.MinLineWidthAA
= 1.0;
515 ctx
->Const
.MaxLineWidth
= 1.0;
516 ctx
->Const
.MaxLineWidthAA
= 1.0;
517 ctx
->Const
.LineWidthGranularity
= 1.0;
520 ctx
->Const
.MinLineWidth
= 1.0;
521 ctx
->Const
.MinLineWidthAA
= 1.0;
522 ctx
->Const
.MaxLineWidth
= 5.0;
523 ctx
->Const
.MaxLineWidthAA
= 5.0;
524 ctx
->Const
.LineWidthGranularity
= 0.5;
527 ctx
->Const
.MinPointSize
= 1.0;
528 ctx
->Const
.MinPointSizeAA
= 1.0;
529 ctx
->Const
.MaxPointSize
= 255.0;
530 ctx
->Const
.MaxPointSizeAA
= 3.0;
531 ctx
->Const
.PointSizeGranularity
= 1.0;
533 /* reinitialize the context point state.
534 * It depend on constants in __GLcontextRec::Const
536 _mesa_init_point(ctx
);
538 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
540 /* Initialize the software rasterizer and helper modules. */
541 _swrast_CreateContext(ctx
);
542 _vbo_CreateContext(ctx
);
543 _tnl_CreateContext(ctx
);
544 _swsetup_CreateContext(ctx
);
546 /* Configure swrast to match hardware characteristics: */
547 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
548 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
550 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
551 intel
->hw_stipple
= 1;
553 /* XXX FBO: this doesn't seem to be used anywhere */
554 switch (mesaVis
->depthBits
) {
555 case 0: /* what to do in this case? */
557 intel
->polygon_offset_scale
= 1.0;
560 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
567 if (IS_965(intelScreen
->deviceID
))
568 intel
->polygon_offset_scale
/= 0xffff;
570 intel
->RenderIndex
= ~0;
572 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
573 intel
->irqsEmitted
= 0;
575 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
576 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
578 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
580 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
581 _mesa_printf("IRQs not active. Exiting\n");
585 intelInitExtensions(ctx
, GL_FALSE
);
587 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
588 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
589 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
591 if (!sPriv
->dri2
.enabled
)
592 intel_recreate_static_regions(intel
);
594 intel
->batch
= intel_batchbuffer_alloc(intel
);
596 intel_bufferobj_init(intel
);
597 intel_fbo_init(intel
);
599 if (intel
->ctx
.Mesa_DXTn
) {
600 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
601 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
603 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
604 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
607 intel
->prim
.primitive
= ~0;
609 /* Force all software fallbacks */
610 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
611 fprintf(stderr
, "disabling 3D rasterization\n");
615 /* Disable all hardware rendering (skip emitting batches and fences/waits
618 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
624 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
626 struct intel_context
*intel
=
627 (struct intel_context
*) driContextPriv
->driverPrivate
;
629 assert(intel
); /* should never be null */
631 GLboolean release_texture_heaps
;
633 INTEL_FIREVERTICES(intel
);
635 intel
->vtbl
.destroy(intel
);
637 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
638 _swsetup_DestroyContext(&intel
->ctx
);
639 _tnl_DestroyContext(&intel
->ctx
);
640 _vbo_DestroyContext(&intel
->ctx
);
642 _swrast_DestroyContext(&intel
->ctx
);
643 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
645 intel_batchbuffer_free(intel
->batch
);
648 free(intel
->prim
.vb
);
649 intel
->prim
.vb
= NULL
;
650 dri_bo_unreference(intel
->prim
.vb_bo
);
651 intel
->prim
.vb_bo
= NULL
;
653 if (release_texture_heaps
) {
654 /* This share group is about to go away, free our private
655 * texture object data.
657 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
658 fprintf(stderr
, "do something to free texture heaps\n");
661 intel_region_release(&intel
->front_region
);
662 intel_region_release(&intel
->back_region
);
663 intel_region_release(&intel
->depth_region
);
665 driDestroyOptionCache(&intel
->optionCache
);
667 /* free the Mesa context */
668 _mesa_free_context_data(&intel
->ctx
);
673 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
679 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
680 __DRIdrawablePrivate
* driDrawPriv
,
681 __DRIdrawablePrivate
* driReadPriv
)
683 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
685 if (driContextPriv
) {
686 struct intel_context
*intel
=
687 (struct intel_context
*) driContextPriv
->driverPrivate
;
688 struct intel_framebuffer
*intel_fb
=
689 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
690 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
692 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
693 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
694 if (driDrawPriv
!= driReadPriv
)
695 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
697 /* XXX FBO temporary fix-ups! */
698 /* if the renderbuffers don't have regions, init them from the context */
699 struct intel_renderbuffer
*irbDepth
700 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
701 struct intel_renderbuffer
*irbStencil
702 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
704 if (intel_fb
->color_rb
[0]) {
705 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
706 intel
->front_region
);
708 if (intel_fb
->color_rb
[1]) {
709 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
714 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
717 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
721 /* set GLframebuffer size to match window, if needed */
722 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
724 if (driReadPriv
!= driDrawPriv
) {
725 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
728 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
730 /* The drawbuffer won't always be updated by _mesa_make_current:
732 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
734 if (intel
->driReadDrawable
!= driReadPriv
)
735 intel
->driReadDrawable
= driReadPriv
;
737 if (intel
->driDrawable
!= driDrawPriv
) {
738 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
741 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
742 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
743 : VBLANK_FLAG_NO_IRQ
;
745 /* Prevent error printf if one crtc is disabled, this will
746 * be properly calculated in intelWindowMoved() next.
748 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
750 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
751 driDrawableInitVBlank(driDrawPriv
);
752 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
754 for (i
= 0; i
< 2; i
++) {
755 if (intel_fb
->color_rb
[i
])
756 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
759 intel
->driDrawable
= driDrawPriv
;
760 intelWindowMoved(intel
);
763 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
767 _mesa_make_current(NULL
, NULL
, NULL
);
774 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
776 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
777 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
778 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
779 int me
= intel
->hHWContext
;
781 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
784 if (INTEL_DEBUG
& DEBUG_LOCK
)
785 _mesa_printf("%s - got contended lock\n", __progname
);
787 /* If the window moved, may need to set a new cliprect now.
789 * NOTE: This releases and regains the hw lock, so all state
790 * checking must be done *after* this call:
793 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
795 if (sarea
&& sarea
->ctxOwner
!= me
) {
796 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
797 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
798 sarea
->ctxOwner
, me
);
800 sarea
->ctxOwner
= me
;
803 /* If the last consumer of the texture memory wasn't us, notify the fake
804 * bufmgr and record the new owner. We should have the memory shared
805 * between contexts of a single fake bufmgr, but this will at least make
806 * things correct for now.
808 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
809 sarea
->texAge
= intel
->hHWContext
;
810 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
811 if (INTEL_DEBUG
& DEBUG_BATCH
)
812 intel_decode_context_reset();
813 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
814 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
815 sarea
->ctxOwner
, intel
->hHWContext
);
820 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
821 intelWindowMoved(intel
);
822 intel
->lastStamp
= dPriv
->lastStamp
;
827 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
829 /* Lock the hardware and validate our state.
831 void LOCK_HARDWARE( struct intel_context
*intel
)
833 __DRIdrawable
*dPriv
= intel
->driDrawable
;
834 __DRIscreen
*sPriv
= intel
->driScreen
;
836 struct intel_framebuffer
*intel_fb
= NULL
;
837 struct intel_renderbuffer
*intel_rb
= NULL
;
839 _glthread_LOCK_MUTEX(lockMutex
);
840 assert(!intel
->locked
);
843 if (intel
->driDrawable
) {
844 intel_fb
= intel
->driDrawable
->driverPrivate
;
848 intel_get_renderbuffer(&intel_fb
->Base
,
849 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
852 if (intel_rb
&& dPriv
->vblFlags
&&
853 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
854 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
857 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
859 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
860 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
863 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
864 drmWaitVBlank(intel
->driFd
, &vbl
);
865 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
868 if (!sPriv
->dri2
.enabled
) {
869 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
870 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
873 intelContendedLock( intel
, 0 );
877 if (INTEL_DEBUG
& DEBUG_LOCK
)
878 _mesa_printf("%s - locked\n", __progname
);
882 /* Unlock the hardware using the global current context
884 void UNLOCK_HARDWARE( struct intel_context
*intel
)
886 __DRIscreen
*sPriv
= intel
->driScreen
;
888 intel
->vtbl
.note_unlock( intel
);
891 if (!sPriv
->dri2
.enabled
)
892 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
894 _glthread_UNLOCK_MUTEX(lockMutex
);
896 if (INTEL_DEBUG
& DEBUG_LOCK
)
897 _mesa_printf("%s - unlocked\n", __progname
);
900 * Nothing should be left in batch outside of LOCK/UNLOCK which references
903 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
904 intel_batchbuffer_flush(intel
->batch
);