/// Creates a new buffer with the given data. If the `usage` flag contains `BufferUsageFlags::MAP_WRITE`,
/// the data is mapped and copied directly. Otherwise, a staging buffer is used to copy the data
Creates a new buffer with the given data. If the `usage` flag contains `BufferUsageFlags::MAP_WRITE`,
the data is mapped and copied directly. Otherwise, a staging buffer is used to copy the data
Creates a new buffer with the given data . If the ` usage ` flag contains ` BufferUsageFlags :: MAP_WRITE ` the data is mapped and copied directly . Otherwise a staging buffer is used to copy the data
pub fn create_buffer_with_data<U: Copy + 'static>(
    device: &Device,
    encoder: &mut CommandEncoder,
    mut usage: BufferUsage,
    data: &[U],
) -> Result<Buffer, Error> {
    let size_bytes = self::byte_length(&data);
    let is_write_mapped = usage.contains(BufferUsage::MAP_WRITE);
    if !is_write_mapped {
        usage |= BufferUsage::COPY_DST;
    }
    let descriptor = BufferDescriptor {
        usage,
        size: size_bytes,
    };
    if is_write_mapped {
        let mapped_buffer = device.create_buffer_mapped(descriptor)?;
        mapped_buffer.copy_from_slice(data)?;
        Ok(mapped_buffer.unmap())
    } else {
        let buffer = device.create_buffer(descriptor)?;
        copy_to_buffer(device, encoder, data, &buffer)?;
        Ok(buffer)
    }
}
pub fn create_buffer_with_data < U : Copy + ' static > ( device : & Device , encoder : & mut CommandEncoder , mut usage : BufferUsage , data : & [ U ] , ) -> Result < Buffer , Error > { let size_bytes = self :: byte_length ( & data ) ; let is_write_mapped = usage . contains ( BufferUsage :: MAP_WRITE ) ; if ! is_write_mapped { usage |= BufferUsage :: COPY_DST ; } let descriptor = BufferDescriptor { usage , size : size_bytes , } ; if is_write_mapped { let mapped_buffer = device . create_buffer_mapped ( descriptor ) ? ; mapped_buffer . copy_from_slice ( data ) ? ; Ok ( mapped_buffer . unmap ( ) ) } else { let buffer = device . create_buffer ( descriptor ) ? ; copy_to_buffer ( device , encoder , data , & buffer ) ? ; Ok ( buffer ) } }
Creates a new buffer with the given data.
Creates a new buffer with the given data .
device
&Device
encoder
&mut CommandEncoder
usage
BufferUsage
data
&[U]