#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(){ std::set unique; unique.insert(graphicsAndPresent.begin(), graphicsAndPresent.end()); unique.insert(computeAndTransfer.begin(), computeAndTransfer.end()); return unique; } uint32_t tryComputeAndTransferDedicated(){ for (uint32_t family : computeAndTransfer){ if (std::find(graphicsAndPresent.begin(), graphicsAndPresent.end(), family) == graphicsAndPresent.end()){ return family; } } return computeAndTransfer[0]; } bool isEnough(){ return !graphicsAndPresent.empty() && !computeAndTransfer.empty(); } }; 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); };