[Mesa-dev] [PATCH RFC 2/2] dri: Pass a __DRIcontext to ->set_damage_region()

Boris Brezillon boris.brezillon at collabora.com
Thu Aug 29 11:54:16 UTC 2019


So we can call st_validate_state() from dri2_set_damage_region() in
order to update the BACK_LEFT attachement before using it. If we don't
do that, the resource passed to pipe_screen->set_damage_region() might
be wrong.

Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
---
Hi,

I honestly don't know if this is the right thing to do. Passing a
context for somethings that we decided to bind to a surface (and
the underlying resources attached to it) seems wrong, but at the same
time I don't see any other option to sync the gallium drawable state
with the EGL DRI surface one.

Any ideas/suggestions?

Regards,

Boris
---
 include/GL/internal/dri_interface.h   |  5 +++--
 src/egl/drivers/dri2/egl_dri2.c       |  7 +++++--
 src/gallium/state_trackers/dri/dri2.c | 11 ++++++++++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 4c60d349ddd5..e04bed689219 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -527,12 +527,13 @@ struct __DRI2bufferDamageExtensionRec {
     *
     * Used to implement EGL_KHR_partial_update.
     *
+    * \param ctx      context
     * \param drawable affected drawable
     * \param nrects   number of rectangles provided
     * \param rects    the array of rectangles, lower-left origin
     */
-   void (*set_damage_region)(__DRIdrawable *drawable, unsigned int nrects,
-                             int *rects);
+   void (*set_damage_region)(__DRIcontext *_ctx, __DRIdrawable *drawable,
+                             unsigned int nrects, int *rects);
 };
 
 /*@}*/
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ea8ae5d44c56..797a76dab13c 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1812,11 +1812,14 @@ dri2_set_damage_region(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    __DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   __DRIcontext *dri_ctx = ctx ? dri2_egl_context(ctx)->dri_context : NULL;
 
-   if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region)
+   if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region ||
+       !dri_ctx)
       return EGL_FALSE;
 
-   dri2_dpy->buffer_damage->set_damage_region(drawable, n_rects, rects);
+   dri2_dpy->buffer_damage->set_damage_region(dri_ctx, drawable, n_rects, rects);
    return EGL_TRUE;
 }
 
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 11ce19787249..bab503046510 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -36,6 +36,7 @@
 #include "util/u_format.h"
 #include "util/u_debug.h"
 #include "state_tracker/drm_driver.h"
+#include "state_tracker/st_atom.h"
 #include "state_tracker/st_cb_bufferobjects.h"
 #include "state_tracker/st_cb_fbo.h"
 #include "state_tracker/st_cb_texture.h"
@@ -1869,9 +1870,17 @@ static const __DRI2interopExtension dri2InteropExtension = {
  * \brief the DRI2bufferDamageExtension set_damage_region method
  */
 static void
-dri2_set_damage_region(__DRIdrawable *dPriv, unsigned int nrects, int *rects)
+dri2_set_damage_region(__DRIcontext *_ctx, __DRIdrawable *dPriv,
+                       unsigned int nrects, int *rects)
 {
    struct dri_drawable *drawable = dri_drawable(dPriv);
+   struct st_context *st = (struct st_context *)dri_context(_ctx)->st;
+
+   /* Make sure drawable->textures[ST_ATTACHMENT_BACK_LEFT] is up-to-date
+    * before using it.
+    */
+   st_validate_state(st, ST_PIPELINE_UPDATE_FRAMEBUFFER);
+
    struct pipe_resource *resource = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
    struct pipe_screen *screen = resource->screen;
    struct pipe_box *boxes = NULL;
-- 
2.21.0



More information about the mesa-dev mailing list