#pragma once #include #include #include #include #include #include #include "vk_mem_alloc.h" #include "imgui.h" #include "imgui/backends/imgui_impl_vulkan.h" #include "imgui/backends/imgui_impl_glfw.h" using std::optional, std::vector; class CommandPool; class Swapchain; void printVmaStats(); class Instance { public: explicit Instance(); ~Instance(); GLFWwindow *window = nullptr; VkQueue graphicsAndPresentQueue = VK_NULL_HANDLE; VkQueue computeAndTransferQueue = VK_NULL_HANDLE; bool windowResized = false; CommandPool *renderingCommandPool = nullptr; CommandPool *computeCommandPool = nullptr; struct QueueFamilyIndices { vector graphicsAndPresent; vector computeAndTransfer; std::set uniqueQueueFamilies(); uint32_t tryComputeAndTransferDedicated(); bool isEnough(); }; QueueFamilyIndices indices {}; static Instance *instance; static VkDevice GetDevice(); static VkPhysicalDevice GetPhysicalDevice(); static VmaAllocator GetAllocator(); static VkSurfaceKHR GetSurface(); void initImGui(const Swapchain &swapchain); private: VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkDevice device = VK_NULL_HANDLE; VkSurfaceKHR surface = VK_NULL_HANDLE; VmaAllocator allocator = VK_NULL_HANDLE; VkDescriptorPool imGuiDescriptorPool = 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); static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface); };