From 344626b33c76b50566a60dcb77f85b9dbd57b796 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 14 Oct 2016 23:25:09 +0100 Subject: [PATCH] dri2 --- include/GL/internal/dri_interface.h | 12 ++++++++++- src/glx/dri2_glx.c | 16 +++++++++++++-- src/mesa/drivers/dri/common/dri_util.c | 6 ++++++ src/mesa/drivers/dri/common/dri_util.h | 4 ++++ src/mesa/drivers/dri/i965/brw_context.c | 32 ++++------------------------- src/mesa/drivers/dri/i965/brw_context.h | 19 ++++++++++++++++- src/mesa/drivers/dri/i965/intel_screen.c | 5 +++-- src/mesa/drivers/dri/i965/intel_tex_image.c | 5 +++-- 8 files changed, 63 insertions(+), 36 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index d0b1bc6..ac7e91e 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -270,7 +270,7 @@ struct __DRItexBufferExtensionRec { * Used by drivers that implement DRI2 */ #define __DRI2_FLUSH "DRI2_Flush" -#define __DRI2_FLUSH_VERSION 4 +#define __DRI2_FLUSH_VERSION 5 #define __DRI2_FLUSH_DRAWABLE (1 << 0) /* the drawable should be flushed. */ #define __DRI2_FLUSH_CONTEXT (1 << 1) /* glFlush should be called */ @@ -316,6 +316,16 @@ struct __DRI2flushExtensionRec { __DRIdrawable *drawable, unsigned flags, enum __DRI2throttleReason throttle_reason); + + /** + * Ask the driver to call getBuffers/getBuffersWithFormat before + * it starts rendering again. + * + * \param screen the screen to invalidate + * + * \since 5 + */ + void (*invalidateScreen)(__DRIscreen *screen); }; diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index af388d9..88f634b 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -633,7 +633,7 @@ dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src) } static void -dri2_wait_x(struct glx_context *gc) +__dri2_copy_x(struct glx_context *gc) { struct dri2_drawable *priv = (struct dri2_drawable *) GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable); @@ -645,6 +645,18 @@ dri2_wait_x(struct glx_context *gc) } static void +dri2_wait_x(struct glx_context *gc) +{ + struct dri2_context *pcp = (struct dri2_context *) gc; + struct dri2_screen *psc = (struct dri2_screen *) pcp->base.psc; + + if (psc->f && psc->f->base.version >= 5 && psc->f->invalidateScreen) + psc->f->invalidateScreen(psc->driScreen); + else + __dri2_copy_x(gc); +} + +static void dri2_wait_gl(struct glx_context *gc) { struct dri2_drawable *priv = (struct dri2_drawable *) @@ -979,7 +991,7 @@ dri2InvalidateBuffers(Display *dpy, XID drawable) psc = (struct dri2_screen *) pdraw->psc; - if (pdraw && psc->f && psc->f->base.version >= 3 && psc->f->invalidate) + if (psc->f && psc->f->base.version >= 3 && psc->f->invalidate) psc->f->invalidate(pdp->driDrawable); } diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 79cb050..68fa0fe 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -805,6 +805,12 @@ dri2InvalidateDrawable(__DRIdrawable *drawable) drawable->dri2.stamp++; } +void +dri2InvalidateScreen(__DRIscreen *screen) +{ + screen->dri2.stamp++; +} + /** * Check that the gl_framebuffer associated with dPriv is the right size. * Resize the gl_framebuffer if needed. diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 6987f55..eb761d4 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -172,6 +172,7 @@ struct __DRIscreenRec { const __DRIdri2LoaderExtension *loader; const __DRIimageLookupExtension *image; const __DRIuseInvalidateExtension *useInvalidate; + unsigned int stamp; } dri2; struct { @@ -285,6 +286,9 @@ extern void dri2InvalidateDrawable(__DRIdrawable *drawable); extern void +dri2InvalidateScreen(__DRIscreen *screen); + +extern void driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv); extern void diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 4f05b6a..90fbc3e 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -1269,14 +1269,12 @@ intelMakeCurrent(__DRIcontext * driContextPriv, fb = _mesa_get_incomplete_framebuffer(); } else { fb = driDrawPriv->driverPrivate; - driContextPriv->dri2.draw_stamp = driDrawPriv->dri2.stamp - 1; } if (driReadPriv == NULL) { readFb = _mesa_get_incomplete_framebuffer(); } else { readFb = driReadPriv->driverPrivate; - driContextPriv->dri2.read_stamp = driReadPriv->dri2.stamp - 1; } /* The sRGB workaround changes the renderbuffer's format. We must change @@ -1364,11 +1362,6 @@ intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable) int i, count; const char *region_name; - /* Set this up front, so that in case our buffers get invalidated - * while we're getting new buffers, we don't clobber the stamp and - * thus ignore the invalidate. */ - drawable->lastStamp = drawable->dri2.stamp; - if (unlikely(INTEL_DEBUG & DEBUG_DRI)) fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable); @@ -1412,15 +1405,10 @@ intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable) } void -intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable) +__intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable) { + __DRIscreen *dri_screen = context->driScreenPriv; struct brw_context *brw = context->driverPrivate; - __DRIscreen *dri_screen = brw->screen->driScrnPriv; - - /* Set this up front, so that in case our buffers get invalidated - * while we're getting new buffers, we don't clobber the stamp and - * thus ignore the invalidate. */ - drawable->lastStamp = drawable->dri2.stamp; if (unlikely(INTEL_DEBUG & DEBUG_DRI)) fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable); @@ -1442,21 +1430,9 @@ intel_prepare_render(struct brw_context *brw) { struct gl_context *ctx = &brw->ctx; __DRIcontext *driContext = brw->driContext; - __DRIdrawable *drawable; - drawable = driContext->driDrawablePriv; - if (drawable && drawable->dri2.stamp != driContext->dri2.draw_stamp) { - if (drawable->lastStamp != drawable->dri2.stamp) - intel_update_renderbuffers(driContext, drawable); - driContext->dri2.draw_stamp = drawable->dri2.stamp; - } - - drawable = driContext->driReadablePriv; - if (drawable && drawable->dri2.stamp != driContext->dri2.read_stamp) { - if (drawable->lastStamp != drawable->dri2.stamp) - intel_update_renderbuffers(driContext, drawable); - driContext->dri2.read_stamp = drawable->dri2.stamp; - } + intel_update_renderbuffers(driContext, driContext->driDrawablePriv); + intel_update_renderbuffers(driContext, driContext->driReadablePriv); /* If we're currently rendering to the front buffer, the rendering * that will happen next will probably dirty the front buffer. So diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 4b0f5d0..b4bd2c3 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -1320,8 +1320,25 @@ enum { DRI_CONF_BO_REUSE_ALL }; -void intel_update_renderbuffers(__DRIcontext *context, +void __intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable); +static inline void +intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable) +{ + __DRIscreen *dri_screen = context->driScreenPriv; + unsigned int stamp = drawable->dri2.stamp + dri_screen->dri2.stamp; + + if (stamp == drawable->lastStamp) + return; + + /* Set this up front, so that in case our buffers get invalidated + * while we're getting new buffers, we don't clobber the stamp and + * thus ignore the invalidate. */ + drawable->lastStamp = stamp; + + __intel_update_renderbuffers(context, drawable); +} + void intel_prepare_render(struct brw_context *brw); void intel_resolve_for_dri2_flush(struct brw_context *brw, diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index 78b296e..7decfc1 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -168,11 +168,12 @@ intel_dri2_flush(__DRIdrawable *drawable) } static const struct __DRI2flushExtensionRec intelFlushExtension = { - .base = { __DRI2_FLUSH, 4 }, + .base = { __DRI2_FLUSH, 5 }, .flush = intel_dri2_flush, - .invalidate = dri2InvalidateDrawable, .flush_with_flags = intel_dri2_flush_with_flags, + .invalidate = dri2InvalidateDrawable, + .invalidateScreen = dri2InvalidateScreen, }; static struct intel_image_format intel_image_formats[] = { diff --git a/src/mesa/drivers/dri/i965/intel_tex_image.c b/src/mesa/drivers/dri/i965/intel_tex_image.c index 755a74c..cdc23b8 100644 --- a/src/mesa/drivers/dri/i965/intel_tex_image.c +++ b/src/mesa/drivers/dri/i965/intel_tex_image.c @@ -281,6 +281,7 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, struct gl_framebuffer *fb = dPriv->driverPrivate; struct brw_context *brw = pDRICtx->driverPrivate; struct gl_context *ctx = &brw->ctx; + __DRIscreen *dri_screen = pDRICtx->driScreenPriv; struct intel_renderbuffer *rb; struct gl_texture_object *texObj; struct gl_texture_image *texImage; @@ -293,8 +294,8 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, if (!texObj) return; - if (dPriv->lastStamp != dPriv->dri2.stamp || - !pDRICtx->driScreenPriv->dri2.useInvalidate) + if (dPriv->lastStamp != dPriv->dri2.stamp + dri_screen->dri2.stamp || + !dri_screen->dri2.useInvalidate) intel_update_renderbuffers(pDRICtx, dPriv); rb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT); -- 2.7.4