Safe and rich Rust wrapper around the Vulkan API
Go to file
Lachlan Deakin 6981040486
Add partial support for khr_fragment_shading_rate (#2574)
* support `khr_fragment_shading_rate`

* Add taskgraph `set_fragment_shading_rate`

* Add `set_fragment_shading_rate` validation

* Cleanup `FragmentShadingRateState` validation

* Consolidate fragment_shading_rate validation

* Add docs for `fragment_shading_rate`

* Update vulkano-taskgraph/src/command_buffer/commands/dynamic_state.rs

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

* Format fragment_shading_rate validation messages

* Apply suggestions from code review

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>

---------

Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com>
2024-10-19 07:34:19 +02:00
.github Fix typos and introduce a workflow (#2537) 2024-06-30 13:19:35 +02:00
examples Revert #2425 (#2576) 2024-10-18 20:00:21 +02:00
vulkano Add partial support for khr_fragment_shading_rate (#2574) 2024-10-19 07:34:19 +02:00
vulkano-macros Use the now-stabilized pointer_bytes_offsets instead of what is technically UB and clean up the BufferContents derive macro expansion (#2563) 2024-09-12 10:27:00 +02:00
vulkano-shaders Fix rust-analyzer choking on &&[u32] in shader macro expansion 2024-08-26 20:34:19 +02:00
vulkano-taskgraph Add partial support for khr_fragment_shading_rate (#2574) 2024-10-19 07:34:19 +02:00
vulkano-util Add a transfer queue to VulkanoContext (#2573) 2024-10-15 20:42:15 +02:00
vulkano-win Use raw-window-metal to get a CAMetalLayer from raw-window-handle (#2561) 2024-09-11 18:03:54 +02:00
.gitattributes Mark generated files (#2542) 2024-09-12 10:45:11 +02:00
.gitignore Ignore the correct file #2451 creates (oops) 2024-03-04 20:37:12 +01:00
.rustfmt.toml Format code in doc comment code blocks (#2447) 2024-01-05 13:47:22 +01:00
.typos.toml Fix typos and introduce a workflow (#2537) 2024-06-30 13:19:35 +02:00
Cargo.lock Remove the gl-interop example from the workspace 2024-10-16 03:28:49 +02:00
Cargo.toml Remove the gl-interop example from the workspace 2024-10-16 03:28:49 +02:00
CHANGELOG.md #2425 changelog 2024-10-18 20:02:45 +02:00
COVERAGE.md #2486 changelog 2024-03-04 20:51:46 +01:00
DESIGN.md Fix and enforce line endings + stray whitespace (#1099) 2018-11-01 14:45:30 +11:00
LICENSE-APACHE Add license everywhere 2016-03-26 10:17:37 +01:00
LICENSE-MIT Add license everywhere 2016-03-26 10:17:37 +01:00
logo.png Add the logo to the README (#779) 2017-08-27 10:04:37 +02:00
README.md Use raw-window-metal to get a CAMetalLayer from raw-window-handle (#2561) 2024-09-11 18:03:54 +02:00
TROUBLES.md Add buffer_slice_field! macro 2016-05-02 11:18:26 +02:00

Vulkano

Build Status Discord Website/guide
vulkano crates.io vulkano-shaders crates.io vulkano-util crates.io vulkano-win crates.io
vulkano docs vulkano-shaders docs vulkano-util docs vulkano-win docs

Vulkano is a Rust wrapper around the Vulkan graphics API. It follows the Rust philosophy, which is that as long as you don't use unsafe code you shouldn't be able to trigger any undefined behavior. In the case of Vulkan, this means that non-unsafe code should always conform to valid API usage.

What does vulkano do?

  • Provides a low-levelish API around Vulkan. It doesn't hide what it does but provides some comfort types.
  • Plans to prevent all invalid API usages, even the most obscure ones. The purpose of Vulkano is not to simply let you draw a teapot, but to cover all possible usages of Vulkan and detect all the possible problems in order to write robust programs. Invalid API usage is prevented thanks to both compile-time checks and runtime checks.
  • Can handle synchronization on the GPU side for you (unless you choose to do that yourself), as this aspect of Vulkan is both annoying to handle and error-prone. Dependencies between submissions are automatically detected, and semaphores are managed automatically. The behavior of the library can be customized thanks to unsafe trait implementations.
  • Tries to be convenient to use. Nobody is going to use a library that requires you to browse the documentation for hours for every single operation.

Comparison

Comparison to other well-known Graphics APIs in Rust ecosystem.

Name Open-sourced Since API Level Notable Features
Vulkano March, 2016 High-level Rust API wrapping Vulkan APIs. Type-safe compile-time shaders. Transparent interoperability with glsl and spir-v shader code types in Rust code. Automatically generated types for shader's Layout.
Wgpu May, 2019 High-level Rust API with multiple backends. Supports multiple backends: Vulkan, Metal, DirectX, WebGPU, and other. Follows WebGPU specification. With async/await API.
Miniquad March, 2020 High-level minimalistic Rust API with multiple backends. Relatively minimalistic API well suited for small to medium graphics projects. Supports multiple backends, including browser target.
Sierra March, 2021 High-level Rust API for Vulkan/Metal APIs. Layouts, Descriptors and shader Types construction in Rust code through the macro system. Built on top of Erupt. Supports Ray Tracing Pipeline.
Glium October, 2014 High-level Rust API wrapping OpenGL OpenGL only.
Ash August, 2016 Low-level API for Vulkan. Unsafe Vulkan API bindings.
Erupt April, 2020 Low-level API for Vulkan. Unsafe Vulkan API bindings.

Please note that by the current date none of the known projects in the ecosystem(including Vulkano) reached stable release versions and the final design goals, their APIs are changing from time to time in a breakable way too, and there could be bugs and unfinished features too.

However, most of the projects mentioned above are already established definitive structures, all feature breaking changes will likely be straightforward to fix in user code, and most of them are maintained. As such we can recommend using any of them in the 3rd party code. The choice depends on the end project's goals and requirements, and we recommend examining their actual set of features and API capabilities beforehand.

Projects using Vulkano

We started collecting this list just recently and it would be appreciated if you help us by contributing(opening a PR) into README.md.

Project Name Description
Basalt GUI framework for Desktop applications
Egui Winit Vulkano Vulkano integration with Egui
Ferret Doom-compatible game engine
Korangar A Vulkan based Ragnarok Online client
Krnl Safe, portable, high performance compute (GPGPU) kernels.
Sandbox 2D Pixel Physics Simulator
Steel The Steel Game Engine.
Vera Animation engine scripted in Rust.
VideowindoW Uses Vulkano under the hood to enable asynchronous video stream compositing

We would love to help you keep your project in sync with the most recent changes in Vulkano if you give us feedback by adding your project to this list.

Thanks in advance!

Documentation and Resources

To get started you are encouraged to use the following resources:

  • The examples folder in this repository.
  • docs.rs - Full Vulkano API documentation
  • The guide on vulkano.rs - Starts with trivial compute examples (~50 lines of code) and then works up to rendering triangles and mandelbrots. The guide is currently outdated a little. We are planning to update it in the future, but it's a good place to start understanding the base building blocks of Vulkano API.
  • GitHub Issues - Raise a topic, ask a question or report a bug. The new topics there are watched regularly by maintainers and other community users.
  • Gitter Chat - Another place to raise a question. However, the chat is not maintained regularly at this moment. Better use GitHub Issues for this purpose.

Contributing

Contributions are very welcome! Feel free to submit pull requests, to open questions and topics in the Issues section.

The project was initially developed by Pierre Krieger(Tomaka), who established Vulkano's base design goals, and the code structure. In the meantime, development is driven by Vulkano community members.

New Pull Requests are usually scheduled for review by the end of each week. The older PRs that are already in review have priority over the new ones. We are trying to push development forward as quick as possible, but the review process sometimes takes time, please be patient as the maintainers need time to check everything properly.

If something needs to get promoted urgently, please ping current Vulkano maintainer(@Eliah-Lakhin) in the PR's or Issue's comments.

If your change adds, removes or modifies a trait or a function, please specify changelog entries in the Pull Request description(not in the changelog file directly). They will be transferred to the changelog right after the PR merge.

Every PR must pass tests in order to be merged to master.

Minor releases are usually happening between 1 to 3 months averagely depending on grow of unreleased and breaking changes in master

Repository Structure

This repository contains four libraries:

  • vulkano is the main one.
  • vulkano-shaders provides the shader! macro for compiling glsl shaders.
  • vulkano-util provides a variety of utility functions to streamline certain common operations such as device and swapchain creation.
  • vulkano-win provides a safe link between vulkano and the winit library which can create a window to render to.

In order to run tests, run cargo test --all at the root of the repository. Make sure your Vulkan driver is up to date before doing so.

Hall of Fame

We would love to mention some members, who put significant contributions to this project:

  • Pierre Krieger. The initial developer. Patreon page.
  • Lucas Kent. Maintainer. Patreon page.
  • Austin Johnson. Maintainer. Patreon page.
  • Rua. An active developer, who put a lot of effort to improve Vulkano and constantly keeping it up to date.
  • You! Thanks to your help, contributions, improvements, bug reports and user experience to make this project one of the major Rust graphics API library in Rust!

Setup and Troubleshooting

Vulkano uses shaderc-rs for shader compilation. Refer to shaderc-rs documentation to provide a pre-built libshaderc for faster build times.

Note that in general vulkano does not require you to install the official Vulkan SDK. This is not something specific to vulkano (you don't need the SDK to write programs that use Vulkan, even without vulkano), but many people are unaware of that and install the SDK thinking that it is required. However, macOS, iOS and tvOS platforms do require a little more Vulkan setup since it is not natively supported. See below for more details.

Unless you provide libshaderc, in order to build libshaderc with the shaderc-sys crate, the following tools must be installed and available on PATH:

  • CMake
  • Ninja Is optional except when building with MSVC. It may speed up build time for libshaderc.
  • Python (works with both Python 2.x and 3.x, on windows the executable must be named python.exe)

These requirements can be either installed with your favourite package manager or with installers from the projects' websites. Below are some examples of ways to set up.

windows-msvc Specific Setup

  1. rustup default stable-x86_64-pc-windows-msvc
  2. Install Build Tools for Visual Studio 2017. If you have already been using this toolchain then its probably already installed.
  3. Install msys2, following ALL of the instructions.
  4. Then in the msys2 terminal run: pacman --noconfirm -Syu mingw-w64-x86_64-cmake mingw-w64-x86_64-python2 mingw-w64-x86_64-ninja
  5. Add the msys2 mingw64 binary path to the PATH environment variable.

Windows-gnu Specific Setup

windows-gnu toolchain is not supported but you can instead cross-compile to windows-gnu from windows-msvc

Steps 1 and 2 are to workaround https://github.com/rust-lang/rust/issues/49078 by using the same mingw that rust uses.

  1. Download and extract https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/x86_64-6.3.0-release-posix-seh-rt_v5-rev2.7z
  2. Add the absolute path to mingw64\bin to your PATH environment variable. (This path needs to be before the msys2 path)
  3. Run the command: rustup default stable-x86_64-pc-windows-msvc
  4. Run the command: rustup target install x86_64-pc-windows-gnu
  5. Install Build Tools for Visual Studio 2017. If you have already been using this toolchain then it's probably already installed.
  6. Install msys2, following ALL of the instructions.
  7. Then in the msys2 terminal run: pacman --noconfirm -Syu mingw64/mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-make mingw-w64-x86_64-python2 mingw-w64-x86_64-ninja
  8. Add the msys2 mingw64 binary path to the PATH environment variable.
  9. Any cargo command that builds the project needs to include --target x86_64-pc-windows-gnu e.g. to run: cargo run --target x86_64-pc-windows-gnu

Linux Specific Setup

Use your package manager to install the required dev-tools and Vulkan drivers

For example on ubuntu:

sudo apt-get install build-essential git python cmake libvulkan-dev vulkan-tools

On arch based system

sudo pacman -Sy base-devel git python cmake vulkan-devel --noconfirm

macOS, iOS and tvOS Specific Setup

Vulkan is not natively supported by macOS, iOS and tvOS. However, there exists MoltenVK an open-source Vulkan implementation on top of Apple's Metal API. This allows vulkano to build and run on macOS, iOS and tvOS platforms.

The easiest way to get vulkano up and running with MoltenVK is to install the Vulkan SDK for macOS. There are installation instructions on the LunarG website.

On iOS and tvOS, vulkano links directly to the MoltenVK framework. There is nothing else to do besides installing it. Note that the Vulkan SDK for macOS also comes with the framework for iOS and tvOS.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.