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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Avoid internally trying to map a zero-sized buffer if mapped_at_creat…
…ion is true.
nical committed Jul 13, 2022
commit 84af28d65dc3680c8d4e00b63d22b76fddd36821
21 changes: 13 additions & 8 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {