C Specification

To attach memory to a buffer object, call:

// Provided by VK_VERSION_1_0
VkResult vkBindBufferMemory(
    VkDevice                                    device,
    VkBuffer                                    buffer,
    VkDeviceMemory                              memory,
    VkDeviceSize                                memoryOffset);

Parameters

  • device is the logical device that owns the buffer and memory.

  • buffer is the buffer to be attached to memory.

  • memory is a VkDeviceMemory object describing the device memory to attach.

  • memoryOffset is the start offset of the region of memory which is to be bound to the buffer. The number of bytes returned in the VkMemoryRequirements::size member in memory, starting from memoryOffset bytes, will be bound to the specified buffer.

Description

vkBindBufferMemory is equivalent to passing the same parameters through VkBindBufferMemoryInfo to vkBindBufferMemory2.

If the memory was obtained by a memory import operation with VkExternalMemoryBufferCreateInfo::handleTypes assigned to VK_EXTERNAL_MEMORY_HANDLE_TYPE_SCI_BUF_BIT_NV, the properties of buffer and the memoryoffset must be compatible with the attributes used to create NvSciBufObj, otherwise the implementation will return VK_ERROR_VALIDATION_FAILED.

If VkPhysicalDeviceVulkanSC10Properties::deviceNoDynamicHostAllocations is VK_TRUE, vkBindBufferMemory must not return VK_ERROR_OUT_OF_HOST_MEMORY.

Valid Usage
  • VUID-vkBindBufferMemory-buffer-07459
    buffer must not have been bound to a memory object

  • VUID-vkBindBufferMemory-buffer-01030
    buffer must not have been created with any sparse memory binding flags

  • VUID-vkBindBufferMemory-memoryOffset-01031
    memoryOffset must be less than the size of memory

  • VUID-vkBindBufferMemory-memory-01035
    memory must have been allocated using one of the memory types allowed in the memoryTypeBits member of the VkMemoryRequirements structure returned from a call to vkGetBufferMemoryRequirements with buffer

  • VUID-vkBindBufferMemory-memoryOffset-01036
    memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from a call to vkGetBufferMemoryRequirements with buffer

  • VUID-vkBindBufferMemory-size-01037
    The size member of the VkMemoryRequirements structure returned from a call to vkGetBufferMemoryRequirements with buffer must be less than or equal to the size of memory minus memoryOffset

  • VUID-vkBindBufferMemory-buffer-01444
    If buffer requires a dedicated allocation (as reported by vkGetBufferMemoryRequirements2 in VkMemoryDedicatedRequirements::requiresDedicatedAllocation for buffer), memory must have been allocated with VkMemoryDedicatedAllocateInfo::buffer equal to buffer

  • VUID-vkBindBufferMemory-memory-01508
    If the VkMemoryAllocateInfo provided when memory was allocated included a VkMemoryDedicatedAllocateInfo structure in its pNext chain, and VkMemoryDedicatedAllocateInfo::buffer was not VK_NULL_HANDLE, then buffer must equal VkMemoryDedicatedAllocateInfo::buffer, and memoryOffset must be zero

  • VUID-vkBindBufferMemory-None-01898
    If buffer was created with the VK_BUFFER_CREATE_PROTECTED_BIT bit set, the buffer must be bound to a memory object allocated with a memory type that reports VK_MEMORY_PROPERTY_PROTECTED_BIT

  • VUID-vkBindBufferMemory-None-01899
    If buffer was created with the VK_BUFFER_CREATE_PROTECTED_BIT bit not set, the buffer must not be bound to a memory object allocated with a memory type that reports VK_MEMORY_PROPERTY_PROTECTED_BIT

  • VUID-vkBindBufferMemory-memory-02726
    If the value of VkExportMemoryAllocateInfo::handleTypes used to allocate memory is not 0, it must include at least one of the handles set in VkExternalMemoryBufferCreateInfo::handleTypes when buffer was created

  • VUID-vkBindBufferMemory-memory-02985
    If memory was allocated by a memory import operation, the external handle type of the imported memory must also have been set in VkExternalMemoryBufferCreateInfo::handleTypes when buffer was created

  • VUID-vkBindBufferMemory-bufferDeviceAddress-03339
    If the VkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress feature is enabled and buffer was created with the VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT bit set, memory must have been allocated with the VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT bit set

  • VUID-vkBindBufferMemory-bufferDeviceAddressCaptureReplay-09200
    If the VkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddressCaptureReplay feature is enabled and buffer was created with the VK_BUFFER_CREATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT bit set, memory must have been allocated with the VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT bit set

Valid Usage (Implicit)
  • VUID-vkBindBufferMemory-device-parameter
    device must be a valid VkDevice handle

  • VUID-vkBindBufferMemory-buffer-parameter
    buffer must be a valid VkBuffer handle

  • VUID-vkBindBufferMemory-memory-parameter
    memory must be a valid VkDeviceMemory handle

  • VUID-vkBindBufferMemory-buffer-parent
    buffer must have been created, allocated, or retrieved from device

  • VUID-vkBindBufferMemory-memory-parent
    memory must have been created, allocated, or retrieved from device

Host Synchronization
  • Host access to buffer must be externally synchronized

Return Codes
On success, this command returns
  • VK_SUCCESS

On failure, this command returns
  • VK_ERROR_OUT_OF_HOST_MEMORY

  • VK_ERROR_OUT_OF_DEVICE_MEMORY

See Also

Document Notes

For more information, see the Vulkan Specification

This page is extracted from the Vulkan Specification. Fixes and changes should be made to the Specification, not directly.

Copyright 2014-2023 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0