A translation of Brendan Galea's Vulkan tutorial into Rust using the ash crate

Overview

Rust Light Vulkan Engine

This is a translation of Brendan Galea's Vulkan tutorial into rust using the Ash crate.

Original tutorial: Brendan Galea's YouTube Page

Each commit will correspond to a video from this tutorial.

Requirements

You will need to have the LunarG Vulkan SDK installed and on linux you will need to add the library and layers to your path.

Things to Note

  • Unlike the tutorial, this translation will use the winit window API as it is fully written in rust. This will result in some large deviations from the videos.
  • Due to the methodology of rust being incredibly different to that of C++, the structure of the code will be different in some areas. These changes will be highlighted with a hopefully correct :) explanation of why this is the case.
  • To get the most out of the tutorial, I recommend trying to follow along with the video and translate the code yourself and use this repository if you get stuck or want to copy large amounts of code (such as videos 3, 4, and 5).

To use the logging functionality in this code, you need to set the RUST_LOG environment variable:

Windows PowerShell

$env:RUST_LOG="debug"

Linux

RUST_LOG=vulkan_tutorial_ash=debug cargo run

More information about using this crate can be found in the documentation.

Acknowledgements

Big thanks to Brendan Galea for making the tutorial that this code is based on, and Alexander Overvoorde for making The Vulkan Tutorial that I first learnt Vulkan from. Also thanks to Adrien Ben for translating Alex's tutorial, a bunch of this code was yoinked from that repo :)

1: Opening a Window (link)

  • Later versions of winit (0.20+) use an architecture that is very different to glfw. Because of this the structure presented in the tutorial will not work, or will be very weird to implement. As such, there is no lve_window struct and ownership of the window has been moved to the application (first_app).

2: Graphics Pipeline Overview (link)

  • A build.rs file was added to compile the shader files when the program is built. This is just a replacement for the shell script presented in the video.
  • "We're about half way to seeing our first triangle on screen"... I've never heard a more blatant lie.

3: Device Setup & Pipeline cont. (link)

  • Due to the nature of Rust, a lot of the functions that were void in the tutorial now return things. This is so we can properly initialise the LveDevice struct by allowing the functions to borrow these Vulkan structs.
  • device_extensions does is not a global constant anymore as ash requires the extension names to be given by a functions, and hence can't be stored in a constant. It can now be found in the LveDevice::get_device_extensions() function.
  • Due to the lack of lve_window module, it was more convenient to use the create_surface() function from the ash-window crate in the LveDevice::create_surface() function. The naming here is a little confusing, sorry about that.
  • You will also note that ash has two surface types, Surface and vk::SurfaceKHR. The former is a struct containing the functions that act on the surface, while the latter is the Vulkan surface itself.
  • The biggest deviation in this code is the fact that the lve_device now owns the pipeline instead of the application owning both. In the tutorial, Brendan says that having a reference to the device in the pipeline can be unsafe as the device needs to be destroyed after the pipeline. In Rust, if it can be unsafe it won't compile, so some restructuring had to be done.

new structure

  • Overall, the way that extensions are handled in this implementation are slightly different so don't expect the exact same console output as the one shown in the video.

4: Fixed Function Pipeline Stages (link)

  • Some pipeline builder functions were commented out as they were optional and required null pointers, something I'm not sure is implemented in rust.
  • Pipeline destructor function was already implemented in the previous commit
You might also like...
Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

Community SVD file, peripheral access crate in embedde Rust for WinnerMicro W800, W801 & W806 chip

A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.
A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.

rs-cord A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use. Documentation • Crates.io • Discord Navigation M

A Rust proc-macro crate which derives functions to compile and parse back enums and structs to and from a bytecode representation

Bytecode A simple way to derive bytecode for you Enums and Structs. What is this This is a crate that provides a proc macro which will derive bytecode

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

An `abilists` parser crate for Rust

An `abilists` parser crate for Rust

A Rust crate to expressively declare bitfield-like structs

proc-bitfield A Rust crate to expressively declare bitfield-like structs, automatically ensuring their correctness at compile time and declaring acces

This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you specified.

prae This crate provides a convenient macro that allows you to generate type wrappers that promise to always uphold arbitrary invariants that you spec

This crate defines a single macro that is a brainfunct compile-time interpreter.

Compile Protection This crate defines a single macro that is a brainfunct compile-time interpreter. One example is as follows #![recursion_limit = "18

Comments
  • Performance

    Performance

    i use your code from this commit c907711f7a703745efedc4e8640956a3a98d9312 and added fps counter and I was getting about 2600 fps but i was getting about 5400 fps with gfx-hal. i am currently working on a game engine with wgpu-hal as backend and with some multithreading i was able to get more than 7500 fps my application was drawing a simple red triangle with multisampling and depth testing enable backend was set to vulkan when testing

    opened by ghost 1
Owner
Mot
Mot
The working code for my Safe Pay app - check out my tutorial!

Safe Pay Tutorial This repository contains the source code for my blog post Using PDAs and SPL Token in Anchor. The code contains the following: Solan

Daniel Pyrathon 39 Aug 28, 2022
📦 Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate.

?? Crate Protocol Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate. A Crate is alw

Crate Protocol 63 Oct 31, 2022
Chains - a bot written in Rust using the serenity crate

Chains (Rusty) Chains is a bot written in Rust using the serenity crate. Chains primarily focuses on easy to set up, easy to use moderation tools such

Quin 3 Mar 28, 2022
A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

William 19 Nov 29, 2022
Simplistic complier~virtual-machine that transforms AST into a Rust function, with basic type checking

rast-jit-vm rast-jit-vm is a simplistic, proof-of-concept~ish compiler / virtual machine that transforms syntax tree into a Rust function, type-checki

Patryk Wychowaniec 4 Oct 23, 2022
Telegram bot to fetch images from Terceira Ponte and Rodosol into your Telegram chat.

rodosol-telegram-bot Add this bot to your contacts list This bot is a quick scraper that gets the pictures from the rodosol "De olho na via" feature a

Armando Magalhães 1 Jan 9, 2022
Meet Rustacean GPT, an experimental project transforming OpenAi's GPT into a helpful, autonomous software engineer to support senior developers and simplify coding life! 🚀🤖🧠

Rustacean GPT Welcome, fellow coding enthusiasts! ?? ?? I am excited to introduce you to Rustacean GPT, my humble yet ambitious project that aims to t

Gary McDougall 3 May 10, 2023
Rust crate for parsing stivale and stivale 2 structures.

stivale-rs Rust crate for parsing stivale and stivale 2 structures. Resources Stivale v2 Specification Stivale Specification License Licensed under ei

Anhad Singh 12 Dec 20, 2022
A simple entity-component-system crate for rust with serialization support

Gallium A simple entity-component-system crate for rust with serialization support Usage You can include the library using carge: [dependencies] galli

null 7 Aug 31, 2021
Rust crate to generate, manipulate and traverse trees.

SOCAREL Rust crate to generate, manipulate and traverse trees. It provides iterators for eight different traversal algorithms. Add and remove nodes in

Andreu 8 Nov 14, 2021