Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/volkPublic

Meta loader for Vulkan API

License

NotificationsYou must be signed in to change notification settings

zeux/volk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose

volk is a meta-loader for Vulkan. It allows you to dynamically load entrypoints required to use Vulkanwithout 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 loadingVulkan entrypoints directly from the driver which can increase performance by skipping loader dispatch overhead.

volk is written in C89 and supports Windows, Linux, Android and macOS (via MoltenVK).

Building

There are multiple ways to use volk in your project:

  1. You can addvolk.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 buildingvolk.c.
  2. You can use provided CMake files, with the usage detailed below.
  3. You can use volk in header-only fashion. Includevolk.h wherever you want to use Vulkan functions. In exactly one source file, defineVOLK_IMPLEMENTATION before includingvolk.h. Do not buildvolk.c at all in this case - however,volk.c must still be in the same directory asvolk.h. This method of integrating volk makes it possible to set the platform defines mentioned above with arbitrary (preprocessor) logic in your code.

Basic usage

To use volk, you have to includevolk.h instead ofvulkan/vulkan.h; this is necessary to use function definitions from volk.

If some files in your application includevulkan/vulkan.h and don't includevolk.h, this can result in symbol conflicts; consider definingVK_NO_PROTOTYPES when compiling code that uses Vulkan to make sure this doesn't happen. It's also important to make sure thatvulkan-1 is not linked into the application, as this results in symbol name conflicts as well.

To initialize volk, call this function first:

VkResultvolkInitialize();

This will attempt to load Vulkan loader from the system; if this function returnsVK_SUCCESS you can proceed to create Vulkan instance.If this function fails, this means Vulkan loader isn't installed on your system.

After creating the Vulkan instance using Vulkan API, call this function:

voidvolkLoadInstance(VkInstance instance);

This function will load all required Vulkan entrypoints, including all extensions; you can use Vulkan from here on as usual.

Optimizing device calls

If you use volk as described in the previous section, all device-related function calls, such asvkCmdDraw, will go through Vulkan loader dispatch code.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.

To avoid this, you have two options:

  1. For applications that use just one VkDevice object, load device-related Vulkan entrypoints directly from the driver with this function:
voidvolkLoadDevice(VkDevice device);
  1. For applications that use multiple VkDevice objects, load device-related Vulkan entrypoints into a table:
voidvolkLoadDeviceTable(structVolkDeviceTable* table, VkDevice device);

The second option requires you to change the application code to store oneVolkDeviceTable perVkDevice and call functions from this table instead.

Device entrypoints are loaded usingvkGetDeviceProcAddr; 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.

SincevolkLoadDevice overwrites some function pointers with device-specific versions, you can choose to usevolkLoadInstanceOnly instead ofvolkLoadInstance; when using table-based interface this can also help enforce the usage of the function tables asvolkLoadInstanceOnly will leave device-specific functions asNULL.

CMake support

If your project uses CMake, volk provides you with targets corresponding to the different use cases:

  1. Targetvolk is a static library. Any platform defines can be passed to the compiler by settingVOLK_STATIC_DEFINES. Example:
if (WIN32)   set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)elseif()   ...endif()add_subdirectory(volk)target_link_library(my_applicationPRIVATE volk)
  1. Targetvolk_headers is an interface target for the header-only style. Example:
add_subdirectory(volk)target_link_library(my_applicationPRIVATE volk_headers)

and in the code:

/* ...any logic setting VK_USE_PLATFORM_WIN32_KHR and friends... */#defineVOLK_IMPLEMENTATION#include"volk.h"

The above example useadd_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.

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 enabled by passing-DVOLK_INSTALL=ON to CMake. Once installed, do something likefind_package(volk CONFIG REQUIRED) in your project's CMakeLists.txt. The imported volk targets are calledvolk::volk andvolk::volk_headers.

License

This library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md).


[8]ページ先頭

©2009-2025 Movatter.jp