virgl: add VIRGL_RENDERER_RENDER_SERVER

When the flag is set, a render server is started and each vkr context is
replaced by a proxy context.

It does not apply to vrend contexts.  There is no plan to support vrend
contexts either currently.

This also extends virgl_renderer_callbacks with a new callback.  The
idea is to allow the client to start the render server externally.  It
can be used to sandbox the render server, or is required when the client
process is sandboxed and cannot fork/exec/socketpair.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent 5519748c9b
commit b8362ae7c1
  1. 35
      src/virglrenderer.c
  2. 9
      src/virglrenderer.h

@ -38,6 +38,7 @@
#include "util/u_math.h" #include "util/u_math.h"
#include "vkr_renderer.h" #include "vkr_renderer.h"
#include "vrend_renderer.h" #include "vrend_renderer.h"
#include "proxy/proxy_renderer.h"
#include "vrend_winsys.h" #include "vrend_winsys.h"
#include "virglrenderer.h" #include "virglrenderer.h"
@ -58,6 +59,7 @@ struct global_state {
bool winsys_initialized; bool winsys_initialized;
bool vrend_initialized; bool vrend_initialized;
bool vkr_initialized; bool vkr_initialized;
bool proxy_initialized;
}; };
static struct global_state state; static struct global_state state;
@ -219,9 +221,12 @@ int virgl_renderer_context_create_with_flags(uint32_t ctx_id,
ctx = vrend_renderer_context_create(ctx_id, nlen, name); ctx = vrend_renderer_context_create(ctx_id, nlen, name);
break; break;
case VIRGL_RENDERER_CAPSET_VENUS: case VIRGL_RENDERER_CAPSET_VENUS:
if (!state.vkr_initialized) if (state.proxy_initialized)
ctx = proxy_context_create(ctx_id, ctx_flags, nlen, name);
else if (state.vkr_initialized)
ctx = vkr_context_create(nlen, name);
else
return EINVAL; return EINVAL;
ctx = vkr_context_create(nlen, name);
break; break;
default: default:
return EINVAL; return EINVAL;
@ -552,6 +557,19 @@ static const struct vrend_if_cbs vrend_cbs = {
make_current, make_current,
}; };
static int
proxy_renderer_cb_get_server_fd(uint32_t version)
{
if (state.cbs && state.cbs->version >= 3 && state.cbs->get_server_fd)
return state.cbs->get_server_fd(state.cookie, version);
else
return -1;
}
static const struct proxy_renderer_cbs proxy_cbs = {
proxy_renderer_cb_get_server_fd,
};
void *virgl_renderer_get_cursor_data(uint32_t resource_id, uint32_t *width, uint32_t *height) void *virgl_renderer_get_cursor_data(uint32_t resource_id, uint32_t *width, uint32_t *height)
{ {
struct virgl_resource *res = virgl_resource_lookup(resource_id); struct virgl_resource *res = virgl_resource_lookup(resource_id);
@ -583,6 +601,9 @@ void virgl_renderer_cleanup(UNUSED void *cookie)
if (state.resource_initialized) if (state.resource_initialized)
virgl_resource_table_cleanup(); virgl_resource_table_cleanup();
if (state.proxy_initialized)
proxy_renderer_fini();
if (state.vkr_initialized) if (state.vkr_initialized)
vkr_renderer_fini(); vkr_renderer_fini();
@ -692,6 +713,13 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
state.vkr_initialized = true; state.vkr_initialized = true;
} }
if (!state.proxy_initialized && (flags & VIRGL_RENDERER_RENDER_SERVER)) {
ret = proxy_renderer_init(&proxy_cbs, flags | VIRGL_RENDERER_NO_VIRGL);
if (ret)
goto fail;
state.proxy_initialized = true;
}
return 0; return 0;
fail: fail:
@ -727,6 +755,9 @@ void virgl_renderer_reset(void)
if (state.resource_initialized) if (state.resource_initialized)
virgl_resource_table_reset(); virgl_resource_table_reset();
if (state.proxy_initialized)
proxy_renderer_reset();
if (state.vkr_initialized) if (state.vkr_initialized)
vkr_renderer_reset(); vkr_renderer_reset();

@ -64,6 +64,9 @@ struct virgl_renderer_callbacks {
#ifdef VIRGL_RENDERER_UNSTABLE_APIS #ifdef VIRGL_RENDERER_UNSTABLE_APIS
void (*write_context_fence)(void *cookie, uint32_t ctx_id, uint64_t queue_id, void *fence_cookie); void (*write_context_fence)(void *cookie, uint32_t ctx_id, uint64_t queue_id, void *fence_cookie);
/* version 0: a connected socket of type SOCK_SEQPACKET */
int (*get_server_fd)(void *cookie, uint32_t version);
#endif #endif
}; };
@ -105,6 +108,12 @@ struct virgl_renderer_callbacks {
*/ */
#define VIRGL_RENDERER_ASYNC_FENCE_CB (1 << 8) #define VIRGL_RENDERER_ASYNC_FENCE_CB (1 << 8)
/* Start a render server and move GPU rendering to the render server.
*
* This is respected by the venus renderer but ignored by the virgl renderer.
*/
#define VIRGL_RENDERER_RENDER_SERVER (1 << 9)
#endif /* VIRGL_RENDERER_UNSTABLE_APIS */ #endif /* VIRGL_RENDERER_UNSTABLE_APIS */
VIRGL_EXPORT int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cb); VIRGL_EXPORT int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cb);

Loading…
Cancel
Save