[PATCH v2] etnaviv: native fence fd support
Philipp Zabel
p.zabel at pengutronix.de
Fri Apr 7 12:21:35 UTC 2017
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>
---
v2: address review comments
- always call etna_cmd_stream_flush2
- remove FIXME comment about in_fence_fd storage
- simplify version check and add an ETNA_DRM_VERSION_FENCE_FD define
This depends on libdrm patches [1][2] which may or may not make their
way into libdrm 2.4.79.
[1] https://patchwork.kernel.org/patch/9669375/
[2] https://patchwork.kernel.org/patch/9669377/
---
configure.ac | 2 +-
src/gallium/drivers/etnaviv/etnaviv_context.c | 14 +++++++--
src/gallium/drivers/etnaviv/etnaviv_context.h | 1 +
src/gallium/drivers/etnaviv/etnaviv_fence.c | 45 +++++++++++++++++++++++++--
src/gallium/drivers/etnaviv/etnaviv_fence.h | 14 ++++++++-
src/gallium/drivers/etnaviv/etnaviv_screen.c | 12 ++++++-
src/gallium/drivers/etnaviv/etnaviv_screen.h | 2 ++
7 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 7d92b33a0f..e75f4a5ce5 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.79
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 555aa12765..09f782fc81 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);
}
@@ -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
@@ -353,10 +359,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 9e00d34d23..56b57b55a8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -178,6 +178,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..65402aaa3b 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,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;
}
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 0bd44004d9..16bca89baa 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -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:
@@ -731,6 +735,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)
@@ -746,6 +751,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();
/* 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..d3124343b3 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.h
@@ -72,6 +72,8 @@ struct etna_screen {
uint32_t features[5];
struct etna_specs specs;
+
+ uint32_t drm_version;
};
static inline struct etna_screen *
--
2.11.0
More information about the etnaviv
mailing list