gallium: support for native fence fd's
authorRob Clark <robclark@freedesktop.org>
Fri, 1 Apr 2016 20:10:42 +0000 (16:10 -0400)
committerRob Clark <robdclark@gmail.com>
Fri, 2 Dec 2016 01:16:31 +0000 (20:16 -0500)
This enables gallium support for EGL_ANDROID_native_fence_sync, for
drivers which support PIPE_CAP_NATIVE_FENCE_FD.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
18 files changed:
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/ilo/ilo_screen.c
src/gallium/drivers/llvmpipe/lp_screen.c
src/gallium/drivers/nouveau/nv30/nv30_screen.c
src/gallium/drivers/nouveau/nv50/nv50_screen.c
src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/softpipe/sp_screen.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/virgl/virgl_screen.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_defines.h
src/gallium/include/pipe/p_screen.h
src/gallium/state_trackers/dri/dri2.c

index 48b796406d1775f426b8cd8bcb87aa3e942fcd82..90060e219fe8e250d14686b41dd5ee66c6f6db13 100644 (file)
@@ -379,6 +379,8 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
                return 10;
        case PIPE_CAP_UMA:
                return 1;
+       case PIPE_CAP_NATIVE_FENCE_FD:
+               return 0;
        }
        debug_printf("unknown param %d\n", param);
        return 0;
index fa19b8bb0e70f31048ef50da054dc59e7327cf32..14f42717b1d517d636735ae82412fede5e1a8b8b 100644 (file)
@@ -295,6 +295,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
    case PIPE_CAP_SAMPLER_VIEW_TARGET:
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
 
    case PIPE_CAP_MAX_VIEWPORTS:
index 3fce936cde228eb1001f236ccef50bf51830760b..c3fad7314edf0ae581475fb806de106b2d96a94d 100644 (file)
@@ -518,6 +518,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 2d75f2d403cb7a2468294991a5ce0fe6df45cb1c..83045cd5e3592737e29e4a0494ffffeb54c104bf 100644 (file)
@@ -339,6 +339,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
    }
    /* should only get here on unhandled cases */
index b4b7a200b64b48c4a657ec9fe0cd335ad3645128..beffeac7a1fb576b7f1d8aa1e3d3d810fa553e4a 100644 (file)
@@ -204,6 +204,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
    case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 60dfddc1552b764fc92d20f730fd3c83a61e8a6f..5b388b5aa1792a288768b4d5a1cce3aef811470e 100644 (file)
@@ -256,6 +256,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 67f1d6b7a0341468f0d31f8139043cae1b1ab3c2..2526a14c5048a58870fbaa4c7399a622a23aa16b 100644 (file)
@@ -275,6 +275,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_PCI_FUNCTION:
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
 
    case PIPE_CAP_VENDOR_ID:
index 0cb817befc9f64ddaeb324d33f0c17d122f3b0b0..d6e3aa4a7bf91c62208f2c495a61562a44d85953 100644 (file)
@@ -226,6 +226,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
         case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
         case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
         case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+        case PIPE_CAP_NATIVE_FENCE_FD:
             return 0;
 
         /* SWTCL-only features. */
index 16c936f0905e8927908a3b060389d05276f2875c..b99da2212dd91ec35a8f8fef02dac12d043b474f 100644 (file)
@@ -375,6 +375,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
        case PIPE_CAP_MAX_WINDOW_RECTANGLES:
        case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
        case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+       case PIPE_CAP_NATIVE_FENCE_FD:
                return 0;
 
        case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
index 4297a4fa57ff5b1aa39f3fd3df7b782c275df1aa..71fc5570d60bd988f50417f063c19e43c0477a8a 100644 (file)
@@ -459,6 +459,7 @@ static int si_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
        case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
        case PIPE_CAP_TGSI_VOTE:
        case PIPE_CAP_MAX_WINDOW_RECTANGLES:
+       case PIPE_CAP_NATIVE_FENCE_FD:
                return 0;
 
        case PIPE_CAP_QUERY_BUFFER_OBJECT:
index 4af1b00f83f4d53c2ac9aa938f274f6a115bdd74..824e86788237fd02da93f8675c8ce7fd62c6b361 100644 (file)
@@ -289,6 +289,7 @@ softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
    case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+   case PIPE_CAP_NATIVE_FENCE_FD:
       return 0;
    case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
       return 4;
index 4e0ebc376debda9fa5b74895c164979f19f25b4b..91484aaa717b47f396304eb40adaaa15ba08367b 100644 (file)
@@ -369,6 +369,7 @@ 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;
index 5334453a18c8109ad6c80191a96b96915b235640..2a640b1c87d955d693f06afb4062a18a65b29573 100644 (file)
@@ -240,6 +240,7 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
         case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
         case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
+        case PIPE_CAP_NATIVE_FENCE_FD:
                 return 0;
 
                 /* Stream output. */
index 87c4ce26bf25f845773e6b28ec0d52368a874085..8c062ba10b72f5be1deea56009566024485f9492 100644 (file)
@@ -261,6 +261,8 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_UMA:
    case PIPE_CAP_VIDEO_MEMORY:
       return 0;
+   case PIPE_CAP_NATIVE_FENCE_FD:
+      return 0;
    }
    /* should only get here on unhandled cases */
    debug_printf("Unexpected PIPE_CAP %d query\n", param);
