-
I am following Wgpu without a window with the code: let buffer_slice = output_buffer.slice(..);
let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel();
buffer_slice.map_async(wgpu::MapMode::Read, move |result| {
tx.send(result).unwrap();
});
self.device.poll(wgpu::Maintain::Wait);
pollster::block_on(rx.receive()).unwrap().unwrap();
let data = buffer_slice.get_mapped_range();
use image::{ImageBuffer, Rgba};
let buffer = ImageBuffer::<Rgba<u8>, _>::from_raw(
self.size.width,
self.size.height,
data,
)
.unwrap();
buffer.save("image.png").unwrap();
output_buffer.unmap(); Now I want to abstract this to Copying the data from gpu to a host memory (buffer) and then copying again to Vec sounds unnecessary. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
Buffer
is located in GPU memory, andBufferView
is a view into that GPU memory (mapped into your programs address space, so that it can be treated as normal memory). The copy from that to theVec<u8>
would only copy the data to CPU memory once.