vulkan/device: Add a check_status hook
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 8 Nov 2021 18:42:40 +0000 (12:42 -0600)
committerJason Ekstrand <jason@jlekstrand.net>
Tue, 16 Nov 2021 16:02:08 +0000 (10:02 -0600)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13427>

src/vulkan/runtime/vk_device.h

index d9da1fb..d716c4d 100644 (file)
@@ -53,6 +53,18 @@ struct vk_device {
       bool reported;
    } _lost;
 
+   /** Checks the status of this device
+    *
+    * This is expected to return either VK_SUCCESS or VK_ERROR_DEVICE_LOST.
+    * It is called before vk_queue::driver_submit and after every non-trivial
+    * wait operation to ensure the device is still around.  This gives the
+    * driver a hook to ask the kernel if its device is still valid.  If the
+    * kernel says the device has been lost, it MUST call vk_device_set_lost().
+    *
+    * This function may be called from any thread at any time.
+    */
+   VkResult (*check_status)(struct vk_device *device);
+
 #ifdef ANDROID
    mtx_t swapchain_private_mtx;
    struct hash_table *swapchain_private;
@@ -97,6 +109,24 @@ vk_device_is_lost(struct vk_device *device)
    return lost;
 }
 
+static inline VkResult
+vk_device_check_status(struct vk_device *device)
+{
+   if (vk_device_is_lost(device))
+      return VK_ERROR_DEVICE_LOST;
+
+   if (!device->check_status)
+      return VK_SUCCESS;
+
+   VkResult result = device->check_status(device);
+
+   assert(result == VK_SUCCESS || result == VK_ERROR_DEVICE_LOST);
+   if (result == VK_ERROR_DEVICE_LOST)
+      assert(vk_device_is_lost_no_report(device));
+
+   return result;
+}
+
 PFN_vkVoidFunction
 vk_device_get_proc_addr(const struct vk_device *device,
                         const char *name);