Compare commits

..
Author SHA1 Message Date
maxjivi05 544a28518e fix(display): limit the modifier-layout guard to layer buffers so client dma-buf imports keep main's path 2026-12-01 14:06:26 -05:00
maxjivi05 577824383d Merge remote-tracking branch 'droiddeck/main' into fix/adreno720-screen-corruption 2026-12-01 09:11:30 -05:00
MaxsTechReview bf772b7c55 ci(desktop): build KWin 6.8.3 to match the Arch Linux ARM package (#3526) 2026-12-01 09:09:51 -05:00
maxjivi05 2ce59fe0c2 Merge remote-tracking branch 'droiddeck/main' into fix/adreno720-screen-corruption 2026-12-01 08:43:49 -05:00
MaxsTechReview 29b04b66eb fix(gamescope): hold forwarded client buffers until the display finished scanning them out (#3516)
* Return a forwarded client buffer to its client only after the display finished scanning it out

* Test that a forwarded client buffer waits for scanout and composite images do not

* Pin the gamescope build that holds forwarded client buffers until scanout ends
2026-12-01 06:02:16 -05:00
The412Banner ceb4c18531 fix(display): UBWC layer buffers fall back to linear on drivers without explicit modifier layouts 2026-11-26 17:15:24 +00:00
15 changed files with 657 additions and 36 deletions

No files matched your search

@@ -8,6 +8,10 @@ static inline int vkp_linear_dmabuf_through_buffer(int drm_modifiers, uint64_t m
return !drm_modifiers && modifier == 0 && !blit_dst;
}
static inline int vkp_dmabuf_layout_describable(int drm_modifiers, uint64_t modifier) {
return drm_modifiers || modifier == 0;
}
static inline int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) {
return dmabuf && !staged;
}
@@ -1834,6 +1834,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
uint32_t stride, uint32_t offset, int as_blit_dst) {
if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL;
if (dev_init() != 0) return NULL;
if (as_blit_dst && !vkp_dmabuf_layout_describable(g_drm_modifiers, modifier)) {
LOGE("layer: the driver has no VK_EXT_image_drm_format_modifier to lay out the %s %dx%d dma-buf",
vkp_modifier_name(modifier), w, h);
return NULL;
}
const VkFormat format = drm_to_vk(drm_format);
const int padded_target = as_blit_dst &&
@@ -275,7 +275,6 @@ public final class LinuxRuntime {
}
}
String[][] seeded = {
{"filesystems", ""},
{"file-max", "9223372036854775807\n"},
{"overcommit_memory", "0\n"},
};
@@ -288,7 +287,6 @@ public final class LinuxRuntime {
}
}
String[][] procFiles = {
{"filesystems", "/proc/filesystems"},
{"pci_devices", "/proc/bus/pci/devices"},
{"stat", "/proc/stat"},
{"version", "/proc/version"},
@@ -4,8 +4,6 @@ import android.content.ContextWrapper
import java.io.File
import java.nio.file.Files
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -37,26 +35,4 @@ class LinuxRuntimeProcFilesTest {
LinuxRuntime.binds(context, null, null, null, null)
assertEquals("1\n", File(fakeProc, "overcommit_memory").readText())
}
@Test fun restrictedFilesystemsHaveAConservativeFallback() {
val binds = LinuxRuntime.binds(context, null, null, null, null)
val fallback = File(fakeProc, "filesystems")
assertEquals("", fallback.readText())
assertEquals(!File("/proc/filesystems").canRead(), binds.contains("${fallback.path}:/proc/filesystems"))
assertTrue(binds.contains("/proc"))
assertFalse(binds.any { it.endsWith(":/proc/self/status") })
}
@Test fun explicitFilesystemsBindingWins() {
val source = File(root, "supported-fs").apply { writeText("nodev\ttmpfs\n") }
val explicit = "${source.path}:/proc/filesystems"
val binds = LinuxRuntime.binds(context, null, null, null, listOf(explicit))
assertEquals(listOf(explicit), binds.filter { it.endsWith(":/proc/filesystems") })
}
@Test fun existingFilesystemsDataIsPreserved() {
val fallback = File(fakeProc, "filesystems").apply { parentFile!!.mkdirs(); writeText("nodev\ttmpfs\n") }
LinuxRuntime.binds(context, null, null, null, null)
assertEquals("nodev\ttmpfs\n", fallback.readText())
}
}
+1 -1
View File
@@ -71,7 +71,7 @@ both build jobs verify the Arch Linux ARM signature and pinned SHA-256 as for ev
The desktop workflow replaces the same-version `kwin_wayland` executable and `libkwin.so`; the rest
comes from the signature-checked Arch packages. `desktop-kde.kwin.txt` records the source, patch,
executable, library and build package hashes. Corresponding source is
https://download.kde.org/stable/plasma/6.8.2/kwin-6.8.2.tar.xz plus the patch in this repository.
https://download.kde.org/stable/plasma/6.8.3/kwin-6.8.3.tar.xz plus the patch in this repository.
The inventories use `.gzip` rather than `.gz`: Android's asset packer expands `.gz` and strips
its suffix. The shared local/CI runtime payload check verifies the exact APK names and bytes.
+1 -1
View File
@@ -6,7 +6,7 @@ here=$(cd "$(dirname "$0")" && pwd)
source "$here/kwin.env"
source "$here/mesa.env"
version=$DESKTOP_KWIN_VERSION
source_sha=ea5e68d957c7d70abed97222a592d4445fda29129e20942658badd224ee138b4
source_sha=fd5cb783f220ea4526a9afee2f72b582c3e87ef7f91b19bc5c7a6662ffe7fbdc
mirror=https://fl.us.mirror.archlinuxarm.org/aarch64
builder=68B3537F39A313B3E574D06777193F152BDBE6A6
work=$(mktemp -d)
+1 -1
View File
@@ -1 +1 @@
DESKTOP_KWIN_VERSION=6.8.2
DESKTOP_KWIN_VERSION=6.8.3
@@ -8,8 +8,8 @@ Third-party files in DroidDeck's KDE desktop package (tools/desktop-kde/overlay)
- steam.svg: Papirus icon theme (https://github.com/PapirusDevelopmentTeam/papirus-icon-theme),
GPL-3.0.
- kwin_wayland: KWin 6.8.2, GPL-2.0-or-later. Built with DroidDeck's nested desktop scale patch.
Corresponding source: https://download.kde.org/stable/plasma/6.8.2/kwin-6.8.2.tar.xz and
- kwin_wayland: KWin 6.8.3, GPL-2.0-or-later. Built with DroidDeck's nested desktop scale patch.
Corresponding source: https://download.kde.org/stable/plasma/6.8.3/kwin-6.8.3.tar.xz and
https://github.com/Droid-Deck/DroidDeck/tree/fix/kde-desktop-followups/tools/desktop-kde/patches
(the source and patch hashes are recorded in desktop-kde.kwin.txt beside the package).
+11
View File
@@ -485,3 +485,14 @@ not wait on fences attached to a dma-buf, so the composite now checks each outpu
It picks the next image that is neither held by the host nor still being scanned out. Only when every free image is
still on the display does it wait for one, up to 100 ms. On kernels that cannot attach the fence, the host keeps
waiting itself and nothing changes. `tools/gamescope/tests/nested-swapchain.cpp` covers the choice and the busy check.
## 0147 Wayland backend: a forwarded client buffer goes back to its client only after scanout
When no composite is needed, gamescope hands a client's own buffer to the host compositor as a plane. The host now
releases a buffer as soon as the display latches the next one and leaves its release fence on the buffer's dma-buf.
gamescope returned the buffer to the client on that release, and a client whose Vulkan driver does not wait on
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
host that waits for the fence itself releases buffers that are already idle, so nothing changes there.
@@ -0,0 +1,351 @@
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
index 12f0f50..a0fedd4 100644
--- a/src/Backends/WaylandBackend.cpp
+++ b/src/Backends/WaylandBackend.cpp
@@ -3,24 +3,28 @@
#include "wlserver.hpp"
#include "vblankmanager.hpp"
#include "steamcompmgr.hpp"
#include "edid.h"
#include "Utils/Defer.h"
#include "Utils/Algorithm.h"
#include "convar.h"
#include "refresh_rate.h"
#include "waitable.h"
#include "Utils/TempFiles.h"
#include "Utils/CursorRouting.h"
#include "Utils/WaylandScaling.h"
+#include "output_image_pick.hpp"
+
+#include <fcntl.h>
+#include <mutex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <csignal>
#include <sys/mman.h>
#include <poll.h>
#include <linux/input-event-codes.h>
#include <xkbcommon/xkbcommon.h>
#include <libdecor.h>
#include "wlr_begin.hpp"
@@ -485,44 +489,82 @@ namespace gamescope
// One backing plane plus every layer steamcompmgr can hand us.
CWaylandPlane m_Planes[k_nMaxLayers + 1];
bool m_bVisible = true;
std::atomic<bool> m_bDesiredFullscreenState = { false };
bool m_bHostCompositorIsCurrentlyVRR = false;
};
class CWaylandFb final : public CBaseBackendFb
{
public:
- CWaylandFb( CWaylandBackend *pBackend, wl_buffer *pHostBuffer );
+ CWaylandFb( CWaylandBackend *pBackend, wl_buffer *pHostBuffer, int nDmabufFd = -1 );
~CWaylandFb();
void OnCompositorAcquire();
void OnCompositorRelease();
+ void OnScanoutDone( uint64_t ulAcquireSerial );
wl_buffer *GetHostBuffer() const { return m_pHostBuffer; }
wlr_buffer *GetClientBuffer() const { return m_pClientBuffer; }
bool HeldByHost() const override { return m_bCompositorAcquired; }
void Wayland_Buffer_Release( wl_buffer *pBuffer );
static const wl_buffer_listener s_BufferListener;
private:
CWaylandBackend *m_pBackend = nullptr;
wl_buffer *m_pHostBuffer = nullptr;
wlr_buffer *m_pClientBuffer = nullptr;
+ int m_nDmabufFd = -1;
+ std::mutex m_AcquireMutex;
+ uint64_t m_ulAcquireSerial = 0;
bool m_bCompositorAcquired = false;
};
+
+ class CWaylandScanoutRelease final : public IWaitable
+ {
+ public:
+ CWaylandScanoutRelease( CWaylandFb *pFb, int nFd, uint64_t ulAcquireSerial )
+ : m_pFb{ pFb }
+ , m_nFd{ nFd }
+ , m_ulAcquireSerial{ ulAcquireSerial }
+ {
+ }
+
+ int GetFD() override { return m_nFd; }
+ void OnPollOut() override { Finish(); }
+ void OnPollHangUp() override { Finish(); }
+
+ static CAsyncWaiter<> &Waiter()
+ {
+ static CAsyncWaiter<> s_Waiter{ "gamescope-scanout" };
+ return s_Waiter;
+ }
+
+ private:
+ void Finish()
+ {
+ Waiter().RemoveWaitable( this );
+ m_pFb->OnScanoutDone( m_ulAcquireSerial );
+ close( m_nFd );
+ delete this;
+ }
+
+ CWaylandFb *m_pFb;
+ int m_nFd;
+ uint64_t m_ulAcquireSerial;
+ };
const wl_buffer_listener CWaylandFb::s_BufferListener =
{
.release = WAYLAND_USERDATA_TO_THIS( CWaylandFb, Wayland_Buffer_Release ),
};
class CWaylandInputThread
{
public:
CWaylandInputThread();
~CWaylandInputThread();
bool Init( CWaylandBackend *pBackend );
@@ -969,73 +1011,108 @@ namespace gamescope
.action = WAYLAND_NULL(),
};
const zwp_primary_selection_source_v1_listener CWaylandBackend::s_PrimarySelectionSourceListener =
{
.send = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_PrimarySelectionSource_Send ),
.cancelled = WAYLAND_USERDATA_TO_THIS( CWaylandBackend, Wayland_PrimarySelectionSource_Cancelled ),
};
//////////////////
// CWaylandFb
//////////////////
- CWaylandFb::CWaylandFb( CWaylandBackend *pBackend, wl_buffer *pHostBuffer )
+ CWaylandFb::CWaylandFb( CWaylandBackend *pBackend, wl_buffer *pHostBuffer, int nDmabufFd )
: CBaseBackendFb()
, m_pBackend { pBackend }
, m_pHostBuffer { pHostBuffer }
+ , m_nDmabufFd { nDmabufFd }
{
wl_buffer_add_listener( pHostBuffer, &s_BufferListener, this );
}
CWaylandFb::~CWaylandFb()
{
// I own the pHostBuffer.
wl_buffer_destroy( m_pHostBuffer );
m_pHostBuffer = nullptr;
+ if ( m_nDmabufFd >= 0 )
+ close( m_nDmabufFd );
}
void CWaylandFb::OnCompositorAcquire()
{
- // If the compositor has acquired us, track that
- // and increment the ref count.
- if ( !m_bCompositorAcquired )
+ bool bTakeRef = false;
{
+ std::scoped_lock lock( m_AcquireMutex );
+ m_ulAcquireSerial++;
+ bTakeRef = !m_bCompositorAcquired;
m_bCompositorAcquired = true;
- IncRef();
}
+
+ if ( bTakeRef )
+ IncRef();
}
void CWaylandFb::OnCompositorRelease()
{
- // Compositor has released us, decrement rc.
- //assert( m_bCompositorAcquired );
+ uint64_t ulSerial;
+ {
+ std::scoped_lock lock( m_AcquireMutex );
+ ulSerial = m_ulAcquireSerial;
+ }
+ OnScanoutDone( ulSerial );
+ }
- if ( m_bCompositorAcquired )
+ void CWaylandFb::OnScanoutDone( uint64_t ulAcquireSerial )
+ {
+ bool bDropRef = false;
{
+ std::scoped_lock lock( m_AcquireMutex );
+ if ( ulAcquireSerial != m_ulAcquireSerial )
+ return;
+ bDropRef = m_bCompositorAcquired;
m_bCompositorAcquired = false;
- DecRef();
}
+
+ if ( bDropRef )
+ DecRef();
else
- {
xdg_log.errorf( "Compositor released us but we were not acquired. Oh no." );
- }
}
void CWaylandFb::Wayland_Buffer_Release( wl_buffer *pBuffer )
{
assert( m_pHostBuffer );
assert( m_pHostBuffer == pBuffer );
xdg_log.debugf( "buffer_release: %p", pBuffer );
+ if ( ShowsClientBuffer() && gamescope::DmabufScanoutPending( m_nDmabufFd ) )
+ {
+ int nFd = fcntl( m_nDmabufFd, F_DUPFD_CLOEXEC, 0 );
+ if ( nFd >= 0 )
+ {
+ uint64_t ulSerial;
+ {
+ std::scoped_lock lock( m_AcquireMutex );
+ ulSerial = m_ulAcquireSerial;
+ }
+ auto *pWait = new CWaylandScanoutRelease( this, nFd, ulSerial );
+ if ( CWaylandScanoutRelease::Waiter().AddWaitable( pWait, EPOLLOUT | EPOLLHUP | EPOLLONESHOT ) )
+ return;
+ delete pWait;
+ close( nFd );
+ }
+ }
+
OnCompositorRelease();
}
//////////////////
// CWaylandConnector
//////////////////
CWaylandConnector::CWaylandConnector( CWaylandBackend *pBackend, uint64_t ulVirtualConnectorKey )
: CBaseBackendConnector{ ulVirtualConnectorKey }
, m_pBackend( pBackend )
, m_Planes{ this, this, this, this, this, this, this, this, this }
{
@@ -2349,25 +2426,26 @@ namespace gamescope
pDmaBuf->format,
0u );
if ( !pImportedBuffer )
{
xdg_log.errorf( "Failed to import dmabuf" );
zwp_linux_buffer_params_v1_destroy( pBufferParams );
return nullptr;
}
zwp_linux_buffer_params_v1_destroy( pBufferParams );
- return new CWaylandFb{ this, pImportedBuffer };
+ int nDmabufFd = pDmaBuf->n_planes > 0 ? fcntl( pDmaBuf->fd[0], F_DUPFD_CLOEXEC, 0 ) : -1;
+ return new CWaylandFb{ this, pImportedBuffer, nDmabufFd };
}
bool CWaylandBackend::UsesModifiers() const
{
if ( !cv_wayland_use_modifiers )
return false;
return m_bCanUseModifiers;
}
std::span<const uint64_t> CWaylandBackend::GetSupportedModifiers( uint32_t uDrmFormat ) const
{
auto iter = m_FormatModifiers.find( uDrmFormat );
diff --git a/src/backend.cpp b/src/backend.cpp
index cc91853..ec59c8b 100644
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -109,41 +109,47 @@ namespace gamescope
wlserver_unlock();
}
// Potentially release now!
DecRefPrivate();
}
return uRefCount;
}
void CBaseBackendFb::SetBuffer( wlr_buffer *pClientBuffer )
{
+ if ( pClientBuffer )
+ m_bShowsClientBuffer = true;
+
if ( m_pClientBuffer == pClientBuffer )
return;
assert( m_pClientBuffer == nullptr );
m_pClientBuffer = pClientBuffer;
if ( GetRefCount() )
{
wlserver_lock();
wlr_buffer_lock( m_pClientBuffer );
wlserver_unlock( false );
}
m_pReleasePoint = nullptr;
}
void CBaseBackendFb::SetReleasePoint( std::shared_ptr<CReleaseTimelinePoint> pReleasePoint )
{
+ if ( pReleasePoint )
+ m_bShowsClientBuffer = true;
+
if ( m_pReleasePoint == pReleasePoint )
return;
m_pReleasePoint = pReleasePoint;
if ( m_pClientBuffer && GetRefCount() )
{
wlserver_lock();
wlr_buffer_unlock( m_pClientBuffer );
wlserver_unlock();
m_pClientBuffer = nullptr;
}
diff --git a/src/backend.h b/src/backend.h
index 30b42ca..9a27711 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -303,26 +303,29 @@ namespace gamescope
public:
CBaseBackendFb();
virtual ~CBaseBackendFb();
uint32_t IncRef() override;
uint32_t DecRef() override;
void SetBuffer( wlr_buffer *pClientBuffer ) override;
void SetReleasePoint( std::shared_ptr<CReleaseTimelinePoint> pReleasePoint ) override;
virtual IBackendFb *EnsureImported() override { return this; };
+ bool ShowsClientBuffer() const { return m_bShowsClientBuffer; }
+
private:
wlr_buffer *m_pClientBuffer = nullptr;
+ std::atomic<bool> m_bShowsClientBuffer = { false };
std::shared_ptr<CReleaseTimelinePoint> m_pReleasePoint;
};
class IBackend
{
public:
virtual ~IBackend() {}
virtual bool Init() = 0;
virtual bool PostInit() = 0;
virtual std::span<const char *const> GetInstanceExtensions() const = 0;
virtual std::span<const char *const> GetDeviceExtensions( VkPhysicalDevice pVkPhysicalDevice ) const = 0;
+2 -2
View File
@@ -1,3 +1,3 @@
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
GAMESCOPE_TAG=gamescope-3.16.29-f7dd44d2
GAMESCOPE_SHA256=a034c36d44f9bca4abc804bda3958c8d303f1ce304fb677375e5d7aa233287a9
GAMESCOPE_TAG=gamescope-3.16.29-cb9c4861
GAMESCOPE_SHA256=89a3d70124a13bb5de0b4c67ff75d748a5d7ba6f29590194621754e3550b1f31
@@ -0,0 +1,222 @@
from pathlib import Path
import os
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
PATCHES = ROOT / "tools/gamescope/patches"
PICK = PATCHES / "0146-composite-waits-for-scanout.patch"
FORWARD = PATCHES / "0147-forwarded-buffers-wait-for-scanout.patch"
def post_image(patch, name):
out, current = [], None
for line in patch.read_text().splitlines():
if line.startswith("+++ "):
current = line[6:] if line.startswith("+++ b/") else line[4:]
continue
if current != name or line.startswith("--- ") or line.startswith("@@"):
continue
if line.startswith("+") or line.startswith(" "):
out.append(line[1:])
elif line == "":
out.append("")
return "\n".join(out)
def block(text, start, end="\n }\n"):
begin = text.index(start)
return text[begin:text.index(end, begin) + len(end)]
PREAMBLE = r'''
#include <atomic>
#include <cassert>
#include <cerrno>
#include <cstdint>
#include <cstdio>
#include <fcntl.h>
#include <mutex>
#include <poll.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <vector>
struct wl_buffer {};
static struct { void debugf(const char *, ...) {} void errorf(const char *, ...) { ++oh_no; } int oh_no = 0; } xdg_log;
namespace droiddeck::frame_trace { enum class Event { OutputRelease }; inline void Record(Event) {} }
namespace gamescope
{
PICK
class IWaitable
{
public:
virtual ~IWaitable() {}
virtual int GetFD() { return -1; }
virtual void OnPollOut() {}
virtual void OnPollHangUp() {}
};
template <typename T = int>
class CAsyncWaiter
{
public:
CAsyncWaiter( const char * ) {}
bool AddWaitable( IWaitable *p, uint32_t ) { waiting.push_back( p ); return true; }
void RemoveWaitable( IWaitable *p ) { std::erase( waiting, p ); }
std::vector<IWaitable *> waiting;
};
class CWaylandBackend;
class CBaseBackendFb
{
public:
uint32_t IncRef() { return refs++; }
uint32_t DecRef() { return --refs; }
bool ShowsClientBuffer() const { return client; }
uint32_t refs = 1;
bool client = false;
};
class CWaylandFb final : public CBaseBackendFb
{
public:
CWaylandFb( int nDmabufFd ) : m_pHostBuffer{ &m_Buffer }, m_nDmabufFd{ nDmabufFd } {}
void OnCompositorAcquire();
void OnCompositorRelease();
void OnScanoutDone( uint64_t ulAcquireSerial );
void Wayland_Buffer_Release( wl_buffer *pBuffer );
wl_buffer m_Buffer;
wl_buffer *m_pHostBuffer;
int m_nDmabufFd = -1;
std::mutex m_AcquireMutex;
uint64_t m_ulAcquireSerial = 0;
bool m_bCompositorAcquired = false;
};
SCANOUT
METHODS
}
'''
MAIN = r'''
using namespace gamescope;
static CAsyncWaiter<> &waiter() { return CWaylandScanoutRelease::Waiter(); }
struct Display {
int fds[2];
Display() { assert( pipe2( fds, O_NONBLOCK ) == 0 ); }
~Display() { close( fds[0] ); close( fds[1] ); }
void scanning() { char b[4096] = {}; while ( write( fds[1], b, sizeof( b ) ) > 0 ) {} }
void done() { char b[4096]; while ( read( fds[0], b, sizeof( b ) ) > 0 ) {} }
int fd() { return fds[1]; }
};
static void fire() {
assert( waiter().waiting.size() == 1 );
waiter().waiting.front()->OnPollOut();
assert( waiter().waiting.empty() );
}
int main( int argc, char **argv ) {
std::string which = argv[1];
Display d;
CWaylandFb fb{ fcntl( d.fd(), F_DUPFD_CLOEXEC, 0 ) };
if ( which == "client-scanning" ) {
fb.client = true;
fb.OnCompositorAcquire();
assert( fb.refs == 2 );
d.scanning();
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
assert( fb.refs == 2 && fb.m_bCompositorAcquired );
d.done();
fire();
assert( fb.refs == 1 && !fb.m_bCompositorAcquired && xdg_log.oh_no == 0 );
} else if ( which == "client-idle" ) {
fb.client = true;
fb.OnCompositorAcquire();
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
assert( fb.refs == 1 && waiter().waiting.empty() );
} else if ( which == "composite-scanning" ) {
fb.OnCompositorAcquire();
d.scanning();
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
assert( fb.refs == 1 && waiter().waiting.empty() );
} else if ( which == "shown-again" ) {
fb.client = true;
fb.OnCompositorAcquire();
d.scanning();
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
fb.OnCompositorAcquire();
d.done();
fire();
assert( fb.refs == 2 && fb.m_bCompositorAcquired );
fb.Wayland_Buffer_Release( fb.m_pHostBuffer );
assert( fb.refs == 1 && !fb.m_bCompositorAcquired && xdg_log.oh_no == 0 );
} else if ( which == "no-dmabuf" ) {
CWaylandFb plain{ -1 };
plain.client = true;
plain.OnCompositorAcquire();
plain.Wayland_Buffer_Release( plain.m_pHostBuffer );
assert( plain.refs == 1 && waiter().waiting.empty() );
} else {
return 2;
}
return 0;
}
'''
class ForwardedBufferScanoutTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cxx = shutil.which(os.environ.get("CXX", "c++"))
if not cxx:
raise AssertionError("C++ compiler required")
pick = post_image(PICK, "src/output_image_pick.hpp")
pick = pick[pick.index("struct OutputImagePick"):pick.rindex("}")]
wayland = post_image(FORWARD, "src/Backends/WaylandBackend.cpp")
scanout = block(wayland, " class CWaylandScanoutRelease", "\n };\n")
methods = "\n".join(block(wayland, " void CWaylandFb::" + name) for name in
("OnCompositorAcquire()", "OnCompositorRelease()", "OnScanoutDone(", "Wayland_Buffer_Release("))
source = PREAMBLE.replace("PICK", pick).replace("SCANOUT", scanout).replace("METHODS", methods) + MAIN
cls.tmp = tempfile.TemporaryDirectory(prefix="droiddeck-forwarded-scanout-")
cls.addClassCleanup(cls.tmp.cleanup)
probe = Path(cls.tmp.name) / "probe.cpp"
probe.write_text(source)
cls.binary = probe.with_suffix("")
built = subprocess.run([cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", "-UNDEBUG",
"-include", "string", str(probe), "-o", str(cls.binary)], capture_output=True, text=True)
if built.returncode:
raise AssertionError(built.stdout + built.stderr)
def scenario(self, name):
result = subprocess.run([str(self.binary), name], capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_forwarded_buffer_is_held_until_scanout_ends(self):
self.scenario("client-scanning")
def test_idle_forwarded_buffer_is_released_at_once(self):
self.scenario("client-idle")
def test_composite_output_image_keeps_the_release_at_latch(self):
self.scenario("composite-scanning")
def test_buffer_shown_again_waits_for_its_next_release(self):
self.scenario("shown-again")
def test_buffer_without_dmabuf_is_released_at_once(self):
self.scenario("no-dmabuf")
if __name__ == "__main__":
unittest.main()
+31 -3
View File
@@ -109,9 +109,11 @@ static struct droiddeck_native_handle handle = {.numFds = 1, .data = {3}};
static AHardwareBuffer *buffer = (AHardwareBuffer *)&handle;
static struct vkp_image image;
static int allocations, imports_10_bit, imports_8_bit, accept_10_bit, accept_8_bit;
static int qti_handle, refuse_compressed, compressed_imports;
static uint64_t allocated_usage;
static int AHardwareBuffer_allocate(const AHardwareBuffer_Desc *d, AHardwareBuffer **out) {
(void)d; allocations++; *out = buffer; return 0;
allocations++; allocated_usage = d->usage; *out = buffer; return 0;
}
static void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) {
(void)b; d->stride = 1920; d->usage = 0;
@@ -119,14 +121,20 @@ static void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_D
static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; }
static const void *native_handle(const AHardwareBuffer *b) { (void)b; return &handle; }
static struct { const void *(*getNativeHandle)(const AHardwareBuffer *); } api = {native_handle};
static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) { (void)h; (void)mod; return 0; }
static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) {
(void)h;
if (!qti_handle) return 0;
*mod = (allocated_usage & SC_LAYER_AHB_USAGE_VENDOR_UBWC) ? MOD_QCOM_COMPRESSED : MOD_LINEAR;
return 1;
}
static int vkp_can_import_ahb(void) { return 0; }
static struct vkp_image *vkp_image_import_ahb(AHardwareBuffer *b, char *info, size_t n) {
(void)b; (void)info; (void)n; return NULL;
}
static struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm, uint64_t mod, int w, int h, uint32_t pitch,
uint32_t offset, int planes) {
(void)fd; (void)mod; (void)w; (void)h; (void)pitch; (void)offset; (void)planes;
(void)fd; (void)w; (void)h; (void)pitch; (void)offset; (void)planes;
if (mod != MOD_LINEAR) { compressed_imports++; return refuse_compressed ? NULL : &image; }
if (drm == DRM_ABGR2101010) { imports_10_bit++; return accept_10_bit ? &image : NULL; }
imports_8_bit++;
return accept_8_bit ? &image : NULL;
@@ -187,6 +195,26 @@ int main(void) {
assert(frame(&nothing_imports) == -1 && g_alloc_failed);
assert(allocations == tried);
assert(imports_10_bit == 1 && imports_8_bit == 1);
int fd;
struct layer ubwc_without_modifiers = {.name = "game", .pool_n = 3};
reset(0, 1);
qti_handle = 1; refuse_compressed = 1; compressed_imports = 0;
assert(take_free_slot(&ubwc_without_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
assert(compressed_imports == 1 && imports_8_bit == 1);
assert(ubwc_without_modifiers.alloc_tier == TIER_PLAIN);
assert(ubwc_without_modifiers.pool_modifier == MOD_LINEAR);
assert(!(allocated_usage & SC_LAYER_AHB_USAGE_VENDOR_UBWC));
assert(take_free_slot(&ubwc_without_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
assert(compressed_imports == 1 && imports_8_bit == 2);
struct layer ubwc_with_modifiers = {.name = "game", .pool_n = 3};
reset(0, 1);
refuse_compressed = 0; compressed_imports = 0;
assert(take_free_slot(&ubwc_with_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
assert(compressed_imports == 1 && imports_8_bit == 0);
assert(ubwc_with_modifiers.alloc_tier == TIER_UBWC);
assert(ubwc_with_modifiers.pool_modifier == MOD_QCOM_COMPRESSED);
return 0;
}
'''
+13
View File
@@ -124,6 +124,19 @@ class VkLinearDmabufTest(unittest.TestCase):
self.assertIn("!as_blit_dst", terms)
self.assertIn("g_vk.GetPhysicalDeviceImageFormatProperties2", terms)
def test_client_imports_are_not_refused_by_the_layer_guard(self):
body = function((SRC / "vk_present.c").read_text(), "vkp_image_import_dmabuf")
self.assertEqual(body.count("vkp_dmabuf_layout_describable("), 1)
self.assertIn("as_blit_dst && !vkp_dmabuf_layout_describable(", body)
def test_undescribable_layout_is_refused_before_any_image_is_made(self):
body = function((SRC / "vk_present.c").read_text(), "vkp_image_import_dmabuf")
guard = body.index("if (as_blit_dst && !vkp_dmabuf_layout_describable(g_drm_modifiers, modifier))")
self.assertLess(body.index("dev_init()"), guard)
self.assertIn("return NULL;", body[guard:body.index("drm_to_vk(drm_format)")])
self.assertLess(guard, body.index("calloc(1, sizeof(*img))"))
self.assertLess(guard, body.index("VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT"))
def test_staged_client_image_stays_layer_candidate(self):
vk = (SRC / "vk_present.c").read_text()
comp = (SRC / "compositor.c").read_text()
+13
View File
@@ -56,6 +56,18 @@ static void check_path_choice(void) {
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 1));
}
static void check_describable_layouts(void) {
const uint64_t linear = 0;
const uint64_t qcom_compressed = 0x0500000000000001ULL;
const uint64_t arm_afbc = 0x0800000000000001ULL;
assert(vkp_dmabuf_layout_describable(0, linear));
assert(vkp_dmabuf_layout_describable(1, linear));
assert(vkp_dmabuf_layout_describable(1, qcom_compressed));
assert(vkp_dmabuf_layout_describable(1, arm_afbc));
assert(!vkp_dmabuf_layout_describable(0, qcom_compressed));
assert(!vkp_dmabuf_layout_describable(0, arm_afbc));
}
static void check_foreign_image(void) {
assert(vkp_linear_dmabuf_foreign_image(1, 0));
assert(!vkp_linear_dmabuf_foreign_image(1, 1));
@@ -117,6 +129,7 @@ int main(void) {
check_rejected_layouts();
check_path_choice();
check_padded_layer_targets();
check_describable_layouts();
check_foreign_image();
check_readback_order();
check_ownership();