pub struct BufferBinding<'a, B: DynBuffer + ?Sized> {
pub buffer: &'a B,
pub offset: BufferAddress,
pub size: Option<BufferSize>,
}
Expand description
A region of a buffer made visible to shaders via a BindGroup
.
§Accessible region
wgpu_hal
guarantees that shaders compiled with
ShaderModuleDescriptor::runtime_checks
set to true
cannot read or
write data via this binding outside the accessible region of buffer
:
-
The accessible region starts at
offset
. -
For
Storage
bindings, the size of the accessible region issize
, which must be a multiple of 4. -
For
Uniform
bindings, the size of the accessible region issize
rounded up to the next multiple ofAlignments::uniform_bounds_check_alignment
.
Note that this guarantee is stricter than WGSL’s requirements for
out-of-bounds accesses, as WGSL allows them to return values from
elsewhere in the buffer. But this guarantee is necessary anyway, to permit
wgpu-core
to avoid clearing uninitialized regions of buffers that will
never be read by the application before they are overwritten. This
optimization consults bind group buffer binding regions to determine which
parts of which buffers shaders might observe. This optimization is only
sound if shader access is bounds-checked.
Fields§
§buffer: &'a B
The buffer being bound.
offset: BufferAddress
The offset at which the bound region starts.
This must be less than the size of the buffer. Some back ends cannot tolerate zero-length regions; for example, see VUID-VkDescriptorBufferInfo-offset-00340 and VUID-VkDescriptorBufferInfo-range-00341, or the documentation for GLES’s glBindBufferRange.
size: Option<BufferSize>
The size of the region bound, in bytes.
If None
, the region extends from offset
to the end of the
buffer. Given the restrictions on offset
, this means that
the size is always greater than zero.
Implementations§
Source§impl<'a> BufferBinding<'a, dyn DynBuffer>
impl<'a> BufferBinding<'a, dyn DynBuffer>
pub fn expect_downcast<B: DynBuffer>(self) -> BufferBinding<'a, B>
Trait Implementations§
Auto Trait Implementations§
impl<'a, B> Freeze for BufferBinding<'a, B>where
B: ?Sized,
impl<'a, B> RefUnwindSafe for BufferBinding<'a, B>where
B: RefUnwindSafe + ?Sized,
impl<'a, B> Send for BufferBinding<'a, B>
impl<'a, B> Sync for BufferBinding<'a, B>
impl<'a, B> Unpin for BufferBinding<'a, B>where
B: ?Sized,
impl<'a, B> UnwindSafe for BufferBinding<'a, B>where
B: RefUnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)