[mesa patch v4 1/3] dri2: Event driven buffer validation.
Francisco Jerez
currojerez at riseup.net
Mon Feb 8 10:27:56 PST 2010
When a buffer invalidation event is received from the X server, the
"invalidate" hook of the DRI2 flush extension is executed: A generic
implementation (dri2InvalidateDrawable) is provided that just bumps
the "pStamp" sequence number in __DRIdrawableRec.
For old servers not supporting buffer invalidation events, the
invalidate hook will be called before flushing the fake front/back
buffer (that's typically once per frame -- not a lot worse than the
situation we were in before).
No effort has been made on preserving backwards compatibility with
version 2 of the flush extension, but I think it's acceptable because
AFAIK no released stack is making use of it.
Note that this bumps the required dri2proto version to 2.3.
---
v4: Drop flush v2 compatibility as the intel driver has stopped using
it for throttling. #ifdef part of the code to make it easier to
build with older protocol headers, along the lines of 01923fb72d.
configure.ac | 2 +-
include/GL/internal/dri_interface.h | 14 ++++-----
src/glx/x11/dri2.c | 10 +++++-
src/glx/x11/dri2.h | 3 ++
src/glx/x11/dri2_glx.c | 42 +++++++++++++++++--------
src/glx/x11/glx_pbuffer.c | 4 --
src/glx/x11/glxclient.h | 4 ++
src/glx/x11/glxcmds.c | 4 --
src/mesa/drivers/dri/common/dri_util.c | 15 ++++++++-
src/mesa/drivers/dri/common/dri_util.h | 8 +++--
src/mesa/drivers/dri/intel/intel_context.c | 1 -
src/mesa/drivers/dri/intel/intel_screen.c | 10 ++----
src/mesa/drivers/dri/intel/intel_tex_image.c | 4 ++-
13 files changed, 76 insertions(+), 45 deletions(-)
diff --git a/configure.ac b/configure.ac
index b6c6535..d92d99a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ AC_CANONICAL_HOST
dnl Versions for external dependencies
LIBDRM_REQUIRED=2.4.15
LIBDRM_RADEON_REQUIRED=2.4.17
-DRI2PROTO_REQUIRED=2.2
+DRI2PROTO_REQUIRED=2.3
GLPROTO_REQUIRED=1.4.11
dnl Check for progs
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index ec6238f..6399787 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -262,22 +262,20 @@ struct __DRItexBufferExtensionRec {
* Used by drivers that implement DRI2
*/
#define __DRI2_FLUSH "DRI2_Flush"
-#define __DRI2_FLUSH_VERSION 2
+#define __DRI2_FLUSH_VERSION 3
struct __DRI2flushExtensionRec {
__DRIextension base;
void (*flush)(__DRIdrawable *drawable);
/**
- * Flush all rendering queue in the driver to the drm and
- * invalidate all buffers. The driver will call out to
- * getBuffers/getBuffersWithFormat before it starts rendering
- * again.
+ * Ask the driver to call getBuffers/getBuffersWithFormat before
+ * it starts rendering again.
*
- * \param drawable the drawable to flush and invalidate
+ * \param drawable the drawable to invalidate
*
- * \since 2
+ * \since 3
*/
- void (*flushInvalidate)(__DRIdrawable *drawable);
+ void (*invalidate)(__DRIdrawable *drawable);
};
diff --git a/src/glx/x11/dri2.c b/src/glx/x11/dri2.c
index 91053d3..e692c8c 100644
--- a/src/glx/x11/dri2.c
+++ b/src/glx/x11/dri2.c
@@ -81,7 +81,7 @@ static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
dri2Info,
dri2ExtensionName,
&dri2ExtensionHooks,
- 1, NULL)
+ DRI2NumberEvents, NULL)
static Bool
DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
@@ -126,7 +126,15 @@ DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
return True;
}
#endif
+#ifdef DRI2_InvalidateBuffers
+ case DRI2_InvalidateBuffers:
+ {
+ xDRI2InvalidateBuffers *awire = (xDRI2InvalidateBuffers *)wire;
+ DRI2InvalidateBuffers(dpy, awire->drawable);
+ return False;
+ }
+#endif
default:
/* client doesn't support server event */
break;
diff --git a/src/glx/x11/dri2.h b/src/glx/x11/dri2.h
index 114e9f8..943ac59 100644
--- a/src/glx/x11/dri2.h
+++ b/src/glx/x11/dri2.h
@@ -103,4 +103,7 @@ DRI2WaitSBC(Display *dpy, XID drawable, CARD64 target_sbc, CARD64 *ust,
extern void
DRI2SwapInterval(Display *dpy, XID drawable, int interval);
+extern void
+DRI2InvalidateBuffers(Display *dpy, XID drawable);
+
#endif
diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index 6200df9..736cd3a 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -66,6 +66,7 @@ struct __GLXDRIdisplayPrivateRec
int driMinor;
int driPatch;
int swapAvailable;
+ int invalidateAvailable;
};
struct __GLXDRIcontextPrivateRec
@@ -309,12 +310,18 @@ dri2WaitGL(__GLXDRIdrawable * pdraw)
XFixesDestroyRegion(pdraw->psc->dpy, region);
}
-
static void
-dri2FlushFrontBuffer(__DRIdrawable * driDrawable, void *loaderPrivate)
+dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
{
- (void) driDrawable;
- dri2WaitGL((__GLXDRIdrawable *) loaderPrivate);
+ __GLXDRIdrawablePrivate *pdraw = loaderPrivate;
+ __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
+ __GLXDRIdisplayPrivate *pdp = (__GLXDRIdisplayPrivate *)priv->dri2Display;
+
+ /* Old servers don't send invalidate events */
+ if (!pdp->invalidateAvailable)
+ DRI2InvalidateBuffers(priv->dpy, pdraw->base.xDrawable);
+
+ dri2WaitGL(loaderPrivate);
}
@@ -374,6 +381,10 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
(*pdraw->psc->f->flush)(pdraw->driDrawable);
#endif
+ /* Old servers don't send invalidate events */
+ if (!pdp->invalidateAvailable)
+ DRI2InvalidateBuffers(dpyPriv->dpy, pdraw->xDrawable);
+
/* Old servers can't handle swapbuffers */
if (!pdp->swapAvailable) {
dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
@@ -385,11 +396,6 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
remainder, &ret);
#endif
-#if __DRI2_FLUSH_VERSION >= 2
- if (pdraw->psc->f)
- (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable);
-#endif
-
return ret;
}
@@ -484,6 +490,17 @@ static const __DRIextension *loader_extensions_old[] = {
NULL
};
+_X_HIDDEN void
+DRI2InvalidateBuffers(Display *dpy, XID drawable)
+{
+ __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
+
+#if __DRI2_FLUSH_VERSION >= 3
+ if (pdraw && pdraw->psc->f)
+ pdraw->psc->f->invalidate(pdraw->driDrawable);
+#endif
+}
+
static __GLXDRIscreen *
dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
__GLXdisplayPrivate * priv)
@@ -650,11 +667,8 @@ dri2CreateDisplay(Display * dpy)
}
pdp->driPatch = 0;
- pdp->swapAvailable = 0;
-#ifdef X_DRI2SwapBuffers
- if (pdp->driMinor >= 2)
- pdp->swapAvailable = 1;
-#endif
+ pdp->swapAvailable = (pdp->driMinor >= 2);
+ pdp->invalidateAvailable = (pdp->driMinor >= 3);
pdp->base.destroyDisplay = dri2DestroyDisplay;
pdp->base.createScreen = dri2CreateScreen;
diff --git a/src/glx/x11/glx_pbuffer.c b/src/glx/x11/glx_pbuffer.c
index a0a0223..4c122ba 100644
--- a/src/glx/x11/glx_pbuffer.c
+++ b/src/glx/x11/glx_pbuffer.c
@@ -186,10 +186,6 @@ DestroyPbuffer(Display * dpy, GLXDrawable drawable)
#ifdef GLX_DIRECT_RENDERING
-extern __GLXDRIdrawable *GetGLXDRIDrawable(Display * dpy,
- GLXDrawable drawable,
- int *const scrn_num);
-
static GLenum
determineTextureTarget(const int *attribs, int numAttribs)
{
diff --git a/src/glx/x11/glxclient.h b/src/glx/x11/glxclient.h
index e0b286b..f88e9fb 100644
--- a/src/glx/x11/glxclient.h
+++ b/src/glx/x11/glxclient.h
@@ -798,6 +798,10 @@ __driGetMscRateOML(__DRIdrawable * draw,
/* So that dri2.c:DRI2WireToEvent() can access
* glx_info->codes->first_event */
XExtDisplayInfo *__glXFindDisplay (Display *dpy);
+
+extern __GLXDRIdrawable *
+GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int *const scrn_num);
+
#endif
#endif /* !__GLX_client_h__ */
diff --git a/src/glx/x11/glxcmds.c b/src/glx/x11/glxcmds.c
index c3be974..da0dcf1 100644
--- a/src/glx/x11/glxcmds.c
+++ b/src/glx/x11/glxcmds.c
@@ -105,10 +105,6 @@ GarbageCollectDRIDrawables(Display * dpy, __GLXscreenConfigs * sc)
XSetErrorHandler(oldXErrorHandler);
}
-extern __GLXDRIdrawable *GetGLXDRIDrawable(Display * dpy,
- GLXDrawable drawable,
- int *const scrn_num);
-
/**
* Get the __DRIdrawable for the drawable associated with a GLXContext
*
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 3649c29..705681e 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -454,7 +454,6 @@ driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config,
pdp->driScreenPriv = psp;
pdp->driContextPriv = &psp->dummyContextPriv;
- pdp->validBuffers = GL_FALSE;
if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes,
renderType == GLX_PIXMAP_BIT)) {
@@ -488,6 +487,9 @@ dri2CreateNewDrawable(__DRIscreen *screen,
pdraw->pClipRects = _mesa_malloc(sizeof *pdraw->pBackClipRects);
pdraw->pBackClipRects = _mesa_malloc(sizeof *pdraw->pBackClipRects);
+ pdraw->pStamp = _mesa_malloc(sizeof(unsigned int));
+ *pdraw->pStamp = pdraw->lastStamp + 1;
+
return pdraw;
}
@@ -515,6 +517,11 @@ static void dri_put_drawable(__DRIdrawable *pdp)
_mesa_free(pdp->pBackClipRects);
pdp->pBackClipRects = NULL;
}
+ if (psp->dri2.enabled && pdp->pStamp) {
+ _mesa_free(pdp->pStamp);
+ pdp->pStamp = NULL;
+
+ }
_mesa_free(pdp);
}
}
@@ -948,4 +955,10 @@ driCalculateSwapUsage( __DRIdrawable *dPriv, int64_t last_swap_ust,
return usage;
}
+void
+dri2InvalidateDrawable(__DRIdrawable *drawable)
+{
+ (*drawable->pStamp)++;
+}
+
/*@}*/
diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
index 95df702..d473091 100644
--- a/src/mesa/drivers/dri/common/dri_util.h
+++ b/src/mesa/drivers/dri/common/dri_util.h
@@ -295,7 +295,8 @@ struct __DRIdrawableRec {
unsigned int index;
/**
- * Pointer to the "drawable has changed ID" stamp in the SAREA.
+ * Pointer to the "drawable has changed ID" stamp in the SAREA (or
+ * in malloc'ed memory if DRI2 is being used).
*/
unsigned int *pStamp;
@@ -376,8 +377,6 @@ struct __DRIdrawableRec {
* GLX_MESA_swap_control.
*/
unsigned int swap_interval;
-
- GLboolean validBuffers;
};
/**
@@ -550,4 +549,7 @@ driCalculateSwapUsage( __DRIdrawable *dPriv,
extern GLint
driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
+extern void
+dri2InvalidateDrawable(__DRIdrawable *drawable);
+
#endif /* _DRI_UTIL_H_ */
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 0adee61..a83e949 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -373,7 +373,6 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
}
}
- drawable->validBuffers = GL_TRUE;
driUpdateFramebufferSize(&intel->ctx, drawable);
}
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index c9ef164..090cef6 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -122,22 +122,18 @@ intelDRI2Flush(__DRIdrawable *drawable)
}
static void
-intelDRI2FlushInvalidate(__DRIdrawable *drawable)
+intelDRI2Invalidate(__DRIdrawable *drawable)
{
struct intel_context *intel = drawable->driContextPriv->driverPrivate;
intel->using_dri2_swapbuffers = GL_TRUE;
-
- intelDRI2Flush(drawable);
- drawable->validBuffers = GL_FALSE;
-
- intel_update_renderbuffers(intel->driContext, drawable);
+ dri2InvalidateDrawable(drawable);
}
static const struct __DRI2flushExtensionRec intelFlushExtension = {
{ __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
intelDRI2Flush,
- intelDRI2FlushInvalidate,
+ intelDRI2Invalidate,
};
static const __DRIextension *intelScreenExtensions[] = {
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index 6402141..8de4e50 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -748,8 +748,10 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
if (!intelObj)
return;
- if (!dPriv->validBuffers)
+ if (dPriv->lastStamp != *dPriv->pStamp) {
+ dPriv->lastStamp = *dPriv->pStamp;
intel_update_renderbuffers(pDRICtx, dPriv);
+ }
rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
/* If the region isn't set, then intel_update_renderbuffers was unable
--
1.6.4.4
More information about the xorg-devel
mailing list