libcruft-vk/except.cpp

149 lines
4.9 KiB
C++
Raw Normal View History

2016-02-26 13:39:01 +11:00
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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>
#include <cruft/util/preprocessor.hpp>
2016-02-24 11:11:41 +11:00
using cruft::vk::error;
using cruft::vk::error_code;
2016-02-24 11:11:41 +11: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, \
VK_ERROR_INVALID_SHADER_NV, \
VK_ERROR_FRAGMENTATION_EXT, \
VK_ERROR_NOT_PERMITTED_EXT)
///////////////////////////////////////////////////////////////////////////////
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";
case VK_ERROR_FRAGMENTATION_EXT: return "too much fragmentation";
case VK_ERROR_NOT_PERMITTED_EXT: return "not permitted";
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";
}
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)
{
#define THROW_CODE(C) case C: throw error_code<C> ();
2016-02-24 11:11:41 +11:00
switch (res) {
VK_RESULT_MAP (THROW_CODE)
2016-02-24 11:11:41 +11:00
}
#undef THROW_CODE
2016-02-24 11:11:41 +11:00
unreachable ();
}
///////////////////////////////////////////////////////////////////////////////
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)