gfx-rs / wgpu-rs

Rust bindings to wgpu native library
https://wgpu.rs
Mozilla Public License 2.0
1.69k stars 186 forks source link

Add Buffer::len to get length? #869

Closed dhardy closed 3 years ago

dhardy commented 3 years ago

In some cases a wgpu::Buffer may be re-used, e.g. to upload the next frame's vertices. In such cases it's necessary to check the buffer length and recreate (or partition or ...) if the length is insufficient. Currently it's not really possible to do this (except perhaps via buffer.slice(..).get_mapped_range().len()).

Solutions:

  1. Expect the user to track the buffer length (status quo). Note that this is hard to do accurately since create_buffer_init may add padding, though ignoring this is acceptable.
  2. Add Buffer::len as a wrapper around the above
  3. Add length field (u32?) to Buffer

I think the last option is probably the best choice?

Slightly off-topic question: why are lengths sometimes u32 (e.g. in RenderPass::draw) and sometimes 64-bit (e.g. BufferSize)? Are buffers larger than u32::MAX supported?

kvark commented 3 years ago

This is a part of the upstream issue https://github.com/gpuweb/gpuweb/issues/1498

We don't want to include the buffer size as an exception. We want a solid approach here, where the line between what we include and what we don't is clear.

why are lengths sometimes u32

Yes, buffers can be larger than u32.

cwfitzgerald commented 3 years ago

Closing because this upstream issue will likely be resolved as is.