From 2491f546811165db59e778164937839de6ed8d7e Mon Sep 17 00:00:00 2001 From: SolDev69 Date: Mon, 1 Jan 2024 11:48:53 -0500 Subject: [PATCH] move libsync useage to panfrost context I really hope this works --- src/android_stub/meson.build | 2 +- src/gallium/drivers/panfrost/pan_context.c | 53 +++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/android_stub/meson.build b/src/android_stub/meson.build index 0e3f27bc4a5..afcb5d92b4e 100644 --- a/src/android_stub/meson.build +++ b/src/android_stub/meson.build @@ -1,6 +1,6 @@ if with_android_stub stub_libs = [] - lib_names = ['hardware', 'log', 'nativewindow', 'sync'] + lib_names = ['hardware', 'log', 'nativewindow'] if with_libbacktrace lib_names += ['backtrace'] diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index e1fed545c4b..98f7c35497f 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -34,7 +34,6 @@ #include "util/format/u_format.h" #include "util/half_float.h" -#include "util/libsync.h" #include "util/macros.h" #include "util/u_debug_cb.h" #include "util/u_helpers.h" @@ -852,6 +851,58 @@ panfrost_create_fence_fd(struct pipe_context *pctx, *pfence = panfrost_fence_from_fd(pan_context(pctx), fd, type); } +struct sync_merge_data { + char name[32]; + int32_t fd2; + int32_t fence; + uint32_t flags; + uint32_t pad; +}; + +#define SYNC_IOC_MAGIC '>' +#define SYNC_IOC_MERGE _IOWR(SYNC_IOC_MAGIC, 3, struct sync_merge_data) + +static inline int sync_merge(const char *name, int fd1, int fd2) +{ + struct sync_merge_data data = {{0}}; + int ret; + + data.fd2 = fd2; + strncpy(data.name, name, sizeof(data.name)); + + do { + ret = ioctl(fd1, SYNC_IOC_MERGE, &data); + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); + + if (ret < 0) + return ret; + + return data.fence; +} + +static inline int sync_accumulate(const char *name, int *fd1, int fd2) +{ + int ret; + + assert(fd2 >= 0); + + if (*fd1 < 0) { + *fd1 = dup(fd2); + return 0; + } + + ret = sync_merge(name, *fd1, fd2); + if (ret < 0) { + /* leave *fd1 as it is */ + return ret; + } + + close(*fd1); + *fd1 = ret; + + return 0; +} + static void panfrost_fence_server_sync(struct pipe_context *pctx, struct pipe_fence_handle *f)