2016-02-26 13:39:01 +11:00
|
|
|
/*
|
2018-08-04 15:24:36 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2016-02-26 13:39:01 +11:00
|
|
|
*
|
|
|
|
* Copyright:
|
2017-09-13 23:26:15 +10:00
|
|
|
* 2016-2017, Danny Robson <danny@nerdcruft.net>
|
2016-02-26 13:39:01 +11:00
|
|
|
*/
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
#include "./except.hpp"
|
|
|
|
|
|
|
|
#include <cruft/util/debug.hpp>
|
2017-05-26 16:30:48 +10:00
|
|
|
#include <cruft/util/preprocessor.hpp>
|
2016-02-24 11:11:41 +11:00
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
using cruft::vk::error;
|
|
|
|
using cruft::vk::error_code;
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
|
2017-05-26 16:32:31 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define VK_RESULT_MAP(FUNC)\
|
2017-09-12 14:23:22 +10:00
|
|
|
MAP0(FUNC, \
|
|
|
|
VK_SUCCESS, \
|
|
|
|
VK_NOT_READY, \
|
|
|
|
VK_TIMEOUT, \
|
|
|
|
VK_EVENT_SET, \
|
|
|
|
VK_EVENT_RESET, \
|
|
|
|
VK_INCOMPLETE, \
|
|
|
|
VK_ERROR_OUT_OF_HOST_MEMORY, \
|
|
|
|
VK_ERROR_OUT_OF_DEVICE_MEMORY, \
|
|
|
|
VK_ERROR_INITIALIZATION_FAILED, \
|
|
|
|
VK_ERROR_DEVICE_LOST, \
|
|
|
|
VK_ERROR_MEMORY_MAP_FAILED, \
|
|
|
|
VK_ERROR_LAYER_NOT_PRESENT, \
|
|
|
|
VK_ERROR_EXTENSION_NOT_PRESENT, \
|
|
|
|
VK_ERROR_FEATURE_NOT_PRESENT, \
|
|
|
|
VK_ERROR_INCOMPATIBLE_DRIVER, \
|
|
|
|
VK_ERROR_TOO_MANY_OBJECTS, \
|
|
|
|
VK_ERROR_FORMAT_NOT_SUPPORTED, \
|
|
|
|
VK_ERROR_FRAGMENTED_POOL, \
|
|
|
|
VK_ERROR_VALIDATION_FAILED_EXT, \
|
|
|
|
VK_ERROR_SURFACE_LOST_KHR, \
|
|
|
|
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR, \
|
|
|
|
VK_SUBOPTIMAL_KHR, \
|
|
|
|
VK_ERROR_OUT_OF_DATE_KHR, \
|
|
|
|
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR, \
|
|
|
|
VK_ERROR_OUT_OF_POOL_MEMORY_KHR, \
|
|
|
|
VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR, \
|
2019-02-21 21:01:57 +11:00
|
|
|
VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT, \
|
2018-06-11 14:55:49 +10:00
|
|
|
VK_ERROR_INVALID_SHADER_NV, \
|
|
|
|
VK_ERROR_FRAGMENTATION_EXT, \
|
2019-02-21 21:01:57 +11:00
|
|
|
VK_ERROR_NOT_PERMITTED_EXT, \
|
|
|
|
VK_ERROR_INVALID_DEVICE_ADDRESS_EXT)
|
2017-05-26 16:32:31 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static constexpr
|
|
|
|
const char*
|
|
|
|
to_string (VkResult res)
|
|
|
|
{
|
|
|
|
switch (res) {
|
|
|
|
case VK_SUCCESS: return "success";
|
|
|
|
|
|
|
|
// partial successes
|
|
|
|
case VK_NOT_READY: return "not ready";
|
|
|
|
case VK_TIMEOUT: return "timeout";
|
|
|
|
case VK_EVENT_SET: return "event set";
|
|
|
|
case VK_EVENT_RESET: return "event reset";
|
|
|
|
case VK_INCOMPLETE: return "incomplete";
|
|
|
|
|
|
|
|
// errors
|
|
|
|
case VK_ERROR_OUT_OF_HOST_MEMORY: return "out of host memory";
|
|
|
|
case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "out of device memory";
|
|
|
|
case VK_ERROR_INITIALIZATION_FAILED: return "initialization failed";
|
|
|
|
case VK_ERROR_DEVICE_LOST: return "device lost";
|
|
|
|
case VK_ERROR_MEMORY_MAP_FAILED: return "memory map failed";
|
|
|
|
case VK_ERROR_LAYER_NOT_PRESENT: return "layer not present";
|
|
|
|
case VK_ERROR_EXTENSION_NOT_PRESENT: return "extension not present";
|
|
|
|
case VK_ERROR_FEATURE_NOT_PRESENT: return "feature not present";
|
|
|
|
case VK_ERROR_INCOMPATIBLE_DRIVER: return "incompatible driver";
|
|
|
|
case VK_ERROR_TOO_MANY_OBJECTS: return "too many objects";
|
|
|
|
case VK_ERROR_FORMAT_NOT_SUPPORTED: return "format not supported";
|
2017-09-07 15:52:14 +10:00
|
|
|
case VK_ERROR_FRAGMENTED_POOL: return "fragmented pool";
|
|
|
|
|
|
|
|
// EXT
|
|
|
|
case VK_ERROR_VALIDATION_FAILED_EXT: return "validation failed";
|
2018-06-11 14:55:49 +10:00
|
|
|
case VK_ERROR_FRAGMENTATION_EXT: return "too much fragmentation";
|
|
|
|
case VK_ERROR_NOT_PERMITTED_EXT: return "not permitted";
|
2019-02-21 21:01:57 +11:00
|
|
|
case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT: return "invalid DRM format modifier plane layout";
|
|
|
|
case VK_ERROR_INVALID_DEVICE_ADDRESS_EXT: return "invalid device address";
|
2017-09-07 15:52:14 +10:00
|
|
|
|
|
|
|
// KHR
|
|
|
|
case VK_ERROR_SURFACE_LOST_KHR: return "surface lost";
|
|
|
|
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "native window in use";
|
|
|
|
case VK_SUBOPTIMAL_KHR: return "suboptimal";
|
|
|
|
case VK_ERROR_OUT_OF_DATE_KHR: return "out of date";
|
|
|
|
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "incompatible display";
|
|
|
|
case VK_ERROR_OUT_OF_POOL_MEMORY_KHR: return "out of pool memory";
|
|
|
|
case VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR: return "invalid external handle";
|
|
|
|
|
|
|
|
// NV
|
|
|
|
case VK_ERROR_INVALID_SHADER_NV: return "invalid shader";
|
2017-05-26 16:32:31 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
unreachable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
error::try_code (VkResult res)
|
|
|
|
{
|
|
|
|
if (__builtin_expect (res >= 0, true))
|
|
|
|
return;
|
|
|
|
|
|
|
|
throw_code (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
error::throw_code (VkResult res)
|
|
|
|
{
|
2017-05-26 16:32:31 +10:00
|
|
|
#define THROW_CODE(C) case C: throw error_code<C> ();
|
2016-02-24 11:11:41 +11:00
|
|
|
switch (res) {
|
2017-05-26 16:32:31 +10:00
|
|
|
VK_RESULT_MAP (THROW_CODE)
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
2017-05-26 16:32:31 +10:00
|
|
|
#undef THROW_CODE
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
unreachable ();
|
|
|
|
}
|
2017-05-26 16:32:31 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <VkResult res>
|
|
|
|
const char*
|
|
|
|
error_code<res>::what (void) const noexcept
|
|
|
|
{
|
|
|
|
return to_string (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define ERROR_CODE(R) template class cruft::vk::error_code<R>;
|
|
|
|
VK_RESULT_MAP(ERROR_CODE)
|