Mesa (master): svga: add context pointer to the invalidate surface interface

Brian Paul brianp at kemper.freedesktop.org
Fri Apr 7 19:51:10 UTC 2017


Module: Mesa
Branch: master
Commit: 16bd2c6d04b0a80f3808266fa530dcfd219d5c9d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=16bd2c6d04b0a80f3808266fa530dcfd219d5c9d

Author: Charmaine Lee <charmainel at vmware.com>
Date:   Thu Jan 26 18:46:23 2017 -0800

svga: add context pointer to the invalidate surface interface

With this patch, we will specify the current context
when we invalidate the surface before the surface is
put back to the recycled surface pool. This allows the
winsys layer to use the specified context to do the
invalidation rather than using the last context that
referenced the surface. This prevents race condition if
the last referenced context is now made current in another thread.

Tested with MTT glretrace, NobelClinicianViewer.

Reviewed-by: Sinclair Yeh <syeh at vmware.com>

---

 src/gallium/drivers/svga/svga_context.c       |  2 +-
 src/gallium/drivers/svga/svga_screen_cache.c  |  8 ++++++--
 src/gallium/drivers/svga/svga_screen_cache.h  |  2 ++
 src/gallium/drivers/svga/svga_winsys.h        | 15 +++++++--------
 src/gallium/winsys/svga/drm/vmw_context.c     |  7 ++++---
 src/gallium/winsys/svga/drm/vmw_screen_svga.c | 13 -------------
 src/gallium/winsys/svga/drm/vmw_surface.c     | 12 ++++++++++++
 src/gallium/winsys/svga/drm/vmw_surface.h     |  3 +++
 8 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index 04466fb7de..a6f3b34890 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -367,7 +367,7 @@ svga_context_flush(struct svga_context *svga,
 
    svga->hud.num_flushes++;
 
-   svga_screen_cache_flush(svgascreen, fence);
+   svga_screen_cache_flush(svgascreen, svga, fence);
 
    SVGA3D_ResetLastCommand(svga->swc);
 
diff --git a/src/gallium/drivers/svga/svga_screen_cache.c b/src/gallium/drivers/svga/svga_screen_cache.c
index d26e79a5c4..82d2ebce97 100644
--- a/src/gallium/drivers/svga/svga_screen_cache.c
+++ b/src/gallium/drivers/svga/svga_screen_cache.c
@@ -32,6 +32,7 @@
 #include "svga_winsys.h"
 #include "svga_screen.h"
 #include "svga_screen_cache.h"
+#include "svga_context.h"
 
 
 #define SVGA_SURFACE_CACHE_ENABLED 1
@@ -310,6 +311,7 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
  */
 void
 svga_screen_cache_flush(struct svga_screen *svgascreen,
+                        struct svga_context *svga,
                         struct pipe_fence_handle *fence)
 {
    struct svga_host_surface_cache *cache = &svgascreen->cache;
@@ -357,8 +359,10 @@ svga_screen_cache_flush(struct svga_screen *svgascreen,
          /* remove entry from the validated list */
          LIST_DEL(&entry->head);
 
-         /* it is now safe to invalidate the surface content. */
-         sws->surface_invalidate(sws, entry->handle);
+         /* It is now safe to invalidate the surface content.
+          * It will be done using the current context.
+          */
+         svga->swc->surface_invalidate(svga->swc, entry->handle);
 
          /* add the entry to the invalidated list */
          LIST_ADD(&entry->head, &cache->invalidated);
diff --git a/src/gallium/drivers/svga/svga_screen_cache.h b/src/gallium/drivers/svga/svga_screen_cache.h
index 2ade1025fc..03b809a41a 100644
--- a/src/gallium/drivers/svga/svga_screen_cache.h
+++ b/src/gallium/drivers/svga/svga_screen_cache.h
@@ -53,6 +53,7 @@
 
 struct svga_winsys_surface;
 struct svga_screen;
+struct svga_context;
 
 /**
  * Same as svga_winsys_screen::surface_create.
@@ -136,6 +137,7 @@ svga_screen_cache_cleanup(struct svga_screen *svgascreen);
 
 void
 svga_screen_cache_flush(struct svga_screen *svgascreen,
+                        struct svga_context *svga,
                         struct pipe_fence_handle *fence);
 
 enum pipe_error
diff --git a/src/gallium/drivers/svga/svga_winsys.h b/src/gallium/drivers/svga/svga_winsys.h
index f226581774..3bb23ce143 100644
--- a/src/gallium/drivers/svga/svga_winsys.h
+++ b/src/gallium/drivers/svga/svga_winsys.h
@@ -392,6 +392,13 @@ struct svga_winsys_context
                     boolean *rebind);
 
    /**
+    * Invalidate the content of this surface
+    */
+   void
+   (*surface_invalidate)(struct svga_winsys_context *swc,
+                         struct svga_winsys_surface *surface);
+
+   /**
     * Create and define a DX GB shader that resides in the device COTable.
     * Caller of this function will issue the DXDefineShader command.
     */
@@ -556,14 +563,6 @@ struct svga_winsys_screen
                          uint32 numMipLevels);
 
    /**
-    * Invalidate the content of this surface
-    */
-   void
-   (*surface_invalidate)(struct svga_winsys_screen *sws,
-                         struct svga_winsys_surface *surface);
-
-
-   /**
     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
     *
     * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c
index 6e691756d1..c306d988e0 100644
--- a/src/gallium/winsys/svga/drm/vmw_context.c
+++ b/src/gallium/winsys/svga/drm/vmw_context.c
@@ -808,11 +808,12 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
    vswc->base.flush = vmw_swc_flush;
    vswc->base.surface_map = vmw_svga_winsys_surface_map;
    vswc->base.surface_unmap = vmw_svga_winsys_surface_unmap;
+   vswc->base.surface_invalidate = vmw_svga_winsys_surface_invalidate;
 
-  vswc->base.shader_create = vmw_svga_winsys_vgpu10_shader_create;
-  vswc->base.shader_destroy = vmw_svga_winsys_vgpu10_shader_destroy;
+   vswc->base.shader_create = vmw_svga_winsys_vgpu10_shader_create;
+   vswc->base.shader_destroy = vmw_svga_winsys_vgpu10_shader_destroy;
 
-  vswc->base.resource_rebind = vmw_svga_winsys_resource_rebind;
+   vswc->base.resource_rebind = vmw_svga_winsys_resource_rebind;
 
    if (sws->have_vgpu10)
       vswc->base.cid = vmw_ioctl_extended_context_create(vws, sws->have_vgpu10);
diff --git a/src/gallium/winsys/svga/drm/vmw_screen_svga.c b/src/gallium/winsys/svga/drm/vmw_screen_svga.c
index 17a1e760dd..31cbda9af6 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen_svga.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen_svga.c
@@ -280,18 +280,6 @@ vmw_svga_winsys_surface_can_create(struct svga_winsys_screen *sws,
 }
 
 
-static void
-vmw_svga_winsys_surface_invalidate(struct svga_winsys_screen *sws,
-                                   struct svga_winsys_surface *surf)
-{
-   /* this is a noop since surface invalidation is not needed for DMA path.
-    * DMA is enabled when guest-backed surface is not enabled or
-    * guest-backed dma is enabled.  Since guest-backed dma is enabled
-    * when guest-backed surface is enabled, that implies DMA is always enabled;
-    * hence, surface invalidation is not needed.
-    */
-}
-
 static boolean
 vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws,
                                    struct svga_winsys_surface *surface)
