Skip to content

Commit

Permalink
Document that various sizes and offsets are in bytes.
Browse files Browse the repository at this point in the history
Document that the following are in bytes:
- `BindingType::Buffer::min_binding_size`
- `BufferBinding::offset`
- `BufferBinding::size`
- `BufferDescriptor::size`

Clarify other requirements as well.

Fixes gfx-rs#3768.
  • Loading branch information
jimblandy committed May 14, 2023
1 parent 372ac9b commit f85e8d9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
37 changes: 30 additions & 7 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4276,7 +4276,7 @@ impl_bitflags!(BufferUsages);
pub struct BufferDescriptor<L> {
/// Debug label of a buffer. This will show up in graphics debuggers for easy identification.
pub label: L,
/// Size of a buffer.
/// Size of a buffer, in bytes.
pub size: BufferAddress,
/// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation
/// will panic.
Expand Down Expand Up @@ -5531,18 +5531,41 @@ pub enum BindingType {
Buffer {
/// Sub-type of the buffer binding.
ty: BufferBindingType,

/// Indicates that the binding has a dynamic offset.
///
/// One offset must be passed to [`RenderPass::set_bind_group`][RPsbg] for each dynamic
/// binding in increasing order of binding number.
/// One offset must be passed to [`RenderPass::set_bind_group`][RPsbg]
/// for each dynamic binding in increasing order of binding number.
///
/// [RPsbg]: ../wgpu/struct.RenderPass.html#method.set_bind_group
#[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))]
has_dynamic_offset: bool,
/// Minimum size of the corresponding `BufferBinding` required to match this entry.
/// When pipeline is created, the size has to cover at least the corresponding structure in the shader
/// plus one element of the unbound array, which can only be last in the structure.
/// If `None`, the check is performed at draw call time instead of pipeline and bind group creation.

/// The minimum size for a [`BufferBinding`] matching this entry, in bytes.
///
/// If this is `Some(size)`:
///
/// - When calling [`create_bind_group`], the resource at this bind point
/// must be a [`BindingResource::Buffer`] whose effective size is at
/// least `size`.
///
/// - When calling [`create_render_pipeline`] or [`create_compute_pipeline`],
/// `size` must be at least the [minimum buffer binding size] for the
/// shader module global at this bind point: large enough to hold the
/// global's value, along with one element of a trailing runtime-sized
/// array, if present.
///
/// If this is `None`:
///
/// - Each draw or dispatch command checks that the buffer range at this
/// bind point satisfies the [minimum buffer binding size].
///
/// [`BufferBinding`]: ../wgpu/struct.BufferBinding.html
/// [`create_bind_group`]: ../wgpu/struct.Device.html#method.create_bind_group
/// [`BindingResource::Buffer`]: ../wgpu/enum.BindingResource.html#variant.Buffer
/// [minimum buffer binding size]: https://www.w3.org/TR/webgpu/#minimum-buffer-binding-size
/// [`create_render_pipeline`]: ../wgpu/struct.Device.html#method.create_render_pipeline
/// [`create_compute_pipeline`]: ../wgpu/struct.Device.html#method.create_compute_pipeline
#[cfg_attr(any(feature = "trace", feature = "replay"), serde(default))]
min_binding_size: Option<BufferSize>,
},
Expand Down
22 changes: 17 additions & 5 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,25 @@ static_assertions::assert_impl_all!(BindingResource: Send, Sync);
pub struct BufferBinding<'a> {
/// The buffer to bind.
pub buffer: &'a Buffer,
/// Base offset of the buffer. For bindings with `dynamic == true`, this offset
/// will be added to the dynamic offset provided in [`RenderPass::set_bind_group`].

/// Base offset of the buffer, in bytes.
///
/// The offset has to be aligned to [`Limits::min_uniform_buffer_offset_alignment`]
/// or [`Limits::min_storage_buffer_offset_alignment`] appropriately.
/// If the [`has_dynamic_offset`] field of this buffer's layout entry is
/// `true`, the offset here will be added to the dynamic offset passed to
/// [`RenderPass::set_bind_group`] or [`ComputePass::set_bind_group`].
///
/// If the buffer was created with [`BufferUsages::UNIFORM`], then this
/// offset must be a multiple of
/// [`Limits::min_uniform_buffer_offset_alignment`].
///
/// If the buffer was created with [`BufferUsages::STORAGE`], then this
/// offset must be a multiple of
/// [`Limits::min_storage_buffer_offset_alignment`].
///
/// [`has_dynamic_offset`]: BindingType::Buffer::has_dynamic_offset
pub offset: BufferAddress,
/// Size of the binding, or `None` for using the rest of the buffer.

/// Size of the binding in bytes, or `None` for using the rest of the buffer.
pub size: Option<BufferSize>,
}
static_assertions::assert_impl_all!(BufferBinding: Send, Sync);
Expand Down

0 comments on commit f85e8d9

Please sign in to comment.