Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 1 | # Layer Description and Status |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 2 | |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 3 | ## Overview |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 4 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 5 | Layer libraries can be written to intercept or hook VK entry points for various |
| 6 | debug and validation purposes. One or more VK entry points can be defined in your Layer |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 7 | library. Undefined entrypoints in the Layer library will be passed to the next Layer which |
| 8 | may be the driver. Multiple layer libraries can be chained (actually a hierarchy) together. |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 9 | vkEnumerateInstanceLayerProperties and vkEnumerateDeviceLayerProperties can be called to list the |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 10 | available layers and their properties. Layers can intercept Vulkan instance level entry points |
| 11 | in which case they are called an Instance Layer. Layers can intercept device entry points |
| 12 | in which case they are called a Device Layer. Instance level entry points are those with VkInstance |
| 13 | or VkPhysicalDevice as first parameter. Device level entry points are those with VkDevice, VkCmdBuffer, |
| 14 | or VkQueue as the first parameter. Layers that want to intercept both instance and device |
| 15 | level entrypoints are called Global Layers. vkXXXXGetProcAddr is used internally by the Layers and |
| 16 | Loader to initialize dispatch tables. Device Layers are activated at vkCreateDevice time. Instance |
| 17 | Layers are activated at vkCreateInstance. Layers can also be activated via environment variables |
| 18 | (VK_INSTANCE_LAYERS or VK_DEVICE_LAYERS). |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 19 | |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 20 | All validation layers work with the DEBUG_REPORT extension to provide the application or user with |
| 21 | validation feedback. When a validation layer is enabled, it will look at the vk_layer_settings.txt |
| 22 | file to determine it's behavior. Such as outputing to a file, stdout or debug output (Windows). An |
| 23 | application can also register callback functions via the DEBUG_REPORT extension to receive callbacks |
| 24 | when the requested validation events happen. Application callbacks happen regardless of the |
| 25 | settings in vk_layer_settings.txt |
| 26 | |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 27 | ##Layer library example code |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 28 | |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 29 | Note that some layers are code-generated and will therefore exist in the directory (build_dir)/layers |
| 30 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | -include/vkLayer.h - header file for layer code. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 32 | |
| 33 | ### Templates |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 34 | layer/Basic.cpp (name=Basic) simple example wrapping a few entrypoints. Shows layer features: |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 35 | - Multiple dispatch tables for supporting multiple GPUs. |
| 36 | - Example layer extension function shown. |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 37 | - Layer extension advertised by vkGetXXXExtension(). |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 38 | |
| 39 | layer/Multi.cpp (name=multi1:multi2) simple example showing multiple layers per library |
| 40 | |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 41 | (build dir)/layer/generic_layer.cpp (name=Generic) - auto generated example wrapping all VK entrypoints. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 42 | |
| 43 | ### Print API Calls and Parameter Values |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 44 | (build dir)/layer/api_dump.cpp (name=APIDump) - print out API calls along with parameter values |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 45 | |
| 46 | ### Print Object Stats |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 47 | (build dir)/layer/object_track.cpp (name=ObjectTracker) - Track object CREATE/USE/DESTROY stats. Individually track objects by category. VkObjectType enum defined in vulkan.h. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 48 | |
| 49 | ### Report Draw State |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 50 | layer/draw\_state.cpp (name=DrawState) - DrawState reports the Descriptor Set, Pipeline State, and dynamic state at each Draw call. DrawState layer performs a number of validation checks on this state. Of primary interest is making sure that the resources bound to Descriptor Sets correctly align with the layout specified for the Set. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 51 | |
| 52 | ### Track GPU Memory |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 53 | layer/mem\_tracker.cpp (name=MemTracker) - MemTracker functions mostly as a validation layer, attempting to ensure that memory objects are managed correctly by the application. These memory objects are bound to pipelines, objects, and command buffers, and then submitted to the GPU for work. As an example, the layer validates that the correct memory objects have been bound, and that they are specified correctly when the command buffers are submitted. Also, that only existing memory objects are referenced, and that any destroyed memory objects are not referenced. Another type of validation done is that before any memory objects are reused or destroyed, the layer ensures that the application has confirmed that they are no longer in use, and that they have been properly unbound before destruction. |
| 54 | |
| 55 | ### Device Limits |
| 56 | <build dir>/layer/device_limits.cpp (name=DeviceLimits) - Check that parameters used do not exceed device limits. |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 57 | |
Tobin Ehlis | 27c2d82 | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 58 | ### Check parameters |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 59 | <build dir>/layer/param_checker.cpp (name=ParamChecker) - Check the input parameters to API calls for validity. Currently this only checks ENUM params directly passed to API calls and ENUMs embedded in struct params. |
| 60 | |
| 61 | ### Image Checker |
| 62 | <build dir>/layer/image.cpp (name=Image) - Verify parameters on Vulkan calls that use VkImage. |
Tobin Ehlis | 27c2d82 | 2014-12-18 10:32:57 -0700 | [diff] [blame] | 63 | |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 64 | ### Check threading |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 65 | <build dir>/layer/threading.cpp (name=Threading) - Check multithreading of API calls for validity. Currently this checks that only one thread at a time uses an object in free-threaded API calls. |
| 66 | |
| 67 | ### Swapchain |
| 68 | <build dir>/layer/swapchain.cpp (name=Swapchain) - Check that WSI extensions are being used correctly. |
| 69 | |
| 70 | ### Shader Checker |
| 71 | <build dir>/layer/shader_checker.cpp (name=ShaderChecker) - Verify SPIR-V shader layout matches descriptor set. |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 72 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 73 | ## Using Layers |
| 74 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 75 | 1. Build VK loader and i965 icd driver using normal steps (cmake and make) |
| 76 | 2. Place libVKLayer<name>.so in the same directory as your VK test or app: |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 77 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 78 | cp build/layer/libVKLayerBasic.so build/layer/libVKLayerGeneric.so build/tests |
Jon Ashburn | de3630c | 2014-12-18 17:26:52 -0700 | [diff] [blame] | 79 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 80 | This is required for the Loader to be able to scan and enumerate your library. |
Courtney Goeltzenleuchter | c66236e | 2015-09-28 15:13:45 -0600 | [diff] [blame^] | 81 | Alternatively, use the VK\_LAYER\_PATH environment variable to specify where the layer libraries reside. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 82 | |
| 83 | 3. Specify which Layers to activate by using |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 84 | vkCreateDevice and/or vkCreateInstance or environment variables. |
Jens Owen | 8b5ed54 | 2014-12-18 14:36:31 -0700 | [diff] [blame] | 85 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 86 | export VK\_INSTANCE\_LAYERS=Basic:Generic |
| 87 | export VK\_DEVICE\_LAYERS=Basic:Generic |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 88 | cd build/tests; ./vkinfo |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 89 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 90 | ## Tips for writing new layers |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 91 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 92 | 1. Must implement vkGetInstanceProcAddr() (aka GIPA) and vkGetDeviceProcAddr() (aka GDPA); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 93 | 2. Must have a local dispatch table to call next layer (see vkLayer.h); |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 94 | 3. Must have a layer manifest file for each Layer library for Loader to find layer properties (see loader/README.md) |
| 95 | 4. next layers GXPA can be found in the wrapped instance or device object; |
| 96 | 5. Loader calls a layer's GXPA first so initialization should occur here; |
| 97 | 6. all entrypoints can be wrapped but only will be called after layer is activated |
| 98 | via the first vkCreatDevice or vkCreateInstance; |
| 99 | 7. entrypoint names can be any name as specified by the layers vkGetXXXXXProcAddr |
| 100 | implementation; exceptions are vkGetXXXXProcAddr, |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 101 | which must have the correct name since the Loader calls these entrypoints; |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 102 | 8. entrypoint names must be exported to the OSes dynamic loader with VK\_LAYER\_EXPORT; |
| 103 | 9. Layer naming convention is camel case same name as in library: libVKLayer<name>.so |
| 104 | 10. For multiple layers in one library the manifest file can specify each layer. |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 105 | |
| 106 | ## Status |
| 107 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 108 | |
Jon Ashburn | 9d290e4 | 2014-11-26 13:27:04 -0700 | [diff] [blame] | 109 | ### Current known issues |
| 110 | |
Jon Ashburn | eaaaced | 2015-07-23 10:59:21 -0600 | [diff] [blame] | 111 | - Layers with multiple layers per library the manifest file parsing in Loader doesn't yet handle this; |
| 112 | - multi.cpp Layer needs rewrite to allow manifest file to specify multiple layers |
| 113 | - multi1 and multi2 layers from multi.cpp: only multi1 layer working |
| 114 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 115 | |