Requires newer libdrm, and the support only is advertised with a
sufficiently new kernel (v4.9 and later) as it depends on fence fd
support in the submit ioctl.

Signed-off-by: Rob Clark <robdcl...@gmail.com>
---
 configure.ac                                      |  2 +-
 src/gallium/drivers/freedreno/freedreno_batch.c   |  5 +++
 src/gallium/drivers/freedreno/freedreno_batch.h   |  3 ++
 src/gallium/drivers/freedreno/freedreno_context.c |  5 +++
 src/gallium/drivers/freedreno/freedreno_fence.c   | 46 +++++++++++++++++++++--
 src/gallium/drivers/freedreno/freedreno_fence.h   |  8 +++-
 src/gallium/drivers/freedreno/freedreno_gmem.c    |  7 +++-
 src/gallium/drivers/freedreno/freedreno_screen.c  |  3 +-
 8 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5f30ae8..ec5bf43 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,7 @@ LIBDRM_AMDGPU_REQUIRED=2.4.63
 LIBDRM_INTEL_REQUIRED=2.4.61
 LIBDRM_NVVIEUX_REQUIRED=2.4.66
 LIBDRM_NOUVEAU_REQUIRED=2.4.66
-LIBDRM_FREEDRENO_REQUIRED=2.4.68
+LIBDRM_FREEDRENO_REQUIRED=2.4.72
 LIBDRM_VC4_REQUIRED=2.4.69
 DRI2PROTO_REQUIRED=2.6
 DRI3PROTO_REQUIRED=1.0
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.c 
b/src/gallium/drivers/freedreno/freedreno_batch.c
index 176a31c..f7b8201 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.c
+++ b/src/gallium/drivers/freedreno/freedreno_batch.c
@@ -60,6 +60,8 @@ batch_init(struct fd_batch *batch)
        fd_ringbuffer_set_parent(batch->draw, batch->gmem);
        fd_ringbuffer_set_parent(batch->binning, batch->gmem);
 
+       batch->in_fence_fd = -1;
+
        batch->cleared = batch->partial_cleared = 0;
        batch->restore = batch->resolve = 0;
        batch->needs_flush = false;
