drivers/svga: Connect driver-side fence_* functions
authorSinclair Yeh <syeh@vmware.com>
Mon, 15 May 2017 23:22:53 +0000 (16:22 -0700)
committerBrian Paul <brianp@vmware.com>
Mon, 17 Jul 2017 16:09:25 +0000 (10:09 -0600)
Connect fence_get_fd, fence_create_fd, and fence_server_sync.
Return PIPE_CAP_NATIVE_FENCE_FD capability based on what the
winsys reports

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/drivers/svga/svga_pipe_flush.c
src/gallium/drivers/svga/svga_screen.c

index 8e0af12d2948121c7508ba5ec8fc6ec28dd4a326..85ec34f3145bb5c0354c1fdeeb367344069c678e 100644 (file)
@@ -42,6 +42,9 @@ static void svga_flush( struct pipe_context *pipe,
     */
    svga_surfaces_flush( svga );
 
+   if (flags & PIPE_FLUSH_FENCE_FD)
+      svga->swc->hints |= SVGA_HINT_FLAG_EXPORT_FENCE_FD;
+
    /* Flush command queue.
     */
    svga_context_flush(svga, fence);
@@ -71,7 +74,45 @@ static void svga_flush( struct pipe_context *pipe,
 }
 
 
+/**
+ * svga_create_fence_fd
+ *
+ * Wraps a SVGA fence around an imported file descriptor.  This
+ * fd represents a fence from another process/device.  The fence created
+ * here can then be fed into fence_server_sync() so SVGA can synchronize
+ * with an external process
+ */
+static void
+svga_create_fence_fd(struct pipe_context *pipe,
+                     struct pipe_fence_handle **fence,
+                     int fd)
+{
+   struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
+
+   sws->fence_create_fd(sws, fence, fd);
+}
+
+
+/**
+ * svga_fence_server_sync
+ *
+ * This function imports a fence from another process/device into the current
+ * software context so that SVGA can synchronize with it.
+ */
+static void
+svga_fence_server_sync(struct pipe_context *pipe,
+                       struct pipe_fence_handle *fence)
+{
+   struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
+   struct svga_context *svga = svga_context(pipe);
+
+   sws->fence_server_sync(sws, &svga->swc->imported_fence_fd, fence);
+}
+
+
 void svga_init_flush_functions( struct svga_context *svga )
 {
    svga->pipe.flush = svga_flush;
+   svga->pipe.create_fence_fd = svga_create_fence_fd;
+   svga->pipe.fence_server_sync = svga_fence_server_sync;
 }
index 1368267d96289852ac04b1061f0a76dc664f0e4f..1ec91e57d3d8b7a844b64b886e8faadf36bddbb7 100644 (file)
@@ -337,6 +337,9 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_GENERATE_MIPMAP:
       return sws->have_generate_mipmap_cmd;
 
+   case PIPE_CAP_NATIVE_FENCE_FD:
+      return sws->have_fence_fd;
+
    /* Unsupported features */
    case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
    case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
@@ -380,7 +383,6 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_PCI_DEVICE:
    case PIPE_CAP_PCI_FUNCTION:
    case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
-   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
    case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
       return 64;
@@ -863,6 +865,16 @@ svga_fence_finish(struct pipe_screen *screen,
 }
 
 
+static int
+svga_fence_get_fd(struct pipe_screen *screen,
+                  struct pipe_fence_handle *fence)
+{
+   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
+
+   return sws->fence_get_fd(sws, fence, TRUE);
+}
+
+
 static int
 svga_get_driver_query_info(struct pipe_screen *screen,
                            unsigned index,
@@ -1024,6 +1036,8 @@ svga_screen_create(struct svga_winsys_screen *sws)
    screen->context_create = svga_context_create;
    screen->fence_reference = svga_fence_reference;
    screen->fence_finish = svga_fence_finish;
+   screen->fence_get_fd = svga_fence_get_fd;
+
    screen->get_driver_query_info = svga_get_driver_query_info;
    svgascreen->sws = sws;