How to create a zero size view of a Buffer with bind groups #4090
-
I am creating a utility that copies a When the The way that I'm doing this is simple: I create a let size = vec.capacity() * std::mem::size_of::<T>();
let buffer = device.create_buffer(&BufferDescriptor {
label: ...
size: size,
usage: ...
mapped_at_creation: true,
}); And whenever the I use the But the capacity of the I can do that easily with // Calculate byte size of the Vec
let size = vec.len() * std::mem::size_of::<T>();
buffer.slice(..size) However that only works for vertex buffers and index buffers. When I try to create a bind group, I run into an issue: // Calculate byte size of the Vec
let size = vec.len() * std::mem::size_of<T>;
let bind_group = device.create_bind_group(&BindGroupDescriptor {
label: None,
layout: ...
entries: &[
BindGroupEntry {
binding: 0,
resource: BindingResource::Buffer(BufferBinding {
buffer: &buffer,
offset: 0,
size: NonZeroU64::new(size),
}),
},
],
}); In this case, if |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The simple answer is that you can't - you need to keep the buffer no smaller than the minimum binding size of the binding (which in the case of an array, is the size of a single element) |
Beta Was this translation helpful? Give feedback.
The simple answer is that you can't - you need to keep the buffer no smaller than the minimum binding size of the binding (which in the case of an array, is the size of a single element)