Layer libraries can be written to intercept or hook VK entry points for various debug and validation purposes. One or more VK entry points can be defined in your Layer library. Undefined entrypoints in the Layer library will be passed to the next Layer which may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together. vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the available layers and their properties. Layers can intercept Vulkan instance level entry points in which case they are called an Instance Layer. Layers can intercept device entry points in which case they are called a Device Layer. Instance level entry points are those with VkInstance or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCommandBuffer, or VkQueue as the first parameter. Layers that want to intercept both instance and device level entrypoints are called Global Layers. vkXXXXGetProcAddr is used internally by the Layers and Loader to initialize dispatch tables. Device Layers are activated at vkCreateDevice time. Instance Layers are activated at vkCreateInstance time. Layers can also be activated via environment variables (VK_INSTANCE_LAYERS or VK_DEVICE_LAYERS).
Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers
-include/vkLayer.h - header file for layer code.
layers/basic.cpp (name=VK_LAYER_LUNARG_basic) simple example wrapping a few entrypoints. Shows layer features:
layers/multi.cpp (name=VK_LAYER_LUNARG_multi1:VK_LAYER_LUNARG_multi2) simple example showing multiple layers per library
(build dir)/layer/generic_layer.cpp (name=VK_LAYER_LUNARG_generic) - auto generated example wrapping all VK entrypoints.
(build dir)/layers/api_dump.cpp (name=VK_LAYER_LUNARG_api_dump) - print out API calls along with parameter values
Build VK loader and i965 icd driver using normal steps (cmake and make)
Place libVkLayer_.so in the same directory as your VK test or app:
cp build/layer/libVkLayer_basic.so build/layer/libVkLayer_generic.so build/tests
This is required for the Loader to be able to scan and enumerate your library. Alternatively, use the VK_LAYER_PATH environment variable to specify where the layer libraries reside.
Create a vk_layer_settings.txt file in the same directory to specify how your layers should behave.
Model it after the following example: vk_layer_settings.txt
Specify which Layers to activate by using vkCreateDevice and/or vkCreateInstance or environment variables.
export VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_basic:VK_LAYER_LUNARG_generic export VK_DEVICE_LAYERS=VK_LAYER_LUNARG_basic:VK_LAYER_LUNARG_generic cd build/tests; ./vkinfo