? src/mesa/drivers/dri/i915/depend Index: src/mesa/drivers/dri/i915/intel_batchbuffer.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_batchbuffer.c,v retrieving revision 1.4 diff -u -u -r1.4 intel_batchbuffer.c --- src/mesa/drivers/dri/i915/intel_batchbuffer.c 10 Sep 2005 00:10:15 -0000 1.4 +++ src/mesa/drivers/dri/i915/intel_batchbuffer.c 17 Dec 2005 00:16:48 -0000 @@ -32,6 +32,7 @@ #include "mtypes.h" #include "context.h" #include "enums.h" +#include "vblank.h" #include "intel_reg.h" #include "intel_batchbuffer.h" @@ -314,6 +315,38 @@ } +static void intelWaitForFrameCompletion( intelContextPtr intel ) +{ + drm_i915_sarea_t *sarea = (drm_i915_sarea_t *)intel->sarea; + + if (intel->do_irqs) { + if (intelGetLastFrame(intel) < sarea->last_dispatch) { + if (!intel->irqsEmitted) { + while (intelGetLastFrame (intel) < sarea->last_dispatch) + ; + } + else { + UNLOCK_HARDWARE( intel ); + intelWaitIrq( intel, intel->alloc.irq_emitted ); + LOCK_HARDWARE( intel ); + } + intel->irqsEmitted = 10; + } + + if (intel->irqsEmitted) { + intelEmitIrqLocked( intel ); + intel->irqsEmitted--; + } + } + else { + while (intelGetLastFrame (intel) < sarea->last_dispatch) { + UNLOCK_HARDWARE( intel ); + if (intel->do_usleeps) + DO_USLEEP( 1 ); + LOCK_HARDWARE( intel ); + } + } +} /* * Copy the back buffer to the front buffer. @@ -321,6 +354,8 @@ void intelCopyBuffer( const __DRIdrawablePrivate *dPriv ) { intelContextPtr intel; + GLboolean missed_target; + int64_t ust; if (0) fprintf(stderr, "%s\n", __FUNCTION__); @@ -332,6 +367,12 @@ intel = (intelContextPtr) dPriv->driContextPriv->driverPrivate; intelFlush( &intel->ctx ); + + LOCK_HARDWARE( intel ); + intelWaitForFrameCompletion( intel ); + UNLOCK_HARDWARE( intel ); + driWaitForVBlank( dPriv, &intel->vbl_seq, intel->vblank_flags, & missed_target ); + LOCK_HARDWARE( intel ); { intelScreenPrivate *intelScreen = intel->intelScreen; @@ -395,6 +436,15 @@ } intelFlushBatchLocked( intel, GL_TRUE, GL_TRUE, GL_TRUE ); UNLOCK_HARDWARE( intel ); + + intel->swap_count++; + (*dri_interface->getUST)(&ust); + if (missed_target) { + intel->swap_missed_count++; + intel->swap_missed_ust = ust - intel->swap_ust; + } + + intel->swap_ust = ust; } Index: src/mesa/drivers/dri/i915/intel_context.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_context.c,v retrieving revision 1.19 diff -u -u -r1.19 intel_context.c --- src/mesa/drivers/dri/i915/intel_context.c 13 Sep 2005 04:42:10 -0000 1.19 +++ src/mesa/drivers/dri/i915/intel_context.c 17 Dec 2005 00:16:49 -0000 @@ -55,7 +55,9 @@ #include "intel_ioctl.h" #include "intel_batchbuffer.h" +#include "vblank.h" #include "utils.h" +#include "xmlpool.h" /* for symbolic values of enum-type options */ #ifndef INTEL_DEBUG int INTEL_DEBUG = (0); #endif @@ -281,6 +283,7 @@ intelScreenPrivate *intelScreen = (intelScreenPrivate *)sPriv->private; drmI830Sarea *saPriv = (drmI830Sarea *) (((GLubyte *)sPriv->pSAREA)+intelScreen->sarea_priv_offset); + int fthrottle_mode; if (!_mesa_initialize_context(&intel->ctx, mesaVis, shareCtx, @@ -297,6 +300,9 @@ (void) memset( intel->texture_heaps, 0, sizeof( intel->texture_heaps ) ); make_empty_list( & intel->swapped ); + driParseConfigFiles (&intel->optionCache, &intelScreen->optionCache, + intel->driScreen->myNum, "i915"); + ctx->Const.MaxTextureMaxAnisotropy = 2.0; ctx->Const.MinLineWidth = 1.0; @@ -360,9 +366,19 @@ intel->RenderIndex = ~0; + fthrottle_mode = driQueryOptioni(&intel->optionCache, "fthrottle_mode"); + intel->iw.irq_seq = -1; + intel->irqsEmitted = 0; + intel->do_irqs = (intel->intelScreen->irq_active && - !getenv("INTEL_NO_IRQS")); + fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS); + + intel->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS); + + intel->vblank_flags = (intel->intelScreen->irq_active != 0) + ? driGetDefaultVBlankFlags(&intelScreen->optionCache) : VBLANK_FLAG_NO_IRQ; + (*dri_interface->getUST)(&intel->swap_ust); _math_matrix_ctr (&intel->ViewportMatrix); driInitExtensions( ctx, card_extensions, GL_TRUE ); @@ -545,6 +561,8 @@ if ( intel->driDrawable != driDrawPriv ) { /* Shouldn't the readbuffer be stored also? */ + driDrawableInitVBlank( driDrawPriv, intel->vblank_flags ); + intel->driDrawable = driDrawPriv; intelWindowMoved( intel ); } @@ -719,3 +737,5 @@ ctx->Driver.DrawBuffer( ctx, ctx->Color.DrawBuffer[0] ); } + + Index: src/mesa/drivers/dri/i915/intel_context.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_context.h,v retrieving revision 1.8 diff -u -u -r1.8 intel_context.h --- src/mesa/drivers/dri/i915/intel_context.h 3 Sep 2005 16:54:20 -0000 1.8 +++ src/mesa/drivers/dri/i915/intel_context.h 17 Dec 2005 00:16:49 -0000 @@ -36,6 +36,7 @@ #include "texmem.h" #include "intel_screen.h" +#include "i915_drm.h" #include "i830_common.h" #include "tnl/t_vertex.h" @@ -214,7 +215,11 @@ int dirtyAge; int perf_boxes; + + GLuint do_usleeps; int do_irqs; + GLuint irqsEmitted; + drm_i915_irq_wait_t iw; GLboolean scissor; drm_clip_rect_t draw_rect; @@ -233,6 +238,17 @@ * Configuration cache */ driOptionCache optionCache; + + /* VBI + */ + GLuint vbl_seq; + GLuint vblank_flags; + + int64_t swap_ust; + int64_t swap_missed_ust; + + GLuint swap_count; + GLuint swap_missed_count; }; Index: src/mesa/drivers/dri/i915/intel_ioctl.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_ioctl.c,v retrieving revision 1.10 diff -u -u -r1.10 intel_ioctl.c --- src/mesa/drivers/dri/i915/intel_ioctl.c 10 Sep 2005 00:10:15 -0000 1.10 +++ src/mesa/drivers/dri/i915/intel_ioctl.c 17 Dec 2005 00:16:49 -0000 @@ -40,9 +40,20 @@ #include "intel_batchbuffer.h" #include "drm.h" +u_int32_t intelGetLastFrame (intelContextPtr intel) +{ + int ret; + u_int32_t frame; + drm_i915_getparam_t gp; + + gp.param = I915_PARAM_LAST_DISPATCH; + gp.value = (int *)&frame; + ret = drmCommandWriteRead( intel->driFd, DRM_I915_GETPARAM, + &gp, sizeof(gp) ); + return frame; +} - -static int intelEmitIrqLocked( intelContextPtr intel ) +int intelEmitIrqLocked( intelContextPtr intel ) { drmI830IrqEmit ie; int ret, seq = 0; @@ -65,18 +76,17 @@ return seq; } -static void intelWaitIrq( intelContextPtr intel, int seq ) +void intelWaitIrq( intelContextPtr intel, int seq ) { - drmI830IrqWait iw; int ret; if (0) fprintf(stderr, "%s %d\n", __FUNCTION__, seq ); - iw.irq_seq = seq; + intel->iw.irq_seq = seq; do { - ret = drmCommandWrite( intel->driFd, DRM_I830_IRQ_WAIT, &iw, sizeof(iw) ); + ret = drmCommandWrite( intel->driFd, DRM_I830_IRQ_WAIT, &intel->iw, sizeof(intel->iw) ); } while (ret == -EAGAIN || ret == -EINTR); if ( ret ) { Index: src/mesa/drivers/dri/i915/intel_ioctl.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_ioctl.h,v retrieving revision 1.2 diff -u -u -r1.2 intel_ioctl.h --- src/mesa/drivers/dri/i915/intel_ioctl.h 18 Jun 2004 10:54:48 -0000 1.2 +++ src/mesa/drivers/dri/i915/intel_ioctl.h 17 Dec 2005 00:16:49 -0000 @@ -62,5 +62,7 @@ extern GLuint intelAgpOffsetFromVirtual( intelContextPtr intel, const GLvoid *p ); - +extern void intelWaitIrq( intelContextPtr intel, int seq ); +extern u_int32_t intelGetLastFrame (intelContextPtr intel); +extern int intelEmitIrqLocked( intelContextPtr intel ); #endif Index: src/mesa/drivers/dri/i915/intel_screen.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/i915/intel_screen.c,v retrieving revision 1.29 diff -u -u -r1.29 intel_screen.c --- src/mesa/drivers/dri/i915/intel_screen.c 10 Sep 2005 00:10:15 -0000 1.29 +++ src/mesa/drivers/dri/i915/intel_screen.c 17 Dec 2005 00:16:49 -0000 @@ -32,6 +32,7 @@ #include "renderbuffer.h" #include "simple_list.h" #include "utils.h" +#include "vblank.h" #include "xmlpool.h" @@ -49,10 +50,14 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE - DRI_CONF_FORCE_S3TC_ENABLE(false) + DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) + DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) DRI_CONF_SECTION_END + DRI_CONF_SECTION_QUALITY + DRI_CONF_FORCE_S3TC_ENABLE(false) + DRI_CONF_SECTION_END DRI_CONF_END; -const GLuint __driNConfigOptions = 1; +const GLuint __driNConfigOptions = 3; extern const struct dri_extension card_extensions[]; @@ -201,6 +206,10 @@ } if (glx_enable_extension != NULL) { + (*glx_enable_extension)( psc, "GLX_SGI_swap_control" ); + (*glx_enable_extension)( psc, "GLX_SGI_video_sync" ); + (*glx_enable_extension)( psc, "GLX_MESA_swap_control" ); + (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" ); (*glx_enable_extension)( psc, "GLX_SGI_make_current_read" ); (*glx_enable_extension)( psc, "GLX_MESA_allocate_memory" ); } @@ -315,6 +324,33 @@ } +/** + * Get information about previous buffer swaps. + */ +static int +intelGetSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo ) +{ + intelContextPtr intel; + + if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL) + || (dPriv->driContextPriv->driverPrivate == NULL) + || (sInfo == NULL) ) { + return -1; + } + + intel = dPriv->driContextPriv->driverPrivate; + sInfo->swap_count = intel->swap_count; + sInfo->swap_ust = intel->swap_ust; + sInfo->swap_missed_count = intel->swap_missed_count; + + sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0) + ? driCalculateSwapUsage( dPriv, 0, intel->swap_missed_ust ) + : 0.0; + + return 0; +} + + /* There are probably better ways to do this, such as an * init-designated function to register chipids and createcontext * functions. @@ -368,9 +404,9 @@ .SwapBuffers = intelSwapBuffers, .MakeCurrent = intelMakeCurrent, .UnbindContext = intelUnbindContext, - .GetSwapInfo = NULL, - .GetMSC = NULL, - .WaitForMSC = NULL, + .GetSwapInfo = intelGetSwapInfo, + .GetMSC = driGetMSC32, + .WaitForMSC = driWaitForMSC32, .WaitForSBC = NULL, .SwapBuffersMSC = NULL };