* fired off as our fence marker.
*/
+#include <libsync.h>
#include <fcntl.h>
#include "util/u_inlines.h"
return f;
}
+static void
+v3d_fence_create_fd(struct pipe_context *pctx, struct pipe_fence_handle **pf,
+ int fd, enum pipe_fd_type type)
+{
+ struct v3d_fence **fence = (struct v3d_fence **)pf;
+ struct v3d_fence *f = calloc(1, sizeof(*f));
+
+ assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
+
+ if (f) {
+ pipe_reference_init(&f->reference, 1);
+ f->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
+ }
+
+ *fence = f;
+}
+
+static void
+v3d_fence_server_sync(struct pipe_context *pctx,
+ struct pipe_fence_handle *pfence)
+{
+ struct v3d_context *v3d = (struct v3d_context *)pctx;
+ struct v3d_fence *fence = (struct v3d_fence *)pfence;
+
+ if (fence->fd >= 0)
+ sync_accumulate("v3d", &v3d->in_fence_fd, fence->fd);
+}
+
static int
v3d_fence_get_fd(struct pipe_screen *screen, struct pipe_fence_handle *pfence)
{
return fcntl(fence->fd, F_DUPFD_CLOEXEC, 3);
}
+int
+v3d_fence_context_init(struct v3d_context *v3d)
+{
+ v3d->base.create_fence_fd = v3d_fence_create_fd;
+ v3d->base.fence_server_sync = v3d_fence_server_sync;
+ v3d->in_fence_fd = -1;
+
+ /* Since we initialize the in_fence_fd to -1 (no wait necessary),
+ * we also need to initialize our in_syncobj as signaled.
+ */
+ if (v3d->screen->has_syncobj) {
+ return drmSyncobjCreate(v3d->fd, DRM_SYNCOBJ_CREATE_SIGNALED,
+ &v3d->in_syncobj);
+ } else {
+ return 0;
+ }
+}
+
void
v3d_fence_init(struct v3d_screen *screen)
{
* finished, we also need to block on any previous TFU job we may have
* dispatched.
*/
- job->submit.in_sync_rcl = v3d->out_sync;
+
+ if (screen->has_syncobj) {
+ if (v3d->in_fence_fd >= 0) {
+ /* This replaces the fence in the syncobj. */
+ drmSyncobjImportSyncFile(v3d->fd, v3d->in_syncobj,
+ v3d->in_fence_fd);
+ job->submit.in_sync_rcl = v3d->in_syncobj;
+ close(v3d->in_fence_fd);
+ v3d->in_fence_fd = -1;
+ }
+ } else {
+ job->submit.in_sync_rcl = v3d->out_sync;
+ }
/* Update the sync object for the last rendering by our context. */
job->submit.out_sync = v3d->out_sync;