From c2701a90c6e52aa0275e377178cc1181ecd9baa1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Thu, 21 Nov 2024 08:39:20 +1000 Subject: [PATCH] venus: handle device probing properly. Currently if you try to probe the virtio ICD on a non-virtio system it will fail in CreateInstance which causes the loader to spit on the screen. However instance creation shouldn't fail, the driver should just not enumerate any devices in this case. It's a bit tricky to ensure this, but return instance and then handle instance destruction and fail device enumeration. Cc: mesa-stable Reviewed-by: Ryan Neph Part-of: (cherry picked from commit 25b8f4f7143f2e022df245ba2e1a2ab3ed4a2f90) --- .pick_status.json | 2 +- src/virtio/vulkan/vn_instance.c | 20 +++++++++++++------- src/virtio/vulkan/vn_physical_device.c | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index f5be3d7c79d..2440526cb79 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -304,7 +304,7 @@ "description": "venus: handle device probing properly.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/virtio/vulkan/vn_instance.c b/src/virtio/vulkan/vn_instance.c index 43f46cfaa28..239d7b93732 100644 --- a/src/virtio/vulkan/vn_instance.c +++ b/src/virtio/vulkan/vn_instance.c @@ -276,6 +276,7 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, return vn_error(NULL, result); } + VkInstance instance_handle = vn_instance_to_handle(instance); /* ring_idx = 0 reserved for CPU timeline */ instance->ring_idx_used_mask = 0x1; @@ -294,6 +295,10 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, } result = vn_instance_init_renderer(instance); + if (result == VK_ERROR_INITIALIZATION_FAILED) { + *pInstance = instance_handle; + return VK_SUCCESS; + } if (result != VK_SUCCESS) goto out_mtx_destroy; @@ -333,7 +338,6 @@ vn_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, local_create_info.pApplicationInfo = &local_app_info; } - VkInstance instance_handle = vn_instance_to_handle(instance); result = vn_call_vkCreateInstance(instance->ring.ring, pCreateInfo, NULL, &instance_handle); if (result != VK_SUCCESS) @@ -407,16 +411,18 @@ vn_DestroyInstance(VkInstance _instance, mtx_destroy(&instance->physical_device.mutex); mtx_destroy(&instance->ring_idx_mutex); - vn_call_vkDestroyInstance(instance->ring.ring, _instance, NULL); + if (instance->renderer) { + vn_call_vkDestroyInstance(instance->ring.ring, _instance, NULL); - vn_instance_fini_ring(instance); + vn_instance_fini_ring(instance); - vn_renderer_shmem_pool_fini(instance->renderer, - &instance->reply_shmem_pool); + vn_renderer_shmem_pool_fini(instance->renderer, + &instance->reply_shmem_pool); - vn_renderer_shmem_pool_fini(instance->renderer, &instance->cs_shmem_pool); + vn_renderer_shmem_pool_fini(instance->renderer, &instance->cs_shmem_pool); - vn_renderer_destroy(instance->renderer, alloc); + vn_renderer_destroy(instance->renderer, alloc); + } driDestroyOptionCache(&instance->dri_options); driDestroyOptionInfo(&instance->available_dri_options); diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index 3022a79e7c0..6ef24a285d0 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -1500,6 +1500,10 @@ enumerate_physical_devices(struct vn_instance *instance, struct vn_physical_device *physical_devs = NULL; VkResult result; + if (!instance->renderer) { + *out_count = 0; + return VK_SUCCESS; + } uint32_t count = 0; result = vn_call_vkEnumeratePhysicalDevices( ring, vn_instance_to_handle(instance), &count, NULL);