[Mesa-dev] [PATCH 1/2] anv: Check for device loss at the end of WaitForFences

Jason Ekstrand jason at jlekstrand.net
Tue Mar 28 21:39:53 UTC 2017


It's possible that the device could have been lost while we were
waiting.  We should let the user know if this has happened.
---
 src/intel/vulkan/anv_device.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 4e4fa19..5f0d00f 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1853,6 +1853,7 @@ VkResult anv_WaitForFences(
     */
    int64_t timeout = MIN2(_timeout, INT64_MAX);
 
+   VkResult result = VK_SUCCESS;
    uint32_t pending_fences = fenceCount;
    while (pending_fences) {
       pending_fences = 0;
@@ -1873,8 +1874,10 @@ VkResult anv_WaitForFences(
             /* This fence is not pending.  If waitAll isn't set, we can return
              * early.  Otherwise, we have to keep going.
              */
-            if (!waitAll)
-               return VK_SUCCESS;
+            if (!waitAll) {
+               result = VK_SUCCESS;
+               goto done;
+            }
             continue;
 
          case ANV_FENCE_STATE_SUBMITTED:
@@ -1883,7 +1886,8 @@ VkResult anv_WaitForFences(
              */
             ret = anv_gem_wait(device, fence->bo.gem_handle, &timeout);
             if (ret == -1 && errno == ETIME) {
-               return VK_TIMEOUT;
+               result = VK_TIMEOUT;
+               goto done;
             } else if (ret == -1) {
                /* We don't know the real error. */
                 device->lost = true;
@@ -1946,7 +1950,8 @@ VkResult anv_WaitForFences(
 
             if (time_elapsed >= timeout) {
                pthread_mutex_unlock(&device->mutex);
-               return VK_TIMEOUT;
+               result = VK_TIMEOUT;
+               goto done;
             }
 
             timeout -= time_elapsed;
@@ -1956,7 +1961,11 @@ VkResult anv_WaitForFences(
       }
    }
 
-   return VK_SUCCESS;
+done:
+   if (unlikely(device->lost))
+      return VK_ERROR_DEVICE_LOST;
+
+   return result;
 }
 
 // Queue semaphore functions
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list