add validation layer checking (c++20 black magic)
This commit is contained in:
@@ -34,6 +34,8 @@ void Engine::draw() {
|
|||||||
|
|
||||||
bool Engine::createInstance() {
|
bool Engine::createInstance() {
|
||||||
|
|
||||||
|
uint32_t errorCount = 0;
|
||||||
|
|
||||||
// create the appInfo filled with information about our app
|
// create the appInfo filled with information about our app
|
||||||
constexpr vk::ApplicationInfo appInfo { // using the c++ api instead of the c api
|
constexpr vk::ApplicationInfo appInfo { // using the c++ api instead of the c api
|
||||||
.pApplicationName = "maiden",
|
.pApplicationName = "maiden",
|
||||||
@@ -46,9 +48,31 @@ bool Engine::createInstance() {
|
|||||||
// get necessary extensions that our windowing library requires
|
// get necessary extensions that our windowing library requires
|
||||||
uint32_t instanceExtensionsCount = 0;
|
uint32_t instanceExtensionsCount = 0;
|
||||||
char const* const* instanceExtensions{ SDL_Vulkan_GetInstanceExtensions(&instanceExtensionsCount) };
|
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();
|
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
|
for(uint32_t i = 0; i < instanceExtensionsCount; i++) { // for each extension that we require
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for(const auto& extensionProperty : extensionProperties) { // see if it matches any extensions that are provided
|
for(const auto& extensionProperty : extensionProperties) { // see if it matches any extensions that are provided
|
||||||
@@ -64,7 +88,7 @@ bool Engine::createInstance() {
|
|||||||
errorCount++;
|
errorCount++;
|
||||||
} else {
|
} else {
|
||||||
// in case you're curious
|
// 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 any weren't then we must exit
|
||||||
if(errorCount != 0) return false;
|
if(errorCount != 0) return false;
|
||||||
@@ -76,10 +100,6 @@ bool Engine::createInstance() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
instance_ = vk::raii::Instance(context_, instanceCreateInfo);
|
instance_ = vk::raii::Instance(context_, instanceCreateInfo);
|
||||||
if(instance_ != nullptr) {
|
return (instance_ != nullptr);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,4 +28,7 @@ private:
|
|||||||
vk::raii::Context context_;
|
vk::raii::Context context_;
|
||||||
vk::raii::Instance instance_ = nullptr;
|
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" };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user