Unarmed1000 / RapidVulkan

Low level C++11 RAII wrapper classes for the Vulkan API. The code is auto generated by RAIIGen.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RapidVulkan

Low level header only C++11 RAII wrapper classes for the Vulkan API. The RAII class design is heavily inspired by std::unique_ptr and is compatible with STL containers.

Technical overview

  • RAII classes with full move support, inspired by std::unique_ptr.
  • Header only C++11.
  • Compatible with STL containers.
  • Generated classes contains related vulkan functions in a C++ version.
  • Exception based error handling.
  • Easy to mix with normal vulkan code.
  • Low dependency design, include what you need.
  • The code is auto generated by RAIIGen.
  • Backwards compatible with old Vulkan SDK releases.

Examples

Creation of a temporary staging buffer

// Create a host-visible staging buffer that contains the raw image data
RapidVulkan::Buffer CreateStagingBuffer(const VkDevice device, const VkDeviceSize size)
{
  VkBufferCreateInfo bufferCreateInfo{};
  bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  bufferCreateInfo.pNext = nullptr;
  bufferCreateInfo.size = size;
  bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
  bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  return RapidVulkan::Buffer(device, bufferCreateInfo);
}

void Main()
{
  // ...

  { // Scope where we need a staging buffer
    RapidVulkan::Buffer stagingBuffer = CreateStagingBuffer(device, bufferSize);

    // Use the staging buffer

    // ...

    vkBindBufferMemory(device, stagingBuffer.Get(), stagingMemory, 0);

    // ...

  }  // The buffer goes out of scope here and is automatically freed

  // ...
}

Partial code for creating a Image and its memory

// ...

VkImageCreateInfo imageCreateInfo{};
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageCreateInfo.pNext = nullptr;
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
imageCreateInfo.format = format;
imageCreateInfo.mipLevels = 1;
imageCreateInfo.arrayLayers = textureArray.GetLayers();
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
imageCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imageCreateInfo.extent = texExtent;
imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
  
RapidVulkan::Image texImage(device, imageCreateInfo);
  
const auto memReqs = texImage.GetImageMemoryRequirements();
  
memAllocInfo.allocationSize = memReqs.size;
memAllocInfo.memoryTypeIndex = GetMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
  
RapidVulkan::Memory texMemory(device, memAllocInfo);
  
vkBindImageMemory(device, texImage.Get(), texMemory.Get(), 0);

// ...

Fence

RapidVulkan::Fence fence;

VkFenceCreateInfo fenceCreateInfo{};
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;

fence.Reset(device.Get(), fenceCreateInfo);

// ...

// device is a RapidVuilkan::Device
device.WaitForFences(1, fence.GetPointer(), VK_TRUE, UINT64_MAX);
device.ResetFences(1, fence.GetPointer());

Defines

Define Functionality
RAPIDVULKAN_DISABLE_PARAM_VALIDATION Disable input parameter validation
RAPIDVULKAN_DISABLE_UNROLLED_STRUCT_METHODS Disable the unrolled structs methods.
RAPIDVULKAN_DISABLE_ARRAY_METHODS Disable support for std::array. if RAPIDVULKAN_DISABLE_UNROLLED_STRUCT_METHODS is set array methods are also disabled.
RAPIDVULKAN_DISABLE_VECTOR_METHODS Disable support for std::vector. if RAPIDVULKAN_DISABLE_UNROLLED_STRUCT_METHODS is set vectory methods are also disabled
RAPIDVULKAN_ERRORFORMATTER_EXTERN Use an extern ErrorFormatter, which allows you to format the exception message to fit your framework. See ErrorFormatter.hpp

Porting

File Functionality
ErrorFormatter.hpp Controls how the VulkanErrorException message is formatted.
Log.hpp Logging macros, customize this to adapt the logging to your system.
Macro.hpp Customize a few compiler dependent macros to fit your build system for optimal performance.

About

Low level C++11 RAII wrapper classes for the Vulkan API. The code is auto generated by RAIIGen.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C++ 99.8%Language:CMake 0.2%