anv: wire up vk_errorf macro to do debug reporting
authorTapani Pälli <tapani.palli@intel.com>
Fri, 25 Aug 2017 06:55:39 +0000 (09:55 +0300)
committerTapani Pälli <tapani.palli@intel.com>
Tue, 12 Sep 2017 06:42:00 +0000 (09:42 +0300)
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c
src/intel/vulkan/anv_util.c
src/intel/vulkan/anv_wsi.c
src/intel/vulkan/genX_cmd_buffer.c
src/intel/vulkan/genX_query.c

index 708b32b34520f247014d90711463db90348e49f0..be750adeb5223919b797f09f2d72eed903e0a1aa 100644 (file)
@@ -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");
    }
 
index f246e0ee6b4e5209d06aa0af546fdb2f92c9da83..32a6e99fa26bd4cbd8aec680fcb44cb9344d113e 100644 (file)
@@ -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, &gtt_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
index eead1aa790926753f50cedd39ac0f3b3389a660d..47acc56fd04137a2a60c542c69c9c0caa566c507 100644 (file)
@@ -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;
index 141712232dafe6654302d39ae1b773b8a7dadca7..1b481621990d9b90a425c77009da9254b1537c31 100644 (file)
@@ -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
index 21ca66757e6e8e736fd766b90669ffb9d6815cd5..aff7c531190891fdda09f7240327bdba74ab935f 100644 (file)
@@ -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;
index 45ce0a3aa0e88b1602b33f64b60ce36b011d2a3a..ec61f7355ef693a8c572ebb6f77a6acff3f68aa5 100644 (file)
@@ -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();
index 00edb220b2bf5e316d4d223b857b1ef7ca76f1d6..c3e5dc1870b1b3e21b31725bd9bf6041bebc25a0 100644 (file)
@@ -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;
    }
index 67fc3f33df616208155fd789c1b40e9d75efa176..a16f67b108c051f1e81363126d952d72af45c679 100644 (file)
@@ -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 {
index 5745fae8df601169e06cc4c46d23ee9cb1d4bc01..7683d0d1e31a614f31515da36d3e6151d8bf7c3b 100644 (file)
@@ -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. */