mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-01 08:08:06 +02:00
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 <kristian.h.kristensen@intel.com>
This commit is contained in:
parent
2e346c882d
commit
c4b30e7885
6 changed files with 52 additions and 27 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue