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_FAKE_FRONT_LEFT
:
239 rb
= intel_fb
->color_rb
[0];
240 region_name
= "dri2 fake front buffer";
243 case __DRI_BUFFER_BACK_LEFT
:
244 rb
= intel_fb
->color_rb
[1];
245 region_name
= "dri2 back buffer";
248 case __DRI_BUFFER_DEPTH
:
249 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
250 region_name
= "dri2 depth buffer";
253 case __DRI_BUFFER_STENCIL
:
254 rb
= intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
255 region_name
= "dri2 stencil buffer";
258 case __DRI_BUFFER_ACCUM
:
261 "unhandled buffer attach event, attacment type %d\n",
262 buffers
[i
].attachment
);
270 dri_bo_flink(rb
->region
->buffer
, &name
);
271 if (name
== buffers
[i
].name
)
275 if (INTEL_DEBUG
& DEBUG_DRI
)
277 "attaching buffer %d, at %d, cpp %d, pitch %d\n",
278 buffers
[i
].name
, buffers
[i
].attachment
,
279 buffers
[i
].cpp
, buffers
[i
].pitch
);
281 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_region
) {
282 if (INTEL_DEBUG
& DEBUG_DRI
)
283 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
284 intel_region_reference(®ion
, depth_region
);
287 region
= intel_region_alloc_for_handle(intel
, buffers
[i
].cpp
,
290 buffers
[i
].pitch
/ buffers
[i
].cpp
,
294 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
)
295 depth_region
= region
;
297 intel_renderbuffer_set_region(rb
, region
);
298 intel_region_release(®ion
);
301 driUpdateFramebufferSize(&intel
->ctx
, drawable
);
305 intel_viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
307 struct intel_context
*intel
= intel_context(ctx
);
308 __DRIcontext
*driContext
= intel
->driContext
;
309 void (*old_viewport
)(GLcontext
*ctx
, GLint x
, GLint y
,
310 GLsizei w
, GLsizei h
);
312 if (!driContext
->driScreenPriv
->dri2
.enabled
)
315 if (!intel
->internal_viewport_call
) {
316 intel_update_renderbuffers(driContext
, driContext
->driDrawablePriv
);
317 if (driContext
->driDrawablePriv
!= driContext
->driReadablePriv
)
318 intel_update_renderbuffers(driContext
, driContext
->driReadablePriv
);
321 old_viewport
= ctx
->Driver
.Viewport
;
322 ctx
->Driver
.Viewport
= NULL
;
323 intel
->driDrawable
= driContext
->driDrawablePriv
;
324 intelWindowMoved(intel
);
325 intel_draw_buffer(ctx
, intel
->ctx
.DrawBuffer
);
326 ctx
->Driver
.Viewport
= old_viewport
;
330 static const struct dri_debug_control debug_control
[] = {
331 { "tex", DEBUG_TEXTURE
},
332 { "state", DEBUG_STATE
},
333 { "ioctl", DEBUG_IOCTL
},
334 { "blit", DEBUG_BLIT
},
335 { "mip", DEBUG_MIPTREE
},
336 { "fall", DEBUG_FALLBACKS
},
337 { "verb", DEBUG_VERBOSE
},
338 { "bat", DEBUG_BATCH
},
339 { "pix", DEBUG_PIXEL
},
340 { "buf", DEBUG_BUFMGR
},
341 { "reg", DEBUG_REGION
},
343 { "lock", DEBUG_LOCK
},
344 { "sync", DEBUG_SYNC
},
345 { "prim", DEBUG_PRIMS
},
346 { "vert", DEBUG_VERTS
},
347 { "dri", DEBUG_DRI
},
348 { "dma", DEBUG_DMA
},
349 { "san", DEBUG_SANITY
},
350 { "sleep", DEBUG_SLEEP
},
351 { "stats", DEBUG_STATS
},
352 { "tile", DEBUG_TILE
},
353 { "sing", DEBUG_SINGLE_THREAD
},
354 { "thre", DEBUG_SINGLE_THREAD
},
356 { "urb", DEBUG_URB
},
363 intelInvalidateState(GLcontext
* ctx
, GLuint new_state
)
365 struct intel_context
*intel
= intel_context(ctx
);
367 _swrast_InvalidateState(ctx
, new_state
);
368 _swsetup_InvalidateState(ctx
, new_state
);
369 _vbo_InvalidateState(ctx
, new_state
);
370 _tnl_InvalidateState(ctx
, new_state
);
371 _tnl_invalidate_vertex_state(ctx
, new_state
);
373 intel
->NewGLState
|= new_state
;
375 if (intel
->vtbl
.invalidate_state
)
376 intel
->vtbl
.invalidate_state( intel
, new_state
);
380 intel_flush(GLcontext
*ctx
, GLboolean needs_mi_flush
)
382 struct intel_context
*intel
= intel_context(ctx
);
387 if (!IS_965(intel
->intelScreen
->deviceID
))
388 INTEL_FIREVERTICES(intel
);
390 /* Emit a flush so that any frontbuffer rendering that might have occurred
391 * lands onscreen in a timely manner, even if the X Server doesn't trigger
395 intel_batchbuffer_emit_mi_flush(intel
->batch
);
397 if (intel
->batch
->map
!= intel
->batch
->ptr
)
398 intel_batchbuffer_flush(intel
->batch
);
400 if ((ctx
->DrawBuffer
->Name
== 0) && intel
->front_buffer_dirty
) {
401 __DRIscreen
*const screen
= intel
->intelScreen
->driScrnPriv
;
403 if (screen
->dri2
.loader
&&
404 (screen
->dri2
.loader
->base
.version
>= 2)
405 && (screen
->dri2
.loader
->flushFrontBuffer
!= NULL
)) {
406 (*screen
->dri2
.loader
->flushFrontBuffer
)(intel
->driDrawable
,
407 intel
->driDrawable
->loaderPrivate
);
409 /* Only clear the dirty bit if front-buffer rendering is no longer
410 * enabled. This is done so that the dirty bit can only be set in
411 * glDrawBuffer. Otherwise the dirty bit would have to be set at
412 * each of N places that do rendering. This has worse performances,
413 * but it is much easier to get correct.
415 if (intel
->is_front_buffer_rendering
) {
416 intel
->front_buffer_dirty
= GL_FALSE
;
423 intelFlush(GLcontext
* ctx
)
425 intel_flush(ctx
, GL_FALSE
);
429 intel_glFlush(GLcontext
*ctx
)
431 intel_flush(ctx
, GL_TRUE
);
435 intelFinish(GLcontext
* ctx
)
437 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
442 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
443 struct intel_renderbuffer
*irb
;
445 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
448 dri_bo_wait_rendering(irb
->region
->buffer
);
450 if (fb
->_DepthBuffer
) {
451 /* XXX: Wait on buffer idle */
456 intelInitDriverFunctions(struct dd_function_table
*functions
)
458 _mesa_init_driver_functions(functions
);
460 functions
->Flush
= intel_glFlush
;
461 functions
->Finish
= intelFinish
;
462 functions
->GetString
= intelGetString
;
463 functions
->UpdateState
= intelInvalidateState
;
465 functions
->CopyColorTable
= _swrast_CopyColorTable
;
466 functions
->CopyColorSubTable
= _swrast_CopyColorSubTable
;
467 functions
->CopyConvolutionFilter1D
= _swrast_CopyConvolutionFilter1D
;
468 functions
->CopyConvolutionFilter2D
= _swrast_CopyConvolutionFilter2D
;
470 intelInitTextureFuncs(functions
);
471 intelInitStateFuncs(functions
);
472 intelInitClearFuncs(functions
);
473 intelInitBufferFuncs(functions
);
474 intelInitPixelFuncs(functions
);
479 intelInitContext(struct intel_context
*intel
,
480 const __GLcontextModes
* mesaVis
,
481 __DRIcontextPrivate
* driContextPriv
,
482 void *sharedContextPrivate
,
483 struct dd_function_table
*functions
)
485 GLcontext
*ctx
= &intel
->ctx
;
486 GLcontext
*shareCtx
= (GLcontext
*) sharedContextPrivate
;
487 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
488 intelScreenPrivate
*intelScreen
= (intelScreenPrivate
*) sPriv
->private;
491 if (!_mesa_initialize_context(&intel
->ctx
, mesaVis
, shareCtx
,
492 functions
, (void *) intel
)) {
493 _mesa_printf("%s: failed to init mesa context\n", __FUNCTION__
);
497 driContextPriv
->driverPrivate
= intel
;
498 intel
->intelScreen
= intelScreen
;
499 intel
->driScreen
= sPriv
;
500 intel
->sarea
= intelScreen
->sarea
;
501 intel
->driContext
= driContextPriv
;
504 intel
->hHWContext
= driContextPriv
->hHWContext
;
505 intel
->driFd
= sPriv
->fd
;
506 intel
->driHwLock
= sPriv
->lock
;
508 driParseConfigFiles(&intel
->optionCache
, &intelScreen
->optionCache
,
509 intel
->driScreen
->myNum
,
510 IS_965(intelScreen
->deviceID
) ? "i965" : "i915");
511 if (intelScreen
->deviceID
== PCI_CHIP_I865_G
)
512 intel
->maxBatchSize
= 4096;
514 intel
->maxBatchSize
= BATCH_SZ
;
516 intel
->bufmgr
= intelScreen
->bufmgr
;
517 intel
->ttm
= intelScreen
->ttm
;
521 bo_reuse_mode
= driQueryOptioni(&intel
->optionCache
, "bo_reuse");
522 switch (bo_reuse_mode
) {
523 case DRI_CONF_BO_REUSE_DISABLED
:
525 case DRI_CONF_BO_REUSE_ALL
:
526 intel_bufmgr_gem_enable_reuse(intel
->bufmgr
);
531 ctx
->Const
.MaxTextureMaxAnisotropy
= 2.0;
533 /* This doesn't yet catch all non-conformant rendering, but it's a
536 if (getenv("INTEL_STRICT_CONFORMANCE")) {
537 unsigned int value
= atoi(getenv("INTEL_STRICT_CONFORMANCE"));
539 intel
->conformance_mode
= value
;
542 intel
->conformance_mode
= 1;
546 if (intel
->conformance_mode
> 0) {
547 ctx
->Const
.MinLineWidth
= 1.0;
548 ctx
->Const
.MinLineWidthAA
= 1.0;
549 ctx
->Const
.MaxLineWidth
= 1.0;
550 ctx
->Const
.MaxLineWidthAA
= 1.0;
551 ctx
->Const
.LineWidthGranularity
= 1.0;
554 ctx
->Const
.MinLineWidth
= 1.0;
555 ctx
->Const
.MinLineWidthAA
= 1.0;
556 ctx
->Const
.MaxLineWidth
= 5.0;
557 ctx
->Const
.MaxLineWidthAA
= 5.0;
558 ctx
->Const
.LineWidthGranularity
= 0.5;
561 ctx
->Const
.MinPointSize
= 1.0;
562 ctx
->Const
.MinPointSizeAA
= 1.0;
563 ctx
->Const
.MaxPointSize
= 255.0;
564 ctx
->Const
.MaxPointSizeAA
= 3.0;
565 ctx
->Const
.PointSizeGranularity
= 1.0;
567 /* reinitialize the context point state.
568 * It depend on constants in __GLcontextRec::Const
570 _mesa_init_point(ctx
);
572 ctx
->Const
.MaxColorAttachments
= 4; /* XXX FBO: review this */
574 /* Initialize the software rasterizer and helper modules. */
575 _swrast_CreateContext(ctx
);
576 _vbo_CreateContext(ctx
);
577 _tnl_CreateContext(ctx
);
578 _swsetup_CreateContext(ctx
);
580 /* Configure swrast to match hardware characteristics: */
581 _swrast_allow_pixel_fog(ctx
, GL_FALSE
);
582 _swrast_allow_vertex_fog(ctx
, GL_TRUE
);
584 intel
->hw_stencil
= mesaVis
->stencilBits
&& mesaVis
->depthBits
== 24;
585 intel
->hw_stipple
= 1;
587 /* XXX FBO: this doesn't seem to be used anywhere */
588 switch (mesaVis
->depthBits
) {
589 case 0: /* what to do in this case? */
591 intel
->polygon_offset_scale
= 1.0;
594 intel
->polygon_offset_scale
= 2.0; /* req'd to pass glean */
601 if (IS_965(intelScreen
->deviceID
))
602 intel
->polygon_offset_scale
/= 0xffff;
604 intel
->RenderIndex
= ~0;
606 fthrottle_mode
= driQueryOptioni(&intel
->optionCache
, "fthrottle_mode");
607 intel
->irqsEmitted
= 0;
609 intel
->do_irqs
= (intel
->intelScreen
->irq_active
&&
610 fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
);
612 intel
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
614 if (IS_965(intelScreen
->deviceID
) && !intel
->intelScreen
->irq_active
) {
615 _mesa_printf("IRQs not active. Exiting\n");
619 intelInitExtensions(ctx
, GL_FALSE
);
621 INTEL_DEBUG
= driParseDebugString(getenv("INTEL_DEBUG"), debug_control
);
622 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
623 dri_bufmgr_set_debug(intel
->bufmgr
, GL_TRUE
);
625 if (!sPriv
->dri2
.enabled
)
626 intel_recreate_static_regions(intel
);
628 intel
->batch
= intel_batchbuffer_alloc(intel
);
630 intel_bufferobj_init(intel
);
631 intel_fbo_init(intel
);
633 if (intel
->ctx
.Mesa_DXTn
) {
634 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
635 _mesa_enable_extension(ctx
, "GL_S3_s3tc");
637 else if (driQueryOptionb(&intel
->optionCache
, "force_s3tc_enable")) {
638 _mesa_enable_extension(ctx
, "GL_EXT_texture_compression_s3tc");
641 intel
->prim
.primitive
= ~0;
643 /* Force all software fallbacks */
644 if (driQueryOptionb(&intel
->optionCache
, "no_rast")) {
645 fprintf(stderr
, "disabling 3D rasterization\n");
649 if (driQueryOptionb(&intel
->optionCache
, "always_flush_batch")) {
650 fprintf(stderr
, "flushing batchbuffer before/after each draw call\n");
651 intel
->always_flush_batch
= 1;
654 if (driQueryOptionb(&intel
->optionCache
, "always_flush_cache")) {
655 fprintf(stderr
, "flushing GPU caches before/after each draw call\n");
656 intel
->always_flush_cache
= 1;
659 /* Disable all hardware rendering (skip emitting batches and fences/waits
662 intel
->no_hw
= getenv("INTEL_NO_HW") != NULL
;
668 intelDestroyContext(__DRIcontextPrivate
* driContextPriv
)
670 struct intel_context
*intel
=
671 (struct intel_context
*) driContextPriv
->driverPrivate
;
673 assert(intel
); /* should never be null */
675 GLboolean release_texture_heaps
;
677 INTEL_FIREVERTICES(intel
);
679 intel
->vtbl
.destroy(intel
);
681 release_texture_heaps
= (intel
->ctx
.Shared
->RefCount
== 1);
682 _swsetup_DestroyContext(&intel
->ctx
);
683 _tnl_DestroyContext(&intel
->ctx
);
684 _vbo_DestroyContext(&intel
->ctx
);
686 _swrast_DestroyContext(&intel
->ctx
);
687 intel
->Fallback
= 0; /* don't call _swrast_Flush later */
689 intel_batchbuffer_free(intel
->batch
);
692 free(intel
->prim
.vb
);
693 intel
->prim
.vb
= NULL
;
694 dri_bo_unreference(intel
->prim
.vb_bo
);
695 intel
->prim
.vb_bo
= NULL
;
697 if (release_texture_heaps
) {
698 /* This share group is about to go away, free our private
699 * texture object data.
701 if (INTEL_DEBUG
& DEBUG_TEXTURE
)
702 fprintf(stderr
, "do something to free texture heaps\n");
705 intel_region_release(&intel
->front_region
);
706 intel_region_release(&intel
->back_region
);
707 intel_region_release(&intel
->depth_region
);
709 driDestroyOptionCache(&intel
->optionCache
);
711 /* free the Mesa context */
712 _mesa_free_context_data(&intel
->ctx
);
717 intelUnbindContext(__DRIcontextPrivate
* driContextPriv
)
723 intelMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
724 __DRIdrawablePrivate
* driDrawPriv
,
725 __DRIdrawablePrivate
* driReadPriv
)
727 __DRIscreenPrivate
*psp
= driDrawPriv
->driScreenPriv
;
729 if (driContextPriv
) {
730 struct intel_context
*intel
=
731 (struct intel_context
*) driContextPriv
->driverPrivate
;
732 struct intel_framebuffer
*intel_fb
=
733 (struct intel_framebuffer
*) driDrawPriv
->driverPrivate
;
734 GLframebuffer
*readFb
= (GLframebuffer
*) driReadPriv
->driverPrivate
;
736 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
737 intel_update_renderbuffers(driContextPriv
, driDrawPriv
);
738 if (driDrawPriv
!= driReadPriv
)
739 intel_update_renderbuffers(driContextPriv
, driReadPriv
);
741 /* XXX FBO temporary fix-ups! */
742 /* if the renderbuffers don't have regions, init them from the context */
743 struct intel_renderbuffer
*irbDepth
744 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_DEPTH
);
745 struct intel_renderbuffer
*irbStencil
746 = intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_STENCIL
);
748 if (intel_fb
->color_rb
[0]) {
749 intel_renderbuffer_set_region(intel_fb
->color_rb
[0],
750 intel
->front_region
);
752 if (intel_fb
->color_rb
[1]) {
753 intel_renderbuffer_set_region(intel_fb
->color_rb
[1],
758 intel_renderbuffer_set_region(irbDepth
, intel
->depth_region
);
761 intel_renderbuffer_set_region(irbStencil
, intel
->depth_region
);
765 /* set GLframebuffer size to match window, if needed */
766 driUpdateFramebufferSize(&intel
->ctx
, driDrawPriv
);
768 if (driReadPriv
!= driDrawPriv
) {
769 driUpdateFramebufferSize(&intel
->ctx
, driReadPriv
);
772 _mesa_make_current(&intel
->ctx
, &intel_fb
->Base
, readFb
);
774 /* The drawbuffer won't always be updated by _mesa_make_current:
776 if (intel
->ctx
.DrawBuffer
== &intel_fb
->Base
) {
778 if (intel
->driReadDrawable
!= driReadPriv
)
779 intel
->driReadDrawable
= driReadPriv
;
781 if (intel
->driDrawable
!= driDrawPriv
) {
782 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
785 driDrawPriv
->vblFlags
= (intel
->intelScreen
->irq_active
!= 0)
786 ? driGetDefaultVBlankFlags(&intel
->optionCache
)
787 : VBLANK_FLAG_NO_IRQ
;
789 /* Prevent error printf if one crtc is disabled, this will
790 * be properly calculated in intelWindowMoved() next.
792 driDrawPriv
->vblFlags
= intelFixupVblank(intel
, driDrawPriv
);
794 (*psp
->systemTime
->getUST
) (&intel_fb
->swap_ust
);
795 driDrawableInitVBlank(driDrawPriv
);
796 intel_fb
->vbl_waited
= driDrawPriv
->vblSeq
;
798 for (i
= 0; i
< 2; i
++) {
799 if (intel_fb
->color_rb
[i
])
800 intel_fb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
803 intel
->driDrawable
= driDrawPriv
;
804 intelWindowMoved(intel
);
807 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
811 _mesa_make_current(NULL
, NULL
, NULL
);
818 intelContendedLock(struct intel_context
*intel
, GLuint flags
)
820 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
821 __DRIscreenPrivate
*sPriv
= intel
->driScreen
;
822 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
823 int me
= intel
->hHWContext
;
825 drmGetLock(intel
->driFd
, intel
->hHWContext
, flags
);
828 if (INTEL_DEBUG
& DEBUG_LOCK
)
829 _mesa_printf("%s - got contended lock\n", __progname
);
831 /* If the window moved, may need to set a new cliprect now.
833 * NOTE: This releases and regains the hw lock, so all state
834 * checking must be done *after* this call:
837 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);
839 if (sarea
&& sarea
->ctxOwner
!= me
) {
840 if (INTEL_DEBUG
& DEBUG_BUFMGR
) {
841 fprintf(stderr
, "Lost Context: sarea->ctxOwner %x me %x\n",
842 sarea
->ctxOwner
, me
);
844 sarea
->ctxOwner
= me
;
847 /* If the last consumer of the texture memory wasn't us, notify the fake
848 * bufmgr and record the new owner. We should have the memory shared
849 * between contexts of a single fake bufmgr, but this will at least make
850 * things correct for now.
852 if (!intel
->ttm
&& sarea
->texAge
!= intel
->hHWContext
) {
853 sarea
->texAge
= intel
->hHWContext
;
854 intel_bufmgr_fake_contended_lock_take(intel
->bufmgr
);
855 if (INTEL_DEBUG
& DEBUG_BATCH
)
856 intel_decode_context_reset();
857 if (INTEL_DEBUG
& DEBUG_BUFMGR
)
858 fprintf(stderr
, "Lost Textures: sarea->texAge %x hw context %x\n",
859 sarea
->ctxOwner
, intel
->hHWContext
);
864 if (dPriv
&& intel
->lastStamp
!= dPriv
->lastStamp
) {
865 intelWindowMoved(intel
);
866 intel
->lastStamp
= dPriv
->lastStamp
;
871 _glthread_DECLARE_STATIC_MUTEX(lockMutex
);
873 /* Lock the hardware and validate our state.
875 void LOCK_HARDWARE( struct intel_context
*intel
)
877 __DRIdrawable
*dPriv
= intel
->driDrawable
;
878 __DRIscreen
*sPriv
= intel
->driScreen
;
880 struct intel_framebuffer
*intel_fb
= NULL
;
881 struct intel_renderbuffer
*intel_rb
= NULL
;
883 _glthread_LOCK_MUTEX(lockMutex
);
884 assert(!intel
->locked
);
887 if (intel
->driDrawable
) {
888 intel_fb
= intel
->driDrawable
->driverPrivate
;
892 intel_get_renderbuffer(&intel_fb
->Base
,
893 intel_fb
->Base
._ColorDrawBufferIndexes
[0]);
896 if (intel_rb
&& dPriv
->vblFlags
&&
897 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
) &&
898 (intel_fb
->vbl_waited
- intel_rb
->vbl_pending
) > (1<<23)) {
901 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
903 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
904 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
907 vbl
.request
.sequence
= intel_rb
->vbl_pending
;
908 drmWaitVBlank(intel
->driFd
, &vbl
);
909 intel_fb
->vbl_waited
= vbl
.reply
.sequence
;
912 if (!sPriv
->dri2
.enabled
) {
913 DRM_CAS(intel
->driHwLock
, intel
->hHWContext
,
914 (DRM_LOCK_HELD
|intel
->hHWContext
), __ret
);
917 intelContendedLock( intel
, 0 );
921 if (INTEL_DEBUG
& DEBUG_LOCK
)
922 _mesa_printf("%s - locked\n", __progname
);
926 /* Unlock the hardware using the global current context
928 void UNLOCK_HARDWARE( struct intel_context
*intel
)
930 __DRIscreen
*sPriv
= intel
->driScreen
;
932 intel
->vtbl
.note_unlock( intel
);
935 if (!sPriv
->dri2
.enabled
)
936 DRM_UNLOCK(intel
->driFd
, intel
->driHwLock
, intel
->hHWContext
);
938 _glthread_UNLOCK_MUTEX(lockMutex
);
940 if (INTEL_DEBUG
& DEBUG_LOCK
)
941 _mesa_printf("%s - unlocked\n", __progname
);
944 * Nothing should be left in batch outside of LOCK/UNLOCK which references
947 if (intel
->batch
->cliprect_mode
== REFERENCES_CLIPRECTS
)
948 intel_batchbuffer_flush(intel
->batch
);