2019-02-20 20:21:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "volk/volk.h"
|
|
|
|
#include "vk_mem_alloc/vk_mem_alloc.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
class VulkanSwapChain;
|
2019-02-26 10:44:29 +00:00
|
|
|
class VulkanSemaphore;
|
|
|
|
class VulkanFence;
|
2019-02-20 20:21:57 +00:00
|
|
|
|
|
|
|
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<VulkanSwapChain> swapChain;
|
|
|
|
uint32_t presentImageIndex = 0;
|
|
|
|
|
|
|
|
VkQueue graphicsQueue = nullptr;
|
|
|
|
|
2019-02-26 10:44:29 +00:00
|
|
|
std::unique_ptr<VulkanSemaphore> imageAvailableSemaphore;
|
|
|
|
std::unique_ptr<VulkanSemaphore> renderFinishedSemaphore;
|
|
|
|
std::unique_ptr<VulkanFence> renderFinishedFence;
|
2019-02-20 20:21:57 +00:00
|
|
|
|
|
|
|
VmaAllocator allocator = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
std::vector<VkLayerProperties> availableLayers;
|
|
|
|
std::vector<VkExtensionProperties> extensions;
|
|
|
|
std::vector<VkExtensionProperties> availableDeviceExtensions;
|
|
|
|
|
|
|
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createInstance();
|
|
|
|
void createSurface();
|
|
|
|
void selectPhysicalDevice();
|
|
|
|
void createDevice();
|
|
|
|
void createAllocator();
|
|
|
|
void createSemaphores();
|
|
|
|
void releaseResources();
|
|
|
|
|
2019-02-26 10:27:29 +00:00
|
|
|
VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;
|
2019-02-20 20:21:57 +00:00
|
|
|
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData);
|
|
|
|
|
|
|
|
std::vector<const char *> 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;
|
|
|
|
};
|