Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
gardell Merge pull request #26 from gardell/master
Only destroy descriptor_set if owned descriptor_pool allows it.
Latest commit 82314d7 Jan 31, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
gradle/wrapper CMake project setup. Linux support. Crash fixes. Dec 8, 2016
sample Removed pre/post_draw_commands from vcc::window. Jan 31, 2017
spirv-reflection-test
spirv-reflection CMake project setup. Linux support. Crash fixes. Dec 8, 2016
textures Heightmap demo with tessellation shader. Jan 1, 2017
tools
types-test
types
vcc-image
vcc-test Rewritten memory layout code. Jan 9, 2017
vcc Only destroy descriptor_set if owned descriptor_pool allows it. Jan 31, 2017
.gitignore
CMakeLists.txt Removed VCC_XCB_SINGLE_THREAD_DRAWING Jan 4, 2017
CMakeLists.txt.freeglut.in
CMakeLists.txt.gli.in
CMakeLists.txt.glm.in
CMakeLists.txt.glslang.in CMake project setup. Linux support. Crash fixes. Dec 8, 2016
CMakeLists.txt.googletest.in CMake project setup. Linux support. Crash fixes. Dec 8, 2016
CMakeLists.txt.openvr.in CMake project setup. Linux support. Crash fixes. Dec 8, 2016
CMakeLists.txt.png.in
CMakeLists.txt.spirv-headers.in
CMakeLists.txt.spirv-tools.in
CMakeLists.txt.zlib.in CMake project setup. Linux support. Crash fixes. Dec 8, 2016
CONTRIBUTING Initial commit. Apr 4, 2016
LICENSE Initial commit. Apr 4, 2016
README.md README.md: Android SDK api level 25. XCB multithread issues fixed. Jan 25, 2017
build.gradle CMake project setup. Linux support. Crash fixes. Dec 8, 2016
gradle.properties
gradlew CMake project setup. Linux support. Crash fixes. Dec 8, 2016
gradlew.bat Initial Android support. May 23, 2016
settings.gradle

README.md

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 read or written to at any time, using the following syntax:

readable_vec3_array r = read(vertices);
// read r[0]

writable_vec3_array m = write(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, {});

Locking the array with the writable_*_array types will increase its reference count when it goes out of scope. Locking the array with readable_*_array makes sure no concurrent read/write occurs. The writable_*_array provides a full std::vector like interface where readable_*_array provides a read-only const std::vector like interface.

Custom types are supported too. The following GLSL definition

struct light_type {
  vec4 position;
  vec3 attenuation;
  vec3 spot_direction;
  float spot_cos_cutoff;
  vec4 ambient;
  vec4 diffuse;
  vec4 specular;
  float spot_exponent;
};

layout(std140, binding = 1) uniform lights {
        light_type lights[max_lights];
} lightsbuf;

can be matched with the following host/C++ code:

struct light_type {
  vec4 position;
  vec3 attenuation;
  vec3 spot_direction;
  float spot_cos_cutoff;
  vec4 ambient;
  vec4 diffuse;
  vec4 specular;
  float spot_exponent;

  VCC_STRUCT_SERIALIZABLE(position, attenuation, spot_direction,
    spot_cos_cutoff, ambient, diffuse, specular, spot_exponent);
};
t_array<light_type> lights(max_lights);

auto light_uniform_buffer(input_buffer::create<linear_std140>(
  std::ref(device), 0, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
  VK_SHARING_MODE_EXCLUSIVE, {}, std::ref(lights)));

See sample/lighting for an example.

Because the data is strongly typed, there are a lot of opportunities for type checking, especially against SPIR-V. This is in the works! The library includes the spirv-reflection project. It parses SPIR-V and extracts uniforms, inputs and outputs. The library will be used to do runtime validation on SPIR-V assembly against the C++ declared arrays. This is currently being worked on.

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.

OpenVR

Samples include an OpenVR example. This simple demo renders the models of the connected devices like trackers and controllers. It supports lazy loading and recompiles the command buffers when any new devices are added or removed. ##Install ###Linux/XCB cmake . downloads all the dependencies needed. cmake --build . compiles the libraries and samples. ###Android Install Android Studio and the NDK. SDK 25 is required. Import the root project directory. Initial building and synchronizing will take a very long time, as it will download the dependency projects needed.

Note: Textures are copied to the assets/ and res/ folders of the respective projects. However, *.spv compiled shaders are not generated. These must be copied to the assets/ folder. ###Visual Studio 2015 Only 2015 is supported. The C++11 support in previous versions is not sufficient. cmake -DVULKAN_SDK_DIR:PATH=<path-to-vulkan-sdk> . downloads all the dependencies and sets up the projects. Either use cmake --build . to compile or open the generated .sln.

Acknowledgements

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

You can’t perform that action at this time.