Buffers, Images and Views

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

In Vulkan a buffer or an image is only a description: a size or an extent, a format, a set of intended uses. It owns no memory until you bind some, and a shader never sees it directly; shaders see descriptors that point at buffers and at image views. Getting these objects right (the usage bits, the tiling, the subresource ranges, the copies that fill them) is most of what separates a first triangle from a renderer that loads textures and meshes. This page covers the objects themselves. Where the memory comes from is the subject of Memory: Heaps, Types and VMA, and how shaders reach the resources is in Descriptors and Push Constants.

The facts were checked in November 2026. The version documented is Vulkan 1.4 (headers 1.4.3xx, LunarG SDK 1.4.363.0), with Vulkan 1.3 as the minimum for the running example: vkCmdCopyBuffer2 and the other 2 copy commands are core in 1.3, while host image copy, VkBufferUsageFlags2CreateInfo and vkCmdBindIndexBuffer2 became core in 1.4 and are optional extras for the example. Everything here is portable across Windows, Linux, Android and, through MoltenVK or KosmicKrisp, macOS (see Vulkan on Apple).

This is the resource layer of the Vulkan Bookshelf (C++20, Vulkan-Hpp, VMA, GLFW or SDL3, Slang shaders): the book vertex buffer, the cover texture and its view are created here, and the next stages use them (see Bookshelf 01: From Triangle to Textured Book). The same ideas in other APIs are in OpenGL buffers and OpenGL textures; the general background is in Meshes and Vertex Data and Textures, Sampling and Mipmaps.

The resource model

Diagram: VkBuffer and VkImage are bound to VkDeviceMemory, buffer views and image views are created from them and become texel buffer descriptors or sampled and storage image descriptors
Figure 1. A resource is created, given memory, and then viewed; descriptors and bind commands refer to the buffer or the view

Every Vulkan resource goes through the same life cycle:

  1. Create the object with vkCreateBuffer or vkCreateImage. The create info states what you intend to do with it; nothing is allocated yet.

  2. Query the requirements with vkGetBufferMemoryRequirements2 or vkGetImageMemoryRequirements2: size, alignment and the memory types that can back it. The 2 variants can chain VkMemoryDedicatedRequirements, which says whether the driver prefers a dedicated allocation.

  3. Allocate and bind memory (vkBindBufferMemory2, vkBindImageMemory2). In practice a library such as VMA does steps 2 and 3 for you (vmaCreateBuffer, vmaCreateImage).

  4. Create views where needed. A buffer needs a view only for texel buffers; an image needs a view for every use as a sampled image, storage image or attachment.

  5. Use it in commands and descriptors, and destroy it only after every submitted command that references it has finished.

Object Describes Needs a view?

VkBuffer

A linear range of bytes with a size and a set of usages.

Only as a VkBufferView for uniform or storage texel buffers. Uniform, storage, vertex, index and indirect uses take the buffer, an offset and a range directly.

VkImage

A one-, two- or three-dimensional array of texels with a format, mip levels, array layers and sample count.

Yes, a VkImageView for every shader or attachment use. Copies, blits and clears name the image itself.

VkBufferView

A format applied to a range of a buffer, so a shader can read it like a one-dimensional texture.

It is the view.

VkImageView

A format, a view type and a subresource range applied to an image.

It is the view.

Buffers

Creating a buffer

VkBufferCreateInfo has few fields, and each one matters:

Field Meaning Notes

size

Size in bytes. Must be greater than zero.

There is no padding to add yourself; alignment is handled when memory is bound. Offsets inside the buffer have their own alignment rules (see the limits table below).

usage

A bit mask of intended uses.

Must be non-zero unless a VkBufferUsageFlags2CreateInfo is chained (see below). Asking for more bits than you need can disable driver optimisations on some GPUs, so list only what you do.

sharingMode

VK_SHARING_MODE_EXCLUSIVE or VK_SHARING_MODE_CONCURRENT.

Exclusive means one queue family owns the buffer at a time; moving it requires an ownership transfer (see Synchronization and sync2). Concurrent lets the families listed in pQueueFamilyIndices share it without transfers, at a possible performance cost.

flags

Optional: VK_BUFFER_CREATE_SPARSE_BINDING_BIT, VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT, VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, VK_BUFFER_CREATE_PROTECTED_BIT, VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT.

The sparse flags need device features and the residency and aliased flags require the binding flag as well. The capture-replay flag is for tools such as GFXReconstruct.

