swapchain: Don't force release of submitted buffers

This commit is contained in:
Victoria Brekenfeld 2022-01-22 21:14:36 +01:00
parent e019b4fa9e
commit 0077a7abf6
3 changed files with 10 additions and 8 deletions

View File

@ -154,11 +154,13 @@ where
/// Mark a given buffer as submitted. /// Mark a given buffer as submitted.
/// ///
/// This might effect internal data (e.g. buffer age) and may only be called, /// This might effect internal data (e.g. buffer age) and may only be called,
/// if the buffer was actually used for display. /// the buffer may not be used for rendering anymore.
/// You may hold on to it, if you require keeping it alive.
///
/// Buffers can always just be safely discarded by dropping them, but not /// Buffers can always just be safely discarded by dropping them, but not
/// calling this function may affect performance characteristics /// calling this function before may affect performance characteristics
/// (e.g. by not tracking the buffer age). /// (e.g. by not tracking the buffer age).
pub fn submitted(&self, slot: Slot<B>) { pub fn submitted(&self, slot: &Slot<B>) {
// don't mess up the state, if the user submitted and old buffer, after e.g. a resize // don't mess up the state, if the user submitted and old buffer, after e.g. a resize
if !self.slots.iter().any(|other| Arc::ptr_eq(&slot.0, other)) { if !self.slots.iter().any(|other| Arc::ptr_eq(&slot.0, other)) {
return; return;
@ -167,7 +169,7 @@ where
slot.0.age.store(1, Ordering::SeqCst); slot.0.age.store(1, Ordering::SeqCst);
for other_slot in &self.slots { for other_slot in &self.slots {
if !Arc::ptr_eq(other_slot, &slot.0) && other_slot.buffer.is_some() { if !Arc::ptr_eq(other_slot, &slot.0) && other_slot.buffer.is_some() {
assert!(other_slot let res = other_slot
.age .age
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |age| { .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |age| {
if age > 0 { if age > 0 {
@ -175,8 +177,8 @@ where
} else { } else {
Some(0) Some(0)
} }
}) });
.is_ok()); assert!(res.is_ok());
} }
} }
} }

View File

@ -213,7 +213,6 @@ where
pub fn frame_submitted(&mut self) -> Result<(), Error> { pub fn frame_submitted(&mut self) -> Result<(), Error> {
if let Some(mut pending) = self.pending_fb.take() { if let Some(mut pending) = self.pending_fb.take() {
std::mem::swap(&mut pending, &mut self.current_fb); std::mem::swap(&mut pending, &mut self.current_fb);
self.swapchain.submitted(pending);
if self.queued_fb.is_some() { if self.queued_fb.is_some() {
self.submit()?; self.submit()?;
} }
@ -233,6 +232,7 @@ where
self.drm.page_flip([(fb, self.drm.plane())].iter(), true) self.drm.page_flip([(fb, self.drm.plane())].iter(), true)
}; };
if flip.is_ok() { if flip.is_ok() {
self.swapchain.submitted(&slot);
self.pending_fb = Some(slot); self.pending_fb = Some(slot);
} }
flip.map_err(Error::DrmError) flip.map_err(Error::DrmError)

View File

@ -123,7 +123,7 @@ impl X11Surface {
// Now present the current buffer // Now present the current buffer
let _ = pixmap.present(&*connection, window.as_ref())?; let _ = pixmap.present(&*connection, window.as_ref())?;
self.swapchain.submitted(next); self.swapchain.submitted(&next);
// Flush the connection after presenting to the window to ensure we don't run out of buffer space in the X11 connection. // Flush the connection after presenting to the window to ensure we don't run out of buffer space in the X11 connection.
let _ = connection.flush(); let _ = connection.flush();