Skip to content

Commit

Permalink
Fixing surface present issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Sep 18, 2023
1 parent 45a618f commit 88dc35c
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 566 deletions.
2 changes: 1 addition & 1 deletion deno_webgpu/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub async fn op_webgpu_buffer_get_map_async(
2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
},
callback: wgpu_core::resource::BufferMapCallback::from_rust(callback),
callback: Some(wgpu_core::resource::BufferMapCallback::from_rust(callback)),
}
))
.err();
Expand Down
4 changes: 2 additions & 2 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl Test<'_> {
expect.offset .. expect.offset+expect.data.len() as wgt::BufferAddress,
wgc::resource::BufferMapOperation {
host: wgc::device::HostMap::Read,
callback: wgc::resource::BufferMapCallback::from_rust(
callback: Some(wgc::resource::BufferMapCallback::from_rust(
Box::new(map_callback)
),
)),
}
))
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion tests/tests/mem_leaks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ fn draw_test_with_reports(
assert_eq!(report.bind_groups.num_allocated, 0);
assert_eq!(report.bind_group_layouts.num_allocated, 0);
assert_eq!(report.pipeline_layouts.num_allocated, 0);
assert_eq!(report.buffers.num_allocated, 0);
//surface is still there
assert_eq!(report.texture_views.num_allocated, 1);
assert_eq!(report.textures.num_allocated, 1);
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ pub(crate) fn clear_texture<A: HalApi>(
alignments: &hal::Alignments,
zero_buffer: &A::Buffer,
) -> Result<(), ClearError> {
let dst_raw = dst_texture
.inner
let dst_inner = dst_texture.inner();
let dst_raw = dst_inner
.as_ref()
.unwrap()
.as_raw()
Expand Down Expand Up @@ -290,7 +290,7 @@ pub(crate) fn clear_texture<A: HalApi>(
let dst_barrier = texture_tracker
.set_single(dst_texture, selector, clear_usage)
.unwrap()
.map(|pending| pending.into_hal(dst_texture));
.map(|pending| pending.into_hal(dst_inner.as_ref().unwrap()));
unsafe {
encoder.transition_textures(dst_barrier.into_iter());
}
Expand Down
6 changes: 5 additions & 1 deletion wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ impl<A: HalApi> CommandBuffer<A> {
profiling::scope!("drain_barriers");

let buffer_barriers = base.buffers.drain_transitions();
let texture_barriers = base.textures.drain_transitions();
let (transitions, textures) = base.textures.drain_transitions();
let texture_barriers = transitions
.into_iter()
.enumerate()
.map(|(i, p)| p.into_hal(textures[i].as_ref().unwrap()));

unsafe {
raw.transition_buffers(buffer_barriers);
Expand Down
25 changes: 13 additions & 12 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.textures
.set_single(dst_texture, dst_range, hal::TextureUses::COPY_DST)
.ok_or(TransferError::InvalidTexture(destination.texture))?;
let dst_raw = dst_texture
.inner
let dst_inner = dst_texture.inner();
let dst_raw = dst_inner
.as_ref()
.unwrap()
.as_raw()
Expand All @@ -812,7 +812,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
TransferError::MissingCopyDstUsageFlag(None, Some(destination.texture)).into(),
);
}
let dst_barrier = dst_pending.map(|pending| pending.into_hal(dst_texture));
let dst_barrier = dst_pending.map(|pending| pending.into_hal(dst_inner.as_ref().unwrap()));

if !dst_base.aspect.is_one() {
return Err(TransferError::CopyAspectNotOne.into());
Expand Down Expand Up @@ -932,8 +932,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.textures
.set_single(src_texture, src_range, hal::TextureUses::COPY_SRC)
.ok_or(TransferError::InvalidTexture(source.texture))?;
let src_raw = src_texture
.inner
let src_inner = src_texture.inner();
let src_raw = src_inner
.as_ref()
.unwrap()
.as_raw()
Expand All @@ -954,7 +954,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
.into());
}
let src_barrier = src_pending.map(|pending| pending.into_hal(src_texture));
let src_barrier = src_pending.map(|pending| pending.into_hal(src_inner.as_ref().unwrap()));

let (dst_buffer, dst_pending) = {
let buffer_guard = hub.buffers.read();
Expand Down Expand Up @@ -1075,9 +1075,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let src_texture = texture_guard
.get(source.texture)
.map_err(|_| TransferError::InvalidTexture(source.texture))?;
let src_inner = src_texture.inner();
let dst_texture = texture_guard
.get(destination.texture)
.map_err(|_| TransferError::InvalidTexture(source.texture))?;
let dst_inner = dst_texture.inner();

// src and dst texture format must be copy-compatible
// https://gpuweb.github.io/gpuweb/#copy-compatible
Expand Down Expand Up @@ -1139,8 +1141,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.textures
.set_single(src_texture, src_range, hal::TextureUses::COPY_SRC)
.ok_or(TransferError::InvalidTexture(source.texture))?;
let src_raw = src_texture
.inner
let src_raw = src_inner
.as_ref()
.unwrap()
.as_raw()
Expand All @@ -1152,16 +1153,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
//TODO: try to avoid this the collection. It's needed because both
// `src_pending` and `dst_pending` try to hold `trackers.textures` mutably.
let mut barriers: ArrayVec<_, 2> = src_pending
.map(|pending| pending.into_hal(src_texture))
.map(|pending| pending.into_hal(src_inner.as_ref().unwrap()))
.collect();

let dst_pending = cmd_buf_data
.trackers
.textures
.set_single(dst_texture, dst_range, hal::TextureUses::COPY_DST)
.ok_or(TransferError::InvalidTexture(destination.texture))?;
let dst_raw = dst_texture
.inner
let dst_raw = dst_inner
.as_ref()
.unwrap()
.as_raw()
Expand All @@ -1172,7 +1172,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
}

barriers.extend(dst_pending.map(|pending| pending.into_hal(dst_texture)));
barriers.extend(dst_pending.map(|pending| pending.into_hal(dst_inner.as_ref().unwrap())));

let hal_copy_size = hal::CopyExtent {
width: src_copy_size.width.min(dst_copy_size.width),
Expand Down Expand Up @@ -1200,6 +1200,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
regions,
);
}

Ok(())
}
}
15 changes: 9 additions & 6 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
resource::TextureClearMode::None => SmallVec::new(),
};

match *texture.inner.as_ref().unwrap() {
match *texture.inner().as_ref().unwrap() {
resource::TextureInner::Native { ref raw } => {
if !raw.is_none() {
let temp = queue::TempResource::Texture(texture.clone(), clear_views);
Expand Down Expand Up @@ -2186,9 +2186,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// User callbacks must not be called while holding buffer_map_async_inner's locks, so we
// defer the error callback if it needs to be called immediately (typically when running
// into errors).
if let Err((op, err)) = self.buffer_map_async_inner::<A>(buffer_id, range, op) {
op.callback.call(Err(err.clone()));

if let Err((mut operation, err)) = self.buffer_map_async_inner::<A>(buffer_id, range, op) {
if let Some(callback) = operation.callback.take() {
callback.call(Err(err.clone()));
}
return Err(err);
}

Expand Down Expand Up @@ -2370,8 +2371,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

// Note: outside the scope where locks are held when calling the callback
if let Some((operation, status)) = closure? {
operation.callback.call(status);
if let Some((mut operation, status)) = closure? {
if let Some(callback) = operation.callback.take() {
callback.call(status);
}
}
Ok(())
}
Expand Down
Loading

0 comments on commit 88dc35c

Please sign in to comment.