Handmade Rust Part 4: Generating Vulkan bindings

May 4, 2019

#Rust #Programming #Vulkan

Vulkan is a C API so we’ll need some kind of bindings to be able to use it in Rust. The API is defined in a XML file distributed by Khronos. This file describes the structs, enums, constants, and functions for each version of the API, and all published extensions. The functions can then be loaded from the Vulkan dynamic library and other functions from the API.

Read more…

Handmade Rust Part 3: Containers

March 23, 2019

#Rust #Programming

The most commonly used kinds of containers are arrays and maps. Pretty much any other container type can be built using those two, so that’s what we’ll build today!

The Rust standard library has Vec which is a dynamic array and HashMap and BTreeMap which are two kind of maps, the first one relying on the key being hashable, and the second one relying on the key being sortable.

The hash map has the cost of hashing the key but then lookup is constant time (in theory at least), whereas the ordered map only compares the keys, but lookup is logarithmic time. I chose to implement a hash map because it’s the one I find myself using most of the time, but ordered map are interesting as well.

Of course, just like for Unq, we won’t be making simple replacements, instead we’ll be making the most minimal containers necessary for now and add features later as needed, but we’ll be make them allocator aware.

As always, full source code is available at github.com/stevenlr/HandmadeRust.

Read more…

Handmade Rust Part 2: Unq, an allocator-aware Box

February 11, 2019

#Rust #Programming

In the Rust standard library, Box is a RAII wrapper for an object on the heap. It’s actually a special type that’s not implemented purely in the library, but also use special features called lang items. It uses the global allocator to allocate its memory. We want a similar type that also has an allocator associated to it. We’ll call it Unq, which mirror C++’s unique_ptr.

Read more…

Handmade Rust Part 1: Introduction & Allocators

February 10, 2019

#Rust #Programming

Welcome to Handmade Rust, a series (hopefully) where I will be developing a Vulkan rendering engine in Rust the Handmade way. By this, I mean using no external libraries, not even the Rust standard library, only the core lib. I am doing this mainly for my own enjoyment but also because I want to get better at writing Rust, and sometimes the best way to really understand something is to just do it yourself. The project will be available on GitHub at stevenlr/HandmadeRust.

Read more…