#pragma once #include "volk/volk.h" #include "vk_mem_alloc/vk_mem_alloc.h" #include #include #include class VulkanSwapChain; class VulkanDevice { public: VulkanDevice(); ~VulkanDevice(); void windowResized(); void waitPresent(); void beginFrame(); void presentFrame(); VkDevice device = nullptr; int graphicsFamily = -1; int computeFamily = -1; int transferFamily = -1; int sparseBindingFamily = -1; int presentFamily = -1; std::unique_ptr swapChain; uint32_t presentImageIndex = 0; VkQueue graphicsQueue = nullptr; VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE; VkSemaphore renderFinishedSemaphore = VK_NULL_HANDLE; VkFence renderFinishedFence = VK_NULL_HANDLE; VmaAllocator allocator = VK_NULL_HANDLE; std::vector availableLayers; std::vector extensions; std::vector availableDeviceExtensions; uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties); private: void createInstance(); void createSurface(); void selectPhysicalDevice(); void createDevice(); void createAllocator(); void createSemaphores(); void releaseResources(); VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE; static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData); std::vector requiredExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; VkInstance instance = nullptr; VkSurfaceKHR surface = 0; VkPhysicalDevice physicalDevice = {}; VkQueue presentQueue = nullptr; VulkanDevice(const VulkanDevice &) = delete; VulkanDevice &operator=(const VulkanDevice &) = delete; friend class VulkanSwapChain; };