vrend: refactor creating a vrend_resource

This is a cleanup for the subsequent commits.

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Gurchetan Singh 5 years ago
parent 7b6b643878
commit 95ce73010a
  1. 43
      src/virglrenderer.c
  2. 29
      src/vrend_renderer.c
  3. 7
      src/vrend_renderer.h

@ -53,11 +53,39 @@ static struct virgl_glx *glx_info;
/* new API - just wrap internal API for now */ /* new API - just wrap internal API for now */
int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs) static int virgl_renderer_resource_create_internal(struct virgl_renderer_resource_create_args *args,
UNUSED struct iovec *iov, UNUSED uint32_t num_iovs,
void *image)
{ {
int ret; int ret;
struct pipe_resource *pipe_res;
struct vrend_renderer_resource_create_args vrend_args = { 0 };
/* do not accept handle 0 */
if (args->handle == 0)
return EINVAL;
vrend_args.target = args->target;
vrend_args.format = args->format;
vrend_args.bind = args->bind;
vrend_args.width = args->width;
vrend_args.height = args->height;
vrend_args.depth = args->depth;
vrend_args.array_size = args->array_size;
vrend_args.nr_samples = args->nr_samples;
vrend_args.last_level = args->last_level;
vrend_args.flags = args->flags;
pipe_res = vrend_renderer_resource_create(&vrend_args, image);
if (!pipe_res)
return EINVAL;
ret = virgl_resource_create_from_pipe(args->handle, pipe_res);
if (ret) {
vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res);
return ret;
}
ret = vrend_renderer_resource_create((struct vrend_renderer_resource_create_args *)args, NULL);
if (!ret && num_iovs) { if (!ret && num_iovs) {
ret = virgl_renderer_resource_attach_iov(args->handle, iov, num_iovs); ret = virgl_renderer_resource_attach_iov(args->handle, iov, num_iovs);
if (ret) { if (ret) {
@ -66,13 +94,19 @@ int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *a
} }
} }
return ret; return 0;
}
int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *args,
struct iovec *iov, uint32_t num_iovs)
{
return virgl_renderer_resource_create_internal(args, iov, num_iovs, NULL);
} }
int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_create_args *args, void *image) int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_create_args *args, void *image)
{ {
#ifdef HAVE_EPOXY_EGL_H #ifdef HAVE_EPOXY_EGL_H
return vrend_renderer_resource_create((struct vrend_renderer_resource_create_args *)args, image); return virgl_renderer_resource_create_internal(args, NULL, 0, image);
#else #else
return EINVAL; return EINVAL;
#endif #endif
@ -308,6 +342,7 @@ int virgl_renderer_resource_get_info(int res_handle,
ret = vrend_renderer_resource_get_info(res->pipe_resource, ret = vrend_renderer_resource_get_info(res->pipe_resource,
(struct vrend_renderer_resource_info *)info); (struct vrend_renderer_resource_info *)info);
info->handle = res_handle;
#ifdef HAVE_EPOXY_EGL_H #ifdef HAVE_EPOXY_EGL_H
if (ret == 0 && use_context == CONTEXT_EGL) if (ret == 0 && use_context == CONTEXT_EGL)
return virgl_egl_get_fourcc_for_texture(egl, info->tex_id, info->virgl_format, &info->drm_fourcc); return virgl_egl_get_fourcc_for_texture(egl, info->tex_id, info->virgl_format, &info->drm_fourcc);

@ -6154,12 +6154,6 @@ struct vrend_context *vrend_create_context(int id, uint32_t nlen, const char *de
static int check_resource_valid(struct vrend_renderer_resource_create_args *args, static int check_resource_valid(struct vrend_renderer_resource_create_args *args,
char errmsg[256]) char errmsg[256])
{ {
/* do not accept handle 0 */
if (args->handle == 0) {
snprintf(errmsg, 256, "Invalid handle");
return -1;
}
/* limit the target */ /* limit the target */
if (args->target >= PIPE_MAX_TEXTURE_TYPES) { if (args->target >= PIPE_MAX_TEXTURE_TYPES) {
snprintf(errmsg, 256, "Invalid texture target %d (>= %d)", snprintf(errmsg, 256, "Invalid texture target %d (>= %d)",
@ -6400,7 +6394,6 @@ vrend_renderer_resource_copy_args(struct vrend_renderer_resource_create_args *ar
assert(gr); assert(gr);
assert(args); assert(args);
gr->handle = args->handle;
gr->base.bind = args->bind; gr->base.bind = args->bind;
gr->base.width0 = args->width; gr->base.width0 = args->width;
gr->base.height0 = args->height; gr->base.height0 = args->height;
@ -6668,8 +6661,8 @@ static int vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
return 0; return 0;
} }
int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct pipe_resource *
void *image_oes) vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, void *image_oes)
{ {
struct vrend_resource *gr; struct vrend_resource *gr;
int ret; int ret;
@ -6678,12 +6671,12 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
ret = check_resource_valid(args, error_string); ret = check_resource_valid(args, error_string);
if (ret) { if (ret) {
vrend_printf("%s, Illegal resource parameters, error: %s\n", __func__, error_string); vrend_printf("%s, Illegal resource parameters, error: %s\n", __func__, error_string);
return EINVAL; return NULL;
} }
gr = (struct vrend_resource *)CALLOC_STRUCT(vrend_texture); gr = (struct vrend_resource *)CALLOC_STRUCT(vrend_texture);
if (!gr) if (!gr)
return ENOMEM; return NULL;
vrend_renderer_resource_copy_args(args, gr); vrend_renderer_resource_copy_args(args, gr);
gr->storage_bits = VREND_STORAGE_GUEST_MEMORY; gr->storage_bits = VREND_STORAGE_GUEST_MEMORY;
@ -6700,7 +6693,7 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
gr->ptr = malloc(args->width); gr->ptr = malloc(args->width);
if (!gr->ptr) { if (!gr->ptr) {
FREE(gr); FREE(gr);
return ENOMEM; return NULL;
} }
} else if (args->bind == VIRGL_BIND_STAGING) { } else if (args->bind == VIRGL_BIND_STAGING) {
/* staging buffers only use guest memory -- nothing to do. */ /* staging buffers only use guest memory -- nothing to do. */
@ -6744,22 +6737,17 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
} else { } else {
vrend_printf("%s: Illegal buffer binding flags 0x%x\n", __func__, args->bind); vrend_printf("%s: Illegal buffer binding flags 0x%x\n", __func__, args->bind);
FREE(gr); FREE(gr);
return EINVAL; return NULL;
} }
} else { } else {
int r = vrend_renderer_resource_allocate_texture(gr, image_oes); int r = vrend_renderer_resource_allocate_texture(gr, image_oes);
if (r) { if (r) {
FREE(gr); FREE(gr);
return r; return NULL;
} }
} }
ret = virgl_resource_create_from_pipe(args->handle, &gr->base); return &gr->base;
if (ret) {
vrend_renderer_resource_destroy(gr);
return ret;
}
return 0;
} }
void vrend_renderer_resource_destroy(struct vrend_resource *res) void vrend_renderer_resource_destroy(struct vrend_resource *res)
@ -10125,7 +10113,6 @@ int vrend_renderer_resource_get_info(struct pipe_resource *pres,
elsize = util_format_get_blocksize(res->base.format); elsize = util_format_get_blocksize(res->base.format);
info->handle = res->handle;
info->tex_id = res->id; info->tex_id = res->id;
info->width = res->base.width0; info->width = res->base.width0;
info->height = res->base.height0; info->height = res->base.height0;

@ -88,8 +88,6 @@ struct vrend_resource {
GLuint tbo_tex_id;/* tbos have two ids to track */ GLuint tbo_tex_id;/* tbos have two ids to track */
bool y_0_top; bool y_0_top;
GLuint handle;
/* Pointer to system memory storage for this resource. Only valid for /* Pointer to system memory storage for this resource. Only valid for
* VREND_RESOURCE_STORAGE_GUEST_ELSE_SYSTEM buffer storage. * VREND_RESOURCE_STORAGE_GUEST_ELSE_SYSTEM buffer storage.
*/ */
@ -174,7 +172,6 @@ struct virgl_context *vrend_renderer_context_create(uint32_t handle,
const char *name); const char *name);
struct vrend_renderer_resource_create_args { struct vrend_renderer_resource_create_args {
uint32_t handle;
enum pipe_texture_target target; enum pipe_texture_target target;
uint32_t format; uint32_t format;
uint32_t bind; uint32_t bind;
@ -187,8 +184,8 @@ struct vrend_renderer_resource_create_args {
uint32_t flags; uint32_t flags;
}; };
int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct pipe_resource *
void *image_eos); vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, void *image_eos);
int vrend_create_surface(struct vrend_context *ctx, int vrend_create_surface(struct vrend_context *ctx,
uint32_t handle, uint32_t handle,

Loading…
Cancel
Save