diff --git a/server/render_context.c b/server/render_context.c index 4658588..46884ff 100644 --- a/server/render_context.c +++ b/server/render_context.c @@ -15,9 +15,9 @@ #include "render_virgl.h" static bool -render_context_import_blob(struct render_context *ctx, - const struct render_context_op_attach_resource_request *req, - int res_fd) +render_context_import_resource(struct render_context *ctx, + const struct render_context_op_import_resource_request *req, + int res_fd) { const uint32_t res_id = req->res_id; const enum virgl_resource_fd_type fd_type = req->fd_type; @@ -108,11 +108,11 @@ render_context_init_virgl_context(struct render_context *ctx, } static bool -render_context_export_blob(struct render_context *ctx, - const struct render_context_op_get_blob_request *req, - enum virgl_resource_fd_type *out_fd_type, - uint32_t *out_map_info, - int *out_res_fd) +render_context_create_resource(struct render_context *ctx, + const struct render_context_op_create_resource_request *req, + enum virgl_resource_fd_type *out_fd_type, + uint32_t *out_map_info, + int *out_res_fd) { const uint32_t res_id = req->res_id; const struct virgl_renderer_resource_create_blob_args blob_args = { @@ -144,6 +144,9 @@ render_context_export_blob(struct render_context *ctx, return false; } + /* RENDER_CONTEXT_OP_CREATE_RESOURCE implies attach and proxy will not send + * RENDER_CONTEXT_OP_IMPORT_RESOURCE to attach the resource again. + */ virgl_renderer_ctx_attach_resource(ctx->ctx_id, res_id); switch (fd_type) { @@ -223,17 +226,17 @@ render_context_dispatch_submit_cmd(struct render_context *ctx, } static bool -render_context_dispatch_get_blob(struct render_context *ctx, - const union render_context_op_request *req, - UNUSED const int *fds, - UNUSED int fd_count) +render_context_dispatch_create_resource(struct render_context *ctx, + const union render_context_op_request *req, + UNUSED const int *fds, + UNUSED int fd_count) { - struct render_context_op_get_blob_reply reply = { + struct render_context_op_create_resource_reply reply = { .fd_type = VIRGL_RESOURCE_FD_INVALID, }; int res_fd; - bool ok = render_context_export_blob(ctx, &req->get_blob, &reply.fd_type, - &reply.map_info, &res_fd); + bool ok = render_context_create_resource(ctx, &req->create_resource, &reply.fd_type, + &reply.map_info, &res_fd); if (!ok) return render_socket_send_reply(&ctx->socket, &reply, sizeof(reply)); @@ -245,17 +248,17 @@ render_context_dispatch_get_blob(struct render_context *ctx, } static bool -render_context_dispatch_detach_resource(UNUSED struct render_context *ctx, - const union render_context_op_request *req, - UNUSED const int *fds, - UNUSED int fd_count) +render_context_dispatch_destroy_resource(UNUSED struct render_context *ctx, + const union render_context_op_request *req, + UNUSED const int *fds, + UNUSED int fd_count) { - virgl_renderer_resource_unref(req->detach_resource.res_id); + virgl_renderer_resource_unref(req->destroy_resource.res_id); return true; } static bool -render_context_dispatch_attach_resource(struct render_context *ctx, +render_context_dispatch_import_resource(struct render_context *ctx, const union render_context_op_request *req, const int *fds, int fd_count) @@ -266,7 +269,7 @@ render_context_dispatch_attach_resource(struct render_context *ctx, } /* classic 3d resource with valid size reuses the blob import path here */ - return render_context_import_blob(ctx, &req->attach_resource, fds[0]); + return render_context_import_resource(ctx, &req->import_resource, fds[0]); } static bool @@ -310,9 +313,9 @@ static const struct render_context_dispatch_entry .dispatch = render_context_dispatch_##name } RENDER_CONTEXT_DISPATCH(NOP, nop, 0), RENDER_CONTEXT_DISPATCH(INIT, init, 2), - RENDER_CONTEXT_DISPATCH(ATTACH_RESOURCE, attach_resource, 1), - RENDER_CONTEXT_DISPATCH(DETACH_RESOURCE, detach_resource, 0), - RENDER_CONTEXT_DISPATCH(GET_BLOB, get_blob, 0), + RENDER_CONTEXT_DISPATCH(CREATE_RESOURCE, create_resource, 0), + RENDER_CONTEXT_DISPATCH(IMPORT_RESOURCE, import_resource, 1), + RENDER_CONTEXT_DISPATCH(DESTROY_RESOURCE, destroy_resource, 0), RENDER_CONTEXT_DISPATCH(SUBMIT_CMD, submit_cmd, 0), RENDER_CONTEXT_DISPATCH(SUBMIT_FENCE, submit_fence, 0), #undef RENDER_CONTEXT_DISPATCH diff --git a/server/render_protocol.h b/server/render_protocol.h index 92610c0..778adcf 100644 --- a/server/render_protocol.h +++ b/server/render_protocol.h @@ -36,9 +36,9 @@ enum render_client_op { enum render_context_op { RENDER_CONTEXT_OP_NOP = 0, RENDER_CONTEXT_OP_INIT, - RENDER_CONTEXT_OP_ATTACH_RESOURCE, - RENDER_CONTEXT_OP_DETACH_RESOURCE, - RENDER_CONTEXT_OP_GET_BLOB, + RENDER_CONTEXT_OP_CREATE_RESOURCE, + RENDER_CONTEXT_OP_IMPORT_RESOURCE, + RENDER_CONTEXT_OP_DESTROY_RESOURCE, RENDER_CONTEXT_OP_SUBMIT_CMD, RENDER_CONTEXT_OP_SUBMIT_FENCE, @@ -131,43 +131,50 @@ struct render_context_op_init_request { /* followed by 1 shmem fd and optionally 1 eventfd */ }; -/* Attach a resource to the context. +/* Export a blob resource from the context * - * This roughly corresponds to virgl_renderer_ctx_attach_resource. + * This roughly corresponds to: + * - virgl_renderer_resource_create_blob + * - virgl_renderer_resource_get_map_info + * - virgl_renderer_resource_export_blob + * - virgl_renderer_ctx_attach_resource */ -struct render_context_op_attach_resource_request { +struct render_context_op_create_resource_request { struct render_context_op_header header; uint32_t res_id; + uint64_t blob_id; + uint64_t blob_size; + uint32_t blob_flags; /* VIRGL_RENDERER_BLOB_FLAG_* */ +}; + +struct render_context_op_create_resource_reply { enum virgl_resource_fd_type fd_type; - uint64_t size; - /* followed by 1 fd */ + uint32_t map_info; /* VIRGL_RENDERER_MAP_* */ + /* followed by 1 fd if not VIRGL_RESOURCE_FD_INVALID */ }; -/* Detach a resource from the context. +/* Import a blob resource to the context * - * This roughly corresponds to virgl_renderer_ctx_detach_resource. + * This roughly corresponds to: + * - virgl_renderer_resource_import_blob + * - virgl_renderer_ctx_attach_resource */ -struct render_context_op_detach_resource_request { +struct render_context_op_import_resource_request { struct render_context_op_header header; uint32_t res_id; + enum virgl_resource_fd_type fd_type; + uint64_t size; + /* followed by 1 fd */ }; -/* Export a blob from the context. +/* Free a blob resource from the context * - * This roughly corresponds to virgl_renderer_resource_create_blob. + * This roughly corresponds to: + * - virgl_renderer_resource_unref */ -struct render_context_op_get_blob_request { +struct render_context_op_destroy_resource_request { struct render_context_op_header header; uint32_t res_id; - uint64_t blob_id; - uint64_t blob_size; - uint32_t blob_flags; /* VIRGL_RENDERER_BLOB_FLAG_* */ -}; - -struct render_context_op_get_blob_reply { - enum virgl_resource_fd_type fd_type; - uint32_t map_info; /* VIRGL_RENDERER_MAP_* */ - /* followed by 1 fd if not VIRGL_RESOURCE_FD_INVALID */ }; /* Submit a small command stream to the context. @@ -209,9 +216,9 @@ union render_context_op_request { struct render_context_op_header header; struct render_context_op_nop_request nop; struct render_context_op_init_request init; - struct render_context_op_attach_resource_request attach_resource; - struct render_context_op_detach_resource_request detach_resource; - struct render_context_op_get_blob_request get_blob; + struct render_context_op_create_resource_request create_resource; + struct render_context_op_import_resource_request import_resource; + struct render_context_op_destroy_resource_request destroy_resource; struct render_context_op_submit_cmd_request submit_cmd; struct render_context_op_submit_fence_request submit_fence; }; diff --git a/src/proxy/proxy_context.c b/src/proxy/proxy_context.c index a87eee6..fcbc374 100644 --- a/src/proxy/proxy_context.c +++ b/src/proxy/proxy_context.c @@ -334,10 +334,14 @@ proxy_context_get_blob(struct virgl_context *base, uint32_t blob_flags, struct virgl_context_blob *blob) { + /* RENDER_CONTEXT_OP_CREATE_RESOURCE implies resource attach, thus proxy tracks + * resources created here to avoid double attaching the same resource when proxy is on + * attach_resource callback. + */ struct proxy_context *ctx = (struct proxy_context *)base; - const struct render_context_op_get_blob_request req = { - .header.op = RENDER_CONTEXT_OP_GET_BLOB, + const struct render_context_op_create_resource_request req = { + .header.op = RENDER_CONTEXT_OP_CREATE_RESOURCE, .res_id = res_id, .blob_id = blob_id, .blob_size = blob_size, @@ -348,7 +352,7 @@ proxy_context_get_blob(struct virgl_context *base, return -1; } - struct render_context_op_get_blob_reply reply; + struct render_context_op_create_resource_reply reply; int reply_fd; int reply_fd_count; if (!proxy_socket_receive_reply_with_fds(&ctx->socket, &reply, sizeof(reply), @@ -412,8 +416,8 @@ proxy_context_detach_resource(struct virgl_context *base, struct virgl_resource struct proxy_context *ctx = (struct proxy_context *)base; const uint32_t res_id = res->res_id; - const struct render_context_op_detach_resource_request req = { - .header.op = RENDER_CONTEXT_OP_DETACH_RESOURCE, + const struct render_context_op_destroy_resource_request req = { + .header.op = RENDER_CONTEXT_OP_DESTROY_RESOURCE, .res_id = res_id, }; if (!proxy_socket_send_request(&ctx->socket, &req, sizeof(req))) @@ -428,7 +432,7 @@ proxy_context_attach_resource(struct virgl_context *base, struct virgl_resource struct proxy_context *ctx = (struct proxy_context *)base; const uint32_t res_id = res->res_id; - /* skip for exported blob resources since they are already attached */ + /* avoid importing resources created from RENDER_CONTEXT_OP_CREATE_RESOURCE */ if (proxy_context_resource_find(ctx, res_id)) return; @@ -446,8 +450,8 @@ proxy_context_attach_resource(struct virgl_context *base, struct virgl_resource } /* the proxy ignores iovs since transfer_3d is not supported */ - const struct render_context_op_attach_resource_request req = { - .header.op = RENDER_CONTEXT_OP_ATTACH_RESOURCE, + const struct render_context_op_import_resource_request req = { + .header.op = RENDER_CONTEXT_OP_IMPORT_RESOURCE, .res_id = res_id, .fd_type = res_fd_type, .size = virgl_resource_get_size(res),