Use a StagingBelt in iced_wgpu for regular buffer uploads

This commit is contained in:
Héctor Ramón Jiménez 2024-03-29 04:02:24 +01:00
parent 1df1cf82f4
commit 2bb53ad6e7
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F
10 changed files with 113 additions and 41 deletions

View file

@ -61,12 +61,22 @@ impl<T: bytemuck::Pod> Buffer<T> {
/// Returns the size of the written bytes.
pub fn write(
&mut self,
queue: &wgpu::Queue,
device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
belt: &mut wgpu::util::StagingBelt,
offset: usize,
contents: &[T],
) -> usize {
let bytes: &[u8] = bytemuck::cast_slice(contents);
queue.write_buffer(&self.raw, offset as u64, bytes);
belt.write_buffer(
encoder,
&self.raw,
offset as u64,
(bytes.len() as u64).try_into().expect("Non-empty write"),
device,
)
.copy_from_slice(bytes);
self.offsets.push(offset as u64);