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_I965_Q
:
127 chipset
= "Intel(R) 965Q";
129 case PCI_CHIP_I965_G
:
130 case PCI_CHIP_I965_G_1
:
131 chipset
= "Intel(R) 965G";
133 case PCI_CHIP_I946_GZ
:
134 chipset
= "Intel(R) 946GZ";
136 case PCI_CHIP_I965_GM
:
137 chipset
= "Intel(R) 965GM";
139 case PCI_CHIP_I965_GME
:
140 chipset
= "Intel(R) 965GME/GLE";
142 case PCI_CHIP_GM45_GM
:
143 chipset
= "Mobile IntelĀ® GM45 Express Chipset";
145 case PCI_CHIP_IGD_E_G
:
146 chipset
= "Intel(R) Integrated Graphics Device";
149 chipset
= "Intel(R) G45/G43";
152 chipset
= "Intel(R) Q45/Q43";
155 chipset
= "Intel(R) G41";
158 chipset
= "Unknown Intel Chipset";
162 (void) driGetRendererString(buffer
, chipset
,
163 (intel
->ttm
) ? DRIVER_DATE_GEM
: DRIVER_DATE
,
165 return (GLubyte
*) buffer
;
173 intel_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
175 struct intel_framebuffer
*intel_fb
= drawable
->driverPrivate
;
176 struct intel_renderbuffer
*rb
;
177 struct intel_region
*region
, *depth_region
;
178 struct intel_context
*intel
= context
->driverPrivate
;
179 __DRIbuffer
*buffers
;
182 unsigned int attachments
[10];
184 const char *region_name
;
186 if (INTEL_DEBUG
& DEBUG_DRI
)
187 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
189 screen
= intel
->intelScreen
->driScrnPriv
;
192 if (intel_fb
->color_rb
[0])
193 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
194 if (intel_fb
->color_rb
[1])
195 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
196 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
))
197 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
198 if (intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
))
199 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
201 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
206 drawable
->loaderPrivate
);
215 drawable
->numClipRects
= 1;
216 drawable
->pClipRects
[0].x1
= 0;
217 drawable
->pClipRects
[0].y1
= 0;
218 drawable
->pClipRects
[0].x2
= drawable
->w
;
219 drawable
->pClipRects
[0].y2
= drawable
->h
;
220 drawable
->numBackClipRects
= 1;
221 drawable
->pBackClipRects
[0].x1
= 0;
222 drawable
->pBackClipRects
[0].y1
= 0;
223 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
224 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
227 for (i
= 0; i
< count
; i
++) {
228 switch (buffers
[i
].attachment
) {
229 case __DRI_BUFFER_FRONT_LEFT
:
230 rb
= intel_fb
->color_rb
[0];
231 region_name
= "dri2 front buffer";
234 case __DRI_BUFFER_BACK_LEFT
:
235 rb
= intel_fb
->color_rb
[1];
236 region_name
= "dri2 back buffer";
239 case __DRI_BUFFER_DEPTH
:
240 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
241 region_name
= "dri2 depth buffer";
244 case __DRI_BUFFER_STENCIL
:
245 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
246 region_name
= "dri2 stencil buffer";
249 case __DRI_BUFFER_ACCUM
:
252 "unhandled buffer attach event, attacment type %d\n",
253 buffers
[i
].attachment
);
261 dri_bo_flink(rb
->region
->buffer
, &name
);
262 if (name
== buffers
[i
].name
)
266 if (INTEL_DEBUG
& DEBUG_DRI
)
268 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
269 buffers
[i
].name
, buffers
[i
].attachment
,
270 buffers
[i
].cpp
, buffers
[i
].pitch
);
272 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
273 if (INTEL_DEBUG
& DEBUG_DRI
)
274 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
275 intel_region_reference(®ion
, depth_region
);
278 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
281 buffers
[i
].pitch
/ buffers
[i
].cpp
,
285 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
286 depth_region
= region
;
288 intel_renderbuffer_set_region(rb
, region
);
289 intel_region_release(®ion
);
292 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
296 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
298 struct intel_context
*intel
= intel_context(ctx
);
299 __DRIcontext
*driContext
= intel
->driContext
;
300 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
301 GLsizei w
, GLsizei h
);
303 if (!driContext
->driScreenPriv
->dri2
.enabled
)
306 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
307 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
308 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
310 old_viewport
= ctx
->Driver
.Viewport
;
311 ctx
->Driver
.Viewport
= NULL
;
312 intel
->driDrawable
= driContext
->driDrawablePriv
;
313 intelWindowMoved(intel
);
314 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
315 ctx
->Driver
.Viewport
= old_viewport
;
319 static const struct dri_debug_control debug_control
[] = {
320 { "tex", DEBUG_TEXTURE
},
321 { "state", DEBUG_STATE
},
322 { "ioctl", DEBUG_IOCTL
},
323 { "blit", DEBUG_BLIT
},
324 { "mip", DEBUG_MIPTREE
},
325 { "fall", DEBUG_FALLBACKS
},
326 { "verb", DEBUG_VERBOSE
},
327 { "bat", DEBUG_BATCH
},
328 { "pix", DEBUG_PIXEL
},
329 { "buf", DEBUG_BUFMGR
},
330 { "reg", DEBUG_REGION
},
332 { "lock", DEBUG_LOCK
},
333 { "sync", DEBUG_SYNC
},
334 { "prim", DEBUG_PRIMS
},
335 { "vert", DEBUG_VERTS
},
336 { "dri", DEBUG_DRI
},
337 { "dma", DEBUG_DMA
},
338 { "san", DEBUG_SANITY
},
339 { "sleep", DEBUG_SLEEP
},
340 { "stats", DEBUG_STATS
},
341 { "tile", DEBUG_TILE
},
342 { "sing", DEBUG_SINGLE_THREAD
},
343 { "thre", DEBUG_SINGLE_THREAD
},
345 { "urb", DEBUG_URB
},
352 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
354 struct intel_context
*intel
= intel_context(ctx
);
356 _swrast_InvalidateState(ctx
, new_state
);
357 _swsetup_InvalidateState(ctx
, new_state
);
358 _vbo_InvalidateState(ctx
, new_state
);
359 _tnl_InvalidateState(ctx
, new_state
);
360 _tnl_invalidate_vertex_state(ctx
, new_state
);
362 intel
->NewGLState
|= new_state
;
364 if (intel
->vtbl
.invalidate_state
)
365 intel
->vtbl
.invalidate_state( intel
, new_state
);
369 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
371 struct intel_context
*intel
= intel_context(ctx
);
376 if (!IS_965(intel
->intelScreen
->deviceID
))
377 INTEL_FIREVERTICES(intel
);
379 /* Emit a flush so that any frontbuffer rendering that might have occurred
380 * lands onscreen in a timely manner, even if the X Server doesn't trigger
384 intel_batchbuffer_emit_mi_flush(intel
->batch
);
386 if (intel
->batch
->map
!= intel
->batch
->ptr
)
387 intel_batchbuffer_flush(intel
->batch
);
391 intelFlush(GLcontext
* ctx
)
393 intel_flush(ctx
, GL_FALSE
);
397 intel_glFlush(GLcontext
*ctx
)
399 intel_flush(ctx
, GL_TRUE
);
403 intelFinish(GLcontext
* ctx
)
405 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
410 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
411 struct intel_renderbuffer
*irb
;
413 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
416 dri_bo_wait_rendering(irb
->region
->buffer
);
418 if (fb
->_DepthBuffer
) {
419 /* XXX: Wait on buffer idle */
424 intelInitDriverFunctions(struct dd_function_table
*functions
)
426 _mesa_init_driver_functions(functions
);
428 functions
->Flush
= intel_glFlush
;
429 functions
->Finish
= intelFinish
;
430 functions
->GetString
= intelGetString
;
431 functions
->UpdateState
= intelInvalidateState
;
433 functions
->CopyColorTable
= _swrast_CopyColorTable
;
434 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
435 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
436 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
438 intelInitTextureFuncs(functions
);
439 intelInitStateFuncs(functions
);
440 intelInitClearFuncs(functions
);
441 intelInitBufferFuncs(functions
);
442 intelInitPixelFuncs(functions
);
447 intelInitContext(struct intel_context
*intel
,
448 const __GLcontextModes
* mesaVis
,
449 __DRIcontextPrivate
* driContextPriv
,
450 void *sharedContextPrivate
,
451 struct dd_function_table
*functions
)
453 GLcontext
*ctx
= &intel
->ctx
;
454 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
455 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
456 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
459 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
460 functions
, (void *) intel
)) {
461 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
465 driContextPriv
->driverPrivate
= intel
;
466 intel
->intelScreen
= intelScreen
;
467 intel
->driScreen
= sPriv
;
468 intel
->sarea
= intelScreen
->sarea
;
469 intel
->driContext
= driContextPriv
;
472 intel
->hHWContext
= driContextPriv
->hHWContext
;
473 intel
->driFd
= sPriv
->fd
;
474 intel
->driHwLock
= sPriv
->lock
;
476 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
477 intel
->driScreen
->myNum
,
478 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
479 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
480 intel
->maxBatchSize
= 4096;
482 intel
->maxBatchSize
= BATCH_SZ
;
484 intel
->bufmgr
= intelScreen
->bufmgr
;
485 intel
->ttm
= intelScreen
->ttm
;
489 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
490 switch (bo_reuse_mode
) {
491 case DRI_CONF_BO_REUSE_DISABLED
:
493 case DRI_CONF_BO_REUSE_ALL
:
494 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
499 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
501 /* This doesn't yet catch all non-conformant rendering, but it's a
504 if (getenv("INTEL_STRICT_CONFORMANCE")) {
505 intel
->strict_conformance
= 1;
508 if (intel
->strict_conformance
) {
509 ctx
->Const
.MinLineWidth
= 1.0;
510 ctx
->Const
.MinLineWidthAA
= 1.0;
511 ctx
->Const
.MaxLineWidth
= 1.0;
512 ctx
->Const
.MaxLineWidthAA
= 1.0;
513 ctx
->Const
.LineWidthGranularity
= 1.0;
516 ctx
->Const
.MinLineWidth
= 1.0;
517 ctx
->Const
.MinLineWidthAA
= 1.0;
518 ctx
->Const
.MaxLineWidth
= 5.0;
519 ctx
->Const
.MaxLineWidthAA
= 5.0;
520 ctx
->Const
.LineWidthGranularity
= 0.5;
523 ctx
->Const
.MinPointSize
= 1.0;
524 ctx
->Const
.MinPointSizeAA
= 1.0;
525 ctx
->Const
.MaxPointSize
= 255.0;
526 ctx
->Const
.MaxPointSizeAA
= 3.0;
527 ctx
->Const
.PointSizeGranularity
= 1.0;
529 /* reinitialize the context point state.
530 * It depend on constants in __GLcontextRec::Const
532 _mesa_init_point(ctx
);
534 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
536 /* Initialize the software rasterizer and helper modules. */
537 _swrast_CreateContext(ctx
);
538 _vbo_CreateContext(ctx
);
539 _tnl_CreateContext(ctx
);
540 _swsetup_CreateContext(ctx
);
542 /* Configure swrast to match hardware characteristics: */
543 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
544 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
546 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
547 intel
->hw_stipple
= 1;
549 /* XXX FBO: this doesn't seem to be used anywhere */
550 switch (mesaVis
->depthBits
) {
551 case 0: /* what to do in this case? */
553 intel
->polygon_offset_scale
= 1.0;
556 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
563 if (IS_965(intelScreen
->deviceID
))
564 intel
->polygon_offset_scale
/= 0xffff;
566 intel
->RenderIndex
= ~0;
568 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
569 intel
->irqsEmitted
= 0;
571 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
572 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
574 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
576 _math_matrix_ctr(&intel
->ViewportMatrix
);
578 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
579 _mesa_printf("IRQs not active. Exiting\n");
583 intelInitExtensions(ctx
, GL_FALSE
);
585 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
586 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
587 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
589 if (!sPriv
->dri2
.enabled
)
590 intel_recreate_static_regions(intel
);
592 intel
->batch
= intel_batchbuffer_alloc(intel
);
594 intel_bufferobj_init(intel
);
595 intel_fbo_init(intel
);
597 if (intel
->ctx
.Mesa_DXTn
) {
598 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
599 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
601 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
602 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
605 intel
->prim
.primitive
= ~0;
607 /* Force all software fallbacks */
608 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
609 fprintf(stderr
, "disabling 3D rasterization\n");
613 /* Disable all hardware rendering (skip emitting batches and fences/waits
616 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
622 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
624 struct intel_context
*intel
=
625 (struct intel_context
*) driContextPriv
->driverPrivate
;
627 assert(intel
); /* should never be null */
629 GLboolean release_texture_heaps
;
631 INTEL_FIREVERTICES(intel
);
633 intel
->vtbl
.destroy(intel
);
635 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
636 _swsetup_DestroyContext(&intel
->ctx
);
637 _tnl_DestroyContext(&intel
->ctx
);
638 _vbo_DestroyContext(&intel
->ctx
);
640 _swrast_DestroyContext(&intel
->ctx
);
641 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
643 intel_batchbuffer_free(intel
->batch
);
646 free(intel
->prim
.vb
);
647 intel
->prim
.vb
= NULL
;
648 dri_bo_unreference(intel
->prim
.vb_bo
);
649 intel
->prim
.vb_bo
= NULL
;
651 if (release_texture_heaps
) {
652 /* This share group is about to go away, free our private
653 * texture object data.
655 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
656 fprintf(stderr
, "do something to free texture heaps\n");
659 intel_region_release(&intel
->front_region
);
660 intel_region_release(&intel
->back_region
);
661 intel_region_release(&intel
->depth_region
);
663 driDestroyOptionCache(&intel
->optionCache
);
665 /* free the Mesa context */
666 _mesa_free_context_data(&intel
->ctx
);
671 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
677 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
678 __DRIdrawablePrivate
* driDrawPriv
,
679 __DRIdrawablePrivate
* driReadPriv
)
681 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
683 if (driContextPriv
) {
684 struct intel_context
*intel
=
685 (struct intel_context
*) driContextPriv
->driverPrivate
;
686 struct intel_framebuffer
*intel_fb
=
687 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
688 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
690 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
691 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
692 if (driDrawPriv
!= driReadPriv
)
693 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
695 /* XXX FBO temporary fix-ups! */
696 /* if the renderbuffers don't have regions, init them from the context */
697 struct intel_renderbuffer
*irbDepth
698 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
699 struct intel_renderbuffer
*irbStencil
700 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
702 if (intel_fb
->color_rb
[0]) {
703 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
704 intel
->front_region
);
706 if (intel_fb
->color_rb
[1]) {
707 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
712 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
715 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
719 /* set GLframebuffer size to match window, if needed */
720 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
722 if (driReadPriv
!= driDrawPriv
) {
723 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
726 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
728 /* The drawbuffer won't always be updated by _mesa_make_current:
730 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
732 if (intel
->driReadDrawable
!= driReadPriv
)
733 intel
->driReadDrawable
= driReadPriv
;
735 if (intel
->driDrawable
!= driDrawPriv
) {
736 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
739 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
740 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
741 : VBLANK_FLAG_NO_IRQ
;
743 /* Prevent error printf if one crtc is disabled, this will
744 * be properly calculated in intelWindowMoved() next.
746 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
748 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
749 driDrawableInitVBlank(driDrawPriv
);
750 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
752 for (i
= 0; i
< 2; i
++) {
753 if (intel_fb
->color_rb
[i
])
754 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
757 intel
->driDrawable
= driDrawPriv
;
758 intelWindowMoved(intel
);
761 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
765 _mesa_make_current(NULL
, NULL
, NULL
);
772 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
774 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
775 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
776 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
777 int me
= intel
->hHWContext
;
779 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
782 if (INTEL_DEBUG
& DEBUG_LOCK
)
783 _mesa_printf("%s - got contended lock\n", __progname
);
785 /* If the window moved, may need to set a new cliprect now.
787 * NOTE: This releases and regains the hw lock, so all state
788 * checking must be done *after* this call:
791 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
793 if (sarea
&& sarea
->ctxOwner
!= me
) {
794 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
795 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
796 sarea
->ctxOwner
, me
);
798 sarea
->ctxOwner
= me
;
801 /* If the last consumer of the texture memory wasn't us, notify the fake
802 * bufmgr and record the new owner. We should have the memory shared
803 * between contexts of a single fake bufmgr, but this will at least make
804 * things correct for now.
806 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
807 sarea
->texAge
= intel
->hHWContext
;
808 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
809 if (INTEL_DEBUG
& DEBUG_BATCH
)
810 intel_decode_context_reset();
811 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
812 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
813 sarea
->ctxOwner
, intel
->hHWContext
);
818 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
819 intelWindowMoved(intel
);
820 intel
->lastStamp
= dPriv
->lastStamp
;
825 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
827 /* Lock the hardware and validate our state.
829 void LOCK_HARDWARE( struct intel_context
*intel
)
831 __DRIdrawable
*dPriv
= intel
->driDrawable
;
832 __DRIscreen
*sPriv
= intel
->driScreen
;
834 struct intel_framebuffer
*intel_fb
= NULL
;
835 struct intel_renderbuffer
*intel_rb
= NULL
;
837 _glthread_LOCK_MUTEX(lockMutex
);
838 assert(!intel
->locked
);
841 if (intel
->driDrawable
) {
842 intel_fb
= intel
->driDrawable
->driverPrivate
;
846 intel_get_renderbuffer(&intel_fb
->Base
,
847 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
850 if (intel_rb
&& dPriv
->vblFlags
&&
851 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
852 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
855 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
857 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
858 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
861 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
862 drmWaitVBlank(intel
->driFd
, &vbl
);
863 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
866 if (!sPriv
->dri2
.enabled
) {
867 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
868 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
871 intelContendedLock( intel
, 0 );
875 if (INTEL_DEBUG
& DEBUG_LOCK
)
876 _mesa_printf("%s - locked\n", __progname
);
880 /* Unlock the hardware using the global current context
882 void UNLOCK_HARDWARE( struct intel_context
*intel
)
884 __DRIscreen
*sPriv
= intel
->driScreen
;
886 intel
->vtbl
.note_unlock( intel
);
889 if (!sPriv
->dri2
.enabled
)
890 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
892 _glthread_UNLOCK_MUTEX(lockMutex
);
894 if (INTEL_DEBUG
& DEBUG_LOCK
)
895 _mesa_printf("%s - unlocked\n", __progname
);
898 * Nothing should be left in batch outside of LOCK/UNLOCK which references
901 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
902 intel_batchbuffer_flush(intel
->batch
);