You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
#pragma once
|
|
|
|
#include <vulkan/vulkan.h>
|
|
#include <GLFW/glfw3.h>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <vector>
|
|
#include "vk_mem_alloc.h"
|
|
|
|
using std::optional, std::vector;
|
|
|
|
class CommandPool;
|
|
|
|
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<uint32_t> graphicsAndPresent;
|
|
vector<uint32_t> computeAndTransfer;
|
|
std::set<uint32_t> uniqueQueueFamilies(){
|
|
std::set<uint32_t> 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();
|
|
private:
|
|
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
|
VkDevice device = VK_NULL_HANDLE;
|
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
|
VmaAllocator allocator = 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);
|
|
|
|
}; |