123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #ifndef GAMINGCORE_VULKAN_UTILS_HPP
- #define GAMINGCORE_VULKAN_UTILS_HPP
- #define GLFW_INCLUDE_VULKAN
- #include <core/Types.hpp>
- #include <core/Utility.hpp>
- #include <GLFW/glfw3.h>
- const char* getVulkanResultString(VkResult r);
- #define VK_ASSERT(a) \
- do { \
- VkResult vkResult = (a); \
- if(vkResult != VK_SUCCESS) { \
- LOG_ERROR("Vulkan error: %s\n", getVulkanResultString(vkResult)); \
- return true; \
- } \
- } while(false)
- bool initVulkanInstance();
- void destroyVulkanInstance();
- bool initVulkanDebugging();
- void destroyVulkanDebugging();
- #define INVALID_VULKAN_QUEUE_FAMILY (static_cast<u32>(-1))
- u32 findVulkanQueueFamily(VkPhysicalDevice pd, VkQueueFlags flags);
- u32 findVulkanSurfaceQueueFamily(VkPhysicalDevice pd, VkSurfaceKHR s);
- typedef int (*VulkanSurfaceFormatSelector)(const VkSurfaceFormatKHR* sf);
- bool findVulkanSurfaceFormat(
- VkSurfaceFormatKHR* sf, VkPhysicalDevice pd, VkSurfaceKHR s,
- VulkanSurfaceFormatSelector sfs);
- typedef int (*VulkanSurfacePresentModeSelector)(VkPresentModeKHR m);
- bool findVulkanSurfacePresentMode(
- VkPresentModeKHR* m, VkPhysicalDevice pd, VkSurfaceKHR s,
- VulkanSurfacePresentModeSelector spms);
- typedef int (*VulkanPhysicalDeviceSelector)(VkPhysicalDevice pd);
- bool findVulkanPhysicalDevice(
- VkPhysicalDevice* pd, VulkanPhysicalDeviceSelector s);
- bool hasVulkanExtension(VkPhysicalDevice pd, const char* extension);
- struct VulkanDeviceQueueData {
- u32 queueFamilyIndex = 0;
- float priority = 0.0f;
- };
- bool initVulkanDevice(
- VkDevice* d, VkPhysicalDevice pd, const VulkanDeviceQueueData* data,
- size_t nData, const char** extensions, size_t nExtensions);
- void destroyVulkanDevice(VkDevice d);
- bool initVulkanSurface(VkSurfaceKHR* s, GLFWwindow* w);
- void destroyVulkanSurface(VkSurfaceKHR s);
- struct VulkanSwapchainData {
- VkPhysicalDevice physicalDevice{};
- VkDevice device{};
- VkSurfaceKHR surface{};
- VkExtent2D size{};
- VkSurfaceFormatKHR surfaceFormat{};
- VkPresentModeKHR presentMode{};
- VkSharingMode sharingMode{};
- u32 queueFamilyIndexCount = 0;
- u32* queueFamilyIndices = nullptr;
- };
- bool initVulkanSwapchain(VkSwapchainKHR* sc, VulkanSwapchainData* d);
- void destroyVulkanSwapchain(VkSwapchainKHR s, VkDevice d);
- struct VulkanSwapchainImages {
- u32 amount;
- VkImage* images;
- VkImageView* imageViews;
- };
- bool initVulkanSwapchainImages(
- VulkanSwapchainImages* si, VkDevice d, VkSwapchainKHR sc, VkFormat format);
- void destroyVulkanSwapchainImages(VulkanSwapchainImages* si, VkDevice d);
- bool initVulkanShaderModule(VkShaderModule* sm, VkDevice d, const char* path);
- void destroyVulkanShaderModule(VkShaderModule sm, VkDevice d);
- bool initVulkanPipelineLayout(VkPipelineLayout* pl, VkDevice d);
- void destroyVulkanPipelineLayout(VkPipelineLayout pl, VkDevice d);
- bool initVulkanFramebuffers(
- VkFramebuffer** f, VulkanSwapchainImages* si, VkDevice d, VkRenderPass rp,
- u32 width, u32 height);
- void destroyVulkanFramebuffers(VkFramebuffer** f, u32 amount, VkDevice d);
- bool initCommandVulkanBuffer(VkCommandBuffer* cb, VkDevice d, VkCommandPool cp);
- bool initVulkanSemaphore(VkSemaphore* s, VkDevice d);
- void destroyVulkanSemaphore(VkSemaphore s, VkDevice d);
- bool initVulkanFence(VkFence* f, VkDevice d);
- void destroyVulkanFence(VkFence f, VkDevice d);
- #endif
|