@@ -109,6 +111,9 @@ batch_fini(struct fd_batch *batch)
 {
        pipe_resource_reference(&batch->query_buf, NULL);
 
+       if (batch->in_fence_fd != -1)
+               close(batch->in_fence_fd);
+
        fd_ringbuffer_del(batch->draw);
        fd_ringbuffer_del(batch->binning);
        fd_ringbuffer_del(batch->gmem);
diff --git a/src/gallium/drivers/freedreno/freedreno_batch.h 
b/src/gallium/drivers/freedreno/freedreno_batch.h
index aeeb9c5..289f36e 100644
--- a/src/gallium/drivers/freedreno/freedreno_batch.h
+++ b/src/gallium/drivers/freedreno/freedreno_batch.h
@@ -68,6 +68,9 @@ struct fd_batch {
        unsigned seqno;
        unsigned idx;
 
+       int in_fence_fd;
+       bool needs_out_fence_fd;
+
        struct fd_context *ctx;
 
        struct util_queue_fence flush_fence;
diff --git a/src/gallium/drivers/freedreno/freedreno_context.c 
b/src/gallium/drivers/freedreno/freedreno_context.c
index 70220f8..0364507 100644
--- a/src/gallium/drivers/freedreno/freedreno_context.c
+++ b/src/gallium/drivers/freedreno/freedreno_context.c
@@ -44,6 +44,9 @@ fd_context_flush(struct pipe_context *pctx, struct 
pipe_fence_handle **fence,
 {
        struct fd_context *ctx = fd_context(pctx);
 
+       if (flags & PIPE_FLUSH_FENCE_FD)
+               ctx->batch->needs_out_fence_fd = true;
+
        if (!ctx->screen->reorder) {
                fd_batch_flush(ctx->batch, true);
        } else {
@@ -251,6 +254,8 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen 
*pscreen,
        pctx->flush = fd_context_flush;
        pctx->emit_string_marker = fd_emit_string_marker;
        pctx->set_debug_callback = fd_set_debug_callback;
+       pctx->create_fence_fd = fd_create_fence_fd;
+       pctx->fence_server_sync = fd_fence_server_sync;
 
        /* TODO what about compute?  Ideally it creates it's own independent
         * batches per compute job (since it isn't using tiling, so no point
diff --git a/src/gallium/drivers/freedreno/freedreno_fence.c 
b/src/gallium/drivers/freedreno/freedreno_fence.c
index a5f7171..f20c6ac 100644
--- a/src/gallium/drivers/freedreno/freedreno_fence.c
+++ b/src/gallium/drivers/freedreno/freedreno_fence.c
@@ -26,6 +26,8 @@
  *    Rob Clark <robcl...@freedesktop.org>
  */
 
+#include <libsync.h>
+
 #include "util/u_inlines.h"
 
 #include "freedreno_fence.h"
@@ -36,16 +38,23 @@ struct pipe_fence_handle {
        struct pipe_reference reference;
        struct fd_context *ctx;
        struct fd_screen *screen;
+       int fence_fd;
        uint32_t timestamp;
 };
 
-void
-fd_fence_ref(struct pipe_screen *pscreen,
+static void fd_fence_destroy(struct pipe_fence_handle *fence)
+{
+       if (fence->fence_fd != -1)
+               close(fence->fence_fd);
+       FREE(fence);
+}
+
+void fd_fence_ref(struct pipe_screen *pscreen,
                struct pipe_fence_handle **ptr,
                struct pipe_fence_handle *pfence)
 {
        if (pipe_reference(&(*ptr)->reference, &pfence->reference))
-               FREE(*ptr);
+               fd_fence_destroy(*ptr);
 
        *ptr = pfence;
 }
@@ -55,14 +64,42 @@ boolean fd_fence_finish(struct pipe_screen *pscreen,
                struct pipe_fence_handle *fence,
                uint64_t timeout)
 {
+       if (fence->fence_fd != -1) {
+               int ret = sync_wait(fence->fence_fd, timeout / 1000000);
+               return ret == 0;
+       }
+
        if (fd_pipe_wait_timeout(fence->screen->pipe, fence->timestamp, 
timeout))
                return false;
 
        return true;
 }
 
+void fd_create_fence_fd(struct pipe_context *pctx,
+               struct pipe_fence_handle **pfence, int fd)
+{
+       *pfence = fd_fence_create(fd_context(pctx), 0, dup(fd));
+}
+
+void fd_fence_server_sync(struct pipe_context *pctx,
+               struct pipe_fence_handle *fence)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       struct fd_batch *batch = ctx->batch;
+
+       if (sync_accumulate("freedreno", &batch->in_fence_fd, fence->fence_fd)) 
{
+               /* error */
+       }
+}
+
+int fd_fence_get_fd(struct pipe_screen *pscreen,
+               struct pipe_fence_handle *fence)
+{
+       return dup(fence->fence_fd);
+}
+
 struct pipe_fence_handle * fd_fence_create(struct fd_context *ctx,
-               uint32_t timestamp)
+               uint32_t timestamp, int fence_fd)
 {
        struct pipe_fence_handle *fence;
 
@@ -75,6 +112,7 @@ struct pipe_fence_handle * fd_fence_create(struct fd_context 
*ctx,
        fence->ctx = ctx;
        fence->screen = ctx->screen;
        fence->timestamp = timestamp;
+       fence->fence_fd = fence_fd;
 
        return fence;
 }
diff --git a/src/gallium/drivers/freedreno/freedreno_fence.h 
b/src/gallium/drivers/freedreno/freedreno_fence.h
index 32bfacc..1de2d0a 100644
--- a/src/gallium/drivers/freedreno/freedreno_fence.h
+++ b/src/gallium/drivers/freedreno/freedreno_fence.h
@@ -38,9 +38,15 @@ boolean fd_fence_finish(struct pipe_screen *screen,
                struct pipe_context *ctx,
                struct pipe_fence_handle *pfence,
                uint64_t timeout);
+void fd_create_fence_fd(struct pipe_context *pctx,
+               struct pipe_fence_handle **pfence, int fd);
+void fd_fence_server_sync(struct pipe_context *pctx,
+               struct pipe_fence_handle *fence);
+int fd_fence_get_fd(struct pipe_screen *pscreen,
+               struct pipe_fence_handle *pfence);
 
 struct fd_context;
 struct pipe_fence_handle * fd_fence_create(struct fd_context *ctx,
-               uint32_t timestamp);
+               uint32_t timestamp, int fence_fd);
 
 #endif /* FREEDRENO_FENCE_H_ */
diff --git a/src/gallium/drivers/freedreno/freedreno_gmem.c 
b/src/gallium/drivers/freedreno/freedreno_gmem.c
index 3b2ecba..0aacb64 100644
--- a/src/gallium/drivers/freedreno/freedreno_gmem.c
+++ b/src/gallium/drivers/freedreno/freedreno_gmem.c
@@ -394,10 +394,13 @@ fd_gmem_render_tiles(struct fd_batch *batch)
                ctx->stats.batch_gmem++;
        }
 
-       fd_ringbuffer_flush(batch->gmem);
+       int out_fence_fd = -1;
+       fd_ringbuffer_flush2(batch->gmem, batch->in_fence_fd,
+                       batch->needs_out_fence_fd ? &out_fence_fd : NULL);
 
        fd_fence_ref(&ctx->screen->base, &ctx->last_fence, NULL);
-       ctx->last_fence = fd_fence_create(ctx, 
fd_ringbuffer_timestamp(batch->gmem));
+       ctx->last_fence = fd_fence_create(ctx,
+                       fd_ringbuffer_timestamp(batch->gmem), out_fence_fd);
 }
 
 /* tile needs restore if it isn't completely contained within the
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 0c65a03..8671fcf 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -378,7 +378,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
        case PIPE_CAP_UMA:
                return 1;
        case PIPE_CAP_NATIVE_FENCE_FD:
-               return 0;
+               return fd_device_version(screen->dev) >= FD_VERSION_FENCE_FD;
        }
        debug_printf("unknown param %d\n", param);
        return 0;
@@ -702,6 +702,7 @@ fd_screen_create(struct fd_device *dev)
 
        pscreen->fence_reference = fd_fence_ref;
        pscreen->fence_finish = fd_fence_finish;
+       pscreen->fence_get_fd = fd_fence_get_fd;
 
        slab_create_parent(&screen->transfer_pool, sizeof(struct fd_transfer), 
16);
 
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to