Major refactoring to fix spaghetti code, hook sanitizers in when debug building, and set up window surfaces.

This commit is contained in:
Lillian Salehi 2024-10-06 04:35:53 -05:00
parent 9a6a351e23
commit 3e0206b581
8 changed files with 185 additions and 147 deletions

View File

@ -1,6 +1,6 @@
CPPFLAGS=-g CPPFLAGS=-g
LDFLAGS=-lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi LDFLAGS=-lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
DEBUGFLAGS=-DDEBUG DEBUGFLAGS=-DDEBUG -fsanitize=address
SRC=$(shell find . -name *.cpp) SRC=$(shell find . -name *.cpp)
OBJ=$(SRC:%.cpp=%.o) OBJ=$(SRC:%.cpp=%.o)

View File

@ -1,127 +1,155 @@
#include "DeviceLibrary.h" #include "DeviceLibrary.h"
#include "debug/VulkanDebugLibs.h"
#include "global.h"
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
#include <set>
#include <stdexcept> #include <stdexcept>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
using namespace AgnosiaEngine;
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; namespace DeviceControl {
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
VulkanDebugLibs debug;
VkQueue graphicsQueue;
#ifdef DEBUG
const bool enableValidationLayers = true;
#else
const bool enableValidationLayers = false;
#endif
struct QueueFamilyIndices { VkSurfaceKHR surface;
std::optional<uint32_t> graphicsFamily; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
VkPhysicalDeviceProperties deviceProperties;
VkPhysicalDeviceFeatures deviceFeatures;
bool isComplete() { VkQueue graphicsQueue;
return graphicsFamily.has_value(); VkQueue presentQueue;
}
};
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {
// First we feed in a integer we want to use to hold the number of queued items, that fills it, then we create that amount of default constructed *VkQueueFamilyProperties* structs.
// These store the flags, the amount of queued items in the family, and timestamp data. Queue families are simply group collections of tasks we want to get done.
// Next, we check the flags of the queueFamily item, use a bitwise and to see if they match, i.e. support graphical operations, then return that to notify that we have at least one family that supports VK_QUEUE_GRAPHICS_BIT.
// Which means this device supports graphical operations!
QueueFamilyIndices indices;
uint32_t queueFamilyCount; struct QueueFamilyIndices {
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr); // We need to check that the Queue families support graphics operations and window presentation, sometimes they can support one or the other,
// therefore, we take into account both for completion.
std::optional<uint32_t> graphicsFamily;
std::optional<uint32_t> presentFamily;
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount); bool isComplete() {
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data()); return graphicsFamily.has_value() && presentFamily.has_value();
int i = 0;
for(const auto& queueFamily : queueFamilies) {
if(queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
indices.graphicsFamily = i;
} }
if(indices.isComplete()) { };
break;
}
i++;
}
return indices;
}
bool isDeviceSuitable(VkPhysicalDevice device) { QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {
// These two are simple, create a structure to hold the apiVersion, driverVersion, vendorID, deviceID and type, name, and a few other settings. // First we feed in a integer we want to use to hold the number of queued items, that fills it, then we create that amount of default constructed *VkQueueFamilyProperties* structs.
// Then populate it by passing in the device and the structure reference. // These store the flags, the amount of queued items in the family, and timestamp data. Queue families are simply group collections of tasks we want to get done.
vkGetPhysicalDeviceProperties(device, &deviceProperties); // Next, we check the flags of the queueFamily item, use a bitwise and to see if they match, i.e. support graphical operations, then return that to notify that we have at least one family that supports VK_QUEUE_GRAPHICS_BIT.
// Similarly, we can pass in the device and a deviceFeatures struct, this is quite special, it holds a struct of optional features the GPU can perform. // Which means this device supports graphical operations!
// Some, like a geometry shader, and stereoscopic rendering (multiViewport) we want, so we dont return true without them. // We also do the same thing for window presentation, just check to see if its supported.
vkGetPhysicalDeviceFeatures(device, &deviceFeatures); QueueFamilyIndices indices;
// We need to find a device that supports graphical operations, or else we cant do much with it! This function just runs over all the queueFamilies and sees if there
// is a queue family with the VK_QUEUE_GRAPHICS_BIT flipped!
QueueFamilyIndices indices = findQueueFamilies(device);
uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
return deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && deviceFeatures.multiViewport && deviceFeatures.geometryShader && indices.isComplete(); std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
} vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());
void DeviceLibrary::pickPhysicalDevice(VkInstance& instance) { int i = 0;
uint32_t deviceCount = 0; for(const auto& queueFamily : queueFamilies) {
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr); if(queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
indices.graphicsFamily = i;
}
if(deviceCount == 0) { VkBool32 presentSupport = false;
throw std::runtime_error("Failed to find GPU's with Vulkan Support!!"); vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
if(presentSupport) {
indices.presentFamily = i;
}
if(indices.isComplete()) {
break;
}
i++;
}
return indices;
} }
std::vector<VkPhysicalDevice> devices(deviceCount); // Direct Initialization is weird af, yo
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
for(const auto& device : devices) { bool isDeviceSuitable(VkPhysicalDevice device) {
if(isDeviceSuitable(device)) { // These two are simple, create a structure to hold the apiVersion, driverVersion, vendorID, deviceID and type, name, and a few other settings.
std::cout << "Using device: " << deviceProperties.deviceName << std::endl; // Then populate it by passing in the device and the structure reference.
//Once we have buttons or such, maybe ask the user or write a config file for which GPU to use? vkGetPhysicalDeviceProperties(device, &deviceProperties);
physicalDevice = device; // Similarly, we can pass in the device and a deviceFeatures struct, this is quite special, it holds a struct of optional features the GPU can perform.
break; // Some, like a geometry shader, and stereoscopic rendering (multiViewport) we want, so we dont return true without them.
vkGetPhysicalDeviceFeatures(device, &deviceFeatures);
// We need to find a device that supports graphical operations, or else we cant do much with it! This function just runs over all the queueFamilies and sees if there
// is a queue family with the VK_QUEUE_GRAPHICS_BIT flipped!
QueueFamilyIndices indices = findQueueFamilies(device);
return deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && deviceFeatures.multiViewport && deviceFeatures.geometryShader && indices.isComplete();
}
void DeviceLibrary::pickPhysicalDevice(VkInstance& instance) {
uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if(deviceCount == 0) {
throw std::runtime_error("Failed to find GPU's with Vulkan Support!!");
}
std::vector<VkPhysicalDevice> devices(deviceCount); // Direct Initialization is weird af, yo
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
for(const auto& device : devices) {
if(isDeviceSuitable(device)) {
std::cout << "Using device: " << deviceProperties.deviceName << std::endl;
//Once we have buttons or such, maybe ask the user or write a config file for which GPU to use?
physicalDevice = device;
break;
}
}
if(physicalDevice == VK_NULL_HANDLE) {
throw std::runtime_error("Failed to find a suitable GPU!");
} }
} }
void DeviceLibrary::destroySurface(VkInstance& instance) {
if(physicalDevice == VK_NULL_HANDLE) { vkDestroySurfaceKHR(instance, surface, nullptr);
throw std::runtime_error("Failed to find a suitable GPU!"); std::cout << "Destroyed surface safely\n" << std::endl;
}
void DeviceLibrary::createSurface(VkInstance& instance, GLFWwindow* window) {
if(glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
throw std::runtime_error("Failed to create window surface!!");
}
std::cout << "GLFW Window Surface created successfully\n" << std::endl;
}
void DeviceLibrary::createLogicalDevice(VkDevice& device) {
// Describe how many queues we want for a single family (1) here, right now we are solely interested in graphics capabilites,
// but Compute Shaders, transfer ops, decode and encode operations can also queued with setup! We also assign each queue a priority.
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;
std::set<uint32_t> uniqueQueueFamilies = {
indices.graphicsFamily.value(),
indices.presentFamily.value()
};
float queuePriority = 1.0f;
for(uint32_t queueFamily : uniqueQueueFamilies) {
VkDeviceQueueCreateInfo queueCreateSingularInfo = {};
queueCreateSingularInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateSingularInfo.queueFamilyIndex = queueFamily;
queueCreateSingularInfo.queueCount = 1;
queueCreateSingularInfo.pQueuePriorities = &queuePriority;
queueCreateInfos.push_back(queueCreateSingularInfo);
}
VkDeviceCreateInfo createDeviceInfo = {};
VkPhysicalDeviceFeatures emptyFeatures = {};
createDeviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createDeviceInfo.pQueueCreateInfos = queueCreateInfos.data();
createDeviceInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());
createDeviceInfo.pEnabledFeatures = &emptyFeatures;
createDeviceInfo.enabledExtensionCount = 0;
if(Global::enableValidationLayers) {
createDeviceInfo.enabledLayerCount = static_cast<uint32_t>(Global::validationLayers.size());
createDeviceInfo.ppEnabledLayerNames = Global::validationLayers.data();
} else {
createDeviceInfo.enabledLayerCount = 0;
}
if(vkCreateDevice(physicalDevice, &createDeviceInfo, nullptr, &device) != VK_SUCCESS) {
throw std::runtime_error("Failed to create logical device");
}
std::cout << "Created Logical device successfully!\n" << std::endl;
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);
} }
} }
void DeviceLibrary::createLogicalDevice(VkDevice& device) {
// Describe how many queues we want for a single family (1) here, right now we are solely interested in graphics capabilites,
// but Compute Shaders, transfer ops, decode and encode operations can also queued with setup! We also assign each queue a priority.
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
VkDeviceQueueCreateInfo queueCreateInfo{};
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queueCreateInfo.queueFamilyIndex = indices.graphicsFamily.value();
queueCreateInfo.queueCount = 1;
float queuePriority = 1.0f;
queueCreateInfo.pQueuePriorities = &queuePriority;
VkDeviceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
createInfo.pQueueCreateInfos = &queueCreateInfo;
createInfo.queueCreateInfoCount = 1;
createInfo.pEnabledFeatures = &deviceFeatures;
createInfo.enabledExtensionCount = 0;
if(enableValidationLayers) {
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
createInfo.ppEnabledLayerNames = validationLayers.data();
} else {
createInfo.enabledLayerCount = 0;
}
if(vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) {
throw std::runtime_error("Failed to create logical device");
}
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
}

