mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #1239
1239: Avoid panic when requesting to unmap a buffer that is pending mapping r=kvark a=Imberflur **Connections** Fix for #1238 **Description** This might not be the cleanest fix but it is quite minimal. I'm not sure what the exact intent is with the organization of things and with the async status enum, would be happy to hear critiques. **Testing** Tested against example in #1238 <!-- Non-trivial functional changes would need to be tested through: - [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) - test the examples. - [wgpu-native](https://github.com/gfx-rs/wgpu-native/) - check the generated C header for sanity. Ideally, a PR needs to link to the draft PRs in these projects with relevant modifications. See https://github.com/gfx-rs/wgpu/pull/666 for an example. If you can add a unit/integration test here in `wgpu`, that would be best. --> Co-authored-by: Imbris <imbrisf@gmail.com>
This commit is contained in:
@@ -698,6 +698,8 @@ impl<B: GfxBackend> LifetimeTracker<B> {
|
||||
resource::BufferMapState::Idle,
|
||||
) {
|
||||
resource::BufferMapState::Waiting(pending_mapping) => pending_mapping,
|
||||
// Mapping cancelled
|
||||
resource::BufferMapState::Idle => continue,
|
||||
_ => panic!("No pending mapping."),
|
||||
};
|
||||
let status = if mapping.range.start != mapping.range.end {
|
||||
|
||||
@@ -4560,10 +4560,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buffer_unmap<B: GfxBackend>(
|
||||
fn buffer_unmap_inner<B: GfxBackend>(
|
||||
&self,
|
||||
buffer_id: id::BufferId,
|
||||
) -> Result<(), resource::BufferAccessError> {
|
||||
) -> Result<Option<BufferMapPendingCallback>, resource::BufferAccessError> {
|
||||
span!(_guard, INFO, "Device::buffer_unmap");
|
||||
|
||||
let hub = B::hub(self);
|
||||
@@ -4645,7 +4645,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
resource::BufferMapState::Idle => {
|
||||
return Err(resource::BufferAccessError::NotMapped);
|
||||
}
|
||||
resource::BufferMapState::Waiting(_) => {}
|
||||
resource::BufferMapState::Waiting(pending) => {
|
||||
return Ok(Some((pending.op, resource::BufferMapAsyncStatus::Aborted)));
|
||||
}
|
||||
resource::BufferMapState::Active {
|
||||
ptr,
|
||||
sub_range,
|
||||
@@ -4671,6 +4673,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
unmap_buffer(&device.raw, buffer)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn buffer_unmap<B: GfxBackend>(
|
||||
&self,
|
||||
buffer_id: id::BufferId,
|
||||
) -> Result<(), resource::BufferAccessError> {
|
||||
self.buffer_unmap_inner::<B>(buffer_id)
|
||||
//Note: outside inner function so no locks are held when calling the callback
|
||||
.map(|pending_callback| fire_map_callbacks(pending_callback.into_iter()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ bitflags::bitflags! {
|
||||
pub enum BufferMapAsyncStatus {
|
||||
Success,
|
||||
Error,
|
||||
Aborted,
|
||||
Unknown,
|
||||
ContextLost,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user