The usage bits you will use most:

Usage bit Used for

VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_BUFFER_USAGE_TRANSFER_DST_BIT

Source or destination of copy and fill commands. A staging buffer is a transfer source, a device-local vertex buffer filled from it is a transfer destination as well as a vertex buffer.

VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_BUFFER_USAGE_INDEX_BUFFER_BIT

Bound with vkCmdBindVertexBuffers and vkCmdBindIndexBuffer (or vkCmdBindIndexBuffer2, core 1.4, which also takes a size). See Vertex Input and Drawing.

VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT

Read-only constant data through a uniform buffer descriptor.

VK_BUFFER_USAGE_STORAGE_BUFFER_BIT

Read-write (or large read-only) data through a storage buffer descriptor.

VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT

Required to create a VkBufferView of that kind.

VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT

Draw and dispatch parameters read by indirect commands.

VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT

Lets you call vkGetBufferDeviceAddress and use the address in shaders (see below).

The limits that govern offsets and copies, all in VkPhysicalDeviceLimits (see Physical and Logical Devices):

Limit What it constrains

minUniformBufferOffsetAlignment

The offset of a uniform buffer descriptor or dynamic offset. A common value is 64 or 256; always read it, never assume it.

minStorageBufferOffsetAlignment

The same for storage buffers.

minTexelBufferOffsetAlignment

Offsets of texel buffer views.

nonCoherentAtomSize

Granularity of vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges on non-coherent memory.

optimalBufferCopyOffsetAlignment, optimalBufferCopyRowPitchAlignment

The offsets and row pitches that make buffer-to-image copies fastest. These are hints, not requirements.

A device-local buffer filled through staging

The most common buffer in a Vulkan program is a device-local vertex or index buffer that the CPU fills once. The example creates it with VMA (the allocation strategy is explained in Memory: Heaps, Types and VMA), writes the data into a host-visible staging buffer and records a vkCmdCopyBuffer2 followed by a synchronization2 barrier.

#include <vk_mem_alloc.h>
#include <vulkan/vulkan.h>

#include <cstring>
#include <vector>
#include <span>
#include <stdexcept>

struct Buffer {
    VkBuffer      buffer{};
    VmaAllocation allocation{};
    VkDeviceSize  size{};
    void*         mapped{};   // only set for host-visible, persistently mapped buffers
};

Buffer createBuffer(VmaAllocator vma, VkDeviceSize size, VkBufferUsageFlags usage,
                    VmaAllocationCreateFlags flags, VmaMemoryUsage memoryUsage)
{
    const VkBufferCreateInfo bufferInfo{
        .sType       = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
        .size        = size,
        .usage       = usage,
        .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
    };
    const VmaAllocationCreateInfo allocInfo{
        .flags = flags,
        .usage = memoryUsage,        // VMA_MEMORY_USAGE_AUTO*: VMA picks the memory type
    };
    Buffer result{.size = size};
    VmaAllocationInfo info{};
    if (vmaCreateBuffer(vma, &bufferInfo, &allocInfo, &result.buffer, &result.allocation, &info) != VK_SUCCESS) {
        throw std::runtime_error("vmaCreateBuffer failed");
    }
    result.mapped = info.pMappedData;
    return result;
}

// Records "copy staging to a new device-local buffer" into cmd. The caller submits cmd,
// waits for it, and only then destroys the staging buffer.
Buffer uploadDeviceLocal(VmaAllocator vma, VkCommandBuffer cmd, std::span<const std::byte> data,
                         VkBufferUsageFlags finalUsage, Buffer& stagingOut)
{
    stagingOut = createBuffer(vma, data.size(), VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
                              VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
                                  VMA_ALLOCATION_CREATE_MAPPED_BIT,
                              VMA_MEMORY_USAGE_AUTO);
    std::memcpy(stagingOut.mapped, data.data(), data.size());
    // Non-coherent memory would need vmaFlushAllocation here; VMA skips the call when it is not needed.
    vmaFlushAllocation(vma, stagingOut.allocation, 0, VK_WHOLE_SIZE);

    Buffer device = createBuffer(vma, data.size(), finalUsage | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
                                 0, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE);

    const VkBufferCopy2 region{.sType = VK_STRUCTURE_TYPE_BUFFER_COPY_2, .size = data.size()};
    const VkCopyBufferInfo2 copy{
        .sType       = VK_STRUCTURE_TYPE_COPY_BUFFER_INFO_2,
        .srcBuffer   = stagingOut.buffer,
        .dstBuffer   = device.buffer,
        .regionCount = 1,
        .pRegions    = &region,
    };
    vkCmdCopyBuffer2(cmd, &copy);

    // Make the transfer write visible to vertex and index fetch (synchronization2 barrier).
    const VkBufferMemoryBarrier2 barrier{
        .sType         = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
        .srcStageMask  = VK_PIPELINE_STAGE_2_COPY_BIT,
        .srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT,
        .dstStageMask  = VK_PIPELINE_STAGE_2_VERTEX_INPUT_BIT,
        .dstAccessMask = VK_ACCESS_2_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_2_INDEX_READ_BIT,
        .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
        .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
        .buffer        = device.buffer,
        .offset        = 0,
        .size          = VK_WHOLE_SIZE,
    };
    const VkDependencyInfo dep{
        .sType                    = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
        .bufferMemoryBarrierCount = 1,
        .pBufferMemoryBarriers    = &barrier,
    };
    vkCmdPipelineBarrier2(cmd, &dep);
    return device;
}

A few details deserve attention. VK_QUEUE_FAMILY_IGNORED is required in the barrier unless you are transferring ownership. The barrier names only the stages and accesses that matter, which is the point of synchronization2 (the old VK_PIPELINE_STAGE_TRANSFER_BIT and VK_ACCESS_TRANSFER_WRITE_BIT pair lived in separate fields; the new masks are 64-bit and per barrier). Finally, the staging buffer must outlive the submission: destroy it after the fence or timeline value for that submission has been reached.

Usage flags 2 and buffer device address

VkBufferUsageFlags2CreateInfo (promoted to core in Vulkan 1.4 from VK_KHR_maintenance5) replaces the 32-bit usage field of VkBufferCreateInfo with a 64-bit mask, VkBufferUsageFlagBits2, when it is chained into pNext. It can also be chained into VkBufferViewCreateInfo to narrow the usage of a view to a subset of the buffer’s usage. Its main reason to exist is that the 32-bit space ran out of bits; for the bits that exist in both, the meaning is the same.

Buffer device address (core since Vulkan 1.2 and a required feature in Vulkan 1.3) turns a buffer into a raw 64-bit pointer a shader can follow:

  1. Enable the bufferDeviceAddress feature when creating the device.

  2. Create the buffer with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT.

  3. Allocate its memory with VkMemoryAllocateFlagsInfo containing VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT (VMA does this when you create the allocator with VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT).

  4. Call vkGetBufferDeviceAddress with a VkBufferDeviceAddressInfo and pass the returned VkDeviceAddress to the shader, usually in a push constant.

The addresses you can compute are valid for the lifetime of the buffer. Pointer-based access is the base of the techniques in Bindless Descriptors and of acceleration structures in Ray Tracing.

Images

Creating an image

VkImageCreateInfo is longer than the buffer one because an image has more dimensions to describe:

Field Meaning Notes

imageType

VK_IMAGE_TYPE_1D, 2D or 3D.

Cubes and arrays are views over 2D images (see the view types below), not image types.

format

A VkFormat.

Support depends on the usage; always check format features (next section).

extent

Width, height, depth.

For 1D and 2D images the unused dimensions are 1.

mipLevels

Number of mip levels, at least 1.

The full chain has \( \lfloor \log_2 \max(w, h, d) \rfloor + 1 \) levels: 9 for the 256x256 Bookshelf cover texture.

arrayLayers

Number of layers, at least 1.

Cube maps use 6 per cube; the implementation limit is maxImageArrayLayers.

samples

VK_SAMPLE_COUNT_1_BIT to 64_BIT.

Multisampled images have one mip level and are covered in Depth, Stencil, Blending and MSAA.

tiling

VK_IMAGE_TILING_OPTIMAL or VK_IMAGE_TILING_LINEAR.

See below. Use optimal unless you have a specific reason.

usage

A bit mask: TRANSFER_SRC, TRANSFER_DST, SAMPLED, STORAGE, COLOR_ATTACHMENT, DEPTH_STENCIL_ATTACHMENT, TRANSIENT_ATTACHMENT, INPUT_ATTACHMENT, HOST_TRANSFER (core 1.4) and others.

