#ifndef CORE_VULKAN_UTILS_H #define CORE_VULKAN_UTILS_H #define GLFW_INCLUDE_VULKAN #include #include const char* getVulkanErrorString(VkResult r); #define VK_ASSERT(a) \ do { \ VkResult vkResult = (a); \ if(vkResult != VK_SUCCESS) { \ LOG_ERROR("Vulkan error: %s\n", getVulkanErrorString(vkResult)); \ return true; \ } \ } while(false) bool initVulkanInstance(); void destroyVulkanInstance(); bool initVulkanDebugging(); void destroyVulkanDebugging(); #define INVALID_VULKAN_QUEUE_FAMILY ((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); typedef struct { u32 queueFamilyIndex; float priority; } VulkanDeviceQueueData; 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); typedef struct { VkPhysicalDevice physicalDevice; VkDevice device; VkSurfaceKHR surface; VkExtent2D size; VkSurfaceFormatKHR surfaceFormat; VkPresentModeKHR presentMode; VkSharingMode sharingMode; u32 queueFamilyIndexCount; u32* queueFamilyIndices; } VulkanSwapchainData; bool initVulkanSwapchain(VkSwapchainKHR* sc, VulkanSwapchainData* d); void destroyVulkanSwapchain(VkSwapchainKHR s, VkDevice d); typedef struct { u32 amount; VkImage* images; VkImageView* imageViews; } VulkanSwapchainImages; 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