Last updated: 2026-09-07
Vulkan Runtime
Vulkan Buffer
Allocate Vulkan buffers used by weights, intermediates, and staging copies.
These helpers centralize buffer creation, memory mapping, and one-shot copy utilities so the rest of the runtime can work with higher-level abstractions.
2 exports shown
struct
Buffer
pub const Buffer = struct Vulkan buffer allocation paired with its device memory and optional mapped pointer.
Methods
6method
Buffer.init
pub fn init( instance: *const Instance, size: vk.c.VkDeviceSize, usage: vk.c.VkBufferUsageFlags, mem_properties: vk.c.VkMemoryPropertyFlags, ) !Buffer Create a Vulkan buffer and allocate backing device memory for it.
method
Buffer.initDeviceLocal
pub fn initDeviceLocal(instance: *const Instance, size: vk.c.VkDeviceSize, usage: vk.c.VkBufferUsageFlags) !Buffer Create a device-local buffer for GPU-only reads and writes.
method
Buffer.initStaging
pub fn initStaging(instance: *const Instance, size: vk.c.VkDeviceSize) !Buffer Create and immediately map a host-visible staging buffer.
method
Buffer.initHostVisibleStorage
pub fn initHostVisibleStorage(instance: *const Instance, size: vk.c.VkDeviceSize) !Buffer Create a host-visible storage buffer that the GPU reads in place via PCIe.
it over PCIe BAR rather than from device-local VRAM. Used to offload large rarely-touched tensors (MoE expert weights) when device memory is insufficient. Coherent memory means no explicit invalidate is needed; we only write at load time.
method
Buffer.upload
pub fn upload(self: *const Buffer, data: []const u8) void Copy raw bytes into a previously mapped buffer (staging or host-visible storage).
method
Buffer.deinit
pub fn deinit(self: *Buffer) void Destroy the Vulkan buffer, free device memory, and unmap any host-mapped pointer.
function
copyBuffer
pub fn copyBuffer( instance: *const Instance, cmd_pool: vk.c.VkCommandPool, src: *const Buffer, dst: *const Buffer, size: vk.c.VkDeviceSize, ) !void Copy bytes between two Vulkan buffers with a temporary one-shot command buffer.