Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time
February 2, 2019 16:14
February 13, 2019 22:57
February 13, 2019 22:57
August 25, 2018 13:36
February 3, 2020 13:13
January 2, 2019 09:18


Rust version of using Vulkano.

Goal: Rust port with code structure as similar as possible to the original C++, so the original tutorial can easily be followed (similar to learn-opengl-rs).

Current State: The chapters Drawing a triangle and Vertex buffers are complete.


This tutorial consists of the the ported code and notes about the differences between the original C++ and the Rust code. The explanatory texts generally apply equally, although the Rust version is often shorter due to the use of Vulkano, a safe wrapper around the Vulkan API with some convenience functionality (the final triangle example is about 600 lines, compared to 950 lines in C++).

If you prefer a lower-level API closer to the Vulkan C API, have a look at Ash and vulkan-tutorial-rust.


(nothing to note here)

Development Environment

Download the Vulkan SDK as described, but ignore everything about library and project setup. Instead, create a new Cargo project:

$ cargo new vulkan-tutorial-rs

Then add this to your Cargo.toml:

vulkano = "0.11.1"

On macOS, copy, adapt the VULKAN_SDK path if necessary and source the file in your terminal. See also vulkano-rs/vulkano#macos-and-ios-specific-setup.

Drawing a triangle


Base code

General structure
extern crate vulkano;

struct HelloTriangleApplication {


impl HelloTriangleApplication {
    pub fn initialize() -> Self {
        Self {


    fn main_loop(&mut self) {


fn main() {
    let mut app = HelloTriangleApplication::initialize();
Resource management

Vulkano handles calling vkDestroyXXX/vkFreeXXX in the Drop implementation of all wrapper objects, so we will skip all cleanup code.

Integrating GLFW winit

Instead of GLFW we'll be using winit, an alternative window managment library written in pure Rust.

Add this to your Cargo.toml:

winit = "0.18.0"

And extend your

extern crate winit;

use winit::{EventsLoop, WindowBuilder, dpi::LogicalSize};

const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;

struct HelloTriangleApplication {
    events_loop: EventsLoop,
    pub fn initialize() -> Self {
        let events_loop = Self::init_window();

        Self {

    fn init_window() -> EventsLoop {
        let events_loop = EventsLoop::new();
        let _window = WindowBuilder::new()
            .with_dimensions(LogicalSize::new(f64::from(WIDTH), f64::from(HEIGHT)))
    fn main_loop(&mut self) {
        loop {
            let mut done = false;
            self.events_loop.poll_events(|ev| {
                if let Event::WindowEvent { event: WindowEvent::CloseRequested, .. } = ev {
                    done = true
            if done {

Complete code



vulkano-win = "0.11.1"

extern crate vulkano_win;
use std::sync::Arc;
use vulkano::instance::{
struct HelloTriangleApplication {
    instance: Option<Arc<Instance>>,
    events_loop: EventsLoop,
    pub fn initialize() -> Self {
        let instance = Self::create_instance();
        let events_loop = Self::init_window();

        Self {
    fn create_instance() -> Arc<Instance> {
        let supported_extensions = InstanceExtensions::supported_by_core()
            .expect("failed to retrieve supported extensions");
        println!("Supported extensions: {:?}", supported_extensions);

        let app_info = ApplicationInfo {
            application_name: Some("Hello Triangle".into()),
            application_version: Some(Version { major: 1, minor: 0, patch: 0 }),
            engine_name: Some("No Engine".into()),
            engine_version: Some(Version { major: 1, minor: 0, patch: 0 }),

        let required_extensions = vulkano_win::required_extensions();
        Instance::new(Some(&app_info), &required_extensions, None)
            .expect("failed to create Vulkan instance")

Diff / Complete code

Validation layers

From here on we'll just link to the code instead of putting everything in the README:

Diff / Complete code

Physical devices and queue families

Diff / Complete code

Logical device and queues

Diff / Complete code


Window surface

Diff / Complete code

Swap chain

Diff / Complete code

Image views

We're skipping this section because image views are handled by Vulkano and can be accessed via the SwapchainImages created in the last section.

Graphics pipeline basics


Diff / Complete code

Shader Modules

Instead of compiling the shaders to SPIR-V manually and loading them at runtime, we'll use vulkano_shaders to do the same at compile-time. Loading them at runtime is also possible, but a bit more invovled - see the runtime shader example of Vulkano.

Diff / Rust code / Vertex shader / Fragment shader

Fixed functions

Diff / Complete code

Render passes

Diff / Complete code


Diff / Complete code



Diff / Complete code

Command buffers

We're skipping the first part because Vulkano maintains a StandardCommandPool.

Diff / Complete code

Rendering and presentation

Diff / Complete code

Swapchain recreation

Diff / Complete code

Vertex buffers

Vertex input description

Vertex shader diff / Vertex shader

(Rust code combined with next section, since this alone won't compile)

Vertex buffer creation

Diff / Complete code

Staging buffer

We're just replacing CpuAccessibleBuffer with ImmutableBuffer, which uses a staging buffer internally. See vulkano::buffer for an overview of Vulkano's buffer types.

Diff / Complete code

Index buffer

Diff / Complete code

Uniform buffers

Uniform Buffer Object

In this section we change the vertex shader to take a uniform buffer object consisting of a model, view, and projection matrix. The shader now outputs the final position as the result of multiplying these three matrices with the original vertex position.

We add a new type of buffer, the CpuAccessibleBuffer, which allows us to update its contents without needing to rebuild the entire buffer. In order to actually be able to write to this buffer we need to specify its usage as a uniform buffer and also the destination of a memory transfer.

Note that unlike the original tutorial we did not need to create any layout binding. This is handled internally by vulkano when creating a descriptor set, as we'll see in the next section.

At this point our program will compile and run but immediately panic because we specify a binding in our shader but do not include a matching descriptor set.

Vertex Shader Diff / Vertex Shader

Diff / Complete code

Texture mapping (TODO)

Depth buffering (TODO)

Loading models (TODO)

Generating Mipmaps (TODO)

Multisampling (TODO)


No releases published


No packages published