diff --git a/CMakeLists.txt b/CMakeLists.txt index c8802c5..9e7c3d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,9 @@ target_link_options(maiden_core PRIVATE --coverage) target_link_options(maiden PRIVATE --coverage) target_link_options(maiden_test PRIVATE --coverage) +# vulkan necessity +target_compile_definitions(maiden_core PRIVATE VULKAN_HPP_NO_STRUCT_CONSTRUCTORS) + target_link_libraries(maiden PRIVATE maiden_core SDL3::SDL3 diff --git a/README.md b/README.md index 3515f4b..090bdaa 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,10 @@ $ cd build $ gcovr -r .. --filter "../src" ``` -### app troubleshooting here +## App Troubleshooting +Basically these are some tricky situations that I encountered when trying to execute this app throughout this development phase. If you are running on WSL Ubuntu 26.04 like me, then you mightr run into these too, hopefully my steps help fix. +note: I am running an x86_64 system with an Nvidia GPU so some things may be slightly different if your system doesn't match. + ## Development Roadmap ### lots of todo here diff --git a/src/Engine.cpp b/src/Engine.cpp index 003fe2e..fec5df3 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1,7 +1,6 @@ #include "Engine.hpp" -#include "vulkan/vulkan.h" #include Engine::Engine(Window* window): window_(window) { @@ -13,24 +12,7 @@ Engine::Engine(Window* window): window_(window) { void Engine::init() { - VkApplicationInfo appInfo { - .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, - .pApplicationName = "maiden", - .apiVersion = VK_API_VERSION_1_4 - }; - - uint32_t instanceExtensionsCount = 0; - char const* const* instanceExtensions{ SDL_Vulkan_GetInstanceExtensions(&instanceExtensionsCount) }; - - VkInstanceCreateInfo instanceCI { - .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, - .pApplicationInfo = &appInfo, - .enabledExtensionCount = instanceExtensionsCount, - .ppEnabledExtensionNames = instanceExtensions, - }; - - VkInstance instance; - if(vkCreateInstance(&instanceCI, nullptr, &instance) == VK_SUCCESS) { + if(createInstance()) { // TODO: need some kind of logger service std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Vulkan instance successfully created." << std::endl; } else { @@ -49,3 +31,55 @@ void Engine::init() { void Engine::draw() { } + +bool Engine::createInstance() { + + // create the appInfo filled with information about our app + constexpr vk::ApplicationInfo appInfo { // using the c++ api instead of the c api + .pApplicationName = "maiden", + .applicationVersion = VK_MAKE_VERSION(1, 0, 0), + .pEngineName = "null", + .engineVersion = VK_MAKE_VERSION(1, 0, 0), + .apiVersion = VK_API_VERSION_1_4 // this one is most important + }; + + // get necessary extensions that our windowing library requires + uint32_t instanceExtensionsCount = 0; + char const* const* instanceExtensions{ SDL_Vulkan_GetInstanceExtensions(&instanceExtensionsCount) }; + // check if these extensions are available + auto extensionProperties = context_.enumerateInstanceExtensionProperties(); + uint32_t errorCount = 0; + for(uint32_t i = 0; i < instanceExtensionsCount; i++) { // for each extension that we require + bool found = false; + for(const auto& extensionProperty : extensionProperties) { // see if it matches any extensions that are provided + if(strcmp(extensionProperty.extensionName, instanceExtensions[i]) == 0) { + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Required SDL3 extension not supported: " << instanceExtensions[i] << std::endl; + } else { + found = true; + break; + } + } + if(!found) { + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Required SDL3 extension not supported: " << instanceExtensions[i] << std::endl; + errorCount++; + } else { + // in case you're curious + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] SDL3 extension located: " << instanceExtensions[i] << std::endl; + } + } // if any weren't then we must exit + if(errorCount != 0) return false; + + vk::InstanceCreateInfo instanceCreateInfo { + .pApplicationInfo = &appInfo, + .enabledExtensionCount = instanceExtensionsCount, + .ppEnabledExtensionNames = instanceExtensions, + }; + + instance_ = vk::raii::Instance(context_, instanceCreateInfo); + if(instance_ != nullptr) { + return true; + } else { + return false; + } +} + diff --git a/src/Engine.hpp b/src/Engine.hpp index cb017e1..e45710c 100644 --- a/src/Engine.hpp +++ b/src/Engine.hpp @@ -1,6 +1,9 @@ #pragma once +// resource allocation is initializion my beloved +#include + #include "Window.hpp" class Engine { @@ -17,8 +20,12 @@ public: private: - // might get rid of this - Window* window_; + bool createInstance(); + + // Vulkan specific + vk::raii::Context context_; + vk::raii::Instance instance_ = nullptr; + };