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: BufferInfoInformation used to create this object.
name: Option<String>A name for debugging purposes.
Implementations
sourceimpl Buffer
impl Buffer
sourcepub fn create(
device: &Arc<Device>,
info: impl Into<BufferInfo>
) -> Result<Self, DriverError>
pub fn create(
device: &Arc<Device>,
info: impl Into<BufferInfo>
) -> Result<Self, DriverError>
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);sourcepub fn create_from_slice(
device: &Arc<Device>,
usage: BufferUsageFlags,
slice: &[u8]
) -> Result<Self, DriverError>
pub fn create_from_slice(
device: &Arc<Device>,
usage: BufferUsageFlags,
slice: &[u8]
) -> Result<Self, DriverError>
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);sourcepub fn access(this: &Self, next_access: AccessType) -> AccessType
pub fn access(this: &Self, next_access: AccessType) -> AccessType
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!sourcepub fn copy_from_slice(this: &mut Self, offset: DeviceSize, slice: &[u8])
pub fn copy_from_slice(this: &mut Self, offset: DeviceSize, slice: &[u8])
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);