gallium: add type parameter to create_fence_fd
authorAndres Rodriguez <andresx7@gmail.com>
Mon, 4 Dec 2017 20:27:08 +0000 (15:27 -0500)
committerAndres Rodriguez <andresx7@gmail.com>
Tue, 30 Jan 2018 20:13:49 +0000 (15:13 -0500)
An fd can potentially have different types of objects backing it.
Specifying the type helps us make sure we treat the FD correctly.

This is in preparation to allow importing syncobj fence FDs in addition
to native sync FDs.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_tests.c
src/gallium/auxiliary/util/u_threaded_context.c
src/gallium/drivers/etnaviv/etnaviv_fence.c
src/gallium/drivers/etnaviv/etnaviv_fence.h
src/gallium/drivers/freedreno/freedreno_fence.c
src/gallium/drivers/freedreno/freedreno_fence.h
src/gallium/drivers/radeonsi/si_fence.c
src/gallium/drivers/svga/svga_pipe_flush.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_defines.h
src/gallium/state_trackers/dri/dri_helpers.c

index cb337a255ae8364e4ba861d41848c362df68f634..e8599e320313b4597d2ae3e6c2f27608fa202019 100644 (file)
@@ -502,6 +502,7 @@ test_sync_file_fences(struct pipe_context *ctx)
 {
    struct pipe_screen *screen = ctx->screen;
    bool pass = true;
+   enum pipe_fd_type fd_type = PIPE_FD_TYPE_NATIVE_SYNC;
 
    if (!screen->get_param(screen, PIPE_CAP_NATIVE_FENCE_FD))
       return;
@@ -536,9 +537,9 @@ test_sync_file_fences(struct pipe_context *ctx)
    /* (Re)import all fences. */
    struct pipe_fence_handle *re_buf_fence = NULL, *re_tex_fence = NULL;
    struct pipe_fence_handle *merged_fence = NULL;
-   ctx->create_fence_fd(ctx, &re_buf_fence, buf_fd);
-   ctx->create_fence_fd(ctx, &re_tex_fence, tex_fd);
-   ctx->create_fence_fd(ctx, &merged_fence, merged_fd);
+   ctx->create_fence_fd(ctx, &re_buf_fence, buf_fd, fd_type);
+   ctx->create_fence_fd(ctx, &re_tex_fence, tex_fd, fd_type);
+   ctx->create_fence_fd(ctx, &merged_fence, merged_fd, fd_type);
    pass = pass && re_buf_fence && re_tex_fence && merged_fence;
 
    /* Run another clear after waiting for everything. */
index ffa824744e5fb59e203ad5829d11a5e3e5124689..3ea1797a9ef68e1721c1655b2af999501c2d6cb3 100644 (file)
@@ -1835,13 +1835,14 @@ tc_set_log_context(struct pipe_context *_pipe, struct u_log_context *log)
 
 static void
 tc_create_fence_fd(struct pipe_context *_pipe,
-                   struct pipe_fence_handle **fence, int fd)
+                   struct pipe_fence_handle **fence, int fd,
+                   enum pipe_fd_type type)
 {
    struct threaded_context *tc = threaded_context(_pipe);
    struct pipe_context *pipe = tc->pipe;
 
    tc_sync(tc);
-   pipe->create_fence_fd(pipe, fence, fd);
+   pipe->create_fence_fd(pipe, fence, fd, type);
 }
 
 static void
index d82708eacbed47e23b451e1a75a5474823282f70..22a964ad282e854c3e9352b47cfa9147dbda4689 100644 (file)
@@ -76,8 +76,10 @@ etna_screen_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
 
 void
 etna_create_fence_fd(struct pipe_context *pctx,
-                     struct pipe_fence_handle **pfence, int fd)
+                     struct pipe_fence_handle **pfence, int fd,
+                     enum pipe_fd_type type)
 {
+   assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
    *pfence = etna_fence_create(pctx, dup(fd));
 }
 
index cd68a428d3f83314e2c923b1c8a5fa70c913de32..8b8bb63e3ef5fd32e782162c93c400b3258f60f5 100644 (file)
@@ -32,7 +32,8 @@
 
 void
 etna_create_fence_fd(struct pipe_context *pctx,
-                     struct pipe_fence_handle **pfence, int fd);
+                     struct pipe_fence_handle **pfence, int fd,
+                     enum pipe_fd_type type);
 
 void
 etna_fence_server_sync(struct pipe_context *pctx,
index 928972003c68b67bf96ed7e7ccfb461d5bfd2c4d..1925f726a25c97a3c91fa643289220bc03c2331f 100644 (file)
@@ -120,8 +120,10 @@ static struct pipe_fence_handle * fence_create(struct fd_context *ctx,
 }
 
 void fd_create_fence_fd(struct pipe_context *pctx,
-               struct pipe_fence_handle **pfence, int fd)
+               struct pipe_fence_handle **pfence, int fd,
+               enum pipe_fd_type type)
 {
+       assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
        *pfence = fence_create(fd_context(pctx), NULL, 0, dup(fd));
 }
 
