Search code examples
vulkan

How can the list of available extensions and layers change?


If an enabled layer or extension is not available at instance creation, vkCreateInstance returns VK_ERROR_EXTENSION_NOT_PRESENT or VK_ERROR_LAYER_NOT_PRESENT. I would like to identify which layer or extension is not supported, to provide better error messages. vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties seem perfect for the job.

However, according to the specification, the list of available extensions and layers may change at any time. My current understanding is that this list can be changed from outside the Vulkan implementation, not by the implementation itself.

Is this correct? How can the list of available layers and extensions change, specifically? Is it likely to happen? Can I actually rely on vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties to provide useful output?

Thanks in advance!


Because the list of available layers may change externally between calls to vkEnumerateInstanceExtensionProperties, two calls may retrieve different results if a pLayerName is available in one call but not in another. The extensions supported by a layer may also change between two calls, e.g. if the layer implementation is replaced by a different version between those calls.

vkEnumerateInstanceExtensionProperties Manual Page

The list of available layers may change at any time due to actions outside of the Vulkan implementation, so two calls to vkEnumerateInstanceLayerProperties with the same parameters may return different results, or retrieve different pPropertyCount values or pProperties contents. Once an instance has been created, the layers enabled for that instance will continue to be enabled and valid for the lifetime of that instance, even if some of them become unavailable for future instances.

vkEnumerateInstanceLayerProperties Manual Page


Solution

  • How can the list of available layers and extensions change, specifically? Is it likely to happen?

    A user can install a new driver. Or more specifically, a driver can be updated between those two calls. The user could also modify settings in the driver that change these things. The user might install additional layers.

    The point the specification is making is this: there is some time in your application between asking what extensions/layers are available and asking to create an instance. The implementation is a shared resource, and the system you're running on is multiprocess. There is no "mutex" or similar locking mechanism to prevent something external from your application from modifying the driver between asking and requesting an instance. As such, there is always a chance, no matter how small, that something will change between asking the question and creating an instance that will invalidate your request.

    Reporting an error with a specific layer/extension isn't especially useful here because there's probably not much a user can actually do with that information. It's not like you telling them that extension VK_Whatever wasn't found is information that will help them fix the problem. It's not even going to help you fix the problem, since you still don't know why VK_Whatever was advertised initially but was later unavailable.

    Your best bet is to just try the whole instance-creation process again, including re-querying the available layers. You may even wish to wait a second or two between attempts. If that doesn't resolve it, then something unpleasant is going on in the system, so just terminate your program.

    Can I actually rely on vkEnumerateInstanceExtensionProperties and vkEnumerateInstanceLayerProperties to provide useful output?

    As useful as you're going to get. Basically, the specification is just recognizing reality: users own their computers, not your application, so they could theoretically do something that causes a problem for your program.

    Deal with it as best you can.