@@ -434,7 +422,6 @@ vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws)
    vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed;
    vws->base.surface_reference = vmw_svga_winsys_surface_ref;
    vws->base.surface_can_create = vmw_svga_winsys_surface_can_create;
-   vws->base.surface_invalidate = vmw_svga_winsys_surface_invalidate;
    vws->base.buffer_create = vmw_svga_winsys_buffer_create;
    vws->base.buffer_map = vmw_svga_winsys_buffer_map;
    vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap;
diff --git a/src/gallium/winsys/svga/drm/vmw_surface.c b/src/gallium/winsys/svga/drm/vmw_surface.c
index 69408ffe9d..80cc0914cc 100644
--- a/src/gallium/winsys/svga/drm/vmw_surface.c
+++ b/src/gallium/winsys/svga/drm/vmw_surface.c
@@ -177,6 +177,18 @@ vmw_svga_winsys_surface_unmap(struct svga_winsys_context *swc,
 }
 
 void
+vmw_svga_winsys_surface_invalidate(struct svga_winsys_context *swc,
+                                   struct svga_winsys_surface *surf)
+{
+   /* this is a noop since surface invalidation is not needed for DMA path.
+    * DMA is enabled when guest-backed surface is not enabled or
+    * guest-backed dma is enabled.  Since guest-backed dma is enabled
+    * when guest-backed surface is enabled, that implies DMA is always enabled;
+    * hence, surface invalidation is not needed.
+    */
+}
+
+void
 vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst,
                                   struct vmw_svga_winsys_surface *src)
 {
diff --git a/src/gallium/winsys/svga/drm/vmw_surface.h b/src/gallium/winsys/svga/drm/vmw_surface.h
index baeef5056b..d6f2381220 100644
--- a/src/gallium/winsys/svga/drm/vmw_surface.h
+++ b/src/gallium/winsys/svga/drm/vmw_surface.h
@@ -94,5 +94,8 @@ void
 vmw_svga_winsys_surface_unmap(struct svga_winsys_context *swc,
                               struct svga_winsys_surface *srf,
                               boolean *rebind);
+void
+vmw_svga_winsys_surface_invalidate(struct svga_winsys_context *swc,
+                                   struct svga_winsys_surface *srf);
 
 #endif /* VMW_SURFACE_H_ */




More information about the mesa-commit mailing list