Skip to content

Commit ce32e47

Browse files
committed
Make get_mapped_range return a Result rather than panicking
1 parent 81eca17 commit ce32e47

File tree

57 files changed

+204
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+204
-168
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bottom level categories:
5353
#### General
5454

5555
- `Features::CLIP_DISTANCE`, `naga::Capabilities::CLIP_DISTANCE`, and `naga::BuiltIn::ClipDistance` have been renamed to `CLIP_DISTANCES` and `ClipDistances` (viz., pluralized) as appropriate, to match the WebGPU spec. By @ErichDonGubler in [#9267](https://github.com/gfx-rs/wgpu/pull/9267).
56+
- `Buffer::get_mapped_range` and variants now return `Result<_, MapRangeError>>` instead of panicking, in line with WebGPU spec. By @atlv24 in [#9281](https://github.com/gfx-rs/wgpu/pull/9281).
5657

5758
#### Validation
5859

examples/features/src/big_compute_buffers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub async fn execute_gpu_inner(
8585
let mut data = Vec::new();
8686
for staging_buffer in &staging_buffers {
8787
let slice = staging_buffer.slice(..);
88-
let mapped = slice.get_mapped_range();
88+
let mapped = slice.get_mapped_range().unwrap();
8989
data.extend_from_slice(bytemuck::cast_slice(&mapped));
9090
drop(mapped);
9191
staging_buffer.unmap();

examples/features/src/cooperative_matrix/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ async fn execute(
411411
.expect("Channel receive failed")
412412
.expect("Buffer mapping failed");
413413

414-
let data = buffer_slice.get_mapped_range();
414+
let data = buffer_slice.get_mapped_range().unwrap();
415415

416416
// Convert result back to f32 for comparison
417417
let result: Vec<f32> = if use_f16 {

examples/features/src/framework.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl<E: Example + wgpu::WasmNotSendSync> From<ExampleTestParams<E>>
735735
ctx.async_poll(wgpu::PollType::wait_indefinitely())
736736
.await
737737
.unwrap();
738-
let bytes = dst_buffer_slice.get_mapped_range().to_vec();
738+
let bytes = dst_buffer_slice.get_mapped_range().unwrap().to_vec();
739739

740740
wgpu_test::image::compare_image_output(
741741
dbg!(env!("CARGO_MANIFEST_DIR").to_string() + "/../../" + params.image_path),

examples/features/src/hello_synchronization/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ async fn get_data<T: bytemuck::Pod>(
184184
buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap());
185185
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
186186
receiver.recv_async().await.unwrap().unwrap();
187-
output.copy_from_slice(bytemuck::cast_slice(&buffer_slice.get_mapped_range()[..]));
187+
output.copy_from_slice(bytemuck::cast_slice(
188+
&buffer_slice.get_mapped_range().unwrap()[..],
189+
));
188190
staging_buffer.unmap();
189191
}
190192

examples/features/src/hello_workgroups/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ async fn get_data<T: bytemuck::Pod>(
173173
buffer_slice.map_async(wgpu::MapMode::Read, move |r| sender.send(r).unwrap());
174174
device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
175175
receiver.recv_async().await.unwrap().unwrap();
176-
output.copy_from_slice(bytemuck::cast_slice(&buffer_slice.get_mapped_range()[..]));
176+
output.copy_from_slice(bytemuck::cast_slice(
177+
&buffer_slice.get_mapped_range().unwrap()[..],
178+
));
177179
staging_buffer.unmap();
178180
}
179181

examples/features/src/mipmap/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,13 @@ impl crate::framework::Example for Example {
417417
let timestamp_view = query_sets
418418
.mapping_buffer
419419
.slice(..size_of::<TimestampQueries>() as wgpu::BufferAddress)
420-
.get_mapped_range();
420+
.get_mapped_range()
421+
.unwrap();
421422
let pipeline_stats_view = query_sets
422423
.mapping_buffer
423424
.slice(pipeline_statistics_offset()..)
424-
.get_mapped_range();
425+
.get_mapped_range()
426+
.unwrap();
425427
// Convert the raw data into a useful structure
426428
let timestamp_data: &TimestampQueries = bytemuck::from_bytes(&timestamp_view);
427429
let pipeline_stats_data: &PipelineStatisticsQueries =

examples/features/src/render_to_texture/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async fn run(_path: Option<String>) {
137137
receiver.recv_async().await.unwrap().unwrap();
138138
log::info!("Output buffer mapped.");
139139
{
140-
let view = buffer_slice.get_mapped_range();
140+
let view = buffer_slice.get_mapped_range().unwrap();
141141
texture_data.extend_from_slice(&view[..]);
142142
}
143143
log::info!("Image data copied to local.");

examples/features/src/repeated_compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async fn compute(local_buffer: &mut [u32], context: &WgpuContext) {
115115
log::info!("Result received.");
116116
// NOW we can call get_mapped_range.
117117
{
118-
let view = buffer_slice.get_mapped_range();
118+
let view = buffer_slice.get_mapped_range().unwrap();
119119
local_buffer.copy_from_slice(bytemuck::cast_slice(&view));
120120
}
121121
log::info!("Results written to local buffer.");

examples/features/src/storage_texture/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async fn run(_path: Option<String>) {
146146
receiver.recv_async().await.unwrap().unwrap();
147147
log::info!("Output buffer mapped");
148148
{
149-
let view = buffer_slice.get_mapped_range();
149+
let view = buffer_slice.get_mapped_range().unwrap();
150150
texture_data.copy_from_slice(&view[..]);
151151
}
152152
log::info!("GPU data copied to local.");

0 commit comments

Comments
 (0)