mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 15:56:01 +00:00
Merge upstream main and preserve routed Home input
Integrate upstream 213c2da5, keeping Home/Guide player-slot handling compatible with remapped controls and disabled routing. Preserve the input-settings overlay gate for Home and Steam volume keys.
Validation: 2,707 JVM tests across 389 suites pass. Device validation and latency measurements were not repeated.
This commit is contained in:
commit
b245017593
121 files changed
+7170
-348
No files matched your search
@@ -3,10 +3,15 @@
|
||||
#include <pulsecore/core-rtclock.h>
|
||||
#include <pulsecore/core-subscribe.h>
|
||||
|
||||
#define ANDROID_VOLUME_IDLE_MS 100
|
||||
#define ANDROID_VOLUME_ACTIVE_MS 16
|
||||
#define ANDROID_VOLUME_ACTIVE_TICKS 40
|
||||
|
||||
struct android_volume {
|
||||
pa_sink *sink;
|
||||
char *directory;
|
||||
pa_time_event *timer;
|
||||
unsigned active_ticks;
|
||||
};
|
||||
|
||||
static bool android_volume_read(const char *directory, unsigned *level, unsigned *maximum, unsigned *muted) {
|
||||
@@ -57,22 +62,39 @@ static void android_volume_refresh(pa_mainloop_api *api, pa_time_event *event, c
|
||||
char *processing = pa_sprintf_malloc("%s.processing", request);
|
||||
char *mute_processing = pa_sprintf_malloc("%s.processing", mute_request);
|
||||
if (access(request, F_OK) != 0 && access(mute_request, F_OK) != 0 &&
|
||||
access(processing, F_OK) != 0 && access(mute_processing, F_OK) != 0 &&
|
||||
android_volume_read(bridge->directory, &level, &maximum, &muted)) {
|
||||
pa_cvolume volume;
|
||||
if (bridge->sink->n_volume_steps != maximum + 1) {
|
||||
bridge->sink->n_volume_steps = maximum + 1;
|
||||
pa_subscription_post(bridge->sink->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, bridge->sink->index);
|
||||
access(processing, F_OK) != 0 && access(mute_processing, F_OK) != 0) {
|
||||
if (android_volume_read(bridge->directory, &level, &maximum, &muted)) {
|
||||
pa_cvolume volume;
|
||||
bool changed = false;
|
||||
if (bridge->sink->n_volume_steps != maximum + 1) {
|
||||
bridge->sink->n_volume_steps = maximum + 1;
|
||||
pa_subscription_post(bridge->sink->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_CHANGE, bridge->sink->index);
|
||||
}
|
||||
pa_cvolume_set(&volume, bridge->sink->sample_spec.channels, (uint64_t)level * PA_VOLUME_NORM / maximum);
|
||||
if (!pa_cvolume_equal(&volume, &bridge->sink->real_volume)) {
|
||||
pa_sink_volume_changed(bridge->sink, &volume);
|
||||
changed = true;
|
||||
}
|
||||
if (bridge->sink->muted != !!muted) {
|
||||
pa_sink_mute_changed(bridge->sink, !!muted);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) bridge->active_ticks = ANDROID_VOLUME_ACTIVE_TICKS;
|
||||
}
|
||||
pa_cvolume_set(&volume, bridge->sink->sample_spec.channels, (uint64_t)level * PA_VOLUME_NORM / maximum);
|
||||
if (!pa_cvolume_equal(&volume, &bridge->sink->real_volume)) pa_sink_volume_changed(bridge->sink, &volume);
|
||||
if (bridge->sink->muted != !!muted) pa_sink_mute_changed(bridge->sink, !!muted);
|
||||
} else {
|
||||
bridge->active_ticks = ANDROID_VOLUME_ACTIVE_TICKS;
|
||||
}
|
||||
pa_xfree(request);
|
||||
pa_xfree(mute_request);
|
||||
pa_xfree(processing);
|
||||
pa_xfree(mute_processing);
|
||||
pa_core_rttime_restart(bridge->sink->core, event, pa_rtclock_now() + 100 * PA_USEC_PER_MSEC);
|
||||
/* A held volume key steps Android every ~50 ms; sampling at 100 ms hands Steam uneven multi-step jumps. */
|
||||
unsigned delay_ms = ANDROID_VOLUME_IDLE_MS;
|
||||
if (bridge->active_ticks) {
|
||||
bridge->active_ticks--;
|
||||
delay_ms = ANDROID_VOLUME_ACTIVE_MS;
|
||||
}
|
||||
pa_core_rttime_restart(bridge->sink->core, event, pa_rtclock_now() + delay_ms * PA_USEC_PER_MSEC);
|
||||
}
|
||||
|
||||
static struct android_volume *android_volume_new(pa_sink *sink, const char *directory) {
|
||||
@@ -90,7 +112,7 @@ static struct android_volume *android_volume_new(pa_sink *sink, const char *dire
|
||||
pa_cvolume_reset(&sink->soft_volume, sink->sample_spec.channels);
|
||||
pa_sink_set_set_volume_callback(sink, android_volume_set);
|
||||
pa_sink_set_set_mute_callback(sink, android_volume_mute);
|
||||
bridge->timer = pa_core_rttime_new(sink->core, pa_rtclock_now() + 100 * PA_USEC_PER_MSEC,
|
||||
bridge->timer = pa_core_rttime_new(sink->core, pa_rtclock_now() + ANDROID_VOLUME_IDLE_MS * PA_USEC_PER_MSEC,
|
||||
android_volume_refresh, bridge);
|
||||
return bridge;
|
||||
}
|
||||
|
||||
@@ -156,3 +156,46 @@ A host mode switch can report a passing rate for a few frames (72 Hz between 144
|
||||
120 Hz on the AYANEO Pocket FIT), so with following on a new rate is taken once it has
|
||||
been reported for 300 ms. Without the variable the reported rate is taken at once, as
|
||||
upstream does.
|
||||
|
||||
The rate comes from the feedback of a frame gamescope presents, so with nothing moving
|
||||
on screen no feedback arrived and the old rate stayed. With following on, gamescope
|
||||
presents once when the host's `wl_output` mode changes (DroidDeck's compositor sends
|
||||
the new mode) and keeps presenting while a new rate is pending (since p16).
|
||||
|
||||
## 0121 Xwayland: skip the X tree walk for a repeated window override
|
||||
|
||||
The WSI layer sends `override_window_content` on every present of an X11 swapchain.
|
||||
gamescope first walked from that window to its top-level window with `XQueryTree`, one
|
||||
blocking X round trip per level under the wlserver lock, and only then noticed that the
|
||||
same swapchain already overrides that window. At thousands of frames per second that is
|
||||
thousands of round trips to Xwayland every second.
|
||||
|
||||
The override now remembers the window it was asked for. When the same swapchain and
|
||||
surface ask for the same window again within 100 ms, the request returns at once; after
|
||||
100 ms the walk runs again, so a window that moved to another top level is still found.
|
||||
|
||||
## 0122 Wayland: wake steamcompmgr after reading host events
|
||||
|
||||
Backport of upstream commit 2962992 by Matthew Schwartz (ValveSoftware/gamescope).
|
||||
The nested Wayland backend's input thread reads the host display, but steamcompmgr
|
||||
does not watch that file descriptor, so buffer releases and presentation feedback
|
||||
queued by that read could wait up to one refresh for steamcompmgr's next poll. The
|
||||
input thread now wakes steamcompmgr after each read.
|
||||
|
||||
## 0123 commit: fence lifetime fixes from upstream
|
||||
|
||||
Backport of upstream commits 0efe47c and 666c52b by Matthew Schwartz (ValveSoftware/gamescope).
|
||||
Pending commits share ownership of their completion list with the Xwayland context, so a late
|
||||
fence signal can no longer append to a list freed with the context; and a commit being destroyed
|
||||
no longer hands the image waiter a new reference to itself. Both touch the code 0124 changes.
|
||||
|
||||
## 0124 commit: mark a finished frame done at import
|
||||
|
||||
Every game frame took two passes of steamcompmgr's loop: the import duplicated the buffer's
|
||||
fence and handed the commit to the image waiter (epoll add), then the waiter thread saw the fence
|
||||
signalled, removed and closed it and woke steamcompmgr again to handle the finished commit.
|
||||
`update_wayland_res` now polls the fence without waiting first. A frame that is already finished
|
||||
is marked done at once - no duplicate fence, no epoll add or delete, no waiter wake - and the main
|
||||
loop handles it in the same pass, after the import (FIFO commits still wait for a vblank). The
|
||||
`commit_ready_check` convar (default on, `gamescopectl commit_ready_check 0`) turns it off; the
|
||||
`xwm` log counts fences ready at import and waited for, every 10 s.
|
||||
@@ -0,0 +1,55 @@
|
||||
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
|
||||
index 9a027a2..e6d8e31 100644
|
||||
--- a/src/wlserver.cpp
|
||||
+++ b/src/wlserver.cpp
|
||||
@@ -98,6 +98,8 @@ struct wlserver_content_override {
|
||||
uint32_t x11_window;
|
||||
struct wl_listener surface_destroy_listener;
|
||||
struct wl_resource *gamescope_swapchain;
|
||||
+ uint32_t requested_window;
|
||||
+ uint64_t ulCheckedNs;
|
||||
};
|
||||
|
||||
std::mutex g_wlserver_xdg_shell_windows_lock;
|
||||
@@ -800,6 +802,20 @@ static void gamescope_swapchain_destroy_co( struct wl_resource *resource );
|
||||
|
||||
void gamescope_xwayland_server_t::handle_override_window_content( struct wl_client *client, struct wl_resource *gamescope_swapchain_resource, struct wlr_surface *surface, uint32_t x11_window )
|
||||
{
|
||||
+ // The WSI layer sends this on every present. Finding the top level walks the X tree with a
|
||||
+ // round trip per level, so a swapchain repeating the same window skips it for 100 ms.
|
||||
+ const uint64_t ulNow = get_time_in_nanos();
|
||||
+ if ( gamescope_swapchain_resource )
|
||||
+ {
|
||||
+ for ( const auto &[ window, existing ] : content_overrides )
|
||||
+ {
|
||||
+ if ( existing->gamescope_swapchain == gamescope_swapchain_resource && existing->surface == surface &&
|
||||
+ existing->requested_window == x11_window && ulNow - existing->ulCheckedNs < 100'000'000ul )
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ const uint32_t requested_window = x11_window;
|
||||
x11_window = x11_find_toplevel_for_xid( this->ctx->dpy, x11_window );
|
||||
|
||||
wlserver_x11_surface_info *x11_surface = lookup_x11_surface_info_from_xid( this, x11_window );
|
||||
@@ -813,7 +829,11 @@ void gamescope_xwayland_server_t::handle_override_window_content( struct wl_clie
|
||||
|
||||
if ( content_overrides.count( x11_window ) ) {
|
||||
if ( content_overrides[x11_window]->gamescope_swapchain == gamescope_swapchain_resource )
|
||||
+ {
|
||||
+ content_overrides[x11_window]->requested_window = requested_window;
|
||||
+ content_overrides[x11_window]->ulCheckedNs = ulNow;
|
||||
return;
|
||||
+ }
|
||||
#ifdef GAMESCOPE_SWAPCHAIN_DEBUG
|
||||
wl_log.infof( "handle_override_window_content: (2) DESTROYING x11_window: 0x%x old_swapchain: %p new_swapchain: %p", x11_window, content_overrides[x11_window]->gamescope_swapchain, gamescope_swapchain_resource );
|
||||
#endif
|
||||
@@ -830,6 +850,8 @@ void gamescope_xwayland_server_t::handle_override_window_content( struct wl_clie
|
||||
co->surface = surface;
|
||||
co->x11_window = x11_window;
|
||||
co->gamescope_swapchain = gamescope_swapchain_resource;
|
||||
+ co->requested_window = requested_window;
|
||||
+ co->ulCheckedNs = ulNow;
|
||||
co->surface_destroy_listener.notify = content_override_handle_surface_destroy;
|
||||
wl_signal_add( &surface->events.destroy, &co->surface_destroy_listener );
|
||||
content_overrides[ x11_window ] = co;
|
||||
@@ -0,0 +1,14 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 1b85e63..370661d 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -2977,6 +2977,9 @@ namespace gamescope
|
||||
LogDisplayError( "Failed to read events on input thread", m_pBackend->GetDisplay() );
|
||||
abort();
|
||||
}
|
||||
+
|
||||
+ // Reading also queues releases and presentation feedback for steamcompmgr.
|
||||
+ nudge_steamcompmgr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
diff --git a/src/commit.cpp b/src/commit.cpp
|
||||
index c9d0001..f2e0f0c 100644
|
||||
--- a/src/commit.cpp
|
||||
+++ b/src/commit.cpp
|
||||
@@ -105,14 +105,15 @@ bool commit_t::CloseFenceInternal()
|
||||
if ( m_nCommitFence < 0 )
|
||||
return false;
|
||||
|
||||
- // Will automatically remove from epoll!
|
||||
- g_ImageWaiter.RemoveWaitable( this );
|
||||
+ // Do not recreate an Rc after deletion has started.
|
||||
+ if ( HasLiveReferences() )
|
||||
+ g_ImageWaiter.RemoveWaitable( this );
|
||||
close( m_nCommitFence );
|
||||
m_nCommitFence = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
-void commit_t::SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, CommitDoneList_t *pDoneCommits )
|
||||
+void commit_t::SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits )
|
||||
{
|
||||
std::unique_lock lock( m_WaitableCommitStateMutex );
|
||||
CloseFenceInternal();
|
||||
diff --git a/src/commit.h b/src/commit.h
|
||||
index 20f881d..8603a9a 100644
|
||||
--- a/src/commit.h
|
||||
+++ b/src/commit.h
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "steamcompmgr_shared.hpp"
|
||||
#include "Utils/NonCopyable.h"
|
||||
|
||||
+#include <memory>
|
||||
#include <optional>
|
||||
#include "main.hpp"
|
||||
#include "rendervulkan.hpp"
|
||||
@@ -34,7 +35,7 @@ struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable,
|
||||
|
||||
// Returns true if we had a fence that was closed.
|
||||
bool CloseFenceInternal();
|
||||
- void SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, CommitDoneList_t *pDoneCommits );
|
||||
+ void SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits );
|
||||
|
||||
bool ShouldPreemptivelyUpscale( GamescopeUpscaleFilter eFilter, GamescopeUpscaleScaler eScaler );
|
||||
|
||||
@@ -81,5 +82,5 @@ struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable,
|
||||
bool m_bMangoNudge = false;
|
||||
// Typed mangoapp stream to nudge, 0 for none, never the legacy type.
|
||||
uint32_t m_uMangoMsgType = 0;
|
||||
- CommitDoneList_t *m_pDoneCommits = nullptr; // I hate this
|
||||
-};
|
||||
\ No newline at end of file
|
||||
+ std::shared_ptr<CommitDoneList_t> m_pDoneCommits; // I hate this
|
||||
+};
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index 5fb9086..22aa907 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -932,7 +932,7 @@ constexpr const T& clamp( const T& x, const T& min, const T& max )
|
||||
|
||||
extern bool g_bForceRelativeMouse;
|
||||
|
||||
-CommitDoneList_t g_steamcompmgr_xdg_done_commits;
|
||||
+std::shared_ptr<CommitDoneList_t> g_steamcompmgr_xdg_done_commits = std::make_shared<CommitDoneList_t>();
|
||||
|
||||
|
||||
static std::mutex s_KeysToCloseMutex;
|
||||
@@ -8073,7 +8073,7 @@ bool handle_done_commit( steamcompmgr_win_t *w, xwayland_ctx_t *ctx, uint64_t co
|
||||
// TODO: Merge these two functions.
|
||||
void handle_done_commits_xwayland( xwayland_ctx_t *ctx, bool vblank, uint64_t vblank_idx )
|
||||
{
|
||||
- std::lock_guard<std::mutex> lock( ctx->doneCommits.listCommitsDoneLock );
|
||||
+ std::lock_guard<std::mutex> lock( ctx->doneCommits->listCommitsDoneLock );
|
||||
|
||||
uint64_t next_refresh_time = g_SteamCompMgrVBlankTime.schedule.ulTargetVBlank;
|
||||
|
||||
@@ -8090,7 +8090,7 @@ void handle_done_commits_xwayland( xwayland_ctx_t *ctx, bool vblank, uint64_t vb
|
||||
uint64_t now = get_time_in_nanos();
|
||||
|
||||
// very fast loop yes
|
||||
- for ( auto& entry : ctx->doneCommits.listCommitsDone )
|
||||
+ for ( auto& entry : ctx->doneCommits->listCommitsDone )
|
||||
{
|
||||
steamcompmgr_win_t *entry_win = nullptr;
|
||||
for ( steamcompmgr_win_t *w = ctx->list; w; w = w->xwayland().next )
|
||||
@@ -8130,12 +8130,12 @@ void handle_done_commits_xwayland( xwayland_ctx_t *ctx, bool vblank, uint64_t vb
|
||||
}
|
||||
}
|
||||
|
||||
- ctx->doneCommits.listCommitsDone.swap( commits_before_their_time );
|
||||
+ ctx->doneCommits->listCommitsDone.swap( commits_before_their_time );
|
||||
}
|
||||
|
||||
void handle_done_commits_xdg( bool vblank, uint64_t vblank_idx )
|
||||
{
|
||||
- std::lock_guard<std::mutex> lock( g_steamcompmgr_xdg_done_commits.listCommitsDoneLock );
|
||||
+ std::lock_guard<std::mutex> lock( g_steamcompmgr_xdg_done_commits->listCommitsDoneLock );
|
||||
|
||||
uint64_t next_refresh_time = g_SteamCompMgrVBlankTime.schedule.ulTargetVBlank;
|
||||
|
||||
@@ -8152,7 +8152,7 @@ void handle_done_commits_xdg( bool vblank, uint64_t vblank_idx )
|
||||
uint64_t now = get_time_in_nanos();
|
||||
|
||||
// very fast loop yes
|
||||
- for ( auto& entry : g_steamcompmgr_xdg_done_commits.listCommitsDone )
|
||||
+ for ( auto& entry : g_steamcompmgr_xdg_done_commits->listCommitsDone )
|
||||
{
|
||||
steamcompmgr_win_t *entry_win = nullptr;
|
||||
for (const auto& xdg_win : g_steamcompmgr_xdg_wins)
|
||||
@@ -8192,7 +8192,7 @@ void handle_done_commits_xdg( bool vblank, uint64_t vblank_idx )
|
||||
}
|
||||
}
|
||||
|
||||
- g_steamcompmgr_xdg_done_commits.listCommitsDone.swap( commits_before_their_time );
|
||||
+ g_steamcompmgr_xdg_done_commits->listCommitsDone.swap( commits_before_their_time );
|
||||
}
|
||||
|
||||
gamescope::ConVar<bool> cv_mangoapp_use_output_timing{ "mangoapp_use_output_timing", true };
|
||||
@@ -8359,7 +8359,7 @@ static TempUpscaleImage_t *GetTempUpscaleImage( global_focus_t *pFocus, uint32_t
|
||||
|
||||
gamescope::ConVar<bool> cv_surface_update_force_only_current_surface( "surface_update_force_only_current_surface", false, "Force updates to apply only to the current surface, ignoring commits for other surfaces." );
|
||||
|
||||
-void update_wayland_res(CommitDoneList_t *doneCommits, steamcompmgr_win_t *w, ResListEntry_t& reslistentry)
|
||||
+void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, steamcompmgr_win_t *w, ResListEntry_t& reslistentry)
|
||||
{
|
||||
struct wlr_buffer *buf = reslistentry.buf;
|
||||
|
||||
@@ -8632,7 +8632,7 @@ void check_new_xwayland_res(xwayland_ctx_t *ctx)
|
||||
for ( uint32_t i = 0; i < tmp_queue.size(); i++ )
|
||||
{
|
||||
steamcompmgr_win_t *w = find_win( ctx, tmp_queue[ i ].surf );
|
||||
- update_wayland_res( &ctx->doneCommits, w, tmp_queue[ i ]);
|
||||
+ update_wayland_res( ctx->doneCommits, w, tmp_queue[ i ]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8645,7 +8645,7 @@ void check_new_xdg_res()
|
||||
{
|
||||
if ( xdg_win->xdg().surface.main_surface == tmp_queue[ i ].surf )
|
||||
{
|
||||
- update_wayland_res( &g_steamcompmgr_xdg_done_commits, xdg_win.get(), tmp_queue[ i ] );
|
||||
+ update_wayland_res( g_steamcompmgr_xdg_done_commits, xdg_win.get(), tmp_queue[ i ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
diff --git a/src/xwayland_ctx.hpp b/src/xwayland_ctx.hpp
|
||||
index 81910a1..3a75650 100644
|
||||
--- a/src/xwayland_ctx.hpp
|
||||
+++ b/src/xwayland_ctx.hpp
|
||||
@@ -92,7 +92,7 @@ struct xwayland_ctx_t final : public gamescope::IWaitable
|
||||
|
||||
std::unique_ptr<MouseCursor> cursor;
|
||||
|
||||
- CommitDoneList_t doneCommits;
|
||||
+ std::shared_ptr<CommitDoneList_t> doneCommits = std::make_shared<CommitDoneList_t>();
|
||||
|
||||
double accum_x = 0.0;
|
||||
double accum_y = 0.0;
|
||||
@@ -0,0 +1,103 @@
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index 22aa907..0aef598 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -8359,6 +8359,33 @@ static TempUpscaleImage_t *GetTempUpscaleImage( global_focus_t *pFocus, uint32_t
|
||||
|
||||
gamescope::ConVar<bool> cv_surface_update_force_only_current_surface( "surface_update_force_only_current_surface", false, "Force updates to apply only to the current surface, ignoring commits for other surfaces." );
|
||||
|
||||
+gamescope::ConVar<bool> cv_commit_ready_check( "commit_ready_check", true, "Check a new commit's fence at import; a finished frame is marked done in the same pass instead of through the image waiter." );
|
||||
+
|
||||
+// Set when update_wayland_res marks a commit done itself, so the main loop handles it in the same pass.
|
||||
+static bool s_bXwaylandCommitsDoneAtImport = false;
|
||||
+static bool s_bXdgCommitsDoneAtImport = false;
|
||||
+
|
||||
+static bool commit_fence_ready_now( int nFd )
|
||||
+{
|
||||
+ struct pollfd pfd = { .fd = nFd, .events = POLLIN, .revents = 0 };
|
||||
+ return poll( &pfd, 1, 0 ) == 1 && ( pfd.revents & POLLIN );
|
||||
+}
|
||||
+
|
||||
+static void note_commit_fence( bool bReadyAtImport )
|
||||
+{
|
||||
+ static uint64_t s_ulReady = 0, s_ulWaited = 0, s_ulLastLog = 0;
|
||||
+ ( bReadyAtImport ? s_ulReady : s_ulWaited )++;
|
||||
+ uint64_t now = get_time_in_nanos();
|
||||
+ if ( !s_ulLastLog )
|
||||
+ s_ulLastLog = now;
|
||||
+ if ( now - s_ulLastLog >= 10'000'000'000ul )
|
||||
+ {
|
||||
+ xwm_log.infof( "commit fences, last 10 s: %lu ready at import, %lu waited for", s_ulReady, s_ulWaited );
|
||||
+ s_ulReady = s_ulWaited = 0;
|
||||
+ s_ulLastLog = now;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, steamcompmgr_win_t *w, ResListEntry_t& reslistentry)
|
||||
{
|
||||
struct wlr_buffer *buf = reslistentry.buf;
|
||||
@@ -8602,7 +8629,11 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
struct wlr_dmabuf_attributes dmabuf = {0};
|
||||
if ( wlr_buffer_get_dmabuf( buf, &dmabuf ) )
|
||||
{
|
||||
- fence = dup( dmabuf.fd[0] );
|
||||
+ // A finished buffer needs no fence of its own.
|
||||
+ if ( cv_commit_ready_check && commit_fence_ready_now( dmabuf.fd[0] ) )
|
||||
+ bKnownReady = true;
|
||||
+ else
|
||||
+ fence = dup( dmabuf.fd[0] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -8610,11 +8641,22 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
|
||||
}
|
||||
}
|
||||
|
||||
+ if ( cv_commit_ready_check )
|
||||
+ {
|
||||
+ if ( !bKnownReady && fence >= 0 && commit_fence_ready_now( fence ) )
|
||||
+ bKnownReady = true;
|
||||
+ note_commit_fence( bKnownReady );
|
||||
+ }
|
||||
+
|
||||
gpuvis_trace_printf( "pushing wait for commit %lu win %lx", newCommit->commitID, w->type == steamcompmgr_win_type_t::XWAYLAND ? w->xwayland().id : 0 );
|
||||
{
|
||||
newCommit->SetFence( fence, mango_nudge, uMangoMsgType, doneCommits );
|
||||
if ( bKnownReady )
|
||||
+ {
|
||||
newCommit->Signal();
|
||||
+ if ( cv_commit_ready_check )
|
||||
+ ( w->type == steamcompmgr_win_type_t::XWAYLAND ? s_bXwaylandCommitsDoneAtImport : s_bXdgCommitsDoneAtImport ) = true;
|
||||
+ }
|
||||
else
|
||||
g_ImageWaiter.AddWaitable( newCommit.get() );
|
||||
}
|
||||
@@ -9400,6 +9442,13 @@ void steamcompmgr_check_xdg(bool vblank, uint64_t vblank_idx)
|
||||
}
|
||||
|
||||
check_new_xdg_res();
|
||||
+
|
||||
+ // Commits marked done at import: handle them now rather than on the next wake. FIFO commits still wait for a vblank.
|
||||
+ if ( s_bXdgCommitsDoneAtImport )
|
||||
+ {
|
||||
+ s_bXdgCommitsDoneAtImport = false;
|
||||
+ handle_done_commits_xdg( false, vblank_idx );
|
||||
+ }
|
||||
}
|
||||
|
||||
void update_edid_prop()
|
||||
@@ -10512,6 +10561,14 @@ steamcompmgr_main(int argc, char **argv)
|
||||
gamescope_xwayland_server_t *server = NULL;
|
||||
for (size_t i = 0; (server = wlserver_get_xwayland_server(i)); i++)
|
||||
check_new_xwayland_res(server->ctx.get());
|
||||
+
|
||||
+ // Commits marked done at import: handle them now rather than on the next wake. FIFO commits still wait for a vblank.
|
||||
+ if ( s_bXwaylandCommitsDoneAtImport )
|
||||
+ {
|
||||
+ s_bXwaylandCommitsDoneAtImport = false;
|
||||
+ for (size_t i = 0; (server = wlserver_get_xwayland_server(i)); i++)
|
||||
+ handle_done_commits_xwayland(server->ctx.get(), false, vblank_idx);
|
||||
+ }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p16
|
||||
GAMESCOPE_SHA256=8ae783d730d910de9a44ddb98dd567643e9cf7987f16ef261fe08cd2c4a7ba5c
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p18
|
||||
GAMESCOPE_SHA256=a79d8acc5628973c807a43524638c20e7d5c101a4fc3bcb8b5068631e6f6fe55
|
||||
@@ -357,21 +357,76 @@ def game_cores(env):
|
||||
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
|
||||
|
||||
|
||||
def cpu_topology(env):
|
||||
def core_speeds(cores, root="/sys/devices/system/cpu"):
|
||||
"""Each core's capacity, else its top clock; None when some core reports neither."""
|
||||
for name in ("cpu_capacity", "cpufreq/cpuinfo_max_freq"):
|
||||
speeds = {}
|
||||
for core in cores:
|
||||
try:
|
||||
with open("%s/cpu%d/%s" % (root, core, name)) as f:
|
||||
speeds[core] = int(f.read().strip())
|
||||
except (OSError, ValueError):
|
||||
break
|
||||
else:
|
||||
return speeds
|
||||
return None
|
||||
|
||||
|
||||
def fastest_first(cores):
|
||||
"""The cores, fastest first; cores of equal or unknown speed keep their numeric order."""
|
||||
cores = sorted(cores)
|
||||
speeds = core_speeds(cores)
|
||||
return sorted(cores, key=lambda core: -speeds[core]) if speeds else cores
|
||||
|
||||
|
||||
def proton_cpu_limit(command, env):
|
||||
"""This game's entry in Proton's own default_cpu_limit list: a core count, another value such as "P" as text, or None."""
|
||||
app_id = env.get("SteamGameId", "")
|
||||
if not command or not app_id.isdigit():
|
||||
return None
|
||||
try:
|
||||
if os.path.getsize(command[0]) > 4 * 1024 * 1024:
|
||||
return None
|
||||
with open(command[0], encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
except OSError:
|
||||
return None
|
||||
table = re.search(r"^default_cpu_limit = \{(.*?)^\}", text, re.M | re.S)
|
||||
match = table and re.search(r'^\s*"%s"\s*:\s*"?(\w+)' % app_id, table.group(1), re.M)
|
||||
if not match:
|
||||
return None
|
||||
value = match.group(1)
|
||||
return int(value) if value.isdigit() else value
|
||||
|
||||
|
||||
def cpu_topology(env, command=()):
|
||||
"""Windows sees the game's cores fastest first, so a thread a game pins to CPU 0 runs on the fastest core."""
|
||||
if "PROTON_CPU_TOPOLOGY" in env:
|
||||
return
|
||||
if "WINE_CPU_TOPOLOGY" in env:
|
||||
if env["WINE_CPU_TOPOLOGY"]:
|
||||
env["PROTON_CPU_TOPOLOGY"] = env["WINE_CPU_TOPOLOGY"]
|
||||
return
|
||||
if not (env.get("DROIDDECK_GAME_CORES", "").strip() or env.get("BL_GAME_CPUS", "").strip()):
|
||||
picked = bool(env.get("DROIDDECK_GAME_CORES", "").strip() or env.get("BL_GAME_CPUS", "").strip())
|
||||
fastest = env.get("DROIDDECK_FASTEST_CORES", "").strip() != "0" and game_id(env) is not None
|
||||
if not (picked or fastest):
|
||||
return
|
||||
try:
|
||||
cores = sorted(os.sched_getaffinity(0))
|
||||
except OSError:
|
||||
return
|
||||
online = online_cores()
|
||||
if not cores or set(cores) >= online or cores[-1] >= len(online):
|
||||
if not cores or cores[-1] >= len(online):
|
||||
return
|
||||
picked = picked and not set(cores) >= online
|
||||
if fastest:
|
||||
limit = None if picked else proton_cpu_limit(command, env)
|
||||
if isinstance(limit, str):
|
||||
return
|
||||
cores = fastest_first(cores)[:limit or None]
|
||||
elif set(cores) >= online:
|
||||
return
|
||||
if cores == sorted(online):
|
||||
return
|
||||
env["WINE_CPU_TOPOLOGY"] = env["PROTON_CPU_TOPOLOGY"] = "%d:%s" % (len(cores), ",".join(map(str, cores)))
|
||||
print("droiddeck-game-env: Windows sees %d cores (%s)" % (len(cores), env["WINE_CPU_TOPOLOGY"]), file=sys.stderr)
|
||||
@@ -409,6 +464,59 @@ def apply_config(env, config, app_id, fixes=None):
|
||||
return result
|
||||
|
||||
|
||||
GAME_DEBUG_CHANNELS = (
|
||||
"timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree",
|
||||
)
|
||||
WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)")
|
||||
|
||||
|
||||
def game_debug_channels(*values):
|
||||
"""Normalize Wine selectors, retaining custom channels before required diagnostics."""
|
||||
selectors = {}
|
||||
for value in values:
|
||||
if not isinstance(value, str) or "\0" in value or len(value) > 8192:
|
||||
continue
|
||||
for part in value.split(","):
|
||||
part = part.strip()
|
||||
match = WINE_DEBUG_SELECTOR.fullmatch(part)
|
||||
if match is None:
|
||||
continue
|
||||
key = (match[1] or "", match[3])
|
||||
# Move the last value to the end: global +/-all and per-class selectors
|
||||
# have ordered semantics, so replacing a value in its old position is wrong.
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = part
|
||||
for channel in GAME_DEBUG_CHANNELS:
|
||||
key = ("", channel)
|
||||
selectors.pop(key, None)
|
||||
selectors[key] = "+" + channel
|
||||
formatted = ",".join(selectors.values())
|
||||
if len(formatted) > 8192:
|
||||
formatted = ",".join("+" + channel for channel in GAME_DEBUG_CHANNELS)
|
||||
return formatted
|
||||
|
||||
|
||||
def apply_game_debug_logs(env, config, debug_dir):
|
||||
"""Apply app-owned diagnostics to a real game, without editing its launch command."""
|
||||
if not isinstance(config, dict) or config.get("version") != 1 or config.get("gameDebugLogs") is not True:
|
||||
return env
|
||||
if (not isinstance(debug_dir, str) or "\0" in debug_dir or len(debug_dir) > 8192
|
||||
or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)):
|
||||
print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr)
|
||||
return env
|
||||
result = dict(env)
|
||||
result.update({
|
||||
"PROTON_LOG": "1",
|
||||
"PROTON_LOG_DIR": debug_dir,
|
||||
"PROTON_CRASH_REPORT_DIR": debug_dir,
|
||||
"DXVK_LOG_PATH": debug_dir,
|
||||
"DXVK_LOG_LEVEL": "debug",
|
||||
"VKD3D_DEBUG": "info",
|
||||
"WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")),
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
def sync_config(config, app_id):
|
||||
games = config.get("games", {})
|
||||
return {
|
||||
@@ -610,6 +718,7 @@ def main():
|
||||
return 2
|
||||
env = game_gpu(os.environ.copy())
|
||||
mic_enabled = env.get("BL_MIC_ENABLED")
|
||||
debug_dir = env.get("BL_DEBUG_DIR", "")
|
||||
scripts = mark_install_scripts(command, env)
|
||||
if scripts and install_scripts_done(scripts, env):
|
||||
print("droiddeck-game-env: install scripts already run in this prefix; evaluator skipped", file=sys.stderr)
|
||||
@@ -634,6 +743,7 @@ def main():
|
||||
own = fixes.get("WINEDLLOVERRIDES")
|
||||
fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components
|
||||
path = Path.home() / ".config/droiddeck/game-environment.json"
|
||||
config = {}
|
||||
try:
|
||||
with path.open(encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
@@ -646,6 +756,11 @@ def main():
|
||||
env = apply_config(env, {"version": 1}, app_id, fixes)
|
||||
except (OSError, ValueError, TypeError, AttributeError):
|
||||
print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr)
|
||||
if waiting:
|
||||
before_debug = env
|
||||
env = apply_game_debug_logs(env, config, debug_dir)
|
||||
if env is not before_debug:
|
||||
print("droiddeck-game-env: game debug logs enabled for this launch", file=sys.stderr)
|
||||
if app_id and len(command) > 1 and command[1] == "waitforexitandrun":
|
||||
command = offline_without_anticheat(command, env)
|
||||
if mic_enabled == "0":
|
||||
@@ -653,7 +768,7 @@ def main():
|
||||
env = vram_cap(env)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
cpu_topology(env)
|
||||
cpu_topology(env, command)
|
||||
try:
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
except Exception as error:
|
||||
|
||||
@@ -799,13 +799,25 @@ x64_gpu_watch() {
|
||||
x64_gpu_probe
|
||||
}
|
||||
|
||||
x64_arm_webhelper_cpu_supported() {
|
||||
local status=0
|
||||
# Valve's native ARM web helper contains LSE atomics; missing CPU data cannot establish incompatibility.
|
||||
awk -F: '
|
||||
$1 ~ /^[[:space:]]*Features[[:space:]]*$/ {
|
||||
if ($2 !~ /(^|[[:space:]])atomics([[:space:]]|$)/) unsupported = 1
|
||||
}
|
||||
END { exit unsupported ? 1 : 0 }
|
||||
' /proc/cpuinfo 2>/dev/null || status=$?
|
||||
[ "$status" != 1 ]
|
||||
}
|
||||
|
||||
x64_exec() {
|
||||
x64_env
|
||||
cd "$STEAM_X64"
|
||||
# The client checksums its files at start and reinstalls over edited ones, so the session shim (preload/net.c)
|
||||
# swaps the web helper at exec. The arm64 helper only comes up against a client of the same build.
|
||||
if [ "${BL_X64_X86_WEBHELPER:-0}" != 1 ] && [ -x /usr/local/bin/droiddeck-x64-arm-webhelper ] &&
|
||||
[ -x "$ARM_STEAM/steamrtarm64/steamwebhelper" ]; then
|
||||
[ -x "$ARM_STEAM/steamrtarm64/steamwebhelper" ] && x64_arm_webhelper_cpu_supported; then
|
||||
local chan x86_build arm_build
|
||||
chan=$(cat "$STEAM_X64/package/beta" 2>/dev/null || echo "$X64_CHANNEL")
|
||||
x86_build=$(awk -F'"' '$2 == "version" { print $4; exit }' "$STEAM_X64/package/steam_client_${chan}_steamrt64.manifest" 2>/dev/null || true)
|
||||
@@ -1049,4 +1061,4 @@ for attempt in 1 2 3 4 5; do
|
||||
( x64_exec -clientbeta "$X64_CHANNEL" -no-cef-sandbox "${cef[@]}" "$@" ) >>"$LOG" 2>&1 || rc=$?
|
||||
step "client exited rc=$rc"
|
||||
[ "$rc" = 42 ] || break
|
||||
done
|
||||
done
|
||||
@@ -276,6 +276,18 @@ bl_vacdiag() {
|
||||
}
|
||||
"""
|
||||
|
||||
# Steam's shader pre-caching runs its D3D driver query through every Proton tool at each start, as
|
||||
# "run <client>/bin/d3ddriverquery64.exe" in compatdata/0. Here it has never succeeded (exit 1 every time), and each
|
||||
# run started Wine in compatdata/0, where the two Protons upgrade the prefix back and forth for many seconds while the
|
||||
# game starts. Steam gets the same failure without starting Wine; other verbs and prefixes are left alone.
|
||||
BL_DRIVER_QUERY_SKIP = """
|
||||
case "$verb:${1##*/}:${STEAM_COMPAT_DATA_PATH%/}" in
|
||||
run:d3ddriverquery64.exe:*/compatdata/0 | run:d3ddriverquery.exe:*/compatdata/0)
|
||||
echo "droiddeck-proton: Steam's D3D driver query is not run (it fails here and would start Wine in compatdata/0)" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
"""
|
||||
|
||||
BL_DIRECTAUDIO_SETUP = """
|
||||
bl_is_steam_installscript_target() {
|
||||
local target=${1:-}
|
||||
@@ -408,7 +420,7 @@ LAUNCHER_TEMPLATE = LAUNCHER_SH
|
||||
|
||||
def launcher_sh(sources=SOURCES):
|
||||
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DRIVER_QUERY_SKIP + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
@@ -455,6 +467,15 @@ bl_store_launch "$@"
|
||||
BL_STORE_ARGS=("$@")
|
||||
bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env "$BL_STORE_PROTON" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
|
||||
"""
|
||||
|
||||
|
||||
def extra_wrapper_sh(entry_point):
|
||||
return (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DRIVER_QUERY_SKIP + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP
|
||||
+ BL_IDTECH3_SETUP + BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
EXTRA_COMPAT_TOOL_VDF = """"compatibilitytools"
|
||||
{
|
||||
"compat_tools"
|
||||
@@ -678,11 +699,7 @@ def adopt_extras(tools):
|
||||
name = first_key(compat_vdf, ["compatibilitytools", "compat_tools"]) or entry
|
||||
wrapper = os.path.join(tool_dir, EXTRA_WRAPPER)
|
||||
try:
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DESKTOP_GPU_SETUP + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
write_changed(wrapper, body, 0o755)
|
||||
write_changed(wrapper, extra_wrapper_sh(entry_point), 0o755)
|
||||
write_changed(manifest, EXTRA_MANIFEST_VDF)
|
||||
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, display_name(entry)))
|
||||
legacy_wrapper = os.path.join(tool_dir, LEGACY_EXTRA_WRAPPER)
|
||||
|
||||
@@ -27,6 +27,7 @@ if [ "$pkg" = "$P" ]; then
|
||||
else
|
||||
python3 "$here/axml_rename.py" "$in" "$work/renamed.apk" \
|
||||
"$P=$pkg" "$P.androidx-startup=$pkg.androidx-startup" "$P.logs=$pkg.logs" \
|
||||
"$P.pairingguide=$pkg.pairingguide" "$P.pin=$pkg.pin" \
|
||||
"$P.documents=$pkg.documents" "$P.home=$pkg.home" "$P.agent=$pkg.agent" \
|
||||
"$P.vr_recovery=$pkg.vr_recovery" \
|
||||
"$P.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION=$pkg.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION"
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef struct pa_sink {
|
||||
struct android_volume;
|
||||
struct userdata { struct android_volume *android_volume; };
|
||||
static int restarts, frees;
|
||||
static uint64_t last_delay;
|
||||
static char *pa_sprintf_malloc(const char *format, ...) {
|
||||
va_list ap; va_start(ap,format); char *result; assert(vasprintf(&result,format,ap)>=0); va_end(ap); return result;
|
||||
}
|
||||
@@ -57,7 +58,7 @@ static void pa_sink_set_set_volume_callback(pa_sink *sink, void (*callback)(pa_s
|
||||
static void pa_sink_set_set_mute_callback(pa_sink *sink, void (*callback)(pa_sink*)) { sink->set_mute=callback; }
|
||||
static void pa_subscription_post(pa_core *core, int event, unsigned index) {}
|
||||
static uint64_t pa_rtclock_now(void) { return 0; }
|
||||
static void pa_core_rttime_restart(pa_core *core, pa_time_event *event, uint64_t time) { restarts++; }
|
||||
static void pa_core_rttime_restart(pa_core *core, pa_time_event *event, uint64_t time) { restarts++; last_delay=time; }
|
||||
static pa_time_event *pa_core_rttime_new(pa_core *core, uint64_t time,
|
||||
void (*callback)(pa_mainloop_api*,pa_time_event*,const struct timeval*,void*), void *userdata) {
|
||||
return calloc(1,sizeof(pa_time_event));
|
||||
@@ -76,11 +77,18 @@ int main(int argc, char **argv) {
|
||||
assert(userdata.android_volume && userdata.android_volume->timer && sink.set_volume && sink.set_mute);
|
||||
state(argv[1],"invalid\n");
|
||||
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
|
||||
assert(sink.real_volume.value==PA_VOLUME_NORM && restarts==1);
|
||||
assert(sink.real_volume.value==PA_VOLUME_NORM && restarts==1 && last_delay==100*PA_USEC_PER_MSEC);
|
||||
state(argv[1],"3 15 1\n");
|
||||
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
|
||||
assert(sink.real_volume.value==3*PA_VOLUME_NORM/15 && sink.muted && sink.n_volume_steps==16);
|
||||
assert(sink.soft_volume.value==PA_VOLUME_NORM && restarts==2);
|
||||
assert(last_delay==16*PA_USEC_PER_MSEC);
|
||||
state(argv[1],"4 15 1\n");
|
||||
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
|
||||
assert(sink.real_volume.value==4*PA_VOLUME_NORM/15 && last_delay==16*PA_USEC_PER_MSEC);
|
||||
for (int i = 0; i < ANDROID_VOLUME_ACTIVE_TICKS + 1; i++)
|
||||
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
|
||||
assert(last_delay==100*PA_USEC_PER_MSEC);
|
||||
sink.real_volume.value=2*PA_VOLUME_NORM/3; sink.set_volume(&sink);
|
||||
char *request=pa_sprintf_malloc("%s/volume.request",argv[1]);
|
||||
FILE *f=fopen(request,"r"); unsigned level; assert(f && fscanf(f,"%u",&level)==1 && level==10); fclose(f); free(request);
|
||||
|
||||
@@ -28,6 +28,121 @@ def config_text(entries):
|
||||
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
|
||||
|
||||
|
||||
class GameDebugLoggingTest(unittest.TestCase):
|
||||
def test_real_game_launch_without_config_file_keeps_the_base_environment(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
probe = home / "proton"
|
||||
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ['PROTON_LOG'])\n")
|
||||
probe.chmod(0o755)
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
|
||||
env={**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
|
||||
"BL_DEBUG_DIR": tmp, "PROTON_LOG": "0"},
|
||||
text=True, capture_output=True, check=True,
|
||||
)
|
||||
self.assertEqual(result.stdout.strip(), "0")
|
||||
|
||||
def test_game_debug_logs_override_only_diagnostic_values_and_keep_raw_settings(self):
|
||||
with tempfile.TemporaryDirectory(prefix="game logs '") as debug_dir:
|
||||
inherited = {"BL_DEBUG_DIR": debug_dir, "PROTON_LOG": "0", "WINEDEBUG": "-all,+relay",
|
||||
"PROTON_LOG_DIR": "/old", "PROTON_CRASH_REPORT_DIR": "/old-crashes",
|
||||
"DXVK_LOG_PATH": "/old-dxvk", "DXVK_LOG_LEVEL": "none", "VKD3D_DEBUG": "none",
|
||||
"CUSTOM": "$(touch never); 'quoted' = literal", "DXVK_CONFIG": "dxvk.tearFree = True"}
|
||||
config = {"version": 1, "gameDebugLogs": True,
|
||||
"shared": {"PROTON_LOG": "0", "BL_DEBUG_DIR": "/profile-redirect"},
|
||||
"games": {"42": {"PROTON_LOG_DIR": None, "DXVK_LOG_PATH": "/game-redirect"}}}
|
||||
normal = MODULE["apply_config"](inherited, config, "42")
|
||||
debug = MODULE["apply_game_debug_logs"](normal, config, inherited["BL_DEBUG_DIR"])
|
||||
self.assertEqual(debug["PROTON_LOG"], "1")
|
||||
for key in ("PROTON_LOG_DIR", "PROTON_CRASH_REPORT_DIR", "DXVK_LOG_PATH"):
|
||||
self.assertEqual(debug[key], debug_dir)
|
||||
self.assertEqual(debug["DXVK_LOG_LEVEL"], "debug")
|
||||
self.assertEqual(debug["VKD3D_DEBUG"], "info")
|
||||
self.assertIn("+relay", debug["WINEDEBUG"].split(","))
|
||||
self.assertTrue(debug["WINEDEBUG"].endswith("+loaddll,+mscoree"))
|
||||
for key in ("CUSTOM", "DXVK_CONFIG", "BL_DEBUG_DIR"):
|
||||
self.assertEqual(debug[key], normal[key])
|
||||
self.assertEqual(normal["PROTON_LOG"], "0")
|
||||
self.assertEqual(inherited["PROTON_LOG_DIR"], "/old")
|
||||
self.assertIs(MODULE["apply_game_debug_logs"](normal, {**config, "gameDebugLogs": False}, debug_dir), normal)
|
||||
self.assertEqual(MODULE["apply_game_debug_logs"](debug, config, debug_dir), debug)
|
||||
|
||||
def test_wine_debug_channels_are_formatted_deduplicated_and_diagnostics_win(self):
|
||||
formatted = MODULE["game_debug_channels"](
|
||||
" +relay, trace-vulkan, -all, -seh, +relay, trace+vulkan, garbage, $(touch never) ",
|
||||
"+seh,warn-foo,warn+foo,+relay",
|
||||
)
|
||||
self.assertEqual(formatted, "-all,trace+vulkan,warn+foo,+relay," +
|
||||
"+timestamp,+pid,+tid,+seh,+unwind,+threadname,+debugstr,+loaddll,+mscoree")
|
||||
self.assertEqual(MODULE["game_debug_channels"](formatted, "1"), formatted)
|
||||
self.assertNotIn("-seh", formatted)
|
||||
for value in ("x\0,+relay", "+" + "x" * 8192, 1, None):
|
||||
self.assertEqual(MODULE["game_debug_channels"](value), MODULE["game_debug_channels"]())
|
||||
oversized = ",".join("+channel_" + str(i) for i in range(550))
|
||||
other = ",".join("+other_" + str(i) for i in range(550))
|
||||
self.assertLessEqual(len(MODULE["game_debug_channels"](oversized, other)), 8192)
|
||||
self.assertTrue(MODULE["game_debug_channels"](oversized, other).endswith("+loaddll,+mscoree"))
|
||||
|
||||
def test_game_debug_logs_require_opt_in_and_a_real_session_log_directory(self):
|
||||
env = {"PROTON_LOG": "user", "CUSTOM": "keep"}
|
||||
for config in ({}, {"version": 1}, {"version": 1, "gameDebugLogs": False},
|
||||
{"version": 1, "gameDebugLogs": "true"}, {"version": 2, "gameDebugLogs": True}):
|
||||
self.assertIs(MODULE["apply_game_debug_logs"](env, config, "/"), env)
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
not_a_directory = Path(tmp) / "file"
|
||||
not_a_directory.write_text("file")
|
||||
for path in (None, "", "relative", "bad\0path", str(not_a_directory), str(Path(tmp) / "missing")):
|
||||
with self.subTest(path=path):
|
||||
self.assertIs(MODULE["apply_game_debug_logs"](env, {"version": 1, "gameDebugLogs": True}, path), env)
|
||||
|
||||
def test_game_debug_toggle_is_live_preserves_command_and_excludes_probes(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
config_path = home / ".config/droiddeck/game-environment.json"
|
||||
config_path.parent.mkdir(parents=True)
|
||||
debug_dir = home / "session logs '$literal; directory'"
|
||||
debug_dir.mkdir()
|
||||
probe = home / "fake proton"
|
||||
probe.write_text("#!" + sys.executable + "\nimport json, os, sys\n"
|
||||
"print(json.dumps({'env': dict(os.environ), 'argv': sys.argv[1:]}))\n")
|
||||
probe.chmod(0o755)
|
||||
literal = "$(touch " + str(home / "never-created") + "); 'literal'=value"
|
||||
config = {"version": 1, "gameDebugLogs": True,
|
||||
"shared": {"PROTON_LOG": "0", "WINEDEBUG": "-all,+relay", "CUSTOM": literal,
|
||||
"BL_DEBUG_DIR": "/profile-must-not-redirect"}}
|
||||
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
|
||||
"BL_DEBUG_DIR": str(debug_dir), "PROTON_LOG": "0", "WINEDEBUG": "-all"}
|
||||
command = [str(probe), "waitforexitandrun", "game 'with quotes'.exe", "argument with spaces", "$(literal)", "%command%"]
|
||||
|
||||
def launch(arguments, environment):
|
||||
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *arguments],
|
||||
env=environment, text=True, capture_output=True, check=True)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
for enabled in (True, False, True):
|
||||
config_path.write_text(json.dumps({**config, "gameDebugLogs": enabled}))
|
||||
result = launch(command, env)
|
||||
self.assertEqual(result["argv"], command[1:])
|
||||
self.assertEqual(result["env"]["CUSTOM"], literal)
|
||||
self.assertEqual(result["env"]["PROTON_LOG"], "1" if enabled else "0")
|
||||
if enabled:
|
||||
self.assertEqual(result["env"]["PROTON_LOG_DIR"], str(debug_dir))
|
||||
self.assertIn("+relay", result["env"]["WINEDEBUG"].split(","))
|
||||
self.assertIn("+seh", result["env"]["WINEDEBUG"].split(","))
|
||||
else:
|
||||
self.assertEqual(result["env"]["WINEDEBUG"], "-all,+relay")
|
||||
for verb, prefix in (("run", "42"), ("waitforexitandrun", "0"), ("waitforexitandrun", "not-a-game")):
|
||||
result = launch([str(probe), verb], {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata" / prefix)})
|
||||
self.assertEqual(result["env"]["PROTON_LOG"], "0")
|
||||
self.assertEqual(result["env"]["WINEDEBUG"], "-all")
|
||||
# Non-Steam shortcuts use the same normalized unsigned compatdata identity.
|
||||
result = launch(command, {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/-1")})
|
||||
self.assertEqual(result["env"]["PROTON_LOG"], "1")
|
||||
self.assertFalse((home / "never-created").exists())
|
||||
self.assertEqual(json.loads(config_path.read_text())["shared"], config["shared"])
|
||||
|
||||
|
||||
class ReadConfigMappingTest(unittest.TestCase):
|
||||
def test_missing_parent_or_unbalanced_vdf_is_not_treated_as_absent_choices(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -464,12 +579,78 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
({"BL_GAME_CPUS": "9"}, {9}, None, None),
|
||||
]
|
||||
for env, affinity, expected, proton in cases:
|
||||
env["DROIDDECK_FASTEST_CORES"] = "0"
|
||||
with mock.patch.dict(MODULE["cpu_topology"].__globals__, online), \
|
||||
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
||||
MODULE["cpu_topology"](env)
|
||||
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
||||
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton, env)
|
||||
|
||||
def test_windows_cpu_0_is_the_fastest_core(self):
|
||||
os_mod = MODULE["os"]
|
||||
pocket_fit = {0: 379, 1: 379, 2: 923, 3: 923, 4: 923, 5: 867, 6: 867, 7: 1024}
|
||||
every = set(range(8))
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton = Path(tmp) / "proton"
|
||||
proton.write_text('default_cpu_limit = {\n "19900" : "16", # Far Cry 2\n'
|
||||
' "2229830" : "1", # Command & Conquer\n "11440" : "4", # DiRT\n'
|
||||
' "1038250" : "P", # DIRT 5\n "618970" : 4, # Outcast, written as Proton 10 does\n'
|
||||
'}\n\nother = {\n "620" : "2",\n}\n')
|
||||
command = [str(proton), "waitforexitandrun", "/game/game.exe"]
|
||||
cases = [
|
||||
({}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
||||
({"BL_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:7,6", "2:7,6"),
|
||||
({"DROIDDECK_GAME_CORES": "0-2"}, {0, 1, 2}, pocket_fit, "3:2,0,1", "3:2,0,1"),
|
||||
({"BL_GAME_CPUS": "0-7"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
||||
({"WINE_CPU_TOPOLOGY": "2:0,1"}, every, pocket_fit, "2:0,1", "2:0,1"),
|
||||
({"WINE_CPU_TOPOLOGY": ""}, every, pocket_fit, "", None),
|
||||
({"PROTON_CPU_TOPOLOGY": "1:0"}, every, pocket_fit, None, "1:0"),
|
||||
({"DROIDDECK_FASTEST_CORES": "0"}, every, pocket_fit, None, None),
|
||||
({"SteamGameId": "2229830"}, every, pocket_fit, "1:7", "1:7"),
|
||||
({"SteamGameId": "11440"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
||||
({"SteamGameId": "19900"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
||||
({"SteamGameId": "1038250"}, every, pocket_fit, None, None),
|
||||
({"SteamGameId": "618970"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
||||
({"SteamGameId": "620"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
||||
({"SteamGameId": "2229830", "BL_GAME_CPUS": "0,1"}, {0, 1}, pocket_fit, "2:0,1", "2:0,1"),
|
||||
({"SteamGameId": "2229830", "DROIDDECK_GAME_CORES": "12-13"}, every, pocket_fit, "1:7", "1:7"),
|
||||
({"SteamGameId": "11440", "BL_GAME_CPUS": "0-7"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
||||
({}, every, {core: 100 for core in every}, None, None),
|
||||
({}, every, None, None, None),
|
||||
({"SteamGameId": "11440"}, every, None, "4:0,1,2,3", "4:0,1,2,3"),
|
||||
({"BL_GAME_CPUS": "9"}, {9}, pocket_fit, None, None),
|
||||
]
|
||||
cases += [
|
||||
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, every, pocket_fit, None, None),
|
||||
({"STEAM_COMPAT_DATA_PATH": ""}, every, pocket_fit, None, None),
|
||||
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0", "BL_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:6,7", "2:6,7"),
|
||||
]
|
||||
for env, affinity, speeds, expected, proton_topology in cases:
|
||||
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
|
||||
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
|
||||
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores, speeds=speeds: speeds}), \
|
||||
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
||||
MODULE["cpu_topology"](env, command)
|
||||
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
||||
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton_topology, env)
|
||||
self.assertIsNone(MODULE["proton_cpu_limit"](["/missing/proton"], {"SteamGameId": "11440"}))
|
||||
self.assertIsNone(MODULE["proton_cpu_limit"](command, {}))
|
||||
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "1038250"}), "P")
|
||||
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "618970"}), 4)
|
||||
|
||||
def test_core_speeds_read_capacity_then_top_clock(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
for core, capacity, clock in ((0, "379", "2265600"), (1, None, "3302400")):
|
||||
folder = Path(tmp) / ("cpu%d" % core) / "cpufreq"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "cpuinfo_max_freq").write_text(clock + "\n")
|
||||
if capacity:
|
||||
(folder.parent / "cpu_capacity").write_text(capacity + "\n")
|
||||
speeds = MODULE["core_speeds"]
|
||||
self.assertEqual(speeds([0], tmp), {0: 379})
|
||||
self.assertEqual(speeds([0, 1], tmp), {0: 2265600, 1: 3302400})
|
||||
self.assertIsNone(speeds([0, 2], tmp))
|
||||
|
||||
def test_reskate_runs_at_feature_level_12_1(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
reskate = Path(tmp) / "ReSkate"
|
||||
@@ -790,6 +971,36 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
|
||||
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
|
||||
|
||||
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
|
||||
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
|
||||
query = "/root/.local/share/Steam/steamrtarm64/../bin/d3ddriverquery64.exe"
|
||||
probe = "/root/.local/share/Steam/steamapps/compatdata/0"
|
||||
for script in scripts:
|
||||
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
|
||||
self.assertLess(script.index('case "$verb:${1##*/}:'), script.index("bl_components "))
|
||||
for args, prefix in (([query, "-d3d12"], probe), ([query], probe + "/"),
|
||||
([query.replace("64.exe", ".exe")], probe)):
|
||||
result = subprocess.run(["bash", "-s", "run"] + args, input=script, text=True, capture_output=True,
|
||||
env={"PATH": os.defpath, "HOME": "/nonexistent", "STEAM_COMPAT_DATA_PATH": prefix},
|
||||
timeout=10)
|
||||
self.assertEqual(result.returncode, 1, result.stderr)
|
||||
self.assertEqual(result.stdout, "")
|
||||
self.assertIn("D3D driver query is not run", result.stderr)
|
||||
skip = COMPAT["BL_DRIVER_QUERY_SKIP"]
|
||||
for verb, args, prefix in (
|
||||
("getcompatpath", [query], probe),
|
||||
("run", [query], "/root/.local/share/Steam/steamapps/compatdata/2276548447"),
|
||||
("run", [query], None),
|
||||
("waitforexitandrun", ["/games/AIO/AIO-Graphics-Test-64bit.exe", "--cube", "dx11"], probe),
|
||||
("run", ["/games/Tool/tool.exe", query], probe),
|
||||
("run", ["/games/d3ddriverquery64.exe.bak"], probe)):
|
||||
env = {"PATH": os.defpath}
|
||||
if prefix is not None:
|
||||
env["STEAM_COMPAT_DATA_PATH"] = prefix
|
||||
out = subprocess.run(["bash", "-c", "verb=" + verb + "\n" + skip + "echo continued", "_"] + args,
|
||||
env=env, capture_output=True, text=True, check=True).stdout
|
||||
self.assertEqual(out, "continued\n", (verb, args, prefix))
|
||||
|
||||
def test_wrappers_preload_the_session_library_before_the_input_shim(self):
|
||||
overlay = "/root/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so"
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from test_output_refresh import SOURCE, extract_function
|
||||
|
||||
|
||||
PREAMBLE = r'''
|
||||
#include <assert.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct wl_event_source { int armed; };
|
||||
static struct wl_event_source idle_source, timer_source;
|
||||
static void (*idle_func)(void *);
|
||||
static int idles_added, timers_armed, renders, window_requests, effects_changes, pose_changes;
|
||||
static int64_t clock_ns;
|
||||
static int g_display_storage;
|
||||
static void *g_display = &g_display_storage;
|
||||
static struct wl_event_source *g_render_idle, *g_fallback_timer;
|
||||
static int g_fallback_armed, g_dirty, g_hud_fresh, framegen;
|
||||
static void *g_hud_surface;
|
||||
static int64_t g_dirty_since_ns, g_last_vsync_ns, g_tick_vsync_ns, g_hud_last_ns, g_rendered_tick_ns;
|
||||
static int g_tick_held;
|
||||
static int64_t g_hold_missed_ns;
|
||||
#define HOLD_RETRY_NS 1000000000LL
|
||||
static int64_t g_refresh_ns = 16666667;
|
||||
volatile int g_render_on_commit = 1;
|
||||
volatile int g_release_unpaced = 1;
|
||||
static atomic_int g_stream_on;
|
||||
static struct { unsigned ticks, ticks_late_2ms, commit_renders; int64_t tick_late_ns, tick_late_max_ns; } g_pace;
|
||||
static struct { unsigned ticks; } g_perf;
|
||||
static int64_t now_ns(void) { return clock_ns; }
|
||||
static void *wl_display_get_event_loop(void *display) { return display; }
|
||||
static struct wl_event_source *wl_event_loop_add_idle(void *loop, void (*func)(void *), void *data) {
|
||||
idles_added++; idle_func = func; return &idle_source;
|
||||
}
|
||||
static struct wl_event_source *wl_event_loop_add_timer(void *loop, int (*func)(void *), void *data) { return &timer_source; }
|
||||
static int wl_event_source_timer_update(struct wl_event_source *source, int ms) { timers_armed++; return 0; }
|
||||
static int vkp_framegen_active(void) { return framegen; }
|
||||
static int vkp_apply_window_request(void) { return window_requests; }
|
||||
static int vkp_effects_sync(void) { return effects_changes; }
|
||||
static int vkp_cardboard_pose_changed(void) { return pose_changes; }
|
||||
static void render_scene(void) { renders++; g_dirty = 0; g_dirty_since_ns = 0; g_rendered_tick_ns = g_tick_vsync_ns; g_tick_held = 0; }
|
||||
static int on_fallback_timer(void *data) { return 0; }
|
||||
static void on_commit_idle(void *data);
|
||||
'''
|
||||
|
||||
CHECKS = r'''
|
||||
static void run_idle(void) {
|
||||
void (*func)(void *) = idle_func;
|
||||
idle_func = NULL;
|
||||
if (func) func(NULL);
|
||||
}
|
||||
|
||||
static void tick(int64_t t) { clock_ns = t; on_vsync(t); }
|
||||
|
||||
static void arrive(int64_t after_ns) { clock_ns += after_ns; schedule_render(); }
|
||||
|
||||
int main(void) {
|
||||
const int64_t refresh = 6944444, ms = 1000000;
|
||||
int64_t t = 1000000000LL;
|
||||
int r0;
|
||||
unsigned c0;
|
||||
g_refresh_ns = refresh;
|
||||
tick(t);
|
||||
assert(renders == 0);
|
||||
|
||||
/* a new frame is drawn when it arrives */
|
||||
arrive(2 * ms);
|
||||
assert(idles_added == 1 && renders == 0);
|
||||
run_idle();
|
||||
assert(renders == 1 && g_pace.commit_renders == 1 && g_render_idle == NULL);
|
||||
|
||||
/* a second frame in the same refresh is left for the next arrival, which is drawn when it arrives */
|
||||
arrive(1 * ms);
|
||||
assert(idles_added == 1);
|
||||
tick(t += refresh);
|
||||
assert(renders == 1 && g_tick_held == 1);
|
||||
arrive(2 * ms);
|
||||
assert(idles_added == 2);
|
||||
run_idle();
|
||||
assert(renders == 2 && g_pace.commit_renders == 2 && g_tick_held == 0);
|
||||
|
||||
/* a frame no other frame follows is drawn at the tick after next */
|
||||
arrive(1 * ms);
|
||||
tick(t += refresh);
|
||||
assert(renders == 2);
|
||||
tick(t += refresh);
|
||||
assert(renders == 3 && g_pace.commit_renders == 2);
|
||||
|
||||
/* after that, the tick draws every frame for a second, then holds one again */
|
||||
arrive(1 * ms);
|
||||
tick(t += refresh);
|
||||
assert(renders == 4 && g_tick_held == 0);
|
||||
t += HOLD_RETRY_NS;
|
||||
tick(t);
|
||||
arrive(1 * ms);
|
||||
run_idle();
|
||||
arrive(1 * ms);
|
||||
tick(t += refresh);
|
||||
assert(renders == 5 && g_tick_held == 1);
|
||||
arrive(2 * ms);
|
||||
run_idle();
|
||||
assert(renders == 6 && g_pace.commit_renders == 4);
|
||||
|
||||
/* one frame per refresh, starting right after a tick draw, settles on drawing every frame when it arrives */
|
||||
window_requests = 1;
|
||||
tick(t += refresh);
|
||||
window_requests = 0;
|
||||
arrive(2 * ms);
|
||||
r0 = renders; c0 = g_pace.commit_renders;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tick(t += refresh);
|
||||
arrive(2 * ms);
|
||||
run_idle();
|
||||
}
|
||||
assert(renders - r0 == 10 && g_pace.commit_renders - c0 == 10);
|
||||
|
||||
/* a client that draws again only after its frame callback (sent when the scene is drawn) keeps one frame
|
||||
per refresh: two held frames in 200 refreshes, about 1.4 s */
|
||||
r0 = renders; c0 = g_pace.commit_renders;
|
||||
{
|
||||
int seen = renders - 1;
|
||||
for (int i = 0; i < 200; i++) {
|
||||
if (renders != seen) { seen = renders; arrive(1 * ms); run_idle(); }
|
||||
tick(t += refresh);
|
||||
}
|
||||
}
|
||||
assert(renders - r0 == 198 && g_pace.commit_renders == c0);
|
||||
|
||||
/* a window, effect or headset change at the tick draws the waiting frame now */
|
||||
t += HOLD_RETRY_NS;
|
||||
tick(t);
|
||||
arrive(1 * ms);
|
||||
run_idle();
|
||||
r0 = renders;
|
||||
arrive(1 * ms);
|
||||
window_requests = 1;
|
||||
tick(t += refresh);
|
||||
window_requests = 0;
|
||||
assert(renders - r0 == 1 && g_tick_held == 0);
|
||||
|
||||
/* a draw queued before the tick still draws the frame once */
|
||||
tick(t += refresh);
|
||||
r0 = renders; c0 = g_pace.commit_renders;
|
||||
arrive(1 * ms);
|
||||
tick(t += refresh);
|
||||
assert(renders == r0);
|
||||
run_idle();
|
||||
assert(renders - r0 == 1 && g_pace.commit_renders - c0 == 1);
|
||||
tick(t += refresh);
|
||||
assert(renders - r0 == 1);
|
||||
|
||||
/* streaming switched on after the draw was queued leaves the frame for the tick */
|
||||
tick(t += refresh);
|
||||
r0 = renders; c0 = g_pace.commit_renders;
|
||||
arrive(1 * ms);
|
||||
atomic_store(&g_stream_on, 1);
|
||||
run_idle();
|
||||
assert(renders == r0);
|
||||
tick(t += refresh);
|
||||
atomic_store(&g_stream_on, 0);
|
||||
assert(renders - r0 == 1 && g_pace.commit_renders == c0);
|
||||
|
||||
/* paced output, frame generation, the switch off and streaming keep drawing on the tick */
|
||||
const int idles = idles_added;
|
||||
r0 = renders;
|
||||
for (int c = 0; c < 4; c++) {
|
||||
tick(t += refresh);
|
||||
if (c == 0) g_release_unpaced = 0;
|
||||
if (c == 1) framegen = 1;
|
||||
if (c == 2) g_render_on_commit = 0;
|
||||
if (c == 3) atomic_store(&g_stream_on, 1);
|
||||
arrive(1 * ms);
|
||||
assert(idles_added == idles);
|
||||
tick(t += refresh);
|
||||
g_release_unpaced = 1; framegen = 0; g_render_on_commit = 1; atomic_store(&g_stream_on, 0);
|
||||
assert(renders - r0 == c + 1);
|
||||
}
|
||||
|
||||
/* without screen ticks the fallback timer still draws */
|
||||
clock_ns += 200000000LL;
|
||||
schedule_render();
|
||||
assert(idles_added == idles && g_fallback_armed == 1 && timers_armed == 1);
|
||||
puts("PASS");
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform.startswith('linux'), 'needs a Linux host compiler')
|
||||
class RenderOnCommitTest(unittest.TestCase):
|
||||
def test_a_new_frame_is_drawn_on_arrival_at_most_once_per_refresh(self):
|
||||
compiler = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if compiler is None:
|
||||
self.skipTest('A host C compiler is required')
|
||||
source = SOURCE.read_text()
|
||||
render = extract_function(source, 'render_scene')
|
||||
self.assertIn('g_rendered_tick_ns = g_tick_vsync_ns;', render)
|
||||
self.assertIn('g_tick_held = 0;', render)
|
||||
functions = ('commit_renders_on', 'render_on_commit', 'schedule_render', 'scene_waits_for_game', 'on_commit_idle', 'on_vsync')
|
||||
harness = PREAMBLE + '\n'.join(extract_function(source, name) for name in functions) + CHECKS
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-render-on-commit-') as folder:
|
||||
path = Path(folder)
|
||||
(path / 'commit.c').write_text(harness)
|
||||
binary = path / 'commit-test'
|
||||
build = subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', '-Werror',
|
||||
'-Wno-unused-parameter', '-Wno-unused-function', '-O2',
|
||||
str(path / 'commit.c'), '-o', str(binary)], capture_output=True, text=True)
|
||||
self.assertEqual(0, build.returncode, build.stderr)
|
||||
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('PASS', result.stdout.strip())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,79 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-x64'
|
||||
|
||||
|
||||
class SteamX64CpuTest(unittest.TestCase):
|
||||
def selection(self, features, *, forced=False, same_build=True, unreadable=False):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
arm = root / 'arm'
|
||||
x64 = root / 'x64'
|
||||
for base in (arm, x64):
|
||||
(base / 'package').mkdir(parents=True)
|
||||
(arm / 'steamrtarm64').mkdir()
|
||||
(arm / 'steamrtarm64/steamwebhelper').touch(mode=0o700)
|
||||
shim = root / 'arm-shim'
|
||||
shim.touch(mode=0o700)
|
||||
(x64 / 'package/beta').write_text('publicbeta\n')
|
||||
for base, arch, version in ((x64, 'steamrt64', '123'), (arm, 'linuxarm64', '123' if same_build else '122')):
|
||||
(base / f'package/steam_client_publicbeta_{arch}.manifest').write_text(f'"version" "{version}"\n')
|
||||
cpuinfo = root / 'cpuinfo'
|
||||
if not unreadable:
|
||||
cpuinfo.write_text(features)
|
||||
text = SCRIPT.read_text()
|
||||
start = text.find('x64_arm_webhelper_cpu_supported() {')
|
||||
helper = text[start:text.index('x64_exec() {')] if start >= 0 else ''
|
||||
selection = text.split('x64_exec() {', 1)[1].split(' mkdir -p "$STEAM_X64/logs"', 1)[0]
|
||||
shell = helper + '\nx64_env() { :; }\nx64_webhelper_gpu() { return 1; }\nselect_helper() {' + selection + '\nprintf "%s|%s\\n" "${BL_X64_ARM_WEBHELPER:-x86}" "${BL_WEBHELPER_ARGS:-}";\n}\nselect_helper\n'
|
||||
shell = shell.replace('/proc/cpuinfo', str(cpuinfo)).replace('/usr/local/bin/droiddeck-x64-arm-webhelper', str(shim))
|
||||
env = dict(os.environ, STEAM_X64=str(x64), ARM_STEAM=str(arm), X64_CHANNEL='publicbeta', BL_X64_X86_WEBHELPER='1' if forced else '0')
|
||||
env.pop('BL_X64_ARM_WEBHELPER', None)
|
||||
env.pop('BL_WEBHELPER_ARGS', None)
|
||||
result = subprocess.run(['bash', '-eu', '-c', shell], env=env, capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
return result.stdout.strip(), str(shim)
|
||||
|
||||
def test_missing_atomics_keeps_x86_helper(self):
|
||||
result, _ = self.selection('Features : fp asimd aes crc32\n')
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
def test_atomics_keeps_same_build_arm_helper(self):
|
||||
result, arm = self.selection('Features : fp asimd atomics aes\n')
|
||||
self.assertEqual(result, arm + '|')
|
||||
|
||||
def test_exact_token_required(self):
|
||||
result, _ = self.selection('Features : fp noatomics atomics_extra\n')
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
def test_any_explicit_core_without_atomics_keeps_x86_helper(self):
|
||||
result, _ = self.selection('processor : 0\nFeatures : fp atomics\nprocessor : 1\nFeatures : fp aes\n')
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
def test_empty_features_is_explicitly_unsupported(self):
|
||||
result, _ = self.selection('Features : \n')
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
def test_absent_features_preserves_existing_behavior(self):
|
||||
result, arm = self.selection('processor : 0\n')
|
||||
self.assertEqual(result, arm + '|')
|
||||
|
||||
def test_unreadable_cpuinfo_preserves_existing_behavior(self):
|
||||
result, arm = self.selection('', unreadable=True)
|
||||
self.assertEqual(result, arm + '|')
|
||||
|
||||
def test_forced_x86_still_wins(self):
|
||||
result, _ = self.selection('Features : atomics\n', forced=True)
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
def test_supported_cpu_still_requires_same_build(self):
|
||||
result, _ = self.selection('Features : atomics\n', same_build=False)
|
||||
self.assertEqual(result, 'x86|stock')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user