server: remove redundant render_context_resource

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Yiwei Zhang 3 years ago
parent 1533b232e6
commit f94c675139
  1. 69
      server/render_context.c
  2. 2
      server/render_context.h

@ -14,11 +14,6 @@
#include "render_virgl.h" #include "render_virgl.h"
struct render_context_resource {
uint32_t res_id;
struct list_head head;
};
/* XXX we need a unique res_id to export a blob /* XXX we need a unique res_id to export a blob
* *
* virglrenderer.h does not have the right APIs for us. We should use vkr * virglrenderer.h does not have the right APIs for us. We should use vkr
@ -26,28 +21,12 @@ struct render_context_resource {
*/ */
#define BLOB_RES_ID (~0u) #define BLOB_RES_ID (~0u)
static void static int
render_context_resource_destroy(struct render_context_resource *res) render_context_import_blob(uint32_t res_id,
{
list_del(&res->head);
virgl_renderer_resource_unref(res->res_id);
free(res);
}
static struct render_context_resource *
render_context_resource_import(uint32_t res_id,
enum virgl_resource_fd_type fd_type, enum virgl_resource_fd_type fd_type,
int res_fd, int res_fd,
uint64_t size) uint64_t size)
{ {
/* TODO pool alloc if resources come and go frequently */
struct render_context_resource *res = calloc(1, sizeof(*res));
if (!res)
return NULL;
res->res_id = res_id;
uint32_t import_fd_type; uint32_t import_fd_type;
switch (fd_type) { switch (fd_type) {
case VIRGL_RESOURCE_FD_DMABUF: case VIRGL_RESOURCE_FD_DMABUF:
@ -64,20 +43,14 @@ render_context_resource_import(uint32_t res_id,
break; break;
} }
const struct virgl_renderer_resource_import_blob_args import_args = { const struct virgl_renderer_resource_import_blob_args import_args = {
.res_handle = res->res_id, .res_handle = res_id,
.blob_mem = VIRGL_RENDERER_BLOB_MEM_HOST3D, .blob_mem = VIRGL_RENDERER_BLOB_MEM_HOST3D,
.fd_type = import_fd_type, .fd_type = import_fd_type,
.fd = res_fd, .fd = res_fd,
.size = size, .size = size,
}; };
int ret = virgl_renderer_resource_import_blob(&import_args); return virgl_renderer_resource_import_blob(&import_args);
if (ret) {
free(res);
return NULL;
}
return res;
} }
void void
@ -91,17 +64,6 @@ render_context_update_timeline(struct render_context *ctx,
write_eventfd(ctx->fence_eventfd, 1); write_eventfd(ctx->fence_eventfd, 1);
} }
static struct render_context_resource *
render_context_find_resource(struct render_context *ctx, uint32_t res_id)
{
list_for_each_entry (struct render_context_resource, res, &ctx->resources, head) {
if (res->res_id == res_id)
return res;
}
return NULL;
}
static bool static bool
render_context_init_virgl_context(struct render_context *ctx, render_context_init_virgl_context(struct render_context *ctx,
const struct render_context_op_init_request *req, const struct render_context_op_init_request *req,
@ -272,17 +234,12 @@ render_context_dispatch_get_blob(struct render_context *ctx,
} }
static bool static bool
render_context_dispatch_detach_resource(struct render_context *ctx, render_context_dispatch_detach_resource(UNUSED struct render_context *ctx,
const union render_context_op_request *req, const union render_context_op_request *req,
UNUSED const int *fds, UNUSED const int *fds,
UNUSED int fd_count) UNUSED int fd_count)
{ {
const uint32_t res_id = req->detach_resource.res_id; virgl_renderer_resource_unref(req->detach_resource.res_id);
struct render_context_resource *res = render_context_find_resource(ctx, res_id);
if (res)
render_context_resource_destroy(res);
return true; return true;
} }
@ -306,14 +263,12 @@ render_context_dispatch_attach_resource(struct render_context *ctx,
} }
/* classic 3d resource with valid size reuses the blob import path here */ /* classic 3d resource with valid size reuses the blob import path here */
struct render_context_resource *res = int ret = render_context_import_blob(res_id, fd_type, fds[0], size);
render_context_resource_import(res_id, fd_type, fds[0], size); if (ret) {
if (!res) { render_log("failed to import resource %d (%d)", res_id, ret);
render_log("failed to import resource %d", res_id);
return false; return false;
} }
list_addtail(&res->head, &ctx->resources);
virgl_renderer_ctx_attach_resource(ctx->ctx_id, res_id); virgl_renderer_ctx_attach_resource(ctx->ctx_id, res_id);
return true; return true;
@ -426,13 +381,8 @@ static void
render_context_fini(struct render_context *ctx) render_context_fini(struct render_context *ctx)
{ {
render_virgl_lock_dispatch(); render_virgl_lock_dispatch();
/* destroy the context first to join its sync threads and ring threads */ /* destroy the context first to join its sync threads and ring threads */
virgl_renderer_context_destroy(ctx->ctx_id); virgl_renderer_context_destroy(ctx->ctx_id);
list_for_each_entry_safe (struct render_context_resource, res, &ctx->resources, head)
render_context_resource_destroy(res);
render_virgl_unlock_dispatch(); render_virgl_unlock_dispatch();
render_virgl_remove_context(ctx); render_virgl_remove_context(ctx);
@ -476,7 +426,6 @@ render_context_init(struct render_context *ctx, const struct render_context_args
memset(ctx, 0, sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx));
ctx->ctx_id = args->ctx_id; ctx->ctx_id = args->ctx_id;
render_socket_init(&ctx->socket, args->ctx_fd); render_socket_init(&ctx->socket, args->ctx_fd);
list_inithead(&ctx->resources);
ctx->shmem_fd = -1; ctx->shmem_fd = -1;
ctx->fence_eventfd = -1; ctx->fence_eventfd = -1;

@ -18,8 +18,6 @@ struct render_context {
char *name; char *name;
size_t name_len; size_t name_len;
struct list_head resources;
int shmem_fd; int shmem_fd;
size_t shmem_size; size_t shmem_size;
void *shmem_ptr; void *shmem_ptr;

Loading…
Cancel
Save