etnaviv: native fence fd support
authorPhilipp Zabel <p.zabel@pengutronix.de>
Wed, 12 Apr 2017 10:31:01 +0000 (12:31 +0200)
committerChristian Gmeiner <christian.gmeiner@gmail.com>
Fri, 14 Apr 2017 23:47:18 +0000 (01:47 +0200)
This adds native fence fd support to etnaviv, similarly to commit
0b98e84e9ba0 ("freedreno: native fence fd"), enabled for kernel
driver version 1.1 or later.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-By: Wladimir J. van der Laan <laanwj@gmail.com>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
configure.ac
src/gallium/drivers/etnaviv/etnaviv_context.c
src/gallium/drivers/etnaviv/etnaviv_context.h
src/gallium/drivers/etnaviv/etnaviv_fence.c
src/gallium/drivers/etnaviv/etnaviv_fence.h
src/gallium/drivers/etnaviv/etnaviv_screen.c
src/gallium/drivers/etnaviv/etnaviv_screen.h

index 957991cef7fcef007d89f51e7527ab2c4fa89e3d..ef19733423e45297c0919d14d917ec1e000a6bab 100644 (file)
@@ -80,7 +80,7 @@ LIBDRM_NVVIEUX_REQUIRED=2.4.66
 LIBDRM_NOUVEAU_REQUIRED=2.4.66
 LIBDRM_FREEDRENO_REQUIRED=2.4.74
 LIBDRM_VC4_REQUIRED=2.4.69
-LIBDRM_ETNAVIV_REQUIRED=2.4.74
+LIBDRM_ETNAVIV_REQUIRED=2.4.80
 
 dnl Versions for external dependencies
 DRI2PROTO_REQUIRED=2.8
index f2f709cbf24f1365d2d282d075f59c80822d29ec..cfbc9065426b1aa743ed12d22acf4c117b60a17d 100644 (file)
@@ -73,6 +73,9 @@ etna_context_destroy(struct pipe_context *pctx)
 
    slab_destroy_child(&ctx->transfer_pool);
 
+   if (ctx->in_fence_fd != -1)
+      close(ctx->in_fence_fd);
+
    FREE(pctx);
 }
 
@@ -275,11 +278,14 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
            enum pipe_flush_flags flags)
 {
    struct etna_context *ctx = etna_context(pctx);
+   int out_fence_fd = -1;
 
-   etna_cmd_stream_flush(ctx->stream);
+   etna_cmd_stream_flush2(ctx->stream, ctx->in_fence_fd,
+                         (flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd :
+                         NULL);
 
    if (fence)
-      *fence = etna_fence_create(pctx);
+      *fence = etna_fence_create(pctx, out_fence_fd);
 }
 
 static void
@@ -356,10 +362,14 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
    /*  Set sensible defaults for state */
    etna_cmd_stream_reset_notify(ctx->stream, ctx);
 
+   ctx->in_fence_fd = -1;
+
    pctx->destroy = etna_context_destroy;
    pctx->draw_vbo = etna_draw_vbo;
    pctx->flush = etna_flush;
    pctx->set_debug_callback = etna_set_debug_callback;
+   pctx->create_fence_fd = etna_create_fence_fd;
+   pctx->fence_server_sync = etna_fence_server_sync;
 
    /* creation of compile states */
    pctx->create_blend_state = etna_blend_state_create;
index 9e00d34d23a2f822ba4835ab5c088a768a2b4a95..56b57b55a8160d0ecdd4ad95f6eb845745664719 100644 (file)
@@ -178,6 +178,7 @@ struct etna_context {
    } stats;
 
    struct pipe_debug_callback debug;
+   int in_fence_fd;
 };
 
 static inline struct etna_context *
index 02f520b8b32385c571a9b61a010e400cbb03d170..65402aaa3bde0bd9c0e0db05adb76ee5f95b0b04 100644 (file)
@@ -25,6 +25,8 @@
  *    Rob Clark <robclark@freedesktop.org>
  */
 
+#include <libsync.h>
+
 #include "etnaviv_fence.h"
 #include "etnaviv_context.h"
 #include "etnaviv_screen.h"
@@ -36,16 +38,25 @@ struct pipe_fence_handle {
    struct pipe_reference reference;
    struct etna_context *ctx;
    struct etna_screen *screen;
+   int fence_fd;
    uint32_t timestamp;
 };
 
+static void
+etna_fence_destroy(struct pipe_fence_handle *fence)
+{
+   if (fence->fence_fd != -1)
+      close(fence->fence_fd);
+   FREE(fence);
+}
+
 static void
 etna_screen_fence_reference(struct pipe_screen *pscreen,
                             struct pipe_fence_handle **ptr,
                             struct pipe_fence_handle *fence)
 {
    if (pipe_reference(&(*ptr)->reference, &fence->reference))
-      FREE(*ptr);
+      etna_fence_destroy(*ptr);
 
    *ptr = fence;
 }
