From 3bd6244579c636ee0a1c6813b73758a3b200470c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 23 Dec 2020 14:14:47 -0800 Subject: [PATCH] virgl: return res from virgl_resource_create_* This allows the callers to modify the returned virgl_resource without looking up. Signed-off-by: Chia-I Wu Reviewed-by: Isaac Bosompem --- src/virgl_resource.c | 18 +++++++++--------- src/virgl_resource.h | 6 +++--- src/virglrenderer.c | 28 +++++++++++++++------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/virgl_resource.c b/src/virgl_resource.c index e3c9423..c58dd70 100644 --- a/src/virgl_resource.c +++ b/src/virgl_resource.c @@ -102,7 +102,7 @@ virgl_resource_create(uint32_t res_id) return res; } -int +struct virgl_resource * virgl_resource_create_from_pipe(uint32_t res_id, struct pipe_resource *pres, const struct iovec *iov, @@ -112,7 +112,7 @@ virgl_resource_create_from_pipe(uint32_t res_id, res = virgl_resource_create(res_id); if (!res) - return ENOMEM; + return NULL; /* take ownership */ res->pipe_resource = pres; @@ -120,10 +120,10 @@ virgl_resource_create_from_pipe(uint32_t res_id, res->iov = iov; res->iov_count = iov_count; - return 0; + return res; } -int +struct virgl_resource * virgl_resource_create_from_fd(uint32_t res_id, enum virgl_resource_fd_type fd_type, int fd, @@ -136,7 +136,7 @@ virgl_resource_create_from_fd(uint32_t res_id, res = virgl_resource_create(res_id); if (!res) - return ENOMEM; + return NULL; res->fd_type = fd_type; /* take ownership */ @@ -145,10 +145,10 @@ virgl_resource_create_from_fd(uint32_t res_id, res->iov = iov; res->iov_count = iov_count; - return 0; + return res; } -int +struct virgl_resource * virgl_resource_create_from_iov(uint32_t res_id, const struct iovec *iov, int iov_count) @@ -160,12 +160,12 @@ virgl_resource_create_from_iov(uint32_t res_id, res = virgl_resource_create(res_id); if (!res) - return ENOMEM; + return NULL; res->iov = iov; res->iov_count = iov_count; - return 0; + return res; } void diff --git a/src/virgl_resource.h b/src/virgl_resource.h index cdd7336..34d92a8 100644 --- a/src/virgl_resource.h +++ b/src/virgl_resource.h @@ -94,20 +94,20 @@ virgl_resource_table_cleanup(void); void virgl_resource_table_reset(void); -int +struct virgl_resource * virgl_resource_create_from_pipe(uint32_t res_id, struct pipe_resource *pres, const struct iovec *iov, int iov_count); -int +struct virgl_resource * virgl_resource_create_from_fd(uint32_t res_id, enum virgl_resource_fd_type fd_type, int fd, const struct iovec *iov, int iov_count); -int +struct virgl_resource * virgl_resource_create_from_iov(uint32_t res_id, const struct iovec *iov, int iov_count); diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 5c57233..1b9f86d 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -65,7 +65,7 @@ static int virgl_renderer_resource_create_internal(struct virgl_renderer_resourc UNUSED struct iovec *iov, UNUSED uint32_t num_iovs, void *image) { - int ret; + struct virgl_resource *res; struct pipe_resource *pipe_res; struct vrend_renderer_resource_create_args vrend_args = { 0 }; @@ -88,10 +88,10 @@ static int virgl_renderer_resource_create_internal(struct virgl_renderer_resourc if (!pipe_res) return EINVAL; - ret = virgl_resource_create_from_pipe(args->handle, pipe_res, iov, num_iovs); - if (ret) { + res = virgl_resource_create_from_pipe(args->handle, pipe_res, iov, num_iovs); + if (!res) { vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res); - return ret; + return -ENOMEM; } return 0; @@ -668,6 +668,7 @@ int virgl_renderer_execute(void *execute_args, uint32_t execute_size) int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_create_blob_args *args) { TRACE_FUNC(); + struct virgl_resource *res; struct virgl_context *ctx; struct virgl_context_blob blob; bool has_host_storage; @@ -707,9 +708,10 @@ int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_cre } if (!has_host_storage) { - return virgl_resource_create_from_iov(args->res_handle, - args->iovecs, - args->num_iovs); + res = virgl_resource_create_from_iov(args->res_handle, + args->iovecs, + args->num_iovs); + return res ? 0 : -ENOMEM; } ctx = virgl_context_lookup(args->ctx_id); @@ -721,23 +723,23 @@ int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_cre return ret; if (blob.type != VIRGL_RESOURCE_FD_INVALID) { - ret = virgl_resource_create_from_fd(args->res_handle, + res = virgl_resource_create_from_fd(args->res_handle, blob.type, blob.u.fd, args->iovecs, args->num_iovs); - if (ret) { + if (!res) { close(blob.u.fd); - return ret; + return -ENOMEM; } } else { - ret = virgl_resource_create_from_pipe(args->res_handle, + res = virgl_resource_create_from_pipe(args->res_handle, blob.u.pipe_resource, args->iovecs, args->num_iovs); - if (ret) { + if (!res) { vrend_renderer_resource_destroy((struct vrend_resource *)blob.u.pipe_resource); - return ret; + return -ENOMEM; } }