Search code examples
c++vulkan

Vulkan Validation Layers Not Available


I'm new to Vulkan, and I've been following vulkan-tutorial.com which has been a great resource so far.

However, one weird thing I've come to realize is that validation layers are supported on my device, but cannot be used without being overridden in vkconfig.

Following the tutorial, this is my C++ code at the moment:

auto check_validation_layer_support() -> bool
{
    // Get the number of layers
    uint32_t layerCount = 0U;
    vkEnumerateInstanceLayerProperties(&layerCount, nullptr);

    // Get the layer properties
    std::vector<VkLayerProperties> availableLayers(layerCount);
    vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());

    // Iterate through to check support
    for (const char* layerName : VulkanInstance::validationLayers)
    {
        bool layerFound = false;
        for (const auto& layerProperties : availableLayers)
        {
            if (strcmp(layerName, layerProperties.layerName) == 0)
            {
                layerFound = true;
                break;
            }
        }

        if(!layerFound)
            return false;
    }

    return true;
}
static constexpr std::array<const char* const, 1UL> validationLayers {
    "VK_LAYER_KHRONOS_validation",
};
source "/opt/vulkansdk/1.3.224.1/setup-env.sh"
export VK_LAYER_PATH="$VULKAN_SDK/lib/vulkan/layers"
export VK_INSTANCE_LAYERS="VK_LAYER_LUNARG_api_dump:VK_LAYER_KHRONOS_validation"

When running vkconfig and overriding to use Validation Layers, suddenly everything works perfectly fine. However, if it is not a forced override, it will not work at all.

I'm using the LunarG SDK (1.3.224.1) for Arch Linux (Wayland).


Solution

  • Your setting for VK_LAYER_PATH does not look right. The setup script should set a "layer path" environment variable for you and so you could try not exporting VK_LAYER_PATH after running the setup script. And if you were to set VK_LAYER_PATH, it should be something like $VULKAN_SDK/etc/vulkan/explicit_layer.d.

    Note that the setup script actually sets VK_ADD_LAYER_PATH which tells the loader to look in the SDK in addition to and before the system default paths. Setting VK_LAYER_PATH after running the setup script causes the loader to ignore VK_ADD_LAYER_PATH and use only VK_LAYER_PATH, which was faulty in your case. This left the loader with no good paths to find layers.