Skip to content

Commit

Permalink
Remove resources ONLY when needed inside wgpu and not in user land (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Nov 27, 2023
1 parent 4f24c31 commit 2c67f79
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 126 deletions.
28 changes: 15 additions & 13 deletions tests/tests/zero_init_texture_after_discard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ static DISCARDING_COLOR_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_A
let mut case = TestCase::new(&mut ctx, TextureFormat::Rgba8UnormSrgb);
case.create_command_encoder();
case.discard();
case.submit_command_encoder();

case.create_command_encoder();
case.copy_texture_to_buffer();
case.submit_command_encoder_and_wait();
case.submit_command_encoder();

case.assert_buffers_are_zero();
});
Expand All @@ -28,7 +31,7 @@ static DISCARDING_COLOR_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_I
case.create_command_encoder();
case.discard();
case.copy_texture_to_buffer();
case.submit_command_encoder_and_wait();
case.submit_command_encoder();

case.assert_buffers_are_zero();
});
Expand All @@ -55,7 +58,7 @@ static DISCARDING_DEPTH_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_I
case.create_command_encoder();
case.discard();
case.copy_texture_to_buffer();
case.submit_command_encoder_and_wait();
case.submit_command_encoder();

case.assert_buffers_are_zero();
}
Expand All @@ -70,13 +73,7 @@ static DISCARDING_EITHER_DEPTH_OR_STENCIL_ASPECT_TEST: GpuTestConfiguration =
DownlevelFlags::DEPTH_TEXTURE_AND_BUFFER_COPIES
| DownlevelFlags::COMPUTE_SHADERS,
)
.limits(Limits::downlevel_defaults())
// https://github.com/gfx-rs/wgpu/issues/4740
.expect_fail(
FailureCase::backend_adapter(Backends::VULKAN, "llvmpipe")
.panic("texture was not fully cleared")
.flaky(),
),
.limits(Limits::downlevel_defaults()),
)
.run_sync(|mut ctx| {
for format in [
Expand All @@ -89,9 +86,15 @@ static DISCARDING_EITHER_DEPTH_OR_STENCIL_ASPECT_TEST: GpuTestConfiguration =
let mut case = TestCase::new(&mut ctx, format);
case.create_command_encoder();
case.discard_depth();
case.submit_command_encoder();

case.create_command_encoder();
case.discard_stencil();
case.submit_command_encoder();

case.create_command_encoder();
case.copy_texture_to_buffer();
case.submit_command_encoder_and_wait();
case.submit_command_encoder();

case.assert_buffers_are_zero();
}
Expand Down Expand Up @@ -209,11 +212,10 @@ impl<'ctx> TestCase<'ctx> {
)
}

pub fn submit_command_encoder_and_wait(&mut self) {
pub fn submit_command_encoder(&mut self) {
self.ctx
.queue
.submit([self.encoder.take().unwrap().finish()]);
self.ctx.device.poll(MaintainBase::Wait);
}

pub fn discard(&mut self) {
Expand Down
7 changes: 3 additions & 4 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
// Wait for all work to finish before configuring the surface.
let fence = device.fence.read();
let fence = fence.as_ref().unwrap();
match device.maintain(hub, fence, wgt::Maintain::Wait) {
match device.maintain(fence, wgt::Maintain::Wait) {
Ok((closures, _)) => {
user_callbacks = closures;
}
Expand Down Expand Up @@ -2074,7 +2074,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
return Err(InvalidDevice);
}
device.lock_life().triage_suspected(
hub,
&device.trackers,
#[cfg(feature = "trace")]
None,
Expand Down Expand Up @@ -2109,7 +2108,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_err(|_| DeviceError::Invalid)?;
let fence = device.fence.read();
let fence = fence.as_ref().unwrap();
device.maintain(hub, fence, maintain)?
device.maintain(fence, maintain)?
};

closures.fire();
Expand Down Expand Up @@ -2143,7 +2142,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
let fence = device.fence.read();
let fence = fence.as_ref().unwrap();
let (cbs, queue_empty) = device.maintain(hub, fence, maintain)?;
let (cbs, queue_empty) = device.maintain(fence, maintain)?;
all_queue_empty = all_queue_empty && queue_empty;

closures.extend(cbs);
Expand Down
Loading

0 comments on commit 2c67f79

Please sign in to comment.