mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-24 10:23:01 -06:00
renderer_vulkan/wrapper: Add exception class
This commit is contained in:
parent
f5cee0e885
commit
3f0b7673f0
2 changed files with 34 additions and 0 deletions
|
@ -14,6 +14,10 @@
|
||||||
|
|
||||||
namespace Vulkan::vk {
|
namespace Vulkan::vk {
|
||||||
|
|
||||||
|
const char* Exception::what() const noexcept {
|
||||||
|
return ToString(result);
|
||||||
|
}
|
||||||
|
|
||||||
const char* ToString(VkResult result) noexcept {
|
const char* ToString(VkResult result) noexcept {
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case VkResult::VK_SUCCESS:
|
case VkResult::VK_SUCCESS:
|
||||||
|
|
|
@ -80,7 +80,37 @@ private:
|
||||||
std::size_t num = 0;
|
std::size_t num = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Vulkan exception generated from a VkResult.
|
||||||
|
class Exception final : public std::exception {
|
||||||
|
public:
|
||||||
|
/// Construct the exception with a result.
|
||||||
|
/// @pre result != VK_SUCCESS
|
||||||
|
explicit Exception(VkResult result_) : result{result_} {}
|
||||||
|
virtual ~Exception() = default;
|
||||||
|
|
||||||
|
const char* what() const noexcept override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
VkResult result;
|
||||||
|
};
|
||||||
|
|
||||||
/// Converts a VkResult enum into a rodata string
|
/// Converts a VkResult enum into a rodata string
|
||||||
const char* ToString(VkResult) noexcept;
|
const char* ToString(VkResult) noexcept;
|
||||||
|
|
||||||
|
/// Throws a Vulkan exception if result is not success.
|
||||||
|
inline void Check(VkResult result) {
|
||||||
|
if (result != VK_SUCCESS) {
|
||||||
|
throw Exception(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Throws a Vulkan exception if result is an error.
|
||||||
|
/// @return result
|
||||||
|
inline VkResult Filter(VkResult result) {
|
||||||
|
if (result < 0) {
|
||||||
|
throw Exception(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Vulkan::vk
|
} // namespace Vulkan::vk
|
||||||
|
|
Loading…
Reference in a new issue