Struct vulkano::buffer::cpu_pool::CpuBufferPool [−][src]
pub struct CpuBufferPool<T, A = Arc<StdMemoryPool>> where
A: MemoryPool, { /* fields omitted */ }
Ring buffer from which “sub-buffers” can be individually allocated.
This buffer is especially suitable when you want to upload or download some data regularly (for example, at each frame for a video game).
Usage
A CpuBufferPool
is similar to a ring buffer. You start by creating an empty pool, then you
grab elements from the pool and use them, and if the pool is full it will automatically grow
in size.
Contrary to a Vec
, elements automatically free themselves when they are dropped (ie. usually
when you call cleanup_finished()
on a future, or when you drop that future).
Arc-like
The CpuBufferPool
struct internally contains an Arc
. You can clone the CpuBufferPool
for
a cheap cost, and all the clones will share the same underlying buffer.
Example
use vulkano::buffer::CpuBufferPool; use vulkano::command_buffer::AutoCommandBufferBuilder; use vulkano::command_buffer::CommandBufferUsage; use vulkano::command_buffer::PrimaryCommandBuffer; use vulkano::sync::GpuFuture; // Create the ring buffer. let buffer = CpuBufferPool::upload(device.clone()); for n in 0 .. 25u32 { // Each loop grabs a new entry from that ring buffer and stores ` data` in it. let data: [f32; 4] = [1.0, 0.5, n as f32 / 24.0, 0.0]; let sub_buffer = buffer.next(data).unwrap(); // You can then use `sub_buffer` as if it was an entirely separate buffer. AutoCommandBufferBuilder::primary(device.clone(), queue.family(), CommandBufferUsage::OneTimeSubmit) .unwrap() // For the sake of the example we just call `update_buffer` on the buffer, even though // it is pointless to do that. .update_buffer(sub_buffer.clone(), &[0.2, 0.3, 0.4, 0.5]) .unwrap() .build().unwrap() .execute(queue.clone()) .unwrap() .then_signal_fence_and_flush() .unwrap(); }
Implementations
impl<T> CpuBufferPool<T>
[src]
impl<T> CpuBufferPool<T>
[src]pub fn new(device: Arc<Device>, usage: BufferUsage) -> CpuBufferPool<T>
[src]
pub fn new(device: Arc<Device>, usage: BufferUsage) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
.
pub fn upload(device: Arc<Device>) -> CpuBufferPool<T>
[src]
pub fn upload(device: Arc<Device>) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
meant for simple uploads.
Shortcut for a pool that can only be used as transfer source and with exclusive queue family accesses.
pub fn download(device: Arc<Device>) -> CpuBufferPool<T>
[src]
pub fn download(device: Arc<Device>) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
meant for simple downloads.
Shortcut for a pool that can only be used as transfer destination and with exclusive queue family accesses.
pub fn uniform_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]
pub fn uniform_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
meant for usage as a uniform buffer.
Shortcut for a pool that can only be used as uniform buffer and with exclusive queue family accesses.
pub fn vertex_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]
pub fn vertex_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
meant for usage as a vertex buffer.
Shortcut for a pool that can only be used as vertex buffer and with exclusive queue family accesses.
pub fn indirect_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]
pub fn indirect_buffer(device: Arc<Device>) -> CpuBufferPool<T>
[src]Builds a CpuBufferPool
meant for usage as a indirect buffer.
Shortcut for a pool that can only be used as indirect buffer and with exclusive queue family accesses.
impl<T, A> CpuBufferPool<T, A> where
A: MemoryPool,
[src]
impl<T, A> CpuBufferPool<T, A> where
A: MemoryPool,
[src]pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
[src]Returns the current capacity of the pool, in number of elements.
pub fn reserve(&self, capacity: usize) -> Result<(), DeviceMemoryAllocError>
[src]
pub fn reserve(&self, capacity: usize) -> Result<(), DeviceMemoryAllocError>
[src]Makes sure that the capacity is at least capacity
. Allocates memory if it is not the
case.
Since this can involve a memory allocation, an OomError
can happen.
pub fn next(
&self,
data: T
) -> Result<CpuBufferPoolSubbuffer<T, A>, DeviceMemoryAllocError>
[src]
pub fn next(
&self,
data: T
) -> Result<CpuBufferPoolSubbuffer<T, A>, DeviceMemoryAllocError>
[src]Grants access to a new subbuffer and puts data
in it.
If no subbuffer is available (because they are still in use by the GPU), a new buffer will automatically be allocated.
Note: You can think of it like a
Vec
. If you insert an element and theVec
is not large enough, a new chunk of memory is automatically allocated.
pub fn chunk<I>(
&self,
data: I
) -> Result<CpuBufferPoolChunk<T, A>, DeviceMemoryAllocError> where
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
[src]
pub fn chunk<I>(
&self,
data: I
) -> Result<CpuBufferPoolChunk<T, A>, DeviceMemoryAllocError> where
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
[src]Grants access to a new subbuffer and puts data
in it.
If no subbuffer is available (because they are still in use by the GPU), a new buffer will automatically be allocated.
Note: You can think of it like a
Vec
. If you insert elements and theVec
is not large enough, a new chunk of memory is automatically allocated.
Panic
Panics if the length of the iterator didn’t match the actual number of element.
pub fn try_next(&self, data: T) -> Option<CpuBufferPoolSubbuffer<T, A>>
[src]
pub fn try_next(&self, data: T) -> Option<CpuBufferPoolSubbuffer<T, A>>
[src]Grants access to a new subbuffer and puts data
in it.
Returns None
if no subbuffer is available.
A CpuBufferPool
is always empty the first time you use it, so you shouldn’t use
try_next
the first time you use it.
Trait Implementations
impl<T, A> Clone for CpuBufferPool<T, A> where
A: MemoryPool + Clone,
[src]
impl<T, A> Clone for CpuBufferPool<T, A> where
A: MemoryPool + Clone,
[src]impl<T, A> DeviceOwned for CpuBufferPool<T, A> where
A: MemoryPool,
[src]
impl<T, A> DeviceOwned for CpuBufferPool<T, A> where
A: MemoryPool,
[src]Auto Trait Implementations
impl<T, A> RefUnwindSafe for CpuBufferPool<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> Send for CpuBufferPool<T, A> where
A: Send,
T: Send,
<A as MemoryPool>::Alloc: Send + Sync,
A: Send,
T: Send,
<A as MemoryPool>::Alloc: Send + Sync,
impl<T, A> Sync for CpuBufferPool<T, A> where
A: Sync,
T: Sync,
<A as MemoryPool>::Alloc: Send + Sync,
A: Sync,
T: Sync,
<A as MemoryPool>::Alloc: Send + Sync,
impl<T, A> Unpin for CpuBufferPool<T, A> where
A: Unpin,
A: Unpin,
impl<T, A> UnwindSafe for CpuBufferPool<T, A> where
A: UnwindSafe,
T: UnwindSafe,
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Content for T
[src]
impl<T> Content for T
[src]pub fn ref_from_ptr(*mut c_void, usize) -> Option<*mut T>
[src]
pub fn ref_from_ptr(*mut c_void, usize) -> Option<*mut T>
[src]Builds a pointer to this type from a raw pointer.
pub fn is_size_suitable(usize) -> bool
[src]
pub fn is_size_suitable(usize) -> bool
[src]Returns true if the size is suitable to store a type like this.
pub fn indiv_size() -> usize
[src]
pub fn indiv_size() -> usize
[src]Returns the size of an individual element.
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more