TRANSIENT_ATTACHMENT marks an attachment that never needs to leave tile memory; pair it with lazily allocated memory on tilers (see Multithreading and Performance).

sharingMode

As for buffers.

Same ownership rules.

initialLayout

VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.

UNDEFINED discards contents and is what you normally want. PREINITIALIZED keeps host-written data of a linear image.

flags

MUTABLE_FORMAT, CUBE_COMPATIBLE, 2D_ARRAY_COMPATIBLE, BLOCK_TEXEL_VIEW_COMPATIBLE, sparse flags, PROTECTED and others.

Each enables a kind of view or a feature on the image (see below).

Formats and format features

A format is a layout of channels (VK_FORMAT_R8G8B8A8_UNORM) plus an interpretation (_UNORM, _SNORM, _UINT, _SINT, _SFLOAT, _SRGB). The _SRGB formats decode to linear on sampling and encode on attachment writes, so the cover and wood textures (authored in sRGB) use R8G8B8A8_SRGB while normal maps and data textures use UNORM (the reasoning is in Color Spaces, HDR and Tone Mapping).

Not every format works for every use. The specification guarantees a mandatory set per usage; anything else must be queried:

  • vkGetPhysicalDeviceFormatProperties2 returns linearTilingFeatures, optimalTilingFeatures and bufferFeatures. Chain VkFormatProperties3 (core 1.3) to get the 64-bit VkFormatFeatureFlags2 versions, which include bits that the 32-bit flags cannot hold, such as VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT.

  • vkGetPhysicalDeviceImageFormatProperties2 answers the exact question "can I create an image with this format, type, tiling, usage and flags, and what are its limits": maximum extent, mip levels, array layers, sample counts and maximum resource size.

  • Block-compressed formats are gated by device features: textureCompressionBC (desktop), textureCompressionETC2 and textureCompressionASTC_LDR (mobile). A texture shipped in KTX2 with Basis Universal supercompression is transcoded to whichever the device supports (see Textures, Samplers and Mipmaps).

  • Depth and stencil formats, and the depth/stencil aspect rules, are in Depth, Stencil, Blending and MSAA.

Tiling and layouts

VK_IMAGE_TILING_OPTIMAL lets the driver arrange texels in whatever swizzled, compressed or tiled order suits the GPU. You cannot map such an image; you fill it with copy commands (or host image copy) and read it through a view. VK_IMAGE_TILING_LINEAR stores rows one after another, with a rowPitch you read from vkGetImageSubresourceLayout2, and can be mapped, but support is limited: implementations may restrict linear images to one layer, one mip level, a few formats and no depth/stencil or attachment use. Treat it as a rare tool, not a staging mechanism.

Independent of tiling, every image subresource has an image layout, which tells the driver how the texels are currently used (TRANSFER_DST_OPTIMAL, SHADER_READ_ONLY_OPTIMAL, COLOR_ATTACHMENT_OPTIMAL, GENERAL, and so on). A layout change is a barrier; the full rules are in Synchronization and sync2. Two layout facts matter here: a new image starts in UNDEFINED, and moving from UNDEFINED allows the driver to discard the contents.

Subresources: mip levels and array layers

Grid of image subresources with mip levels as rows and array layers as columns and a highlighted sub-range covering mip levels 1 to 3 and layers 1 to 2
Figure 2. The subresource grid of an image, and the range a view or barrier can select

An image consists of subresources addressed by an aspect (colour, depth, stencil, or planes for multi-planar formats), a mip level and an array layer. VkImageSubresourceRange selects a rectangle of that grid: aspectMask, baseMipLevel, levelCount, baseArrayLayer, layerCount. Barriers, clears, image views and many copies take such a range. VK_REMAINING_MIP_LEVELS and VK_REMAINING_ARRAY_LAYERS mean "from the base to the end", which keeps code correct when the mip count changes.

Image views

A VkImageView is a window onto an image: it chooses how the texels are interpreted and which subresources are visible.

VkImageViewCreateInfo field Meaning Notes

viewType

1D, 1D_ARRAY, 2D, 2D_ARRAY, CUBE, CUBE_ARRAY, 3D.

The view type must be compatible with the image: a cube view needs a 2D image created with CUBE_COMPATIBLE and 6 layers per cube, a 2D-array view of a 3D image needs 2D_ARRAY_COMPATIBLE.

format

Usually the image format.

A different format is allowed when it is compatible (same size class) and the image was created with MUTABLE_FORMAT; see below.

