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.