Search code examples
c#vulkan

EnumerateInstanceLayerProperties does not return VK_LAYER_KHRONOS_validation layer


I am trying Vulkan API through Silk.NET.

In check validation layer step it returns this layers:

"VK_LAYER_VALVE" "VK_LAYER_OW" "VK_LAYER_OBS"

but it doesn't contain VK_LAYER_KHRONOS_validation, and this throws an exception.

private readonly bool enableValidationLayers;
private readonly string[] validationLayers =
[
    "VK_LAYER_KHRONOS_validation"
];
...
if (enableValidationLayers && !CheckValidationLayerSupport())
{
    throw new Exception("Validation layers requested, but not available!");
}
...
private bool CheckValidationLayerSupport()
{
    // get all available layers ...
    uint layerCount = 0;
    vk!.EnumerateInstanceLayerProperties(ref layerCount, null);
    LayerProperties[] availableLayers = new LayerProperties[layerCount];
    fixed (LayerProperties* availableLayersPtr = availableLayers)
    {
        vk!.EnumerateInstanceLayerProperties(ref layerCount, availableLayersPtr);
    }
    HashSet<string?> availableLayerNames = availableLayers.Select(layer => Marshal.PtrToStringAnsi((IntPtr)layer.LayerName)).ToHashSet();
    // ... and check that required are in there
    return validationLayers.All(availableLayerNames.Contains);
}

If I am not using validation layers it works, but then what's the point


Solution

  • The most likely explanation is that you do not have the validation layer installed. It does not get installed by default in your OS or by installing Vulkan drivers. You can get the validation layer from the Vulkan SDK (https://vulkan.lunarg.com).