Trait vulkano::buffer::BufferAccess
source · pub unsafe trait BufferAccess: DeviceOwned {
fn inner(&self) -> BufferInner<'_>;
fn size(&self) -> usize;
fn conflicts_buffer(&self, other: &dyn BufferAccess) -> bool;
fn conflicts_image(&self, other: &dyn ImageAccess) -> bool;
fn conflict_key(&self) -> (u64, usize);
fn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>;
unsafe fn increase_gpu_lock(&self);
unsafe fn unlock(&self);
fn as_buffer_slice(&self) -> BufferSlice<Self::Content, &Self>
where
Self: Sized + TypedBufferAccess,
{ ... }
fn slice<T>(&self, range: Range<usize>) -> Option<BufferSlice<[T], &Self>>
where
Self: Sized + TypedBufferAccess<Content = [T]>,
{ ... }
fn into_buffer_slice(self) -> BufferSlice<Self::Content, Self>
where
Self: Sized + TypedBufferAccess,
{ ... }
fn index<T>(&self, index: usize) -> Option<BufferSlice<[T], &Self>>
where
Self: Sized + TypedBufferAccess<Content = [T]>,
{ ... }
}
Expand description
Trait for objects that represent a way for the GPU to have access to a buffer or a slice of a buffer.
See also TypedBufferAccess
.
Required Methods
sourcefn inner(&self) -> BufferInner<'_>
fn inner(&self) -> BufferInner<'_>
Returns the inner information about this buffer.
sourcefn conflicts_buffer(&self, other: &dyn BufferAccess) -> bool
fn conflicts_buffer(&self, other: &dyn BufferAccess) -> bool
Returns true if an access to self
potentially overlaps the same memory as an access to
other
.
If this function returns false
, this means that we are allowed to mutably access the
content of self
at the same time as the content of other
without causing a data
race.
Note that the function must be transitive. In other words if conflicts(a, b)
is true and
conflicts(b, c)
is true, then conflicts(a, c)
must be true as well.
sourcefn conflicts_image(&self, other: &dyn ImageAccess) -> bool
fn conflicts_image(&self, other: &dyn ImageAccess) -> bool
Returns true if an access to self
potentially overlaps the same memory as an access to
other
.
If this function returns false
, this means that we are allowed to mutably access the
content of self
at the same time as the content of other
without causing a data
race.
Note that the function must be transitive. In other words if conflicts(a, b)
is true and
conflicts(b, c)
is true, then conflicts(a, c)
must be true as well.
sourcefn conflict_key(&self) -> (u64, usize)
fn conflict_key(&self) -> (u64, usize)
Returns a key that uniquely identifies the buffer. Two buffers or images that potentially overlap in memory must return the same key.
The key is shared amongst all buffers and images, which means that you can make several different buffer objects share the same memory, or make some buffer objects share memory with images, as long as they return the same key.
Since it is possible to accidentally return the same key for memory ranges that don’t
overlap, the conflicts_buffer
or conflicts_image
function should always be called to
verify whether they actually overlap.
sourcefn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>
fn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>
Locks the resource for usage on the GPU. Returns an error if the lock can’t be acquired.
This function exists to prevent the user from causing a data race by reading and writing to the same resource at the same time.
If you call this function, you should call unlock()
once the resource is no longer in use
by the GPU. The implementation is not expected to automatically perform any unlocking and
can rely on the fact that unlock()
is going to be called.
sourceunsafe fn increase_gpu_lock(&self)
unsafe fn increase_gpu_lock(&self)
Locks the resource for usage on the GPU. Supposes that the resource is already locked, and simply increases the lock by one.
Must only be called after try_gpu_lock()
succeeded.
If you call this function, you should call unlock()
once the resource is no longer in use
by the GPU. The implementation is not expected to automatically perform any unlocking and
can rely on the fact that unlock()
is going to be called.
Provided Methods
sourcefn as_buffer_slice(&self) -> BufferSlice<Self::Content, &Self>where
Self: Sized + TypedBufferAccess,
fn as_buffer_slice(&self) -> BufferSlice<Self::Content, &Self>where
Self: Sized + TypedBufferAccess,
Builds a BufferSlice
object holding the buffer by reference.
sourcefn slice<T>(&self, range: Range<usize>) -> Option<BufferSlice<[T], &Self>>where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn slice<T>(&self, range: Range<usize>) -> Option<BufferSlice<[T], &Self>>where
Self: Sized + TypedBufferAccess<Content = [T]>,
Builds a BufferSlice
object holding part of the buffer by reference.
This method can only be called for buffers whose type is known to be an array.
This method can be used when you want to perform an operation on some part of the buffer and not on the whole buffer.
Returns None
if out of range.
sourcefn into_buffer_slice(self) -> BufferSlice<Self::Content, Self>where
Self: Sized + TypedBufferAccess,
fn into_buffer_slice(self) -> BufferSlice<Self::Content, Self>where
Self: Sized + TypedBufferAccess,
Builds a BufferSlice
object holding the buffer by value.
sourcefn index<T>(&self, index: usize) -> Option<BufferSlice<[T], &Self>>where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn index<T>(&self, index: usize) -> Option<BufferSlice<[T], &Self>>where
Self: Sized + TypedBufferAccess<Content = [T]>,
Builds a BufferSlice
object holding part of the buffer by reference.
This method can only be called for buffers whose type is known to be an array.
This method can be used when you want to perform an operation on a specific element of the buffer and not on the whole buffer.
Returns None
if out of range.