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);
fail:
close(fd);
- return vk_error(VK_ERROR_UNAVAILABLE);
+ return result;
}
static void *default_alloc(
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++)
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;
}
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;
* 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
}
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",
"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;
}