add required extensions to vulkan instance (+ use the c++ library over c library)
Some checks failed
Build and Test verification / build (push) Failing after 29s
Build and Test verification / test (push) Has been skipped

This commit is contained in:
2026-05-11 23:32:28 -05:00
parent 302b680a48
commit 0194699815
4 changed files with 69 additions and 22 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -1,7 +1,6 @@
#include "Engine.hpp"
#include "vulkan/vulkan.h"
#include <iostream>
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;
}
}

View File

@@ -1,6 +1,9 @@
#pragma once
// resource allocation is initializion my beloved
#include <vulkan/vulkan_raii.hpp>
#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;
};