components

A VkComponentMapping that swizzles each channel to R, G, B, A, ZERO, ONE or IDENTITY.

Useful for single-channel textures: map R to all of R, G, B and A to ONE to make a grey texture. Storage image views and attachments must use the identity mapping.

subresourceRange

The slice of the image the view sees.

A render-target view must cover exactly one mip level. Sampling views can cover several levels, which is how a shader reads a full mip chain through one view.

pNext

VkImageViewUsageCreateInfo and others.

Narrows the usage of a view to a subset of the image usage, which can make a view valid for a format that does not support the whole image usage.

Creating the Bookshelf cover texture and its view

The example creates the 2D, single-mip sRGB cover texture with VMA, uploads it from a staging buffer with vkCmdCopyBufferToImage2, and wraps it in a view using Vulkan-Hpp RAII. A full mip chain is generated by blits as described in Textures, Samplers and Mipmaps. The Buffer type and createBuffer helper are from the previous example.

struct Image {
    VkImage       image{};
    VmaAllocation allocation{};
    VkExtent3D    extent{};
    uint32_t      mipLevels{1};
};

Image createSampledImage(VmaAllocator vma, VkFormat format, uint32_t width, uint32_t height)
{
    const VkImageCreateInfo info{
        .sType         = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
        .imageType     = VK_IMAGE_TYPE_2D,
        .format        = format,
        .extent        = {width, height, 1},
        .mipLevels     = 1,
        .arrayLayers   = 1,
        .samples       = VK_SAMPLE_COUNT_1_BIT,
        .tiling        = VK_IMAGE_TILING_OPTIMAL,
        .usage         = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
        .sharingMode   = VK_SHARING_MODE_EXCLUSIVE,
        .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
    };
    const VmaAllocationCreateInfo alloc{.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE};
    Image result{.extent = info.extent, .mipLevels = info.mipLevels};
    if (vmaCreateImage(vma, &info, &alloc, &result.image, &result.allocation, nullptr) != VK_SUCCESS) {
        throw std::runtime_error("vmaCreateImage failed");
    }
    return result;
}

void transitionImage(VkCommandBuffer cmd, VkImage image, VkImageLayout from, VkImageLayout to,
                     VkPipelineStageFlags2 srcStage, VkAccessFlags2 srcAccess,
                     VkPipelineStageFlags2 dstStage, VkAccessFlags2 dstAccess)
{
    const VkImageMemoryBarrier2 barrier{
        .sType               = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
        .srcStageMask        = srcStage,
        .srcAccessMask       = srcAccess,
        .dstStageMask        = dstStage,
        .dstAccessMask       = dstAccess,
        .oldLayout           = from,
        .newLayout           = to,
        .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
        .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
        .image               = image,
        .subresourceRange    = {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS},
    };
    const VkDependencyInfo dep{
        .sType                   = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
        .imageMemoryBarrierCount = 1,
        .pImageMemoryBarriers    = &barrier,
    };
    vkCmdPipelineBarrier2(cmd, &dep);
}

// Records: UNDEFINED -> TRANSFER_DST, copy from the staging buffer, TRANSFER_DST -> SHADER_READ_ONLY.
void recordUpload(VkCommandBuffer cmd, const Image& img, VkBuffer staging)
{
    transitionImage(cmd, img.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
                    VK_PIPELINE_STAGE_2_NONE, VK_ACCESS_2_NONE,
                    VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT);

    const VkBufferImageCopy2 region{
        .sType             = VK_STRUCTURE_TYPE_BUFFER_IMAGE_COPY_2,
        .bufferOffset      = 0,
        .bufferRowLength   = 0,   // 0 = tightly packed, measured in texels when non-zero
        .bufferImageHeight = 0,
        .imageSubresource  = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
        .imageOffset       = {0, 0, 0},
        .imageExtent       = img.extent,
    };
    const VkCopyBufferToImageInfo2 copy{
        .sType          = VK_STRUCTURE_TYPE_COPY_BUFFER_TO_IMAGE_INFO_2,
        .srcBuffer      = staging,
        .dstImage       = img.image,
        .dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
        .regionCount    = 1,
        .pRegions       = &region,
    };
    vkCmdCopyBufferToImage2(cmd, &copy);

    transitionImage(cmd, img.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
                    VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT,
                    VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT, VK_ACCESS_2_SHADER_SAMPLED_READ_BIT);
}

