2 Commits

Author SHA1 Message Date
6835359510 add validation layer checking (c++20 black magic)
Some checks failed
Build and Test verification / build (push) Failing after 38m46s
Build and Test verification / test (push) Has been skipped
2026-05-12 23:19:21 -05:00
e6b98362b6 fixed formatting because nano trolled me 2026-05-12 23:00:43 -05:00
2 changed files with 40 additions and 17 deletions

View File

@@ -34,6 +34,8 @@ void Engine::draw() {
bool Engine::createInstance() {
uint32_t errorCount = 0;
// create the appInfo filled with information about our app
constexpr vk::ApplicationInfo appInfo { // using the c++ api instead of the c api
.pApplicationName = "maiden",
@@ -46,9 +48,31 @@ bool Engine::createInstance() {
// 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
// get required validation layers as specified by our app
std::vector<const char*> requiredValidationLayers;
if(enableValidationLayers) requiredValidationLayers.assign(validationLayers.begin(), validationLayers.end());
auto validationLayerProperties = context_.enumerateInstanceLayerProperties();
auto unsupportedLayer = std::ranges::find_if(requiredValidationLayers, [&validationLayerProperties](const auto& requiredLayer) {
return std::ranges::none_of(validationLayerProperties, [requiredLayer](const auto& layerProperty) {
return strcmp(layerProperty.layerName, requiredLayer) == 0;
});
}); // TODO: what black magic even is this
if(unsupportedLayer != requiredValidationLayers.end()) {
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Required validation layer not supported: " << *unsupportedLayer << std::endl;
errorCount++;
}
// get all available extensions
auto extensionProperties = context_.enumerateInstanceExtensionProperties();
uint32_t errorCount = 0;
// print if we feel like it
std::cout << "Available Vulkan Extensions: " << std::endl;
for(const auto& extensionProperty : extensionProperties) {
std::cout << "\t" << extensionProperty.extensionName << std::endl;
}
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
@@ -64,7 +88,7 @@ bool Engine::createInstance() {
errorCount++;
} else {
// in case you're curious
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] SDL3 extension located: " << instanceExtensions[i] << std::endl;
//std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] SDL3 extension located: " << instanceExtensions[i] << std::endl;
}
} // if any weren't then we must exit
if(errorCount != 0) return false;
@@ -76,10 +100,6 @@ bool Engine::createInstance() {
};
instance_ = vk::raii::Instance(context_, instanceCreateInfo);
if(instance_ != nullptr) {
return true;
} else {
return false;
}
return (instance_ != nullptr);
}

View File

@@ -28,4 +28,7 @@ private:
vk::raii::Context context_;
vk::raii::Instance instance_ = nullptr;
static constexpr bool enableValidationLayers = true; // TODO: only true in debug mode
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
};