diff options
-rw-r--r-- | src/gallium/drivers/v3d/v3d_context.c | 3 | ||||
-rw-r--r-- | src/gallium/drivers/v3d/v3d_context.h | 6 | ||||
-rw-r--r-- | src/gallium/drivers/v3d/v3d_fence.c | 47 | ||||
-rw-r--r-- | src/gallium/drivers/v3d/v3d_job.c | 14 |
4 files changed, 69 insertions, 1 deletions
diff --git a/src/gallium/drivers/v3d/v3d_context.c b/src/gallium/drivers/v3d/v3d_context.c index f931447111f..eef3612c64c 100644 --- a/src/gallium/drivers/v3d/v3d_context.c +++ b/src/gallium/drivers/v3d/v3d_context.c @@ -379,6 +379,9 @@ v3d_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) v3d->fd = screen->fd; + if(v3d_fence_context_init(v3d)) + goto fail; + slab_create_child(&v3d->transfer_pool, &screen->transfer_pool); v3d->uploader = u_upload_create_default(&v3d->base); diff --git a/src/gallium/drivers/v3d/v3d_context.h b/src/gallium/drivers/v3d/v3d_context.h index 04ff23e859d..66646df85f6 100644 --- a/src/gallium/drivers/v3d/v3d_context.h +++ b/src/gallium/drivers/v3d/v3d_context.h @@ -577,6 +577,9 @@ struct v3d_context { uint32_t prim_counts_offset; struct pipe_debug_callback debug; /** @} */ + + int in_fence_fd; + uint32_t in_syncobj; }; struct v3d_rasterizer_state { @@ -751,6 +754,9 @@ void v3d_get_tile_buffer_size(bool is_msaa, uint32_t *tile_width, uint32_t *tile_height, uint32_t *max_bpp); +int v3d_fence_context_init(struct v3d_context *v3d); + +void v3d_tf_update_counters(struct v3d_context *v3d); #ifdef v3dX # include "v3dx_context.h" diff --git a/src/gallium/drivers/v3d/v3d_fence.c b/src/gallium/drivers/v3d/v3d_fence.c index e969a207541..6958c4e65fd 100644 --- a/src/gallium/drivers/v3d/v3d_fence.c +++ b/src/gallium/drivers/v3d/v3d_fence.c @@ -34,6 +34,7 @@ * fired off as our fence marker. */ +#include <libsync.h> #include <fcntl.h> #include "util/u_inlines.h" @@ -122,6 +123,34 @@ v3d_fence_create(struct v3d_context *v3d) 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) { @@ -130,6 +159,24 @@ 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) { diff --git a/src/gallium/drivers/v3d/v3d_job.c b/src/gallium/drivers/v3d/v3d_job.c index 5b96d5582a0..e01729064ee 100644 --- a/src/gallium/drivers/v3d/v3d_job.c +++ b/src/gallium/drivers/v3d/v3d_job.c @@ -494,7 +494,19 @@ v3d_job_submit(struct v3d_context *v3d, struct v3d_job *job) * 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; |