Skip to content

Commit 2c67f79

Browse files
authored
Remove resources ONLY when needed inside wgpu and not in user land (#4782)
1 parent 4f24c31 commit 2c67f79

File tree

10 files changed

+38
-126
lines changed

10 files changed

+38
-126
lines changed

tests/tests/zero_init_texture_after_discard.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ static DISCARDING_COLOR_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_A
1313
let mut case = TestCase::new(&mut ctx, TextureFormat::Rgba8UnormSrgb);
1414
case.create_command_encoder();
1515
case.discard();
16+
case.submit_command_encoder();
17+
18+
case.create_command_encoder();
1619
case.copy_texture_to_buffer();
17-
case.submit_command_encoder_and_wait();
20+
case.submit_command_encoder();
1821

1922
case.assert_buffers_are_zero();
2023
});
@@ -28,7 +31,7 @@ static DISCARDING_COLOR_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_I
2831
case.create_command_encoder();
2932
case.discard();
3033
case.copy_texture_to_buffer();
31-
case.submit_command_encoder_and_wait();
34+
case.submit_command_encoder();
3235

3336
case.assert_buffers_are_zero();
3437
});
@@ -55,7 +58,7 @@ static DISCARDING_DEPTH_TARGET_RESETS_TEXTURE_INIT_STATE_CHECK_VISIBLE_ON_COPY_I
5558
case.create_command_encoder();
5659
case.discard();
5760
case.copy_texture_to_buffer();
58-
case.submit_command_encoder_and_wait();
61+
case.submit_command_encoder();
5962

6063
case.assert_buffers_are_zero();
6164
}
@@ -70,13 +73,7 @@ static DISCARDING_EITHER_DEPTH_OR_STENCIL_ASPECT_TEST: GpuTestConfiguration =
7073
DownlevelFlags::DEPTH_TEXTURE_AND_BUFFER_COPIES
7174
| DownlevelFlags::COMPUTE_SHADERS,
7275
)
73-
.limits(Limits::downlevel_defaults())
74-
// https://github.com/gfx-rs/wgpu/issues/4740
75-
.expect_fail(
76-
FailureCase::backend_adapter(Backends::VULKAN, "llvmpipe")
77-
.panic("texture was not fully cleared")
78-
.flaky(),
79-
),
76+
.limits(Limits::downlevel_defaults()),
8077
)
8178
.run_sync(|mut ctx| {
8279
for format in [
@@ -89,9 +86,15 @@ static DISCARDING_EITHER_DEPTH_OR_STENCIL_ASPECT_TEST: GpuTestConfiguration =
8986
let mut case = TestCase::new(&mut ctx, format);
9087
case.create_command_encoder();
9188
case.discard_depth();
89+
case.submit_command_encoder();
90+
91+
case.create_command_encoder();
9292
case.discard_stencil();
93+
case.submit_command_encoder();
94+
95+
case.create_command_encoder();
9396
case.copy_texture_to_buffer();
94-
case.submit_command_encoder_and_wait();
97+
case.submit_command_encoder();
9598

9699
case.assert_buffers_are_zero();
97100
}
@@ -209,11 +212,10 @@ impl<'ctx> TestCase<'ctx> {
209212
)
210213
}
211214

212-
pub fn submit_command_encoder_and_wait(&mut self) {
215+
pub fn submit_command_encoder(&mut self) {
213216
self.ctx
214217
.queue
215218
.submit([self.encoder.take().unwrap().finish()]);
216-
self.ctx.device.poll(MaintainBase::Wait);
217219
}
218220

219221
pub fn discard(&mut self) {

wgpu-core/src/device/global.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
20042004
// Wait for all work to finish before configuring the surface.
20052005
let fence = device.fence.read();
20062006
let fence = fence.as_ref().unwrap();
2007-
match device.maintain(hub, fence, wgt::Maintain::Wait) {
2007+
match device.maintain(fence, wgt::Maintain::Wait) {
20082008
Ok((closures, _)) => {
20092009
user_callbacks = closures;
20102010
}
@@ -2074,7 +2074,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
20742074
return Err(InvalidDevice);
20752075
}
20762076
device.lock_life().triage_suspected(
2077-
hub,
20782077
&device.trackers,
20792078
#[cfg(feature = "trace")]
20802079
None,
@@ -2109,7 +2108,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
21092108
.map_err(|_| DeviceError::Invalid)?;
21102109
let fence = device.fence.read();
21112110
let fence = fence.as_ref().unwrap();
2112-
device.maintain(hub, fence, maintain)?
2111+
device.maintain(fence, maintain)?
21132112
};
21142113

21152114
closures.fire();
@@ -2143,7 +2142,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
21432142
};
21442143
let fence = device.fence.read();
21452144
let fence = fence.as_ref().unwrap();
2146-
let (cbs, queue_empty) = device.maintain(hub, fence, maintain)?;
2145+
let (cbs, queue_empty) = device.maintain(fence, maintain)?;
21472146
all_queue_empty = all_queue_empty && queue_empty;
21482147

21492148
closures.extend(cbs);

0 commit comments

Comments
 (0)