[Mesa-dev] [RFC] etnaviv: native fence fd support

Christian Gmeiner christian.gmeiner at gmail.com
Wed Apr 5 17:46:06 UTC 2017


2017-04-05 18:14 GMT+02:00 Philipp Zabel <p.zabel at pengutronix.de>:
> 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 at pengutronix.de>
> ---
> This depends on libdrm patches [1][2] which may or may not make their
> way into libdrm 2.4.78.
> [1] https://patchwork.kernel.org/patch/9664401/
> [2] https://patchwork.kernel.org/patch/9664403/
> ---
>  configure.ac                                  |  2 +-
>  src/gallium/drivers/etnaviv/etnaviv_context.c | 17 ++++++++--
>  src/gallium/drivers/etnaviv/etnaviv_context.h |  1 +
>  src/gallium/drivers/etnaviv/etnaviv_fence.c   | 46 +++++++++++++++++++++++++--
>  src/gallium/drivers/etnaviv/etnaviv_fence.h   | 14 +++++++-
>  src/gallium/drivers/etnaviv/etnaviv_screen.c  | 10 +++++-
>  src/gallium/drivers/etnaviv/etnaviv_screen.h  |  3 ++
>  7 files changed, 86 insertions(+), 7 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 1c60a59823..a5e1d69912 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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.78
>
>  dnl Versions for external dependencies
>  DRI2PROTO_REQUIRED=2.8
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c
> index dfd9e1f73a..14170342ff 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_context.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
> @@ -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);
>  }
>
> @@ -230,11 +233,17 @@ 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);
> +   if (ctx->in_fence_fd != -1 || (flags & PIPE_FLUSH_FENCE_FD))
> +      etna_cmd_stream_flush_explicit(ctx->stream, ctx->in_fence_fd,
> +                                     (flags & PIPE_FLUSH_FENCE_FD) ?
> +                                     &out_fence_fd : NULL);
> +   else
> +      etna_cmd_stream_flush(ctx->stream);
>
>     if (fence)
> -      *fence = etna_fence_create(pctx);
> +      *fence = etna_fence_create(pctx, out_fence_fd);
>  }
>
>  static void
> @@ -308,10 +317,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;
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h b/src/gallium/drivers/etnaviv/etnaviv_context.h
> index a9214034af..700a39c4cb 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_context.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
> @@ -176,6 +176,7 @@ struct etna_context {
>     } stats;
>
>     struct pipe_debug_callback debug;
> +   int in_fence_fd;
>  };
>
>  static inline struct etna_context *
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_fence.c b/src/gallium/drivers/etnaviv/etnaviv_fence.c
> index 02f520b8b3..ff46e32863 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_fence.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_fence.c
> @@ -25,6 +25,8 @@
>   *    Rob Clark <robclark at 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,43 @@ 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);
> +
> +   /* FIXME: where should in_fence_fd be stored? */
> +   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 +115,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 +125,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;
>  }
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_fence.h b/src/gallium/drivers/etnaviv/etnaviv_fence.h
> index cd91d2e19e..cd68a428d3 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_fence.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_fence.h
> @@ -30,8 +30,20 @@
>
>  #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);
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c
> index 151a1e031e..6703969b0a 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
> @@ -137,6 +137,9 @@ 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_major > 1 ||
> +             (screen->drm_major == 1 && screen->drm_minor >= 1);
>

I would like to see a etna_device_version(..) in libdrm-etnaviv and used like:
    return etna_device_version(screen->dev) >= ETNA_VERSION_FENCE_FD;

>     /* Memory */
>     case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
> @@ -237,7 +240,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:
> @@ -734,6 +736,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)
> @@ -749,6 +752,11 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu,
>        goto fail;
>     }
>
> +   version = drmGetVersion(screen->ro->gpu_fd);
> +   screen->drm_major = version->version_major;
> +   screen->drm_minor = version->version_minor;
> +   drmFreeVersion(version);
> +
>     etna_mesa_debug = debug_get_option_etna_mesa_debug();
>
>     /* FIXME: Disable tile status for stability at the moment */
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.h b/src/gallium/drivers/etnaviv/etnaviv_screen.h
> index c33a9e32fa..015ff6bb31 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_screen.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.h
> @@ -72,6 +72,9 @@ struct etna_screen {
>     uint32_t features[5];
>
>     struct etna_specs specs;
> +
> +   int drm_major;
> +   int drm_minor;
>  };
>
>  static inline struct etna_screen *
> --
> 2.11.0
>

greets
--
Christian Gmeiner, MSc

https://www.youtube.com/user/AloryOFFICIAL
https://soundcloud.com/christian-gmeiner


More information about the mesa-dev mailing list