diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index f322c5f38b..bd813adcb0 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -494,5 +494,6 @@ gamescope returned the buffer to the client on that release, and a client whose fences attached to a dma-buf then drew into it while the display was still scanning it out, which showed as black tiles in compressed buffers. A forwarded client buffer now stays held until `poll(POLLOUT)` on its dma-buf reports that the display has finished with it, on a waiter thread so nothing else blocks. A release that arrives after the -buffer was shown again is dropped, so the later release decides. Composite output images keep the 0146 path, and a +buffer was shown again is dropped, so the later release decides. A pending wait holds its own reference on the +buffer, since that later release can drop the host's reference before the wait ends. Composite output images keep the 0146 path, and a host that waits for the fence itself releases buffers that are already idle, so nothing changes there. diff --git a/tools/gamescope/patches/0147-forwarded-buffers-wait-for-scanout.patch b/tools/gamescope/patches/0147-forwarded-buffers-wait-for-scanout.patch index 928f1ba9b0..61e3af5b09 100644 --- a/tools/gamescope/patches/0147-forwarded-buffers-wait-for-scanout.patch +++ b/tools/gamescope/patches/0147-forwarded-buffers-wait-for-scanout.patch @@ -1,5 +1,5 @@ diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp -index 12f0f50..a0fedd4 100644 +index 12f0f50..d9db2e6 100644 --- a/src/Backends/WaylandBackend.cpp +++ b/src/Backends/WaylandBackend.cpp @@ -3,24 +3,28 @@ @@ -31,7 +31,7 @@ index 12f0f50..a0fedd4 100644 #include #include "wlr_begin.hpp" -@@ -485,44 +489,82 @@ namespace gamescope +@@ -485,44 +489,86 @@ namespace gamescope // One backing plane plus every layer steamcompmgr can hand us. CWaylandPlane m_Planes[k_nMaxLayers + 1]; @@ -78,8 +78,12 @@ index 12f0f50..a0fedd4 100644 + , m_nFd{ nFd } + , m_ulAcquireSerial{ ulAcquireSerial } + { ++ // A later acquire and release can drop the compositor's reference before this wait ends. ++ m_pFb->IncRef(); + } + ++ ~CWaylandScanoutRelease() { m_pFb->DecRef(); } ++ + int GetFD() override { return m_nFd; } + void OnPollOut() override { Finish(); } + void OnPollHangUp() override { Finish(); } @@ -115,7 +119,7 @@ index 12f0f50..a0fedd4 100644 ~CWaylandInputThread(); bool Init( CWaylandBackend *pBackend ); -@@ -969,73 +1011,108 @@ namespace gamescope +@@ -969,73 +1015,108 @@ namespace gamescope .action = WAYLAND_NULL(), }; const zwp_primary_selection_source_v1_listener CWaylandBackend::s_PrimarySelectionSourceListener = @@ -235,7 +239,7 @@ index 12f0f50..a0fedd4 100644 , m_pBackend( pBackend ) , m_Planes{ this, this, this, this, this, this, this, this, this } { -@@ -2349,25 +2426,26 @@ namespace gamescope +@@ -2349,25 +2430,26 @@ namespace gamescope pDmaBuf->format, 0u ); diff --git a/tools/tests/test_gamescope_forwarded_buffer_scanout.py b/tools/tests/test_gamescope_forwarded_buffer_scanout.py index 77e6f32a30..79a581407f 100644 --- a/tools/tests/test_gamescope_forwarded_buffer_scanout.py +++ b/tools/tests/test_gamescope_forwarded_buffer_scanout.py @@ -136,10 +136,21 @@ int main( int argc, char **argv ) { assert( fb.refs == 2 ); d.scanning(); fb.Wayland_Buffer_Release( fb.m_pHostBuffer ); - assert( fb.refs == 2 && fb.m_bCompositorAcquired ); + assert( fb.refs == 3 && fb.m_bCompositorAcquired ); d.done(); fire(); assert( fb.refs == 1 && !fb.m_bCompositorAcquired && xdg_log.oh_no == 0 ); + } else if ( which == "stale-wait-keeps-buffer" ) { + fb.client = true; + fb.OnCompositorAcquire(); + d.scanning(); + fb.Wayland_Buffer_Release( fb.m_pHostBuffer ); + fb.OnCompositorAcquire(); + d.done(); + fb.Wayland_Buffer_Release( fb.m_pHostBuffer ); + assert( fb.refs == 2 && !fb.m_bCompositorAcquired ); + fire(); + assert( fb.refs == 1 && xdg_log.oh_no == 0 ); } else if ( which == "client-idle" ) { fb.client = true; fb.OnCompositorAcquire(); @@ -214,6 +225,9 @@ class ForwardedBufferScanoutTest(unittest.TestCase): def test_buffer_shown_again_waits_for_its_next_release(self): self.scenario("shown-again") + def test_pending_wait_keeps_the_buffer_after_a_later_release(self): + self.scenario("stale-wait-keeps-buffer") + def test_buffer_without_dmabuf_is_released_at_once(self): self.scenario("no-dmabuf")