Skip to content

Commit

Permalink
Remove TextureInner::Surface::has_work.
Browse files Browse the repository at this point in the history
When no work is submitted for a frame, presenting the surface results
in a timeout due to no work having been submitted.

Fixes gfx-rs#3189.

This flag was added in gfx-rs#1892 with a note that it was going to be
temporary until gfx-rs#1688 landed.
  • Loading branch information
waywardmonkeys committed Feb 5, 2024
1 parent b7b7f7d commit d348866
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Bottom level categories:
- Fix the validation of vertex and index ranges. By @nical in [#5144](https://github.com/gfx-rs/wgpu/pull/5144) and [#5156](https://github.com/gfx-rs/wgpu/pull/5156)
- Device lost callbacks are invoked when replaced and when global is dropped. By @bradwerth in [#5168](https://github.com/gfx-rs/wgpu/pull/5168)
- Fix panic when creating a surface while no backend is available. By @wumpf [#5166](https://github.com/gfx-rs/wgpu/pull/5166)
- Fix timeout when presenting a surface where no work has been done. By @waywardmonkeys in [#5200](https://github.com/gfx-rs/wgpu/pull/5200)

#### WGL

Expand Down
16 changes: 2 additions & 14 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,13 +1222,7 @@ impl Global {
return Err(QueueSubmitError::DestroyedTexture(id));
}
Some(TextureInner::Native { .. }) => false,
Some(TextureInner::Surface {
ref has_work,
ref raw,
..
}) => {
has_work.store(true, Ordering::Relaxed);

Some(TextureInner::Surface { ref raw, .. }) => {
if raw.is_some() {
submit_surface_textures_owned.push(texture.clone());
}
Expand Down Expand Up @@ -1423,13 +1417,7 @@ impl Global {
return Err(QueueSubmitError::DestroyedTexture(id));
}
Some(TextureInner::Native { .. }) => {}
Some(TextureInner::Surface {
ref has_work,
ref raw,
..
}) => {
has_work.store(true, Ordering::Relaxed);

Some(TextureInner::Surface { ref raw, .. }) => {
if raw.is_some() {
submit_surface_textures_owned.push(texture.clone());
}
Expand Down
17 changes: 2 additions & 15 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ When this texture is presented, we remove it from the device tracker as well as
extract it from the hub.
!*/

use std::{
borrow::Borrow,
sync::atomic::{AtomicBool, Ordering},
};
use std::borrow::Borrow;

#[cfg(feature = "trace")]
use crate::device::trace::Action;
Expand Down Expand Up @@ -213,7 +210,6 @@ impl Global {
inner: Snatchable::new(resource::TextureInner::Surface {
raw: Some(ast.texture),
parent_id: surface_id,
has_work: AtomicBool::new(false),
}),
device: device.clone(),
desc: texture_desc,
Expand Down Expand Up @@ -331,15 +327,10 @@ impl Global {
resource::TextureInner::Surface {
ref mut raw,
ref parent_id,
ref has_work,
} => {
if surface_id != *parent_id {
log::error!("Presented frame is from a different surface");
Err(hal::SurfaceError::Lost)
} else if !has_work.load(Ordering::Relaxed) {
log::error!("No work has been submitted for this frame");
unsafe { suf.unwrap().discard_texture(raw.take().unwrap()) };
Err(hal::SurfaceError::Outdated)
} else {
unsafe {
queue
Expand Down Expand Up @@ -420,11 +411,7 @@ impl Global {
let suf = A::get_surface(&surface);
let exclusive_snatch_guard = device.snatchable_lock.write();
match texture.inner.snatch(exclusive_snatch_guard).unwrap() {
resource::TextureInner::Surface {
mut raw,
parent_id,
has_work: _,
} => {
resource::TextureInner::Surface { mut raw, parent_id } => {
if surface_id == parent_id {
unsafe { suf.unwrap().discard_texture(raw.take().unwrap()) };
} else {
Expand Down
3 changes: 1 addition & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::{
ops::Range,
ptr::NonNull,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
atomic::{AtomicUsize, Ordering},
Arc, Weak,
},
};
Expand Down Expand Up @@ -736,7 +736,6 @@ pub(crate) enum TextureInner<A: HalApi> {
Surface {
raw: Option<A::SurfaceTexture>,
parent_id: SurfaceId,
has_work: AtomicBool,
},
}

Expand Down

0 comments on commit d348866

Please sign in to comment.