gardenThe debugging voice of an otherwise silent API
Vulkan validation layers
The concept
Vulkan is a low-level API and is not very talkative. If we make an error, the
program will often crash without any explanation. A validation layer can be
added to the Vulkan instance to help catch errors, such as the standard
VK_LAYER_KHRONOS_validation.
// cpp
std::vector<const char*> layers;
layers.push_back("VK_LAYER_KHRONOS_validation");Validation layers are only used during the development phase and are removed in production builds to improve performance.
To use validation layers we also need to check that they are installed on our
dev machine; if not, we will get VK_ERROR_LAYER_NOT_PRESENT.
// cpp
bool checkLayersSupport(
const std::vector<const char*>& requiredLayers,
const std::vector<vk::LayerProperties>& availableLayers)
{
for (const auto& required : requiredLayers) {
const bool found =
std::ranges::any_of(availableLayers, [required](const auto& prop) {
return strcmp(prop.layerName, required) == 0;
});
if (!found) {
std::cerr << "[Error] Missing required layer: " << required
<< std::endl;
return false;
}
}
return true;
}
// usage
std::vector<const char*> layers;
layers.push_back("VK_LAYER_KHRONOS_validation");
if (!checkLayersSupport(layers, d_context.enumerateInstanceLayerProperties())) {
std::cerr << "Failed to find all required layers!" << std::endl;
}Linked references 3
notes that point at this one
Vulkan extensionsvulkan
push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); #endif As with validation layers, we also need to check that our extensions are available on this machine.
Vulkan instancevulkan
What the instance enables Two more things are configured at instance creation, each with its own note: Vulkan validation layers — debugging help attached to the instance…
Architecturegamegine
Context initialization — the Vulkan context then builds its pieces, each with its own note: Vulkan instance — the connection to the Vulkan library, with Vulkan validation lay…