diff options
| -rw-r--r-- | src/video_core/renderer_vulkan/wrapper.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/wrapper.h | 30 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/wrapper.cpp b/src/video_core/renderer_vulkan/wrapper.cpp index b4afafbd5..1adf1b8c2 100644 --- a/src/video_core/renderer_vulkan/wrapper.cpp +++ b/src/video_core/renderer_vulkan/wrapper.cpp | |||
| @@ -14,6 +14,10 @@ | |||
| 14 | 14 | ||
| 15 | namespace Vulkan::vk { | 15 | namespace Vulkan::vk { |
| 16 | 16 | ||
| 17 | const char* Exception::what() const noexcept { | ||
| 18 | return ToString(result); | ||
| 19 | } | ||
| 20 | |||
| 17 | const char* ToString(VkResult result) noexcept { | 21 | const char* ToString(VkResult result) noexcept { |
| 18 | switch (result) { | 22 | switch (result) { |
| 19 | case VkResult::VK_SUCCESS: | 23 | case VkResult::VK_SUCCESS: |
diff --git a/src/video_core/renderer_vulkan/wrapper.h b/src/video_core/renderer_vulkan/wrapper.h index 8ecc1b5a3..b13d3882e 100644 --- a/src/video_core/renderer_vulkan/wrapper.h +++ b/src/video_core/renderer_vulkan/wrapper.h | |||
| @@ -80,7 +80,37 @@ private: | |||
| 80 | std::size_t num = 0; | 80 | std::size_t num = 0; |
| 81 | }; | 81 | }; |
| 82 | 82 | ||
| 83 | /// Vulkan exception generated from a VkResult. | ||
| 84 | class Exception final : public std::exception { | ||
| 85 | public: | ||
| 86 | /// Construct the exception with a result. | ||
| 87 | /// @pre result != VK_SUCCESS | ||
| 88 | explicit Exception(VkResult result_) : result{result_} {} | ||
| 89 | virtual ~Exception() = default; | ||
| 90 | |||
| 91 | const char* what() const noexcept override; | ||
| 92 | |||
| 93 | private: | ||
| 94 | VkResult result; | ||
| 95 | }; | ||
| 96 | |||
| 83 | /// Converts a VkResult enum into a rodata string | 97 | /// Converts a VkResult enum into a rodata string |
| 84 | const char* ToString(VkResult) noexcept; | 98 | const char* ToString(VkResult) noexcept; |
| 85 | 99 | ||
| 100 | /// Throws a Vulkan exception if result is not success. | ||
| 101 | inline void Check(VkResult result) { | ||
| 102 | if (result != VK_SUCCESS) { | ||
| 103 | throw Exception(result); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | /// Throws a Vulkan exception if result is an error. | ||
| 108 | /// @return result | ||
| 109 | inline VkResult Filter(VkResult result) { | ||
| 110 | if (result < 0) { | ||
| 111 | throw Exception(result); | ||
| 112 | } | ||
| 113 | return result; | ||
| 114 | } | ||
| 115 | |||
| 86 | } // namespace Vulkan::vk | 116 | } // namespace Vulkan::vk |