Trait vulkano::buffer::BufferAccess [−][src]
pub unsafe trait BufferAccess: DeviceOwned + Send + Sync {
fn inner(&self) -> BufferInner<'_>;
fn size(&self) -> DeviceSize;
fn conflict_key(&self) -> (u64, u64);
fn try_gpu_lock(
&self,
exclusive_access: bool,
queue: &Queue
) -> Result<(), AccessError>;
unsafe fn increase_gpu_lock(&self);
unsafe fn unlock(&self);
fn into_buffer_slice(
self: &Arc<Self>
) -> Arc<BufferSlice<Self::Content, Self>>
where
Self: Sized + TypedBufferAccess,
{ ... }
fn slice<T>(
self: &Arc<Self>,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], Self>>>
where
Self: Sized + TypedBufferAccess<Content = [T]>,
{ ... }
fn index<T>(
self: &Arc<Self>,
index: DeviceSize
) -> Option<Arc<BufferSlice<T, Self>>>
where
Self: Sized + TypedBufferAccess<Content = [T]>,
{ ... }
fn raw_device_address(
&self
) -> Result<NonZeroU64, DeviceAddressUsageNotEnabledError> { ... }
}
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
fn inner(&self) -> BufferInner<'_>
fn inner(&self) -> BufferInner<'_>
Returns the inner information about this buffer.
fn size(&self) -> DeviceSize
fn size(&self) -> DeviceSize
Returns the size of the buffer in bytes.
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.
fn 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.
unsafe 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
fn into_buffer_slice(self: &Arc<Self>) -> Arc<BufferSlice<Self::Content, Self>> where
Self: Sized + TypedBufferAccess,
fn into_buffer_slice(self: &Arc<Self>) -> Arc<BufferSlice<Self::Content, Self>> where
Self: Sized + TypedBufferAccess,
Returns a BufferSlice
covering the whole buffer.
fn slice<T>(
self: &Arc<Self>,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn slice<T>(
self: &Arc<Self>,
range: Range<DeviceSize>
) -> Option<Arc<BufferSlice<[T], Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
Returns a BufferSlice
for a subrange of elements in the buffer. Returns None
if
out of range.
This method can be used when you want to perform an operation on some part of the buffer and not on the whole buffer.
fn index<T>(
self: &Arc<Self>,
index: DeviceSize
) -> Option<Arc<BufferSlice<T, Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
fn index<T>(
self: &Arc<Self>,
index: DeviceSize
) -> Option<Arc<BufferSlice<T, Self>>> where
Self: Sized + TypedBufferAccess<Content = [T]>,
Returns a BufferSlice
for a single element in the buffer. Returns None
if out of range.
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.
fn raw_device_address(
&self
) -> Result<NonZeroU64, DeviceAddressUsageNotEnabledError>
fn raw_device_address(
&self
) -> Result<NonZeroU64, DeviceAddressUsageNotEnabledError>
Gets the device address for this buffer.
Safety
No lock checking or waiting is performed. This is nevertheless still safe because the returned value isn’t directly dereferencable. Unsafe code is required to dereference the value in a shader.