// Vulkan-Hpp RAII view; the RAII object destroys the VkImageView with the device's allocator.
vk::raii::ImageView createCoverView(const vk::raii::Device& device, vk::Image image)
{
    const vk::ImageViewCreateInfo info{
        {},
        image,
        vk::ImageViewType::e2D,
        vk::Format::eR8G8B8A8Srgb,
        vk::ComponentMapping{},   // identity
        vk::ImageSubresourceRange{vk::ImageAspectFlagBits::eColor, 0, vk::RemainingMipLevels, 0, vk::RemainingArrayLayers},
    };
    return vk::raii::ImageView{device, info};
}

VK_PIPELINE_STAGE_2_NONE and VK_ACCESS_2_NONE in the first barrier say "nothing needs to be made available": the image is brand new. The final barrier makes the transfer write available and visible to fragment-shader sampling; if the texture is also sampled in the vertex stage, add VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT to the destination stage. Wrap a raw VkImage as vk::Image{ raw } when you mix the C handles of VMA with Vulkan-Hpp; the RAII wrapper class details are in Vulkan-Hpp, RAII and C++ Bindings. A conventional RAII helper holding both the image and its allocation is the usual way to keep this lifetime tidy, following the ideas in Memory Management and Smart Pointers.

Mutable formats

Creating an image with VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT and a VkImageFormatListCreateInfo (core 1.2) listing the allowed formats lets you create views in a different format than the image. The common use is to render into or sample an R8G8B8A8_SRGB image and also create a R8G8B8A8_UNORM view of it for a storage-image write in a compute shader (sRGB formats cannot be storage images on most hardware). Listing the formats up front, instead of just setting the flag, gives drivers the information to keep compression enabled.

const VkFormat viewFormats[] = {VK_FORMAT_R8G8B8A8_SRGB, VK_FORMAT_R8G8B8A8_UNORM};
const VkImageFormatListCreateInfo formatList{
    .sType           = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO,
    .viewFormatCount = 2,
    .pViewFormats    = viewFormats,
};
VkImageCreateInfo info{ /* ... as above ... */ };
info.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
info.usage |= VK_IMAGE_USAGE_STORAGE_BIT;   // used through the UNORM view only
info.pNext = &formatList;

Buffer views (texel buffers)

A VkBufferView gives a buffer a format so a shader can fetch from it like a one-dimensional texture, with texelFetch or a samplerBuffer (uniform texel buffer) or imageLoad and imageStore (storage texel buffer). VkBufferViewCreateInfo has buffer, format, offset and range (VK_WHOLE_SIZE means "to the end"). The buffer must have the matching texel usage bit, offset must satisfy minTexelBufferOffsetAlignment, and the format must advertise UNIFORM_TEXEL_BUFFER or STORAGE_TEXEL_BUFFER buffer features. Since storage buffers can hold structured data without a format, texel buffers are mostly used for formats the shader should decode, such as packed 8-bit data or very large one-dimensional lookup tables.

Copies and blits

The copy commands moved from the 1.0 form to an extensible form with core Vulkan 1.3 (VK_KHR_copy_commands2). Each takes one info structure with sType and pNext, so they can be extended without new entry points.

Command (core 1.3) Info and region structures Purpose

vkCmdCopyBuffer2

VkCopyBufferInfo2, VkBufferCopy2

Buffer to buffer. size must be greater than zero; regions in the same buffer must not overlap.

vkCmdCopyImage2

VkCopyImageInfo2, VkImageCopy2

Image to image of compatible formats and sample counts, no scaling or conversion.

vkCmdCopyBufferToImage2, vkCmdCopyImageToBuffer2

VkCopyBufferToImageInfo2, VkCopyImageToBufferInfo2, VkBufferImageCopy2

Between a buffer and an image. bufferRowLength and bufferImageHeight are in texels and define the memory layout of the buffer side; zero means tightly packed to the image extent.

vkCmdBlitImage2

VkBlitImageInfo2, VkImageBlit2

Scaling copy with a filter (NEAREST, LINEAR); the format must support BLIT_SRC and BLIT_DST. The mip chain generator uses it.

vkCmdResolveImage2

VkResolveImageInfo2, VkImageResolve2

Resolve a multisampled image into a single-sample image.