View File

@ -1,9 +1,14 @@
#pragma once #pragma once
#include <vulkan/vulkan_core.h> #include "global.h"
namespace AgnosiaEngine { namespace DeviceControl {
class DeviceLibrary { class DeviceLibrary {
public: public:
void pickPhysicalDevice(VkInstance& instance); void pickPhysicalDevice(VkInstance& instance);
void createLogicalDevice(VkDevice& devicvee); void createLogicalDevice(VkDevice& device);
void createSurface(VkInstance& instance, GLFWwindow* window);
void destroySurface(VkInstance& instance);
}; };
} }

View File

@ -5,18 +5,11 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "../global.h" #include "../global.h"
#include "VulkanDebugLibs.h" using namespace Debug;
using namespace AgnosiaEngine;
#include <cstring> #include <cstring>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
// This ifdef checks if the build flag is present, hence whether to hook the debugger in at all.
#ifdef DEBUG
const bool enableValidationLayers = true;
#else
const bool enableValidationLayers = false;
#endif
// This is our messenger object! It handles passing along debug messages to the debug callback we will also set. // This is our messenger object! It handles passing along debug messages to the debug callback we will also set.
VkDebugUtilsMessengerEXT debugMessenger; VkDebugUtilsMessengerEXT debugMessenger;
// This is the set of "layers" to hook into. Basically, layers are used to tell the messenger what data we want, its a filter. *validation* is the general blanket layer to cover incorrect usage. // This is the set of "layers" to hook into. Basically, layers are used to tell the messenger what data we want, its a filter. *validation* is the general blanket layer to cover incorrect usage.
@ -31,7 +24,7 @@ std::vector<const char*> getRequiredExtensions() {
std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount); std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
if(enableValidationLayers) { if(Global::enableValidationLayers) {
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
} }
return extensions; return extensions;
@ -51,6 +44,8 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
return VK_FALSE; return VK_FALSE;
} }
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo) { void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo) {
// There is absolutely nothing about this i like, those long ass flags for messageType and Severity are just fucking hex values. Khronos should never cook again ToT // There is absolutely nothing about this i like, those long ass flags for messageType and Severity are just fucking hex values. Khronos should never cook again ToT
// On a serious note, this is just a struct to define the parameters of the debug messenger, nothing super special. // On a serious note, this is just a struct to define the parameters of the debug messenger, nothing super special.
@ -71,9 +66,9 @@ void VulkanDebugLibs::vulkanDebugSetup(VkInstanceCreateInfo& createInfo, VkInsta
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size()); createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
createInfo.ppEnabledExtensionNames = extensions.data(); createInfo.ppEnabledExtensionNames = extensions.data();
if(enableValidationLayers) { if(Global::enableValidationLayers) {
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size()); createInfo.enabledLayerCount = static_cast<uint32_t>(Global::validationLayers.size());
createInfo.ppEnabledLayerNames = validationLayers.data(); createInfo.ppEnabledLayerNames = Global::validationLayers.data();
populateDebugMessengerCreateInfo(debugCreateInfo); populateDebugMessengerCreateInfo(debugCreateInfo);
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo; createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
@ -90,7 +85,7 @@ void VulkanDebugLibs::vulkanDebugSetup(VkInstanceCreateInfo& createInfo, VkInsta
void VulkanDebugLibs::checkUnavailableValidationLayers() { void VulkanDebugLibs::checkUnavailableValidationLayers() {
// Check if we are trying to hook validation layers in without support. // Check if we are trying to hook validation layers in without support.
if(enableValidationLayers && !checkValidationLayerSupport()) { if(Global::enableValidationLayers && !checkValidationLayerSupport()) {
throw std::runtime_error("Validation layers request, but not available! Are your SDK path variables set?"); throw std::runtime_error("Validation layers request, but not available! Are your SDK path variables set?");
} }
} }
@ -106,7 +101,7 @@ bool VulkanDebugLibs::checkValidationLayerSupport() {
std::vector<VkLayerProperties> availableLayers(layerCount); std::vector<VkLayerProperties> availableLayers(layerCount);
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
for(const char* layerName : validationLayers) { for(const char* layerName : Global::validationLayers) {
bool layerFound = false; bool layerFound = false;
for(const auto& layerProperties : availableLayers) { for(const auto& layerProperties : availableLayers) {
@ -153,7 +148,7 @@ void VulkanDebugLibs::DestroyDebugUtilsMessengerEXT(VkInstance instance,
void VulkanDebugLibs::setupDebugMessenger(VkInstance& vulkanInstance) { void VulkanDebugLibs::setupDebugMessenger(VkInstance& vulkanInstance) {
// This is a pretty simple function! we just pass in the values to build the debug messenger, populate the structure with the data we want, // This is a pretty simple function! we just pass in the values to build the debug messenger, populate the structure with the data we want,
// and safely create it, covering for runtime errors as per usual, this is the first thing that will be called! // and safely create it, covering for runtime errors as per usual, this is the first thing that will be called!
if(!enableValidationLayers) return; if(!Global::enableValidationLayers) return;
VkDebugUtilsMessengerCreateInfoEXT createInfo; VkDebugUtilsMessengerCreateInfoEXT createInfo;
populateDebugMessengerCreateInfo(createInfo); populateDebugMessengerCreateInfo(createInfo);

View File

@ -2,8 +2,9 @@
#include <vector> #include <vector>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
namespace AgnosiaEngine { namespace Debug {
class VulkanDebugLibs { class VulkanDebugLibs {
public: public:
void vulkanDebugSetup(VkInstanceCreateInfo& createInfo, VkInstance& instance); void vulkanDebugSetup(VkInstanceCreateInfo& createInfo, VkInstance& instance);
bool checkValidationLayerSupport(); bool checkValidationLayerSupport();

View File

@ -1,5 +1,13 @@
#include "global.h" #include "global.h"
namespace Global {
const std::vector<const char*> validationLayers = { const std::vector<const char*> validationLayers = {
"VK_LAYER_KHRONOS_validation" "VK_LAYER_KHRONOS_validation"
}; };
#ifdef DEBUG
const bool enableValidationLayers = true;
#else
const bool enableValidationLayers = false;
#endif
}

View File

@ -1,5 +1,13 @@
#pragma once #pragma once
#include "debug/VulkanDebugLibs.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <vulkan/vulkan_core.h>
extern const std::vector<const char*> validationLayers; #define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
namespace Global {
extern const std::vector<const char*> validationLayers;
extern const bool enableValidationLayers;
}

View File

@ -1,24 +1,14 @@
#include <vector>
#include <vulkan/vulkan_core.h>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include "debug/VulkanDebugLibs.h" #include "debug/VulkanDebugLibs.h"
#include "DeviceLibrary.h" #include "DeviceLibrary.h"
using namespace AgnosiaEngine; #include "debug/VulkanDebugLibs.h"
#include "global.h"
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#ifdef DEBUG
const bool enableValidationLayers = true;
#else
const bool enableValidationLayers = false;
#endif
const uint32_t WIDTH = 800; const uint32_t WIDTH = 800;
const uint32_t HEIGHT = 600; const uint32_t HEIGHT = 600;
@ -26,7 +16,6 @@ const uint32_t HEIGHT = 600;
class TriangleTestApplication { class TriangleTestApplication {
public: public:
void run() { void run() {
initWindow(); initWindow();
initVulkan(); initVulkan();
@ -35,11 +24,13 @@ public:
} }
private: private:
DeviceControl::DeviceLibrary deviceLibs;
Debug::VulkanDebugLibs debugController;
GLFWwindow* window; GLFWwindow* window;
VkInstance instance; VkInstance instance;
VulkanDebugLibs debug;
DeviceLibrary deviceLibs;
VkDevice device; VkDevice device;
// Initialize GLFW Window. First, Initialize GLFW lib, disable resizing for // Initialize GLFW Window. First, Initialize GLFW lib, disable resizing for
// now, and create window. // now, and create window.
void initWindow() { void initWindow() {
@ -53,13 +44,14 @@ private:
void initVulkan() { void initVulkan() {
createInstance(); createInstance();
debug.setupDebugMessenger(instance); // The debug messenger is out holy grail, it gives us Vulkan related debug info when built with the -DNDEBUG flag (as per the makefile) debugController.setupDebugMessenger(instance); // The debug messenger is out holy grail, it gives us Vulkan related debug info when built with the -DNDEBUG flag (as per the makefile)
deviceLibs.createSurface(instance, window);
deviceLibs.pickPhysicalDevice(instance); deviceLibs.pickPhysicalDevice(instance);
deviceLibs.createLogicalDevice(device); deviceLibs.createLogicalDevice(device);
} }
void createInstance() { void createInstance() {
debug.checkUnavailableValidationLayers(); // Check if there is a mistake with our Validation Layers. debugController.checkUnavailableValidationLayers(); // Check if there is a mistake with our Validation Layers.
// Set application info for the vulkan instance! // Set application info for the vulkan instance!
VkApplicationInfo appInfo{}; VkApplicationInfo appInfo{};
@ -69,13 +61,13 @@ private:
appInfo.applicationVersion = VK_MAKE_VERSION(1,0,0); // Create a Major Minor Patch version number for the application! appInfo.applicationVersion = VK_MAKE_VERSION(1,0,0); // Create a Major Minor Patch version number for the application!
appInfo.pEngineName = "Agnosia Engine"; // Give an internal name for the engine running appInfo.pEngineName = "Agnosia Engine"; // Give an internal name for the engine running
appInfo.engineVersion = VK_MAKE_VERSION(1,0,0); // Similar to the App version, give vulkan an *engine* version appInfo.engineVersion = VK_MAKE_VERSION(1,0,0); // Similar to the App version, give vulkan an *engine* version
appInfo.apiVersion = VK_API_VERSION_1_0; // Tell vulkan what the highest API version we will allow this program to run on appInfo.apiVersion = VK_API_VERSION_1_1; // Tell vulkan what the highest API version we will allow this program to run on
VkInstanceCreateInfo createInfo{}; // Define parameters of new vulkan instance VkInstanceCreateInfo createInfo{}; // Define parameters of new vulkan instance
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; // Tell vulkan this is a info structure createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; // Tell vulkan this is a info structure
createInfo.pApplicationInfo = &appInfo; // We just created a new appInfo structure, so we pass the pointer to it. createInfo.pApplicationInfo = &appInfo; // We just created a new appInfo structure, so we pass the pointer to it.
debug.vulkanDebugSetup(createInfo, instance); // Handoff to the debug library to wrap the validation libs in! (And set the window up!) debugController.vulkanDebugSetup(createInfo, instance); // Handoff to the debug library to wrap the validation libs in! (And set the window up!)
} }
void mainLoop() { // This loop just updates the GLFW window. void mainLoop() { // This loop just updates the GLFW window.
@ -86,14 +78,15 @@ private:
void cleanup() { // Similar to the last handoff, destroy the debug util in a safe manner in the library! void cleanup() { // Similar to the last handoff, destroy the debug util in a safe manner in the library!
vkDestroyDevice(device, nullptr); vkDestroyDevice(device, nullptr);
if(enableValidationLayers) { if(Global::enableValidationLayers) {
debug.DestroyDebugUtilsMessengerEXT(instance, nullptr); debugController.DestroyDebugUtilsMessengerEXT(instance, nullptr);
} }
deviceLibs.destroySurface(instance);
vkDestroyInstance(instance, nullptr); vkDestroyInstance(instance, nullptr);
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();
} }
}; };
int main() { int main() {