diff options
author | Kristian Høgsberg Kristensen <[email protected]> | 2015-08-26 04:03:38 -0700 |
---|---|---|
committer | Kristian Høgsberg Kristensen <[email protected]> | 2015-09-03 11:53:08 -0700 |
commit | c4b30e7885f1d47e57753db49d232669d87a88e5 (patch) | |
tree | da3699b7618cab688392ec8b4e194cf2ad6d14b0 /src/vulkan | |
parent | 2e346c882ddbea68db6dc0b6a05a9e9186624c04 (diff) |
vk: Add new vk_errorf that takes a format string
This allows us to annotate error cases in debug builds.
Signed-off-by: Kristian Høgsberg Kristensen <[email protected]>
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/anv_device.c | 43 | ||||
-rw-r--r-- | src/vulkan/anv_image.c | 3 | ||||
-rw-r--r-- | src/vulkan/anv_private.h | 5 | ||||
-rw-r--r-- | src/vulkan/anv_query.c | 2 | ||||
-rw-r--r-- | src/vulkan/anv_util.c | 22 | ||||
-rw-r--r-- | src/vulkan/anv_x11.c | 4 |
6 files changed, 52 insertions, 27 deletions
diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index 19f3c1ed3cc..37cf7d3cea9 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -36,38 +36,53 @@ anv_physical_device_init(struct anv_physical_device *device, struct anv_instance *instance, const char *path) { + VkResult result; int fd; fd = open(path, O_RDWR | O_CLOEXEC); if (fd < 0) - return vk_error(VK_ERROR_UNAVAILABLE); + return vk_errorf(VK_ERROR_UNAVAILABLE, "failed to open %s: %m", path); device->instance = instance; device->path = path; device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID); - if (!device->chipset_id) + if (!device->chipset_id) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get chipset id: %m"); goto fail; + } device->name = brw_get_device_name(device->chipset_id); device->info = brw_get_device_info(device->chipset_id, -1); - if (!device->info) + if (!device->info) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get device info"); goto fail; + } - if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) + if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "failed to get aperture size: %m"); goto fail; + } - if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "kernel missing gem wait"); goto fail; + } - if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "kernel missing execbuf2"); goto fail; + } - if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC)) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "non-llc gpu"); goto fail; + } - if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CONSTANTS)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CONSTANTS)) { + result = vk_errorf(VK_ERROR_UNAVAILABLE, "kernel missing exec constants"); goto fail; + } close(fd); @@ -75,7 +90,7 @@ anv_physical_device_init(struct anv_physical_device *device, fail: close(fd); - return vk_error(VK_ERROR_UNAVAILABLE); + return result; } static void *default_alloc( @@ -729,12 +744,12 @@ VkResult anv_QueueSubmit( ret = anv_gem_execbuffer(device, &cmd_buffer->execbuf2.execbuf); if (ret != 0) - return vk_error(VK_ERROR_UNKNOWN); + return vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m"); if (fence) { ret = anv_gem_execbuffer(device, &fence->execbuf); if (ret != 0) - return vk_error(VK_ERROR_UNKNOWN); + return vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m"); } for (uint32_t i = 0; i < cmd_buffer->execbuf2.bo_count; i++) @@ -797,14 +812,14 @@ VkResult anv_DeviceWaitIdle( ret = anv_gem_execbuffer(device, &execbuf); if (ret != 0) { - result = vk_error(VK_ERROR_UNKNOWN); + result = vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m"); goto fail; } timeout = INT64_MAX; ret = anv_gem_wait(device, bo->gem_handle, &timeout); if (ret != 0) { - result = vk_error(VK_ERROR_UNKNOWN); + result = vk_errorf(VK_ERROR_UNKNOWN, "execbuf2 failed: %m"); goto fail; } @@ -1211,7 +1226,7 @@ VkResult anv_WaitForFences( if (ret == -1 && errno == ETIME) return VK_TIMEOUT; else if (ret == -1) - return vk_error(VK_ERROR_UNKNOWN); + return vk_errorf(VK_ERROR_UNKNOWN, "gem wait failed: %m"); } return VK_SUCCESS; diff --git a/src/vulkan/anv_image.c b/src/vulkan/anv_image.c index 7a37497d0cc..fbcd435a1a0 100644 --- a/src/vulkan/anv_image.c +++ b/src/vulkan/anv_image.c @@ -259,8 +259,7 @@ anv_image_create(VkDevice _device, extent->height > limits->height || extent->depth > limits->depth) { /* TODO(chadv): What is the correct error? */ - anv_loge("image extent is too large"); - return vk_error(VK_ERROR_INVALID_MEMORY_SIZE); + return vk_errorf(VK_ERROR_INVALID_MEMORY_SIZE, "image extent is too large"); } image = anv_device_alloc(device, sizeof(*image), 8, diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index b662af6cf5f..ca62dc487d7 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -120,10 +120,11 @@ struct anv_common { * propagating errors. Might be useful to plug in a stack trace here. */ -VkResult __vk_error(VkResult error, const char *file, int line); +VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...); #ifdef DEBUG -#define vk_error(error) __vk_error(error, __FILE__, __LINE__); +#define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL); +#define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__); #else #define vk_error(error) error #endif diff --git a/src/vulkan/anv_query.c b/src/vulkan/anv_query.c index 3785560dc3b..4ef9d8c4b0c 100644 --- a/src/vulkan/anv_query.c +++ b/src/vulkan/anv_query.c @@ -123,7 +123,7 @@ VkResult anv_GetQueryPoolResults( if (flags & VK_QUERY_RESULT_WAIT_BIT) { ret = anv_gem_wait(device, pool->bo.gem_handle, &timeout); if (ret == -1) - return vk_error(VK_ERROR_UNKNOWN); + return vk_errorf(VK_ERROR_UNKNOWN, "gem_wait failed %m"); } for (uint32_t i = 0; i < queryCount; i++) { diff --git a/src/vulkan/anv_util.c b/src/vulkan/anv_util.c index a78847acec6..94f14f98f8f 100644 --- a/src/vulkan/anv_util.c +++ b/src/vulkan/anv_util.c @@ -83,8 +83,11 @@ anv_abortfv(const char *format, va_list va) } VkResult -__vk_error(VkResult error, const char *file, int line) +__vk_errorf(VkResult error, const char *file, int line, const char *format, ...) { + va_list ap; + char buffer[256]; + static const char *error_names[] = { "VK_ERROR_UNKNOWN", "VK_ERROR_UNAVAILABLE", @@ -120,11 +123,18 @@ __vk_error(VkResult error, const char *file, int line) "VK_ERROR_INVALID_LAYER", }; - if (error <= VK_ERROR_UNKNOWN && error >= VK_ERROR_INVALID_LAYER) - fprintf(stderr, "%s:%d: %s\n", - file, line, error_names[-error - VK_ERROR_UNKNOWN]); - else - fprintf(stderr, "%s:%d: vk error %d\n", file, line, error); + assert(error <= VK_ERROR_UNKNOWN && error >= VK_ERROR_INVALID_LAYER); + + if (format) { + va_start(ap, format); + vsnprintf(buffer, sizeof(buffer), format, ap); + va_end(ap); + + fprintf(stderr, "%s:%d: %s (%s)\n", file, line, + buffer, error_names[-error - 1]); + } else { + fprintf(stderr, "%s:%d: %s\n", file, line, error_names[-error - 1]); + } return error; } diff --git a/src/vulkan/anv_x11.c b/src/vulkan/anv_x11.c index f65a86487cb..3c6d41aa79e 100644 --- a/src/vulkan/anv_x11.c +++ b/src/vulkan/anv_x11.c @@ -163,13 +163,13 @@ VkResult anv_CreateSwapChainWSI( ret = anv_gem_set_tiling(device, memory->bo.gem_handle, surface->stride, I915_TILING_X); if (ret) { - result = vk_error(VK_ERROR_UNKNOWN); + result = vk_errorf(VK_ERROR_UNKNOWN, "set_tiling failed: %m"); goto fail; } int fd = anv_gem_handle_to_fd(device, memory->bo.gem_handle); if (fd == -1) { - result = vk_error(VK_ERROR_UNKNOWN); + result = vk_errorf(VK_ERROR_UNKNOWN, "handle_to_fd failed: %m"); goto fail; } |