Common copy mistakes: a layout that does not match the dstImageLayout you declared (copy to an image that is not in TRANSFER_DST_OPTIMAL or GENERAL); copying a depth/stencil image without naming the aspect; and a bufferOffset that breaks the offset alignment rules of the copy commands in the specification. For compressed formats the extent is in texels but must be a multiple of the block size at the edges unless it reaches the image border.

Host image copy (Vulkan 1.4)

Host image copy lets the CPU write straight into an optimal-tiling image (and read back, or copy between images) without a staging buffer, a command buffer, a queue submission or a barrier. It started as VK_EXT_host_image_copy and was promoted to core in Vulkan 1.4 with the EXT suffix dropped. The feature is optional: a 1.4 implementation must support either the hostImageCopy feature or a separate transfer-capable queue, and you must check the specific format.

Three upload paths side by side: staging buffer followed by a GPU copy, host image copy straight from CPU memory, and linear tiling with a mapped image
Figure 3. Staging copy, host image copy and linear tiling compared

The commands:

Command Purpose

vkCopyMemoryToImage

Host memory to image (VkCopyMemoryToImageInfo, VkMemoryToImageCopy).

vkCopyImageToMemory

Image to host memory.

vkCopyImageToImage

Image to image on the host.

vkTransitionImageLayout

Layout transition done by the CPU (VkHostImageLayoutTransitionInfo), in place of a barrier.

To use it:

  1. Query the VkPhysicalDeviceHostImageCopyFeatures feature and enable it at device creation.

  2. Check that the format has VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT through VkFormatProperties3.

  3. Create the image with VK_IMAGE_USAGE_HOST_TRANSFER_BIT in addition to its normal usage.

  4. Read VkPhysicalDeviceHostImageCopyProperties to learn which layouts the host copies accept (pCopyDstLayouts and pCopySrcLayouts); VK_IMAGE_LAYOUT_GENERAL is the baseline.

  5. Transition with vkTransitionImageLayout, copy with vkCopyMemoryToImage, and transition to the layout the shader will read.

// Returns true if the CPU can upload straight into 'image' on this device.
bool supportsHostUpload(VkPhysicalDevice gpu, VkFormat format)
{
    VkFormatProperties3 props3{.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3};
    VkFormatProperties2 props2{.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, .pNext = &props3};
    vkGetPhysicalDeviceFormatProperties2(gpu, format, &props2);
    return (props3.optimalTilingFeatures & VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT) != 0;
}

