diff --git a/src/meson.build b/src/meson.build index af13b2a..575b7a3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -76,6 +76,7 @@ vrend_winsys_glx_sources = [ venus_sources = [ 'venus-protocol/vn_protocol_renderer.h', + 'venus_hw.h', 'vkr_cs.c', 'vkr_cs.h', 'vkr_object.h', diff --git a/src/venus_hw.h b/src/venus_hw.h new file mode 100644 index 0000000..076e616 --- /dev/null +++ b/src/venus_hw.h @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Chromium + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef VENUS_HW_H +#define VENUS_HW_H + +#include + +#ifdef VIRGL_RENDERER_UNSTABLE_APIS +struct virgl_renderer_capset_venus { + uint32_t wire_format_version; + uint32_t vk_xml_version; + uint32_t vk_ext_command_serialization_spec_version; + uint32_t vk_mesa_venus_protocol_spec_version; +}; +#endif + +#endif /* VENUS_HW_H */ diff --git a/src/virglrenderer.c b/src/virglrenderer.c index bc11105..8527534 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -35,6 +35,7 @@ #include "pipe/p_state.h" #include "util/u_format.h" #include "util/u_math.h" +#include "vkr_renderer.h" #include "vrend_renderer.h" #include "vrend_winsys.h" @@ -55,6 +56,7 @@ struct global_state { bool context_initialized; bool winsys_initialized; bool vrend_initialized; + bool vkr_initialized; }; static struct global_state state; @@ -160,6 +162,10 @@ void virgl_renderer_fill_caps(uint32_t set, uint32_t version, case VIRGL_RENDERER_CAPSET_VIRGL2: vrend_renderer_fill_caps(set, version, (union virgl_caps *)caps); break; + case VIRGL_RENDERER_CAPSET_VENUS: + if (state.vkr_initialized) + vkr_get_capset(caps); + break; default: break; } @@ -205,6 +211,11 @@ int virgl_renderer_context_create_with_flags(uint32_t ctx_id, case VIRGL_RENDERER_CAPSET_VIRGL2: ctx = vrend_renderer_context_create(ctx_id, nlen, name); break; + case VIRGL_RENDERER_CAPSET_VENUS: + if (!state.vkr_initialized) + return EINVAL; + ctx = vkr_context_create(nlen, name); + break; default: return EINVAL; break; @@ -461,6 +472,12 @@ void virgl_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, 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); + } + break; default: *max_ver = 0; *max_size = 0; @@ -558,6 +575,9 @@ void virgl_renderer_cleanup(UNUSED void *cookie) if (state.resource_initialized) virgl_resource_table_cleanup(); + if (state.vkr_initialized) + vkr_renderer_fini(); + if (state.vrend_initialized) vrend_renderer_fini(); @@ -641,6 +661,17 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks state.vrend_initialized = true; } + if (!state.vkr_initialized && (flags & VIRGL_RENDERER_VENUS)) { + uint32_t vkr_flags = 0; + if (flags & VIRGL_RENDERER_THREAD_SYNC) + vkr_flags |= VKR_RENDERER_THREAD_SYNC; + + int ret = vkr_renderer_init(vkr_flags); + if (ret) + goto fail; + state.vkr_initialized = true; + } + return 0; fail: @@ -676,6 +707,9 @@ void virgl_renderer_reset(void) if (state.resource_initialized) virgl_resource_table_reset(); + if (state.vkr_initialized) + vkr_renderer_reset(); + if (state.vrend_initialized) vrend_renderer_reset(); } diff --git a/src/virglrenderer.h b/src/virglrenderer.h index d56b5dc..ff747ed 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -90,6 +90,10 @@ struct virgl_renderer_callbacks { */ #define VIRGL_RENDERER_USE_EXTERNAL_BLOB (1 << 5) +/* Enable venus renderer. + */ +#define VIRGL_RENDERER_VENUS (1 << 6) + #endif /* VIRGL_RENDERER_UNSTABLE_APIS */ VIRGL_EXPORT int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cb); diff --git a/src/virglrenderer_hw.h b/src/virglrenderer_hw.h index 65f98cb..0490d77 100644 --- a/src/virglrenderer_hw.h +++ b/src/virglrenderer_hw.h @@ -24,12 +24,15 @@ #ifndef VIRGLRENDERER_HW_H #define VIRGLRENDERER_HW_H +#include "venus_hw.h" #include "virgl_hw.h" #ifdef VIRGL_RENDERER_UNSTABLE_APIS enum virgl_renderer_capset { VIRGL_RENDERER_CAPSET_VIRGL = 1, VIRGL_RENDERER_CAPSET_VIRGL2 = 2, + /* 3 is reserved for gfxstream */ + VIRGL_RENDERER_CAPSET_VENUS = 4, }; #endif diff --git a/src/vkr_renderer.c b/src/vkr_renderer.c index be24747..a7bb18a 100644 --- a/src/vkr_renderer.c +++ b/src/vkr_renderer.c @@ -4008,13 +4008,6 @@ fail: return NULL; } -struct virgl_renderer_capset_venus { - uint32_t wire_format_version; - uint32_t vk_xml_version; - uint32_t vk_ext_command_serialization_spec_version; - uint32_t vk_mesa_venus_protocol_spec_version; -}; - size_t vkr_get_capset(void *capset) {