#pragma once #include #include #include #include #include "vk_mem_alloc.h" class CommandPool; class Instance { public: explicit Instance(); ~Instance(); GLFWwindow *window = nullptr; VkQueue graphicsQueue = VK_NULL_HANDLE; VkQueue presentQueue = VK_NULL_HANDLE; VkQueue computeQueue = VK_NULL_HANDLE; bool windowResized = false; CommandPool* commandPool = nullptr; struct QueueFamilyIndices { std::optional graphicsFamily; std::optional computeFamily; std::optional presentFamily; std::optional graphicsAndComputeFamily; bool isComplete() const { return graphicsFamily.has_value() && computeFamily.has_value() && presentFamily.has_value() && graphicsAndComputeFamily.has_value(); } std::set uniqueQueueFamilies(){ return { graphicsFamily.value(), presentFamily.value(), computeFamily.value(), graphicsAndComputeFamily.value() }; } }; static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface); static Instance* instance; static VkDevice GetDevice(); static VkPhysicalDevice GetPhysicalDevice(); static VmaAllocator GetAllocator(); static VkSurfaceKHR GetSurface(); private: VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkDevice device = VK_NULL_HANDLE; VkSurfaceKHR surface = VK_NULL_HANDLE; VmaAllocator allocator = VK_NULL_HANDLE; VkInstance handle = VK_NULL_HANDLE; void initWindow(); void createInstance(); void createSurface(); void pickPhysicalDevice(); void createLogicalDevice(); void createAllocator(); bool isDeviceSuitable(VkPhysicalDevice potentialPhysicalDevice); static bool checkDeviceExtensionSupport(VkPhysicalDevice device); };