All Projects → vcoda → magma

vcoda / magma

Licence: GPL-3.0 license
Abstraction layer to facilitate usage of Khronos Vulkan API

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to magma

Kazan
Mirror; Work-in-progress software-rendering Vulkan implementation
Stars: ✭ 226 (+882.61%)
Mutual labels:  vulkan, vulkan-api
framework
The exomia/framework is used for building 2D and 3D games and more inspired by the XNA/Mono framework.
Stars: ✭ 21 (-8.7%)
Mutual labels:  vulkan, vulkan-api
Lugdunum
[UNMAINTAINED] A modern cross-platform 3D engine built with Vulkan, glTF 2.0 and modern C++14.
Stars: ✭ 230 (+900%)
Mutual labels:  vulkan, vulkan-api
Vulkan
Vulkan module for Jai
Stars: ✭ 23 (+0%)
Mutual labels:  vulkan, vulkan-api
Vulkan.NET
This repository contains low-level bindings for Vulkan used in Evergine.
Stars: ✭ 119 (+417.39%)
Mutual labels:  vulkan, vulkan-api
Vulkan Renderer
A new 3D game engine using modern C++ and Vulkan API
Stars: ✭ 205 (+791.3%)
Mutual labels:  vulkan, vulkan-api
Vulkano
Safe and rich Rust wrapper around the Vulkan API
Stars: ✭ 2,950 (+12726.09%)
Mutual labels:  vulkan, vulkan-api
Gapid
GAPID is a collection of tools that allows you to inspect, tweak and replay calls from an application to a graphics driver.
Stars: ✭ 1,975 (+8486.96%)
Mutual labels:  vulkan, vulkan-api
RTX-Mesh-Shaders
Different mesh shading techniques using the NVIDIA RTX (Turing) technology.
Stars: ✭ 84 (+265.22%)
Mutual labels:  vulkan, vulkan-api
vkel
Simple Dynamic Vulkan Extension Loader
Stars: ✭ 39 (+69.57%)
Mutual labels:  vulkan, vulkan-api
The Forge
The Forge Cross-Platform Rendering Framework PC Windows, Linux, Ray Tracing, macOS / iOS, Android, XBOX, PS4, PS5, Switch, Quest 2
Stars: ✭ 2,710 (+11682.61%)
Mutual labels:  vulkan, vulkan-api
racket-vulkan
Racket integration with all things Vulkan 💥
Stars: ✭ 40 (+73.91%)
Mutual labels:  vulkan, vulkan-api
Awesome Vulkan
Awesome Vulkan ecosystem
Stars: ✭ 2,322 (+9995.65%)
Mutual labels:  vulkan, vulkan-api
Yave
Yet Another Vulkan Engine
Stars: ✭ 211 (+817.39%)
Mutual labels:  vulkan, vulkan-api
Clvk
Experimental implementation of OpenCL on Vulkan
Stars: ✭ 158 (+586.96%)
Mutual labels:  vulkan, vulkan-api
Wolf.engine
The Wolf is a comprehensive set of C/C++ open source libraries for realtime rendering, realtime streaming and game developing
Stars: ✭ 230 (+900%)
Mutual labels:  vulkan, vulkan-api
Diligentsamples
Sample projects demonstrating the usage of Diligent Engine
Stars: ✭ 138 (+500%)
Mutual labels:  vulkan, vulkan-api
Simple vulkan synchronization
A single-header library with a simplified interface for Vulkan synchronization
Stars: ✭ 153 (+565.22%)
Mutual labels:  vulkan, vulkan-api
clustered forward demo vk
Clustered forward rendering demo with Vulkan
Stars: ✭ 50 (+117.39%)
Mutual labels:  vulkan, vulkan-api
Vortice.Vulkan
Cross platform .NET bindings for Vulkan, VMA, SPIRV-Cross and shaderc
Stars: ✭ 172 (+647.83%)
Mutual labels:  vulkan, vulkan-api

Abstraction layer to facilitate usage of Khronos Vulkan API

Problem

Writing rendering stuff in Vulkan requires a lot of boilerplate code, unlike OpenGL and Direct3D 9. This is the cost we pay for low-level and high-performant API, where we can control a lot of things that previously only graphics driver was responsible for. Vulkan has very verbose interface where you have to initialize a lot of structures to get things work. This complicates fast prototyping, makes your program error prone and hard to read and understand.

Solutions

There are a lot of different C++ bindings, developed to simplify usage of Vulkan, including:

