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 <olvaffe@gmail.com>
Reviewed-by: Isaac Bosompem <mrisaacb@google.com>
macos/master
Chia-I Wu 4 years ago
parent 4215cb7aa7
commit 3bd6244579
  1. 18
      src/virgl_resource.c
  2. 6
      src/virgl_resource.h
  3. 24
      src/virglrenderer.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

@ -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);

@ -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,
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;
}
}

Loading…
Cancel
Save