anv: Check for device loss at the end of WaitForFences

It's possible that the device could have been lost while we were
waiting.  We should let the user know if this has happened.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Jason Ekstrand
2017-03-27 16:01:42 -07:00
parent c6f69eea6a
commit 82573d0f75

View File

@@ -1857,6 +1857,7 @@ VkResult anv_WaitForFences(
*/ */
int64_t timeout = MIN2(_timeout, INT64_MAX); int64_t timeout = MIN2(_timeout, INT64_MAX);
VkResult result = VK_SUCCESS;
uint32_t pending_fences = fenceCount; uint32_t pending_fences = fenceCount;
while (pending_fences) { while (pending_fences) {
pending_fences = 0; pending_fences = 0;
@@ -1877,8 +1878,10 @@ VkResult anv_WaitForFences(
/* This fence is not pending. If waitAll isn't set, we can return /* This fence is not pending. If waitAll isn't set, we can return
* early. Otherwise, we have to keep going. * early. Otherwise, we have to keep going.
*/ */
if (!waitAll) if (!waitAll) {
return VK_SUCCESS; result = VK_SUCCESS;
goto done;
}
continue; continue;
case ANV_FENCE_STATE_SUBMITTED: case ANV_FENCE_STATE_SUBMITTED:
@@ -1887,7 +1890,8 @@ VkResult anv_WaitForFences(
*/ */
ret = anv_gem_wait(device, fence->bo.gem_handle, &timeout); ret = anv_gem_wait(device, fence->bo.gem_handle, &timeout);
if (ret == -1 && errno == ETIME) { if (ret == -1 && errno == ETIME) {
return VK_TIMEOUT; result = VK_TIMEOUT;
goto done;
} else if (ret == -1) { } else if (ret == -1) {
/* We don't know the real error. */ /* We don't know the real error. */
device->lost = true; device->lost = true;
@@ -1950,7 +1954,8 @@ VkResult anv_WaitForFences(
if (time_elapsed >= timeout) { if (time_elapsed >= timeout) {
pthread_mutex_unlock(&device->mutex); pthread_mutex_unlock(&device->mutex);
return VK_TIMEOUT; result = VK_TIMEOUT;
goto done;
} }
timeout -= time_elapsed; timeout -= time_elapsed;
@@ -1960,7 +1965,11 @@ VkResult anv_WaitForFences(
} }
} }
return VK_SUCCESS; done:
if (unlikely(device->lost))
return VK_ERROR_DEVICE_LOST;
return result;
} }
// Queue semaphore functions // Queue semaphore functions