43 virtual void Init()
override;
44 virtual void SwapBuffers()
override;
47 void CreateInstance();
49 void PrintAvailableExtensions();
50 void PrintAvailablePhysicalDevices(
const std::vector<VkPhysicalDevice>& physicalDevices);
53 bool CheckValidationLayerSupport();
54 std::vector<const char*> GetRequiredExtensions(VkInstanceCreateFlags& flagsToBeSet);
56 static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
57 VkDebugUtilsMessageTypeFlagsEXT messageType,
58 const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
61 void SetupDebugMessenger();
62 void PopulateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
63 VkResult CreateDebugUtilsMessengerEXT(VkInstance instance,
64 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
65 const VkAllocationCallbacks* pAllocator,
66 VkDebugUtilsMessengerEXT* pDebugMessenger);
68 void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger,
const VkAllocationCallbacks* pAllocator);
74 void PickPhysicalDevice();
75 bool IsDeviceSuitable(VkPhysicalDevice device);
79 void CreateLogicalDevice();
82 void CreateSwapChain();
83 bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
85 VkSurfaceFormatKHR ChooseSwapSurfaceFormat(
const std::vector<VkSurfaceFormatKHR>& availableFormats);
86 VkPresentModeKHR ChooseSwapPresentMode(
const std::vector<VkPresentModeKHR>& availablePresentModes);
87 VkExtent2D ChooseSwapExtent(
const VkSurfaceCapabilitiesKHR& capabilities);
88 uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
91 void CreateImageViews();
94 void CreateRenderPass();
97 void CreateFrameBuffers();
100 void CreateCommandPool();
103 void CreateDepthResources();
104 VkFormat FindSupportedFormat(
const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
105 VkFormat FindDepthFormat();
106 bool HasStencilComponent(VkFormat format);
110 void TransitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout);
111 void CopyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);
115 void RecreateSwapChain();
116 void CleanupSwapChain();
118 void SetVSync(
bool bEnable);
120 void Initializeglslang();
121 void RegisterUBO(
const std::shared_ptr<VulkanUniformBuffer>& ubo);
124 void UploadUBO(
size_t frameIndex);
127 VkDevice GetLogicalDevice()
const {
return m_device; }
128 VkPhysicalDevice GetPhysicalDevice()
const {
return m_physicalDevice; }
129 VkExtent2D GetSwapChainExtent()
const {
return m_swapChainExtent; }
130 VkRenderPass GetRenderPass()
const {
return m_renderPass; }
131 const std::vector<VkFramebuffer>& GetSwapChainFrameBuffer()
const {
return m_swapChainFrameBuffers; }
132 VkSwapchainKHR GetSwapChain()
const {
return m_swapChain; }
133 inline const std::vector<VkImage>& GetSwapChainImages()
const {
return m_swapChainImages; }
134 VkFormat GetSwapChainImageFormat()
const {
return m_swapChainImageFormat; }
135 const std::vector<VkImageView>& GetSwapChainImageViews()
const {
return m_swapChainImageViews; }
136 VkSurfaceFormatKHR GetSurfaceFormat()
const {
return m_surfaceFormat; }
137 VkQueue GetGraphicsQueue()
const {
return m_graphicsQueue; }
138 VkQueue GetPresentQueue()
const {
return m_presentQueue; }
139 VkCommandPool GetCommandPool()
const {
return m_commandPool; }
142 const VkPhysicalDeviceFeatures& GetSupportedDeviceFeatures()
const {
return m_SupportedDeviceFeatures; }
143 VkInstance GetInstance()
const {
return m_Instance; }
144 uint32_t GetImageCount()
const {
return uint32_t(m_swapChainImages.size()); }
145 uint32_t GetMinImageCount()
const {
return m_MinImageCount; }
146 VkSurfaceKHR GetSurface()
const {
return m_surface; }
147 VkPresentModeKHR GetPresentMode()
const {
return m_presentMode; }
152 GLFWwindow* m_windowHandle;
155 VkInstance m_Instance;
156 VkDebugUtilsMessengerEXT debugMessenger;
158 VkPhysicalDeviceFeatures m_SupportedDeviceFeatures;
160 static bool bEnableValidationLayers;
162 VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
164 VkQueue m_graphicsQueue;
166 VkSurfaceKHR m_surface;
167 VkQueue m_presentQueue;
168 VkPresentModeKHR m_presentMode;
170 VkSurfaceFormatKHR m_surfaceFormat;
172 VkSwapchainKHR m_swapChain;
173 std::vector<VkImage> m_swapChainImages;
174 VkFormat m_swapChainImageFormat;
175 VkExtent2D m_swapChainExtent;
176 std::vector<VkImageView> m_swapChainImageViews;
178 VkRenderPass m_renderPass;
180 std::vector<VkFramebuffer> m_swapChainFrameBuffers;
181 VkCommandPool m_commandPool;
183 std::set<std::shared_ptr<VulkanUniformBuffer>> m_VulkanUBO;
187 VkImage m_DepthImage;
188 VkDeviceMemory m_DepthImageMemory;
189 VkImageView m_DepthImageView;
191 uint32_t m_MinImageCount = 0;