virgl: add VIRGL_RENDERER_NO_VIRGL

It disables vrend renderer.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 4 years ago
parent 6c31f85330
commit 76be631ae5
  1. 3
      src/virgl_resource.c
  2. 41
      src/virglrenderer.c
  3. 4
      src/virglrenderer.h

@ -59,7 +59,8 @@ virgl_resource_table_init(const struct virgl_resource_pipe_callbacks *callbacks)
if (!virgl_resource_table) if (!virgl_resource_table)
return ENOMEM; return ENOMEM;
pipe_callbacks = *callbacks; if (callbacks)
pipe_callbacks = *callbacks;
return 0; return 0;
} }

@ -71,6 +71,9 @@ static int virgl_renderer_resource_create_internal(struct virgl_renderer_resourc
struct pipe_resource *pipe_res; struct pipe_resource *pipe_res;
struct vrend_renderer_resource_create_args vrend_args = { 0 }; struct vrend_renderer_resource_create_args vrend_args = { 0 };
if (!state.vrend_initialized)
return EINVAL;
/* do not accept handle 0 */ /* do not accept handle 0 */
if (args->handle == 0) if (args->handle == 0)
return EINVAL; return EINVAL;
@ -160,7 +163,8 @@ void virgl_renderer_fill_caps(uint32_t set, uint32_t version,
switch (set) { switch (set) {
case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL:
case VIRGL_RENDERER_CAPSET_VIRGL2: 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; break;
case VIRGL_RENDERER_CAPSET_VENUS: case VIRGL_RENDERER_CAPSET_VENUS:
if (state.vkr_initialized) if (state.vkr_initialized)
@ -209,6 +213,8 @@ int virgl_renderer_context_create_with_flags(uint32_t ctx_id,
switch (capset_id) { switch (capset_id) {
case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL:
case VIRGL_RENDERER_CAPSET_VIRGL2: case VIRGL_RENDERER_CAPSET_VIRGL2:
if (!state.vrend_initialized)
return EINVAL;
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:
@ -416,7 +422,8 @@ int virgl_renderer_context_get_poll_fd(uint32_t ctx_id)
void virgl_renderer_force_ctx_0(void) void virgl_renderer_force_ctx_0(void)
{ {
TRACE_FUNC(); 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) 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) uint32_t *max_size)
{ {
TRACE_FUNC(); TRACE_FUNC();
/* this may be called before virgl_renderer_init */
switch (cap_set) { switch (cap_set) {
case VIRGL_RENDERER_CAPSET_VIRGL: case VIRGL_RENDERER_CAPSET_VIRGL:
case VIRGL_RENDERER_CAPSET_VIRGL2: case VIRGL_RENDERER_CAPSET_VIRGL2:
vrend_renderer_get_cap_set(cap_set, max_ver, max_size); vrend_renderer_get_cap_set(cap_set, max_ver, max_size);
break; break;
case VIRGL_RENDERER_CAPSET_VENUS: case VIRGL_RENDERER_CAPSET_VENUS:
if (state.vkr_initialized) { *max_ver = 0;
*max_ver = 0; *max_size = vkr_get_capset(NULL);
*max_size = vkr_get_capset(NULL);
}
break; break;
default: default:
*max_ver = 0; *max_ver = 0;
@ -604,9 +611,8 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
return -EBUSY; return -EBUSY;
if (!state.client_initialized) { if (!state.client_initialized) {
if (!cookie || !cbs) if (cbs && (cbs->version < 1 ||
return -1; cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION))
if (cbs->version < 1 || cbs->version > VIRGL_RENDERER_CALLBACKS_VERSION)
return -1; return -1;
state.cookie = cookie; state.cookie = cookie;
@ -616,7 +622,11 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
} }
if (!state.resource_initialized) { 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) if (ret)
goto fail; goto fail;
state.resource_initialized = true; state.resource_initialized = true;
@ -629,8 +639,8 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
state.context_initialized = true; state.context_initialized = true;
} }
if (!state.winsys_initialized && (flags & (VIRGL_RENDERER_USE_EGL | if (!state.winsys_initialized && !(flags & VIRGL_RENDERER_NO_VIRGL) &&
VIRGL_RENDERER_USE_GLX))) { (flags & (VIRGL_RENDERER_USE_EGL | VIRGL_RENDERER_USE_GLX))) {
int drm_fd = -1; int drm_fd = -1;
if (flags & VIRGL_RENDERER_USE_EGL) { 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; state.winsys_initialized = true;
} }
if (!state.vrend_initialized) { if (!state.vrend_initialized && !(flags & VIRGL_RENDERER_NO_VIRGL)) {
uint32_t renderer_flags = 0; uint32_t renderer_flags = 0;
if (!cookie || !cbs) {
ret = -1;
goto fail;
}
if (flags & VIRGL_RENDERER_THREAD_SYNC) if (flags & VIRGL_RENDERER_THREAD_SYNC)
renderer_flags |= VREND_USE_THREAD_SYNC; renderer_flags |= VREND_USE_THREAD_SYNC;
if (flags & VIRGL_RENDERER_USE_EXTERNAL_BLOB) if (flags & VIRGL_RENDERER_USE_EXTERNAL_BLOB)

@ -94,6 +94,10 @@ struct virgl_renderer_callbacks {
*/ */
#define VIRGL_RENDERER_VENUS (1 << 6) #define VIRGL_RENDERER_VENUS (1 << 6)
/* Disable virgl renderer.
*/
#define VIRGL_RENDERER_NO_VIRGL (1 << 7)
#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