index c1a9fd3f1ccee9bc6fccecd94688cd9d293cd5c6..0842a1d618dfd40a3599f41b617f983cc1b4ca46 100644 (file)
@@ -41,7 +41,8 @@ boolean fd_fence_finish(struct pipe_screen *screen,
                struct pipe_fence_handle *pfence,
                uint64_t timeout);
 void fd_create_fence_fd(struct pipe_context *pctx,
-               struct pipe_fence_handle **pfence, int fd);
+               struct pipe_fence_handle **pfence, int fd,
+               enum pipe_fd_type type);
 void fd_fence_server_sync(struct pipe_context *pctx,
                struct pipe_fence_handle *fence);
 int fd_fence_get_fd(struct pipe_screen *pscreen,
index 47d68dbc3370c023803db3b215b8040c0cc99b3f..d3a68e50e1c13f2e5095a20bb5413c5742fe1d5d 100644 (file)
@@ -298,12 +298,15 @@ static boolean si_fence_finish(struct pipe_screen *screen,
 }
 
 static void si_create_fence_fd(struct pipe_context *ctx,
-                              struct pipe_fence_handle **pfence, int fd)
+                              struct pipe_fence_handle **pfence, int fd,
+                              enum pipe_fd_type type)
 {
        struct si_screen *sscreen = (struct si_screen*)ctx->screen;
        struct radeon_winsys *ws = sscreen->ws;
        struct si_multi_fence *rfence;
 
+       assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
+
        *pfence = NULL;
 
        if (!sscreen->info.has_fence_to_handle)
index 85ec34f3145bb5c0354c1fdeeb367344069c678e..1f4eebc124a950fbc305a3bf04875ca2e7de01da 100644 (file)
@@ -85,10 +85,12 @@ static void svga_flush( struct pipe_context *pipe,
 static void
 svga_create_fence_fd(struct pipe_context *pipe,
                      struct pipe_fence_handle **fence,
-                     int fd)
+                     int fd,
+                     enum pipe_fd_type type)
 {
    struct svga_winsys_screen *sws = svga_winsys_screen(pipe->screen);
 
+   assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
    sws->fence_create_fd(sws, fence, fd);
 }
 
index b74e6492196ad74025acbc51064da3cf82bb9c6f..1c7f52cfc59c7753e17fd4127e2c6984fe56df31 100644 (file)
@@ -505,17 +505,19 @@ struct pipe_context {
                  unsigned flags);
 
    /**
-    * Create a fence from a native sync fd.
+    * Create a fence from a 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
+    * \param fd     fd representing the fence object
+    * \param type   indicates which fence types backs fd
     */
    void (*create_fence_fd)(struct pipe_context *pipe,
                            struct pipe_fence_handle **fence,
-                           int fd);
+                           int fd,
+                           enum pipe_fd_type type);
 
    /**
     * Insert commands to have GPU wait for fence to be signaled.
index b34e7a8570a98cafa4dc6bca7682c3efb3313c7a..60546f55d984c465a3168b8559b52e313129bc00 100644 (file)
@@ -1084,6 +1084,11 @@ struct pipe_driver_query_group_info
    unsigned num_queries;
 };
 
+enum pipe_fd_type
+{
+   PIPE_FD_TYPE_NATIVE_SYNC,
+};
+
 enum pipe_debug_type
 {
    PIPE_DEBUG_TYPE_OUT_OF_MEMORY = 1,
index 37ab2c2f404e4725fe7c424f781cc56c3fae6709..f1501bfb81531944df51cca21ac2c50c0979be97 100644 (file)
@@ -119,7 +119,7 @@ dri2_create_fence_fd(__DRIcontext *_ctx, int fd)
       stapi->flush(stapi, ST_FLUSH_FENCE_FD, &fence->pipe_fence);
    } else {
       /* importing a foreign fence fd: */
-      ctx->create_fence_fd(ctx, &fence->pipe_fence, fd);
+      ctx->create_fence_fd(ctx, &fence->pipe_fence, fd, PIPE_FD_TYPE_NATIVE_SYNC);
    }
    if (!fence->pipe_fence) {
       FREE(fence);