Skip to content

kleopatra999/vulkan-cpp-library

 
 

Repository files navigation

vulkan-cpp

Vulkan abstraction library using C++11 for memory, resource management, type and thread safety as well as system independency. The goal is to be able to quickly write Vulkan code that is type safe, readable and clearly states its purpose, instead of being overwhelmed by pointer arithmetics, memory alignment and the "Vulkan/OpenGL" black screen of death.

Resource management

Buffer content is typed, referenced and revision counted. Push and specialization constants are typed. The library synchronizes your buffers between client and host lazily, layouts data according to std140, std430, interleaved or linear depending on your need.

vec3_array vertices;
vec3_array normals;
vec2_array texcoords;

buffer_type vertex_buffer(create(interleaved_std140, ...,
  std::ref(vertices), std::ref(texcoords), std::ref(normals)));

The above vertices, normals and texcoords can be updated at any time, using the following syntax:

mutated_vec3_array m = mutate(vertices);
m[0] = 1.f;

Submitting a command buffer which depend on the buffer will cause a flush of said buffer.

queue::submit(queue, {}, command_buffers, {});

The mutated_vec3_array is a movable only lock of the underlying array. The mutated_*_array provides a full std::vector like interface where *_array provides a read-only interface.

Because the data is strongly typed, there are a lot of opportunities for type checking, especially against SPIR-V. This is in the works!

Memory management

All Vulkan objects are encapsulated and hidden in C++ classes. These are movable only and destroy the underlying Vulkan objects when they go out of scope.

This makes memory management as easy as is expected with C++, simply move your object to a safe place and use std::ref whenever another object needs to keep a reference, or, move your object into a std::shared_ptr for reference counting. All functions that take a supplier<T> in this library will keep a reference to the object, where functions taking a reference will use the argument only for the scope of the function. supplier<T> has overloads for rvalue references (takes ownership), std::shared_ptr std::unique_ptr, std::reference_wrapper (std::ref) and function<T&()>.

Multithreading

The library is thread-safe as required by the Vulkan specification, 2.5 Threading Behavior, Externally Synchronized Parameters, Externally Synchronized Parameter Lists. Notice that Implicit Externally Synchronized Parameters is not included.

Android support.

In the works.

Xlib/xcb

In the works.

Install

Visual Studio 2015

Only 2015 is supported. The C++11 support in previous versions is not sufficient.

  • Open the vulkan-cpp.sln,
  • click "Property Manager" (next to "Solution Explorer", bottom left corner),
  • Expand any of the projects and configurations,
  • right-click on Microsoft.Cpp.Win32.user or Microsoft.Cpp.x64.user and select properties.
  • Under Common Properties > User Macros,
  • edit the VulkanSdk, GoogleTestDir, PngDir, GlmDir and GliDir to point to the locations of the respective libraries.
  • The project should now compile. Win32 and x64 in Release and Debug configurations are setup.

Acknowledgements

This is not an official Google product. This is purely a project made by a Google employee.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 54.3%
  • C 43.9%
  • GLSL 1.8%