Drawing cube using gfx-hal

· 3mins

Lines before <!--more--> or first 70 characters acts as page summary that will be shown in the posts list in home page.

This blog is a Work in Progress. As I complete learning few things one by one, I will update the doc accordingly.
⚠️  For now, read it at your own risk!!!

I have found that learning new things every often, leads to chaos, and people (specifically ME) tend to forget many things they have already learnt before.


These notes will help me to keep reference notes for myself, as well as for anybody who is willing to learn Vulkan API using gfx-hal.

Do note that gfx-hal provides it’s own API, which is very similar to Vulkans’, but is not purely Vulkan. If you are very much interested in understanding pure Vulkan API using Rust, I would recommend taking a look into:

For MaikKlein/ash though, you can find a very good tutorial, I still prefer gfx-rs (I call it gfx-hal just to ensure that it’s a very low level API, providing us just Hardware Abstraction Layer), because gfx-hal is cross-platform and have the best in class support for DX-12, Vulkan and Metal.


Learning rust language and vulkan APIs, both are very difficult for starters. I am still struggling to understand the basics, let aside writing proper Memory Management and Performance optimized Rust Code. Reading these notes requires prior knowledge of at-least one statically typed language (like java, C etc.), and some understanding of graphics, though even I am very new to Graphics Programming, so even for me many concepts are very new, and I will try to either explain them as much as I could, or better point you to some reference to take a look into and understand it better.


Special Thanks to:

  • @lokathor, for writing an open book on learning basics of using gfx-hal, though with very old gfx-hal version, but it still guided me a lot. You can read it here.
  • @mistodon, for writing such a good blog on gfx-hal and vulkan, which you can read here.
  • gfx-rs examples, are great to take a look into for basics. Most of my code is inspired from those examples, but since there was no way of understanding those examples without other references, you might see some changes.
  • LunarG Vulkan Tutorial
  • Special Mentions, (most of them I haven’t read completely, but will help me later for reference):

Before moving forward, I would like to clear some basics on Rust and Cargo. Follow <Link href={rustArchiveRecord[‘rust-cargo-basics’].link}>this guide, if you want to clear some basics on the same.


Table of Contents

Draw a Cube

export const displayWindow = halArchiveRecord[‘display-window’]; export const devices = halArchiveRecord[‘physical-logical-devices’]; export const swapChain = halArchiveRecord[‘swap-chain’];

export const commandBuffers = halArchiveRecord[‘command-buffers’]; export const shaders = halArchiveRecord[‘shaders’];

  • {displayWindow.title}
  • {devices.title}
  • {swapChain.title}