Skip to content

Commit

Permalink
Record that the buffer is mapped when its size is zero. (#2877)
Browse files Browse the repository at this point in the history
* Record that the buffer is mapped when its size is zero.

* Avoid internally trying to map a zero-sized buffer if mapped_at_creation is true.

* Add an entry in the changelog.
  • Loading branch information
nical authored and cwfitzgerald committed Jul 14, 2022
1 parent 8cff4a0 commit 9a8229a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Bottom level categories:
- Fix bind group / pipeline deduplication not taking into account RenderBundle execution resetting these values by @shoebe [#2867](https://github.com/gfx-rs/wgpu/pull/2867)
- Fix panics that occur when using `as_hal` functions when the hal generic type does not match the hub being looked up in by @i509VCB [#2871](https://github.com/gfx-rs/wgpu/pull/2871)
- Add some validation in map_async by @nical in [#2876](https://github.com/gfx-rs/wgpu/pull/2876)
- Fix bugs when mapping/unmapping zero-sized buffers and ranges by @nical in [#2877](https://github.com/gfx-rs/wgpu/pull/2877)

#### DX12
- `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851)
Expand Down
5 changes: 5 additions & 0 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,11 @@ impl<A: HalApi> LifetimeTracker<A> {
}
}
} else {
buffer.map_state = resource::BufferMapState::Active {
ptr: std::ptr::NonNull::dangling(),
range: mapping.range,
host: mapping.op.host,
};
resource::BufferMapAsyncStatus::Success
};
pending_callbacks.push((mapping.op, status));
Expand Down
21 changes: 13 additions & 8 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3247,14 +3247,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} else if desc.usage.contains(wgt::BufferUsages::MAP_WRITE) {
// buffer is mappable, so we are just doing that at start
let map_size = buffer.size;
let ptr = match map_buffer(&device.raw, &mut buffer, 0, map_size, HostMap::Write) {
Ok(ptr) => ptr,
Err(e) => {
let raw = buffer.raw.unwrap();
device
.lock_life(&mut token)
.schedule_resource_destruction(queue::TempResource::Buffer(raw), !0);
break e.into();
let ptr = if map_size == 0 {
std::ptr::NonNull::dangling()
} else {
match map_buffer(&device.raw, &mut buffer, 0, map_size, HostMap::Write) {
Ok(ptr) => ptr,
Err(e) => {
let raw = buffer.raw.unwrap();
device.lock_life(&mut token).schedule_resource_destruction(
queue::TempResource::Buffer(raw),
!0,
);
break e.into();
}
}
};
buffer.map_state = resource::BufferMapState::Active {
Expand Down

0 comments on commit 9a8229a

Please sign in to comment.