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

Remove resources ONLY when needed inside wgpu and not in user land #4782

Merged
merged 5 commits into from
Nov 27, 2023
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
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
Loading