Add Buffer abstractions

This commit is contained in:
Thraix
2023-01-14 18:15:33 +01:00
parent fa207c591c
commit be8bcb0aaf
20 changed files with 1221 additions and 757 deletions
+26 -4
View File
@@ -4,10 +4,21 @@
#include <vulkan/vulkan.hpp>
#include <iostream>
#define ASSERT(Function, message) if(!(Function)) { throw std::runtime_error(message); } while(false)
#define VK_ASSERT(Function, message) if(Function != VK_SUCCESS) { throw VulkanException(message); } while(false)
#define CP_DEBUG(format, ...) std::cout << "[DBG] " << StringFormat(format, __VA_ARGS__) << std::endl
#define CP_INFO(format, ...) std::cout << "[INF] " << StringFormat(format, __VA_ARGS__) << std::endl
#define CP_WARN(format, ...) std::cout << "[WRN] " << StringFormat(format, __VA_ARGS__) << std::endl
#define CP_ERR(format, ...) std::cout << "[ERR] " << StringFormat(format, __VA_ARGS__) << std::endl
VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance,
#define CP_UNIMPLEMENTED() CP_WARN("%s is unimplemented", __FUNCTION__)
#define CP_ASSERT(Function, format, ...) if(!(Function)) { throw std::runtime_error(StringFormat(format, __VA_ARGS__)); } while(false)
#define CP_VK_ASSERT(Function, format, ...) if(Function != VK_SUCCESS) { throw VulkanException(StringFormat(format, __VA_ARGS__)); } while(false)
#define CP_DELETE_COPY_AND_MOVE_CTOR(ClassName) \
ClassName(ClassName&&) = delete; \
ClassName(const ClassName&) = delete; \
ClassName& operator=(ClassName&&) = delete; \
ClassName& operator=(const ClassName&) = delete
static VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance,
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkDebugUtilsMessengerEXT* pDebugMessenger)
@@ -18,7 +29,7 @@ VkResult vkCreateDebugUtilsMessengerEXT(VkInstance instance,
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
void vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
static void vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
VkDebugUtilsMessengerEXT debugMessenger,
const VkAllocationCallbacks* pAllocator) {
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
@@ -26,3 +37,14 @@ void vkDestroyDebugUtilsMessengerEXT(VkInstance instance,
func(instance, debugMessenger, pAllocator);
}
}
template<typename ... Args>
std::string StringFormat(const std::string& format, Args... args)
{
int size = std::snprintf(nullptr, 0, format.c_str(), args...) + 1;
CP_ASSERT(size > 0, "Error during formatting");
std::unique_ptr<char[]> buf(new char[size]);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
}