From: Jason Ekstrand Date: Sat, 18 Jan 2020 04:43:06 +0000 (-0600) Subject: anv: Take an anv_device in vk_errorf X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb6ea7704574475c56c930e18363070be6073cc1;p=mesa.git anv: Take an anv_device in vk_errorf Reviewed-by: Lionel Landwerlin Part-of: --- diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 572dd7aed92..6cf1d5fa36a 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -207,7 +207,7 @@ anv_state_table_expand_range(struct anv_state_table *table, uint32_t size) map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, table->fd, 0); if (map == MAP_FAILED) { - return vk_errorf(table->device->instance, table->device, + return vk_errorf(table->device, table->device, VK_ERROR_OUT_OF_HOST_MEMORY, "mmap failed: %m"); } @@ -519,7 +519,7 @@ 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(pool->device->instance, pool->device, + return vk_errorf(pool->device, pool->device, VK_ERROR_MEMORY_MAP_FAILED, "mmap failed: %m"); struct anv_bo *new_bo; @@ -1586,8 +1586,7 @@ anv_device_alloc_bo(struct anv_device *device, if (new_bo.map) anv_gem_munmap(new_bo.map, size); anv_gem_close(device, new_bo.gem_handle); - return vk_errorf(device->instance, NULL, - VK_ERROR_OUT_OF_DEVICE_MEMORY, + return vk_errorf(device, NULL, VK_ERROR_OUT_OF_DEVICE_MEMORY, "failed to allocate virtual address for BO"); } } @@ -1636,24 +1635,21 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device, assert(bo->gem_handle == gem_handle); if (bo_flags != bo->flags) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "same host pointer imported two different ways"); } if (bo->has_client_visible_address != ((alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported with and without buffer " "device address"); } if (client_address && client_address != gen_48b_address(bo->offset)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported at two different " "addresses"); } @@ -1677,8 +1673,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device, if (!anv_vma_alloc(device, &new_bo, client_address)) { anv_gem_close(device, new_bo.gem_handle); pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_OUT_OF_DEVICE_MEMORY, + return vk_errorf(device, NULL, VK_ERROR_OUT_OF_DEVICE_MEMORY, "failed to allocate virtual address for BO"); } @@ -1737,8 +1732,7 @@ anv_device_import_bo(struct anv_device *device, if ((bo->flags & EXEC_OBJECT_PINNED) != (bo_flags & EXEC_OBJECT_PINNED)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported two different ways"); } @@ -1753,24 +1747,21 @@ anv_device_import_bo(struct anv_device *device, (bo->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) != (bo_flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported on two different heaps"); } if (bo->has_client_visible_address != ((alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported with and without buffer " "device address"); } if (client_address && client_address != gen_48b_address(bo->offset)) { pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported at two different " "addresses"); } @@ -1801,8 +1792,7 @@ anv_device_import_bo(struct anv_device *device, if (!anv_vma_alloc(device, &new_bo, client_address)) { anv_gem_close(device, new_bo.gem_handle); pthread_mutex_unlock(&cache->mutex); - return vk_errorf(device->instance, NULL, - VK_ERROR_OUT_OF_DEVICE_MEMORY, + return vk_errorf(device, NULL, VK_ERROR_OUT_OF_DEVICE_MEMORY, "failed to allocate virtual address for BO"); } diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index dc5b9722985..7e4047696f9 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -445,8 +445,7 @@ anv_image_from_gralloc(VkDevice device_h, }; if (gralloc_info->handle->numFds != 1) { - return vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "VkNativeBufferANDROID::handle::numFds is %d, " "expected 1", gralloc_info->handle->numFds); } @@ -472,7 +471,7 @@ anv_image_from_gralloc(VkDevice device_h, 0 /* client_address */, &bo); if (result != VK_SUCCESS) { - return vk_errorf(device->instance, device, result, + return vk_errorf(device, device, result, "failed to import dma-buf from VkNativeBufferANDROID"); } @@ -488,14 +487,12 @@ anv_image_from_gralloc(VkDevice device_h, anv_info.isl_tiling_flags = ISL_TILING_Y0_BIT; break; case -1: - result = vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "DRM_IOCTL_I915_GEM_GET_TILING failed for " "VkNativeBufferANDROID"); goto fail_tiling; default: - result = vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "DRM_IOCTL_I915_GEM_GET_TILING returned unknown " "tiling %d for VkNativeBufferANDROID", i915_tiling); goto fail_tiling; @@ -516,8 +513,7 @@ anv_image_from_gralloc(VkDevice device_h, goto fail_create; if (bo->size < image->size) { - result = vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "dma-buf from VkNativeBufferANDROID is too small for " "VkImage: %"PRIu64"B < %"PRIu64"B", bo->size, image->size); @@ -568,7 +564,7 @@ format_supported_with_usage(VkDevice device_h, VkFormat format, result = anv_GetPhysicalDeviceImageFormatProperties2(phys_dev_h, &image_format_info, &image_format_props); if (result != VK_SUCCESS) { - return vk_errorf(device->instance, device, result, + return vk_errorf(device, device, result, "anv_GetPhysicalDeviceImageFormatProperties2 failed " "inside %s", __func__); } @@ -607,7 +603,7 @@ setup_gralloc0_usage(VkFormat format, VkImageUsageFlags imageUsage, * gralloc swapchains. */ if (imageUsage != 0) { - return vk_errorf(device->instance, device, VK_ERROR_FORMAT_NOT_SUPPORTED, + return vk_errorf(device, device, VK_ERROR_FORMAT_NOT_SUPPORTED, "unsupported VkImageUsageFlags(0x%x) for gralloc " "swapchain", imageUsage); } @@ -709,7 +705,7 @@ anv_AcquireImageANDROID( * VkFence. */ if (sync_wait(nativeFenceFd, /*timeout*/ -1) < 0) { - result = vk_errorf(device->instance, device, VK_ERROR_DEVICE_LOST, + result = vk_errorf(device, device, VK_ERROR_DEVICE_LOST, "%s: failed to wait on nativeFenceFd=%d", __func__, nativeFenceFd); } @@ -755,7 +751,7 @@ anv_AcquireImageANDROID( result = anv_QueueSubmit(anv_queue_to_handle(&device->queue), 1, &submit, fence_h); if (result != VK_SUCCESS) { - return vk_errorf(device->instance, device, result, + return vk_errorf(device, device, result, "anv_QueueSubmit failed inside %s", __func__); } } diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index a4fa701bae1..9eb87162aa7 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -136,8 +136,9 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd) "Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m"); if (anv_gem_get_aperture(fd, &device->gtt_size) == -1) { - return vk_errorf(NULL, NULL, VK_ERROR_INITIALIZATION_FAILED, - "failed to get aperture size: %m"); + return vk_errorfi(device->instance, NULL, + VK_ERROR_INITIALIZATION_FAILED, + "failed to get aperture size: %m"); } } @@ -212,16 +213,16 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) const struct build_id_note *note = build_id_find_nhdr_for_addr(anv_physical_device_init_uuids); if (!note) { - return vk_errorf(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "Failed to find build-id"); + return vk_errorfi(device->instance, NULL, + 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(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "build-id too short. It needs to be a SHA"); + return vk_errorfi(device->instance, NULL, + VK_ERROR_INITIALIZATION_FAILED, + "build-id too short. It needs to be a SHA"); } memcpy(device->driver_build_sha1, build_id_data(note), 20); @@ -377,9 +378,8 @@ anv_physical_device_init(struct anv_physical_device *device, } else if (device->info.gen == 12) { intel_logw("Vulkan is not yet fully supported on gen12"); } else { - result = vk_errorf(device->instance, device, - VK_ERROR_INCOMPATIBLE_DRIVER, - "Vulkan not yet supported on %s", device->name); + result = vk_errorfi(instance, NULL, VK_ERROR_INCOMPATIBLE_DRIVER, + "Vulkan not yet supported on %s", device->name); goto fail; } @@ -388,32 +388,32 @@ 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(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "failed to get command parser version"); + result = vk_errorfi(device->instance, NULL, + 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(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "kernel missing gem wait"); + result = vk_errorfi(device->instance, NULL, + VK_ERROR_INITIALIZATION_FAILED, + "kernel missing gem wait"); goto fail; } if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) { - result = vk_errorf(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "kernel missing execbuf2"); + result = vk_errorfi(device->instance, NULL, + 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(device->instance, device, - VK_ERROR_INITIALIZATION_FAILED, - "kernel missing wc mmap"); + result = vk_errorfi(device->instance, NULL, + VK_ERROR_INITIALIZATION_FAILED, + "kernel missing wc mmap"); goto fail; } @@ -3077,7 +3077,7 @@ _anv_device_set_lost(struct anv_device *device, p_atomic_inc(&device->_lost); va_start(ap, msg); - err = __vk_errorv(device->instance, device, + err = __vk_errorv(device->physical->instance, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, VK_ERROR_DEVICE_LOST, file, line, msg, ap); va_end(ap); @@ -3099,7 +3099,7 @@ _anv_queue_set_lost(struct anv_queue *queue, p_atomic_inc(&queue->device->_lost); va_start(ap, msg); - err = __vk_errorv(queue->device->instance, queue->device, + err = __vk_errorv(queue->device->physical->instance, queue->device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, VK_ERROR_DEVICE_LOST, file, line, msg, ap); va_end(ap); @@ -3437,8 +3437,7 @@ VkResult anv_AllocateMemory( * this sort of attack but only if it can trust the buffer size. */ if (mem->bo->size < aligned_alloc_size) { - result = vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "aligned allocationSize too large for " "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT: " "%"PRIu64"B > %"PRIu64"B", @@ -3507,8 +3506,7 @@ VkResult anv_AllocateMemory( i915_tiling); if (ret) { anv_device_release_bo(device, mem->bo); - result = vk_errorf(device->instance, NULL, - VK_ERROR_OUT_OF_DEVICE_MEMORY, + result = vk_errorf(device, device, VK_ERROR_OUT_OF_DEVICE_MEMORY, "failed to set BO tiling: %m"); goto fail; } @@ -3520,8 +3518,7 @@ VkResult anv_AllocateMemory( if (mem_heap_used > mem_heap->size) { p_atomic_add(&mem_heap->used, -mem->bo->size); anv_device_release_bo(device, mem->bo); - result = vk_errorf(device->instance, NULL, - VK_ERROR_OUT_OF_DEVICE_MEMORY, + result = vk_errorf(device, device, VK_ERROR_OUT_OF_DEVICE_MEMORY, "Out of heap memory"); goto fail; } diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index a1c4923cf2c..caf409ea9f3 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -1160,10 +1160,10 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2( * vkGetPhysicalDeviceImageFormatProperties2 returns * VK_ERROR_FORMAT_NOT_SUPPORTED. */ - result = vk_errorf(physical_device->instance, physical_device, - VK_ERROR_FORMAT_NOT_SUPPORTED, - "unsupported VkExternalMemoryTypeFlagBits 0x%x", - external_info->handleType); + result = vk_errorfi(physical_device->instance, physical_device, + VK_ERROR_FORMAT_NOT_SUPPORTED, + "unsupported VkExternalMemoryTypeFlagBits 0x%x", + external_info->handleType); goto fail; } } diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index d73bc3d3768..23489c011a1 100644 --- a/src/intel/vulkan/anv_intel.c +++ b/src/intel/vulkan/anv_intel.c @@ -82,8 +82,7 @@ VkResult anv_CreateDmaBufImageINTEL( VkDeviceSize aligned_image_size = align_u64(image->size, 4096); if (mem->bo->size < aligned_image_size) { - result = vk_errorf(device->instance, device, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "dma-buf too small for image in " "vkCreateDmaBufImageINTEL: %"PRIu64"B < %"PRIu64"B", mem->bo->size, aligned_image_size); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 8b772582190..84f1dc53d86 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -448,15 +448,16 @@ VkResult __vk_errorf(struct anv_instance *instance, const void *object, #define vk_error(error) __vk_errorf(NULL, NULL,\ VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\ error, __FILE__, __LINE__, NULL) -#define vk_errorv(instance, obj, error, format, args)\ - __vk_errorv(instance, obj, REPORT_OBJECT_TYPE(obj), error,\ - __FILE__, __LINE__, format, args) -#define vk_errorf(instance, obj, error, format, ...)\ +#define vk_errorfi(instance, obj, error, format, ...)\ __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\ __FILE__, __LINE__, format, ## __VA_ARGS__) +#define vk_errorf(device, obj, error, format, ...)\ + vk_errorfi(anv_device_instance_or_null(device),\ + obj, error, format, ## __VA_ARGS__) #else #define vk_error(error) error -#define vk_errorf(instance, obj, error, format, ...) error +#define vk_errorfi(instance, obj, error, format, ...) error +#define vk_errorf(device, obj, error, format, ...) error #endif /** @@ -1270,6 +1271,12 @@ struct anv_device { struct gen_aux_map_context *aux_map_ctx; }; +static inline struct anv_instance * +anv_device_instance_or_null(const struct anv_device *device) +{ + return device ? device->physical->instance : NULL; +} + static inline struct anv_state_pool * anv_binding_table_pool(struct anv_device *device) { diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c index 0a25b5ecf04..b93d070711d 100644 --- a/src/intel/vulkan/anv_queue.c +++ b/src/intel/vulkan/anv_queue.c @@ -1624,8 +1624,7 @@ 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(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "syncobj sync file import failed: %m"); } break; @@ -2020,8 +2019,7 @@ VkResult anv_ImportSemaphoreFdKHR( return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); if (anv_gem_syncobj_import_sync_file(device, new_impl.syncobj, fd)) { anv_gem_syncobj_destroy(device, new_impl.syncobj); - return vk_errorf(device->instance, NULL, - VK_ERROR_INVALID_EXTERNAL_HANDLE, + return vk_errorf(device, NULL, VK_ERROR_INVALID_EXTERNAL_HANDLE, "syncobj sync file import failed: %m"); } /* Ownership of the FD is transfered to Anv. Since we don't need it diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 3062429a4d8..88d17eeab1e 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -3838,7 +3838,7 @@ verify_cmd_parser(const struct anv_device *device, const char *function) { if (device->physical->cmd_parser_version < required_version) { - return vk_errorf(device->instance, device->instance, + return vk_errorf(device, device->physical, VK_ERROR_FEATURE_NOT_PRESENT, "cmd parser version %d is required for %s", required_version, function);