summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2017-04-12 12:31:01 +0200
committerChristian Gmeiner <christian.gmeiner@gmail.com>2017-04-15 01:47:18 +0200
commit36f21017237ab536db74c84e0f778d3a58271c75 (patch)
tree399a8b2a5831dc764be6a80f4eafb76db62a8d78 /src
parent96dfc014fd33a4f38e31fa1d4c9c4ea52d85a0b8 (diff)
etnaviv: native fence fd support
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>
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_context.c14
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_context.h1
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_fence.c45
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_fence.h14
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_screen.c12
-rw-r--r--src/gallium/drivers/etnaviv/etnaviv_screen.h2
6 files changed, 82 insertions, 6 deletions
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c
index f2f709cbf2..cfbc906542 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
@@ -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;
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@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 f61b7f6de3..626f7c7789 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:
@@ -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 */
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.h b/src/gallium/drivers/etnaviv/etnaviv_screen.h
index a606e5d708..bec740b0a0 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.h
@@ -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 *