Add Buffer::len to get length?
dhardy opened this issue · 2 comments
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:
- 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. - Add
Buffer::len
as a wrapper around the above - Add length field (
u32
?) toBuffer
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?
This is a part of the upstream issue gpuweb/gpuweb#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.
Closing because this upstream issue will likely be resolved as is.