and many others, but I've found that no one suitable for my purposes, because their implementations are different from my vision how such wrapper should be implemented and used. So eventually I decided to write my own.

Design

Magma is all about initialization. It was designed with simplicity of object construction in mind. Initialization exploit C++ RAII idiom with constructor overloading and default parameters that can be omitted. Also library has a lot of pre-defined state objects, so developer can use them without initialization of custom states. With this approach construction of the most complex Vulkan object - VkPipeline - takes only a dozen lines of code.

All objects are inherited from two types: Dispatchable and NonDispatchable, according to API specification. These types in turn are inherited from base Object class. Render state objects are simply structures that inherited from Vulkan structures and has plenty of constructors to conveniently initialize state description. They don't have any additional members, so user can safely cast an array of state objects to an array of Vulkan structures. All state objects have ::hash() method, which can be used to quickly lookup similar pipeline states in the cache instead of creating a new one.

The library was designed with zero or almost zero overhead in mind. While C++ exceptions are heavily used during object construction time, there are numerous methods marked with "noexcept" specifier. Consider, for example, VkCommandBuffer object:

  • Most of wrapper's methods don't throw any exceptions.
  • Parameters like shared pointers are passed by reference, so there is no reference counter increment/decrement.
  • Thin methods around API calls are made inline.

Command buffer's calls in release build should be as much efficient as native C API calls.

Predefined render states are usually "constexpr" objects, which means that they are initialized at compile-time (not run-time), mapping efficiently to low-level API.

The library often allocates temporary arrays on the stack instead of creating them in the heap. This may cause stack overflow in abuse cases, but speeds up allocations and reduces memory fragmentation in run-time.

Reflection

Defining descriptor set layouts usually the most complicated part of Vulkan API and often results in a lot of entagled code. From conceptual point of view, it should be done using reflection between C++ and GLSL code. Reflection is a mechanism making it possible to investigate yourself. In programming languages, reflection is used to investigate format of objects at runtime, invoke methods and access fields of these objects. While C++ doesn't support true reflection, Magma is trying to mimic it using variadics and SPIR-V reflection data. This allows to define descriptor set layouts as regular C++ structures and check their validity against specific shader bytecode. At run-time, you can assign resources (images, buffers, uniforms) to descriptor bindings and they will be attached to shader when descriptor set is binded using command buffer.

Memory management

While it is legal to create buffers and images without custom memory allocator, it is highly encouraging to provide host and device memory allocators during resource creation. Keep in mind that there is an implementation-dependent limit of a number of memory allocations reported by VkPhysicalDeviceLimits::maxMemoryAllocationCount, so per-object allocation approach suitable only for a small graphics applications. Custom allocator allows sub-allocations from larger memory chunks and reduces memory fragmentation in dynamic scenarios. Magma provides IDeviceMemoryAllocator interface that allows you to implement your own allocator or you can use a default one which is written on top of Vulkan Memory Allocator. Usually "allocator" parameter is the first among default parameters passed in the constructor which simplifies construction expressions.

Features

Magma was written mainly around Vulkan 1.0 specification, but has built-in support for some extensions, like NVidia ray-tracing, fill rectangle primitive and some other minor extensions. There are a lot of mobile hardware that support only Vulkan 1.0, so it is better to have a wider range of compatible hardware rather than a questionable features. Support for new API versions (1.1 and beyond) still not implemented.

Auxiliary

Magma provides some auxiliary objects that were written on top of core functionality. Their goals are to facilitate development by providing typical operations used in 3D graphics. For example, sometimes I miss immediate mode from OpenGL 1.x era, where you can quickly draw a few primitives with glBegin/glEnd. Or often there is need to quickly present rendered image to the screen, or create shader from GLSL source instead of pre-compiled SPIR-V binary and so on. Auxiliary objects are placed in nested namespace and are not part of the Magma core.

Some auxiliary objects use built-in precompiled shaders. Hash of a bytecode of these shaders calculated in compile-time to reduce loading overhead.

Dependencies

There are dependencies from the following third party libraries:

  • shaderc - a collection of tools, libraries, and tests for Vulkan shader compilation.
  • SPIRV-Reflect - a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.
  • Vulkan Memory Allocator - Vulkan memory allocation library.

Library depends on STL and has not been designed to be used with custom containers. It doesn't use any file input/output.

Language

Code is written in modern C++11/14 and takes advantage of new language features.

Supported compilers:

  • MSC
  • GCC
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].