pub fn new_from_reader<R: Read>(
        device: &Device,
        memory: &mut Memory,
        commander: &Commander,
        src: &mut R,
        staging_buffer: &mut HostVisibleBuffer,
        usage: BufferUsageFlags,
        lifetime: Lifetime,
        reason: &str) -> Result<DeviceLocalBuffer, Error>
    {
        // Copy data into staging buffer
        let size: u64 = ::std::io::copy(src, staging_buffer)?;

        // Create device buffer
        let device_buffer = {
            let (buffer, block) = _new(
                device, memory, size,
                usage | BufferUsageFlags::TRANSFER_DST,
                lifetime, reason, MemoryPropertyFlags::DEVICE_LOCAL)?;
            DeviceLocalBuffer {
                buffer: buffer,
                block: block
            }
        };

        // Force a flush (FIXME if block held arc to mapped memory we would not have
        // to flush every chunk)
        memory.flush()?;

        // Copy from staging buffer to device buffer
        copy(device, commander,
             &staging_buffer.buffer,
             &device_buffer.buffer,
             &[BufferCopy {
                 src_offset: 0,
                 dst_offset: 0,
                 size: size,
             }])?;

        Ok(device_buffer)
    }
// Warning! this does not align data on the device, it copies byte-for-byte.
Warning. this does not align data on the device, it copies byte-for-byte.
Warning . this does not align data on the device it copies byte - for - byte .
pub fn new_from_reader<R: Read>(
        device: &Device,
        memory: &mut Memory,
        commander: &Commander,
        src: &mut R,
        staging_buffer: &mut HostVisibleBuffer,
        usage: BufferUsageFlags,
        lifetime: Lifetime,
        reason: &str) -> Result<DeviceLocalBuffer, Error>
    {
        // Copy data into staging buffer
        let size: u64 = ::std::io::copy(src, staging_buffer)?;
        // Create device buffer
        let device_buffer = {
            let (buffer, block) = _new(
                device, memory, size,
                usage | BufferUsageFlags::TRANSFER_DST,
                lifetime, reason, MemoryPropertyFlags::DEVICE_LOCAL)?;
            DeviceLocalBuffer {
                buffer: buffer,
                block: block
            }
        };
        // Force a flush (FIXME if block held arc to mapped memory we would not have
        // to flush every chunk)
        memory.flush()?;
        // Copy from staging buffer to device buffer
        copy(device, commander,
             &staging_buffer.buffer,
             &device_buffer.buffer,
             &[BufferCopy {
                 src_offset: 0,
                 dst_offset: 0,
                 size: size,
             }])?;
        Ok(device_buffer)
    }
pub fn new_from_reader < R : Read > ( device : & Device , memory : & mut Memory , commander : & Commander , src : & mut R , staging_buffer : & mut HostVisibleBuffer , usage : BufferUsageFlags , lifetime : Lifetime , reason : & str ) -> Result < DeviceLocalBuffer , Error > { // Copy data into staging buffer let size : u64 = :: std :: io :: copy ( src , staging_buffer ) ? ; // Create device buffer let device_buffer = { let ( buffer , block ) = _new ( device , memory , size , usage | BufferUsageFlags :: TRANSFER_DST , lifetime , reason , MemoryPropertyFlags :: DEVICE_LOCAL ) ? ; DeviceLocalBuffer { buffer : buffer , block : block } } ; // Force a flush (FIXME if block held arc to mapped memory we would not have // to flush every chunk) memory . flush ( ) ? ; // Copy from staging buffer to device buffer copy ( device , commander , & staging_buffer . buffer , & device_buffer . buffer , & [ BufferCopy { src_offset : 0 , dst_offset : 0 , size : size , } ] ) ? ; Ok ( device_buffer ) }
Warning!
Warning!
device
&Device
memory
&mut Memory
commander
&Commander
src
&mut R
staging_buffer
&mut HostVisibleBuffer
usage
BufferUsageFlags
lifetime
Lifetime
reason
&str
device
&Device
memory
&mut Memory
commander
&Commander
src
&mut R
staging_buffer
&mut HostVisibleBuffer
usage
BufferUsageFlags
lifetime
Lifetime
reason
&str