mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Add BufferView and BufferViewMut and fix safety issues with mapped range.
This commit is contained in:
@@ -117,7 +117,8 @@ async fn run() {
|
||||
queue.submit(Some(command_buffer));
|
||||
|
||||
// Note that we're not calling `.await` here.
|
||||
let buffer_future = output_buffer.map_async(wgpu::MapMode::Read, 0, wgt::BufferSize::WHOLE);
|
||||
let buffer_slice = output_buffer.slice(..);
|
||||
let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read);
|
||||
|
||||
// Poll the device in a blocking manner so that our future resolves.
|
||||
// In an actual application, `device.poll(...)` should
|
||||
@@ -131,7 +132,7 @@ async fn run() {
|
||||
}
|
||||
|
||||
if let Ok(()) = buffer_future.await {
|
||||
let padded_buffer = output_buffer.get_mapped_range(0, wgt::BufferSize::WHOLE);
|
||||
let padded_buffer = buffer_slice.get_mapped_range();
|
||||
|
||||
let mut png_encoder = png::Encoder::new(
|
||||
File::create("red.png").unwrap(),
|
||||
|
||||
@@ -108,7 +108,8 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
|
||||
queue.submit(Some(encoder.finish()));
|
||||
|
||||
// Note that we're not calling `.await` here.
|
||||
let buffer_future = staging_buffer.map_async(wgpu::MapMode::Read, 0, wgt::BufferSize::WHOLE);
|
||||
let buffer_slice = staging_buffer.slice(..);
|
||||
let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read);
|
||||
|
||||
// Poll the device in a blocking manner so that our future resolves.
|
||||
// In an actual application, `device.poll(...)` should
|
||||
@@ -116,7 +117,7 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
|
||||
device.poll(wgpu::Maintain::Wait);
|
||||
|
||||
if let Ok(()) = buffer_future.await {
|
||||
let data = staging_buffer.get_mapped_range(0, wgt::BufferSize::WHOLE);
|
||||
let data = buffer_slice.get_mapped_range();
|
||||
let result = data
|
||||
.chunks_exact(4)
|
||||
.map(|b| u32::from_ne_bytes(b.try_into().unwrap()))
|
||||
|
||||
Reference in New Issue
Block a user