sawickiap / VkExtensionsFeaturesHelp

Small header-only C++ library that helps to initialize Vulkan instance and device object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vulkan Extensions & Features Help, or VkExtensionsFeaturesHelp, is a small, header-only, C++ library for developers who use Vulkan API. It helps to avoid boilerplate code while creating VkInstance and VkDevice object by providing a convenient way to query and then enable:

  • instance layers
  • instance extensions
  • instance feature structures
  • device features
  • device extensions
  • device feature structures

The library provides a domain-specific language to describe the list of required or supported extensions, features, and layers. The language is fully defined in terms of preprocessor macros, so no custom build step is needed.

Author: Adam Sawicki - https://asawicki.info
Version: 1.1.0, 2021-04-08
License: MIT (see file: LICENSE)

Documentation

Quick example

  • Copy file "VkExtensionsFeaturesHelp.hpp" into your project and #include it.
  • Create file "VkExtensionsFeatures.inl" and put appropriate macros there to define device extensions and features your program supports, e.g.:
VKEFH_DEVICE_EXTENSION(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME)
VKEFH_DEVICE_FEATURE_STRUCT(VkPhysicalDeviceMemoryPriorityFeaturesEXT,
    VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT)
  • Use class VKEFH::DeviceInitHelp to conveniently create Vulkan device object:
VKEFH::DeviceInitHelp devInitHelp;
devInitHelp.GetPhysicalDeviceFeatures(physicalDevice);
devInitHelp.EnumerateExtensions(physicalDevice);

bool memoryPrioritySupported =
    devInitHelp.IsExtensionSupported(VK_EXT_MEMORY_PRIORITY_EXTENSION_NAME) &&
    devInitHelp.GetVkPhysicalDeviceMemoryPriorityFeaturesEXT().memoryPriority;

devInitHelp.PrepareCreation();

VkDeviceCreateInfo devCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
devCreateInfo.pNext = devInitHelp.GetFeaturesChain();
devCreateInfo.enabledExtensionCount = devInitHelp.GetEnabledExtensionCount();
devCreateInfo.ppEnabledExtensionNames = devInitHelp.GetEnabledExtensionNames();
devCreateInfo.queueCreateInfoCount = /* ... */;
devCreateInfo.pQueueCreateInfos = /* ... */;

VkDevice device = nullptr;
VkResult res = vkCreateDevice(physicalDevice, &devCreateInfo, nullptr, &device);

Example integration

To see example integration of this library and check how much it simplifies the code, visit following forked repositories:

About

Small header-only C++ library that helps to initialize Vulkan instance and device object

License:MIT License


Languages

Language:C++ 100.0%