Template Class BuilderBase

Class Documentation

template<typename BuilderType, typename CreateInfoType>
class BuilderBase

Base class for resource builders, provides common VMA allocation options.

Contains VMA allocation configuration methods shared by all resource builders (BufferBuilder, ImageBuilder, etc.). Derived builders add resource-specific options like buffer usage flags or image formats. Methods return the derived type for method chaining.

Usage:

auto buffer = BufferBuilder(1024)
    .with_usage(vk::BufferUsageFlagBits::eStorageBuffer)
    .with_vma_usage(VMA_MEMORY_USAGE_GPU_ONLY)
    .build(device);

Template Parameters:
  • BuilderType – The derived builder type (for CRTP method chaining)

  • CreateInfoType – The Vulkan create info structure (vk::BufferCreateInfo, vk::ImageCreateInfo, etc.)

Public Functions

virtual ~BuilderBase() = default
inline const VmaAllocationCreateInfo &get_allocation_create_info() const

Gets the VMA allocation create info.

inline const CreateInfoType &get_create_info() const

Gets the Vulkan create info structure.

inline const std::string &get_debug_name() const

Gets the debug name.

inline BuilderType &with_debug_name(const std::string &name)

Sets debug name for GPU debuggers.

Parameters:

name – Debug name (appears in RenderDoc, NSight, etc.)

Returns:

Reference to derived builder for chaining

inline BuilderType &with_implicit_sharing_mode()

Automatically sets sharing mode based on queue family count.

Returns:

Reference to derived builder for chaining

inline BuilderType &with_memory_type_bits(uint32_t type_bits)

Sets memory type bits for VMA allocation.

Parameters:

type_bits – Bitfield of allowed memory types

Returns:

Reference to derived builder for chaining

inline BuilderType &with_queue_families(uint32_t count, const uint32_t *family_indices)

Sets queue families that can access this resource.

Parameters:
  • count – Number of queue family indices

  • family_indices – Array of queue family indices

Returns:

Reference to derived builder for chaining

inline BuilderType &with_queue_families(const std::vector<uint32_t> &queue_families)

Sets queue families that can access this resource.

Parameters:

queue_families – Vector of queue family indices

Returns:

Reference to derived builder for chaining

inline BuilderType &with_sharing_mode(vk::SharingMode sharing_mode)

Sets queue sharing mode (Exclusive or Concurrent)

Parameters:

sharing_mode – The sharing mode

Returns:

Reference to derived builder for chaining

inline BuilderType &with_vma_flags(const VmaAllocationCreateFlags flags)

Sets VMA allocation flags (e.g., VMA_ALLOCATION_CREATE_MAPPED_BIT)

Parameters:

flags – VMA allocation create flags

Returns:

Reference to derived builder for chaining

inline BuilderType &with_vma_pool(const VmaPool pool)

Sets VMA memory pool to allocate from.

Parameters:

pool – The VMA pool

Returns:

Reference to derived builder for chaining

inline BuilderType &with_vma_preferred_flags(const vk::MemoryPropertyFlags flags)

Sets preferred memory property flags (e.g., HOST_CACHED)

Parameters:

flags – Preferred memory properties

Returns:

Reference to derived builder for chaining

inline BuilderType &with_vma_required_flags(const vk::MemoryPropertyFlags flags)

Sets required memory property flags (e.g., HOST_VISIBLE | HOST_COHERENT)

Parameters:

flags – Required memory properties

Returns:

Reference to derived builder for chaining

inline BuilderType &with_vma_usage(VmaMemoryUsage usage)

Sets VMA memory usage hint (GPU_ONLY, CPU_TO_GPU, etc.)

Parameters:

usage – VMA memory usage

Returns:

Reference to derived builder for chaining

inline CreateInfoType &get_create_info()

Gets mutable reference to Vulkan create info.

Protected Functions

inline explicit BuilderBase(const CreateInfoType &create_info)

Protected Attributes

VmaAllocationCreateInfo alloc_create_info = {}
CreateInfoType create_info = {}
std::string debug_name = {}