summaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2019-04-09 18:18:43 +0000
committerGurchetan Singh <[email protected]>2019-04-15 23:25:47 +0000
commit334103efbfcd37488eed49e16871f46d56d8e9a8 (patch)
tree2c93f4d1f96ec57a3bb6fcd8186fd0d90e15baeb /src/gallium/winsys
parenta23c091988f30fd432b5e1a68aedc95c307efa34 (diff)
virgl: hide fence internals from the driver
Fence fds are cheaper than resources. We want to let winsys make the decision and use fence fds whenever they are supported. This commit prepares the work. For the moment, we create a resource _and_ a fence fd when supports_fences is true. This will be fixed such that we create a resource _or_ a fence fd. (And because of a version check bug that we will fix later, supports_fences is actually never true). Signed-off-by: Chia-I Wu <[email protected]> Reviewed-by: Emil Velikov <[email protected]>
Diffstat (limited to 'src/gallium/winsys')
-rw-r--r--src/gallium/winsys/virgl/drm/virgl_drm_winsys.c40
-rw-r--r--src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c30
2 files changed, 42 insertions, 28 deletions
diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
index 1c5ec714e25..2cd4bf70429 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
@@ -709,9 +709,24 @@ static void virgl_drm_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
}
+static struct pipe_fence_handle *
+virgl_drm_fence_create(struct virgl_winsys *vws, int fd)
+{
+ struct virgl_hw_res *res;
+
+ res = virgl_drm_winsys_resource_cache_create(vws,
+ PIPE_BUFFER,
+ PIPE_FORMAT_R8_UNORM,
+ VIRGL_BIND_CUSTOM,
+ 8, 1, 1, 0, 0, 0, 8);
+
+ res->fence_fd = fd;
+ return (struct pipe_fence_handle *)res;
+}
+
static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
struct virgl_cmd_buf *_cbuf,
- int *out_fence_fd)
+ struct pipe_fence_handle **fence)
{
struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
struct virgl_drm_cmd_buf *cbuf = virgl_drm_cmd_buf(_cbuf);
@@ -734,11 +749,10 @@ static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
eb.fence_fd = cbuf->in_fence_fd;
}
- if (out_fence_fd != NULL)
+ if (fence != NULL)
eb.flags |= VIRTGPU_EXECBUF_FENCE_FD_OUT;
} else {
assert(cbuf->in_fence_fd < 0);
- assert(out_fence_fd == NULL);
}
ret = drmIoctl(qdws->fd, DRM_IOCTL_VIRTGPU_EXECBUFFER, &eb);
@@ -751,10 +765,13 @@ static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
close(cbuf->in_fence_fd);
cbuf->in_fence_fd = -1;
}
- }
- if (out_fence_fd != NULL)
- *out_fence_fd = eb.fence_fd;
+ if (fence != NULL && ret == 0)
+ *fence = virgl_drm_fence_create(qws, eb.fence_fd);
+ } else {
+ if (fence != NULL && ret == 0)
+ *fence = virgl_drm_fence_create(qws, -1);
+ }
virgl_drm_release_all_res(qdws, cbuf);
@@ -809,16 +826,7 @@ static int handle_compare(void *key1, void *key2)
static struct pipe_fence_handle *
virgl_cs_create_fence(struct virgl_winsys *vws, int fd)
{
- struct virgl_hw_res *res;
-
- res = virgl_drm_winsys_resource_cache_create(vws,
- PIPE_BUFFER,
- PIPE_FORMAT_R8_UNORM,
- VIRGL_BIND_CUSTOM,
- 8, 1, 1, 0, 0, 0, 8);
-
- res->fence_fd = fd;
- return (struct pipe_fence_handle *)res;
+ return virgl_drm_fence_create(vws, fd);
}
static bool virgl_fence_wait(struct virgl_winsys *vws,
diff --git a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
index 2ea0187fec9..e3a38e00ec5 100644
--- a/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
+++ b/src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c
@@ -486,9 +486,23 @@ static void virgl_vtest_cmd_buf_destroy(struct virgl_cmd_buf *_cbuf)
FREE(cbuf);
}
+static struct pipe_fence_handle *
+virgl_vtest_fence_create(struct virgl_winsys *vws)
+{
+ struct virgl_hw_res *res;
+
+ res = virgl_vtest_winsys_resource_cache_create(vws,
+ PIPE_BUFFER,
+ PIPE_FORMAT_R8_UNORM,
+ VIRGL_BIND_CUSTOM,
+ 8, 1, 1, 0, 0, 0, 8);
+
+ return (struct pipe_fence_handle *)res;
+}
+
static int virgl_vtest_winsys_submit_cmd(struct virgl_winsys *vws,
struct virgl_cmd_buf *_cbuf,
- int *out_fence_fd)
+ struct pipe_fence_handle **fence)
{
struct virgl_vtest_winsys *vtws = virgl_vtest_winsys(vws);
struct virgl_vtest_cmd_buf *cbuf = virgl_vtest_cmd_buf(_cbuf);
@@ -497,9 +511,9 @@ static int virgl_vtest_winsys_submit_cmd(struct virgl_winsys *vws,
if (cbuf->base.cdw == 0)
return 0;
- assert(out_fence_fd == NULL);
-
ret = virgl_vtest_submit_cmd(vtws, cbuf);
+ if (fence && ret == 0)
+ *fence = virgl_vtest_fence_create(vws);
virgl_vtest_release_all_res(vtws, cbuf);
memset(cbuf->is_handle_added, 0, sizeof(cbuf->is_handle_added));
@@ -543,15 +557,7 @@ static int virgl_vtest_get_caps(struct virgl_winsys *vws,
static struct pipe_fence_handle *
virgl_cs_create_fence(struct virgl_winsys *vws, int fd)
{
- struct virgl_hw_res *res;
-
- res = virgl_vtest_winsys_resource_cache_create(vws,
- PIPE_BUFFER,
- PIPE_FORMAT_R8_UNORM,
- VIRGL_BIND_CUSTOM,
- 8, 1, 1, 0, 0, 0, 8);
-
- return (struct pipe_fence_handle *)res;
+ return virgl_vtest_fence_create(vws);
}
static bool virgl_fence_wait(struct virgl_winsys *vws,