index ee8a5113caa1cb3508910058c1aaec101c9e0f13..171dc570ba0def93a39272e4c23da73a646f39c0 100644 (file)
@@ -474,6 +474,19 @@ struct pipe_context {
                  struct pipe_fence_handle **fence,
                  unsigned flags);
 
+   /**
+    * Create a fence from a native sync fd.
+    *
+    * This is used for importing a foreign/external fence fd.
+    *
+    * \param fence  if not NULL, an old fence to unref and transfer a
+    *    new fence reference to
+    * \param fd     native fence fd
+    */
+   void (*create_fence_fd)(struct pipe_context *pipe,
+                           struct pipe_fence_handle **fence,
+                           int fd);
+
    /**
     * Insert commands to have GPU wait for fence to be signaled.
     */
index 46e9039a9eccda53c038e162e537df378fd31dfd..f1dd7935a780a2f0ebee199a121a54e0cfcbc37a 100644 (file)
@@ -350,6 +350,7 @@ enum pipe_flush_flags
 {
    PIPE_FLUSH_END_OF_FRAME = (1 << 0),
    PIPE_FLUSH_DEFERRED = (1 << 1),
+   PIPE_FLUSH_FENCE_FD = (1 << 2),
 };
 
 /**
@@ -741,6 +742,7 @@ enum pipe_cap
    PIPE_CAP_TGSI_ARRAY_COMPONENTS,
    PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS,
    PIPE_CAP_TGSI_CAN_READ_OUTPUTS,
+   PIPE_CAP_NATIVE_FENCE_FD,
 };
 
 #define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0)
index 255647ed2730f8f97a9b20578e9d665cd8b0def3..f04c2ed83ab7b279325e60879e48caf514753101 100644 (file)
@@ -264,6 +264,16 @@ struct pipe_screen {
                            struct pipe_fence_handle *fence,
                            uint64_t timeout);
 
+   /**
+    * For fences created with PIPE_FLUSH_FENCE_FD (exported fd) or
+    * by create_fence_fd() (imported fd), return the native fence fd
+    * associated with the fence.  This may return -1 for fences
+    * created with PIPE_FLUSH_DEFERRED if the fence command has not
+    * been flushed yet.
+    */
+   int (*fence_get_fd)(struct pipe_screen *screen,
+                       struct pipe_fence_handle *fence);
+
    /**
     * Returns a driver-specific query.
     *
index 1a44bcb771e5afa9bc34dfef1587d41b3c437045..77523e98ffed170413405ff2274ac6fd6a3a4158 100644 (file)
@@ -1457,6 +1457,18 @@ struct dri2_fence {
    void *cl_event;
 };
 
+static unsigned dri2_fence_get_caps(__DRIscreen *_screen)
+{
+   struct dri_screen *driscreen = dri_screen(_screen);
+   struct pipe_screen *screen = driscreen->base.screen;
+   unsigned caps = 0;
+
+   if (screen->get_param(screen, PIPE_CAP_NATIVE_FENCE_FD))
+      caps |= __DRI_FENCE_CAP_NATIVE_FD;
+
+   return caps;
+}
+
 static void *
 dri2_create_fence(__DRIcontext *_ctx)
 {
@@ -1477,6 +1489,39 @@ dri2_create_fence(__DRIcontext *_ctx)
    return fence;
 }
 
+static void *
+dri2_create_fence_fd(__DRIcontext *_ctx, int fd)
+{
+   struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
+   struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
+
+   if (fd == -1) {
+      /* exporting driver created fence, flush: */
+      ctx->flush(ctx, &fence->pipe_fence,
+                 PIPE_FLUSH_DEFERRED | PIPE_FLUSH_FENCE_FD);
+   } else {
+      /* importing a foreign fence fd: */
+      ctx->create_fence_fd(ctx, &fence->pipe_fence, fd);
+   }
+   if (!fence->pipe_fence) {
+      FREE(fence);
+      return NULL;
+   }
+
+   fence->driscreen = dri_screen(_ctx->driScreenPriv);
+   return fence;
+}
+
+static int
+dri2_get_fence_fd(__DRIscreen *_screen, void *_fence)
+{
+   struct dri_screen *driscreen = dri_screen(_screen);
+   struct pipe_screen *screen = driscreen->base.screen;
+   struct dri2_fence *fence = (struct dri2_fence*)_fence;
+
+   return screen->fence_get_fd(screen, fence->pipe_fence);
+}
+
 static void *
 dri2_get_fence_from_cl_event(__DRIscreen *_screen, intptr_t cl_event)
 {
@@ -1556,13 +1601,16 @@ dri2_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags)
 }
 
 static __DRI2fenceExtension dri2FenceExtension = {
-   .base = { __DRI2_FENCE, 1 },
+   .base = { __DRI2_FENCE, 2 },
 
    .create_fence = dri2_create_fence,
    .get_fence_from_cl_event = dri2_get_fence_from_cl_event,
    .destroy_fence = dri2_destroy_fence,
    .client_wait_sync = dri2_client_wait_sync,
-   .server_wait_sync = dri2_server_wait_sync
+   .server_wait_sync = dri2_server_wait_sync,
+   .get_capabilities = dri2_fence_get_caps,
+   .create_fence_fd = dri2_create_fence_fd,
+   .get_fence_fd = dri2_get_fence_fd,
 };
 
 static const __DRIrobustnessExtension dri2Robustness = {