/// I could create a buffer myself and allocate memory with VMA, but their
/// recomended approach is to allow the library to create a buffer and bind
/// the memory, effectively replacing all of this code.  See their [docs](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/choosing_memory_type.html).
/// To see manual creation of this (with super naive memory allocation) see
/// this file at tag 17_vertex_buffer_creation.
///
/// So in summary, VMA handles creating the buffer, finding the appropriate
/// memory type index, allocating the memory, and binding the buffer to the
/// memory.
///
/// The way this function operates to keep things as efficient as possible at
/// GPU runtime is to copy into a staging buffer and initiate a transfer
/// operation on the GPU to a more efficient device only GPU memory buffer.
I could create a buffer myself and allocate memory with VMA, but their
recomended approach is to allow the library to create a buffer and bind
the memory, effectively replacing all of this code.  See their [docs].
To see manual creation of this (with super naive memory allocation) see
this file at tag 17_vertex_buffer_creation.

So in summary, VMA handles creating the buffer, finding the appropriate
memory type index, allocating the memory, and binding the buffer to the
memory.

The way this function operates to keep things as efficient as possible at
GPU runtime is to copy into a staging buffer and initiate a transfer
operation on the GPU to a more efficient device only GPU memory buffer.
I could create a buffer myself and allocate memory with VMA but their recomended approach is to allow the library to create a buffer and bind the memory effectively replacing all of this code . See their [ docs ] . To see manual creation of this ( with super naive memory allocation ) see this file at tag 17_vertex_buffer_creation . So in summary VMA handles creating the buffer finding the appropriate memory type index allocating the memory and binding the buffer to the memory . The way this function operates to keep things as efficient as possible at GPU runtime is to copy into a staging buffer and initiate a transfer operation on the GPU to a more efficient device only GPU memory buffer .
fn load_buffer_with_staging<BufElem: Sized + Copy>(
    &self, buffer_type: BufferType, buffer: &[BufElem],
  ) -> SarektResult<ResourceWithMemory> {
    let buffer_size =
      (std::mem::size_of::<BufElem>() as vk::DeviceSize) * buffer.len() as vk::DeviceSize;
    // Create the staging buffer and memory.
    let (staging_buffer, staging_allocation, _) = self.create_staging_buffer(buffer_size)?;
    // Copy over all the bytes from host memory to mapped device memory
    let data = self.allocator.map_memory(&staging_allocation)? as *mut BufElem;
    unsafe {
      data.copy_from_nonoverlapping(buffer.as_ptr(), buffer.len());
    }
    self.allocator.unmap_memory(&staging_allocation)?;
    let (gpu_buffer, gpu_allocation, _gpu_allocation_info) =
      self.create_gpu_buffer(buffer_type, buffer_size, self.transfer_queue_family)?;
    self.transfer_staging_to_gpu_buffer_or_image(
      buffer_size,
      staging_buffer,
      ImageOrBuffer::Buffer(gpu_buffer),
      None,
    )?;
    // Staging buffer no longer needed, delete it.
    info!("Destroying staging buffer and memory...");
    self
      .allocator
      .destroy_buffer(staging_buffer, &staging_allocation)?;
    // If this is an index buffer, keep track of the size of the elements (16 or
    // 32).
    let index_buffer_elem_size = match buffer_type {
      BufferType::Index(size) => Some(size),
      _ => None,
    };
    Ok(ResourceWithMemory::Buffer(BufferAndMemory {
      buffer: gpu_buffer,
      length: buffer.len() as u32,
      index_buffer_elem_size,
      allocation: gpu_allocation,
    }))
  }
fn load_buffer_with_staging < BufElem : Sized + Copy > ( & self , buffer_type : BufferType , buffer : & [ BufElem ] , ) -> SarektResult < ResourceWithMemory > { let buffer_size = ( std :: mem :: size_of :: < BufElem > ( ) as vk :: DeviceSize ) * buffer . len ( ) as vk :: DeviceSize ; // Create the staging buffer and memory. let ( staging_buffer , staging_allocation , _ ) = self . create_staging_buffer ( buffer_size ) ? ; // Copy over all the bytes from host memory to mapped device memory let data = self . allocator . map_memory ( & staging_allocation ) ? as * mut BufElem ; unsafe { data . copy_from_nonoverlapping ( buffer . as_ptr ( ) , buffer . len ( ) ) ; } self . allocator . unmap_memory ( & staging_allocation ) ? ; let ( gpu_buffer , gpu_allocation , _gpu_allocation_info ) = self . create_gpu_buffer ( buffer_type , buffer_size , self . transfer_queue_family ) ? ; self . transfer_staging_to_gpu_buffer_or_image ( buffer_size , staging_buffer , ImageOrBuffer :: Buffer ( gpu_buffer ) , None , ) ? ; // Staging buffer no longer needed, delete it. info ! ( " " ) ; self . allocator . destroy_buffer ( staging_buffer , & staging_allocation ) ? ; // If this is an index buffer, keep track of the size of the elements (16 or // 32). let index_buffer_elem_size = match buffer_type { BufferType :: Index ( size ) => Some ( size ) , _ => None , } ; Ok ( ResourceWithMemory :: Buffer ( BufferAndMemory { buffer : gpu_buffer , length : buffer . len ( ) as u32 , index_buffer_elem_size , allocation : gpu_allocation , } ) ) }
I could create a buffer myself and allocate memory with VMA, but their
recomended approach is to allow the library to create a buffer and bind
the memory, effectively replacing all of this code.
I could create a buffer myself and allocate memory with VMA but their recomended approach is to allow the library to create a buffer and bind the memory effectively replacing all of this code .
&self
buffer_type
BufferType
buffer
&[BufElem]