libcruft-vk/except.cpp

68 lines
2.5 KiB
C++

/*
* 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>
*/
#include "./except.hpp"
#include <cruft/util/debug.hpp>
#include <cruft/util/preprocessor.hpp>
using cruft::vk::error;
using cruft::vk::error_code;
///////////////////////////////////////////////////////////////////////////////
void
error::try_code (VkResult res)
{
if (__builtin_expect (res >= 0, true))
return;
throw_code (res);
}
//-----------------------------------------------------------------------------
void
error::throw_code (VkResult res)
{
switch (res) {
case VK_SUCCESS: throw error_code<VK_SUCCESS> ();
// partial successes
case VK_NOT_READY: throw error_code<VK_NOT_READY> ();
case VK_TIMEOUT: throw error_code<VK_TIMEOUT> ();
case VK_EVENT_SET: throw error_code<VK_EVENT_SET> ();
case VK_EVENT_RESET: throw error_code<VK_EVENT_RESET> ();
case VK_INCOMPLETE: throw error_code<VK_INCOMPLETE> ();
// errors
case VK_ERROR_OUT_OF_HOST_MEMORY: throw error_code<VK_ERROR_OUT_OF_HOST_MEMORY> ();
case VK_ERROR_OUT_OF_DEVICE_MEMORY: throw error_code<VK_ERROR_OUT_OF_DEVICE_MEMORY> ();
case VK_ERROR_INITIALIZATION_FAILED: throw error_code<VK_ERROR_INITIALIZATION_FAILED> ();
case VK_ERROR_DEVICE_LOST: throw error_code<VK_ERROR_DEVICE_LOST> ();
case VK_ERROR_MEMORY_MAP_FAILED: throw error_code<VK_ERROR_MEMORY_MAP_FAILED> ();
case VK_ERROR_LAYER_NOT_PRESENT: throw error_code<VK_ERROR_LAYER_NOT_PRESENT> ();
case VK_ERROR_EXTENSION_NOT_PRESENT: throw error_code<VK_ERROR_EXTENSION_NOT_PRESENT> ();
case VK_ERROR_FEATURE_NOT_PRESENT: throw error_code<VK_ERROR_FEATURE_NOT_PRESENT> ();
case VK_ERROR_INCOMPATIBLE_DRIVER: throw error_code<VK_ERROR_INCOMPATIBLE_DRIVER> ();
case VK_ERROR_TOO_MANY_OBJECTS: throw error_code<VK_ERROR_TOO_MANY_OBJECTS> ();
case VK_ERROR_FORMAT_NOT_SUPPORTED: throw error_code<VK_ERROR_FORMAT_NOT_SUPPORTED> ();
}
unreachable ();
}