From d083bc1c4b162ae23495fd9236d5fba27c04075b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tapani=20P=C3=A4lli?= Date: Fri, 25 Aug 2017 09:55:39 +0300 Subject: [PATCH] anv: wire up vk_errorf macro to do debug reporting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Tapani Pälli Reviewed-by: Jason Ekstrand --- src/intel/vulkan/anv_allocator.c | 8 ++++--- src/intel/vulkan/anv_device.c | 38 +++++++++++++++++++----------- src/intel/vulkan/anv_formats.c | 3 ++- src/intel/vulkan/anv_private.h | 12 +++++++--- src/intel/vulkan/anv_queue.c | 13 ++++++---- src/intel/vulkan/anv_util.c | 21 ++++++++++++++--- src/intel/vulkan/anv_wsi.c | 6 +++-- src/intel/vulkan/genX_cmd_buffer.c | 3 ++- src/intel/vulkan/genX_query.c | 3 ++- 9 files changed, 74 insertions(+), 33 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 708b32b3452..be750adeb52 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -361,12 +361,14 @@ anv_block_pool_expand_range(struct anv_block_pool *pool, MAP_SHARED | MAP_POPULATE, pool->fd, BLOCK_POOL_MEMFD_CENTER - center_bo_offset); if (map == MAP_FAILED) - return vk_errorf(VK_ERROR_MEMORY_MAP_FAILED, "mmap failed: %m"); + return vk_errorf(pool->device->instance, pool->device, + VK_ERROR_MEMORY_MAP_FAILED, "mmap failed: %m"); gem_handle = anv_gem_userptr(pool->device, map, size); if (gem_handle == 0) { munmap(map, size); - return vk_errorf(VK_ERROR_TOO_MANY_OBJECTS, "userptr failed: %m"); + return vk_errorf(pool->device->instance, pool->device, + VK_ERROR_TOO_MANY_OBJECTS, "userptr failed: %m"); } cleanup->map = map; @@ -1190,7 +1192,7 @@ anv_bo_cache_init(struct anv_bo_cache *cache) if (pthread_mutex_init(&cache->mutex, NULL)) { _mesa_hash_table_destroy(cache->bo_map, NULL); - return vk_errorf(VK_ERROR_OUT_OF_HOST_MEMORY, + return vk_errorf(NULL, NULL, VK_ERROR_OUT_OF_HOST_MEMORY, "pthread_mutex_init failed: %m"); } diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index f246e0ee6b4..32a6e99fa26 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -68,7 +68,7 @@ anv_compute_heap_size(int fd, uint64_t *heap_size) "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m"); if (anv_gem_get_aperture(fd, >t_size) == -1) { - return vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + return vk_errorf(NULL, NULL, VK_ERROR_INITIALIZATION_FAILED, "failed to get aperture size: %m"); } } @@ -210,13 +210,15 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) { const struct build_id_note *note = build_id_find_nhdr("libvulkan_intel.so"); if (!note) { - return vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + return vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "Failed to find build-id"); } unsigned build_id_len = build_id_length(note); if (build_id_len < 20) { - return vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + return vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "build-id too short. It needs to be a SHA"); } @@ -298,7 +300,8 @@ anv_physical_device_init(struct anv_physical_device *device, /* Broadwell, Cherryview, Skylake, Broxton, Kabylake is as fully * supported as anything */ } else { - result = vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, + result = vk_errorf(device->instance, device, + VK_ERROR_INCOMPATIBLE_DRIVER, "Vulkan not yet supported on %s", device->name); goto fail; } @@ -308,27 +311,31 @@ anv_physical_device_init(struct anv_physical_device *device, device->cmd_parser_version = anv_gem_get_param(fd, I915_PARAM_CMD_PARSER_VERSION); if (device->cmd_parser_version == -1) { - result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + result = vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "failed to get command parser version"); goto fail; } } if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) { - result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + result = vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "kernel missing gem wait"); goto fail; } if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) { - result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + result = vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "kernel missing execbuf2"); goto fail; } if (!device->info.has_llc && anv_gem_get_param(fd, I915_PARAM_MMAP_VERSION) < 1) { - result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED, + result = vk_errorf(device->instance, device, + VK_ERROR_INITIALIZATION_FAILED, "kernel missing wc mmap"); goto fail; } @@ -475,7 +482,7 @@ VkResult anv_CreateInstance( "incompatible driver version", ctor_cb->pUserData); - return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, + return vk_errorf(NULL, NULL, VK_ERROR_INCOMPATIBLE_DRIVER, "Client requested version %d.%d.%d", VK_VERSION_MAJOR(client_version), VK_VERSION_MINOR(client_version), @@ -1362,16 +1369,17 @@ anv_device_query_status(struct anv_device *device) if (ret == -1) { /* We don't know the real error. */ device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, "get_reset_stats failed: %m"); + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + "get_reset_stats failed: %m"); } if (active) { device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, "GPU hung on one of our command buffers"); } else if (pending) { device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, "GPU hung with commands in-flight"); } @@ -1391,7 +1399,8 @@ anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo) } 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"); + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + "gem wait failed: %m"); } /* Query for device status after the busy call. If the BO we're checking @@ -1413,7 +1422,8 @@ anv_device_wait(struct anv_device *device, struct anv_bo *bo, } 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"); + return vk_errorf(device->instance, device, 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_formats.c b/src/intel/vulkan/anv_formats.c index eead1aa7909..47acc56fd04 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -730,7 +730,8 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR( * vkGetPhysicalDeviceImageFormatProperties2KHR returns * VK_ERROR_FORMAT_NOT_SUPPORTED. */ - result = vk_errorf(VK_ERROR_FORMAT_NOT_SUPPORTED, + result = vk_errorf(physical_device->instance, physical_device, + VK_ERROR_FORMAT_NOT_SUPPORTED, "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x", external_info->handleType); goto fail; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 141712232da..1b481621990 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -303,11 +303,17 @@ vk_to_isl_color(VkClearColorValue color) * propagating errors. Might be useful to plug in a stack trace here. */ -VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...); +VkResult __vk_errorf(struct anv_instance *instance, const void *object, + VkDebugReportObjectTypeEXT type, VkResult error, + const char *file, int line, const char *format, ...); #ifdef DEBUG -#define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL); -#define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__); +#define vk_error(error) __vk_errorf(NULL, NULL,\ + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\ + error, __FILE__, __LINE__, NULL); +#define vk_errorf(instance, obj, error, format, ...)\ + __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\ + __FILE__, __LINE__, format, ## __VA_ARGS__); #define anv_debug(format, ...) fprintf(stderr, "debug: " format, ##__VA_ARGS__) #else #define vk_error(error) error diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c index 21ca66757e6..aff7c531190 100644 --- a/src/intel/vulkan/anv_queue.c +++ b/src/intel/vulkan/anv_queue.c @@ -43,7 +43,8 @@ anv_device_execbuf(struct anv_device *device, if (ret != 0) { /* We don't know the real error. */ device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, "execbuf2 failed: %m"); + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + "execbuf2 failed: %m"); } struct drm_i915_gem_exec_object2 *objects = @@ -239,7 +240,8 @@ out: * VK_ERROR_DEVICE_LOST to ensure that clients do not attempt to * submit the same job again to this device. */ - result = vk_errorf(VK_ERROR_DEVICE_LOST, "vkQueueSubmit() failed"); + result = vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + "vkQueueSubmit() failed"); device->lost = true; } @@ -429,7 +431,7 @@ VkResult anv_GetFenceStatus( } else { /* We don't know the real error. */ device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, "drm_syncobj_wait failed: %m"); } } else { @@ -509,7 +511,7 @@ anv_wait_for_syncobj_fences(struct anv_device *device, } else { /* We don't know the real error. */ device->lost = true; - return vk_errorf(VK_ERROR_DEVICE_LOST, + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, "drm_syncobj_wait failed: %m"); } } else { @@ -751,7 +753,8 @@ VkResult anv_ImportFenceFdKHR( if (anv_gem_syncobj_import_sync_file(device, new_impl.syncobj, fd)) { anv_gem_syncobj_destroy(device, new_impl.syncobj); - return vk_errorf(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR, + return vk_errorf(device->instance, NULL, + VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR, "syncobj sync file import failed: %m"); } break; diff --git a/src/intel/vulkan/anv_util.c b/src/intel/vulkan/anv_util.c index 45ce0a3aa0e..ec61f7355ef 100644 --- a/src/intel/vulkan/anv_util.c +++ b/src/intel/vulkan/anv_util.c @@ -93,10 +93,13 @@ __anv_perf_warn(struct anv_instance *instance, const void *object, } VkResult -__vk_errorf(VkResult error, const char *file, int line, const char *format, ...) +__vk_errorf(struct anv_instance *instance, const void *object, + VkDebugReportObjectTypeEXT type, VkResult error, + const char *file, int line, const char *format, ...) { va_list ap; char buffer[256]; + char report[256]; const char *error_str = vk_Result_to_str(error); @@ -105,11 +108,23 @@ __vk_errorf(VkResult error, const char *file, int line, const char *format, ...) vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - fprintf(stderr, "%s:%d: %s (%s)\n", file, line, buffer, error_str); + snprintf(report, sizeof(report), "%s:%d: %s (%s)", file, line, buffer, + error_str); } else { - fprintf(stderr, "%s:%d: %s\n", file, line, error_str); + snprintf(report, sizeof(report), "%s:%d: %s", file, line, error_str); } + anv_debug_report(instance, + VK_DEBUG_REPORT_ERROR_BIT_EXT, + type, + (uint64_t) (uintptr_t) object, + line, + 0, + "anv", + report); + + fprintf(stderr, "%s\n", report); + if (error == VK_ERROR_DEVICE_LOST && env_var_as_boolean("ANV_ABORT_ON_DEVICE_LOSS", false)) abort(); diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c index 00edb220b2b..c3e5dc1870b 100644 --- a/src/intel/vulkan/anv_wsi.c +++ b/src/intel/vulkan/anv_wsi.c @@ -248,7 +248,8 @@ anv_wsi_image_create(VkDevice device_h, surface->isl.row_pitch, I915_TILING_X); if (ret) { /* FINISHME: Choose a better error. */ - result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, + result = vk_errorf(device->instance, device, + VK_ERROR_OUT_OF_DEVICE_MEMORY, "set_tiling failed: %m"); goto fail_alloc_memory; } @@ -256,7 +257,8 @@ anv_wsi_image_create(VkDevice device_h, int fd = anv_gem_handle_to_fd(device, memory->bo->gem_handle); if (fd == -1) { /* FINISHME: Choose a better error. */ - result = vk_errorf(VK_ERROR_OUT_OF_DEVICE_MEMORY, + result = vk_errorf(device->instance, device, + VK_ERROR_OUT_OF_DEVICE_MEMORY, "handle_to_fd failed: %m"); goto fail_alloc_memory; } diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 67fc3f33df6..a16f67b108c 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -2492,7 +2492,8 @@ verify_cmd_parser(const struct anv_device *device, const char *function) { if (device->instance->physicalDevice.cmd_parser_version < required_version) { - return vk_errorf(VK_ERROR_FEATURE_NOT_PRESENT, + return vk_errorf(device->instance, device->instance, + VK_ERROR_FEATURE_NOT_PRESENT, "cmd parser version %d is required for %s", required_version, function); } else { diff --git a/src/intel/vulkan/genX_query.c b/src/intel/vulkan/genX_query.c index 5745fae8df6..7683d0d1e31 100644 --- a/src/intel/vulkan/genX_query.c +++ b/src/intel/vulkan/genX_query.c @@ -167,7 +167,8 @@ wait_for_available(struct anv_device *device, } 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"); + return vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + "gem wait failed: %m"); } else { assert(ret == 0); /* The BO is no longer busy. */ -- 2.30.2