// Image was created with VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_HOST_TRANSFER_BIT.
void hostUpload(VkDevice device, VkPhysicalDevice gpu, VkImage image, const void* pixels,
                uint32_t width, uint32_t height)
{
    // Which layouts can the host copy write into? (two-call idiom)
    VkPhysicalDeviceHostImageCopyProperties hic{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_PROPERTIES};
    VkPhysicalDeviceProperties2 props{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &hic};
    vkGetPhysicalDeviceProperties2(gpu, &props);
    std::vector<VkImageLayout> dstLayouts(hic.copyDstLayoutCount);
    hic.pCopyDstLayouts = dstLayouts.data();
    vkGetPhysicalDeviceProperties2(gpu, &props);

    // Prefer the final layout when the device accepts it, otherwise copy in GENERAL.
    VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL;
    for (VkImageLayout l : dstLayouts) {
        if (l == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { layout = l; break; }
    }

    const VkHostImageLayoutTransitionInfo transition{
        .sType            = VK_STRUCTURE_TYPE_HOST_IMAGE_LAYOUT_TRANSITION_INFO,
        .image            = image,
        .oldLayout        = VK_IMAGE_LAYOUT_UNDEFINED,
        .newLayout        = layout,
        .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
    };
    vkTransitionImageLayout(device, 1, &transition);

    const VkMemoryToImageCopy region{
        .sType             = VK_STRUCTURE_TYPE_MEMORY_TO_IMAGE_COPY,
        .pHostPointer      = pixels,
        .memoryRowLength   = 0,      // tightly packed, in texels
        .memoryImageHeight = 0,
        .imageSubresource  = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
        .imageOffset       = {0, 0, 0},
        .imageExtent       = {width, height, 1},
    };
    const VkCopyMemoryToImageInfo copy{
        .sType          = VK_STRUCTURE_TYPE_COPY_MEMORY_TO_IMAGE_INFO,
        .dstImage       = image,
        .dstImageLayout = layout,
        .regionCount    = 1,
        .pRegions       = &region,
    };
    vkCopyMemoryToImage(device, &copy);
    // The image is ready: descriptors that sample it must declare 'layout' as the image layout.
}

Host image copy is a good fit for streaming textures from a worker thread (no queue contention) and for emulation layers that receive pixels in host memory. It is not a replacement for staging when a transfer queue is idle and the data is huge: the CPU performs the swizzle, and a very large upload can cost more CPU time than a DMA engine would. Layout transitions done on the host and on the GPU are not synchronised with each other automatically; a host copy must finish (the call is synchronous) before a submission that uses the image.

Sparse resources

Sparse resources let a buffer or image be larger than the memory bound to it, with memory bound and unbound in pages after creation. The pieces are the create flags above, the sparseBinding, sparseResidencyBuffer, sparseResidencyImage2D and related device features, a queue family with VK_QUEUE_SPARSE_BINDING_BIT, vkQueueBindSparse to bind and unbind pages, and vkGetImageSparseMemoryRequirements2 for the page granularity and the mip tail. Typical uses are virtual texturing and terrain streaming, where only the visible part of a huge texture is resident. Support is uneven (several mobile GPUs do not expose residency), the feature set is large, and the Bookshelf does not need it, so this page stops at the idea; the specification chapter on sparse resources is the reference.

Mistakes, performance and recent changes

Mistake or tip Why and what to do

Destroying a view or an image still in use

Wait for the frame’s fence or timeline value first; see Timeline Semaphores and Frames in Flight. Destroy views before the image.

Missing usage bit

TRANSFER_DST for uploads, TRANSFER_SRC for mip generation and read-back, SAMPLED for textures. The validation layers name the missing bit (see Validation and Debug Utils).

Using VK_IMAGE_TILING_LINEAR as a convenient staging image

Support is restricted. Use a buffer for staging and optimal tiling for the real image.

Assuming the uniform-buffer offset alignment

Read minUniformBufferOffsetAlignment; round dynamic offsets up to it.

One allocation per resource

There is a device limit (maxMemoryAllocationCount, commonly 4096). Sub-allocate with VMA.

Reading a view of an image in the wrong layout

The descriptor declares the layout; it must match what the image is in when the shader runs.

Forgetting VK_REMAINING_* when the mip count changes

A hard-coded levelCount = 1 leaves the other mips in the wrong layout.

Performance

Keep staging buffers for the lifetime of a transfer ring, not for each upload. Prefer one large device-local buffer with offsets for many meshes, and suballocate; request the transfer usage bits only where needed. Give render targets and depth images dedicated allocations when the driver asks for it (VkMemoryDedicatedRequirements).

What changed recently:

  • Vulkan 1.3 (2022) made vkCmdCopyBuffer2 and the other copy commands, VkFormatProperties3 and the 64-bit format feature flags core.

  • Vulkan 1.4 (2024-12-03) promoted host image copy and VkBufferUsageFlags2CreateInfo / vkCmdBindIndexBuffer2 (maintenance5), and made several image-related capabilities mandatory.

  • Roadmap 2026 (announced 2026-01-23) builds on 1.4; the descriptor heap extension changes how buffers and images are exposed to shaders, covered in Bindless Descriptors.

Where older guides are outdated

Older teaching Today

Vulkan Programming Guide ch. 2 and 4, Vulkan Cookbook ch. 4: vkCmdCopyBufferToImage, vkCmdCopyBuffer

The 2 variants are core since Vulkan 1.3 and are the extensible form; host image copy (core 1.4) removes the staging buffer when the format allows it.

Vulkan Programming Guide ch. 2, Vulkan Cookbook ch. 4: one VkDeviceMemory per resource, manual memory type search

Sub-allocation with VMA, dedicated allocation only when the driver prefers it, and buffer device address for pointer access.

Both books: vkGetPhysicalDeviceFormatProperties and vkGetPhysicalDeviceImageFormatProperties

The 2 forms with VkFormatProperties3 expose 64-bit format feature flags and chained information.

Both books: 32-bit buffer usage flags only

VkBufferUsageFlags2CreateInfo provides a 64-bit usage mask (core 1.4).

Both books: image barriers with vkCmdPipelineBarrier and top/bottom-of-pipe stages

vkCmdPipelineBarrier2 with precise 64-bit stage and access masks (core 1.3).

Vulkan Programming Guide and Vulkan Cookbook on sparse resources

The concepts are unchanged; support remains optional and uneven, so check features before relying on them.

See also