Skip to content

Commit 756dd3c

Browse files
ryankaplanRyan Kaplan
andauthored
Fix bug where mapped range in WebBuffer is not cloned correctly (#8349)
Co-authored-by: Ryan Kaplan <ryan@Ryans-M2>
1 parent f0209e3 commit 756dd3c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ SamplerDescriptor {
8080

8181
### Bug Fixes
8282

83+
- 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)
84+
8385
#### General
8486

8587
- Reject fragment shader output `location`s > `max_color_attachments` limit. By @ErichDonGubler in [#8316](https://github.com/gfx-rs/wgpu/pull/8316).

wgpu/src/api/buffer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ fn range_overlaps(a: &Range<BufferAddress>, b: &Range<BufferAddress>) -> bool {
688688
a.start < b.end && b.start < a.end
689689
}
690690

691+
fn range_contains(a: &Range<BufferAddress>, b: &Range<BufferAddress>) -> bool {
692+
a.start <= b.start && a.end >= b.end
693+
}
694+
691695
#[derive(Debug, Copy, Clone)]
692696
enum RangeMappingKind {
693697
Mutable,
@@ -786,7 +790,7 @@ impl MapContext {
786790
if self.mapped_range.is_empty() {
787791
panic!("tried to call get_mapped_range(_mut) on an unmapped buffer");
788792
}
789-
if !range_overlaps(&self.mapped_range, &new_sub.index) {
793+
if !range_contains(&self.mapped_range, &new_sub.index) {
790794
panic!(
791795
"tried to call get_mapped_range(_mut) on a range that is not entirely mapped. \
792796
Attempted to get range {}, but the mapped range is {}..{}",

wgpu/src/backend/webgpu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ pub struct WebBuffer {
12211221
/// The associated GPU buffer.
12221222
inner: webgpu_sys::GpuBuffer,
12231223
/// The mapped array buffer and mapped range.
1224-
mapping: RefCell<WebBufferMapState>,
1224+
mapping: Rc<RefCell<WebBufferMapState>>,
12251225
/// Unique identifier for this Buffer.
12261226
ident: crate::cmp::Identifier,
12271227
}
@@ -1231,10 +1231,10 @@ impl WebBuffer {
12311231
fn new(inner: webgpu_sys::GpuBuffer, desc: &crate::BufferDescriptor<'_>) -> Self {
12321232
Self {
12331233
inner,
1234-
mapping: RefCell::new(WebBufferMapState {
1234+
mapping: Rc::new(RefCell::new(WebBufferMapState {
12351235
mapped_buffer: None,
12361236
range: 0..desc.size,
1237-
}),
1237+
})),
12381238
ident: crate::cmp::Identifier::create(),
12391239
}
12401240
}

0 commit comments

Comments
 (0)