Changeset 8b823e7 in opengl-game for vulkan-utils.hpp


Ignore:
Timestamp:
Jan 24, 2021, 11:38:43 PM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
d8cf709
Parents:
ce9dc9f
Message:

Create an error-checking macro to check Vulkan function results, which will print a custom message, the error code, and the line number for all results besides VK_SUCCESS, and update the imgui error-checking callback with similar functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-utils.hpp

    rce9dc9f r8b823e7  
    33
    44#include <optional>
     5#include <sstream>
     6#include <stdexcept>
    57#include <string>
    68#include <vector>
     
    3234class VulkanUtils {
    3335   public:
     36      static string resultString(VkResult result);
     37
    3438      static bool checkValidationLayerSupport(const vector<const char*> &validationLayers);
    3539
     
    136140}
    137141
     142#define VKUTIL_CHECK_RESULT(f, msg) {                                                                                      \
     143   VkResult res = (f);                                                                                                     \
     144                                                                                                                           \
     145   if (res != VK_SUCCESS) {                                                                                                \
     146      ostringstream oss;                                                                                                   \
     147      oss << msg << " VkResult is \"" << VulkanUtils::resultString(res) << "\" in " << __FILE__ << " at line " << __LINE__;\
     148                                                                                                                           \
     149      if (res < 0) {                                                                                                       \
     150         throw runtime_error("Fatal: " + oss.str());                                                                       \
     151      } else {                                                                                                             \
     152         cerr << oss.str();                                                                                                \
     153      }                                                                                                                    \
     154   }                                                                                                                       \
     155}
     156
    138157#endif // _VULKAN_UTILS_H
Note: See TracChangeset for help on using the changeset viewer.