virgl: flatten virgl_renderer_resource_create_blob

Add has_{host,guest}_storage and reduce the indentation.  There
should be no real change.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 4 years ago
parent 5e96edf216
commit 6761206ea9
  1. 72
      src/virglrenderer.c

@ -654,44 +654,56 @@ 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) int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_create_blob_args *args)
{ {
struct virgl_context *ctx;
int ret;
uint32_t blob_mem = args->blob_mem;
uint64_t blob_id = args->blob_id;
uint32_t res_handle = args->res_handle;
struct pipe_resource *pipe_res; struct pipe_resource *pipe_res;
bool has_host_storage;
bool has_guest_storage;
int ret;
if (blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D || switch (args->blob_mem) {
blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST) { case VIRGL_RENDERER_BLOB_MEM_GUEST:
struct virgl_context *ctx = virgl_context_lookup(args->ctx_id); has_host_storage = false;
if (!ctx) has_guest_storage = true;
return -EINVAL; break;
case VIRGL_RENDERER_BLOB_MEM_HOST3D:
has_host_storage = true;
has_guest_storage = false;
break;
case VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST:
has_host_storage = true;
has_guest_storage = true;
break;
default:
return -EINVAL;
}
pipe_res = ctx->get_blob_pipe(ctx, blob_id); if (!has_host_storage) {
if (!pipe_res) return virgl_resource_create_from_iov(args->res_handle,
return -EINVAL; args->iovecs,
args->num_iovs);
}
ret = virgl_resource_create_from_pipe(res_handle, pipe_res); ctx = virgl_context_lookup(args->ctx_id);
if (ret) { if (!ctx)
vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res); return -EINVAL;
return ret;
}
if (blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST) { pipe_res = ctx->get_blob_pipe(ctx, args->blob_id);
ret = virgl_renderer_resource_attach_iov(res_handle, args->iovecs, args->num_iovs); if (!pipe_res)
if (ret) {
virgl_resource_remove(res_handle);
return ret;
}
}
} else if (blob_mem == VIRGL_RENDERER_BLOB_MEM_GUEST) {
ret = virgl_resource_create_from_iov(res_handle, args->iovecs, args->num_iovs);
if (ret)
return -EINVAL;
} else {
return -EINVAL; return -EINVAL;
ret = virgl_resource_create_from_pipe(args->res_handle, pipe_res);
if (ret) {
vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res);
return ret;
} }
if (has_guest_storage) {
ret = virgl_renderer_resource_attach_iov(args->res_handle, args->iovecs, args->num_iovs);
if (ret) {
virgl_resource_remove(args->res_handle);
return ret;
}
}
return 0; return 0;
} }

Loading…
Cancel
Save