Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record that the buffer is mapped when its size is zero. #2877

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -3249,14 +3249,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