~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/ThirdParty/ANGLE/src/third_party/volk/README.md

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# 🐺 volk [![Build Status](https://travis-ci.org/zeux/volk.svg?branch=master)](https://travis-ci.org/zeux/volk)
 
2
 
 
3
## ANGLE Integration
 
4
 
 
5
Note that the entirety of the volk README.md is included below. This is an additional section with information
 
6
on volk's integration into ANGLE. The volk source files are copied directly from the volk GitHub repo.
 
7
To update volk in ANGLE, copy the latest volk.h/c files into ANGLE "src/third_party/volk" dir and push update.
 
8
If any changes are made to volk source files locally within ANGLE, please also make corresponding PRs so that
 
9
the changes land in the upstream source volk GitHub repo.
 
10
 
 
11
## Purpose
 
12
 
 
13
volk is a meta-loader for Vulkan. It allows you to dynamically load entrypoints required to use Vulkan
 
14
without 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
 
15
Vulkan entrypoints directly from the driver which can increase performance by skipping loader dispatch overhead.
 
16
 
 
17
volk is written in C89 and supports Windows, Linux, Android and macOS (via MoltenVK).
 
18
 
 
19
## Building
 
20
 
 
21
There are multiple ways to use volk in your project:
 
22
 
 
23
1. 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`.
 
24
2. 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.
 
25
3. You can use provided CMake files, with the usage detailed below.
 
26
 
 
27
## Basic usage
 
28
 
 
29
To use volk, you have to include `volk.h` instead of `vulkan/vulkan.h`; this is necessary to use function definitions from volk.
 
30
If 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.
 
31
 
 
32
To initialize volk, call this function first:
 
33
 
 
34
```c++
 
35
VkResult volkInitialize();
 
36
```
 
37
 
 
38
This will attempt to load Vulkan loader from the system; if this function returns `VK_SUCCESS` you can proceed to create Vulkan instance.
 
39
If this function fails, this means Vulkan loader isn't installed on your system.
 
40
 
 
41
After creating the Vulkan instance using Vulkan API, call this function:
 
42
 
 
43
```c++
 
44
void volkLoadInstance(VkInstance instance);
 
45
```
 
46
 
 
47
This function will load all required Vulkan entrypoints, including all extensions; you can use Vulkan from here on as usual.
 
48
 
 
49
## Optimizing device calls
 
50
 
 
51
If you use volk as described in the previous section, all device-related function calls, such as `vkCmdDraw`, will go through Vulkan loader dispatch code.
 
52
This 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.
 
53
 
 
54
To avoid this, you have one of two options:
 
55
 
 
56
1. For applications that use just one VkDevice object, load device-related Vulkan entrypoints directly from the driver with this function:
 
57
 
 
58
```c++
 
59
void volkLoadDevice(VkDevice device);
 
60
```
 
61
 
 
62
2. For applications that use multiple VkDevice objects, load device-related Vulkan entrypoints into a table:
 
63
 
 
64
```c++
 
65
void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device);
 
66
```
 
67
 
 
68
The second option requires you to change the application code to store one `VolkDeviceTable` per `VkDevice` and call functions from this table instead.
 
69
 
 
70
Device 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.
 
71
 
 
72
## CMake support
 
73
 
 
74
If your project uses CMake, volk provides you with targets corresponding to the different use cases:
 
75
 
 
76
1. Target `volk` is a static library. Any platform defines can be passed to the compiler by setting `VOLK_STATIC_DEFINES`. Example:
 
77
```cmake
 
78
if (WIN32)
 
79
   set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
 
80
elseif()
 
81
   ...
 
82
endif()
 
83
add_subdirectory(volk)
 
84
target_link_library(my_application PRIVATE volk)
 
85
```
 
86
2. Target `volk_headers` is an interface target for the header-only style. Example:
 
87
```cmake
 
88
add_subdirectory(volk)
 
89
target_link_library(my_application PRIVATE volk_headers)
 
90
```
 
91
and in the code:
 
92
```c
 
93
/* ...any logic setting VK_USE_PLATFORM_WIN32_KHR and friends... */
 
94
#define VOLK_IMPLEMENTATION
 
95
#include "volk.h"
 
96
```
 
97
 
 
98
The 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.
 
99
 
 
100
Volk 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`.
 
101
 
 
102
## License
 
103
 
 
104
This library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md).