xref: /aosp_15_r20/external/angle/src/third_party/volk/README.md (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# �� volk [![Build Status](https://travis-ci.org/zeux/volk.svg?branch=master)](https://travis-ci.org/zeux/volk)
2*8975f5c5SAndroid Build Coastguard Worker
3*8975f5c5SAndroid Build Coastguard Worker## ANGLE Integration
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard WorkerNote that the entirety of the volk README.md is included below. This is an additional section with information
6*8975f5c5SAndroid Build Coastguard Workeron volk's integration into ANGLE. The volk source files are copied directly from the volk GitHub repo.
7*8975f5c5SAndroid Build Coastguard WorkerTo update volk in ANGLE, copy the latest volk.h/c files into ANGLE "src/third_party/volk" dir and push update.
8*8975f5c5SAndroid Build Coastguard WorkerIf any changes are made to volk source files locally within ANGLE, please also make corresponding PRs so that
9*8975f5c5SAndroid Build Coastguard Workerthe changes land in the upstream source volk GitHub repo.
10*8975f5c5SAndroid Build Coastguard WorkerMake sure to change tabs to spaces, which clang-format later fixes, after updating the files.
11*8975f5c5SAndroid Build Coastguard WorkerAlso make sure to update the `Revision:` field in `README.chromium`.
12*8975f5c5SAndroid Build Coastguard Worker
13*8975f5c5SAndroid Build Coastguard Worker## Purpose
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Workervolk is a meta-loader for Vulkan. It allows you to dynamically load entrypoints required to use Vulkan
16*8975f5c5SAndroid Build Coastguard Workerwithout linking to vulkan-1.dll or statically linking Vulkan loader. Additionally, volk simplifies the use of Vulkan extensions by automatically loading all associated entrypoints. Finally, volk enables loading
17*8975f5c5SAndroid Build Coastguard WorkerVulkan entrypoints directly from the driver which can increase performance by skipping loader dispatch overhead.
18*8975f5c5SAndroid Build Coastguard Worker
19*8975f5c5SAndroid Build Coastguard Workervolk is written in C89 and supports Windows, Linux, Android and macOS (via MoltenVK).
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker## Building
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard WorkerThere are multiple ways to use volk in your project:
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker1. You can just add `volk.c` to your build system. Note that the usual preprocessor defines that enable Vulkan's platform-specific functions (VK_USE_PLATFORM_WIN32_KHR, VK_USE_PLATFORM_XLIB_KHR, VK_USE_PLATFORM_MACOS_MVK, etc) must be passed as desired to the compiler when building `volk.c`.
26*8975f5c5SAndroid Build Coastguard Worker2. You can use volk in header-only fashion. Include `volk.h` whereever you want to use Vulkan functions. In exactly one source file, define `VOLK_IMPLEMENTATION` before including `volk.h`. Do not build `volk.c` at all in this case. This method of integrating volk makes it possible to set the platform defines mentioned above with arbitrary (preprocessor) logic in your code.
27*8975f5c5SAndroid Build Coastguard Worker3. You can use provided CMake files, with the usage detailed below.
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker## Basic usage
30*8975f5c5SAndroid Build Coastguard Worker
31*8975f5c5SAndroid Build Coastguard WorkerTo use volk, you have to include `volk.h` instead of `vulkan/vulkan.h`; this is necessary to use function definitions from volk.
32*8975f5c5SAndroid Build Coastguard WorkerIf some files in your application include `vulkan/vulkan.h` and don't include `volk.h`, this can result in symbol conflicts; consider defining `VK_NO_PROTOTYPES` when compiling code that uses Vulkan to make sure this doesn't happen.
33*8975f5c5SAndroid Build Coastguard Worker
34*8975f5c5SAndroid Build Coastguard WorkerTo initialize volk, call this function first:
35*8975f5c5SAndroid Build Coastguard Worker
36*8975f5c5SAndroid Build Coastguard Worker```c++
37*8975f5c5SAndroid Build Coastguard WorkerVkResult volkInitialize();
38*8975f5c5SAndroid Build Coastguard Worker```
39*8975f5c5SAndroid Build Coastguard Worker
40*8975f5c5SAndroid Build Coastguard WorkerThis will attempt to load Vulkan loader from the system; if this function returns `VK_SUCCESS` you can proceed to create Vulkan instance.
41*8975f5c5SAndroid Build Coastguard WorkerIf this function fails, this means Vulkan loader isn't installed on your system.
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard WorkerAfter creating the Vulkan instance using Vulkan API, call this function:
44*8975f5c5SAndroid Build Coastguard Worker
45*8975f5c5SAndroid Build Coastguard Worker```c++
46*8975f5c5SAndroid Build Coastguard Workervoid volkLoadInstance(VkInstance instance);
47*8975f5c5SAndroid Build Coastguard Worker```
48*8975f5c5SAndroid Build Coastguard Worker
49*8975f5c5SAndroid Build Coastguard WorkerThis function will load all required Vulkan entrypoints, including all extensions; you can use Vulkan from here on as usual.
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard Worker## Optimizing device calls
52*8975f5c5SAndroid Build Coastguard Worker
53*8975f5c5SAndroid Build Coastguard WorkerIf you use volk as described in the previous section, all device-related function calls, such as `vkCmdDraw`, will go through Vulkan loader dispatch code.
54*8975f5c5SAndroid Build Coastguard WorkerThis allows you to transparently support multiple VkDevice objects in the same application, but comes at a price of dispatch overhead which can be as high as 7% depending on the driver and application.
55*8975f5c5SAndroid Build Coastguard Worker
56*8975f5c5SAndroid Build Coastguard WorkerTo avoid this, you have one of two options:
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker1. For applications that use just one VkDevice object, load device-related Vulkan entrypoints directly from the driver with this function:
59*8975f5c5SAndroid Build Coastguard Worker
60*8975f5c5SAndroid Build Coastguard Worker```c++
61*8975f5c5SAndroid Build Coastguard Workervoid volkLoadDevice(VkDevice device);
62*8975f5c5SAndroid Build Coastguard Worker```
63*8975f5c5SAndroid Build Coastguard Worker
64*8975f5c5SAndroid Build Coastguard Worker2. For applications that use multiple VkDevice objects, load device-related Vulkan entrypoints into a table:
65*8975f5c5SAndroid Build Coastguard Worker
66*8975f5c5SAndroid Build Coastguard Worker```c++
67*8975f5c5SAndroid Build Coastguard Workervoid volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device);
68*8975f5c5SAndroid Build Coastguard Worker```
69*8975f5c5SAndroid Build Coastguard Worker
70*8975f5c5SAndroid Build Coastguard WorkerThe second option requires you to change the application code to store one `VolkDeviceTable` per `VkDevice` and call functions from this table instead.
71*8975f5c5SAndroid Build Coastguard Worker
72*8975f5c5SAndroid Build Coastguard WorkerDevice entrypoints are loaded using `vkGetDeviceProcAddr`; when no layers are present, this commonly results in most function pointers pointing directly at the driver functions, minimizing the call overhead. When layers are loaded, the entrypoints will point at the implementations in the first applicable layer, so this is compatible with any layers including validation layers.
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Worker## CMake support
75*8975f5c5SAndroid Build Coastguard Worker
76*8975f5c5SAndroid Build Coastguard WorkerIf your project uses CMake, volk provides you with targets corresponding to the different use cases:
77*8975f5c5SAndroid Build Coastguard Worker
78*8975f5c5SAndroid Build Coastguard Worker1. Target `volk` is a static library. Any platform defines can be passed to the compiler by setting `VOLK_STATIC_DEFINES`. Example:
79*8975f5c5SAndroid Build Coastguard Worker```cmake
80*8975f5c5SAndroid Build Coastguard Workerif (WIN32)
81*8975f5c5SAndroid Build Coastguard Worker   set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
82*8975f5c5SAndroid Build Coastguard Workerelseif()
83*8975f5c5SAndroid Build Coastguard Worker   ...
84*8975f5c5SAndroid Build Coastguard Workerendif()
85*8975f5c5SAndroid Build Coastguard Workeradd_subdirectory(volk)
86*8975f5c5SAndroid Build Coastguard Workertarget_link_library(my_application PRIVATE volk)
87*8975f5c5SAndroid Build Coastguard Worker```
88*8975f5c5SAndroid Build Coastguard Worker2. Target `volk_headers` is an interface target for the header-only style. Example:
89*8975f5c5SAndroid Build Coastguard Worker```cmake
90*8975f5c5SAndroid Build Coastguard Workeradd_subdirectory(volk)
91*8975f5c5SAndroid Build Coastguard Workertarget_link_library(my_application PRIVATE volk_headers)
92*8975f5c5SAndroid Build Coastguard Worker```
93*8975f5c5SAndroid Build Coastguard Workerand in the code:
94*8975f5c5SAndroid Build Coastguard Worker```c
95*8975f5c5SAndroid Build Coastguard Worker/* ...any logic setting VK_USE_PLATFORM_WIN32_KHR and friends... */
96*8975f5c5SAndroid Build Coastguard Worker#define VOLK_IMPLEMENTATION
97*8975f5c5SAndroid Build Coastguard Worker#include "volk.h"
98*8975f5c5SAndroid Build Coastguard Worker```
99*8975f5c5SAndroid Build Coastguard Worker
100*8975f5c5SAndroid Build Coastguard WorkerThe above example use `add_subdirectory` to include volk into CMake's build tree. This is a good choice if you copy the volk files into your project tree or as a git submodule.
101*8975f5c5SAndroid Build Coastguard Worker
102*8975f5c5SAndroid Build Coastguard WorkerVolk also supports installation and config-file packages. Installation is disabled by default (so as to not pollute user projects with install rules), and can be disabled by passing `-DVOLK_INSTALL=ON` to CMake. Once installed, do something like `find_package(volk CONFIG REQUIRED)` in your project's CMakeLists.txt. The imported volk targets are called `volk::volk` and `volk::volk_headers`.
103*8975f5c5SAndroid Build Coastguard Worker
104*8975f5c5SAndroid Build Coastguard Worker## License
105*8975f5c5SAndroid Build Coastguard Worker
106*8975f5c5SAndroid Build Coastguard WorkerThis library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md).
107