diff options
Diffstat (limited to 'flowy/src/motion/mod.rs')
-rw-r--r-- | flowy/src/motion/mod.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/flowy/src/motion/mod.rs b/flowy/src/motion/mod.rs index cd53550..337290f 100644 --- a/flowy/src/motion/mod.rs +++ b/flowy/src/motion/mod.rs @@ -102,7 +102,7 @@ impl CommonBuffers { } } - pub fn upload(&self, queue: &Queue, params: &Params, rp: &RoundParams, buffer: &[u8]) { + pub fn upload_texture(&self, queue: &Queue, params: &Params, rp: &RoundParams, buffer: &[u8]) { queue.write_texture( ImageCopyTexture { aspect: wgpu::TextureAspect::All, @@ -119,6 +119,23 @@ impl CommonBuffers { params.extent, ); } + // pub fn upload_offsets(&self, queue: &Queue, params: &Params, rp: &RoundParams, buffer: &[u8]) { + // queue.write_texture( + // ImageCopyTexture { + // aspect: wgpu::TextureAspect::All, + // mip_level: 0, + // origin: Origin3d::ZERO, + // texture: &self.textures[rp.swap], + // }, + // buffer, + // wgpu::ImageDataLayout { + // offset: 0, + // bytes_per_row: Some(params.extent.width * 4), + // rows_per_image: Some(params.extent.height), + // }, + // params.extent, + // ); + // } pub fn prepare_texture_download( &self, @@ -148,8 +165,30 @@ impl CommonBuffers { params.extent, ); } + pub fn prepare_offsets_download(&self, encoder: &mut CommandEncoder, params: &Params) { + encoder.copy_buffer_to_buffer( + &self.offsets, + 0, + self.offsets_download.as_ref().unwrap(), + 0, + (params.blocks * size_of::<BlockOffset>()) as u64, + ); + } + + pub fn download_offsets(&self, device: &Device, buffer: &mut [u8]) { + let buffer_slice = self.offsets_download.as_ref().unwrap().slice(..); + let (sender, receiver) = oneshot::channel(); + buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap()); + device.poll(wgpu::Maintain::Wait); + receiver.recv().unwrap().unwrap(); + { + let view = buffer_slice.get_mapped_range(); + buffer.copy_from_slice(&view[..]); + } + self.offsets_download.as_ref().unwrap().unmap(); + } - pub fn download(&self, device: &Device, buffer: &mut [u8]) { + pub fn download_texture(&self, device: &Device, buffer: &mut [u8]) { let buffer_slice = self.texture_download.as_ref().unwrap().slice(..); let (sender, receiver) = oneshot::channel(); buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap()); |