From 76be631ae588aefcc3a3dce9075bcb30c086078b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 17 Jul 2020 21:00:15 -0700 Subject: [PATCH] virgl: add VIRGL_RENDERER_NO_VIRGL It disables vrend renderer. Signed-off-by: Chia-I Wu Reviewed-by: Ryan Neph Reviewed-by: Gert Wollny --- src/virgl_resource.c | 3 ++- src/virglrenderer.c | 41 ++++++++++++++++++++++++++++------------- src/virglrenderer.h | 4 ++++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/virgl_resource.c b/src/virgl_resource.c index c58dd70..254a6af 100644 --- a/src/virgl_resource.c +++ b/src/virgl_resource.c @@ -59,7 +59,8 @@ virgl_resource_table_init(const struct virgl_resource_pipe_callbacks *callbacks) if (!virgl_resource_table) return ENOMEM; - pipe_callbacks = *callbacks; + if (callbacks) + pipe_callbacks = *callbacks; return 0; } diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 8527534..900818c 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -71,6 +71,9 @@ static int virgl_renderer_resource_create_internal(struct virgl_renderer_resourc struct pipe_resource *pipe_res; struct vrend_renderer_resource_create_args vrend_args = { 0 }; + if (!state.vrend_initialized) + return EINVAL; + /* do not accept handle 0 */ if (args->handle == 0) return EINVAL; @@ -160,7 +163,8 @@ void virgl_renderer_fill_caps(uint32_t set, uint32_t version, switch (set) { case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL2: - vrend_renderer_fill_caps(set, version, (union virgl_caps *)caps); + if (state.vrend_initialized) + vrend_renderer_fill_caps(set, version, (union virgl_caps *)caps); break; case VIRGL_RENDERER_CAPSET_VENUS: if (state.vkr_initialized) @@ -209,6 +213,8 @@ int virgl_renderer_context_create_with_flags(uint32_t ctx_id, switch (capset_id) { case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL2: + if (!state.vrend_initialized) + return EINVAL; ctx = vrend_renderer_context_create(ctx_id, nlen, name); break; case VIRGL_RENDERER_CAPSET_VENUS: @@ -416,7 +422,8 @@ int virgl_renderer_context_get_poll_fd(uint32_t ctx_id) void virgl_renderer_force_ctx_0(void) { TRACE_FUNC(); - vrend_renderer_force_ctx_0(); + if (state.vrend_initialized) + vrend_renderer_force_ctx_0(); } void virgl_renderer_ctx_attach_resource(int ctx_id, int res_handle) @@ -467,16 +474,16 @@ void virgl_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, uint32_t *max_size) { TRACE_FUNC(); + + /* this may be called before virgl_renderer_init */ switch (cap_set) { case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL2: vrend_renderer_get_cap_set(cap_set, max_ver, max_size); break; case VIRGL_RENDERER_CAPSET_VENUS: - if (state.vkr_initialized) { - *max_ver = 0; - *max_size = vkr_get_capset(NULL); - } + *max_ver = 0; + *max_size = vkr_get_capset(NULL); break; default: *max_ver = 0; @@ -604,9 +611,8 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks return -EBUSY; if (!state.client_initialized) { - if (!cookie || !cbs) - return -1; - if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION) + if (cbs && (cbs->version < 1 || + cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION)) return -1; state.cookie = cookie; @@ -616,7 +622,11 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks } if (!state.resource_initialized) { - ret = virgl_resource_table_init(vrend_renderer_get_pipe_callbacks()); + const struct virgl_resource_pipe_callbacks *pipe_cbs = + (flags & VIRGL_RENDERER_NO_VIRGL) ? NULL : + vrend_renderer_get_pipe_callbacks(); + + ret = virgl_resource_table_init(pipe_cbs); if (ret) goto fail; state.resource_initialized = true; @@ -629,8 +639,8 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks state.context_initialized = true; } - if (!state.winsys_initialized && (flags & (VIRGL_RENDERER_USE_EGL | - VIRGL_RENDERER_USE_GLX))) { + if (!state.winsys_initialized && !(flags & VIRGL_RENDERER_NO_VIRGL) && + (flags & (VIRGL_RENDERER_USE_EGL | VIRGL_RENDERER_USE_GLX))) { int drm_fd = -1; if (flags & VIRGL_RENDERER_USE_EGL) { @@ -647,9 +657,14 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks state.winsys_initialized = true; } - if (!state.vrend_initialized) { + if (!state.vrend_initialized && !(flags & VIRGL_RENDERER_NO_VIRGL)) { uint32_t renderer_flags = 0; + if (!cookie || !cbs) { + ret = -1; + goto fail; + } + if (flags & VIRGL_RENDERER_THREAD_SYNC) renderer_flags |= VREND_USE_THREAD_SYNC; if (flags & VIRGL_RENDERER_USE_EXTERNAL_BLOB) diff --git a/src/virglrenderer.h b/src/virglrenderer.h index ff747ed..2fe43aa 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -94,6 +94,10 @@ struct virgl_renderer_callbacks { */ #define VIRGL_RENDERER_VENUS (1 << 6) +/* Disable virgl renderer. + */ +#define VIRGL_RENDERER_NO_VIRGL (1 << 7) + #endif /* VIRGL_RENDERER_UNSTABLE_APIS */ VIRGL_EXPORT int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cb);