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:
|
|
|
|
* 2016, Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
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)\
|
|
|
|
MAP(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, \
|
2017-09-05 17:20:17 +10:00
|
|
|
VK_ERROR_FORMAT_NOT_SUPPORTED)
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|