@@ -54,14 +65,42 @@ static boolean
 etna_screen_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
                          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 (etna_pipe_wait_ns(fence->screen->pipe, fence->timestamp, timeout))
       return false;
 
    return true;
 }
 
+void
+etna_create_fence_fd(struct pipe_context *pctx,
+                     struct pipe_fence_handle **pfence, int fd)
+{
+   *pfence = etna_fence_create(pctx, dup(fd));
+}
+
+void
+etna_fence_server_sync(struct pipe_context *pctx,
+                       struct pipe_fence_handle *pfence)
+{
+   struct etna_context *ctx = etna_context(pctx);
+
+   sync_accumulate("etnaviv", &ctx->in_fence_fd, pfence->fence_fd);
+}
+
+static int
+etna_screen_fence_get_fd(struct pipe_screen *pscreen,
+                         struct pipe_fence_handle *pfence)
+{
+   return dup(pfence->fence_fd);
+}
+
 struct pipe_fence_handle *
-etna_fence_create(struct pipe_context *pctx)
+etna_fence_create(struct pipe_context *pctx, int fence_fd)
 {
    struct pipe_fence_handle *fence;
    struct etna_context *ctx = etna_context(pctx);
@@ -75,6 +114,7 @@ etna_fence_create(struct pipe_context *pctx)
    fence->ctx = ctx;
    fence->screen = ctx->screen;
    fence->timestamp = etna_cmd_stream_timestamp(ctx->stream);
+   fence->fence_fd = fence_fd;
 
    return fence;
 }
@@ -84,4 +124,5 @@ etna_fence_screen_init(struct pipe_screen *pscreen)
 {
    pscreen->fence_reference = etna_screen_fence_reference;
    pscreen->fence_finish = etna_screen_fence_finish;
+   pscreen->fence_get_fd = etna_screen_fence_get_fd;
 }
index cd91d2e19ed644faf793952ca68bb47eda6fd9c9..cd68a428d3f83314e2c923b1c8a5fa70c913de32 100644 (file)
 
 #include "pipe/p_context.h"
 
+void
+etna_create_fence_fd(struct pipe_context *pctx,
+                     struct pipe_fence_handle **pfence, int fd);
+
+void
+etna_fence_server_sync(struct pipe_context *pctx,
+                       struct pipe_fence_handle *fence);
+
+int
+etna_fence_get_fd(struct pipe_screen *pscreen,
+                  struct pipe_fence_handle *pfence);
+
 struct pipe_fence_handle *
-etna_fence_create(struct pipe_context *pctx);
+etna_fence_create(struct pipe_context *pctx, int fence_fd);
 
 void
 etna_fence_screen_init(struct pipe_screen *pscreen);
index f61b7f6de30a0dca42a34e862eeb64deee3a5c1c..626f7c77898555acda91741364af7ffa69e812d0 100644 (file)
@@ -45,6 +45,9 @@
 
 #include "state_tracker/drm_driver.h"
 
+#define ETNA_DRM_VERSION(major, minor) ((major) << 16 | (minor))
+#define ETNA_DRM_VERSION_FENCE_FD      ETNA_DRM_VERSION(1, 1)
+
 static const struct debug_named_value debug_options[] = {
    {"dbg_msgs",       ETNA_DBG_MSGS, "Print debug messages"},
    {"frame_msgs",     ETNA_DBG_FRAME_MSGS, "Print frame messages"},
@@ -137,6 +140,8 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_TGSI_TEXCOORD:
    case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
       return 1;
+   case PIPE_CAP_NATIVE_FENCE_FD:
+      return screen->drm_version >= ETNA_DRM_VERSION_FENCE_FD;
 
    /* Memory */
    case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
@@ -237,7 +242,6 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
    case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
    case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
-   case PIPE_CAP_NATIVE_FENCE_FD:
    case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
    case PIPE_CAP_TGSI_FS_FBFETCH:
    case PIPE_CAP_TGSI_MUL_ZERO_WINS:
@@ -736,6 +740,7 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu,
 {
    struct etna_screen *screen = CALLOC_STRUCT(etna_screen);
    struct pipe_screen *pscreen;
+   drmVersionPtr version;
    uint64_t val;
 
    if (!screen)
@@ -751,6 +756,11 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu,
       goto fail;
    }
 
+   version = drmGetVersion(screen->ro->gpu_fd);
+   screen->drm_version = ETNA_DRM_VERSION(version->version_major,
+                                          version->version_minor);
+   drmFreeVersion(version);
+
    etna_mesa_debug = debug_get_option_etna_mesa_debug();
 
    /* Disable autodisable for correct rendering with TS */
index a606e5d7080c9407e922c01b1f3b24c414886353..bec740b0a000a14bdb9d1c4aec97606e0a6b4865 100644 (file)
@@ -74,6 +74,8 @@ struct etna_screen {
    uint32_t features[VIV_FEATURES_WORD_COUNT];
 
    struct etna_specs specs;
+
+   uint32_t drm_version;
 };
 
 static inline struct etna_screen *