VulkanUtils.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef CORE_VULKAN_UTILS_H
  2. #define CORE_VULKAN_UTILS_H
  3. #define GLFW_INCLUDE_VULKAN
  4. #include <GLFW/glfw3.h>
  5. #include <core/Utility.h>
  6. const char* getVulkanErrorString(VkResult r);
  7. #define VK_ASSERT(a) \
  8. do { \
  9. VkResult vkResult = (a); \
  10. if(vkResult != VK_SUCCESS) { \
  11. LOG_ERROR("Vulkan error: %s\n", getVulkanErrorString(vkResult)); \
  12. return true; \
  13. } \
  14. } while(false)
  15. bool initVulkanInstance();
  16. void destroyVulkanInstance();
  17. bool initVulkanDebugging();
  18. void destroyVulkanDebugging();
  19. #define INVALID_VULKAN_QUEUE_FAMILY ((u32) - 1)
  20. u32 findVulkanQueueFamily(VkPhysicalDevice pd, VkQueueFlags flags);
  21. u32 findVulkanSurfaceQueueFamily(VkPhysicalDevice pd, VkSurfaceKHR s);
  22. typedef int (*VulkanSurfaceFormatSelector)(const VkSurfaceFormatKHR* sf);
  23. bool findVulkanSurfaceFormat(
  24. VkSurfaceFormatKHR* sf, VkPhysicalDevice pd, VkSurfaceKHR s,
  25. VulkanSurfaceFormatSelector sfs);
  26. typedef int (*VulkanSurfacePresentModeSelector)(VkPresentModeKHR m);
  27. bool findVulkanSurfacePresentMode(
  28. VkPresentModeKHR* m, VkPhysicalDevice pd, VkSurfaceKHR s,
  29. VulkanSurfacePresentModeSelector spms);
  30. typedef int (*VulkanPhysicalDeviceSelector)(VkPhysicalDevice pd);
  31. bool findVulkanPhysicalDevice(
  32. VkPhysicalDevice* pd, VulkanPhysicalDeviceSelector s);
  33. bool hasVulkanExtension(VkPhysicalDevice pd, const char* extension);
  34. typedef struct {
  35. u32 queueFamilyIndex;
  36. float priority;
  37. } VulkanDeviceQueueData;
  38. bool initVulkanDevice(
  39. VkDevice* d, VkPhysicalDevice pd, const VulkanDeviceQueueData* data,
  40. size_t nData, const char** extensions, size_t nExtensions);
  41. void destroyVulkanDevice(VkDevice d);
  42. bool initVulkanSurface(VkSurfaceKHR* s, GLFWwindow* w);
  43. void destroyVulkanSurface(VkSurfaceKHR s);
  44. typedef struct {
  45. VkPhysicalDevice physicalDevice;
  46. VkDevice device;
  47. VkSurfaceKHR surface;
  48. VkExtent2D size;
  49. VkSurfaceFormatKHR surfaceFormat;
  50. VkPresentModeKHR presentMode;
  51. VkSharingMode sharingMode;
  52. u32 queueFamilyIndexCount;
  53. u32* queueFamilyIndices;
  54. } VulkanSwapchainData;
  55. bool initVulkanSwapchain(VkSwapchainKHR* sc, VulkanSwapchainData* d);
  56. void destroyVulkanSwapchain(VkSwapchainKHR s, VkDevice d);
  57. typedef struct {
  58. u32 amount;
  59. VkImage* images;
  60. VkImageView* imageViews;
  61. } VulkanSwapchainImages;
  62. bool initVulkanSwapchainImages(
  63. VulkanSwapchainImages* si, VkDevice d, VkSwapchainKHR sc, VkFormat format);
  64. void destroyVulkanSwapchainImages(VulkanSwapchainImages* si, VkDevice d);
  65. bool initVulkanShaderModule(VkShaderModule* sm, VkDevice d, const char* path);
  66. void destroyVulkanShaderModule(VkShaderModule sm, VkDevice d);
  67. bool initVulkanPipelineLayout(VkPipelineLayout* pl, VkDevice d);
  68. void destroyVulkanPipelineLayout(VkPipelineLayout pl, VkDevice d);
  69. bool initVulkanFramebuffers(
  70. VkFramebuffer** f, VulkanSwapchainImages* si, VkDevice d, VkRenderPass rp,
  71. u32 width, u32 height);
  72. void destroyVulkanFramebuffers(VkFramebuffer** f, u32 amount, VkDevice d);
  73. bool initCommandVulkanBuffer(VkCommandBuffer* cb, VkDevice d, VkCommandPool cp);
  74. bool initVulkanSemaphore(VkSemaphore* s, VkDevice d);
  75. void destroyVulkanSemaphore(VkSemaphore s, VkDevice d);
  76. bool initVulkanFence(VkFence* f, VkDevice d);
  77. void destroyVulkanFence(VkFence f, VkDevice d);
  78. #endif