From 7f7742998e6731ae7b21adaf0f1a9ebd6bf6470e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 29 Apr 2021 09:48:02 -0700 Subject: [PATCH] venus: clarify/fix instance renderer versions Add vn_instance::renderer_version to indicate the maximum renderer instance version we can use internally. It is not all that useful because we only use 1.1 instance features and VN_MIN_RENDERER_VERSION is set to 1.1, but whatever. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_device.c | 52 +++++++++++++++++++---------------- src/virtio/vulkan/vn_device.h | 9 ++++++ 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c index 7cad27c68ab..38f96e41dca 100644 --- a/src/virtio/vulkan/vn_device.c +++ b/src/virtio/vulkan/vn_device.c @@ -81,38 +81,44 @@ static const driOptionDescription vn_dri_options[] = { }; static VkResult -vn_instance_init_version(struct vn_instance *instance) +vn_instance_init_renderer_versions(struct vn_instance *instance) { - uint32_t renderer_version = 0; + uint32_t instance_version = 0; VkResult result = - vn_call_vkEnumerateInstanceVersion(instance, &renderer_version); + vn_call_vkEnumerateInstanceVersion(instance, &instance_version); if (result != VK_SUCCESS) { if (VN_DEBUG(INIT)) vn_log(instance, "failed to enumerate renderer instance version"); return result; } - if (renderer_version < VN_MIN_RENDERER_VERSION) { + if (instance_version < VN_MIN_RENDERER_VERSION) { if (VN_DEBUG(INIT)) { vn_log(instance, "unsupported renderer instance version %d.%d", - VK_VERSION_MAJOR(instance->renderer_api_version), - VK_VERSION_MINOR(instance->renderer_api_version)); + VK_VERSION_MAJOR(instance_version), + VK_VERSION_MINOR(instance_version)); } return VK_ERROR_INITIALIZATION_FAILED; } - instance->renderer_api_version = - instance->base.base.app_info.api_version > VN_MIN_RENDERER_VERSION - ? instance->base.base.app_info.api_version - : VN_MIN_RENDERER_VERSION; - if (VN_DEBUG(INIT)) { - vn_log(instance, "vk instance version %d.%d.%d", - VK_VERSION_MAJOR(instance->renderer_api_version), - VK_VERSION_MINOR(instance->renderer_api_version), - VK_VERSION_PATCH(instance->renderer_api_version)); + vn_log(instance, "renderer instance version %d.%d.%d", + VK_VERSION_MAJOR(instance_version), + VK_VERSION_MINOR(instance_version), + VK_VERSION_PATCH(instance_version)); } + /* request at least VN_MIN_RENDERER_VERSION internally */ + instance->renderer_api_version = + MAX2(instance->base.base.app_info.api_version, VN_MIN_RENDERER_VERSION); + + /* instance version for internal use is capped */ + instance_version = MIN3(instance_version, instance->renderer_api_version, + instance->renderer_info.vk_xml_version); + assert(instance_version >= VN_MIN_RENDERER_VERSION); + + instance->renderer_version = instance_version; + return VK_SUCCESS; } @@ -1849,26 +1855,26 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, if (result != VK_SUCCESS) goto fail; - result = vn_instance_init_version(instance); + result = vn_instance_init_renderer_versions(instance); if (result != VK_SUCCESS) goto fail; - VkInstanceCreateInfo local_create_info; - local_create_info = *pCreateInfo; + VkInstanceCreateInfo local_create_info = *pCreateInfo; local_create_info.ppEnabledExtensionNames = NULL; local_create_info.enabledExtensionCount = 0; pCreateInfo = &local_create_info; - /* request at least instance->renderer_api_version */ - VkApplicationInfo local_app_info = { - .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, - .apiVersion = instance->renderer_api_version, - }; + VkApplicationInfo local_app_info; if (instance->base.base.app_info.api_version < instance->renderer_api_version) { if (pCreateInfo->pApplicationInfo) { local_app_info = *pCreateInfo->pApplicationInfo; local_app_info.apiVersion = instance->renderer_api_version; + } else { + local_app_info = (const VkApplicationInfo){ + .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, + .apiVersion = instance->renderer_api_version, + }; } local_create_info.pApplicationInfo = &local_app_info; } diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h index 1188d9f113d..0986d7ab0d8 100644 --- a/src/virtio/vulkan/vn_device.h +++ b/src/virtio/vulkan/vn_device.h @@ -28,7 +28,16 @@ struct vn_instance { struct vn_renderer *renderer; struct vn_renderer_info renderer_info; + /* Between the driver and the app, VN_MAX_API_VERSION is what we advertise + * and base.base.app_info.api_version is what the app requests. + * + * Between the driver and the renderer, renderer_api_version is the api + * version we request internally, which can be higher than + * base.base.app_info.api_version. renderer_version is the instance + * version we can use internally. + */ uint32_t renderer_api_version; + uint32_t renderer_version; /* to synchronize renderer/ring */ mtx_t roundtrip_mutex;