--- src/intel/vulkan/anv_device.c | 26 +++++++++++++++++++------- src/intel/vulkan/anv_gem.c | 17 +++++++++++++++++ src/intel/vulkan/anv_private.h | 1 + 3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 9e860d5..fc3c27e 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -1294,13 +1294,25 @@ VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo, int64_t timeout) { - int ret = anv_gem_wait(device, bo->gem_handle, &timeout); - if (ret == -1 && errno == ETIME) { - return VK_TIMEOUT; - } else if (ret == -1) { - /* We don't know the real error. */ - device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, "gem wait failed: %m"); + if (timeout == 0) { + /* GEM_BUSY is more efficient if we don't want to wait */ + int ret = anv_gem_busy(device, bo->gem_handle); + if (ret == 1) { + return VK_TIMEOUT; + } else if (ret == -1) { + /* We don't know the real error. */ + device->lost = true; + return vk_errorf(VK_ERROR_DEVICE_LOST, "gem wait failed: %m"); + } + } else { + int ret = anv_gem_wait(device, bo->gem_handle, &timeout); + if (ret == -1 && errno == ETIME) { + return VK_TIMEOUT; + } else if (ret == -1) { + /* We don't know the real error. */ + device->lost = true; + return vk_errorf(VK_ERROR_DEVICE_LOST, "gem wait failed: %m"); + } } /* Query for device status after the wait. If the BO we're waiting on got diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c index 7612f49..86a456a 100644 --- a/src/intel/vulkan/anv_gem.c +++ b/src/intel/vulkan/anv_gem.c @@ -147,6 +147,23 @@ anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle, } /** + * Returns 0, 1, or negative to indicate error + */ +int +anv_gem_busy(struct anv_device *device, uint32_t gem_handle) +{ + struct drm_i915_gem_busy busy = { + .handle = gem_handle, + }; + + int ret = anv_ioctl(device->fd, DRM_IOCTL_I915_GEM_BUSY, &busy); + if (ret < 0) + return ret; + + return busy.busy != 0; +} + +/** * On error, \a timeout_ns holds the remaining time. */ int diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index dc83b4a..2375247 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -647,6 +647,7 @@ void anv_gem_munmap(void *p, uint64_t size); uint32_t anv_gem_create(struct anv_device *device, size_t size); void anv_gem_close(struct anv_device *device, uint32_t gem_handle); uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size); +int anv_gem_busy(struct anv_device *device, uint32_t gem_handle); int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns); int anv_gem_execbuffer(struct anv_device *device, struct drm_i915_gem_execbuffer2 *execbuf); -- 2.5.0.400.gff86faf _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev