Implementing staging buffers
Vulkan device-local buffers are often not visible from the host, meaning we can upload data into them only through various CPU-GPU-CPU transfer operations. In Vulkan, this is achieved by creating an auxiliary buffer, known as a staging buffer, which is CPU-visible (host-visible). We upload data into this staging buffer from the host and then issue GPU commands to copy the data from the staging buffer into a device-local buffer. Let’s learn how to implement this technique in Vulkan.
Getting ready…
Before reading any further, check out the previous recipe Dealing with buffers in Vulkan to learn how to create different types of Vulkan buffers.
How to do it…
As usual, let’s start with the high-level interface of LightweightVK and then dive deep into the implementation. The interface class IContext
, declared in lightweightvk/lvk/LVK.h
, exposes the following virtual methods to operate on buffers.
class IContext...