pub struct Buffer {
    pub info: BufferInfo,
    pub name: Option<String>,
    /* private fields */
}
Expand description

Smart pointer handle to a buffer object.

Also contains information about the object.

Deref behavior

Buffer automatically dereferences to vk::Buffer (via the Deref trait), so you can call vk::Buffer’s methods on a value of type Buffer. To avoid name clashes with vk::Buffer’s methods, the methods of Buffer itself are associated functions, called using fully qualified syntax:

let addr = Buffer::device_address(&my_buf);

Fields

info: BufferInfo

Information used to create this object.

name: Option<String>

A name for debugging purposes.

Implementations

Creates a new buffer on the given device.

Examples

Basic usage:

const SIZE: vk::DeviceSize = 1024;
let info = BufferInfo::new_mappable(SIZE, vk::BufferUsageFlags::UNIFORM_BUFFER);
let buf = Buffer::create(&device, info)?;

assert_ne!(*buf, vk::Buffer::null());
assert_eq!(buf.info.size, SIZE);

Creates a new mappable buffer on the given device and fills it with the data in slice.

Examples

Basic usage:

const DATA: [u8; 4] = [0xfe, 0xed, 0xbe, 0xef];
let buf = Buffer::create_from_slice(&device, vk::BufferUsageFlags::UNIFORM_BUFFER, &DATA)?;

assert_ne!(*buf, vk::Buffer::null());
assert_eq!(buf.info.size, 4);
assert_eq!(Buffer::mapped_slice(&buf), &DATA);

Keeps track of some next_access which affects this object.

Returns the previous access for which a pipeline barrier should be used to prevent data corruption.

Note

Used to maintain object state when passing a Screen 13-created vk::Buffer handle to external code such as Ash or Erupt bindings.

Examples

Basic usage:

// Initially we want to "Read Other"
let next = AccessType::ComputeShaderReadOther;
let prev = Buffer::access(&my_buf, next);
assert_eq!(prev, AccessType::Nothing);

// External code may now "Read Other"; no barrier required

// Subsequently we want to "Write"
let next = AccessType::ComputeShaderWrite;
let prev = Buffer::access(&my_buf, next);
assert_eq!(prev, AccessType::ComputeShaderReadOther);

// A barrier on "Read Other" before "Write" is required!

Updates a mappable buffer starting at offset with the data in slice.

Panics

Panics if the buffer was not created with the can_map flag set to true.

Examples

Basic usage:

const DATA: [u8; 4] = [0xde, 0xad, 0xc0, 0xde];
Buffer::copy_from_slice(&mut my_buf, 0, &DATA);

assert_eq!(Buffer::mapped_slice(&my_buf), &DATA);

Returns the device address of this object.

Panics

Panics if the buffer was not created with the SHADER_DEVICE_ADDRESS usage flag.

Examples

Basic usage:

let addr = Buffer::device_address(&my_buf);

assert_ne!(addr, 0);

Returns a mapped slice.

Panics

Panics if the buffer was not created with the can_map flag set to true.

Examples

Basic usage:

// my_buf is mappable and filled with four zeroes
let data = Buffer::mapped_slice(&my_buf);

assert_eq!(data.len(), 4);
assert_eq!(data[0], 0x00);

Returns a mapped mutable slice.

Panics

Panics if the buffer was not created with the can_map flag set to true.

Examples

Basic usage:

let mut data = Buffer::mapped_slice_mut(&mut my_buf);
data.copy_from_slice(&42f32.to_be_bytes());

assert_eq!(data.len(), 4);
assert_eq!(data[0], 0x42);

Trait Implementations

Binds the resource to a graph-like object. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Executes the destructor for this type. Read more
Lease a resource.
Lease a resource.
Lease a resource.
Lease a resource.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.