diff --git a/CHANGELOG.md b/CHANGELOG.md index a58eb8209..21dc76f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,8 @@ SamplerDescriptor { ### Bug Fixes +- Fixed bug where mapping sub-ranges of a buffer on web would fail with `OperationError: GPUBuffer.getMappedRange: GetMappedRange range extends beyond buffer's mapped range`. By @ryankaplan in [#8349](https://github.com/gfx-rs/wgpu/pull/8349) + #### General - Reject fragment shader output `location`s > `max_color_attachments` limit. By @ErichDonGubler in [#8316](https://github.com/gfx-rs/wgpu/pull/8316). diff --git a/wgpu/src/api/buffer.rs b/wgpu/src/api/buffer.rs index f38c70427..1123c5444 100644 --- a/wgpu/src/api/buffer.rs +++ b/wgpu/src/api/buffer.rs @@ -688,6 +688,10 @@ fn range_overlaps(a: &Range, b: &Range) -> bool { a.start < b.end && b.start < a.end } +fn range_contains(a: &Range, b: &Range) -> bool { + a.start <= b.start && a.end >= b.end +} + #[derive(Debug, Copy, Clone)] enum RangeMappingKind { Mutable, @@ -786,7 +790,7 @@ impl MapContext { if self.mapped_range.is_empty() { panic!("tried to call get_mapped_range(_mut) on an unmapped buffer"); } - if !range_overlaps(&self.mapped_range, &new_sub.index) { + if !range_contains(&self.mapped_range, &new_sub.index) { panic!( "tried to call get_mapped_range(_mut) on a range that is not entirely mapped. \ Attempted to get range {}, but the mapped range is {}..{}", diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 0115d4079..411fcd706 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -1221,7 +1221,7 @@ pub struct WebBuffer { /// The associated GPU buffer. inner: webgpu_sys::GpuBuffer, /// The mapped array buffer and mapped range. - mapping: RefCell, + mapping: Rc>, /// Unique identifier for this Buffer. ident: crate::cmp::Identifier, } @@ -1231,10 +1231,10 @@ impl WebBuffer { fn new(inner: webgpu_sys::GpuBuffer, desc: &crate::BufferDescriptor<'_>) -> Self { Self { inner, - mapping: RefCell::new(WebBufferMapState { + mapping: Rc::new(RefCell::new(WebBufferMapState { mapped_buffer: None, range: 0..desc.size, - }), + })), ident: crate::cmp::Identifier::create(), } }