mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
Merge org main 0f839bef into the non-Adreno test branch
Conflicts resolved: - build.yml: main's proot pack pin check and the Venus component fetch both kept. - compositor.c: main's unpaced release goes through send_buffer_release (DMA-BUF quarantine). - PulseAudioComponent: the AAudio retry loop stays; both sinks get main's control_dir. - SessionService: main's add-on pack and proot checks, then the PowerVR driver setup and staging. - droiddeck-session: main's stretch and refresh arguments with the selectable backend. - droiddeck-gpu: main's desktop window mode on the wayland backend; PowerVR's sdl backend stays full screen. - gamescope/release.env: the non-Adreno build stays pinned until the next one is published. - FrontEndActivity/FrontEndScreen/SessionActivity/SessionFiles/SessionPrefs/LinuxRuntime/strings: both sides kept. - test_gamescope_backend: the desktop backend test turns window mode off.
This commit is contained in:
commit
941cde30f2
394 files changed
+28009
-3092
No files matched your search
@@ -0,0 +1,103 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#include <stdio.h>
|
||||
#include <pulsecore/core-rtclock.h>
|
||||
#include <pulsecore/core-subscribe.h>
|
||||
|
||||
struct android_volume {
|
||||
pa_sink *sink;
|
||||
char *directory;
|
||||
pa_time_event *timer;
|
||||
};
|
||||
|
||||
static bool android_volume_read(const char *directory, unsigned *level, unsigned *maximum, unsigned *muted) {
|
||||
char *path = pa_sprintf_malloc("%s/volume.state", directory);
|
||||
FILE *file = fopen(path, "r");
|
||||
pa_xfree(path);
|
||||
if (!file) return false;
|
||||
int fields = fscanf(file, "%u %u %u", level, maximum, muted);
|
||||
fclose(file);
|
||||
return fields == 3 && *maximum > 0 && *level <= *maximum && *muted <= 1;
|
||||
}
|
||||
|
||||
static void android_volume_request(pa_sink *sink, const char *name, unsigned value) {
|
||||
struct userdata *u = sink->userdata;
|
||||
if (!u->android_volume || sink->state == PA_SINK_INIT) return;
|
||||
char *path = pa_sprintf_malloc("%s/%s.request", u->android_volume->directory, name);
|
||||
char *staged = pa_sprintf_malloc("%s.tmp", path);
|
||||
FILE *file = fopen(staged, "w");
|
||||
if (file) {
|
||||
fprintf(file, "%u\n", value);
|
||||
if (fclose(file) == 0 && rename(staged, path) < 0) pa_log_warn("Could not publish Android %s", name);
|
||||
}
|
||||
pa_xfree(staged);
|
||||
pa_xfree(path);
|
||||
}
|
||||
|
||||
static void android_volume_set(pa_sink *sink) {
|
||||
struct userdata *u = sink->userdata;
|
||||
unsigned level, maximum, muted;
|
||||
if (!u->android_volume || !android_volume_read(u->android_volume->directory, &level, &maximum, &muted)) return;
|
||||
unsigned requested = PA_MIN(pa_cvolume_max(&sink->real_volume), PA_VOLUME_NORM);
|
||||
level = ((uint64_t)requested * maximum + PA_VOLUME_NORM / 2) / PA_VOLUME_NORM;
|
||||
pa_cvolume_set(&sink->real_volume, sink->sample_spec.channels, (uint64_t)level * PA_VOLUME_NORM / maximum);
|
||||
/* Android applies media gain to both PulseAudio and DirectAudio streams. */
|
||||
pa_cvolume_reset(&sink->soft_volume, sink->sample_spec.channels);
|
||||
android_volume_request(sink, "volume", level);
|
||||
}
|
||||
|
||||
static void android_volume_mute(pa_sink *sink) {
|
||||
android_volume_request(sink, "mute", sink->muted ? 1 : 0);
|
||||
}
|
||||
|
||||
static void android_volume_refresh(pa_mainloop_api *api, pa_time_event *event, const struct timeval *tv, void *userdata) {
|
||||
struct android_volume *bridge = userdata;
|
||||
unsigned level, maximum, muted;
|
||||
char *request = pa_sprintf_malloc("%s/volume.request", bridge->directory);
|
||||
char *mute_request = pa_sprintf_malloc("%s/mute.request", bridge->directory);
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
static struct android_volume *android_volume_new(pa_sink *sink, const char *directory) {
|
||||
unsigned level, maximum, muted;
|
||||
if (!directory) return NULL;
|
||||
struct android_volume *bridge = pa_xnew0(struct android_volume, 1);
|
||||
bridge->sink = sink;
|
||||
bridge->directory = pa_xstrdup(directory);
|
||||
if (android_volume_read(directory, &level, &maximum, &muted)) {
|
||||
pa_cvolume_set(&sink->real_volume, sink->sample_spec.channels, (uint64_t)level * PA_VOLUME_NORM / maximum);
|
||||
sink->reference_volume = sink->real_volume;
|
||||
sink->muted = !!muted;
|
||||
sink->n_volume_steps = maximum + 1;
|
||||
}
|
||||
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,
|
||||
android_volume_refresh, bridge);
|
||||
return bridge;
|
||||
}
|
||||
|
||||
static void android_volume_free(struct android_volume *bridge) {
|
||||
if (!bridge) return;
|
||||
bridge->sink->core->mainloop->time_free(bridge->timer);
|
||||
pa_xfree(bridge->directory);
|
||||
pa_xfree(bridge);
|
||||
}
|
||||
@@ -42,6 +42,7 @@ PA_MODULE_USAGE(
|
||||
"channels=<number of channels> "
|
||||
"channel_map=<channel map> "
|
||||
"volume=<initial volume, linear, 1.0 = full> "
|
||||
"control_dir=<Android media volume bridge directory> "
|
||||
"performance_mode=<0 none, 1 low latency, 2 power saving> "
|
||||
"adaptive=<grow the buffer after underruns: 0 or 1> "
|
||||
"buffer_frames=<initial buffer size in frames, 0 = two bursts> "
|
||||
@@ -56,6 +57,7 @@ PA_MODULE_USAGE(
|
||||
#define STATS_EVERY_USEC (30 * PA_USEC_PER_SEC)
|
||||
|
||||
static const char* const valid_modargs[] = {
|
||||
"control_dir",
|
||||
"sink_name",
|
||||
"sink_properties",
|
||||
"format",
|
||||
@@ -70,7 +72,10 @@ static const char* const valid_modargs[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
struct android_volume;
|
||||
|
||||
struct userdata {
|
||||
struct android_volume *android_volume;
|
||||
pa_core *core;
|
||||
pa_module *module;
|
||||
pa_sink *sink;
|
||||
@@ -100,6 +105,9 @@ struct userdata {
|
||||
int32_t xruns_reported;
|
||||
};
|
||||
|
||||
#include "android-volume.h"
|
||||
|
||||
|
||||
static pa_usec_t frames_to_usec(const struct userdata *u, int64_t frames) {
|
||||
return (pa_usec_t) (frames * (int64_t) PA_USEC_PER_SEC / (int64_t) u->ss.rate);
|
||||
}
|
||||
@@ -472,6 +480,7 @@ int pa__init(pa_module *m) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
u->android_volume = android_volume_new(u->sink, pa_modargs_get_value(ma, "control_dir", NULL));
|
||||
pa_sink_put(u->sink);
|
||||
pa_modargs_free(ma);
|
||||
return 0;
|
||||
@@ -498,6 +507,8 @@ void pa__done(pa_module *m) {
|
||||
if (!(u = m->userdata))
|
||||
return;
|
||||
|
||||
android_volume_free(u->android_volume);
|
||||
u->android_volume = NULL;
|
||||
if (u->sink)
|
||||
pa_sink_unlink(u->sink);
|
||||
if (u->thread) {
|
||||
|
||||
@@ -110,7 +110,8 @@
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
]
|
||||
],
|
||||
"ndk": true
|
||||
},
|
||||
"audio": {
|
||||
"script": "tools/components/recipes/audio.sh",
|
||||
|
||||
+11
-1
@@ -10,7 +10,7 @@
|
||||
# 5. on a foldable cycles the device state (half-opened, and with --closed also closed) through
|
||||
# `cmd device_state`, then puts the original state back;
|
||||
# 6. reads the newest session folder of a debug build: first frame, last frame rate, the
|
||||
# memory page size and the last process exits.
|
||||
# memory page size, the proot that session ran, and the last process exits.
|
||||
#
|
||||
# Usage: tools/device-smoke.sh [--serial SERIAL] [--apk FILE] [--pkg PACKAGE]
|
||||
# [--no-density] [--no-size] [--no-fold] [--closed]
|
||||
@@ -279,6 +279,16 @@ else
|
||||
ev=$(sh_ run-as "$pkg" cat "files/logs/$dir/events.jsonl" 2>/dev/null)
|
||||
echo "$ev" | grep -q '"frame.first"' && ok "first frame was drawn" || note "no frame.first in $dir"
|
||||
echo "$ev" | grep -q '"session.failed"' && bad "session.failed: $(echo "$ev" | grep '"session.failed"' | tail -1 | cut -c1-160)"
|
||||
report=$(sh_ run-as "$pkg" cat "files/logs/$dir/device.txt" 2>/dev/null)
|
||||
proot_line=$(echo "$report" | grep 'proot binary' | head -1)
|
||||
case $proot_line in
|
||||
*"rootfs fallback"*|*"missing"*) bad "session proot is not the patched binary ($proot_line)" ;;
|
||||
*"apk"*|*"add-on pack"*) ok "patched proot ($proot_line)" ;;
|
||||
*) note "device report has no proot binary line (build from before the check)" ;;
|
||||
esac
|
||||
app_log=$(sh_ run-as "$pkg" cat "files/logs/$dir/app.log" 2>/dev/null)
|
||||
echo "$app_log" | grep -Fq 'proot: fast path on (' && ok "proot fast path was on" \
|
||||
|| note "proot fast path activation was not recorded ($(echo "$report" | grep 'proot fast path' | tr '\n' '; '))"
|
||||
fps=$(sh_ run-as "$pkg" cat "files/logs/$dir/app.log" 2>/dev/null | grep 'last 10 s:' | tail -1 | sed 's/.*last 10 s: //' | cut -c1-70)
|
||||
[ -n "$fps" ] && echo " last stats $fps"
|
||||
sh_ run-as "$pkg" cat "files/logs/$dir/device.txt" 2>/dev/null | grep -E 'Memory page size|^Kernel' | sed 's/^/ report /'
|
||||
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
repo_root=$1
|
||||
source_dir=$2
|
||||
: "${NDK:=${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}}}"
|
||||
: "${NDK:?set NDK to the Android NDK root}"
|
||||
case "$(uname -s)" in
|
||||
Darwin) host=darwin-x86_64 ;;
|
||||
Linux) host=linux-x86_64 ;;
|
||||
*) echo 'Unsupported NDK host' >&2; exit 1 ;;
|
||||
esac
|
||||
toolchain="$NDK/toolchains/llvm/prebuilt/$host/bin"
|
||||
patch -d "$source_dir" -p1 < "$repo_root/tools/directaudio/microphone-toggle.patch"
|
||||
"$toolchain/aarch64-linux-android28-clang" -O2 -Wl,-z,max-page-size=16384 \
|
||||
"$source_dir/directaudio-relay.c" -o "$repo_root/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so" \
|
||||
-laaudio -llog -pthread
|
||||
"$toolchain/llvm-strip" --strip-unneeded "$repo_root/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
@@ -3,7 +3,7 @@ set -euo pipefail
|
||||
repo_root=$1
|
||||
sink_out=$2
|
||||
. "${repo_root}/tools/directaudio/release.env"
|
||||
for v in DIRECTAUDIO_REPO DIRECTAUDIO_TAG DIRECTAUDIO_WINE11_SHA256 DIRECTAUDIO_SYSTHREAD_SHA256 DIRECTAUDIO_RELAY_SHA256 DIRECTAUDIO_SINK_SHA256; do
|
||||
for v in DIRECTAUDIO_REPO DIRECTAUDIO_TAG DIRECTAUDIO_WINE11_SHA256 DIRECTAUDIO_SYSTHREAD_SHA256 DIRECTAUDIO_SINK_SHA256 DIRECTAUDIO_SOURCE_COMMIT DIRECTAUDIO_SOURCE_SHA256; do
|
||||
[[ -n "${!v:-}" && "${!v}" != TBD ]] || { echo "tools/directaudio/release.env: ${v} is not set" >&2; exit 1; }
|
||||
done
|
||||
work=$(mktemp -d)
|
||||
@@ -24,7 +24,15 @@ fetch() {
|
||||
}
|
||||
fetch directaudio-linux-wine11.zip "${DIRECTAUDIO_WINE11_SHA256}"
|
||||
fetch directaudio-linux-wine11-systhread.zip "${DIRECTAUDIO_SYSTHREAD_SHA256}"
|
||||
fetch directaudio-linux-relay.zip "${DIRECTAUDIO_RELAY_SHA256}"
|
||||
source_archive="${cache}/${DIRECTAUDIO_SOURCE_SHA256}-directaudio-source.tar.gz"
|
||||
if ! echo "${DIRECTAUDIO_SOURCE_SHA256} ${source_archive}" | sha256sum -c - >/dev/null 2>&1; then
|
||||
curl -fsSL --retry 3 -o "${work}/source.tar.gz" \
|
||||
"https://github.com/${DIRECTAUDIO_REPO}/archive/${DIRECTAUDIO_SOURCE_COMMIT}.tar.gz"
|
||||
echo "${DIRECTAUDIO_SOURCE_SHA256} ${work}/source.tar.gz" | sha256sum -c - >/dev/null
|
||||
mv "${work}/source.tar.gz" "${source_archive}"
|
||||
fi
|
||||
mkdir "${work}/source"
|
||||
tar -xzf "${source_archive}" --strip-components=1 -C "${work}/source"
|
||||
fetch directaudio-linux-sink.zip "${DIRECTAUDIO_SINK_SHA256}"
|
||||
|
||||
assets="${repo_root}/app/src/main/assets/directaudio"
|
||||
@@ -40,9 +48,8 @@ done
|
||||
grep -q '^abi wine11$' "${assets}/linux-wine11/version.txt"
|
||||
grep -q '^abi systhread$' "${assets}/linux-wine11-systhread/version.txt"
|
||||
|
||||
mkdir -p "${work}/relay" "${work}/sink" "${sink_out}" "${repo_root}/app/src/main/jniLibs/arm64-v8a"
|
||||
unzip -q "${work}/directaudio-linux-relay.zip" -d "${work}/relay"
|
||||
install -m755 "${work}/relay/libdirectaudiorelay.so" "${repo_root}/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
mkdir -p "${work}/sink" "${sink_out}" "${repo_root}/app/src/main/jniLibs/arm64-v8a"
|
||||
"${repo_root}/tools/directaudio/build-relay.sh" "${repo_root}" "${work}/source"
|
||||
unzip -q "${work}/directaudio-linux-sink.zip" -d "${work}/sink"
|
||||
install -m755 "${work}/sink/module-directaudio-native-sink.so" "${sink_out}/"
|
||||
echo "DirectAudio ${DIRECTAUDIO_TAG}: two driver sets, the relay helper and the client sink in place"
|
||||
@@ -0,0 +1,123 @@
|
||||
--- a/directaudio-relay.c
|
||||
+++ b/directaudio-relay.c
|
||||
@@ -70,6 +70,9 @@
|
||||
* session log captures it too. Event-level lines are always on: they fire a
|
||||
* handful of times per session and are what makes a field report actionable. */
|
||||
static int g_verbose;
|
||||
+static const char *g_mic_control;
|
||||
+static int g_mic_enabled = 1;
|
||||
+static pthread_mutex_t g_mic_operations = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static void rlog(const char *fmt, ...)
|
||||
{
|
||||
@@ -735,6 +738,9 @@
|
||||
(void)user;
|
||||
if (aq != __atomic_load_n(&g_mic.cq, __ATOMIC_SEQ_CST) && __atomic_load_n(&g_mic.cq, __ATOMIC_SEQ_CST))
|
||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||
+ if (!__atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE))
|
||||
+ memset(audioData, 0, numFrames * g_mic.in_channels *
|
||||
+ (g_mic.in_format == AAUDIO_FORMAT_PCM_I16 ? sizeof(int16_t) : sizeof(float)));
|
||||
__atomic_add_fetch(&g_mic.cb_count, 1, __ATOMIC_RELAXED);
|
||||
|
||||
pthread_mutex_lock(&g_clients_lock);
|
||||
@@ -832,13 +838,14 @@
|
||||
AAudioStream *aq = NULL;
|
||||
int start = 0, stop = 0;
|
||||
|
||||
+ pthread_mutex_lock(&g_mic_operations);
|
||||
pthread_mutex_lock(&g_mic.lock);
|
||||
g_mic.want += delta;
|
||||
if (g_mic.want < 0) g_mic.want = 0;
|
||||
if (g_mic.cq)
|
||||
{
|
||||
- if (g_mic.want > 0 && !g_mic.started) { g_mic.started = 1; start = 1; aq = g_mic.cq; }
|
||||
- if (g_mic.want == 0 && g_mic.started) { g_mic.started = 0; stop = 1; aq = g_mic.cq; }
|
||||
+ if (g_mic.want > 0 && __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE) && !g_mic.started) { g_mic.started = 1; start = 1; aq = g_mic.cq; }
|
||||
+ if ((g_mic.want == 0 || !__atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE)) && g_mic.started) { g_mic.started = 0; stop = 1; aq = g_mic.cq; }
|
||||
}
|
||||
pthread_mutex_unlock(&g_mic.lock);
|
||||
|
||||
@@ -856,8 +863,23 @@
|
||||
else if (stop)
|
||||
{
|
||||
AAudioStream_requestStop(aq);
|
||||
- REVENT("mic stop (%s was the last consumer)", who);
|
||||
- }
|
||||
+ REVENT("mic stop (%s)", who);
|
||||
+ }
|
||||
+ pthread_mutex_unlock(&g_mic_operations);
|
||||
+}
|
||||
+
|
||||
+static void mic_control_update(void)
|
||||
+{
|
||||
+ FILE *f;
|
||||
+ int enabled;
|
||||
+ if (!g_mic_control) return;
|
||||
+ f = fopen(g_mic_control, "r");
|
||||
+ enabled = f && fgetc(f) == '1';
|
||||
+ if (f) fclose(f);
|
||||
+ if (enabled == __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE)) return;
|
||||
+ __atomic_store_n(&g_mic_enabled, enabled, __ATOMIC_RELEASE);
|
||||
+ mic_want(0, "session toggle");
|
||||
+ REVENT("mic enabled=%d", enabled);
|
||||
}
|
||||
|
||||
static void *mic_reopen_thread(void *unused)
|
||||
@@ -870,8 +892,9 @@
|
||||
|
||||
__atomic_store_n(&g_mic.reopen_redo, 0, __ATOMIC_SEQ_CST);
|
||||
|
||||
+ pthread_mutex_lock(&g_mic_operations);
|
||||
pthread_mutex_lock(&g_mic.lock);
|
||||
- want_start = g_mic.want > 0;
|
||||
+ want_start = g_mic.want > 0 && __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE);
|
||||
pthread_mutex_unlock(&g_mic.lock);
|
||||
|
||||
if (open_input(&neu) == AAUDIO_OK)
|
||||
@@ -902,6 +925,7 @@
|
||||
AAudioStream_close(old);
|
||||
}
|
||||
|
||||
+ pthread_mutex_unlock(&g_mic_operations);
|
||||
if (__atomic_load_n(&g_mic.reopen_redo, __ATOMIC_SEQ_CST)) { usleep(20000); continue; }
|
||||
__atomic_store_n(&g_mic.reopen_running, 0, __ATOMIC_SEQ_CST);
|
||||
if (!__atomic_load_n(&g_mic.reopen_redo, __ATOMIC_SEQ_CST)) break;
|
||||
@@ -1348,7 +1372,8 @@
|
||||
/* ---- housekeeping: watchdog tick + mailbox watch, once a second ------------- */
|
||||
static void *housekeeping_thread(void *unused)
|
||||
{
|
||||
- struct timespec iv = { 1, 0 };
|
||||
+ struct timespec iv = { 0, 100000000 };
|
||||
+ unsigned tick = 0;
|
||||
|
||||
(void)unused;
|
||||
for (;;)
|
||||
@@ -1357,6 +1382,8 @@
|
||||
int reload = 0;
|
||||
|
||||
nanosleep(&iv, NULL);
|
||||
+ mic_control_update();
|
||||
+ if (++tick % 10) continue;
|
||||
|
||||
if (g_rt_path[0])
|
||||
{
|
||||
@@ -1402,8 +1429,9 @@
|
||||
{
|
||||
if (!strcmp(argv[i], "--socket") && i + 1 < argc) path = argv[++i];
|
||||
else if (!strcmp(argv[i], "--mic-fifo") && i + 1 < argc) fifo_path = argv[++i];
|
||||
+ else if (!strcmp(argv[i], "--mic-control") && i + 1 < argc) g_mic_control = argv[++i];
|
||||
else if (!strcmp(argv[i], "--log")) g_verbose = 1;
|
||||
- else { fprintf(stderr, "usage: directaudio-relay --socket <path> [--mic-fifo <path>] [--log]\n"); return 2; }
|
||||
+ else { fprintf(stderr, "usage: directaudio-relay --socket <path> [--mic-fifo <path>] [--mic-control <path>] [--log]\n"); return 2; }
|
||||
}
|
||||
if (!path)
|
||||
{
|
||||
@@ -1429,6 +1457,8 @@
|
||||
chmod(path, 0666);
|
||||
if (listen(srv, 8) != 0) { REVENT("listen: %d", errno); return 1; }
|
||||
|
||||
+ mic_control_update();
|
||||
+ REVENT("mic enabled=%d", __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE));
|
||||
if (pthread_create(&th, NULL, housekeeping_thread, NULL) == 0) pthread_detach(th);
|
||||
if (fifo_path && fifo_setup(fifo_path) != 0)
|
||||
REVENT("mic-fifo: disabled");
|
||||
@@ -2,5 +2,6 @@ DIRECTAUDIO_REPO=The412Banner/directaudio
|
||||
DIRECTAUDIO_TAG=directaudio-linux-v1.1.0
|
||||
DIRECTAUDIO_WINE11_SHA256=835e6cab072f5148893c43379e60506483aeb3f1444e777b430c295cbeb472c9
|
||||
DIRECTAUDIO_SYSTHREAD_SHA256=2ddc47f446142d5940540ad40a423ca8d47fd536e3225b888df1077c6be7329e
|
||||
DIRECTAUDIO_RELAY_SHA256=b68eb6d7a892fd92a1cd73fac36dc05cabb77cc73792e2c582d3eeccad355942
|
||||
DIRECTAUDIO_SINK_SHA256=1d5d3ed709e5389ef7603f019c62b07e4e8428bb42882193d4a144a5c15425b6
|
||||
DIRECTAUDIO_SOURCE_COMMIT=52aedbf8ddd42874a5bbd21df20e1046367f442e
|
||||
DIRECTAUDIO_SOURCE_SHA256=a20c9a0684ae3b1e60a6b9c17b7f1d5ec2501627ae9683aa9f391576a6c1974d
|
||||
@@ -59,6 +59,7 @@ PA_MODULE_DESCRIPTION("Android audio output: DirectAudio's AAudio engine, in-pro
|
||||
PA_MODULE_VERSION(PACKAGE_VERSION);
|
||||
PA_MODULE_LOAD_ONCE(false);
|
||||
PA_MODULE_USAGE(
|
||||
"control_dir=<Android media volume bridge directory> "
|
||||
"sink_name=<name for the sink> "
|
||||
"sink_properties=<properties for the sink> "
|
||||
"volume=<initial volume, linear, 1.0 = full> "
|
||||
@@ -91,11 +92,15 @@ PA_MODULE_USAGE(
|
||||
#define DA_FADE_FRAMES 64
|
||||
|
||||
static const char* const valid_modargs[] = {
|
||||
"control_dir",
|
||||
"sink_name", "sink_properties", "volume", "performance_mode", "buffer_ms", "max_ms", "ring_ms",
|
||||
"adaptive", "decay", "limiter", "watchdog", NULL
|
||||
};
|
||||
|
||||
struct android_volume;
|
||||
|
||||
struct userdata {
|
||||
struct android_volume *android_volume;
|
||||
pa_core *core;
|
||||
pa_module *module;
|
||||
pa_sink *sink;
|
||||
@@ -136,6 +141,9 @@ struct userdata {
|
||||
unsigned int opens;
|
||||
};
|
||||
|
||||
#include "../../aaudio-sink/android-volume.h"
|
||||
|
||||
|
||||
static uint64_t now_ns(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
@@ -774,6 +782,7 @@ int pa__init(pa_module *m) {
|
||||
pa_log("Failed to create thread.");
|
||||
goto fail;
|
||||
}
|
||||
u->android_volume = android_volume_new(u->sink, pa_modargs_get_value(ma, "control_dir", NULL));
|
||||
pa_sink_put(u->sink);
|
||||
pa_modargs_free(ma);
|
||||
return 0;
|
||||
@@ -799,6 +808,8 @@ void pa__done(pa_module *m) {
|
||||
pa_assert(m);
|
||||
if (!(u = m->userdata))
|
||||
return;
|
||||
android_volume_free(u->android_volume);
|
||||
u->android_volume = NULL;
|
||||
if (u->sink)
|
||||
pa_sink_unlink(u->sink);
|
||||
if (u->thread) {
|
||||
|
||||
@@ -17,7 +17,7 @@ if __name__ == '__main__':
|
||||
sys.exit('Docker is unavailable: ' + engine.stderr.strip())
|
||||
image = run('image', 'inspect', sys.argv[1])
|
||||
if image.returncode:
|
||||
if 'No such image' not in image.stderr:
|
||||
if 'No such image' not in image.stderr and 'image not known' not in image.stderr: # Docker, Podman
|
||||
sys.exit('Cannot inspect the build image: ' + image.stderr.strip())
|
||||
repo = Path(__file__).resolve().parents[1]
|
||||
subprocess.run(['docker', 'build', '--platform', 'linux/amd64', '-t', sys.argv[1],
|
||||
|
||||
+32
-1
@@ -21,6 +21,7 @@ from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from adb_device import DeviceResolutionError, resolve_serial
|
||||
from proot_profile import report as proot_profile_report
|
||||
|
||||
|
||||
# tools/release/variants.txt: the same app also ships as other packages (e.g. com.antutu.benchmark.full).
|
||||
@@ -37,6 +38,13 @@ class ControlError(RuntimeError):
|
||||
self.code = code
|
||||
|
||||
|
||||
def profile_slow_us(value: str) -> int:
|
||||
number = int(value)
|
||||
if not 1 <= number <= 1_000_000_000:
|
||||
raise argparse.ArgumentTypeError("--slow-us must be between 1 and 1000000000")
|
||||
return number
|
||||
|
||||
|
||||
def adb_path(configured: str | None) -> str:
|
||||
if configured:
|
||||
return configured
|
||||
@@ -628,6 +636,10 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
request["text"] = args.text
|
||||
return add_serial(checked(provider_call(adb, serial, "ui", request=request), "UI_FAILED"), serial)
|
||||
|
||||
if command == "proot-profile":
|
||||
lines = ["PROOT_PROFILE=1", f"PROOT_PROFILE_SLOW_US={args.slow_us}"] if args.profile_op == "enable" else ["PROOT_PROFILE=0"]
|
||||
return add_serial(checked(provider_call(adb, serial, "env", request={"op": "set", "lines": lines, "persistent": False}), "ENV_FAILED"), serial)
|
||||
|
||||
if command == "env":
|
||||
if args.env_op == "set":
|
||||
request = {"op": "set", "lines": args.lines, "persistent": args.persistent}
|
||||
@@ -828,6 +840,16 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
if name == "set-text":
|
||||
op.add_argument("--text", required=True)
|
||||
|
||||
profile = commands.add_parser("proot-profile", help="profile PRoot syscall handlers in the next session, or rank a saved log")
|
||||
profile_ops = profile.add_subparsers(dest="profile_op", required=True)
|
||||
profile_enable = profile_ops.add_parser("enable", help="enable counters and bounded slow samples for the next session")
|
||||
profile_enable.add_argument("--slow-us", type=profile_slow_us, default=1000, metavar="US")
|
||||
profile_ops.add_parser("disable", help="disable profiling for the next session")
|
||||
profile_report = profile_ops.add_parser("report", help="read a local session.log without a device")
|
||||
profile_report.add_argument("path", type=Path)
|
||||
profile_report.add_argument("--sort", choices=["wall", "cpu", "calls"], default="wall")
|
||||
profile_report.add_argument("--limit", type=int, default=20)
|
||||
|
||||
env = commands.add_parser("env", help="session environment lines (debugging tools)")
|
||||
env_ops = env.add_subparsers(dest="env_op", required=True)
|
||||
env_ops.add_parser("list")
|
||||
@@ -837,7 +859,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
env_clear = env_ops.add_parser("clear")
|
||||
env_clear.add_argument("scope", nargs="?", choices=["next", "persistent", "all"], default="next")
|
||||
|
||||
override = commands.add_parser("override", help="put a binary first on the next session's PATH (debugging tools)")
|
||||
override = commands.add_parser("override", help="override a program or libblfastpath.so for the next session (debugging tools)")
|
||||
override.add_argument("name", help="the program name, e.g. gamescope")
|
||||
override.add_argument("path", help="the local file to push")
|
||||
|
||||
@@ -941,6 +963,15 @@ def main(argv: list[str] | None = None) -> int:
|
||||
try:
|
||||
if not PACKAGE_NAME.fullmatch(PACKAGE): # it reaches the device shell through `am start` and `content call`
|
||||
raise ControlError(f"DROIDDECK_PACKAGE is not an Android package name: {PACKAGE!r}", "INVALID_REQUEST")
|
||||
if args.command == "proot-profile" and args.profile_op == "report":
|
||||
if args.limit < 1:
|
||||
raise ControlError("--limit must be positive", "INVALID_ARGUMENTS")
|
||||
try:
|
||||
result = proot_profile_report(args.path.expanduser(), args.sort, args.limit)
|
||||
except OSError as exc:
|
||||
raise ControlError(str(exc), "FILE_IO") from exc
|
||||
print(json.dumps(result, indent=2, sort_keys=True))
|
||||
return 0
|
||||
adb = adb_path(args.adb)
|
||||
serial = resolve_serial(adb, args.serial, log=True)
|
||||
result = execute(args, adb, serial)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
diff --git a/Source/Tools/FEXInterpreter/ELFCodeLoader.h b/Source/Tools/FEXInterpreter/ELFCodeLoader.h
|
||||
--- a/Source/Tools/FEXInterpreter/ELFCodeLoader.h
|
||||
+++ b/Source/Tools/FEXInterpreter/ELFCodeLoader.h
|
||||
@@ -640,7 +640,7 @@
|
||||
AuxVariables.emplace_back(auxv_t {16, HWCap}); // AT_HWCAP
|
||||
AuxVariables.emplace_back(auxv_t {26, HWCap2}); // AT_HWCAP2
|
||||
AuxVariables.emplace_back(auxv_t {51, CalculateSignalStackSize()}); // AT_MINSIGSTKSZ
|
||||
- AuxPlatform = &AuxVariables.emplace_back(auxv_t {24, ~0ULL}); // AT_PLATFORM
|
||||
+ AuxPlatform = &AuxVariables.emplace_back(auxv_t {15, ~0ULL}); // AT_PLATFORM
|
||||
AuxExecFN = &AuxVariables.emplace_back(auxv_t {AT_EXECFN, ~0ULL}); // AT_EXECFN
|
||||
|
||||
if (Is64BitMode()) {
|
||||
@@ -141,3 +141,74 @@ the patched component retained 1/20, then 0 after destruction. The unassigned
|
||||
control retained 20/20 and then 0. In Backpack Battles, two batches of ten touch
|
||||
drags leaked 188 and 197 SHM descriptors before the fix; the same batches added
|
||||
zero after the fix (112 total descriptors before and after each batch).
|
||||
|
||||
## 0117 WSI: cache the present-time Xwayland bypass check
|
||||
|
||||
`QueuePresentKHR` in the WSI layer calls `canBypassXWayland` for every swapchain on
|
||||
every present. Each call makes several synchronous X requests (window geometry,
|
||||
`_WINE_ALLOW_FLIP`, parent window, a child-window scan, the toplevel window). At
|
||||
high frame rates that is thousands of round trips a second: on an AYANEO Pocket FIT
|
||||
running AIO Graphics Test uncapped, Xwayland used 24-32% of a core and the game's
|
||||
present thread sat about half idle.
|
||||
|
||||
The patch can keep the result for `DROIDDECK_WSI_BYPASS_CHECK_MS` milliseconds. Unset
|
||||
or 0 keeps the per-present check; the app sets 100. With 100, a window resize or a flip/obscure change is seen up to 100 ms
|
||||
later than before; surface creation and capability queries still check every time.
|
||||
|
||||
## 0118 Wayland: preserve signed plane positions
|
||||
|
||||
Fill scaling and Steam magnification can place the image at negative x/y coordinates.
|
||||
The Wayland backend converted these signed positions through an unsigned size helper:
|
||||
at host scale 120, -120 became 35791275 and the image moved off-screen while overlays
|
||||
could remain visible. A separate signed conversion uses a 64-bit intermediate and
|
||||
retains the existing ceiling convention; viewport sizes keep their original helper.
|
||||
|
||||
The component build runs `wayland_scaling` for negative crop offsets, positive/zero
|
||||
positions, fractional host scales and wide intermediates. This patch may be worth
|
||||
upstreaming: the same unsigned position calls were present in ValveSoftware/gamescope
|
||||
3.16.29 and master `d175688ad4ec490dc7b0695c5c62f8807684a1f1` when checked on
|
||||
2026-10-26. Carry it here until an upstream release containing the fix is adopted.
|
||||
|
||||
Device validation on AYN Thor (1280x720 session, 1920x1080 Android output):
|
||||
800x600 and 1600x600 source windows retained their image through Auto, Fit,
|
||||
Stretch, Fill, Integer and 2x Steam magnification, including returning to Fit.
|
||||
The old component lost the image in Fill and magnification. The tested executable
|
||||
matches the pinned p14 archive and the locally assembled APK. Hardware checks used
|
||||
native Gamescope properties; the physical Back+LB shortcut was not independently
|
||||
confirmed. The original APK and runtime were restored after validation.
|
||||
|
||||
## 0119 WSI: default image count while the frame limiter runs
|
||||
|
||||
The app sets `GAMESCOPE_WSI_MIN_IMAGE_COUNT=8` so an uncapped game keeps drawing while
|
||||
gamescope turns its buffers around. With Steam's Frame Limit on, gamescope forces FIFO,
|
||||
and the layer always hands the driver MAILBOX, so a game with eight images could queue
|
||||
up to seven frames inside gamescope before it blocked: each one adds a frame of input
|
||||
latency at the limited rate.
|
||||
|
||||
While the limiter forces FIFO, the layer now reports and enforces its default minimum
|
||||
of 3 images instead of the raised count; with the limiter off it uses the raised count
|
||||
as before. DXVK and VKD3D-Proton already recreate their swapchain when the limiter
|
||||
changes (the layer returns `VK_ERROR_OUT_OF_DATE_KHR`), so their image count follows
|
||||
the Quick Access menu. Other apps keep their swapchain on a limiter change; they now
|
||||
get `VK_SUBOPTIMAL_KHR` while their image count no longer matches, unless the layer
|
||||
marks them as not taking it (`NoSuboptimal`).
|
||||
|
||||
## 0120 Wayland: nested refresh follows the host
|
||||
|
||||
`-r` fixes the refresh gamescope paces at, and the frame limiter and Steam's Frame Limit
|
||||
slider use the same value. The app passes the panel refresh at session start, so a
|
||||
panel switched to another mode during the session (for example in the device's own
|
||||
quick settings) left gamescope pacing at the old rate until the next session; only the
|
||||
reported output refresh changed.
|
||||
|
||||
With `GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1`, a refresh the host compositor reports
|
||||
through presentation feedback replaces the `-r` value, so pacing and the limiter switch
|
||||
with the panel. `-r` still sets the starting rate, which avoids gamescope assuming
|
||||
60 Hz until the first frame is shown. When the refresh changes, gamescope also sends
|
||||
its `gamescope_control` display information to Steam again; Steam otherwise reads it
|
||||
only when it binds.
|
||||
|
||||
A host mode switch can report a passing rate for a few frames (72 Hz between 144 and
|
||||
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.
|
||||
@@ -39,7 +39,7 @@ else
|
||||
fi
|
||||
PREP
|
||||
makepkg -A -s --noconfirm --skipchecksums --skippgpcheck
|
||||
meson test -C src/build --no-rebuild --print-errorlogs cursor_routing
|
||||
meson test -C src/build --no-rebuild --print-errorlogs cursor_routing wayland_scaling
|
||||
ls -l *.pkg.tar.*
|
||||
"
|
||||
cd "$WORK"
|
||||
@@ -52,7 +52,11 @@ tar -xf "$PKG" -C out --strip-components=2 usr/bin/gamescope
|
||||
mv out/gamescope out/usr/local/bin/gamescope
|
||||
chmod 755 out/usr/local/bin/gamescope
|
||||
strip --strip-unneeded out/usr/local/bin/gamescope || true
|
||||
NEEDED=$(readelf -d out/usr/local/bin/gamescope | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p')
|
||||
# The WSI layer carries patches too (0117); the runtime's stock copy is replaced.
|
||||
mkdir -p out/usr/lib
|
||||
tar --use-compress-program=unzstd -xf "$PKG" -C out usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so
|
||||
strip --strip-unneeded out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so || true
|
||||
NEEDED=$(for f in out/usr/local/bin/gamescope out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so; do readelf -d "$f" | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p'; done | sort -u)
|
||||
echo "NEEDED: $NEEDED"
|
||||
MISSING=""
|
||||
for lib in $NEEDED; do grep -qx "$lib" tools/gamescope/runtime-sonames.txt || MISSING="$MISSING $lib"; done
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
--- a/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.179978889 +0000
|
||||
+++ b/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.207978889 +0000
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <optional>
|
||||
|
||||
#include <poll.h>
|
||||
+#include <time.h>
|
||||
+#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
// For limiter file.
|
||||
#include <time.h>
|
||||
@@ -476,6 +478,34 @@
|
||||
// Cached for comparison.
|
||||
std::optional<VkRect2D> cachedWindowRect;
|
||||
|
||||
+ // canBypassXWayland costs several X round trips; at present time it is refreshed at most
|
||||
+ // every DROIDDECK_WSI_BYPASS_CHECK_MS (default 0 = every present; DroidDeck's Performance mode sets 100).
|
||||
+ std::optional<bool> presentBypass;
|
||||
+ bool presentBypassHdr = false;
|
||||
+ uint64_t presentBypassNs = 0;
|
||||
+
|
||||
+ static uint64_t presentBypassIntervalNs() {
|
||||
+ static const uint64_t interval = [] {
|
||||
+ const char *v = getenv("DROIDDECK_WSI_BYPASS_CHECK_MS");
|
||||
+ return uint64_t(v && *v ? strtoull(v, nullptr, 10) : 0) * 1000000ull;
|
||||
+ }();
|
||||
+ return interval;
|
||||
+ }
|
||||
+
|
||||
+ bool canBypassXWaylandAtPresent(bool hdrColorspace) {
|
||||
+ if (isWayland())
|
||||
+ return true;
|
||||
+ timespec ts;
|
||||
+ clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
+ const uint64_t now = uint64_t(ts.tv_sec) * 1000000000ull + uint64_t(ts.tv_nsec);
|
||||
+ if (!presentBypass || presentBypassHdr != hdrColorspace || now - presentBypassNs >= presentBypassIntervalNs()) {
|
||||
+ presentBypass = canBypassXWayland(hdrColorspace);
|
||||
+ presentBypassHdr = hdrColorspace;
|
||||
+ presentBypassNs = now;
|
||||
+ }
|
||||
+ return *presentBypass;
|
||||
+ }
|
||||
+
|
||||
bool isWayland() const {
|
||||
// Is native Wayland?
|
||||
return connection == nullptr;
|
||||
@@ -1597,7 +1627,7 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
- const bool canBypass = gamescopeSurface->canBypassXWayland(gamescopeSwapchain->isHdrColorspace);
|
||||
+ const bool canBypass = gamescopeSurface->canBypassXWaylandAtPresent(gamescopeSwapchain->isHdrColorspace);
|
||||
if (canBypass != gamescopeSwapchain->isBypassingXWayland) {
|
||||
if (canBypass) {
|
||||
if (!(gamescopeSurface->flags & GamescopeLayerClient::Flag::NoSuboptimal))
|
||||
@@ -0,0 +1,106 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index d00644f..40164ba 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "waitable.h"
|
||||
#include "Utils/TempFiles.h"
|
||||
#include "Utils/CursorRouting.h"
|
||||
+#include "Utils/WaylandScaling.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
@@ -1618,8 +1619,8 @@ namespace gamescope
|
||||
{
|
||||
wl_subsurface_set_position(
|
||||
m_pSubsurface,
|
||||
- WaylandScaleToLogical( oState->nDestX, uScale ),
|
||||
- WaylandScaleToLogical( oState->nDestY, uScale ) );
|
||||
+ gamescope::WaylandPositionToLogical( oState->nDestX, uScale ),
|
||||
+ gamescope::WaylandPositionToLogical( oState->nDestY, uScale ) );
|
||||
}
|
||||
// The x/y here does nothing? Why? What is it for...
|
||||
// Use the subsurface set_position thing instead.
|
||||
diff --git a/src/Utils/WaylandScaling.h b/src/Utils/WaylandScaling.h
|
||||
new file mode 100644
|
||||
index 0000000..d488e39
|
||||
--- /dev/null
|
||||
+++ b/src/Utils/WaylandScaling.h
|
||||
@@ -0,0 +1,12 @@
|
||||
+#pragma once
|
||||
+
|
||||
+#include <cstdint>
|
||||
+
|
||||
+namespace gamescope
|
||||
+{
|
||||
+ constexpr int32_t WaylandPositionToLogical( int32_t nValue, uint32_t uFactor )
|
||||
+ {
|
||||
+ const int64_t nScaled = int64_t( nValue ) * 120;
|
||||
+ return int32_t( nScaled / uFactor + ( nScaled % uFactor > 0 ) );
|
||||
+ }
|
||||
+}
|
||||
diff --git a/tests/meson.build b/tests/meson.build
|
||||
index 1ccdf7d..d86bf9e 100644
|
||||
--- a/tests/meson.build
|
||||
+++ b/tests/meson.build
|
||||
@@ -8,7 +8,7 @@ endforeach
|
||||
|
||||
gamescope_tests = executable(
|
||||
'gamescope_tests',
|
||||
- unittest_src + ['test_convar.cpp', 'test_cursor_routing.cpp', 'test_focus_placement.cpp', 'test_mangoapp_config.cpp', 'test_mangoapp_control.cpp', 'test_process.cpp', 'test_upscale.cpp', 'test_utils_parsers.cpp', 'test_utils_string.cpp', 'test_vrclient_detect.cpp'],
|
||||
+ unittest_src + ['test_convar.cpp', 'test_cursor_routing.cpp', 'test_focus_placement.cpp', 'test_mangoapp_config.cpp', 'test_mangoapp_control.cpp', 'test_process.cpp', 'test_upscale.cpp', 'test_utils_parsers.cpp', 'test_utils_string.cpp', 'test_vrclient_detect.cpp', 'test_wayland_scaling.cpp'],
|
||||
include_directories: [srcdir, sol2_include],
|
||||
dependencies: [catch2_dep, luajit_dep, cap_dep, drm_dep, glm_dep, wlroots_dep],
|
||||
cpp_args: gamescope_cpp_args,
|
||||
@@ -18,6 +18,7 @@ reaper_test_helper = executable('reaper_test_helper', 'reaper_test_helper.cpp')
|
||||
|
||||
test('convar', gamescope_tests, args: ['[convar]'])
|
||||
test('cursor_routing', gamescope_tests, args: ['[cursor_routing]'])
|
||||
+test('wayland_scaling', gamescope_tests, args: ['[wayland_scaling]'])
|
||||
test('focus_placement', gamescope_tests, args: ['[focus_placement]'])
|
||||
test('mangoapp_config', gamescope_tests, args: ['[mangoapp_config]'])
|
||||
test('mangoapp_control', gamescope_tests, args: ['[mangoapp_control]'])
|
||||
diff --git a/tests/test_wayland_scaling.cpp b/tests/test_wayland_scaling.cpp
|
||||
new file mode 100644
|
||||
index 0000000..498f55b
|
||||
--- /dev/null
|
||||
+++ b/tests/test_wayland_scaling.cpp
|
||||
@@ -0,0 +1,38 @@
|
||||
+#include <catch2/catch_test_macros.hpp>
|
||||
+
|
||||
+#include "Utils/WaylandScaling.h"
|
||||
+
|
||||
+#include <cmath>
|
||||
+#include <limits>
|
||||
+
|
||||
+using namespace gamescope;
|
||||
+
|
||||
+TEST_CASE("cropped Wayland planes retain negative positions", "[wayland_scaling]")
|
||||
+{
|
||||
+ REQUIRE( WaylandPositionToLogical( -120, 120 ) == -120 );
|
||||
+ REQUIRE( WaylandPositionToLogical( -640, 120 ) == -640 );
|
||||
+ REQUIRE( WaylandPositionToLogical( -360, 120 ) == -360 );
|
||||
+ REQUIRE( WaylandPositionToLogical( 0, 120 ) == 0 );
|
||||
+ REQUIRE( WaylandPositionToLogical( 160, 120 ) == 160 );
|
||||
+}
|
||||
+
|
||||
+TEST_CASE("Wayland positions round up at fractional host scales", "[wayland_scaling]")
|
||||
+{
|
||||
+ const int32_t positions[] = { -100000000, -1000000, -640, -120, -1, 0, 1, 120, 640, 1000000, 100000000 };
|
||||
+ const uint32_t scales[] = { 120, 150, 180, 240, 360, 480 };
|
||||
+ for ( uint32_t uScale : scales )
|
||||
+ {
|
||||
+ for ( int32_t nPosition : positions )
|
||||
+ {
|
||||
+ CAPTURE( nPosition, uScale );
|
||||
+ const int32_t nExpected = int32_t( std::ceil( (long double)( nPosition ) * 120 / uScale ) );
|
||||
+ REQUIRE( WaylandPositionToLogical( nPosition, uScale ) == nExpected );
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+TEST_CASE("Wayland position conversion widens before multiplying", "[wayland_scaling]")
|
||||
+{
|
||||
+ REQUIRE( WaylandPositionToLogical( std::numeric_limits<int32_t>::min(), 120 ) == std::numeric_limits<int32_t>::min() );
|
||||
+ REQUIRE( WaylandPositionToLogical( std::numeric_limits<int32_t>::max(), 120 ) == std::numeric_limits<int32_t>::max() );
|
||||
+}
|
||||
@@ -0,0 +1,59 @@
|
||||
diff --git a/layer/VkLayer_FROG_gamescope_wsi.cpp b/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
index ea4ba84..46d086c 100644
|
||||
--- a/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
+++ b/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
@@ -201,6 +201,13 @@ namespace GamescopeWSILayer {
|
||||
return s_minImageCount;
|
||||
}
|
||||
|
||||
+ // The raised count keeps an uncapped game drawing while gamescope turns its buffers around.
|
||||
+ // Under the frame limiter's FIFO the extra images only queue frames ahead of the screen,
|
||||
+ // so a limited swapchain gets the default count.
|
||||
+ static uint32_t getMinImageCount(bool forcingFifo) {
|
||||
+ return forcingFifo ? std::min(getMinImageCount(), 3u) : getMinImageCount();
|
||||
+ }
|
||||
+
|
||||
static bool getEnsureMinImageCount() {
|
||||
static bool s_ensureMinImageCount = []() -> bool {
|
||||
if (auto ensure = parseEnv<bool>("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT")) {
|
||||
@@ -984,7 +991,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
pSurfaceCapabilities->currentExtent = rect->extent;
|
||||
}
|
||||
- pSurfaceCapabilities->minImageCount = getMinImageCount();
|
||||
+ pSurfaceCapabilities->minImageCount = getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects));
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -1027,7 +1034,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
pSurfaceCapabilities->surfaceCapabilities.currentExtent = rect->extent;
|
||||
}
|
||||
- pSurfaceCapabilities->surfaceCapabilities.minImageCount = getMinImageCount();
|
||||
+ pSurfaceCapabilities->surfaceCapabilities.minImageCount = getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects));
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -1305,7 +1312,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
uint32_t minImageCount = swapchainInfo.minImageCount;
|
||||
if (getEnsureMinImageCount())
|
||||
- minImageCount = std::max(getMinImageCount(), minImageCount);
|
||||
+ minImageCount = std::max(getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects)), minImageCount);
|
||||
swapchainInfo.minImageCount = minImageCount;
|
||||
|
||||
fprintf(stderr, "[Gamescope WSI] Creating swapchain for xid: 0x%0x - oldSwapchain: %p - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
|
||||
@@ -1627,6 +1634,13 @@ namespace GamescopeWSILayer {
|
||||
continue;
|
||||
}
|
||||
|
||||
+ // Other apps keep their swapchain when the limiter changes; ask them to recreate it so
|
||||
+ // the image count follows the limiter as well.
|
||||
+ if (!frameLimiterAware && gamescopeSwapchain->forceFifo != forceFifo &&
|
||||
+ getMinImageCount(true) != getMinImageCount(false) &&
|
||||
+ !(gamescopeSurface->flags & GamescopeLayerClient::Flag::NoSuboptimal))
|
||||
+ UpdateSwapchainResult(VK_SUBOPTIMAL_KHR);
|
||||
+
|
||||
const bool canBypass = gamescopeSurface->canBypassXWaylandAtPresent(gamescopeSwapchain->isHdrColorspace);
|
||||
if (canBypass != gamescopeSwapchain->isBypassingXWayland) {
|
||||
if (canBypass) {
|
||||
@@ -0,0 +1,108 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 40164ba..1b85e63 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -1698,6 +1698,52 @@ namespace gamescope
|
||||
}
|
||||
}
|
||||
|
||||
+ // -r sets the refresh gamescope starts with. With GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1 a refresh
|
||||
+ // the host compositor reports later replaces it, so pacing and the frame limiter follow a panel
|
||||
+ // switched to another mode during the session.
|
||||
+ static bool NestedRefreshFollowsHost()
|
||||
+ {
|
||||
+ static const bool s_bFollow = []
|
||||
+ {
|
||||
+ const char *pszFollow = getenv( "GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST" );
|
||||
+ return pszFollow && atoi( pszFollow ) != 0;
|
||||
+ }();
|
||||
+ return s_bFollow;
|
||||
+ }
|
||||
+
|
||||
+ // A mode switch on the host can report a passing rate for a few frames (72 Hz between 144 and
|
||||
+ // 120 on an AYANEO Pocket FIT); a new rate is taken once it has been reported for 300 ms.
|
||||
+ // Until then gamescope keeps presenting, so a still screen also gets the feedback that takes it.
|
||||
+ static bool HostRefreshChanged( int32_t nRefreshmHz, uint64_t ulPresentedNs )
|
||||
+ {
|
||||
+ static int32_t s_nPendingmHz = 0;
|
||||
+ static uint64_t s_ulPendingSinceNs = 0;
|
||||
+ if ( !nRefreshmHz || nRefreshmHz == g_nOutputRefresh )
|
||||
+ {
|
||||
+ s_nPendingmHz = 0;
|
||||
+ return false;
|
||||
+ }
|
||||
+ if ( !NestedRefreshFollowsHost() )
|
||||
+ return true;
|
||||
+ if ( nRefreshmHz != s_nPendingmHz )
|
||||
+ {
|
||||
+ s_nPendingmHz = nRefreshmHz;
|
||||
+ s_ulPendingSinceNs = ulPresentedNs;
|
||||
+ }
|
||||
+ if ( ulPresentedNs - s_ulPendingSinceNs >= 300'000'000ul )
|
||||
+ return true;
|
||||
+ force_repaint();
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ static void FollowHostRefresh( int32_t nRefreshmHz )
|
||||
+ {
|
||||
+ if ( !NestedRefreshFollowsHost() || !g_nNestedRefresh || g_nNestedRefresh == nRefreshmHz )
|
||||
+ return;
|
||||
+ xdg_log.infof( "Nested refresh follows the host: %.3fhz", ConvertmHzToHz( (float) nRefreshmHz ) );
|
||||
+ g_nNestedRefresh = nRefreshmHz;
|
||||
+ }
|
||||
+
|
||||
void CWaylandPlane::UpdateVRRRefreshRate()
|
||||
{
|
||||
if ( m_pParent )
|
||||
@@ -1724,6 +1770,7 @@ namespace gamescope
|
||||
// TODO(strategy): We should pick the largest refresh rate.
|
||||
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nLargestRefreshRateMhz ) );
|
||||
g_nOutputRefresh = nLargestRefreshRateMhz;
|
||||
+ FollowHostRefresh( nLargestRefreshRateMhz );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1794,10 +1841,11 @@ namespace gamescope
|
||||
if ( uRefreshCycle )
|
||||
{
|
||||
int32_t nRefresh = RefreshCycleTomHz( uRefreshCycle );
|
||||
- if ( nRefresh && nRefresh != g_nOutputRefresh )
|
||||
+ if ( HostRefreshChanged( nRefresh, ulTime ) )
|
||||
{
|
||||
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nRefresh ) );
|
||||
g_nOutputRefresh = nRefresh;
|
||||
+ FollowHostRefresh( nRefresh );
|
||||
}
|
||||
|
||||
m_pConnector->SetHostCompositorIsCurrentlyVRR( false );
|
||||
@@ -2636,6 +2684,9 @@ namespace gamescope
|
||||
}
|
||||
void CWaylandBackend::Wayland_Output_Mode( wl_output *pOutput, uint32_t uFlags, int32_t nWidth, int32_t nHeight, int32_t nRefresh )
|
||||
{
|
||||
+ // The followed rate comes from presentation feedback, so a still screen presents once for it.
|
||||
+ if ( NestedRefreshFollowsHost() && m_pOutputs[ pOutput ].nRefresh != nRefresh )
|
||||
+ force_repaint();
|
||||
m_pOutputs[ pOutput ].nRefresh = nRefresh;
|
||||
}
|
||||
void CWaylandBackend::Wayland_Output_Done( wl_output *pOutput )
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index 6c9299d..5fb9086 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -9254,6 +9254,15 @@ void update_vrr_atoms(xwayland_ctx_t *root_ctx, bool force, bool* needs_flush =
|
||||
g_nCurrentRefreshRate_CachedValue = g_nOutputRefresh;
|
||||
if (needs_flush)
|
||||
*needs_flush = true;
|
||||
+
|
||||
+ // Steam reads the display's refresh rates from gamescope_control when it binds; send them again.
|
||||
+ if ( !force )
|
||||
+ {
|
||||
+ wlserver_lock();
|
||||
+ for ( const auto &control : wlserver.gamescope_controls )
|
||||
+ wlserver_send_gamescope_control( control );
|
||||
+ wlserver_unlock();
|
||||
+ }
|
||||
}
|
||||
|
||||
// Don't update this in-sync with DRM vrr usage.
|
||||
@@ -12,6 +12,9 @@ export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
|
||||
export MOZ_SHM_NO_SEALS=1
|
||||
export KWIN_COMPOSE=Q QT_QUICK_BACKEND=software LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe
|
||||
[ -e /etc/mpv/mpv.conf ] || { mkdir -p /etc/mpv && echo gpu-sw=yes >/etc/mpv/mpv.conf; } 2>/dev/null
|
||||
for conf in client client-rt; do
|
||||
mkdir -p "/etc/pipewire/$conf.conf.d" && printf 'context.properties = {\n module.rt = false\n}\n' >"/etc/pipewire/$conf.conf.d/droiddeck-rt.conf"
|
||||
done 2>/dev/null
|
||||
export DROIDDECK_NESTED_SCALE=1
|
||||
export DROIDDECK_GLTHREAD=${mesa_glthread:-}
|
||||
unset MESA_LOADER_DRIVER_OVERRIDE LIBGL_KOPPER_DRI2 mesa_glthread
|
||||
|
||||
@@ -11,22 +11,43 @@ case "$backend" in
|
||||
wayland|sdl) ;;
|
||||
*) echo "== unsupported gamescope backend: $backend" >&2; exit 64 ;;
|
||||
esac
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
window=0
|
||||
if [ "$backend" = wayland ] && [ "${BL_DESKTOP_GPU_WINDOW:-1}" != 0 ] && [ -n "${WAYLAND_DISPLAY:-}" ] && [ "$WAYLAND_DISPLAY" != wayland-0 ]; then
|
||||
window=1
|
||||
parent=$WAYLAND_DISPLAY
|
||||
args=(--backend sdl --expose-wayland -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
else
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")
|
||||
fi
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
fi
|
||||
[ "${BL_HDR:-0}" = 1 ] && args+=(--hdr-enabled)
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
if [ "$window" = 1 ]; then
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} in a window on $parent)"
|
||||
else
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): $* (gamescope ${width}x${height} on wayland-0)"
|
||||
export WAYLAND_DISPLAY=wayland-0
|
||||
fi
|
||||
export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11
|
||||
[ "$backend" = sdl ] && export SDL_VIDEODRIVER=wayland
|
||||
unset LIBGL_ALWAYS_SOFTWARE QT_QUICK_BACKEND KWIN_COMPOSE
|
||||
wsi=",${MESA_VK_WSI_DEBUG:-},"
|
||||
while [[ $wsi == *,sw,* ]]; do wsi=${wsi//,sw,/,}; done
|
||||
wsi=${wsi#,}; wsi=${wsi%,}
|
||||
if [ -n "$wsi" ]; then export MESA_VK_WSI_DEBUG=$wsi; else unset MESA_VK_WSI_DEBUG; fi
|
||||
export BL_DESKTOP_GPU_CHILD=1
|
||||
export MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink LIBGL_KOPPER_DRI2=true
|
||||
[ -n "${DROIDDECK_GLTHREAD:-}" ] && export mesa_glthread=$DROIDDECK_GLTHREAD
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
gamescope "${args[@]}" -- env SDL_VIDEODRIVER=x11 /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
if [ "$window" = 1 ]; then
|
||||
export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-}
|
||||
SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
else
|
||||
gamescope "${args[@]}" -- env SDL_VIDEODRIVER=x11 /usr/local/bin/droiddeck-gpu-window "$@"
|
||||
fi
|
||||
rc=$?
|
||||
echo "== droiddeck-gpu $(date -u +%H:%M:%S): exited $rc"
|
||||
exit $rc
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Runs DroidDeck's bundled innoextract with its own boost libraries. The guest's
|
||||
# env -i startup has no LD_LIBRARY_PATH, and the rootfs must not grow a second
|
||||
# copy of boost for the installer fallback.
|
||||
LD_LIBRARY_PATH=/usr/local/lib/droiddeck-inno
|
||||
export LD_LIBRARY_PATH
|
||||
exec /usr/local/lib/droiddeck-inno/innoextract "$@"
|
||||
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
BIN
Binary file not shown.
+23
@@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
Copyright (C) 2011-2020 Daniel Scharrer <daniel@constexpr.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author(s) be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
+1318
File diff suppressed because it is too large.
Load diff
@@ -11,6 +11,7 @@ import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
HOME = os.environ.get("HOME") or "/root"
|
||||
STEAM_ROOT = os.path.join(HOME, ".local", "share", "Steam")
|
||||
@@ -27,6 +28,8 @@ PRELOADS = "/usr/local/lib/droiddeck-fex"
|
||||
URUNTIME = "/usr/local/lib/droiddeck/uruntime"
|
||||
HOST_PRELOAD = "/etc/ld.so.preload"
|
||||
FEX_APPID = "3127680"
|
||||
OWN_FEX = "/usr/local"
|
||||
OWN_FEX_TAG = os.path.join(OWN_FEX, "share", "fex-emu", ".droiddeck-tag")
|
||||
SNIPER_APPID = "1628350"
|
||||
SLR4_APPID = "4183110"
|
||||
INSTALL_DIRS = {FEX_APPID: "FEX-Emu", SNIPER_APPID: "SteamLinuxRuntime_sniper", SLR4_APPID: "SteamLinuxRuntime_4"}
|
||||
@@ -152,8 +155,52 @@ def first_dir(prefix, candidates):
|
||||
return None
|
||||
|
||||
|
||||
def own_fex_loads():
|
||||
for name in ("FEX", "FEXServer"):
|
||||
binary = os.path.join(OWN_FEX, "bin", name)
|
||||
if not os.access(binary, os.X_OK):
|
||||
return False
|
||||
try:
|
||||
listed = subprocess.run(["/usr/lib/ld-linux-aarch64.so.1", "--list", binary],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=20)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return False
|
||||
if listed.returncode != 0 or b"not found" in listed.stdout:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def update_own_fex():
|
||||
wanted = os.environ.get("BL_FEX_TAG")
|
||||
if not wanted:
|
||||
return
|
||||
if (read_text(OWN_FEX_TAG) or "").strip() == wanted and own_fex_loads():
|
||||
return
|
||||
failed = os.path.join(STATE, "update-failed")
|
||||
try:
|
||||
if (read_text(failed) or "").strip() == wanted and time.time() - os.path.getmtime(failed) < 3600:
|
||||
return
|
||||
except OSError:
|
||||
pass
|
||||
say("installing DroidDeck's FEX build %s" % wanted)
|
||||
try:
|
||||
code = subprocess.call([os.path.join(BIN_DIR, "droiddeck-fex-update")], stdout=sys.stderr)
|
||||
except OSError:
|
||||
code = 1
|
||||
if code == 0:
|
||||
with contextlib.suppress(OSError):
|
||||
os.remove(failed)
|
||||
return
|
||||
with contextlib.suppress(OSError):
|
||||
with open(failed, "w", encoding="utf-8") as handle:
|
||||
handle.write(wanted + "\n")
|
||||
say("DroidDeck's FEX build %s did not install; using the FEX already here" % wanted)
|
||||
|
||||
|
||||
def fex_install():
|
||||
prefixes = []
|
||||
if os.path.isfile(OWN_FEX_TAG) and own_fex_loads():
|
||||
prefixes.append((OWN_FEX, False))
|
||||
tool = app_dir(FEX_APPID)
|
||||
if tool:
|
||||
prefixes += [(os.path.join(tool, sub), True) for sub in ("usr", "", "files/usr", "files")]
|
||||
@@ -445,6 +492,7 @@ def describe(fex, platform, graphics=None):
|
||||
|
||||
def prepare(app=SNIPER_APPID):
|
||||
with locked():
|
||||
update_own_fex()
|
||||
fex = fex_install()
|
||||
platform = runtime_platform(app)
|
||||
status = describe(fex, platform)
|
||||
@@ -730,6 +778,7 @@ def extracted():
|
||||
|
||||
def want_fex():
|
||||
with locked():
|
||||
update_own_fex()
|
||||
status = describe(fex_install(), runtime_platform(), graphics_platform())
|
||||
if not status["ready"]:
|
||||
request_install()
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
FEX_TAG=fex-2610-r5
|
||||
FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4
|
||||
FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst
|
||||
|
||||
# Whether every program in the FEX tree at $1 finds its libraries (r4 did not without libxxhash).
|
||||
fex_loads() {
|
||||
local b out
|
||||
for b in FEX FEXServer unsquashfs; do
|
||||
out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue
|
||||
echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2
|
||||
return 1
|
||||
done
|
||||
}
|
||||
|
||||
# Installs one FEX build only once its archive matches the sha256 and it loads. The files it replaces are kept
|
||||
# until the installed copy loads too, and put back otherwise; the tag is written last.
|
||||
fex_install() {
|
||||
local tag=$1 sha=$2 urls=$3 dst=/ tmp u f
|
||||
tmp=$(mktemp -d)
|
||||
for u in $urls; do
|
||||
curl -fsSL --retry 2 --connect-timeout 20 --speed-limit 1024 --speed-time 60 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
rm -f "$tmp/fex.tzst"
|
||||
done
|
||||
if [ ! -s "$tmp/fex.tzst" ]; then
|
||||
echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
(cd "$tmp/root" && find . ! -type d) > "$tmp/files"
|
||||
mkdir "$tmp/old"
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then
|
||||
cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; }
|
||||
fi
|
||||
done < "$tmp/files"
|
||||
if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" &&
|
||||
mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then
|
||||
rm -rf "$tmp"
|
||||
return 0
|
||||
fi
|
||||
echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
[ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f"
|
||||
done < "$tmp/files"
|
||||
tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
}
|
||||
|
||||
# The build DroidDeck-Components' fex.json names (the app passes it as BL_FEX_*) comes first, then a working
|
||||
# installed one, then FEX_TAG above. Sets FEX_NOW and FEX_FROM.
|
||||
fex_ready() {
|
||||
local have ok=
|
||||
have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true)
|
||||
[ -x /usr/local/bin/FEX ] && fex_loads / && ok=1
|
||||
if [ -n "${BL_FEX_TAG:-}" ]; then
|
||||
if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi
|
||||
step "downloading FEX ($BL_FEX_TAG)"
|
||||
if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi
|
||||
fi
|
||||
if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi
|
||||
step "downloading FEX ($FEX_TAG)"
|
||||
if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
||||
set -eu
|
||||
step() { echo "== STEP $*" >&2; }
|
||||
fex_ready || exit 1
|
||||
echo "$FEX_NOW ($FEX_FROM)"
|
||||
fi
|
||||
@@ -3,6 +3,7 @@ set -u
|
||||
export LANG=C.UTF-8
|
||||
step() { echo "== STEP $*"; }
|
||||
fail() { echo "== FAIL $*"; exit 1; }
|
||||
[ "$(id -u)" = 0 ] || fail "needs root: install Flatpak from the launcher's Store, which runs this as root"
|
||||
|
||||
PACKAGES="flatpak ostree appstream libxmlb libmalcontent libfyaml accountsservice composefs xdg-dbus-proxy"
|
||||
while read -r pkg probe; do
|
||||
@@ -24,6 +25,7 @@ NEEDS
|
||||
WORK=/var/cache/droiddeck-flatpak
|
||||
CONF=$WORK/pacman.conf
|
||||
mkdir -p "$WORK/pkg" "$WORK/db" || fail "cannot create $WORK"
|
||||
exec 9>"$WORK/setup.lock" && flock -n 9 || fail "another Flatpak setup is still running"
|
||||
|
||||
OVERSEAS="https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org"
|
||||
MAINLAND=""
|
||||
@@ -48,10 +50,14 @@ if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubrin
|
||||
fi
|
||||
|
||||
step "Reading the package lists"
|
||||
pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy >/dev/null 2>&1 \
|
||||
|| pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1 | tail -3 \
|
||||
|| fail "could not reach the Arch Linux ARM mirrors"
|
||||
[ -f "$WORK/db/sync/extra.db" ] || fail "could not reach the Arch Linux ARM mirrors"
|
||||
rm -f "$WORK/db/db.lck"
|
||||
sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) \
|
||||
|| sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1)
|
||||
if [ ! -f "$WORK/db/sync/extra.db" ]; then
|
||||
printf '%s\n' "$sync_log" | tail -3
|
||||
reason=$(printf '%s\n' "$sync_log" | grep -m1 -i '^error' | cut -c1-160)
|
||||
fail "could not reach the Arch Linux ARM mirrors${reason:+ ($reason)}"
|
||||
fi
|
||||
|
||||
step "Downloading Flatpak"
|
||||
out=$(pacman --config "$CONF" --dbpath "$WORK/db" --cachedir "$WORK/pkg" --noconfirm -Sw -dd $PACKAGES 2>&1)
|
||||
|
||||
@@ -103,10 +103,19 @@ def godot_vulkan(game):
|
||||
@fix
|
||||
def godot_sentry(game):
|
||||
sentry = sorted(n[:-4] for n in game.files if n.startswith("libsentry.windows.") and n.endswith(".dll"))
|
||||
if is_godot(game) and sentry:
|
||||
if is_godot(game) and sentry and ("coreclr.dll" in game.files or "godotsharp.dll" in game.files):
|
||||
return {"WINEDLLOVERRIDES": ";".join(n + "=d" for n in sentry)}, [], "Godot: Sentry crash handler off"
|
||||
|
||||
|
||||
@fix
|
||||
def d3dgear_hook(game):
|
||||
"""D3DGear's capture DLL left beside a game (The Crew 2) is loaded by it and hooks the DXGI swapchain;
|
||||
under Wine the hook faults over a thousand times within seconds and the game never presents again:
|
||||
black screen while the sound keeps playing."""
|
||||
if "d3dgear64.dll" in game.files:
|
||||
return {"WINEDLLOVERRIDES": "d3dgear64=d"}, [], "D3DGear capture hook off (it stops the game drawing)"
|
||||
|
||||
|
||||
@fix
|
||||
def deep_rock_gdk_raytracing(game):
|
||||
if game.stem == "fsd-wingdk-shipping" and not any(game.has_arg(arg) for arg in ("-raytracing", "-noraytracing")):
|
||||
@@ -122,12 +131,32 @@ def arkham_city_x87(game):
|
||||
|
||||
|
||||
|
||||
@fix
|
||||
def protonfixes_off(game):
|
||||
if game.stem in ("blackops3", "darksoulsremastered"):
|
||||
return {"PROTONFIXES_DISABLE": "1"}, [], "umu-protonfixes off (its ALSA audio and VC++ installer steps fail here)"
|
||||
|
||||
|
||||
@fix
|
||||
def caravan_sandwitch_feature_level(game):
|
||||
if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)"
|
||||
|
||||
|
||||
@fix
|
||||
def robocop_rogue_city_feature_level(game):
|
||||
"""vkd3d-proton turns mesh shaders off on Adreno, but 12_2 still advertises them, and UE5 then builds mesh
|
||||
pipelines with no pipeline layout that crash Turnip on launch."""
|
||||
if "robocop.exe" in game.files or game.stem == "robocop-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "RoboCop: Rogue City: D3D12 feature level 12_1"
|
||||
|
||||
|
||||
@fix
|
||||
def reskate_feature_level(game):
|
||||
if "skate.exe" in game.files and "reskate.dll" in game.files:
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "ReSkate (skate.): D3D12 feature level 12_1"
|
||||
|
||||
|
||||
@fix
|
||||
def cyberpunk_feature_level(game):
|
||||
if game.stem == "cyberpunk2077" or (
|
||||
@@ -240,7 +269,10 @@ def engine_fixes(exe, args):
|
||||
for check in FIXES:
|
||||
found = check(game)
|
||||
if found:
|
||||
env.update(found[0])
|
||||
for name, value in found[0].items():
|
||||
if name == "WINEDLLOVERRIDES" and env.get(name):
|
||||
value = env[name] + ";" + value
|
||||
env[name] = value
|
||||
extra += found[1]
|
||||
notes.append(found[2])
|
||||
return env, extra, notes
|
||||
@@ -273,6 +305,78 @@ def game_gpu(env):
|
||||
return result
|
||||
|
||||
|
||||
def vram_cap(env):
|
||||
"""Puts the session's VRAM cap ahead of the game's own DXVK settings, so a game profile can still raise it."""
|
||||
value = env.get("BL_VRAM_MB", "")
|
||||
if not re.fullmatch(r"[1-9][0-9]{0,6}", value):
|
||||
return env
|
||||
result = env.copy()
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
return result
|
||||
|
||||
|
||||
def parse_cores(text):
|
||||
"""CPU numbers from a list such as "0-3,6"; None when the text is not one."""
|
||||
cores = set()
|
||||
for part in text.replace(" ", "").split(","):
|
||||
match = re.fullmatch(r"(\d{1,3})(?:-(\d{1,3}))?", part)
|
||||
if not match:
|
||||
return None
|
||||
first, last = int(match.group(1)), int(match.group(2) or match.group(1))
|
||||
if last < first:
|
||||
return None
|
||||
cores.update(range(first, last + 1))
|
||||
return cores or None
|
||||
|
||||
|
||||
def online_cores():
|
||||
try:
|
||||
with open("/sys/devices/system/cpu/online") as f:
|
||||
cores = parse_cores(f.read().strip())
|
||||
except OSError:
|
||||
cores = None
|
||||
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
|
||||
|
||||
|
||||
def game_cores(env):
|
||||
"""Pins the game to the cores its profile names, in place of the session's game cores."""
|
||||
text = env.get("DROIDDECK_GAME_CORES", "").strip()
|
||||
if not text:
|
||||
return
|
||||
cores = parse_cores(text)
|
||||
chosen = cores & online_cores() if cores else None
|
||||
if not chosen:
|
||||
print("droiddeck-game-env: ignoring game cores %r" % text, file=sys.stderr)
|
||||
return
|
||||
try:
|
||||
os.sched_setaffinity(0, chosen)
|
||||
print("droiddeck-game-env: game cores %s" % ",".join(map(str, sorted(chosen))), file=sys.stderr)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
|
||||
|
||||
|
||||
def cpu_topology(env):
|
||||
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()):
|
||||
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):
|
||||
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)
|
||||
|
||||
|
||||
def apply_config(env, config, app_id, fixes=None):
|
||||
if config.get("version") != 1:
|
||||
raise ValueError("unsupported environment configuration")
|
||||
@@ -660,7 +764,10 @@ def main():
|
||||
env = game_logs(command, env, app_id)
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env = vram_cap(env)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
cpu_topology(env)
|
||||
try:
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
except Exception as error:
|
||||
|
||||
@@ -45,6 +45,13 @@ def advertise_compositing():
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
raise SystemExit('usage: droiddeck-gpu-window <program> [args...]')
|
||||
if 'BL_GPU_CHILD_WSI' in os.environ:
|
||||
wsi = os.environ.pop('BL_GPU_CHILD_WSI')
|
||||
if wsi:
|
||||
os.environ['MESA_VK_WSI_DEBUG'] = wsi
|
||||
else:
|
||||
os.environ.pop('MESA_VK_WSI_DEBUG', None)
|
||||
os.environ['SDL_VIDEODRIVER'] = 'x11'
|
||||
os.environ.setdefault('GTK_CSD', '1')
|
||||
try:
|
||||
connection = advertise_compositing()
|
||||
|
||||
@@ -9,9 +9,9 @@ Add an app does) when that holds native programs or libraries. A Steam library's
|
||||
droiddeck-open --exec FILE [ARGS...] an exec the kernel refused (libblsession)
|
||||
droiddeck-open --install the Run entries and default handlers
|
||||
|
||||
The desktop composites in software, so a program started from it goes full screen on the GPU
|
||||
(droiddeck-gpu), as the menu's games do: --window keeps it in a desktop window instead, --terminal
|
||||
runs it in Konsole. A plain script stays on the desktop, and an exec whose output is read (a terminal,
|
||||
The desktop composites in software, so a program started from it runs on the GPU in a window of its
|
||||
own (droiddeck-gpu), as the menu's games do: --window keeps it on the desktop's software drawing
|
||||
instead, --terminal runs it in Konsole. A plain script stays on the desktop, and an exec whose output is read (a terminal,
|
||||
a pipe, a file) stays where it was started.
|
||||
"""
|
||||
import fcntl
|
||||
@@ -337,7 +337,7 @@ def unattended(env):
|
||||
|
||||
|
||||
def placed(cmd, what, mode, env):
|
||||
"""[cmd] where it shows: full screen on the GPU from the desktop, else where it was started."""
|
||||
"""[cmd] where it shows: on the GPU from the desktop, else where it was started."""
|
||||
if mode == "terminal" and what not in ("windows", "steam") and shutil.which("konsole"):
|
||||
return ["konsole", "--hold", "-e"] + cmd
|
||||
if mode == "window" or what in ("script", "steam") or not on_desktop(env):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
"""Runs a Windows program with the Proton the Steam client has chosen for it.
|
||||
|
||||
droiddeck-proton-run [--window] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run --app ID [--dir FOLDER] [--options TEXT] [PROGRAM [ARGS...]]
|
||||
|
||||
The program belongs to an installed Steam game when it sits in one's folder, to a prefix when it
|
||||
@@ -10,10 +10,15 @@ its own, under the id the client gives a new shortcut. That title's CompatToolMa
|
||||
config.vdf picks the tool, else the client's default for all other titles ("0"). The tool is
|
||||
started as the client starts it - its toolmanifest's command line, the waitforexitandrun verb and
|
||||
the STEAM_COMPAT_* environment - so its wrapper applies the game's settings, components and audio.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D on the desktop's software
|
||||
GL (llvmpipe): KWin there composites in software, and the session's zink finds no device.
|
||||
--prefix ID puts the program in compatdata/ID whatever it is. --verb run starts it beside what already
|
||||
runs in the prefix, which waitforexitandrun would wait for; the wrapper's launch-time steps are skipped.
|
||||
--game-id ID keeps the id of the launch it runs for: gamescope shows the windows that carry the id Steam launched.
|
||||
--app starts one game without the Steam client (its Start without Steam): a Steam game's default
|
||||
Windows launch option from appinfo.vdf when no program is given, else the program in that
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options).
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options). Without
|
||||
--options it takes the launch options set in the client's Properties for that game or shortcut.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -30,7 +35,10 @@ BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
STATE = os.path.join(HOME, ".local", "share", "droiddeck-compat", "state.json")
|
||||
EXTRA_LIBRARIES = ("/mnt/droiddeck", "/mnt/droiddeck-sd")
|
||||
SYSTEM_TOOLS = ("/usr/share/steam/compatibilitytools.d", "/usr/local/share/steam/compatibilitytools.d")
|
||||
DESKTOP_GL = {"LIBGL_ALWAYS_SOFTWARE": "1", "GALLIUM_DRIVER": "llvmpipe"}
|
||||
NOT_DESKTOP_GL = ("MESA_LOADER_DRIVER_OVERRIDE", "LIBGL_KOPPER_DRI2")
|
||||
VERB = "waitforexitandrun"
|
||||
VERBS = (VERB, "run")
|
||||
SHORTCUT_BIT = 0x80000000
|
||||
STEAM_APP_LIMIT = 2 ** 31
|
||||
|
||||
@@ -185,9 +193,9 @@ def steam_game(program, libs):
|
||||
def prefix_of(program):
|
||||
for folder, below in ancestors(program):
|
||||
parent = os.path.dirname(folder)
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and os.path.basename(folder).isdigit():
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and re.fullmatch(r"-?[0-9]+", os.path.basename(folder)):
|
||||
library = os.path.dirname(os.path.dirname(parent))
|
||||
return Target(os.path.basename(folder), folder, os.path.dirname(program), library, "prefix")
|
||||
return Target(str(int(os.path.basename(folder)) % 2 ** 32), folder, os.path.dirname(program), library, "prefix")
|
||||
return None
|
||||
|
||||
|
||||
@@ -230,10 +238,68 @@ def shortcut_entries(root):
|
||||
return entries
|
||||
|
||||
|
||||
def prefix_folder(root, appid):
|
||||
"""The prefix folder the client made for [appid], under either spelling of the id."""
|
||||
folder = os.path.join(root, "steamapps", "compatdata")
|
||||
try:
|
||||
names = sorted(os.listdir(folder))
|
||||
except OSError:
|
||||
names = []
|
||||
candidates = []
|
||||
for name in names:
|
||||
if not re.fullmatch(r"-?[0-9]+", name):
|
||||
continue
|
||||
try:
|
||||
matches = int(name) % 2 ** 32 == appid % 2 ** 32
|
||||
except ValueError:
|
||||
continue
|
||||
match = os.path.join(folder, name)
|
||||
if matches and os.path.isdir(match):
|
||||
candidates.append((os.path.isdir(os.path.join(match, "pfx")),
|
||||
name == str(appid % 2 ** 32), name, match))
|
||||
if candidates:
|
||||
return min(candidates, key=lambda item: (not item[0], not item[1], item[2]))[3]
|
||||
return os.path.join(folder, str(appid % 2 ** 32))
|
||||
|
||||
|
||||
def vdf_string(token):
|
||||
return re.sub(r'\\(.)', r'\1', token[1:-1]) if token.startswith('"') else ""
|
||||
|
||||
|
||||
def steam_options(app, root):
|
||||
"""The launch options the client keeps for a game (localconfig.vdf) or a shortcut (shortcuts.vdf)."""
|
||||
try:
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
account = tool["account_dir"](root)
|
||||
if not account:
|
||||
return ""
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f:
|
||||
shortcuts = tool["parse"](f.read()).get("shortcuts", {})
|
||||
for value in shortcuts.values():
|
||||
if isinstance(value, dict) and (value.get("appid", value.get("AppId")) or 0) & 0xFFFFFFFF == int(app):
|
||||
options = value.get("LaunchOptions", value.get("launchoptions", ""))
|
||||
return options if isinstance(options, str) else ""
|
||||
return ""
|
||||
tokens = compat()["tokenize"](read_text(os.path.join(account, "config", "localconfig.vdf")) or "")
|
||||
start = compat()["find_block"](tokens, ["UserLocalConfigStore", "Software", "Valve", "Steam", "apps", app])
|
||||
if start is None:
|
||||
return ""
|
||||
end, depth = compat()["block_end"](tokens, start), 0
|
||||
for i in range(start + 1, end):
|
||||
if tokens[i] in ("{", "}"):
|
||||
depth += 1 if tokens[i] == "{" else -1
|
||||
elif depth == 0 and tokens[i].lower() == '"launchoptions"' and i + 1 < end:
|
||||
return vdf_string(tokens[i + 1])
|
||||
except (OSError, ValueError, IndexError, KeyError, TypeError, AttributeError, struct.error):
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def shortcut(program, root):
|
||||
for appid, exe, start in shortcut_entries(root):
|
||||
if same_file(program, exe):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "shortcut", start if os.path.isdir(start) else None)
|
||||
return None
|
||||
|
||||
@@ -250,10 +316,19 @@ def locate(program, root):
|
||||
if found:
|
||||
return found
|
||||
appid = own_id(program)
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "own")
|
||||
|
||||
|
||||
def fixed(program, root, appid):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
os.path.dirname(program), root, "fixed")
|
||||
|
||||
|
||||
def prefix_id(value):
|
||||
return value if value.isdigit() and not value.startswith("0") and int(value) <= 0xFFFFFFFF else None
|
||||
|
||||
|
||||
def split_words(text):
|
||||
try:
|
||||
return shlex.split(text or "")
|
||||
@@ -325,7 +400,8 @@ def steam_launch(appid, root):
|
||||
|
||||
|
||||
def shortcut_target(appid, program, start, root):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)), os.path.dirname(program), root,
|
||||
appid = int(appid) % 2 ** 32
|
||||
return Target(str(appid), prefix_folder(root, appid), os.path.dirname(program), root,
|
||||
"shortcut", start if start and os.path.isdir(start) else None)
|
||||
|
||||
|
||||
@@ -337,7 +413,7 @@ def steam_launches(target, program, root):
|
||||
return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ())
|
||||
|
||||
|
||||
def environment(env, target, tool_folder, root, window=False):
|
||||
def environment(env, target, tool_folder, root, window=False, game_id=None):
|
||||
env = dict(env)
|
||||
steamapps = [os.path.join(lib, "steamapps") for lib in libraries(root)]
|
||||
env.update({
|
||||
@@ -355,28 +431,52 @@ def environment(env, target, tool_folder, root, window=False):
|
||||
else:
|
||||
game = str(number << 32 | 0x02000000)
|
||||
env.update(SteamAppId="0", STEAM_COMPAT_APP_ID="0", SteamGameId=game, SteamOverlayGameId=game)
|
||||
if game_id:
|
||||
env.update(SteamGameId=game_id, SteamOverlayGameId=game_id)
|
||||
if window:
|
||||
env.setdefault("PROTON_USE_WINED3D", "1")
|
||||
env.update(DESKTOP_GL)
|
||||
for name in NOT_DESKTOP_GL:
|
||||
env.pop(name, None)
|
||||
return env
|
||||
|
||||
|
||||
def windows_path(path):
|
||||
def windows_path(path, compatdata=None):
|
||||
if compatdata:
|
||||
drive = os.path.join(compatdata, "pfx", "drive_c")
|
||||
inside = os.path.relpath(path, drive)
|
||||
if inside != "." and not inside.startswith(".."):
|
||||
return "C:\\" + inside.replace("/", "\\")
|
||||
return "Z:" + path.replace("/", "\\")
|
||||
|
||||
|
||||
def arguments(program, args):
|
||||
def arguments(program, args, desktop=None, compatdata=None):
|
||||
if program.lower().endswith(".msi"):
|
||||
return ["msiexec", "/i", windows_path(program)] + args
|
||||
if desktop:
|
||||
return ["explorer.exe", "/desktop=droiddeck,%s" % desktop, windows_path(program, compatdata)] + args
|
||||
return [program] + args
|
||||
|
||||
|
||||
def main(argv):
|
||||
window = False
|
||||
app, start, options = None, None, ""
|
||||
prefix = None
|
||||
verb = VERB
|
||||
game_id = None
|
||||
desktop = None
|
||||
app, start, options = None, None, None
|
||||
while argv and argv[0].startswith("--"):
|
||||
option = argv.pop(0)
|
||||
if option == "--window":
|
||||
window = True
|
||||
elif option == "--prefix" and argv and prefix_id(argv[0]):
|
||||
prefix = argv.pop(0)
|
||||
elif option == "--verb" and argv and argv[0] in VERBS:
|
||||
verb = argv.pop(0)
|
||||
elif option == "--game-id" and argv and argv[0].isdigit() and argv[0] != "0":
|
||||
game_id = argv.pop(0)
|
||||
elif option == "--desktop" and argv and re.fullmatch(r"[1-9][0-9]{2,4}x[1-9][0-9]{2,4}", argv[0]):
|
||||
desktop = argv.pop(0)
|
||||
elif option in ("--app", "--dir", "--options") and argv:
|
||||
value = argv.pop(0)
|
||||
if option == "--app":
|
||||
@@ -394,9 +494,11 @@ def main(argv):
|
||||
say("%s is not an app id" % app)
|
||||
return 2
|
||||
if not argv and app is None:
|
||||
say("usage: droiddeck-proton-run [--window] PROGRAM [ARGS...]")
|
||||
say("usage: droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
if options is None:
|
||||
options = steam_options(app, root) if app is not None else ""
|
||||
extra, args = split_options(options)
|
||||
if not argv:
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
@@ -416,6 +518,8 @@ def main(argv):
|
||||
args = args + argv[1:]
|
||||
if app is not None and int(app) >= STEAM_APP_LIMIT:
|
||||
target = shortcut_target(app, program, start, root)
|
||||
elif prefix:
|
||||
target = fixed(program, root, prefix)
|
||||
else:
|
||||
target = locate(program, root)
|
||||
available = tools(root)
|
||||
@@ -425,7 +529,7 @@ def main(argv):
|
||||
return 69
|
||||
folder, command = available[name]
|
||||
os.makedirs(target.compatdata, exist_ok=True)
|
||||
env = environment(os.environ, target, folder, root, window)
|
||||
env = environment(os.environ, target, folder, root, window, game_id)
|
||||
env.update(extra)
|
||||
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
|
||||
", without the Steam client" if app is not None else ""))
|
||||
@@ -434,7 +538,7 @@ def main(argv):
|
||||
except OSError:
|
||||
os.chdir(os.path.dirname(program))
|
||||
entry = os.path.join(folder, command)
|
||||
os.execve(entry, [entry, VERB] + arguments(program, args), env)
|
||||
os.execve(entry, [entry, verb] + arguments(program, args, desktop, target.compatdata), env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -26,7 +26,7 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
fi
|
||||
exec > >({ dd of="$BL_LOG" oflag=append conv=notrunc iflag=count_bytes count="${BL_LOG_CAP:-268435456}" bs=65536 status=none; cat >/dev/null; }) 2>&1
|
||||
echo "== droiddeck-session $(date) mode=$mode $*"
|
||||
echo "== uid=$(id -u) size=${BL_WIDTH:-?}x${BL_HEIGHT:-?} fps=${BL_FPS:-0} icd=${VK_ICD_FILENAMES:-none}"
|
||||
echo "== uid=$(id -u) size=${BL_WIDTH:-?}x${BL_HEIGHT:-?} icd=${VK_ICD_FILENAMES:-none}"
|
||||
echo "== gamescope: $(gamescope --version 2>&1 | head -1) at $(command -v gamescope)"
|
||||
echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)"
|
||||
fi
|
||||
@@ -390,13 +390,19 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
nested=$width
|
||||
nested_h=$height
|
||||
if [ "${BL_FOLLOW_OUTPUT:-0}" = 1 ]; then
|
||||
echo "== gamescope: the output follows the screen (${width}x${height} to start)"
|
||||
elif [ "$mode" = steam ] && [ "${BL_GAMESCOPE_STRETCH_16X9:-0}" = 1 ]; then
|
||||
wide=$(( (height * 16 + 4) / 9 / 2 * 2 ))
|
||||
tall=$(( (width * 9 + 8) / 16 / 2 * 2 ))
|
||||
if [ "$wide" -gt "$width" ]; then
|
||||
nested=$wide
|
||||
echo "== gamescope: games at ${nested}x${height} stretched to the ${width}x${height} output"
|
||||
elif [ "$tall" -gt "$height" ]; then
|
||||
nested_h=$tall
|
||||
fi
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
backend=${BL_GAMESCOPE_BACKEND:-wayland}
|
||||
@@ -410,12 +416,15 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then
|
||||
export gamescope_cursor_composite=2
|
||||
fi
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$height")
|
||||
[ "$nested" != "$width" ] && args+=(-S stretch) && export BL_STRETCHED=1
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args=(--backend "$backend" --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
args+=(-S stretch)
|
||||
export BL_STRETCHED=1
|
||||
fi
|
||||
if [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
# -r is the starting rate; gamescope follows the panel when it switches modes later.
|
||||
export GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1
|
||||
fi
|
||||
[ "$mode" = steam ] && [ "${BL_STEAM_UI:-}" != desktop ] && args+=(-e)
|
||||
if [ "$mode" = steam ] && [ "${BL_XWAYLAND_COUNT:-2}" -gt 1 ]; then
|
||||
@@ -434,6 +443,10 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== gamescope: mangoapp on ($(command -v mangoapp), config $MANGOHUD_CONFIGFILE)"
|
||||
fi
|
||||
export BL_INSIDE=1
|
||||
# A fixed path: left to itself gamescope creates a new limiter state file on every start.
|
||||
rm -f "${XDG_RUNTIME_DIR:-/tmp}"/gamescope-limiter-*
|
||||
export GAMESCOPE_LIMITER_FILE="${XDG_RUNTIME_DIR:-/tmp}/droiddeck-gamescope-limiter"
|
||||
rm -f "$GAMESCOPE_LIMITER_FILE"
|
||||
if [ "$mode" = steam ]; then
|
||||
if /usr/local/bin/droiddeck-pipewire start; then
|
||||
eval "$(/usr/local/bin/droiddeck-pipewire env)"
|
||||
@@ -631,49 +644,172 @@ case $mode in
|
||||
fi
|
||||
if [ "${BL_ZRAM:-0}" = 1 ]; then
|
||||
step "zRAM compression: on"
|
||||
[ "${BL_ZRAM_CLIENT:-1}" = 1 ] || step "zRAM: Steam is not compressed while games run (turned off in Performance)"
|
||||
_bl_ram_cap=0
|
||||
case ${BL_RAM_CAP_MB:-} in
|
||||
''|0) ;;
|
||||
*[!0-9]*|0*|???????*) step "RAM cap: ignored invalid value '$BL_RAM_CAP_MB'" ;;
|
||||
*) _bl_ram_cap=$((BL_RAM_CAP_MB * 1024)); step "RAM cap: ${BL_RAM_CAP_MB} MB" ;;
|
||||
esac
|
||||
(
|
||||
bl_zram_scan() {
|
||||
_bl_game=0 _bl_pids=()
|
||||
_bl_game=0 _bl_pids=() _bl_others=() _bl_apps=
|
||||
local _d _c _args _name _a _id
|
||||
for _d in /proc/[0-9]*; do
|
||||
# Under FEX the program is FEX's first argument.
|
||||
{ IFS= read -r -d '' _c && case ${_c##*/} in FEX|FEXInterpreter) IFS= read -r -d '' _c ;; esac; } \
|
||||
2>/dev/null < "$_d/cmdline" || continue
|
||||
case ${_c##*/} in
|
||||
reaper) _bl_game=1 ;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d#/proc/}") ;;
|
||||
[ "${_d##*/}" != "$BASHPID" ] || continue
|
||||
_args=()
|
||||
# Under FEX the program is FEX's first argument. AppId= is its own argument.
|
||||
while IFS= read -r -d '' _c; do _args+=("$_c"); done 2>/dev/null < "$_d/cmdline" || true
|
||||
[ "${#_args[@]}" -gt 0 ] || continue
|
||||
_name=${_args[0]}
|
||||
if [ "${#_args[@]}" -gt 1 ]; then
|
||||
case ${_name##*/} in FEX|FEXInterpreter) _name=${_args[1]} ;; esac
|
||||
fi
|
||||
case ${_name##*/} in
|
||||
reaper)
|
||||
for _a in "${_args[@]}"; do
|
||||
case $_a in
|
||||
AppId=769) ;;
|
||||
AppId=[0-9]*)
|
||||
_id=${_a#AppId=}
|
||||
case $_id in *[!0-9]*) ;; *) _bl_game=1; _bl_apps="$_bl_apps $_id" ;; esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d##*/}") ;;
|
||||
*) _bl_others+=("${_d##*/}") ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
bl_zram_usage() {
|
||||
local _p _k _v _u _rss=0 _swap=0
|
||||
for _p in "${_bl_pids[@]}"; do
|
||||
for _p in "$@"; do
|
||||
while read -r _k _v _u; do
|
||||
case $_k in VmRSS:) _rss=$((_rss + _v)) ;; VmSwap:) _swap=$((_swap + _v)) ;; esac
|
||||
done 2>/dev/null < "/proc/$_p/status"
|
||||
done
|
||||
echo "${#_bl_pids[@]} processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
_bl_rss=$_rss
|
||||
echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
}
|
||||
# Only processes that loaded libblsession are the session's own and answer SIGURG.
|
||||
bl_session_others() {
|
||||
local _p
|
||||
_bl_session=()
|
||||
for _p in "${_bl_others[@]}"; do
|
||||
grep -q -m1 '/libblsession\.so$' "/proc/$_p/maps" 2>/dev/null && _bl_session+=("$_p")
|
||||
done
|
||||
}
|
||||
bl_zram_pick() {
|
||||
if [ "$1" = session ]; then
|
||||
bl_session_others
|
||||
_pids=("${_bl_session[@]}")
|
||||
else
|
||||
_pids=("${_bl_pids[@]}")
|
||||
fi
|
||||
}
|
||||
# Same protocol as SessionSuspendController: an empty ack when the page-out starts, a byte when it is done.
|
||||
# A process whose SIGURG handler was replaced never acks, so it is not waited for after the first 2 s.
|
||||
bl_zram_wait() {
|
||||
local _p _left _start=$SECONDS
|
||||
while [ $((SECONDS - _start)) -lt 12 ]; do
|
||||
_left=0
|
||||
for _p in "$@"; do
|
||||
[ -s "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
[ -d "/proc/$_p" ] || continue
|
||||
[ $((SECONDS - _start)) -ge 2 ] && [ ! -e "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
_left=1
|
||||
done
|
||||
[ "$_left" = 1 ] || break
|
||||
nap 0.2
|
||||
done
|
||||
for _p in "$@"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
}
|
||||
bl_zram_send() {
|
||||
step "zRAM: $2 ($(bl_zram_usage))"
|
||||
printf '%s' "$1" > /tmp/.bl-zram
|
||||
[ "${#_bl_pids[@]}" = 0 ] || kill -URG "${_bl_pids[@]}" 2>/dev/null
|
||||
nap 5
|
||||
local _mode=$1 _what=$2 _which=$3 _pids _p
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: $_what ($(bl_zram_usage "${_pids[@]}"))"
|
||||
for _p in "${_pids[@]}"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
printf '%s' "$_mode" > /tmp/.bl-zram
|
||||
[ "${#_pids[@]}" = 0 ] || kill -URG "${_pids[@]}" 2>/dev/null
|
||||
if [ "$_mode" = 1 ]; then bl_zram_wait "${_pids[@]}"; else nap 5; fi
|
||||
bl_zram_scan
|
||||
step "zRAM: done ($(bl_zram_usage))"
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: done ($(bl_zram_usage "${_pids[@]}"))"
|
||||
}
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
# Proton starts its reaper before the game window; compressing during launch stalls it.
|
||||
# Desktop Steam has no focus.json, so it still uses the game process as its trigger.
|
||||
# A configured RAM cap can still force compression while a game is launching.
|
||||
bl_game_focused() {
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] || [ -z "${BL_LAUNCH_DIR:-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
local id
|
||||
id=$(sed -n 's/.*"focusedApp"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' \
|
||||
"$BL_LAUNCH_DIR/agent/focus.json" 2>/dev/null | head -1)
|
||||
[ -n "$id" ] || return 1
|
||||
case " ${_bl_apps-} " in
|
||||
*" $id "*) return 0 ;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
bl_over_cap() {
|
||||
[ "$_bl_ram_cap" -gt 0 ] || return 1
|
||||
_bl_measured=$SECONDS
|
||||
bl_session_others
|
||||
bl_zram_usage "${_bl_pids[@]}" "${_bl_session[@]}" > /dev/null
|
||||
[ "$_bl_rss" -gt "$_bl_ram_cap" ]
|
||||
}
|
||||
bl_cap_due() {
|
||||
[ "$_bl_ram_cap" -gt 0 ] && { [ "$_bl_measured" -lt 0 ] || [ $((SECONDS - _bl_measured)) -ge 30 ]; }
|
||||
}
|
||||
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
|
||||
while kill -0 $$ 2>/dev/null; do
|
||||
bl_zram_scan
|
||||
if [ "$_bl_game" = 1 ]; then
|
||||
[ "$_bl_since" -ge 0 ] || _bl_since=$SECONDS
|
||||
if [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
if bl_cap_due; then
|
||||
if bl_over_cap; then
|
||||
# A cap below the game's working set cannot be met; paging out again every 30 s only churns.
|
||||
if [ "$_bl_capped" -lt 0 ] || [ $((SECONDS - _bl_capped)) -ge "$_bl_backoff" ]; then
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
if [ "$_bl_rss" -ge $((512 * 1024)) ]; then
|
||||
bl_zram_send 1 "over the ${BL_RAM_CAP_MB} MB RAM cap, compressing the client" client
|
||||
[ "$_bl_game" = 1 ] && _bl_packed=$SECONDS
|
||||
else
|
||||
step "RAM cap: over, client already small ($((_bl_rss / 1024)) MB resident), skipping it"
|
||||
fi
|
||||
bl_over_cap && bl_zram_send 1 "still over the RAM cap, compressing the rest of the session" session
|
||||
if bl_over_cap; then
|
||||
_bl_backoff=$((_bl_backoff * 2 > 600 ? 600 : _bl_backoff * 2))
|
||||
step "RAM cap: still over after paging out, next try in ${_bl_backoff} s"
|
||||
else
|
||||
_bl_backoff=30
|
||||
fi
|
||||
_bl_capped=$SECONDS
|
||||
fi
|
||||
else
|
||||
_bl_backoff=30
|
||||
if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ]; then
|
||||
bl_zram_send 0 "back under the RAM cap, reading the client back" client
|
||||
_bl_unpack=0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ "$_bl_game" = 1 ] && bl_game_focused; then
|
||||
if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then
|
||||
_bl_since=$SECONDS _bl_since_apps=$_bl_apps
|
||||
fi
|
||||
if [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
{ [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; }; then
|
||||
bl_zram_send 1 "compressing the client"
|
||||
bl_zram_send 1 "compressing the client" client
|
||||
_bl_packed=$SECONDS
|
||||
fi
|
||||
elif [ "$_bl_since" -ge 0 ]; then
|
||||
[ "$_bl_packed" -lt 0 ] || bl_zram_send 0 "game closed, reading the client back"
|
||||
elif [ "$_bl_game" != 1 ]; then
|
||||
if [ "$_bl_packed" -ge 0 ]; then
|
||||
if bl_over_cap; then _bl_unpack=1; else bl_zram_send 0 "game closed, reading the client back" client; _bl_unpack=0; fi
|
||||
fi
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
else
|
||||
_bl_since=-1
|
||||
fi
|
||||
nap 5
|
||||
done
|
||||
@@ -1007,7 +1143,11 @@ BUSCONF
|
||||
echo "== steam: devtools port $BL_CDP_PORT, guest processes only"
|
||||
fi
|
||||
[ -n "${BL_LAUNCH_DIR:-}" ] && mkdir -p "$BL_LAUNCH_DIR/agent" && echo "$BL_CDP_PORT" > "$BL_LAUNCH_DIR/agent/cdp-port"
|
||||
[ "$steam_x64" = 1 ] || { "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 & }
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
{ droiddeck-steam-compat --files-only "$steam_root" 2>&1 & }
|
||||
else
|
||||
{ "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 & }
|
||||
fi
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
# bl_steam_angle / bl_steam_presentation (set above) default to the Adreno values (vulkan,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import base64
|
||||
import ctypes
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import runpy
|
||||
import select
|
||||
@@ -15,6 +16,50 @@ import time
|
||||
HERE = os.path.dirname(os.path.realpath(__file__))
|
||||
COMPAT = runpy.run_path(os.path.join(HERE, "steam-compatibility"))
|
||||
BINDING = "droiddeckCompatChanged"
|
||||
BRIGHTNESS_BINDING = "droiddeckBrightnessChanged"
|
||||
CONTROLS_DIR = "/etc/droiddeck-device-controls"
|
||||
BRIGHTNESS_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckBrightness) return "present";
|
||||
const display = SteamClient.System?.Display;
|
||||
if (!display?.RegisterForBrightnessChanges || !display?.SetBrightness) return "unavailable";
|
||||
const self = { expected: null, updating: true, revision: 0 };
|
||||
self.set = value => {
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) return;
|
||||
if (!self.updating && self.expected !== null && Math.abs(value - self.expected) < 0.0001) return;
|
||||
self.expected = value;
|
||||
self.updating = true;
|
||||
const revision = ++self.revision;
|
||||
setTimeout(() => { if (self.revision === revision) self.updating = false; }, 500);
|
||||
display.SetBrightness(value);
|
||||
};
|
||||
self.subscription = display.RegisterForBrightnessChanges(state => {
|
||||
const value = state?.flBrightness;
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1 || self.expected === null) return;
|
||||
if (Math.abs(value - self.expected) < 0.0001) { self.updating = false; return; }
|
||||
if (self.updating) { self.updating = false; return; }
|
||||
self.expected = value;
|
||||
if (typeof window.__BINDING__ === "function") window.__BINDING__(String(value));
|
||||
});
|
||||
window.__droiddeckBrightness = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", BRIGHTNESS_BINDING)
|
||||
|
||||
|
||||
def brightness_request(payload, directory=CONTROLS_DIR):
|
||||
try:
|
||||
value = float(payload)
|
||||
if not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
path = os.path.join(directory, "brightness.request")
|
||||
with open(path + ".tmp", "w") as target:
|
||||
target.write(str(value) + "\n")
|
||||
os.replace(path + ".tmp", path)
|
||||
except (ValueError, TypeError, OSError):
|
||||
return
|
||||
|
||||
|
||||
INSTALL_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckCompat) return "present";
|
||||
@@ -196,6 +241,74 @@ TOUR_JS = r"""
|
||||
return "off";
|
||||
})()
|
||||
"""
|
||||
# Steam keeps the Quick Access Frame Limit as the client setting gamescope_app_target_framerate
|
||||
# (CMsgClientSettings field 21002) and offers the values gamescope's display state lists in
|
||||
# active_display_info.supported_frame_rates. When the panel's refresh rate changes, a remembered
|
||||
# limit that is not one of the new values leaves the slider on its first value while the game runs
|
||||
# at the old limit. The limit is kept when it is still offered and moved to the highest value
|
||||
# otherwise. Choices are read once they have been unchanged for a moment, since a mode switch can
|
||||
# report a passing rate first.
|
||||
FRAME_LIMIT_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckFrameLimit) return "present";
|
||||
const settings = window.settingsStore;
|
||||
let service = null;
|
||||
try {
|
||||
// Steam's webpack does not expose its module cache; the gamescope service client is found by
|
||||
// the calls its module makes and loaded by id.
|
||||
let require;
|
||||
window.webpackChunksteamui.push([[Symbol("droiddeck-frame-limit")], {}, r => { require = r; }]);
|
||||
for (const id of Object.keys(require.m || {})) {
|
||||
const source = String(require.m[id]);
|
||||
if (!source.includes("SetBlurParams") || !source.includes("RegisterForNotifyStateChanged")) continue;
|
||||
let exports;
|
||||
try { exports = require(id); } catch (e) { continue; }
|
||||
if (!exports || typeof exports !== "object") continue;
|
||||
service = Object.values(exports).find(value => value && typeof value.GetState === "function" &&
|
||||
typeof value.RegisterForNotifyStateChanged === "function" && typeof value.SetBlurParams === "function");
|
||||
if (service) break;
|
||||
}
|
||||
} catch (e) {
|
||||
service = null;
|
||||
}
|
||||
if (!service || !settings?.clientSettings || typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable";
|
||||
const self = { timer: null };
|
||||
const write = value => {
|
||||
const bytes = [];
|
||||
for (let n of [21002 * 8, value]) {
|
||||
while (n > 127) { bytes.push((n & 127) | 128); n = Math.floor(n / 128); }
|
||||
bytes.push(n);
|
||||
}
|
||||
return SteamClient.Settings.SetSetting(btoa(String.fromCharCode(...bytes)));
|
||||
};
|
||||
self.check = async () => {
|
||||
let rates;
|
||||
try {
|
||||
const reply = await service.GetState({});
|
||||
if (!reply.BSuccess()) return;
|
||||
rates = reply.Body().toObject().state?.active_display_info?.supported_frame_rates;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(rates) || rates.length === 0) return;
|
||||
const current = settings.clientSettings;
|
||||
if (!current.gamescope_enable_app_target_framerate || rates.includes(current.gamescope_app_target_framerate)) return;
|
||||
try {
|
||||
await write(Math.max(...rates));
|
||||
} catch (e) {
|
||||
}
|
||||
};
|
||||
self.schedule = () => {
|
||||
clearTimeout(self.timer);
|
||||
self.timer = setTimeout(self.check, 1500);
|
||||
};
|
||||
self.subscription = service.RegisterForNotifyStateChanged(self.schedule);
|
||||
self.interval = setInterval(self.schedule, 5000);
|
||||
self.schedule();
|
||||
window.__droiddeckFrameLimit = self;
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
FILE_BINDING = "droiddeckOpenFileDialog"
|
||||
FILE_JS = r"""
|
||||
(() => {
|
||||
@@ -620,10 +733,11 @@ class Watcher:
|
||||
|
||||
|
||||
class Helper:
|
||||
def __init__(self, steam_root, port, steamos=False):
|
||||
def __init__(self, steam_root, port, steamos=False, files_only=False):
|
||||
self.steam_root = steam_root
|
||||
self.port = port
|
||||
self.steamos = steamos
|
||||
self.files_only = files_only
|
||||
self.page = None
|
||||
self.known = set()
|
||||
self.installed = None
|
||||
@@ -632,6 +746,44 @@ class Helper:
|
||||
self.tools_checked = None
|
||||
self.vr_launch = None
|
||||
self.chooser = None
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
|
||||
def sync_controls(self):
|
||||
try:
|
||||
with open(os.path.join(CONTROLS_DIR, "state.json")) as source:
|
||||
state = json.load(source)
|
||||
value = state.get("brightness")
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or not 0 <= value <= 1:
|
||||
return
|
||||
if not self.controls_installed:
|
||||
self.page.call("Runtime.addBinding", {"name": BRIGHTNESS_BINDING})
|
||||
self.controls_installed = self.page.evaluate(BRIGHTNESS_JS) in ("installed", "present")
|
||||
if not self.controls_installed:
|
||||
return
|
||||
if state != self.controls_state:
|
||||
if self.page.evaluate("!!window.__droiddeckBrightness && (window.__droiddeckBrightness.set(%s), true)" % json.dumps(value)) is True:
|
||||
self.controls_state = state
|
||||
else:
|
||||
self.controls_installed = False
|
||||
self.controls_state = None
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def sync_frame_limit(self):
|
||||
# Steam can still be loading its settings and gamescope state when the helper attaches.
|
||||
if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry:
|
||||
return
|
||||
try:
|
||||
state = self.page.evaluate(FRAME_LIMIT_JS)
|
||||
except RuntimeError as e:
|
||||
state = "failed (%s)" % e
|
||||
if state != self.frame_limit_state:
|
||||
say("frame limit sync: %s" % state)
|
||||
self.frame_limit_state = state
|
||||
self.frame_limit_retry = time.monotonic() + 10
|
||||
|
||||
def open_chooser(self, payload):
|
||||
try:
|
||||
@@ -647,9 +799,14 @@ class Helper:
|
||||
self.finish_chooser(ident, None)
|
||||
return
|
||||
command = [sys.executable, os.path.realpath(__file__), "--choose-file"]
|
||||
reaper = os.path.join(self.steam_root, "steamrtarm64", "reaper")
|
||||
if os.access(reaper, os.X_OK):
|
||||
command = [reaper, "SteamLaunch", "AppId=769", "--"] + command
|
||||
# Gamescope shows the dialog over the client by the AppId on a reaper above it; the x86-64 client has no
|
||||
# native reaper, so the arm64 client's is borrowed when it is installed.
|
||||
data = os.environ.get("XDG_DATA_HOME") or os.path.join(os.path.expanduser("~"), ".local", "share")
|
||||
for root in (self.steam_root, os.path.join(data, "Steam")):
|
||||
reaper = os.path.join(root, "steamrtarm64", "reaper")
|
||||
if os.access(reaper, os.X_OK):
|
||||
command = [reaper, "SteamLaunch", "AppId=769", "--"] + command
|
||||
break
|
||||
try:
|
||||
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
@@ -699,6 +856,14 @@ class Helper:
|
||||
try:
|
||||
if page.evaluate("typeof SteamClient === 'object' && typeof SteamClient.WebUITransport === 'object'") is not True:
|
||||
raise LookupError("SteamClient is not ready")
|
||||
if self.files_only:
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.sync_controls()
|
||||
return True
|
||||
page.call("Runtime.addBinding", {"name": BINDING})
|
||||
page.call("Runtime.addBinding", {"name": VR_BINDING})
|
||||
page.evaluate(VR_JS)
|
||||
@@ -717,6 +882,11 @@ class Helper:
|
||||
page.ws.close()
|
||||
raise
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
self.sync_controls()
|
||||
return True
|
||||
|
||||
def reconcile(self):
|
||||
@@ -843,21 +1013,40 @@ class Helper:
|
||||
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
|
||||
self.vr_launch = launch_steamvr()
|
||||
for e in events:
|
||||
if called(e, BRIGHTNESS_BINDING):
|
||||
brightness_request(e.get("params", {}).get("payload"))
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
return events
|
||||
|
||||
def serve_files(self):
|
||||
say("attached to the client on port %d for its file dialogs" % self.port)
|
||||
while True:
|
||||
self.sync_controls()
|
||||
sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else [])
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
if self.page.ws in ready or self.page.events:
|
||||
self.drain()
|
||||
|
||||
def serve(self, watcher):
|
||||
if self.files_only:
|
||||
return self.serve_files()
|
||||
with open(COMPAT["state_path"]("live.pid"), "w") as f:
|
||||
f.write("%d\n" % os.getpid())
|
||||
say("attached to the client on port %d" % self.port)
|
||||
self.reconcile()
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
self.sync_controls()
|
||||
self.sync_frame_limit()
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 0.25)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
due = False
|
||||
@@ -903,12 +1092,29 @@ def chooser_main():
|
||||
|
||||
|
||||
def main():
|
||||
steam_root = sys.argv[1]
|
||||
files_only = sys.argv[1:2] == ["--files-only"]
|
||||
steam_root = sys.argv[2 if files_only else 1]
|
||||
try:
|
||||
port = int(os.environ.get("BL_CDP_PORT", ""))
|
||||
except ValueError:
|
||||
say("no devtools port for this session; the client's mapping is kept through config.vdf")
|
||||
return 0
|
||||
if files_only:
|
||||
helper = Helper(steam_root, port, files_only=True)
|
||||
failures = 0
|
||||
while True:
|
||||
try:
|
||||
helper.attach()
|
||||
failures = 0
|
||||
helper.serve(None)
|
||||
except Exception as e:
|
||||
helper.close_chooser()
|
||||
if helper.page is not None:
|
||||
say("lost the client (%s); reattaching" % e)
|
||||
helper.page.ws.close()
|
||||
helper.page = None
|
||||
failures += 1
|
||||
time.sleep(min(2 * max(failures, 1), 10))
|
||||
os.makedirs(COMPAT["COMPAT_DIR"], exist_ok=True)
|
||||
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json")] +
|
||||
[os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
|
||||
@@ -943,4 +1149,5 @@ if __name__ == "__main__":
|
||||
try:
|
||||
sys.exit(main())
|
||||
finally:
|
||||
detach()
|
||||
if sys.argv[1:2] != ["--files-only"]:
|
||||
detach()
|
||||
@@ -1,8 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
FEX_TAG=fex-2610-r5
|
||||
FEX_SHA256=0fc1ca2ba13817ad70d1ea157119a75c9c02446b57d166e6d676cce0807c19c4
|
||||
FEX_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/$FEX_TAG/fex.tzst
|
||||
ROOTFS_URL=https://github.com/Droid-Deck/DroidDeck-Components/releases/download/fex-rootfs-ubuntu-24.04-2026-08-11/Ubuntu_24_04.sqsh
|
||||
ROOTFS_SHA256=2854b06d3ff1b8f6e526135bfb6dd5b7b30ab3ab73e79ae933a3d9fed959a178
|
||||
CDN=https://client-update.fastly.steamstatic.com
|
||||
@@ -18,6 +15,7 @@ ARM_STEAM=${XDG_DATA_HOME:-$REAL_HOME/.local/share}/Steam
|
||||
LOG=$X64_HOME/steam-x64.log
|
||||
mkdir -p "$X64_HOME"
|
||||
step() { echo "== STEP $(date -u +%H:%M:%S) $*" | tee -a "$LOG"; }
|
||||
. "${BASH_SOURCE[0]%/*}/droiddeck-fex-update"
|
||||
|
||||
x64_default_dir() {
|
||||
local d
|
||||
@@ -319,76 +317,6 @@ print("droiddeck-steam-x64: %d Linux title(s) on DroidDeck direct (%d on the new
|
||||
PY
|
||||
}
|
||||
|
||||
# Whether every program in the FEX tree at $1 finds its libraries (r4 did not without libxxhash).
|
||||
fex_loads() {
|
||||
local b out
|
||||
for b in FEX FEXServer unsquashfs; do
|
||||
out=$(/usr/lib/ld-linux-aarch64.so.1 --list "$1/usr/local/bin/$b" 2>&1) && ! grep -q "not found" <<<"$out" && continue
|
||||
echo "== FEX check: $b: $(grep -E "not found|error" <<<"$out" | tr -s '\t ' ' ' | tr '\n' ';')" >&2
|
||||
return 1
|
||||
done
|
||||
}
|
||||
|
||||
# Installs one FEX build only once its archive matches the sha256 and it loads. The files it replaces are kept
|
||||
# until the installed copy loads too, and put back otherwise; the tag is written last.
|
||||
fex_install() {
|
||||
local tag=$1 sha=$2 urls=$3 dst=/ tmp u f
|
||||
tmp=$(mktemp -d)
|
||||
for u in $urls; do
|
||||
curl -fsSL --retry 2 "$u" -o "$tmp/fex.tzst" && echo "$sha $tmp/fex.tzst" | sha256sum -c --quiet >/dev/null 2>&1 && break
|
||||
rm -f "$tmp/fex.tzst"
|
||||
done
|
||||
if [ ! -s "$tmp/fex.tzst" ]; then
|
||||
echo "== FEX $tag: no source gave the archive with sha256 ${sha:0:12}" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! { mkdir "$tmp/root" && zstd -dc "$tmp/fex.tzst" | tar -C "$tmp/root" -x && fex_loads "$tmp/root"; }; then
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
(cd "$tmp/root" && find . ! -type d) > "$tmp/files"
|
||||
mkdir "$tmp/old"
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
if [ -e "$dst$f" ] || [ -L "$dst$f" ]; then
|
||||
cp -a --parents "$dst$f" "$tmp/old" || { echo "== FEX $tag: could not keep $dst$f aside" >&2; rm -rf "$tmp"; return 1; }
|
||||
fi
|
||||
done < "$tmp/files"
|
||||
if tar -C "$tmp/root" -c . | tar -C "$dst" -x && fex_loads "$dst" &&
|
||||
mkdir -p "${dst}usr/local/share/fex-emu" && echo "$tag" > "${dst}usr/local/share/fex-emu/.droiddeck-tag"; then
|
||||
rm -rf "$tmp"
|
||||
return 0
|
||||
fi
|
||||
echo "== FEX $tag: the installed copy did not load or its tag was not written; putting the previous files back" >&2
|
||||
while IFS= read -r f; do
|
||||
f=${f#./}
|
||||
[ -e "$tmp/old/$dst$f" ] || [ -L "$tmp/old/$dst$f" ] || rm -f "$dst$f"
|
||||
done < "$tmp/files"
|
||||
tar -C "$tmp/old$dst" -c . | tar -C "$dst" -x || echo "== FEX $tag: could not put the previous files back" >&2
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
}
|
||||
|
||||
# The build DroidDeck-Components' fex.json names (the app passes it as BL_FEX_*) comes first, then a working
|
||||
# installed one, then FEX_TAG above. Sets FEX_NOW and FEX_FROM.
|
||||
x64_fex() {
|
||||
local have ok=
|
||||
have=$(cat /usr/local/share/fex-emu/.droiddeck-tag 2>/dev/null || true)
|
||||
[ -x /usr/local/bin/FEX ] && fex_loads / && ok=1
|
||||
if [ -n "${BL_FEX_TAG:-}" ]; then
|
||||
if [ -n "$ok" ] && [ "$have" = "$BL_FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=catalog; return 0; fi
|
||||
step "downloading FEX ($BL_FEX_TAG)"
|
||||
if fex_install "$BL_FEX_TAG" "${BL_FEX_SHA256:-}" "${BL_FEX_URLS:-}"; then FEX_NOW=$BL_FEX_TAG FEX_FROM=catalog; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $BL_FEX_TAG did not install"; return 0; fi
|
||||
fi
|
||||
if [ -n "$ok" ] && [ "$have" = "$FEX_TAG" ]; then FEX_NOW=$have FEX_FROM=built-in; return 0; fi
|
||||
step "downloading FEX ($FEX_TAG)"
|
||||
if fex_install "$FEX_TAG" "$FEX_SHA256" "$FEX_URL"; then FEX_NOW=$FEX_TAG FEX_FROM=built-in; return 0; fi
|
||||
if [ -n "$ok" ]; then FEX_NOW=$have FEX_FROM="kept; $FEX_TAG did not install"; return 0; fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# A resumable download that reports every tenth of its size as a step.
|
||||
x64_fetch() {
|
||||
local url=$1 out=$2 label=$3 total pid rc=0 last=-1 pct
|
||||
@@ -406,7 +334,7 @@ x64_fetch() {
|
||||
}
|
||||
|
||||
x64_prepare() {
|
||||
x64_fex || { step "FEX could not be installed; see $LOG"; exit 1; }
|
||||
fex_ready || { step "FEX could not be installed; see $LOG"; exit 1; }
|
||||
step "FEX ready ($FEX_NOW, $FEX_FROM)"
|
||||
# The client's opt-in to its SteamRT3 build; without it, it re-executes through steam.sh, whose checks fail under proot.
|
||||
mkdir -p "$STEAM_X64" && : > "$STEAM_X64/.steam-enable-steamrt64-client"
|
||||
|
||||
@@ -25,6 +25,8 @@ Android: an EOS sign-in step that falls back to a browser (a consent Epic asks f
|
||||
is finished there. An EOS overlay pointer (HKCU\Software\Epic Games\EOS "OverlayPath") an earlier
|
||||
build wrote is removed - with it the game exited while loading.
|
||||
|
||||
Battle.net.exe in Battle.net's prefix is handed to droiddeck-battlenet, which runs the whole launch.
|
||||
|
||||
droiddeck-store-launch <the arguments Steam gave the compat tool>
|
||||
"""
|
||||
|
||||
@@ -291,6 +293,27 @@ def create_prefix(compat_data, proton, timeout=120):
|
||||
CLOUD_TIMEOUT = 15.0
|
||||
CLOUD_STORES = ("gog", "epic")
|
||||
STORE_GAME = 10
|
||||
RAN = 11
|
||||
RAN_FAILED = 12
|
||||
BATTLENET = "/usr/local/bin/droiddeck-battlenet"
|
||||
BATTLENET_EXE = re.compile(r"(?i)/compatdata/2596113170/pfx/drive_c/Program Files \(x86\)/Battle\.net/Battle\.net\.exe$")
|
||||
BATTLENET_LAUNCH = re.compile(r'(?i)^--exec=\s*"?launch\s+([A-Za-z0-9_]{1,16})"?$')
|
||||
|
||||
|
||||
def battlenet(argv, env=os.environ):
|
||||
if env.get("BL_BATTLENET"):
|
||||
return None
|
||||
exe, code = False, None
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'")
|
||||
if BATTLENET_EXE.search(arg.replace("\\", "/")):
|
||||
exe = True
|
||||
found = BATTLENET_LAUNCH.match(arg)
|
||||
if found:
|
||||
code = found.group(1)
|
||||
if not exe:
|
||||
return None
|
||||
return [BATTLENET, "launch", code] if code else [BATTLENET, "open"]
|
||||
|
||||
|
||||
def cloud_on(sidecar):
|
||||
@@ -511,6 +534,10 @@ def main(argv):
|
||||
pass
|
||||
rest = rest[2:]
|
||||
return exited(rest, code)
|
||||
command = battlenet(argv)
|
||||
if command is not None:
|
||||
log("battlenet " + " ".join(command[1:]))
|
||||
return RAN if subprocess.call(command) == 0 else RAN_FAILED
|
||||
found = find_store_game(argv)
|
||||
if found is None:
|
||||
return 0
|
||||
|
||||
@@ -27,6 +27,7 @@ CLASSES = {
|
||||
'Windows.Storage.Streams.DataWriter'),
|
||||
}
|
||||
CLASS_KEY = 'Software\\Microsoft\\WindowsRuntime\\ActivatableClassId\\'
|
||||
VIEW_DRIVES = 'xwvutsrqponmlkjihgfe'
|
||||
|
||||
|
||||
def bridge(upstream):
|
||||
@@ -137,6 +138,29 @@ def register_classes(proton, prefix, env):
|
||||
print('droiddeck-xbox: Windows Runtime class registration failed; launching without it', file=sys.stderr)
|
||||
|
||||
|
||||
def view_drive(prefix, exe):
|
||||
path = Path(exe)
|
||||
view = next((parent for parent in path.parents if parent.name.startswith('droiddeck-xbox-')), None)
|
||||
if not path.is_absolute() or view is None:
|
||||
return exe, None
|
||||
devices = prefix / 'dosdevices'
|
||||
for letter in VIEW_DRIVES:
|
||||
link = devices / (letter + ':')
|
||||
staged = devices / ('.%s-%s' % (letter, secrets.token_hex(4)))
|
||||
try:
|
||||
if os.path.lexists(link) and (os.path.exists(link) or not os.readlink(link).startswith(str(view.parent.parent) + '/')):
|
||||
continue
|
||||
devices.mkdir(parents=True, exist_ok=True)
|
||||
staged.symlink_to(view)
|
||||
os.replace(staged, link)
|
||||
except OSError:
|
||||
if os.path.lexists(staged):
|
||||
staged.unlink()
|
||||
continue
|
||||
return letter.upper() + ':\\' + str(path.relative_to(view)).replace('/', '\\'), link
|
||||
return exe, None
|
||||
|
||||
|
||||
def wine(argv, source_env=None):
|
||||
source_env = os.environ if source_env is None else source_env
|
||||
with open(source_env['DROIDDECK_XBOX_COMMAND_FILE'], encoding='utf-8') as file:
|
||||
@@ -163,7 +187,15 @@ def wine(argv, source_env=None):
|
||||
register_classes(command[0], prefix, env)
|
||||
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
|
||||
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
|
||||
return subprocess.call([*command[:2], argv[0], *command[3:]], env=env)
|
||||
exe, drive = view_drive(prefix, argv[0])
|
||||
try:
|
||||
return subprocess.call([*command[:2], exe, *command[3:]], env=env)
|
||||
finally:
|
||||
if drive is not None:
|
||||
try:
|
||||
drive.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def renew_lease(ask, channel, product, lease, stopped):
|
||||
|
||||
@@ -69,7 +69,10 @@ bl_store_launch() {
|
||||
fi
|
||||
[ -x /usr/local/bin/droiddeck-store-launch ] || return 0
|
||||
/usr/local/bin/droiddeck-store-launch "$@"
|
||||
[ $? -eq 10 ] && BL_STORE_EXIT=1
|
||||
rc=$?
|
||||
[ $rc -eq 10 ] && BL_STORE_EXIT=1
|
||||
[ $rc -eq 11 ] && exit 0
|
||||
[ $rc -eq 12 ] && exit 1
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -87,6 +90,34 @@ bl_run() {
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DESKTOP_GPU_SETUP = """
|
||||
bl_desktop_gpu() {
|
||||
local name saved gpu=/usr/local/bin/droiddeck-gpu
|
||||
local names=(LD_PRELOAD LD_LIBRARY_PATH ENABLE_VK_LAYER_VALVE_steam_overlay_1 ENABLE_VK_LAYER_VALVE_steam_fossilize_1)
|
||||
if [ -n "${BL_DESKTOP_GPU_CHILD:-}" ]; then
|
||||
for name in "${names[@]}"; do
|
||||
saved=BL_GPU_SAVED_$name
|
||||
[ -n "${!saved+x}" ] || continue
|
||||
export "$name=${!saved}"
|
||||
unset "$saved"
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
[ "${BL_DESKTOP:-}" = 1 ] && [ "${verb:-}" = waitforexitandrun ] && [ -x "$gpu" ] || return 0
|
||||
local choice=${BL_DESKTOP_GPU:-on}
|
||||
case "${choice,,}" in off | 0 | no | false) return 0 ;; esac
|
||||
case " $* " in *iscriptevaluator*) return 0 ;; esac
|
||||
local clear=()
|
||||
for name in "${names[@]}"; do
|
||||
[ -n "${!name+x}" ] || continue
|
||||
export "BL_GPU_SAVED_$name=${!name}"
|
||||
clear+=(-u "$name")
|
||||
done
|
||||
echo "droiddeck-gpu: the desktop starts this game on the GPU" >&2
|
||||
exec env "${clear[@]}" "$gpu" "$0" "$verb" "$@"
|
||||
}
|
||||
bl_desktop_gpu "$@"
|
||||
"""
|
||||
BL_COMPONENTS_SETUP = """
|
||||
bl_components() {
|
||||
base=$1
|
||||
@@ -380,7 +411,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_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
"verb=$1; shift", "verb=$1; shift\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)
|
||||
|
||||
|
||||
@@ -469,7 +500,7 @@ verb=$1; shift
|
||||
case $verb in
|
||||
getcompatpath | getnativepath) printf '%s\\n' "$1"; exit 0 ;;
|
||||
esac
|
||||
""" + BL_GAME_CPUS_SETUP + """
|
||||
""" + BL_DESKTOP_GPU_SETUP + BL_GAME_CPUS_SETUP + """
|
||||
bl_game_cpus
|
||||
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
|
||||
exec /usr/local/bin/droiddeck-steamvr-game ${BL_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
|
||||
@@ -652,7 +683,7 @@ def adopt_extras(tools):
|
||||
try:
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
'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(manifest, EXTRA_MANIFEST_VDF)
|
||||
@@ -1222,6 +1253,32 @@ def requested_games(requests, catalog, runnable=None):
|
||||
return resolved
|
||||
|
||||
|
||||
OWN_PROTON = "DroidDeck-Proton"
|
||||
ARCH_WORDS = re.compile(r"(?i)aarch64|arm64|x86_64|x86-64|amd64")
|
||||
|
||||
|
||||
def own_builds(tools):
|
||||
return [t for t in tools if isinstance(t, dict) and not t.get("valve") and
|
||||
isinstance(t.get("dir"), str) and t["dir"].startswith(OWN_PROTON) and t.get("name")]
|
||||
|
||||
|
||||
def build_key(name):
|
||||
return [int(n) for n in re.findall(r"\d+", ARCH_WORDS.sub(" ", name))]
|
||||
|
||||
|
||||
def own_proton_moves(state, catalog):
|
||||
names = {t["name"] for t in catalog}
|
||||
before = state.get("tools") if isinstance(state.get("tools"), list) else ()
|
||||
seen = state.get("own_builds") if isinstance(state.get("own_builds"), list) else []
|
||||
known = {n for n in seen if isinstance(n, str)} | {t["name"] for t in own_builds(before)} | {t["name"] for t in own_builds(catalog)}
|
||||
state["own_builds"] = sorted(known)
|
||||
builds = own_builds(catalog)
|
||||
if not builds:
|
||||
return None, set()
|
||||
newest = max(builds, key=lambda t: (build_key(t["dir"]), t["dir"]))["name"]
|
||||
return newest, known - names
|
||||
|
||||
|
||||
def now_ms():
|
||||
import time
|
||||
return int(time.time() * 1000)
|
||||
@@ -1382,11 +1439,26 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
catalog = tool_catalog(os.path.dirname(os.path.dirname(os.path.abspath(config_path))),
|
||||
dict(protect) if isinstance(protect, dict) else {name: name for name in protect})
|
||||
names = [t["name"] for t in catalog]
|
||||
newest, gone = own_proton_moves(state, catalog)
|
||||
previous, applied, chosen = state.get("default"), state.get("applied"), state.get("seq")
|
||||
if default is None:
|
||||
if settle:
|
||||
default, state = choose_default(current.get("0", ""), state, read_json(state_path("request.json", directory)), catalog)
|
||||
else:
|
||||
default = state.get("default") if state.get("default") in names else TOOL
|
||||
if settle and newest and default == TOOL and state.get("applied") == applied and state.get("seq") == chosen and (
|
||||
previous in gone or not state.get("own_proton")):
|
||||
default = newest
|
||||
state.update(default=newest, seq=now_ms(), source="update")
|
||||
if settle and newest:
|
||||
state["own_proton"] = True
|
||||
if newest:
|
||||
for app, name in list(current.items()):
|
||||
if app != "0" and name in gone:
|
||||
set_mapping(tokens, mapping, app, newest)
|
||||
current[app] = newest
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = {app: newest if name in gone else name for app, name in state["auto"].items()}
|
||||
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
|
||||
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
|
||||
overrides = requested_games(requests or {}, catalog)
|
||||
|
||||
@@ -407,6 +407,7 @@ int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long
|
||||
int bl_ntsync_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_venc_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_vdec_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg,
|
||||
@@ -423,6 +424,7 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
int rc;
|
||||
if (bl_ntsync_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_venc_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_vdec_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_drm_gem_close(fd, request, arg, &rc)) return rc;
|
||||
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
|
||||
if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
|
||||
|
||||
@@ -1459,10 +1459,12 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags) {
|
||||
|
||||
void bl_fsync_fds_closed(unsigned int first, unsigned int last) __attribute__((visibility("hidden")));
|
||||
void bl_venc_closed(int fd) __attribute__((visibility("hidden")));
|
||||
void bl_vdec_closed(int fd) __attribute__((visibility("hidden")));
|
||||
|
||||
int close(int fd) {
|
||||
if (fd >= 0) bl_fsync_fds_closed((unsigned int)fd, (unsigned int)fd);
|
||||
bl_venc_closed(fd);
|
||||
bl_vdec_closed(fd);
|
||||
uint64_t *t = __atomic_load_n(&ns_fdt, __ATOMIC_ACQUIRE);
|
||||
if (t && fd >= 0 && fd < NS_FDS && __atomic_load_n(&t[fd], __ATOMIC_ACQUIRE)) ns_forget(fd);
|
||||
return ns_close_fd(fd);
|
||||
|
||||
@@ -16,6 +16,7 @@ int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((vis
|
||||
int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
int bl_venc_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_vdec_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_dircache_create(int dirfd, const char *path, int flags, mode_t mode,
|
||||
int (*real)(int, const char *, int, mode_t)) __attribute__((visibility("hidden")));
|
||||
|
||||
@@ -57,6 +58,7 @@ int open(const char *path, int flags, ...) {
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_vdec_open(path, flags)) != -2) return fd;
|
||||
if (real_open == NULL) real_open = dlsym(RTLD_NEXT, "open");
|
||||
if (real_open == NULL) {
|
||||
errno = ENOSYS;
|
||||
@@ -84,6 +86,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_venc_open(path, flags)) != -2) return fd;
|
||||
if ((fd = bl_vdec_open(path, flags)) != -2) return fd;
|
||||
if (real_openat == NULL) real_openat = dlsym(RTLD_NEXT, "openat");
|
||||
if (real_openat == NULL) {
|
||||
errno = ENOSYS;
|
||||
|
||||
@@ -0,0 +1,978 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__aarch64__) || defined(BL_VDEC_ANY_ARCH)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../../app/src/main/cpp/venc/venc_proto.h"
|
||||
|
||||
#define VDEC_DEVICE "/dev/video-dec0"
|
||||
#define VDEC_INSTANCES 4
|
||||
#define VDEC_BUFFERS 16
|
||||
#define VDEC_BITSTREAM_SIZE (4u << 20)
|
||||
#define VDEC_PADDING 64
|
||||
#define VDEC_DUMB 64
|
||||
|
||||
struct vd_dma_heap_alloc {
|
||||
uint64_t len;
|
||||
uint32_t fd;
|
||||
uint32_t fd_flags;
|
||||
uint64_t heap_flags;
|
||||
};
|
||||
#define VD_DMA_HEAP_IOCTL_ALLOC _IOWR('H', 0x0, struct vd_dma_heap_alloc)
|
||||
|
||||
struct vd_dma_buf_sync {
|
||||
uint64_t flags;
|
||||
};
|
||||
#define VD_DMA_BUF_SYNC_WRITE 2u
|
||||
#define VD_DMA_BUF_SYNC_START 0u
|
||||
#define VD_DMA_BUF_SYNC_END 4u
|
||||
#define VD_DMA_BUF_IOCTL_SYNC _IOW('b', 0, struct vd_dma_buf_sync)
|
||||
|
||||
struct vd_create_dumb {
|
||||
uint32_t height, width, bpp, flags, handle, pitch;
|
||||
uint64_t size;
|
||||
};
|
||||
struct vd_destroy_dumb {
|
||||
uint32_t handle;
|
||||
};
|
||||
struct vd_prime_handle {
|
||||
uint32_t handle, flags;
|
||||
int32_t fd;
|
||||
};
|
||||
#define VD_IOCTL_MODE_CREATE_DUMB _IOWR('d', 0xB2, struct vd_create_dumb)
|
||||
#define VD_IOCTL_MODE_DESTROY_DUMB _IOWR('d', 0xB4, struct vd_destroy_dumb)
|
||||
#define VD_IOCTL_PRIME_HANDLE_TO_FD _IOWR('d', 0x2d, struct vd_prime_handle)
|
||||
|
||||
struct vd_mode_info {
|
||||
uint32_t clock;
|
||||
uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
|
||||
uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
|
||||
uint32_t vrefresh, flags, type;
|
||||
char name[32];
|
||||
};
|
||||
struct vd_res {
|
||||
int count_fbs;
|
||||
uint32_t *fbs;
|
||||
int count_crtcs;
|
||||
uint32_t *crtcs;
|
||||
int count_connectors;
|
||||
uint32_t *connectors;
|
||||
int count_encoders;
|
||||
uint32_t *encoders;
|
||||
uint32_t min_width, max_width, min_height, max_height;
|
||||
};
|
||||
struct vd_connector {
|
||||
uint32_t connector_id, encoder_id, connector_type, connector_type_id;
|
||||
int connection;
|
||||
uint32_t mm_width, mm_height;
|
||||
int subpixel;
|
||||
int count_modes;
|
||||
struct vd_mode_info *modes;
|
||||
int count_props;
|
||||
uint32_t *props;
|
||||
uint64_t *prop_values;
|
||||
int count_encoders;
|
||||
uint32_t *encoders;
|
||||
};
|
||||
struct vd_encoder {
|
||||
uint32_t encoder_id, encoder_type, crtc_id, possible_crtcs, possible_clones;
|
||||
};
|
||||
struct vd_crtc {
|
||||
uint32_t crtc_id, buffer_id, x, y, width, height;
|
||||
int mode_valid;
|
||||
struct vd_mode_info mode;
|
||||
int gamma_size;
|
||||
};
|
||||
struct vd_device {
|
||||
char **nodes;
|
||||
int available_nodes;
|
||||
int bustype;
|
||||
void *businfo;
|
||||
void *deviceinfo;
|
||||
};
|
||||
|
||||
struct vd_capture {
|
||||
int fd;
|
||||
ino_t ino;
|
||||
uint8_t *map;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct vd_done {
|
||||
uint32_t index;
|
||||
struct timeval timestamp;
|
||||
};
|
||||
|
||||
struct vdec {
|
||||
int used, fd;
|
||||
uint32_t fourcc, width, height;
|
||||
uint32_t cap_width, cap_height, bpl, cap_size;
|
||||
uint8_t *bitstream;
|
||||
uint32_t out_count;
|
||||
uint32_t out_done[VDEC_BUFFERS], n_out_done;
|
||||
struct vd_capture cap[VDEC_BUFFERS];
|
||||
uint32_t cap_count;
|
||||
uint32_t cap_queue[VDEC_BUFFERS], n_cap_queue;
|
||||
struct vd_done cap_done[VDEC_BUFFERS];
|
||||
uint32_t n_cap_done;
|
||||
int out_on, cap_on;
|
||||
int sock, hw, hw_failed;
|
||||
int64_t pts;
|
||||
void *ctx, *packet, *frame;
|
||||
uint8_t *packet_data;
|
||||
size_t packet_capacity;
|
||||
int last;
|
||||
uint32_t frames, slow;
|
||||
double decode_ms;
|
||||
};
|
||||
|
||||
static struct {
|
||||
void *(*find_decoder_by_name)(const char *);
|
||||
void *(*alloc_context3)(const void *);
|
||||
int (*open2)(void *, const void *, void **);
|
||||
void (*free_context)(void **);
|
||||
int (*send_packet)(void *, const void *);
|
||||
int (*receive_frame)(void *, void *);
|
||||
void (*flush_buffers)(void *);
|
||||
void *(*packet_alloc)(void);
|
||||
void (*packet_free)(void **);
|
||||
void *(*frame_alloc)(void);
|
||||
void (*frame_free)(void **);
|
||||
void (*frame_unref)(void *);
|
||||
int (*dict_set)(void **, const char *, const char *, int);
|
||||
void (*dict_free)(void **);
|
||||
const char *(*pix_fmt_name)(int);
|
||||
} av;
|
||||
|
||||
static pthread_mutex_t vd_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct vdec vd_all[VDEC_INSTANCES];
|
||||
static int vd_open_count;
|
||||
static int vd_state;
|
||||
static int vd_ffmpeg;
|
||||
static int vd_heap = -1;
|
||||
static int vd_dumb_fd[VDEC_DUMB];
|
||||
static char vd_drm_handle;
|
||||
|
||||
static void vd_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
static void vd_log(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char line[256];
|
||||
va_start(ap, fmt);
|
||||
int n = vsnprintf(line, sizeof line - 1, fmt, ap);
|
||||
va_end(ap);
|
||||
if (n < 0) return;
|
||||
if (n > (int)sizeof line - 2) n = sizeof line - 2;
|
||||
line[n++] = '\n';
|
||||
if (write(2, "droiddeck-vdec: ", 16) < 0 || write(2, line, n) < 0) return;
|
||||
}
|
||||
|
||||
static int vd_load_ffmpeg(void) {
|
||||
void *codec = dlopen("libavcodec.so.62", RTLD_LAZY | RTLD_LOCAL);
|
||||
void *util = codec ? dlopen("libavutil.so.60", RTLD_LAZY | RTLD_LOCAL) : NULL;
|
||||
if (codec == NULL || util == NULL) {
|
||||
vd_log("FFmpeg 8 is not available (%s), Remote Play decoding stays off", dlerror());
|
||||
return 0;
|
||||
}
|
||||
#define VD_SYM(lib, field, name) \
|
||||
if ((*(void **)&av.field = dlsym(lib, name)) == NULL) { \
|
||||
vd_log("FFmpeg has no %s, Remote Play decoding stays off", name); \
|
||||
return 0; \
|
||||
}
|
||||
VD_SYM(codec, find_decoder_by_name, "avcodec_find_decoder_by_name")
|
||||
VD_SYM(codec, alloc_context3, "avcodec_alloc_context3")
|
||||
VD_SYM(codec, open2, "avcodec_open2")
|
||||
VD_SYM(codec, free_context, "avcodec_free_context")
|
||||
VD_SYM(codec, send_packet, "avcodec_send_packet")
|
||||
VD_SYM(codec, receive_frame, "avcodec_receive_frame")
|
||||
VD_SYM(codec, flush_buffers, "avcodec_flush_buffers")
|
||||
VD_SYM(codec, packet_alloc, "av_packet_alloc")
|
||||
VD_SYM(codec, packet_free, "av_packet_free")
|
||||
VD_SYM(util, frame_alloc, "av_frame_alloc")
|
||||
VD_SYM(util, frame_free, "av_frame_free")
|
||||
VD_SYM(util, frame_unref, "av_frame_unref")
|
||||
VD_SYM(util, dict_set, "av_dict_set")
|
||||
VD_SYM(util, dict_free, "av_dict_free")
|
||||
VD_SYM(util, pix_fmt_name, "av_get_pix_fmt_name")
|
||||
#undef VD_SYM
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int vd_have_ffmpeg(void) {
|
||||
if (vd_ffmpeg == 0) vd_ffmpeg = vd_load_ffmpeg() ? 1 : -1;
|
||||
return vd_ffmpeg > 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_venc_connect(void);
|
||||
|
||||
static int vd_enabled(void) {
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
if (vd_state == 0) {
|
||||
const char *flag = getenv("BL_REMOTE_PLAY_DECODE"), *socket = getenv("BL_VENC_SOCKET");
|
||||
vd_state = -1;
|
||||
if (strcmp(program_invocation_short_name, "streaming_client") == 0 && (flag == NULL || strcmp(flag, "0") != 0)) {
|
||||
vd_heap = open("/dev/dma_heap/system", O_RDONLY | O_CLOEXEC);
|
||||
if (vd_heap < 0) vd_log("no /dev/dma_heap/system (%s), Remote Play decoding stays off", strerror(errno));
|
||||
else if ((socket && *socket) || vd_have_ffmpeg()) vd_state = 1;
|
||||
for (int i = 0; i < VDEC_DUMB; i++) vd_dumb_fd[i] = -1;
|
||||
}
|
||||
}
|
||||
int on = vd_state > 0;
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
return on;
|
||||
}
|
||||
|
||||
static struct vdec *vd_find(int fd) {
|
||||
if (fd < 0 || __atomic_load_n(&vd_open_count, __ATOMIC_ACQUIRE) == 0) return NULL;
|
||||
for (int i = 0; i < VDEC_INSTANCES; i++) if (vd_all[i].used && vd_all[i].fd == fd) return &vd_all[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_open(const char *path, int flags) {
|
||||
(void)flags;
|
||||
if (path == NULL || strcmp(path, VDEC_DEVICE) != 0 || !vd_enabled()) return -2;
|
||||
int fd = memfd_create("droiddeck-vdec", 0);
|
||||
if (fd < 0) return -1;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
struct vdec *v = NULL;
|
||||
for (int i = 0; i < VDEC_INSTANCES && v == NULL; i++) if (!vd_all[i].used) v = &vd_all[i];
|
||||
if (v == NULL) {
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
close(fd);
|
||||
errno = EBUSY;
|
||||
return -1;
|
||||
}
|
||||
memset(v, 0, sizeof *v);
|
||||
v->used = 1;
|
||||
v->fd = fd;
|
||||
v->fourcc = V4L2_PIX_FMT_H264;
|
||||
v->last = -1;
|
||||
v->sock = -1;
|
||||
for (int i = 0; i < VDEC_BUFFERS; i++) v->cap[i].fd = -1;
|
||||
__atomic_add_fetch(&vd_open_count, 1, __ATOMIC_RELEASE);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void vd_close_decoder(struct vdec *v) {
|
||||
if (v->frames) {
|
||||
vd_log("%u frames, %.1f ms each on average, %u over 25 ms", v->frames, v->decode_ms / v->frames, v->slow);
|
||||
}
|
||||
if (v->sock >= 0) close(v->sock);
|
||||
v->sock = -1;
|
||||
v->hw = 0;
|
||||
if (v->ctx) av.free_context(&v->ctx);
|
||||
if (v->packet) av.packet_free(&v->packet);
|
||||
if (v->frame) av.frame_free(&v->frame);
|
||||
free(v->packet_data);
|
||||
v->packet_data = NULL;
|
||||
v->packet_capacity = 0;
|
||||
v->frames = v->slow = 0;
|
||||
v->decode_ms = 0;
|
||||
v->last = -1;
|
||||
}
|
||||
|
||||
static int vd_send(int sock, const void *msg, size_t len, int fd) {
|
||||
struct iovec iov = { .iov_base = (void *)msg, .iov_len = len };
|
||||
char control[CMSG_SPACE(sizeof(int))];
|
||||
struct msghdr m = { .msg_iov = &iov, .msg_iovlen = 1 };
|
||||
if (fd >= 0) {
|
||||
memset(control, 0, sizeof control);
|
||||
m.msg_control = control;
|
||||
m.msg_controllen = sizeof control;
|
||||
struct cmsghdr *c = CMSG_FIRSTHDR(&m);
|
||||
c->cmsg_level = SOL_SOCKET;
|
||||
c->cmsg_type = SCM_RIGHTS;
|
||||
c->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
memcpy(CMSG_DATA(c), &fd, sizeof fd);
|
||||
}
|
||||
return sendmsg(sock, &m, MSG_NOSIGNAL) == (ssize_t)len ? 0 : -1;
|
||||
}
|
||||
|
||||
static void vd_send_capture(struct vdec *v, uint32_t index) {
|
||||
struct vdec_capture c = { .type = VDEC_CAPTURE, .index = index, .size = (uint32_t)v->cap[index].len };
|
||||
if (v->sock >= 0 && v->cap[index].map && vd_send(v->sock, &c, sizeof c, v->cap[index].fd) != 0)
|
||||
vd_log("could not hand capture buffer %u to the app: %s", index, strerror(errno));
|
||||
}
|
||||
|
||||
static int vd_open_hardware(struct vdec *v) {
|
||||
if (v->hw_failed) return -1;
|
||||
int sock = bl_venc_connect();
|
||||
if (sock < 0) return -1;
|
||||
struct vdec_config c = {
|
||||
.type = VDEC_CONFIG, .codec = v->fourcc == V4L2_PIX_FMT_HEVC ? VENC_HEVC : VENC_H264,
|
||||
.width = v->width ? v->width : v->cap_width, .height = v->height ? v->height : v->cap_height,
|
||||
.stride = v->bpl, .rows = v->cap_height, .bitstreams = v->out_count, .bitstream_size = VDEC_BITSTREAM_SIZE,
|
||||
};
|
||||
struct vdec_result r;
|
||||
if (vd_send(sock, &c, sizeof c, v->fd) != 0 || recv(sock, &r, sizeof r, 0) != (ssize_t)sizeof r ||
|
||||
r.type != VDEC_RESULT || r.status != 0) {
|
||||
vd_log("the app has no %s decoder for %ux%u", c.codec == VENC_HEVC ? "HEVC" : "H.264", c.width, c.height);
|
||||
close(sock);
|
||||
v->hw_failed = 1;
|
||||
return -1;
|
||||
}
|
||||
v->sock = sock;
|
||||
v->hw = 1;
|
||||
for (uint32_t i = 0; i < v->cap_count; i++) vd_send_capture(v, i);
|
||||
vd_log("decoding %s %ux%u with the app's MediaCodec into %ux%u NV12 dma-bufs",
|
||||
c.codec == VENC_HEVC ? "HEVC" : "H.264", c.width, c.height, v->cap_width, v->cap_height);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_open_decoder(struct vdec *v) {
|
||||
if (vd_open_hardware(v) == 0) return 0;
|
||||
if (!vd_have_ffmpeg()) return -1;
|
||||
const char *name = v->fourcc == V4L2_PIX_FMT_HEVC ? "hevc" : "h264";
|
||||
const void *codec = av.find_decoder_by_name(name);
|
||||
if (codec == NULL) {
|
||||
vd_log("FFmpeg has no %s decoder", name);
|
||||
return -1;
|
||||
}
|
||||
v->ctx = av.alloc_context3(codec);
|
||||
v->packet = av.packet_alloc();
|
||||
v->frame = av.frame_alloc();
|
||||
void *options = NULL;
|
||||
long cores = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
char threads[8];
|
||||
snprintf(threads, sizeof threads, "%ld", cores > 4 ? 4L : cores < 1 ? 1L : cores);
|
||||
av.dict_set(&options, "threads", threads, 0);
|
||||
av.dict_set(&options, "thread_type", "slice", 0);
|
||||
av.dict_set(&options, "flags", "+low_delay", 0);
|
||||
av.dict_set(&options, "flags2", "+fast", 0);
|
||||
int r = v->ctx && v->packet && v->frame ? av.open2(v->ctx, codec, &options) : -1;
|
||||
av.dict_free(&options);
|
||||
if (r < 0) {
|
||||
vd_log("could not open the %s decoder (%d)", name, r);
|
||||
vd_close_decoder(v);
|
||||
return -1;
|
||||
}
|
||||
vd_log("decoding %s %ux%u in software into %ux%u NV12 dma-bufs", v->fourcc == V4L2_PIX_FMT_HEVC ? "HEVC" : "H.264",
|
||||
v->width, v->height, v->cap_width, v->cap_height);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vd_unmap_capture(struct vdec *v) {
|
||||
for (uint32_t i = 0; i < VDEC_BUFFERS; i++) {
|
||||
if (v->cap[i].map) munmap(v->cap[i].map, v->cap[i].len);
|
||||
v->cap[i] = (struct vd_capture){ .fd = -1 };
|
||||
}
|
||||
v->cap_count = v->n_cap_queue = v->n_cap_done = 0;
|
||||
v->last = -1;
|
||||
}
|
||||
|
||||
static void vd_sync(int fd, uint64_t flags) {
|
||||
struct vd_dma_buf_sync s = { .flags = flags | VD_DMA_BUF_SYNC_WRITE };
|
||||
ioctl(fd, VD_DMA_BUF_IOCTL_SYNC, &s);
|
||||
}
|
||||
|
||||
static void vd_blank(struct vdec *v, struct vd_capture *c) {
|
||||
size_t luma = (size_t)v->bpl * v->cap_height;
|
||||
if (luma + luma / 2 > c->len) return;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
memset(c->map, 16, luma);
|
||||
memset(c->map + luma, 128, luma / 2);
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
}
|
||||
|
||||
static int vd_map_capture(struct vdec *v, uint32_t index, int fd) {
|
||||
struct stat st;
|
||||
if (fd < 0 || fstat(fd, &st) != 0) return -EINVAL;
|
||||
struct vd_capture *c = &v->cap[index];
|
||||
if (c->map && c->ino == st.st_ino) {
|
||||
c->fd = fd;
|
||||
return 0;
|
||||
}
|
||||
if (c->map) {
|
||||
munmap(c->map, c->len);
|
||||
*c = (struct vd_capture){ .fd = -1 };
|
||||
if (v->last == (int)index) v->last = -1;
|
||||
}
|
||||
off_t len = lseek(fd, 0, SEEK_END);
|
||||
if (len < (off_t)v->cap_size) return -EINVAL;
|
||||
void *p = mmap(NULL, (size_t)len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
vd_log("could not map capture buffer %u: %s", index, strerror(errno));
|
||||
*c = (struct vd_capture){ .fd = -1 };
|
||||
return -EINVAL;
|
||||
}
|
||||
*c = (struct vd_capture){ .fd = fd, .ino = st.st_ino, .map = p, .len = (size_t)len };
|
||||
vd_blank(v, c);
|
||||
if (v->hw) vd_send_capture(v, index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_write_frame(struct vdec *v, struct vd_capture *c) {
|
||||
uint8_t **data = (uint8_t **)v->frame;
|
||||
int *linesize = (int *)((uint8_t *)v->frame + 64);
|
||||
int width = *(int *)((uint8_t *)v->frame + 104), height = *(int *)((uint8_t *)v->frame + 108);
|
||||
const char *format = av.pix_fmt_name(*(int *)((uint8_t *)v->frame + 116));
|
||||
if (format == NULL || width <= 0 || height <= 0) return -1;
|
||||
int nv12 = strcmp(format, "nv12") == 0;
|
||||
if (!nv12 && strcmp(format, "yuv420p") != 0 && strcmp(format, "yuvj420p") != 0) {
|
||||
static int warned;
|
||||
if (!warned++) vd_log("cannot show %s frames", format);
|
||||
return -1;
|
||||
}
|
||||
uint32_t w = (uint32_t)width < v->bpl ? (uint32_t)width : v->bpl;
|
||||
uint32_t h = (uint32_t)height < v->cap_height ? (uint32_t)height : v->cap_height;
|
||||
uint8_t *y = c->map, *uv = c->map + (size_t)v->bpl * v->cap_height;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
for (uint32_t row = 0; row < h; row++) memcpy(y + (size_t)row * v->bpl, data[0] + (size_t)row * linesize[0], w);
|
||||
for (uint32_t row = 0; row < (h + 1) / 2; row++) {
|
||||
uint8_t *dst = uv + (size_t)row * v->bpl;
|
||||
if (nv12) {
|
||||
memcpy(dst, data[1] + (size_t)row * linesize[1], w & ~1u);
|
||||
continue;
|
||||
}
|
||||
const uint8_t *u = data[1] + (size_t)row * linesize[1], *vv = data[2] + (size_t)row * linesize[2];
|
||||
for (uint32_t x = 0; x < w / 2; x++) {
|
||||
dst[2 * x] = u[x];
|
||||
dst[2 * x + 1] = vv[x];
|
||||
}
|
||||
}
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vd_copy_last(struct vdec *v, struct vd_capture *c) {
|
||||
if (v->last < 0 || v->cap[v->last].map == NULL || &v->cap[v->last] == c) return;
|
||||
size_t size = v->cap_size < c->len ? v->cap_size : c->len;
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_START);
|
||||
memcpy(c->map, v->cap[v->last].map, size);
|
||||
vd_sync(c->fd, VD_DMA_BUF_SYNC_END);
|
||||
}
|
||||
|
||||
static double vd_now_ms(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return ts.tv_sec * 1000.0 + ts.tv_nsec / 1e6;
|
||||
}
|
||||
|
||||
static void vd_deliver(struct vdec *v, int written, double start, struct timeval timestamp) {
|
||||
uint32_t target = v->cap_queue[0];
|
||||
if (!written) {
|
||||
if (v->last < 0) return;
|
||||
vd_copy_last(v, &v->cap[target]);
|
||||
}
|
||||
double ms = vd_now_ms() - start;
|
||||
v->frames++;
|
||||
v->decode_ms += ms;
|
||||
if (ms > 25.0) v->slow++;
|
||||
memmove(v->cap_queue, v->cap_queue + 1, --v->n_cap_queue * sizeof v->cap_queue[0]);
|
||||
v->cap_done[v->n_cap_done++] = (struct vd_done){ .index = target, .timestamp = timestamp };
|
||||
v->last = (int)target;
|
||||
}
|
||||
|
||||
static void vd_decode_hardware(struct vdec *v, uint32_t index, uint32_t bytes, struct timeval timestamp) {
|
||||
double start = vd_now_ms();
|
||||
v->pts += 16667;
|
||||
struct vdec_packet p = { .type = VDEC_PACKET, .input = index, .bytes = bytes, .capture = v->cap_queue[0], .pts_us = v->pts };
|
||||
struct vdec_result r;
|
||||
if (vd_send(v->sock, &p, sizeof p, -1) != 0 || recv(v->sock, &r, sizeof r, 0) != (ssize_t)sizeof r ||
|
||||
r.type != VDEC_RESULT) {
|
||||
vd_log("lost the app's decoder (%s), switching to software", strerror(errno));
|
||||
vd_close_decoder(v);
|
||||
v->hw_failed = 1;
|
||||
return;
|
||||
}
|
||||
vd_deliver(v, r.status == 0 && r.frame, start, timestamp);
|
||||
}
|
||||
|
||||
static void vd_decode(struct vdec *v, uint32_t index, uint32_t bytes, struct timeval timestamp) {
|
||||
if (!v->cap_on || v->n_cap_queue == 0) return;
|
||||
if (v->ctx == NULL && !v->hw && vd_open_decoder(v) != 0) return;
|
||||
if (v->hw) {
|
||||
vd_decode_hardware(v, index, bytes, timestamp);
|
||||
return;
|
||||
}
|
||||
if (v->packet_capacity < bytes + VDEC_PADDING) {
|
||||
free(v->packet_data);
|
||||
v->packet_capacity = bytes + VDEC_PADDING + (64u << 10);
|
||||
v->packet_data = malloc(v->packet_capacity);
|
||||
if (v->packet_data == NULL) {
|
||||
v->packet_capacity = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
memcpy(v->packet_data, v->bitstream + (size_t)index * VDEC_BITSTREAM_SIZE, bytes);
|
||||
memset(v->packet_data + bytes, 0, VDEC_PADDING);
|
||||
*(uint8_t **)((uint8_t *)v->packet + 24) = v->packet_data;
|
||||
*(int *)((uint8_t *)v->packet + 32) = (int)bytes;
|
||||
double start = vd_now_ms();
|
||||
uint32_t target = v->cap_queue[0];
|
||||
struct vd_capture *c = &v->cap[target];
|
||||
int written = 0;
|
||||
if (av.send_packet(v->ctx, v->packet) >= 0) {
|
||||
while (av.receive_frame(v->ctx, v->frame) >= 0) {
|
||||
if (vd_write_frame(v, c) == 0) written = 1;
|
||||
av.frame_unref(v->frame);
|
||||
}
|
||||
}
|
||||
*(uint8_t **)((uint8_t *)v->packet + 24) = NULL;
|
||||
*(int *)((uint8_t *)v->packet + 32) = 0;
|
||||
vd_deliver(v, written, start, timestamp);
|
||||
}
|
||||
|
||||
static int is_output(uint32_t type) { return type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || type == V4L2_BUF_TYPE_VIDEO_OUTPUT; }
|
||||
static int is_capture(uint32_t type) { return type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || type == V4L2_BUF_TYPE_VIDEO_CAPTURE; }
|
||||
|
||||
static void vd_fill_format(struct vdec *v, struct v4l2_format *f) {
|
||||
struct v4l2_pix_format_mplane *p = &f->fmt.pix_mp;
|
||||
memset(p, 0, sizeof *p);
|
||||
p->field = V4L2_FIELD_NONE;
|
||||
p->num_planes = 1;
|
||||
p->colorspace = V4L2_COLORSPACE_REC709;
|
||||
if (is_output(f->type)) {
|
||||
p->width = v->width;
|
||||
p->height = v->height;
|
||||
p->pixelformat = v->fourcc;
|
||||
p->plane_fmt[0].sizeimage = VDEC_BITSTREAM_SIZE;
|
||||
} else {
|
||||
p->width = v->cap_width;
|
||||
p->height = v->cap_height;
|
||||
p->pixelformat = V4L2_PIX_FMT_NV12;
|
||||
p->plane_fmt[0].bytesperline = v->bpl;
|
||||
p->plane_fmt[0].sizeimage = v->cap_size;
|
||||
}
|
||||
}
|
||||
|
||||
static int vd_set_format(struct vdec *v, struct v4l2_format *f, int apply) {
|
||||
struct v4l2_pix_format_mplane *p = &f->fmt.pix_mp;
|
||||
if (f->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) return -EINVAL;
|
||||
struct vdec t = *v;
|
||||
if (is_output(f->type)) {
|
||||
if (p->pixelformat != V4L2_PIX_FMT_H264 && p->pixelformat != V4L2_PIX_FMT_HEVC) return -EINVAL;
|
||||
t.fourcc = p->pixelformat;
|
||||
t.width = p->width;
|
||||
t.height = p->height;
|
||||
} else {
|
||||
uint32_t w = p->width > t.width ? p->width : t.width, h = p->height > t.height ? p->height : t.height;
|
||||
if (w < 16 || h < 16 || w > 8192 || h > 8192) return -EINVAL;
|
||||
t.cap_width = (w + 15) & ~15u;
|
||||
t.cap_height = (h + 15) & ~15u;
|
||||
t.bpl = t.cap_width;
|
||||
t.cap_size = t.bpl * t.cap_height * 3 / 2;
|
||||
}
|
||||
if (apply) {
|
||||
if (t.fourcc != v->fourcc || (t.hw && (t.bpl != v->bpl || t.cap_height != v->cap_height))) vd_close_decoder(&t);
|
||||
*v = t;
|
||||
}
|
||||
vd_fill_format(&t, f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_reqbufs(struct vdec *v, struct v4l2_requestbuffers *r) {
|
||||
uint32_t n = r->count > VDEC_BUFFERS ? VDEC_BUFFERS : r->count;
|
||||
if (r->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && r->memory == V4L2_MEMORY_MMAP) {
|
||||
if (v->bitstream) munmap(v->bitstream, (size_t)v->out_count * VDEC_BITSTREAM_SIZE);
|
||||
v->bitstream = NULL;
|
||||
v->out_count = v->n_out_done = 0;
|
||||
if (n && ftruncate(v->fd, (off_t)n * VDEC_BITSTREAM_SIZE) != 0) return -ENOMEM;
|
||||
if (n) {
|
||||
void *p = mmap(NULL, (size_t)n * VDEC_BITSTREAM_SIZE, PROT_READ, MAP_SHARED, v->fd, 0);
|
||||
if (p == MAP_FAILED) return -ENOMEM;
|
||||
v->bitstream = p;
|
||||
}
|
||||
v->out_count = n;
|
||||
} else if (r->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && r->memory == V4L2_MEMORY_DMABUF) {
|
||||
if (v->hw) vd_close_decoder(v);
|
||||
vd_unmap_capture(v);
|
||||
v->cap_count = n;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
r->count = n;
|
||||
r->capabilities = r->memory == V4L2_MEMORY_MMAP ? V4L2_BUF_CAP_SUPPORTS_MMAP : V4L2_BUF_CAP_SUPPORTS_DMABUF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_querybuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || b->index >= v->out_count || b->m.planes == NULL || b->length < 1)
|
||||
return -EINVAL;
|
||||
b->memory = V4L2_MEMORY_MMAP;
|
||||
b->flags = V4L2_BUF_FLAG_MAPPED;
|
||||
b->length = 1;
|
||||
b->m.planes[0].length = VDEC_BITSTREAM_SIZE;
|
||||
b->m.planes[0].m.mem_offset = b->index * VDEC_BITSTREAM_SIZE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_qbuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->m.planes == NULL || b->length < 1) return -EINVAL;
|
||||
if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
||||
if (b->index >= v->out_count || v->n_out_done >= VDEC_BUFFERS) return -EINVAL;
|
||||
uint32_t bytes = b->m.planes[0].bytesused;
|
||||
if (bytes > VDEC_BITSTREAM_SIZE) bytes = VDEC_BITSTREAM_SIZE;
|
||||
if (v->out_on && bytes) vd_decode(v, b->index, bytes, b->timestamp);
|
||||
v->out_done[v->n_out_done++] = b->index;
|
||||
} else if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
|
||||
if (b->index >= v->cap_count || v->cap_size == 0) return -EINVAL;
|
||||
int r = vd_map_capture(v, b->index, b->m.planes[0].m.fd);
|
||||
if (r < 0) return r;
|
||||
for (uint32_t i = 0; i < v->n_cap_queue; i++) if (v->cap_queue[i] == b->index) return 0;
|
||||
if (v->n_cap_queue >= VDEC_BUFFERS) return -EINVAL;
|
||||
v->cap_queue[v->n_cap_queue++] = b->index;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
b->flags |= V4L2_BUF_FLAG_QUEUED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_dqbuf(struct vdec *v, struct v4l2_buffer *b) {
|
||||
if (b->m.planes == NULL || b->length < 1) return -EINVAL;
|
||||
if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
|
||||
if (v->n_out_done == 0) return -EAGAIN;
|
||||
b->index = v->out_done[0];
|
||||
memmove(v->out_done, v->out_done + 1, --v->n_out_done * sizeof v->out_done[0]);
|
||||
b->memory = V4L2_MEMORY_MMAP;
|
||||
b->flags = V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_MAPPED;
|
||||
b->length = 1;
|
||||
b->m.planes[0].bytesused = 0;
|
||||
b->m.planes[0].length = VDEC_BITSTREAM_SIZE;
|
||||
b->m.planes[0].m.mem_offset = b->index * VDEC_BITSTREAM_SIZE;
|
||||
return 0;
|
||||
}
|
||||
if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) return -EINVAL;
|
||||
if (v->n_cap_done == 0) return -EAGAIN;
|
||||
struct vd_done d = v->cap_done[0];
|
||||
memmove(v->cap_done, v->cap_done + 1, --v->n_cap_done * sizeof d);
|
||||
b->index = d.index;
|
||||
b->memory = V4L2_MEMORY_DMABUF;
|
||||
b->flags = V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_TIMESTAMP_COPY;
|
||||
b->field = V4L2_FIELD_NONE;
|
||||
b->timestamp = d.timestamp;
|
||||
b->length = 1;
|
||||
b->m.planes[0].bytesused = v->cap_size;
|
||||
b->m.planes[0].length = v->cap_size;
|
||||
b->m.planes[0].m.fd = v->cap[d.index].fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vd_ioctl(struct vdec *v, unsigned long req, void *arg) {
|
||||
switch (req) {
|
||||
case VIDIOC_QUERYCAP: {
|
||||
struct v4l2_capability *c = arg;
|
||||
memset(c, 0, sizeof *c);
|
||||
strcpy((char *)c->driver, "droiddeck_vdec");
|
||||
strcpy((char *)c->card, "DroidDeck video decoder");
|
||||
strcpy((char *)c->bus_info, "platform:droiddeck-vdec");
|
||||
c->version = 0x00060000;
|
||||
c->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
|
||||
c->capabilities = c->device_caps | V4L2_CAP_DEVICE_CAPS;
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_ENUM_FMT: {
|
||||
struct v4l2_fmtdesc *d = arg;
|
||||
static const uint32_t coded[] = { V4L2_PIX_FMT_H264, V4L2_PIX_FMT_HEVC };
|
||||
if (is_capture(d->type) && d->index == 0) {
|
||||
d->pixelformat = V4L2_PIX_FMT_NV12;
|
||||
strcpy((char *)d->description, "Y/CbCr 4:2:0");
|
||||
d->flags = 0;
|
||||
} else if (is_output(d->type) && d->index < 2) {
|
||||
d->pixelformat = coded[d->index];
|
||||
strcpy((char *)d->description, d->index ? "HEVC" : "H.264");
|
||||
d->flags = V4L2_FMT_FLAG_COMPRESSED;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_G_FMT: {
|
||||
struct v4l2_format *f = arg;
|
||||
if (!is_output(f->type) && !is_capture(f->type)) return -EINVAL;
|
||||
vd_fill_format(v, f);
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_S_FMT: return vd_set_format(v, arg, 1);
|
||||
case VIDIOC_TRY_FMT: return vd_set_format(v, arg, 0);
|
||||
case VIDIOC_REQBUFS: return vd_reqbufs(v, arg);
|
||||
case VIDIOC_QUERYBUF: return vd_querybuf(v, arg);
|
||||
case VIDIOC_QBUF: return vd_qbuf(v, arg);
|
||||
case VIDIOC_DQBUF: return vd_dqbuf(v, arg);
|
||||
case VIDIOC_STREAMON:
|
||||
case VIDIOC_STREAMOFF: {
|
||||
uint32_t type = *(uint32_t *)arg;
|
||||
int on = req == VIDIOC_STREAMON;
|
||||
if (is_output(type)) {
|
||||
v->out_on = on;
|
||||
if (!on) {
|
||||
v->n_out_done = 0;
|
||||
if (v->ctx) av.flush_buffers(v->ctx);
|
||||
}
|
||||
} else if (is_capture(type)) {
|
||||
v->cap_on = on;
|
||||
if (!on) v->n_cap_queue = v->n_cap_done = 0;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (v->out_on && v->cap_on && v->ctx == NULL && !v->hw && v->out_count && v->cap_size) vd_open_decoder(v);
|
||||
return 0;
|
||||
}
|
||||
case VIDIOC_SUBSCRIBE_EVENT:
|
||||
case VIDIOC_UNSUBSCRIBE_EVENT:
|
||||
case VIDIOC_DECODER_CMD:
|
||||
case VIDIOC_TRY_DECODER_CMD:
|
||||
return 0;
|
||||
case VIDIOC_DQEVENT:
|
||||
return -ENOENT;
|
||||
default:
|
||||
vd_log("unhandled ioctl 0x%lx", req);
|
||||
return -ENOTTY;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
struct vdec *v = vd_find(fd);
|
||||
if (v == NULL) return 0;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
int r = arg ? vd_ioctl(v, req, arg) : -EFAULT;
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
if (r < 0) {
|
||||
errno = -r;
|
||||
*rc = -1;
|
||||
} else {
|
||||
*rc = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) void bl_vdec_closed(int fd) {
|
||||
struct vdec *v = vd_find(fd);
|
||||
if (v == NULL) return;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
vd_close_decoder(v);
|
||||
vd_unmap_capture(v);
|
||||
if (v->bitstream) munmap(v->bitstream, (size_t)v->out_count * VDEC_BITSTREAM_SIZE);
|
||||
v->bitstream = NULL;
|
||||
v->used = 0;
|
||||
__atomic_sub_fetch(&vd_open_count, 1, __ATOMIC_RELEASE);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret) {
|
||||
if (n != 1 || vd_find(fds[0].fd) == NULL) return 0;
|
||||
struct vdec *v = vd_find(fds[0].fd);
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
short ready = (v->n_cap_done ? POLLIN | POLLRDNORM : 0) | (v->n_out_done ? POLLOUT | POLLWRNORM : 0);
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
fds[0].revents = ready & fds[0].events;
|
||||
if (fds[0].revents == 0 && timeout_ms != 0) real(NULL, 0, timeout_ms < 0 || timeout_ms > 1000 ? 1000 : timeout_ms);
|
||||
*ret = fds[0].revents ? 1 : 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int drm_get_devices2(uint32_t flags, struct vd_device **devices, int max) {
|
||||
(void)flags;
|
||||
static char *nodes[3] = { "/dev/null", NULL, NULL };
|
||||
static struct vd_device device = { .nodes = nodes, .available_nodes = 1 };
|
||||
if (devices == NULL || max < 1) return 1;
|
||||
devices[0] = &device;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void drm_free_devices(struct vd_device **devices, int count) { (void)devices; (void)count; }
|
||||
|
||||
static struct vd_mode_info drm_mode = {
|
||||
.clock = 148500, .hdisplay = 1920, .hsync_start = 2008, .hsync_end = 2052, .htotal = 2200,
|
||||
.vdisplay = 1080, .vsync_start = 1084, .vsync_end = 1089, .vtotal = 1125, .vrefresh = 60, .name = "1920x1080",
|
||||
};
|
||||
static uint32_t drm_crtc_ids[1] = { 1 }, drm_connector_ids[1] = { 2 }, drm_encoder_ids[1] = { 3 };
|
||||
|
||||
static struct vd_res *drm_get_resources(int fd) {
|
||||
(void)fd;
|
||||
static struct vd_res res = {
|
||||
.count_crtcs = 1, .crtcs = drm_crtc_ids, .count_connectors = 1, .connectors = drm_connector_ids,
|
||||
.count_encoders = 1, .encoders = drm_encoder_ids, .max_width = 8192, .max_height = 8192,
|
||||
};
|
||||
return &res;
|
||||
}
|
||||
|
||||
static struct vd_connector *drm_get_connector(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_connector connector = {
|
||||
.connector_id = 2, .encoder_id = 3, .connector_type = 14, .connection = 1, .count_modes = 1,
|
||||
.modes = &drm_mode, .count_encoders = 1, .encoders = drm_encoder_ids,
|
||||
};
|
||||
return id == 2 ? &connector : NULL;
|
||||
}
|
||||
|
||||
static struct vd_encoder *drm_get_encoder(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_encoder encoder = { .encoder_id = 3, .encoder_type = 8, .crtc_id = 1, .possible_crtcs = 1 };
|
||||
return id == 3 ? &encoder : NULL;
|
||||
}
|
||||
|
||||
static struct vd_crtc *drm_get_crtc(int fd, uint32_t id) {
|
||||
(void)fd;
|
||||
static struct vd_crtc crtc;
|
||||
if (id != 1) return NULL;
|
||||
crtc = (struct vd_crtc){ .crtc_id = 1, .width = 1920, .height = 1080, .mode_valid = 1, .mode = drm_mode };
|
||||
return &crtc;
|
||||
}
|
||||
|
||||
static void drm_free(void *p) { (void)p; }
|
||||
static void *drm_null(void) { return NULL; }
|
||||
static int drm_fail(void) { return -EINVAL; }
|
||||
|
||||
static int drm_dumb_slot(uint32_t handle) { return handle >= 1 && handle <= VDEC_DUMB ? (int)handle - 1 : -1; }
|
||||
|
||||
static int drm_ioctl(int fd, unsigned long request, void *arg) {
|
||||
(void)fd;
|
||||
int r = -EINVAL;
|
||||
pthread_mutex_lock(&vd_lock);
|
||||
if (request == VD_IOCTL_MODE_CREATE_DUMB && arg) {
|
||||
struct vd_create_dumb *c = arg;
|
||||
uint64_t pitch = ((uint64_t)c->width * c->bpp + 7) / 8;
|
||||
uint64_t size = (pitch * c->height + 4095) & ~4095ull;
|
||||
int slot = -1;
|
||||
for (int i = 0; i < VDEC_DUMB && slot < 0; i++) if (vd_dumb_fd[i] < 0) slot = i;
|
||||
struct vd_dma_heap_alloc a = { .len = size, .fd_flags = O_RDWR | O_CLOEXEC };
|
||||
if (slot < 0 || size == 0 || size > (512ull << 20)) {
|
||||
r = -ENOMEM;
|
||||
} else if (ioctl(vd_heap, VD_DMA_HEAP_IOCTL_ALLOC, &a) != 0) {
|
||||
r = -errno;
|
||||
vd_log("dma-heap allocation of %llu bytes failed: %s", (unsigned long long)size, strerror(errno));
|
||||
} else {
|
||||
vd_dumb_fd[slot] = (int)a.fd;
|
||||
c->handle = (uint32_t)slot + 1;
|
||||
c->pitch = (uint32_t)pitch;
|
||||
c->size = size;
|
||||
r = 0;
|
||||
}
|
||||
} else if (request == VD_IOCTL_PRIME_HANDLE_TO_FD && arg) {
|
||||
struct vd_prime_handle *h = arg;
|
||||
int slot = drm_dumb_slot(h->handle);
|
||||
int dup_fd = slot >= 0 && vd_dumb_fd[slot] >= 0 ? fcntl(vd_dumb_fd[slot], F_DUPFD_CLOEXEC, 0) : -1;
|
||||
if (dup_fd >= 0) {
|
||||
h->fd = dup_fd;
|
||||
r = 0;
|
||||
} else {
|
||||
r = slot >= 0 ? -errno : -ENOENT;
|
||||
}
|
||||
} else if (request == VD_IOCTL_MODE_DESTROY_DUMB && arg) {
|
||||
int slot = drm_dumb_slot(((struct vd_destroy_dumb *)arg)->handle);
|
||||
if (slot >= 0 && vd_dumb_fd[slot] >= 0) {
|
||||
close(vd_dumb_fd[slot]);
|
||||
vd_dumb_fd[slot] = -1;
|
||||
r = 0;
|
||||
} else {
|
||||
r = -ENOENT;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&vd_lock);
|
||||
if (r < 0) {
|
||||
errno = -r;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
void *fn;
|
||||
} drm_table[] = {
|
||||
{ "drmGetDevices2", (void *)drm_get_devices2 },
|
||||
{ "drmFreeDevices", (void *)drm_free_devices },
|
||||
{ "drmSetMaster", (void *)drm_fail },
|
||||
{ "drmSetClientCap", (void *)drm_fail },
|
||||
{ "drmModeGetResources", (void *)drm_get_resources },
|
||||
{ "drmModeFreeResources", (void *)drm_free },
|
||||
{ "drmModeGetConnector", (void *)drm_get_connector },
|
||||
{ "drmModeFreeConnector", (void *)drm_free },
|
||||
{ "drmModeGetEncoder", (void *)drm_get_encoder },
|
||||
{ "drmModeFreeEncoder", (void *)drm_free },
|
||||
{ "drmModeGetCrtc", (void *)drm_get_crtc },
|
||||
{ "drmModeSetCrtc", (void *)drm_fail },
|
||||
{ "drmModeFreeCrtc", (void *)drm_free },
|
||||
{ "drmModeGetPlaneResources", (void *)drm_null },
|
||||
{ "drmModeFreePlaneResources", (void *)drm_free },
|
||||
{ "drmModeGetPlane", (void *)drm_null },
|
||||
{ "drmModeFreePlane", (void *)drm_free },
|
||||
{ "drmModeObjectGetProperties", (void *)drm_null },
|
||||
{ "drmModeFreeObjectProperties", (void *)drm_free },
|
||||
{ "drmModeGetProperty", (void *)drm_null },
|
||||
{ "drmModeFreeProperty", (void *)drm_free },
|
||||
{ "drmModeAddFB2", (void *)drm_fail },
|
||||
{ "drmModeAddFB2WithModifiers", (void *)drm_fail },
|
||||
{ "drmModeRmFB", (void *)drm_fail },
|
||||
{ "drmModeAtomicAlloc", (void *)drm_null },
|
||||
{ "drmModeAtomicFree", (void *)drm_free },
|
||||
{ "drmModeAtomicAddProperty", (void *)drm_fail },
|
||||
{ "drmModeAtomicCommit", (void *)drm_fail },
|
||||
{ "drmIoctl", (void *)drm_ioctl },
|
||||
};
|
||||
|
||||
void *SDL_LoadObject(const char *name) {
|
||||
static void *(*real)(const char *);
|
||||
if (name && strcmp(name, "libdrm.so.2") == 0 && vd_enabled()) return &vd_drm_handle;
|
||||
if (!real) real = (void *(*)(const char *))dlsym(RTLD_NEXT, "SDL_LoadObject");
|
||||
return real ? real(name) : NULL;
|
||||
}
|
||||
|
||||
void *SDL_LoadFunction(void *handle, const char *name) {
|
||||
static void *(*real)(void *, const char *);
|
||||
if (handle == &vd_drm_handle) {
|
||||
for (size_t i = 0; name && i < sizeof drm_table / sizeof drm_table[0]; i++)
|
||||
if (strcmp(drm_table[i].name, name) == 0) return drm_table[i].fn;
|
||||
return NULL;
|
||||
}
|
||||
if (!real) real = (void *(*)(void *, const char *))dlsym(RTLD_NEXT, "SDL_LoadFunction");
|
||||
return real ? real(handle, name) : NULL;
|
||||
}
|
||||
|
||||
void SDL_UnloadObject(void *handle) {
|
||||
static void (*real)(void *);
|
||||
if (handle == &vd_drm_handle) return;
|
||||
if (!real) real = (void (*)(void *))dlsym(RTLD_NEXT, "SDL_UnloadObject");
|
||||
if (real) real(handle);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_open(const char *path, int flags) {
|
||||
(void)path;
|
||||
(void)flags;
|
||||
return -2;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
(void)fd;
|
||||
(void)req;
|
||||
(void)arg;
|
||||
(void)rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) void bl_vdec_closed(int fd) { (void)fd; }
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret) {
|
||||
(void)fds;
|
||||
(void)n;
|
||||
(void)timeout_ms;
|
||||
(void)real;
|
||||
(void)ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -625,9 +625,14 @@ static int vn_poll(struct pollfd *fds, nfds_t n, int timeout_ms, int (*real)(str
|
||||
return r + ready;
|
||||
}
|
||||
|
||||
__attribute__((weak, visibility("hidden"))) int bl_vdec_poll(struct pollfd *fds, nfds_t n, int timeout_ms,
|
||||
int (*real)(struct pollfd *, nfds_t, int), int *ret);
|
||||
|
||||
int poll(struct pollfd *fds, nfds_t n, int timeout_ms) {
|
||||
static int (*real)(struct pollfd *, nfds_t, int);
|
||||
if (!real) real = (int (*)(struct pollfd *, nfds_t, int))dlsym(RTLD_NEXT, "poll");
|
||||
int ret;
|
||||
if (bl_vdec_poll && bl_vdec_poll(fds, n, timeout_ms, real, &ret)) return ret;
|
||||
if (__atomic_load_n(&vn_open_count, __ATOMIC_ACQUIRE) == 0) return real(fds, n, timeout_ms);
|
||||
return vn_poll(fds, n, timeout_ms, real);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Published proot pack for a build that did not compile libproot.so into the APK.
|
||||
# CI builds embed the binary and publish their own pack; this pin is what a source
|
||||
# build downloads. Tag on DroidDeck-Components: pack-proot-<first 16 hex of the digest>.
|
||||
# Update both lines when source builds should pick up a newer proot.
|
||||
PROOT_PACK_SHA256=5a2b7284e6357f88a14a790abd54e61effbe5f202c63b6aaba9b974c559649c3
|
||||
PROOT_PACK_SIZE=96643
|
||||
@@ -124,3 +124,11 @@ Old kernel fixes:
|
||||
by the kernel instead. The original clone flags are preserved. When the kernel supplies a valid
|
||||
ID in the notification, normal setup is unchanged. No timers or background polling are added.
|
||||
Completely missing notifications and ambiguous matches for separate processes are not recovered.
|
||||
|
||||
Development diagnostics:
|
||||
|
||||
- `0018-syscall-handler-profile.patch` - `PROOT_PROFILE=1` enables per-syscall entry/exit handler
|
||||
counts, wall/CPU time, periodic cumulative JSON totals, and bounded slow-handler samples on
|
||||
stderr. `profile.h` is copied into the source tree by `build.sh`. It adds no ptrace stops;
|
||||
handler timing excludes tracee kernel time and scheduling before handler entry. See
|
||||
`docs/development/proot-performance.md` for the capture and library-override workflow.
|
||||
@@ -31,6 +31,7 @@ fetch() {
|
||||
fetch proot.tar.gz "https://github.com/termux/proot/archive/${PROOT_COMMIT}.tar.gz" "$PROOT_SHA256"
|
||||
fetch talloc.tar.gz "https://www.samba.org/ftp/talloc/talloc-${TALLOC_VERSION}.tar.gz" "$TALLOC_SHA256"
|
||||
cp "$HERE/statx_mnt_id.h" "$WORK/proot/src/tracee/statx_mnt_id.h"
|
||||
cp "$HERE/profile.h" "$WORK/proot/src/syscall/profile.h"
|
||||
for patch in "$HERE"/patches/*.patch; do
|
||||
patch -d "$WORK/proot" -p1 --forward --quiet < "$patch"
|
||||
done
|
||||
|
||||
@@ -875,19 +875,84 @@ int __fxstat(int ver, int fd, struct stat *st) {
|
||||
}
|
||||
int __fxstat64(int ver, int fd, struct stat64 *st) { return __fxstat(ver, fd, (struct stat *)st); }
|
||||
|
||||
#ifndef STATX__RESERVED
|
||||
#define STATX__RESERVED 0x80000000U
|
||||
#endif
|
||||
|
||||
static int statx_missing;
|
||||
|
||||
static unsigned int dev_major(unsigned long long dev) {
|
||||
return ((dev >> 8) & 0xfff) | ((unsigned int)(dev >> 32) & ~0xfffU);
|
||||
}
|
||||
static unsigned int dev_minor(unsigned long long dev) {
|
||||
return (dev & 0xff) | ((unsigned int)(dev >> 12) & ~0xffU);
|
||||
}
|
||||
|
||||
static void fill_statx(struct statx *out, const struct stat *st) {
|
||||
memset(out, 0, sizeof *out);
|
||||
out->stx_mask = STATX_BASIC_STATS;
|
||||
out->stx_blksize = st->st_blksize;
|
||||
out->stx_nlink = st->st_nlink;
|
||||
out->stx_uid = st->st_uid;
|
||||
out->stx_gid = st->st_gid;
|
||||
out->stx_mode = st->st_mode;
|
||||
out->stx_ino = st->st_ino;
|
||||
out->stx_size = st->st_size;
|
||||
out->stx_blocks = st->st_blocks;
|
||||
out->stx_atime.tv_sec = st->st_atim.tv_sec;
|
||||
out->stx_atime.tv_nsec = st->st_atim.tv_nsec;
|
||||
out->stx_ctime.tv_sec = st->st_ctim.tv_sec;
|
||||
out->stx_ctime.tv_nsec = st->st_ctim.tv_nsec;
|
||||
out->stx_mtime.tv_sec = st->st_mtim.tv_sec;
|
||||
out->stx_mtime.tv_nsec = st->st_mtim.tv_nsec;
|
||||
out->stx_rdev_major = dev_major(st->st_rdev);
|
||||
out->stx_rdev_minor = dev_minor(st->st_rdev);
|
||||
out->stx_dev_major = dev_major(st->st_dev);
|
||||
out->stx_dev_minor = dev_minor(st->st_dev);
|
||||
}
|
||||
|
||||
/* Emulate statx on older kernels < 4.11 */
|
||||
static long statx_call(int dirfd, const char *path, int flags, unsigned mask, struct statx *out) {
|
||||
struct stat st;
|
||||
long rs;
|
||||
if ((flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_STATX_SYNC_TYPE)) ||
|
||||
(flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
|
||||
return -EINVAL;
|
||||
if (!statx_missing) {
|
||||
rs = sc(SYS_statx, dirfd, (long)path, flags, mask, (long)out);
|
||||
if (rs != -ENOSYS) return rs;
|
||||
statx_missing = 1;
|
||||
}
|
||||
if (flags & AT_STATX_SYNC_TYPE) return -ENOSYS;
|
||||
rs = sc(SYS_newfstatat, dirfd, (long)path, (long)&st,
|
||||
flags & (AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT), 0);
|
||||
if (rs < 0) return rs;
|
||||
fill_statx(out, &st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int statx(int dirfd, const char *path, int flags, unsigned mask, struct statx *out) {
|
||||
REAL(statx, int (*)(int, const char *, int, unsigned, struct statx *));
|
||||
struct res r;
|
||||
long rs;
|
||||
if (mask & STATX__RESERVED) { errno = EINVAL; return -1; }
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnonnull-compare"
|
||||
if (!out) { errno = EFAULT; return -1; }
|
||||
if (!path) {
|
||||
if (!(flags & AT_EMPTY_PATH)) { errno = EFAULT; return -1; }
|
||||
return real_statx ? real_statx(dirfd, path, flags, mask, out) : ret(sc(SYS_statx, dirfd, (long)path, flags, mask, (long)out));
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
if ((flags & AT_EMPTY_PATH) && !path[0] && fp_ready()) {
|
||||
hits++;
|
||||
return ret(sc(SYS_statx, dirfd, (long)"", flags, mask, (long)out));
|
||||
return ret(statx_call(dirfd, "", flags, mask, out));
|
||||
}
|
||||
rs = (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_STATX_SYNC_TYPE)) ? FP_SLOW
|
||||
: resolve(dirfd, path, (flags & AT_SYMLINK_NOFOLLOW ? 0 : 1) | MAY_BE_UNSEEN, &r);
|
||||
if (rs == 1) rs = -ENOENT;
|
||||
if (rs == 0 || rs == UNSEEN)
|
||||
rs = sc(SYS_statx, AT_FDCWD, (long)r.host, flags | (rs == 0 && !r.magic ? AT_SYMLINK_NOFOLLOW : 0), mask, (long)out);
|
||||
rs = statx_call(AT_FDCWD, r.host, flags | (rs == 0 && !r.magic ? AT_SYMLINK_NOFOLLOW : 0), mask, out);
|
||||
ANSWER(rs, dirfd, path, real_statx(dirfd, path, flags, mask, out));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/src/syscall/syscall.c
|
||||
+++ b/src/syscall/syscall.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "tracee/reg.h"
|
||||
#include "tracee/mem.h"
|
||||
#include "cli/note.h"
|
||||
+#include "syscall/profile.h"
|
||||
|
||||
/**
|
||||
* Copy in @path a C string (PATH_MAX bytes max.) from the @tracee's
|
||||
@@ -100,7 +101,7 @@
|
||||
return set_sysarg_data(tracee, path, strlen(path) + 1, reg);
|
||||
}
|
||||
|
||||
-void translate_syscall(Tracee *tracee)
|
||||
+static void translate_syscall_impl(Tracee *tracee)
|
||||
{
|
||||
const bool is_enter_stage = IS_IN_SYSENTER(tracee);
|
||||
int status;
|
||||
@@ -283,3 +284,18 @@
|
||||
else
|
||||
print_current_regs(tracee, 4, "sysexit end");
|
||||
}
|
||||
+
|
||||
+void translate_syscall(Tracee *tracee)
|
||||
+{
|
||||
+ if (!dd_profile_enabled()) {
|
||||
+ translate_syscall_impl(tracee);
|
||||
+ return;
|
||||
+ }
|
||||
+ int saved = errno;
|
||||
+ const bool entering = IS_IN_SYSENTER(tracee);
|
||||
+ uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
+ uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
+ errno = saved;
|
||||
+ translate_syscall_impl(tracee);
|
||||
+ dd_profile_record(get_sysnum(tracee, ORIGINAL), entering, tracee->pid, wall, cpu);
|
||||
+}
|
||||
@@ -0,0 +1,99 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#ifndef DROIDDECK_PROOT_PROFILE_H
|
||||
#define DROIDDECK_PROOT_PROFILE_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct dd_profile_counter {
|
||||
uint64_t calls, wall_ns, cpu_ns, max_ns;
|
||||
};
|
||||
static struct dd_profile_counter dd_profile_counts[PR_NB_SYSNUM][2];
|
||||
static int dd_profile_on = -1;
|
||||
static uint64_t dd_profile_id, dd_profile_next, dd_profile_slow_ns = 1000000;
|
||||
static unsigned dd_profile_samples;
|
||||
|
||||
static uint64_t dd_profile_clock(clockid_t clock)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (clock_gettime(clock, &ts) != 0) return 0;
|
||||
return (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
|
||||
}
|
||||
|
||||
static void dd_profile_flush(void)
|
||||
{
|
||||
int saved = errno;
|
||||
for (unsigned nr = 0; nr < PR_NB_SYSNUM; nr++) {
|
||||
for (unsigned stage = 0; stage < 2; stage++) {
|
||||
const struct dd_profile_counter *c = &dd_profile_counts[nr][stage];
|
||||
if (!c->calls) continue;
|
||||
fprintf(stderr, "proot-profile {\"type\":\"total\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"syscall\":\"%s\",\"stage\":\"%s\",\"calls\":%" PRIu64
|
||||
",\"wall_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 ",\"max_ns\":%" PRIu64 "}\n",
|
||||
getpid(), dd_profile_id, stringify_sysnum(nr), stage ? "exit" : "enter",
|
||||
c->calls, c->wall_ns, c->cpu_ns, c->max_ns);
|
||||
}
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static int dd_profile_enabled(void)
|
||||
{
|
||||
if (dd_profile_on >= 0) return dd_profile_on;
|
||||
int saved = errno;
|
||||
const char *value = getenv("PROOT_PROFILE");
|
||||
dd_profile_on = value && strcmp(value, "1") == 0;
|
||||
if (dd_profile_on) {
|
||||
value = getenv("PROOT_PROFILE_SLOW_US");
|
||||
if (value && *value) {
|
||||
char *end;
|
||||
unsigned long long us = strtoull(value, &end, 10);
|
||||
if (!*end && us > 0 && us <= 1000000000ULL) dd_profile_slow_ns = us * 1000;
|
||||
}
|
||||
dd_profile_id = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
dd_profile_next = dd_profile_id + 5000000000ULL;
|
||||
atexit(dd_profile_flush);
|
||||
fprintf(stderr, "proot-profile {\"type\":\"start\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"slow_ns\":%" PRIu64 ",\"sample_limit\":32,\"sample_window_ms\":5000,\"scope\":\"syscall-handler\"}\n",
|
||||
getpid(), dd_profile_id, dd_profile_slow_ns);
|
||||
}
|
||||
errno = saved;
|
||||
return dd_profile_on;
|
||||
}
|
||||
|
||||
static void dd_profile_record(unsigned nr, int entering, pid_t pid,
|
||||
uint64_t start_wall, uint64_t start_cpu)
|
||||
{
|
||||
int saved = errno;
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
if (nr >= PR_NB_SYSNUM) nr = PR_void;
|
||||
if (!start_wall || !start_cpu || wall < start_wall || cpu < start_cpu) goto done;
|
||||
uint64_t elapsed = wall - start_wall, used = cpu - start_cpu;
|
||||
struct dd_profile_counter *c = &dd_profile_counts[nr][!entering];
|
||||
c->calls++;
|
||||
c->wall_ns += elapsed;
|
||||
c->cpu_ns += used;
|
||||
if (elapsed > c->max_ns) c->max_ns = elapsed;
|
||||
if (wall >= dd_profile_next) {
|
||||
dd_profile_flush();
|
||||
dd_profile_next = wall + 5000000000ULL;
|
||||
dd_profile_samples = 0;
|
||||
}
|
||||
if (elapsed >= dd_profile_slow_ns && dd_profile_samples < 32) {
|
||||
dd_profile_samples++;
|
||||
fprintf(stderr, "proot-profile {\"type\":\"slow\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"pid\":%d,\"syscall\":\"%s\",\"stage\":\"%s\",\"wall_ns\":%" PRIu64
|
||||
",\"cpu_ns\":%" PRIu64 "}\n", getpid(), dd_profile_id, pid,
|
||||
stringify_sysnum(nr), entering ? "enter" : "exit", elapsed, used);
|
||||
}
|
||||
done:
|
||||
errno = saved;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Read cumulative PRoot handler counters from a session log without double counting snapshots."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections import deque
|
||||
from pathlib import Path
|
||||
|
||||
PREFIX = "proot-profile "
|
||||
|
||||
|
||||
def report(path: Path, sort: str = "wall", limit: int = 20) -> dict:
|
||||
latest = {}
|
||||
starts = set()
|
||||
samples = deque(maxlen=128)
|
||||
malformed = 0
|
||||
with path.open(errors="replace") as stream:
|
||||
for line in stream:
|
||||
if PREFIX not in line:
|
||||
continue
|
||||
try:
|
||||
row = json.loads(line.split(PREFIX, 1)[1])
|
||||
identity = (int(row["tracer"]), int(row["id"]))
|
||||
if row["type"] == "start":
|
||||
starts.add(identity)
|
||||
elif row["type"] in {"total", "slow"}:
|
||||
if row["stage"] not in {"enter", "exit"} or not isinstance(row["syscall"], str):
|
||||
raise ValueError("invalid syscall/stage")
|
||||
fields = ("calls", "wall_ns", "cpu_ns", "max_ns") if row["type"] == "total" else ("wall_ns", "cpu_ns", "pid")
|
||||
if any(type(row[key]) is not int or row[key] < 0 for key in fields):
|
||||
raise ValueError("invalid counter")
|
||||
if row["type"] == "total":
|
||||
latest[identity + (row["syscall"], row["stage"])] = row
|
||||
else:
|
||||
samples.append(row)
|
||||
except (ValueError, TypeError, KeyError):
|
||||
malformed += 1
|
||||
groups = {}
|
||||
for (_, _, syscall, stage), row in latest.items():
|
||||
total = groups.setdefault((syscall, stage), dict(syscall=syscall, stage=stage, calls=0, wall_ns=0, cpu_ns=0, max_ns=0))
|
||||
for key in ("calls", "wall_ns", "cpu_ns"):
|
||||
total[key] += row[key]
|
||||
total["max_ns"] = max(total["max_ns"], row["max_ns"])
|
||||
for row in groups.values():
|
||||
row["wallMs"] = round(row["wall_ns"] / 1_000_000, 3)
|
||||
row["cpuMs"] = round(row["cpu_ns"] / 1_000_000, 3)
|
||||
row["meanUs"] = round(row["wall_ns"] / max(row["calls"], 1) / 1000, 3)
|
||||
row["maxUs"] = round(row["max_ns"] / 1000, 3)
|
||||
rows = sorted(groups.values(), key=lambda row: row[{"wall": "wall_ns", "cpu": "cpu_ns", "calls": "calls"}[sort]], reverse=True)
|
||||
return dict(ok=True, command="proot-profile", scope="syscall-handler",
|
||||
note="Handler wall time includes tracer descheduling and filesystem waits; it excludes tracee kernel time and wake-up/queue delay before the handler. Counts are handler visits, including chained calls, not unique syscalls.",
|
||||
path=str(path), tracers=len(starts | {key[:2] for key in latest}),
|
||||
handlerCalls=sum(row["calls"] for row in rows),
|
||||
handlerWallNs=sum(row["wall_ns"] for row in rows),
|
||||
handlerCpuNs=sum(row["cpu_ns"] for row in rows),
|
||||
malformedRecords=malformed, totals=rows[:limit], slowSamples=list(samples),
|
||||
hasCounters=bool(latest))
|
||||
@@ -13,11 +13,8 @@ MARK="<!-- droiddeck-pr-build -->"
|
||||
echo
|
||||
echo "The \`droiddeck-apk\` artifact is [on this run]($RUN_URL), signed with the public test key."
|
||||
echo
|
||||
if [ "$SAME_REPO" = true ]; then
|
||||
echo "After the parallel regression tests pass, a release-signed tester build that installs over Stable or Preview will be published and will appear in DroidDeck's **Test builds** list. Label the PR \`no-test-build\` to skip that."
|
||||
else
|
||||
echo "**Maintainer:** add the \`publish-test\` label to publish a release-signed tester build that installs over Stable or Preview and appears in DroidDeck's **Test builds** list. The label is removed automatically after publishing."
|
||||
fi
|
||||
echo "Same-repository PRs and PRs opened by contributors listed in \`.github/trusted-test-builds.txt\` are eligible for automatic release-signed test builds after the full build passes. Label the PR \`no-test-build\` to skip that."
|
||||
echo "For other PRs, a maintainer can add the \`publish-test\` label to request a signed build."
|
||||
echo
|
||||
echo "Fallback: [open **PR Release Publish**]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/workflows/pr-release-publish.yml) on \`main\` and enter PR \`$PR\`."
|
||||
;;
|
||||
|
||||
@@ -34,6 +34,22 @@ def documentation_only(sha):
|
||||
return all(path.endswith(b".md") or path in (b"LICENSE", b".gitignore") for path in paths if path)
|
||||
|
||||
|
||||
def trusted_list_violation(repo, pr, sha):
|
||||
changed = subprocess.run(
|
||||
["git", "diff", "--no-renames", "--quiet", f"origin/main...{sha}", "--", ".github/trusted-test-builds.txt"],
|
||||
check=False,
|
||||
)
|
||||
if changed.returncode not in (0, 1):
|
||||
raise RuntimeError("Could not check trusted contributor changes")
|
||||
if changed.returncode == 0:
|
||||
return []
|
||||
opener = pr["user"]["login"]
|
||||
permission = api(f"repos/{repo}/collaborators/{opener}/permission")
|
||||
if permission["permission"] != "admin" and permission.get("role_name") != "maintain":
|
||||
return [f"Only a maintainer may open a PR changing .github/trusted-test-builds.txt (opened by @{opener})"]
|
||||
return []
|
||||
|
||||
|
||||
def main():
|
||||
with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as source:
|
||||
event = json.load(source)
|
||||
@@ -76,6 +92,7 @@ def main():
|
||||
commits, errors = check_revision(sha)
|
||||
if pr:
|
||||
errors.extend(event_violations({"pull_request": pr}))
|
||||
errors.extend(trusted_list_violation(repo, pr, sha))
|
||||
if errors:
|
||||
raise RuntimeError("\n".join(errors))
|
||||
print(f"Source and metadata validated for {len(commits)} commits")
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
#include "framegen.hpp"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int levels = 7;
|
||||
constexpr VkImageUsageFlags flow_usage =
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
enum Pipeline { LUMA, DOWNSAMPLE, FLOW3, FLOW4, EXPAND3, EXPAND4, GLOBAL_MOTION, PREWARP, FLOW_REG, SYNTH };
|
||||
struct Image { VkExtent3D extent; VkFormat format; VkImageUsageFlags usage; };
|
||||
struct Allocation { VkDeviceSize size; std::unique_ptr<uint8_t[]> data; };
|
||||
struct Binding { VkDescriptorType type; VkImageView view; VkBuffer buffer; VkDeviceSize range; };
|
||||
struct Dispatch { unsigned pipeline; uint32_t x, y, z; };
|
||||
std::map<VkImage, Image> images;
|
||||
std::map<VkImageView, VkImage> views;
|
||||
std::map<VkBuffer, VkBufferCreateInfo> buffers;
|
||||
std::map<VkDeviceMemory, Allocation> allocations;
|
||||
std::map<VkBuffer, VkDeviceMemory> buffer_memory;
|
||||
std::map<VkDescriptorSet, std::map<uint32_t, Binding>> descriptors;
|
||||
std::map<VkPipeline, unsigned> pipelines;
|
||||
std::map<VkImage, unsigned> image_ids;
|
||||
std::map<VkBuffer, unsigned> buffer_ids;
|
||||
std::vector<Dispatch> dispatches;
|
||||
uintptr_t serial = 100;
|
||||
unsigned buffer_creates, set_creates;
|
||||
VkPipeline bound_pipeline;
|
||||
VkDescriptorSet bound_set;
|
||||
uint64_t command_hash = 14695981039346656037ull;
|
||||
|
||||
template<class T> T handle() { return reinterpret_cast<T>(++serial); }
|
||||
|
||||
void hash(uint64_t value) {
|
||||
for (unsigned i = 0; i < 8; i++) {
|
||||
command_hash = (command_hash ^ (value & 255)) * 1099511628211ull;
|
||||
value >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
void hash_image(VkImage image) {
|
||||
assert(images.count(image));
|
||||
if (!image_ids.count(image)) image_ids[image] = static_cast<unsigned>(image_ids.size() + 1);
|
||||
const auto &info = images.at(image);
|
||||
hash(image_ids.at(image));
|
||||
hash(info.extent.width); hash(info.extent.height); hash(info.format); hash(info.usage);
|
||||
}
|
||||
|
||||
template<class Info, class Out>
|
||||
VkResult VKAPI_CALL create(VkDevice, const Info *, const VkAllocationCallbacks *, Out *out) {
|
||||
*out = handle<Out>();
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
template<class T> void VKAPI_CALL destroy(VkDevice, T, const VkAllocationCallbacks *) {}
|
||||
|
||||
VkResult VKAPI_CALL create_image(VkDevice, const VkImageCreateInfo *info,
|
||||
const VkAllocationCallbacks *, VkImage *out) {
|
||||
*out = handle<VkImage>();
|
||||
images[*out] = {info->extent, info->format, info->usage};
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VkResult VKAPI_CALL create_view(VkDevice, const VkImageViewCreateInfo *info,
|
||||
const VkAllocationCallbacks *, VkImageView *out) {
|
||||
assert(images.count(info->image));
|
||||
*out = handle<VkImageView>();
|
||||
views[*out] = info->image;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL destroy_image(VkDevice, VkImage image, const VkAllocationCallbacks *) {
|
||||
assert(images.erase(image) == 1);
|
||||
}
|
||||
void VKAPI_CALL destroy_view(VkDevice, VkImageView view, const VkAllocationCallbacks *) {
|
||||
assert(views.erase(view) == 1);
|
||||
}
|
||||
VkResult VKAPI_CALL create_buffer(VkDevice, const VkBufferCreateInfo *info,
|
||||
const VkAllocationCallbacks *, VkBuffer *out) {
|
||||
*out = handle<VkBuffer>();
|
||||
buffers[*out] = *info;
|
||||
buffer_creates++;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL destroy_buffer(VkDevice, VkBuffer buffer, const VkAllocationCallbacks *) {
|
||||
assert(buffers.erase(buffer) == 1);
|
||||
buffer_memory.erase(buffer);
|
||||
}
|
||||
void VKAPI_CALL image_requirements(VkDevice, VkImage image, VkMemoryRequirements *out) {
|
||||
const auto &info = images.at(image);
|
||||
const uint64_t bytes = info.format == VK_FORMAT_R32_SFLOAT ? 4 : 8;
|
||||
*out = {uint64_t(info.extent.width) * info.extent.height * bytes, 1, 1};
|
||||
}
|
||||
void VKAPI_CALL buffer_requirements(VkDevice, VkBuffer buffer, VkMemoryRequirements *out) {
|
||||
*out = {buffers.at(buffer).size, 1, 1};
|
||||
}
|
||||
VkResult VKAPI_CALL allocate(VkDevice, const VkMemoryAllocateInfo *info,
|
||||
const VkAllocationCallbacks *, VkDeviceMemory *out) {
|
||||
*out = handle<VkDeviceMemory>();
|
||||
allocations[*out].size = info->allocationSize;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL free_memory(VkDevice, VkDeviceMemory memory, const VkAllocationCallbacks *) {
|
||||
assert(allocations.erase(memory) == 1);
|
||||
}
|
||||
VkResult VKAPI_CALL bind_image(VkDevice, VkImage image, VkDeviceMemory memory, VkDeviceSize) {
|
||||
assert(images.count(image) && allocations.count(memory));
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VkResult VKAPI_CALL bind_buffer(VkDevice, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize) {
|
||||
assert(buffers.count(buffer) && allocations.count(memory));
|
||||
buffer_memory[buffer] = memory;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VkResult VKAPI_CALL map_memory(VkDevice, VkDeviceMemory memory, VkDeviceSize offset,
|
||||
VkDeviceSize size, VkMemoryMapFlags, void **out) {
|
||||
auto &allocation = allocations.at(memory);
|
||||
assert(offset == 0 && size <= allocation.size);
|
||||
allocation.data = std::make_unique<uint8_t[]>(allocation.size);
|
||||
*out = allocation.data.get();
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL unmap(VkDevice, VkDeviceMemory memory) { assert(allocations.count(memory)); }
|
||||
VkResult VKAPI_CALL idle(VkDevice) { return VK_SUCCESS; }
|
||||
void VKAPI_CALL memory_properties(VkPhysicalDevice, VkPhysicalDeviceMemoryProperties *out) {
|
||||
*out = {};
|
||||
out->memoryTypeCount = 1;
|
||||
out->memoryTypes[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
}
|
||||
VkResult VKAPI_CALL allocate_sets(VkDevice, const VkDescriptorSetAllocateInfo *info, VkDescriptorSet *out) {
|
||||
for (uint32_t i = 0; i < info->descriptorSetCount; i++) {
|
||||
out[i] = handle<VkDescriptorSet>();
|
||||
descriptors[out[i]] = {};
|
||||
set_creates++;
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
VkResult VKAPI_CALL reset_pool(VkDevice, VkDescriptorPool, VkDescriptorPoolResetFlags) {
|
||||
descriptors.clear();
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL update_sets(VkDevice, uint32_t count, const VkWriteDescriptorSet *writes,
|
||||
uint32_t, const VkCopyDescriptorSet *) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
const auto &write = writes[i];
|
||||
assert(descriptors.count(write.dstSet) && write.descriptorCount == 1);
|
||||
Binding binding{write.descriptorType, VK_NULL_HANDLE, VK_NULL_HANDLE, 0};
|
||||
if (write.pImageInfo) {
|
||||
binding.view = write.pImageInfo->imageView;
|
||||
assert(views.count(binding.view));
|
||||
} else {
|
||||
binding.buffer = write.pBufferInfo->buffer;
|
||||
binding.range = write.pBufferInfo->range;
|
||||
assert(buffers.count(binding.buffer));
|
||||
}
|
||||
descriptors.at(write.dstSet)[write.dstBinding] = binding;
|
||||
}
|
||||
}
|
||||
VkResult VKAPI_CALL create_pipelines(VkDevice, VkPipelineCache, uint32_t count,
|
||||
const VkComputePipelineCreateInfo *, const VkAllocationCallbacks *,
|
||||
VkPipeline *out) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
const auto index = static_cast<unsigned>(pipelines.size());
|
||||
out[i] = handle<VkPipeline>();
|
||||
pipelines[out[i]] = index;
|
||||
}
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
void VKAPI_CALL bind_pipeline(VkCommandBuffer, VkPipelineBindPoint, VkPipeline pipeline) {
|
||||
assert(pipelines.count(pipeline));
|
||||
bound_pipeline = pipeline;
|
||||
}
|
||||
void VKAPI_CALL bind_sets(VkCommandBuffer, VkPipelineBindPoint, VkPipelineLayout,
|
||||
uint32_t, uint32_t count, const VkDescriptorSet *sets,
|
||||
uint32_t, const uint32_t *) {
|
||||
assert(count == 1 && descriptors.count(sets[0]));
|
||||
bound_set = sets[0];
|
||||
}
|
||||
void VKAPI_CALL dispatch(VkCommandBuffer, uint32_t x, uint32_t y, uint32_t z) {
|
||||
const unsigned pipeline = pipelines.at(bound_pipeline);
|
||||
dispatches.push_back({pipeline, x, y, z});
|
||||
hash(1); hash(pipeline); hash(x); hash(y); hash(z);
|
||||
for (const auto &[slot, binding] : descriptors.at(bound_set)) {
|
||||
hash(slot); hash(binding.type);
|
||||
if (binding.view) {
|
||||
hash_image(views.at(binding.view));
|
||||
} else {
|
||||
if (!buffer_ids.count(binding.buffer))
|
||||
buffer_ids[binding.buffer] = static_cast<unsigned>(buffer_ids.size() + 1);
|
||||
const auto &allocation = allocations.at(buffer_memory.at(binding.buffer));
|
||||
const auto size = binding.range == VK_WHOLE_SIZE ? allocation.size : binding.range;
|
||||
assert(allocation.data && size <= allocation.size);
|
||||
hash(buffer_ids.at(binding.buffer)); hash(size);
|
||||
for (VkDeviceSize i = 0; i < size; i++) hash(allocation.data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
void VKAPI_CALL barrier(VkCommandBuffer, VkPipelineStageFlags src, VkPipelineStageFlags dst,
|
||||
VkDependencyFlags flags, uint32_t nm, const VkMemoryBarrier *memory,
|
||||
uint32_t nb, const VkBufferMemoryBarrier *, uint32_t ni,
|
||||
const VkImageMemoryBarrier *image) {
|
||||
assert(nb == 0);
|
||||
hash(2); hash(src); hash(dst); hash(flags); hash(nm); hash(ni);
|
||||
for (uint32_t i = 0; i < nm; i++) {
|
||||
hash(memory[i].srcAccessMask); hash(memory[i].dstAccessMask);
|
||||
}
|
||||
for (uint32_t i = 0; i < ni; i++) {
|
||||
hash_image(image[i].image);
|
||||
hash(image[i].oldLayout); hash(image[i].newLayout);
|
||||
hash(image[i].srcAccessMask); hash(image[i].dstAccessMask);
|
||||
hash(image[i].srcQueueFamilyIndex); hash(image[i].dstQueueFamilyIndex);
|
||||
}
|
||||
}
|
||||
void VKAPI_CALL clear_image(VkCommandBuffer, VkImage image, VkImageLayout layout,
|
||||
const VkClearColorValue *color, uint32_t count, const VkImageSubresourceRange *) {
|
||||
assert(count == 1);
|
||||
hash(3); hash_image(image); hash(layout);
|
||||
for (unsigned i = 0; i < 4; i++) hash(color->uint32[i]);
|
||||
}
|
||||
void VKAPI_CALL copy_image(VkCommandBuffer, VkImage src, VkImageLayout sl, VkImage dst,
|
||||
VkImageLayout dl, uint32_t count, const VkImageCopy *region) {
|
||||
assert(count == 1);
|
||||
hash(4); hash_image(src); hash(sl); hash_image(dst); hash(dl);
|
||||
hash(region->extent.width); hash(region->extent.height); hash(region->extent.depth);
|
||||
}
|
||||
|
||||
uint32_t dimension(uint32_t full, int level) { return std::max(full >> level, 1u); }
|
||||
|
||||
void check_images(uint32_t width, uint32_t height, int finest) {
|
||||
assert(images.size() == static_cast<size_t>(32 - 2 * finest));
|
||||
for (int level = finest; level < levels; level++) {
|
||||
const auto w = dimension(width, level), h = dimension(height, level);
|
||||
assert(std::any_of(images.begin(), images.end(), [=](const auto &entry) {
|
||||
const auto &image = entry.second;
|
||||
return image.format == VK_FORMAT_R16G16B16A16_SFLOAT && image.usage == flow_usage &&
|
||||
image.extent.width == w && image.extent.height == h;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
VkImageView external_image(uint32_t width, uint32_t height) {
|
||||
VkImage image = handle<VkImage>();
|
||||
VkImageView view = handle<VkImageView>();
|
||||
images[image] = {{width, height, 1}, VK_FORMAT_R8G8B8A8_UNORM,
|
||||
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT};
|
||||
views[view] = image;
|
||||
return view;
|
||||
}
|
||||
|
||||
void record(ddfg::FrameGen &fg, int model, uint32_t width, uint32_t height, unsigned generations) {
|
||||
const auto previous = external_image(width, height), current = external_image(width, height);
|
||||
const auto first = dispatches.size();
|
||||
for (unsigned i = 0; i < generations; i++)
|
||||
fg.record(reinterpret_cast<VkCommandBuffer>(1), previous, current, external_image(width, height),
|
||||
float(i + 1) / float(generations + 1), 0, i, i != 0);
|
||||
std::vector<Dispatch> expected;
|
||||
auto add = [&](unsigned pipeline, int level) {
|
||||
expected.push_back({pipeline, (dimension(width, level) + 15) / 16,
|
||||
(dimension(height, level) + 15) / 16, 1});
|
||||
};
|
||||
add(LUMA, 0); add(LUMA, 0);
|
||||
for (int level = 1; level < levels; level++) { add(DOWNSAMPLE, level); add(DOWNSAMPLE, level); }
|
||||
expected.push_back({GLOBAL_MOTION, 8, 1, 1});
|
||||
for (int level = fg.flowFinest(); level < levels; level++) add(PREWARP, level);
|
||||
for (int level = levels - 1; level >= fg.flowFinest(); level--) add(model == 4 ? FLOW4 : FLOW3, level);
|
||||
for (int i = 0; i < 4; i++) add(FLOW_REG, fg.flowFinest());
|
||||
add(model == 4 ? EXPAND4 : EXPAND3, 0);
|
||||
for (unsigned i = 0; i < generations; i++) add(SYNTH, 0);
|
||||
assert(dispatches.size() - first == expected.size());
|
||||
for (size_t i = 0; i < expected.size(); i++) {
|
||||
const auto &actual = dispatches[first + i], &want = expected[i];
|
||||
assert(actual.pipeline == want.pipeline && actual.x == want.x && actual.y == want.y && actual.z == want.z);
|
||||
}
|
||||
for (auto it = views.begin(); it != views.end();) {
|
||||
if (images.at(it->second).format == VK_FORMAT_R8G8B8A8_UNORM) {
|
||||
images.erase(it->second);
|
||||
it = views.erase(it);
|
||||
} else ++it;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 8);
|
||||
const std::string mode = argv[1];
|
||||
const int model = std::atoi(argv[2]), preset = std::atoi(argv[3]);
|
||||
uint32_t width = static_cast<uint32_t>(std::atoi(argv[4]));
|
||||
uint32_t height = static_cast<uint32_t>(std::atoi(argv[5]));
|
||||
const unsigned generations = static_cast<unsigned>(std::atoi(argv[6]));
|
||||
const unsigned repeats = static_cast<unsigned>(std::atoi(argv[7]));
|
||||
assert((model == 3 || model == 4) && preset >= 0 && preset <= 2);
|
||||
assert(width && height && generations >= 1 && generations <= 3 && repeats > 0);
|
||||
ddfg::DeviceDispatch dd;
|
||||
ddfg::InstanceDispatch id;
|
||||
id.GetPhysicalDeviceMemoryProperties = memory_properties;
|
||||
dd.CreateImage = create_image; dd.DestroyImage = destroy_image;
|
||||
dd.CreateImageView = create_view; dd.DestroyImageView = destroy_view;
|
||||
dd.CreateBuffer = create_buffer; dd.DestroyBuffer = destroy_buffer;
|
||||
dd.GetImageMemoryRequirements = image_requirements; dd.GetBufferMemoryRequirements = buffer_requirements;
|
||||
dd.AllocateMemory = allocate; dd.FreeMemory = free_memory;
|
||||
dd.BindImageMemory = bind_image; dd.BindBufferMemory = bind_buffer;
|
||||
dd.MapMemory = map_memory; dd.UnmapMemory = unmap; dd.DeviceWaitIdle = idle;
|
||||
dd.CreateSampler = create<VkSamplerCreateInfo, VkSampler>; dd.DestroySampler = destroy<VkSampler>;
|
||||
dd.CreateShaderModule = create<VkShaderModuleCreateInfo, VkShaderModule>;
|
||||
dd.DestroyShaderModule = destroy<VkShaderModule>;
|
||||
dd.CreateDescriptorSetLayout = create<VkDescriptorSetLayoutCreateInfo, VkDescriptorSetLayout>;
|
||||
dd.DestroyDescriptorSetLayout = destroy<VkDescriptorSetLayout>;
|
||||
dd.CreatePipelineLayout = create<VkPipelineLayoutCreateInfo, VkPipelineLayout>;
|
||||
dd.DestroyPipelineLayout = destroy<VkPipelineLayout>;
|
||||
dd.CreateDescriptorPool = create<VkDescriptorPoolCreateInfo, VkDescriptorPool>;
|
||||
dd.DestroyDescriptorPool = destroy<VkDescriptorPool>; dd.ResetDescriptorPool = reset_pool;
|
||||
dd.AllocateDescriptorSets = allocate_sets; dd.UpdateDescriptorSets = update_sets;
|
||||
dd.CreateComputePipelines = create_pipelines; dd.DestroyPipeline = destroy<VkPipeline>;
|
||||
dd.CmdBindPipeline = bind_pipeline; dd.CmdBindDescriptorSets = bind_sets; dd.CmdDispatch = dispatch;
|
||||
dd.CmdPipelineBarrier = barrier; dd.CmdClearColorImage = clear_image; dd.CmdCopyImage = copy_image;
|
||||
ddfg::FrameGen fg;
|
||||
assert(fg.init(&dd, &id, reinterpret_cast<VkPhysicalDevice>(1), reinterpret_cast<VkDevice>(2),
|
||||
0, reinterpret_cast<VkQueue>(3)));
|
||||
ddfg::Config cfg;
|
||||
cfg.enabled = true; cfg.model = model; cfg.perfPreset = preset; cfg.flowScale = 0.6f;
|
||||
fg.configure(cfg);
|
||||
assert(fg.onResize({width, height}, VK_FORMAT_R8G8B8A8_UNORM));
|
||||
assert(mode == "resources" || mode == "record" || mode == "resize" || mode == "preset");
|
||||
for (unsigned repeat = 0; repeat < repeats; repeat++) {
|
||||
const auto old_buffers = buffer_creates, old_sets = set_creates;
|
||||
if (mode != "record") check_images(width, height, fg.flowFinest());
|
||||
record(fg, model, width, height, generations);
|
||||
if (mode != "record") {
|
||||
assert(buffer_creates - old_buffers == static_cast<unsigned>(15 - fg.flowFinest()));
|
||||
assert(set_creates - old_sets == static_cast<unsigned>(54 - 4 * fg.flowFinest()));
|
||||
}
|
||||
if (repeat + 1 == repeats) break;
|
||||
if (mode == "resize") {
|
||||
width += 17; height += 9;
|
||||
assert(fg.onResize({width, height}, VK_FORMAT_R8G8B8A8_UNORM));
|
||||
} else if (mode == "preset") {
|
||||
cfg.perfPreset = (cfg.perfPreset + 1) % 3;
|
||||
fg.configure(cfg);
|
||||
} else {
|
||||
assert(mode == "record");
|
||||
}
|
||||
}
|
||||
uint64_t bytes = 0;
|
||||
for (const auto &[image, info] : images) {
|
||||
(void)image;
|
||||
bytes += uint64_t(info.extent.width) * info.extent.height *
|
||||
(info.format == VK_FORMAT_R32_SFLOAT ? 4 : 8);
|
||||
}
|
||||
std::printf("PASS images=%zu bytes=%llu buffers=%u sets=%u dispatches=%zu trace=%016llx\n",
|
||||
images.size(), static_cast<unsigned long long>(bytes), buffer_creates, set_creates,
|
||||
dispatches.size(), static_cast<unsigned long long>(command_hash));
|
||||
fg.destroy();
|
||||
assert(images.empty() && views.empty());
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("cc"), "C compiler required")
|
||||
class AndroidVolumeTest(unittest.TestCase):
|
||||
def test_missing_or_invalid_initial_state_recovers_without_restarting_the_sink(self):
|
||||
header = Path(__file__).resolve().parents[1] / "aaudio-sink/android-volume.h"
|
||||
harness = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#define PA_VOLUME_NORM 65536U
|
||||
#define PA_USEC_PER_MSEC 1000
|
||||
#define PA_SINK_INIT 0
|
||||
#define PA_SUBSCRIPTION_EVENT_SINK 1
|
||||
#define PA_SUBSCRIPTION_EVENT_CHANGE 2
|
||||
#define PA_MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#define pa_xnew0(type,n) ((type*)calloc(n,sizeof(type)))
|
||||
#define pa_xstrdup strdup
|
||||
#define pa_xfree free
|
||||
#define pa_log_warn(...) ((void)0)
|
||||
typedef struct { unsigned value; } pa_cvolume;
|
||||
typedef struct pa_time_event { int value; } pa_time_event;
|
||||
typedef struct pa_mainloop_api { void (*time_free)(pa_time_event*); } pa_mainloop_api;
|
||||
typedef struct { pa_mainloop_api *mainloop; } pa_core;
|
||||
typedef struct pa_sink {
|
||||
void *userdata; int state; bool muted; unsigned n_volume_steps, index;
|
||||
struct { unsigned channels; } sample_spec;
|
||||
pa_cvolume real_volume, reference_volume, soft_volume;
|
||||
pa_core *core;
|
||||
void (*set_volume)(struct pa_sink*), (*set_mute)(struct pa_sink*);
|
||||
} pa_sink;
|
||||
struct android_volume;
|
||||
struct userdata { struct android_volume *android_volume; };
|
||||
static int restarts, frees;
|
||||
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;
|
||||
}
|
||||
static void pa_cvolume_set(pa_cvolume *volume, unsigned channels, unsigned value) { volume->value=value; }
|
||||
static unsigned pa_cvolume_max(const pa_cvolume *volume) { return volume->value; }
|
||||
static void pa_cvolume_reset(pa_cvolume *volume, unsigned channels) { volume->value=PA_VOLUME_NORM; }
|
||||
static bool pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) { return a->value==b->value; }
|
||||
static void pa_sink_volume_changed(pa_sink *sink, const pa_cvolume *volume) { sink->real_volume=*volume; }
|
||||
static void pa_sink_mute_changed(pa_sink *sink, bool muted) { sink->muted=muted; }
|
||||
static void pa_sink_set_set_volume_callback(pa_sink *sink, void (*callback)(pa_sink*)) { sink->set_volume=callback; }
|
||||
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 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));
|
||||
}
|
||||
static void free_timer(pa_time_event *event) { frees++; free(event); }
|
||||
#include "android-volume.h"
|
||||
static void state(const char *directory, const char *text) {
|
||||
char *path=pa_sprintf_malloc("%s/volume.state",directory);
|
||||
FILE *f=fopen(path,"w"); assert(f); fputs(text,f); fclose(f); free(path);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
pa_mainloop_api api={.time_free=free_timer}; pa_core core={.mainloop=&api};
|
||||
struct userdata userdata={0};
|
||||
pa_sink sink={.userdata=&userdata,.core=&core,.state=1,.sample_spec={.channels=2},.real_volume={PA_VOLUME_NORM}};
|
||||
userdata.android_volume=android_volume_new(&sink,argv[1]);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
android_volume_free(userdata.android_volume); assert(frees==1);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "pulsecore").mkdir()
|
||||
for name in ("core-rtclock.h", "core-subscribe.h"):
|
||||
(root / "pulsecore" / name).touch()
|
||||
source = root / "test.c"
|
||||
source.write_text(harness)
|
||||
binary = root / "test"
|
||||
subprocess.run(["cc", "-std=c11", "-I", str(root), "-I", str(header.parent),
|
||||
str(source), "-o", str(binary)], check=True, capture_output=True)
|
||||
subprocess.run([str(binary), str(root)], check=True, capture_output=True)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,169 @@
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session'
|
||||
|
||||
|
||||
def function_source(name):
|
||||
source = SCRIPT.read_text()
|
||||
start = source.index('%s() {' % name)
|
||||
end = source.index('\n }', start)
|
||||
return source[start:end + len('\n }')]
|
||||
|
||||
|
||||
def run_bash(script, env=None):
|
||||
return subprocess.run(['bash', '-c', script], capture_output=True, text=True, timeout=10, env=env)
|
||||
|
||||
|
||||
class ClientZramFocusTest(unittest.TestCase):
|
||||
def test_refocus_restarts_the_delay_and_game_exit_restores_a_packed_client(self):
|
||||
source = SCRIPT.read_text()
|
||||
start = source.index(' if [ "$_bl_game" = 1 ] && bl_game_focused; then')
|
||||
stop = source.index(' nap 5', start)
|
||||
body = source[start:stop]
|
||||
harness = '''
|
||||
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_apps=" 413150"
|
||||
_bl_pids=(123)
|
||||
bl_game_focused() { [ "$focused" = 1 ]; }
|
||||
bl_over_cap() { return 1; }
|
||||
bl_zram_send() { echo "send:$1"; }
|
||||
tick() {
|
||||
SECONDS=$1 _bl_game=$2 focused=$3
|
||||
''' + body + '''
|
||||
}
|
||||
tick 0 1 1
|
||||
tick 5 1 0
|
||||
tick 30 1 1
|
||||
echo "refocus:$_bl_packed"
|
||||
tick 49 1 1
|
||||
tick 50 1 1
|
||||
tick 55 1 0
|
||||
tick 60 0 0
|
||||
'''
|
||||
result = run_bash(harness)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
self.assertEqual(['refocus:-1', 'send:1', 'send:0'], result.stdout.splitlines())
|
||||
|
||||
def monitor_harness(self):
|
||||
source = SCRIPT.read_text()
|
||||
start = source.index(' bl_zram_scan\n if bl_cap_due; then')
|
||||
stop = source.index(' nap 5', start)
|
||||
return '''
|
||||
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
|
||||
_bl_apps=" 413150"
|
||||
_bl_pids=(123)
|
||||
step() { :; }
|
||||
bl_zram_scan() { :; }
|
||||
bl_game_focused() { [ "$focused" = 1 ]; }
|
||||
bl_cap_due() { [ "$cap_due" = 1 ]; }
|
||||
bl_over_cap() { [ "$over_cap" = 1 ]; }
|
||||
bl_zram_send() { echo "send:$1:$3"; }
|
||||
tick() {
|
||||
SECONDS=$1 _bl_game=$2 focused=$3 over_cap=$4 cap_due=$5
|
||||
''' + source[start:stop] + '\n}\n'
|
||||
|
||||
def test_client_toggle_still_disables_automatic_compression(self):
|
||||
result = run_bash(self.monitor_harness() + '''
|
||||
BL_ZRAM_CLIENT=0
|
||||
tick 0 1 1 0 0
|
||||
tick 25 1 1 0 0
|
||||
tick 30 0 0 0 0
|
||||
''')
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
self.assertEqual('', result.stdout)
|
||||
|
||||
def test_a_new_game_restarts_the_compression_delay(self):
|
||||
result = run_bash(self.monitor_harness() + '''
|
||||
tick 0 1 1 0 0
|
||||
_bl_apps=" 413150 1245620"
|
||||
tick 15 1 1 0 0
|
||||
tick 20 1 1 0 0
|
||||
echo "starting:$_bl_packed"
|
||||
tick 34 1 1 0 0
|
||||
tick 35 1 1 0 0
|
||||
''')
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
self.assertEqual(['starting:-1', 'send:1:client'], result.stdout.splitlines())
|
||||
|
||||
def test_ram_cap_can_still_compress_an_unfocused_client(self):
|
||||
result = run_bash(self.monitor_harness() + '''
|
||||
BL_ZRAM_CLIENT=0 BL_RAM_CAP_MB=1024
|
||||
bl_zram_usage() { _bl_rss=$((768 * 1024)); }
|
||||
tick 0 1 0 1 1
|
||||
echo "cap:$_bl_packed:$_bl_since:$_bl_backoff"
|
||||
tick 5 0 0 0 0
|
||||
''')
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
self.assertEqual(['send:1:client', 'send:1:session', 'cap:0:-1:60', 'send:0:client'], result.stdout.splitlines())
|
||||
|
||||
def test_game_exit_defers_restore_until_the_session_is_under_the_ram_cap(self):
|
||||
result = run_bash(self.monitor_harness() + '''
|
||||
tick 0 1 1 0 0
|
||||
tick 20 1 1 0 0
|
||||
tick 25 1 0 0 0
|
||||
tick 30 0 0 1 0
|
||||
echo "deferred:$_bl_unpack:$_bl_packed"
|
||||
tick 35 0 0 0 1
|
||||
echo "restored:$_bl_unpack"
|
||||
''')
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
self.assertEqual(['send:1:client', 'deferred:1:-1', 'send:0:client', 'restored:0'], result.stdout.splitlines())
|
||||
|
||||
def test_scan_keeps_the_running_game_and_ignores_steams_own_reaper(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
root = Path(temp.name)
|
||||
self.write_cmd(root, 10, ['/usr/lib/steam/reaper', 'SteamLaunch', 'AppId=769', '--'])
|
||||
self.write_cmd(root, 20, ['/usr/bin/FEX', '/usr/lib/steam/reaper', 'SteamLaunch', 'AppId=1245620', '--'])
|
||||
self.write_cmd(root, 30, ['/home/deck/.local/share/Steam/steamrtarm64/steam'])
|
||||
self.write_cmd(root, 40, ['/usr/bin/wine', 'game.exe'])
|
||||
self.write_cmd(root, 50, ['/usr/bin/FEXInterpreter', '/usr/bin/steamwebhelper'])
|
||||
scan = function_source('bl_zram_scan').replace('for _d in /proc/[0-9]*', 'for _d in "$FAKE"/[0-9]*')
|
||||
result = run_bash('FAKE=%s\n%s\nbl_zram_scan\necho "game=$_bl_game"\necho "apps=${_bl_apps# }"\necho "pids=${_bl_pids[*]}"\necho "others=${_bl_others[*]}"' % (root, scan))
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(['game=1', 'apps=1245620', 'pids=30 50', 'others=40'], result.stdout.splitlines())
|
||||
|
||||
def test_focus_must_be_the_running_game(self):
|
||||
focus = function_source('bl_game_focused')
|
||||
script = '''
|
||||
%s
|
||||
check() {
|
||||
BL_DESKTOP=$1 BL_LAUNCH_DIR=$2 _bl_apps=$3
|
||||
if bl_game_focused; then echo yes; else echo no; fi
|
||||
}
|
||||
check "" "$dir" " 413150"
|
||||
check "" "$dir" " 1245620"
|
||||
printf '%%s\\n' '{"focusedApp": 999}' > "$dir/agent/focus.json"
|
||||
check "" "$dir" " 413150"
|
||||
printf '%%s\\n' '{"focusedApp": 769}' > "$dir/agent/focus.json"
|
||||
check "" "$dir" " 413150"
|
||||
rm -f "$dir/agent/focus.json"
|
||||
check 1 "$dir" " 413150"
|
||||
check "" "" " 413150"
|
||||
''' % focus
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
launch = Path(temp.name)
|
||||
(launch / 'agent').mkdir()
|
||||
(launch / 'agent' / 'focus.json').write_text('{"t": 1, "focusedApp": 413150}\n')
|
||||
result = run_bash('dir=%s\n%s' % (launch, script))
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(['yes', 'no', 'no', 'no', 'yes', 'yes'], result.stdout.splitlines())
|
||||
|
||||
@staticmethod
|
||||
def write_cmd(root, pid, args):
|
||||
proc = root / str(pid)
|
||||
proc.mkdir()
|
||||
(proc / 'cmdline').write_bytes(b'\0'.join(arg.encode() for arg in args) + b'\0')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,102 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CHAIN = ROOT / "app/src/main/cpp/framegen/ddfg"
|
||||
|
||||
|
||||
class DdfgFlowLevelsTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
compiler = shutil.which(os.environ.get("CXX", "c++"))
|
||||
if compiler is None:
|
||||
raise unittest.SkipTest("A host C++ compiler is required")
|
||||
candidates = [Path("/usr/include/vulkan"), Path("/opt/homebrew/include/vulkan")]
|
||||
for key in ("ANDROID_NDK_HOME", "ANDROID_NDK_ROOT", "NDK_HOME"):
|
||||
if os.environ.get(key):
|
||||
candidates.extend(Path(os.environ[key]).glob("toolchains/llvm/prebuilt/*/sysroot/usr/include/vulkan"))
|
||||
for sdk in {Path(os.environ.get("ANDROID_HOME", "/nonexistent")),
|
||||
Path(os.environ.get("ANDROID_SDK_ROOT", "/nonexistent")),
|
||||
Path.home() / "Library/Android/sdk", Path.home() / "Android/Sdk"}:
|
||||
candidates.extend(sdk.glob("ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include/vulkan"))
|
||||
headers = next((p for p in candidates if (p / "vulkan.h").is_file()), None)
|
||||
if headers is None:
|
||||
raise unittest.SkipTest("Vulkan headers from the Android NDK or system SDK are required")
|
||||
cls.temp = tempfile.TemporaryDirectory(prefix="droiddeck-ddfg-levels-")
|
||||
cls.addClassCleanup(cls.temp.cleanup)
|
||||
work = Path(cls.temp.name)
|
||||
shutil.copytree(headers, work / "include/vulkan", ignore=shutil.ignore_patterns("*.hpp"))
|
||||
if (headers.parent / "vk_video").is_dir():
|
||||
shutil.copytree(headers.parent / "vk_video", work / "include/vk_video")
|
||||
cls.binary = work / "ddfg-flow-levels"
|
||||
build = subprocess.run([
|
||||
compiler, "-std=c++17", "-O2", "-Wall", "-Wextra",
|
||||
"-Wno-missing-field-initializers", "-Wno-misleading-indentation",
|
||||
"-I" + str(work / "include"), "-I" + str(CHAIN),
|
||||
str(ROOT / "tools/tests/ddfg_flow_levels_harness.cpp"), str(CHAIN / "framegen.cpp"),
|
||||
"-o", str(cls.binary),
|
||||
], capture_output=True, text=True, timeout=120)
|
||||
if build.returncode:
|
||||
raise RuntimeError(build.stdout + build.stderr)
|
||||
|
||||
def run_case(self, mode="resources", model=4, preset=2, width=1280, height=720, generations=1, repeats=1):
|
||||
result = subprocess.run([
|
||||
str(self.binary), mode, str(model), str(preset), str(width), str(height),
|
||||
str(generations), str(repeats),
|
||||
], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertTrue(result.stdout.startswith("PASS "), result.stdout)
|
||||
return dict(re.findall(r"(\w+)=(\w+)", result.stdout))
|
||||
|
||||
def test_each_model_and_preset_allocates_only_solved_flow_levels(self):
|
||||
for model in (3, 4):
|
||||
for preset, finest in enumerate((1, 2, 3)):
|
||||
with self.subTest(model=model, preset=preset):
|
||||
values = self.run_case(model=model, preset=preset)
|
||||
self.assertEqual(int(values["images"]), 32 - 2 * finest)
|
||||
self.assertEqual(int(values["buffers"]), 18 - finest)
|
||||
self.assertEqual(int(values["sets"]), 54 - 4 * finest)
|
||||
|
||||
def test_default_preset_saves_the_exact_high_resolution_flow_payload(self):
|
||||
for width, height in ((1280, 720), (1920, 1080), (2560, 1440)):
|
||||
with self.subTest(width=width, height=height):
|
||||
values = self.run_case(width=width, height=height)
|
||||
pixels = lambda level: max(width >> level, 1) * max(height >> level, 1)
|
||||
luma_bytes = 4 * (2 * sum(pixels(l) for l in range(7)) +
|
||||
sum(pixels(l) for l in range(3, 7)))
|
||||
flow_bytes = 8 * (sum(pixels(l) for l in range(3, 7)) +
|
||||
2 * width * height + 2 * pixels(3))
|
||||
self.assertEqual(int(values["bytes"]), luma_bytes + flow_bytes)
|
||||
|
||||
def test_small_and_odd_extents_keep_valid_bindings_and_dispatch_sizes(self):
|
||||
for width, height in ((1, 1), (17, 9), (135, 73)):
|
||||
for preset in range(3):
|
||||
with self.subTest(width=width, height=height, preset=preset):
|
||||
self.run_case(width=width, height=height, preset=preset)
|
||||
|
||||
def test_two_three_and_four_times_generation_keep_the_same_dispatch_schedule(self):
|
||||
for model in (3, 4):
|
||||
for preset in range(3):
|
||||
for generations in (1, 2, 3):
|
||||
with self.subTest(model=model, preset=preset, generations=generations):
|
||||
self.run_case("record", model=model, preset=preset, generations=generations, repeats=3)
|
||||
|
||||
def test_resize_rebuilds_every_solved_level(self):
|
||||
for preset in range(3):
|
||||
with self.subTest(preset=preset):
|
||||
self.run_case("resize", preset=preset, generations=3, repeats=3)
|
||||
|
||||
def test_live_preset_changes_rebuild_the_level_range(self):
|
||||
for model in (3, 4):
|
||||
with self.subTest(model=model):
|
||||
self.run_case("preset", model=model, generations=3, repeats=4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,74 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
GPU = TOOLS / "linuxfs/desktop/droiddeck-gpu"
|
||||
WINDOW = TOOLS / "linuxfs/overlay/usr/local/bin/droiddeck-gpu-window"
|
||||
KEYS = ("MESA_VK_WSI_DEBUG", "SDL_VIDEODRIVER", "WAYLAND_DISPLAY", "BL_GPU_CHILD_WSI", "BL_DESKTOP_GPU_CHILD")
|
||||
|
||||
|
||||
class DesktopGpuWindowTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
self.out = self.tmp / "gamescope.json"
|
||||
fake = self.tmp / "gamescope"
|
||||
fake.write_text("#!%s\nimport json, os, sys\njson.dump({'args': sys.argv[1:], 'env': {k: os.environ.get(k) for k in %r}}, open(%r, 'w'))\n"
|
||||
% (sys.executable, KEYS, str(self.out)))
|
||||
fake.chmod(0o755)
|
||||
|
||||
def run_gpu(self, **env):
|
||||
base = {k: v for k, v in os.environ.items() if k not in KEYS + ("BL_DEBUG_DIR", "BL_DESKTOP_GPU_WINDOW")}
|
||||
base.update(PATH="%s:%s" % (self.tmp, os.environ["PATH"]), BL_WIDTH="1280", BL_HEIGHT="720", **env)
|
||||
subprocess.run(["bash", str(GPU), "game.exe"], env=base, check=True, capture_output=True)
|
||||
return json.loads(self.out.read_text())
|
||||
|
||||
def test_on_the_desktop_the_game_gets_a_window_of_its_own(self):
|
||||
run = self.run_gpu(WAYLAND_DISPLAY="wayland-1", MESA_VK_WSI_DEBUG="sw,linear")
|
||||
self.assertEqual(run["args"][:2], ["--backend", "sdl"])
|
||||
self.assertNotIn("-f", run["args"])
|
||||
self.assertEqual(run["args"][-2:], ["/usr/local/bin/droiddeck-gpu-window", "game.exe"])
|
||||
self.assertEqual(run["env"]["WAYLAND_DISPLAY"], "wayland-1")
|
||||
self.assertEqual(run["env"]["SDL_VIDEODRIVER"], "wayland")
|
||||
self.assertEqual(run["env"]["MESA_VK_WSI_DEBUG"], "sw")
|
||||
self.assertEqual(run["env"]["BL_GPU_CHILD_WSI"], "linear")
|
||||
self.assertEqual(run["env"]["BL_DESKTOP_GPU_CHILD"], "1")
|
||||
|
||||
def test_full_screen_stays_available(self):
|
||||
for env in ({"WAYLAND_DISPLAY": "wayland-1", "BL_DESKTOP_GPU_WINDOW": "0"}, {"WAYLAND_DISPLAY": "wayland-0"}, {}):
|
||||
run = self.run_gpu(**env)
|
||||
self.assertEqual(run["args"][:2], ["--backend", "wayland"])
|
||||
self.assertIn("-f", run["args"])
|
||||
self.assertEqual(run["env"]["WAYLAND_DISPLAY"], "wayland-0")
|
||||
self.assertIsNone(run["env"]["MESA_VK_WSI_DEBUG"])
|
||||
self.assertIsNone(run["env"]["BL_GPU_CHILD_WSI"])
|
||||
|
||||
def test_the_game_inside_the_window_gets_its_own_settings_back(self):
|
||||
script = "import json, os; print(json.dumps({k: os.environ.get(k) for k in %r}))" % (KEYS,)
|
||||
for saved, expected in (("linear", "linear"), ("", None)):
|
||||
env = {k: v for k, v in os.environ.items() if k not in KEYS + ("DISPLAY",)}
|
||||
env.update(BL_GPU_CHILD_WSI=saved, MESA_VK_WSI_DEBUG="sw", SDL_VIDEODRIVER="wayland")
|
||||
out = subprocess.run([sys.executable, str(WINDOW), sys.executable, "-c", script], env=env,
|
||||
check=True, capture_output=True, text=True).stdout
|
||||
child = json.loads(out)
|
||||
self.assertEqual(child["MESA_VK_WSI_DEBUG"], expected)
|
||||
self.assertEqual(child["SDL_VIDEODRIVER"], "x11")
|
||||
self.assertIsNone(child["BL_GPU_CHILD_WSI"])
|
||||
|
||||
def test_outside_a_window_the_game_keeps_its_settings(self):
|
||||
script = "import os; print(os.environ.get('MESA_VK_WSI_DEBUG'), os.environ.get('SDL_VIDEODRIVER'))"
|
||||
env = {k: v for k, v in os.environ.items() if k not in KEYS + ("DISPLAY",)}
|
||||
env.update(MESA_VK_WSI_DEBUG="linear", SDL_VIDEODRIVER="x11")
|
||||
out = subprocess.run([sys.executable, str(WINDOW), sys.executable, "-c", script], env=env,
|
||||
check=True, capture_output=True, text=True).stdout.split()
|
||||
self.assertEqual(out, ["linear", "x11"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -456,6 +456,15 @@ class ProtonRunTest(Temp):
|
||||
("0", "0", str(appid << 32 | 0x02000000), "1"))
|
||||
self.assertEqual(env["STEAM_COMPAT_DATA_PATH"], str(self.root / ("steamapps/compatdata/%d" % appid)))
|
||||
|
||||
def test_a_window_draws_with_the_desktops_software_gl(self):
|
||||
target = RUN["Target"]("2596113170", "/c", "/i", str(self.root), "fixed")
|
||||
session = {"MESA_LOADER_DRIVER_OVERRIDE": "zink", "GALLIUM_DRIVER": "zink", "LIBGL_KOPPER_DRI2": "true"}
|
||||
env = RUN["environment"](session, target, "/tool", str(self.root), window=True)
|
||||
self.assertEqual((env["LIBGL_ALWAYS_SOFTWARE"], env["GALLIUM_DRIVER"]), ("1", "llvmpipe"))
|
||||
self.assertNotIn("MESA_LOADER_DRIVER_OVERRIDE", env)
|
||||
self.assertNotIn("LIBGL_KOPPER_DRI2", env)
|
||||
self.assertEqual(RUN["environment"](session, target, "/tool", str(self.root))["GALLIUM_DRIVER"], "zink")
|
||||
|
||||
def test_a_steam_game_keeps_its_own_id(self):
|
||||
target = RUN["Target"]("413150", "/c", "/i", str(self.root), "steam")
|
||||
env = RUN["environment"]({"PROTON_USE_WINED3D": "0"}, target, "/tool", str(self.root), window=True)
|
||||
@@ -465,6 +474,13 @@ class ProtonRunTest(Temp):
|
||||
self.assertEqual(RUN["arguments"]("/root/x/setup.msi", ["/qn"]), ["msiexec", "/i", "Z:\\root\\x\\setup.msi", "/qn"])
|
||||
self.assertEqual(RUN["arguments"]("/root/x/a.exe", ["-w"]), ["/root/x/a.exe", "-w"])
|
||||
|
||||
def test_a_virtual_desktop_runs_the_program_by_its_windows_path(self):
|
||||
pfx = "/root/Steam/steamapps/compatdata/2596113170"
|
||||
self.assertEqual(RUN["arguments"](pfx + "/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe", [], "1280x720", pfx),
|
||||
["explorer.exe", "/desktop=droiddeck,1280x720", "C:\\Program Files (x86)\\Battle.net\\Battle.net Launcher.exe"])
|
||||
self.assertEqual(RUN["arguments"]("/root/.cache/setup.exe", ["--lang=enUS"], "1920x1080", pfx),
|
||||
["explorer.exe", "/desktop=droiddeck,1920x1080", "Z:\\root\\.cache\\setup.exe", "--lang=enUS"])
|
||||
|
||||
def test_a_games_own_program_is_left_to_steam(self):
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: STARDEW}))
|
||||
self.assertEqual(RUN["compat"]()["launch_programs"](STARDEW["config"]),
|
||||
@@ -554,6 +570,50 @@ class ProtonRunTest(Temp):
|
||||
self.game("70", "Linux Game", "run.sh")
|
||||
self.assertEqual(self.run_main(["--app", "70"])[0], 2)
|
||||
|
||||
def test_without_steam_a_shortcut_reuses_a_signed_prefix_folder(self):
|
||||
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
|
||||
start = self.tmp / "Games/Epic/Game/Binaries"
|
||||
start.mkdir()
|
||||
signed = self.root / "steamapps/compatdata/-1561598272"
|
||||
signed.mkdir(parents=True)
|
||||
code, calls, dirs = self.run_main(["--app", "2733369024", "--dir", str(start), "--", str(bat)])
|
||||
self.assertIsNone(code)
|
||||
env = calls[0][2]
|
||||
self.assertEqual(env["STEAM_COMPAT_DATA_PATH"], str(signed))
|
||||
self.assertFalse((self.root / "steamapps/compatdata/2733369024").exists())
|
||||
|
||||
def test_prefix_folder_prefers_initialized_unsigned_over_empty_signed(self):
|
||||
signed = self.root / "steamapps/compatdata/-1561598272"
|
||||
signed.mkdir(parents=True)
|
||||
initialized = self.root / "steamapps/compatdata/2733369024/pfx"
|
||||
initialized.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(initialized.parent))
|
||||
|
||||
def test_prefix_folder_prefers_initialized_signed_over_empty_unsigned(self):
|
||||
unsigned = self.root / "steamapps/compatdata/2733369024"
|
||||
unsigned.mkdir(parents=True)
|
||||
initialized = self.root / "steamapps/compatdata/-1561598272/pfx"
|
||||
initialized.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(initialized.parent))
|
||||
|
||||
def test_prefix_folder_prefers_unsigned_when_initialization_ties(self):
|
||||
unsigned = self.root / "steamapps/compatdata/2733369024/pfx"
|
||||
unsigned.mkdir(parents=True)
|
||||
signed = self.root / "steamapps/compatdata/-1561598272/pfx"
|
||||
signed.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(unsigned.parent))
|
||||
|
||||
def test_prefix_folder_skips_numeric_names_too_long_to_convert(self):
|
||||
from unittest.mock import patch
|
||||
folder = self.root / "steamapps/compatdata"
|
||||
folder.mkdir(parents=True)
|
||||
with patch.object(RUN["os"], "listdir", return_value=["9" * 5000]):
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024),
|
||||
str(folder / "2733369024"))
|
||||
|
||||
def test_without_steam_a_shortcut_keeps_its_prefix_folder_and_launch_options(self):
|
||||
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
|
||||
start = self.tmp / "Games/Epic/Game/Binaries"
|
||||
@@ -568,6 +628,43 @@ class ProtonRunTest(Temp):
|
||||
self.assertTrue((self.root / "steamapps/compatdata/2733369024").is_dir())
|
||||
self.assertEqual(dirs, [str(start)])
|
||||
|
||||
def write_account(self):
|
||||
self.write("Steam/config/loginusers.vdf",
|
||||
'"users"\n{\n\t"76561198352563669"\n\t{\n\t\t"MostRecent"\t\t"1"\n\t}\n}\n')
|
||||
return "Steam/userdata/392297941/config/"
|
||||
|
||||
def test_without_steam_and_options_a_game_takes_its_steam_launch_options(self):
|
||||
config = self.write_account()
|
||||
self.write(config + "localconfig.vdf", '"UserLocalConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n'
|
||||
'\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"apps"\n\t\t\t\t{\n\t\t\t\t\t"413150"\n\t\t\t\t\t{\n'
|
||||
'\t\t\t\t\t\t"cloud"\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t"LaunchOptions"\t\t"-wrong"\n\t\t\t\t\t\t}\n'
|
||||
'\t\t\t\t\t\t"LaunchOptions"\t\t"DXVK_HUD=1 %command% -d3d9 \\"-name=Two Words\\""\n'
|
||||
'\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n')
|
||||
shortcuts = runpy.run_path(str(BIN / "droiddeck-steam-shortcuts"))
|
||||
self.write(config + "shortcuts.vdf", shortcuts["write"]({"shortcuts": {
|
||||
"0": {"appid": -1561598272, "AppName": "Batman", "LaunchOptions": "-d3d9"},
|
||||
"1": {"appid": -1, "AppName": "Other", "LaunchOptions": "-x"},
|
||||
}}))
|
||||
root = str(self.root)
|
||||
self.assertEqual(RUN["steam_options"]("413150", root), 'DXVK_HUD=1 %command% -d3d9 "-name=Two Words"')
|
||||
self.assertEqual(RUN["steam_options"]("2733369024", root), "-d3d9")
|
||||
self.assertEqual(RUN["steam_options"]("70", root), "")
|
||||
self.assertEqual(RUN["steam_options"]("2733369025", root), "")
|
||||
info = {"common": {"type": "Game"}, "config": {"launch": {
|
||||
"0": {"executable": "Game.exe", "type": "default", "config": {"oslist": "windows"}}}}}
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: info}))
|
||||
program = self.game("413150", "Some Game", "Game.exe")
|
||||
code, calls, _ = self.run_main(["--app", "413150"])
|
||||
self.assertIsNone(code)
|
||||
_, argv, env = calls[0]
|
||||
self.assertEqual(argv[1:], ["waitforexitandrun", str(program), "-d3d9", "-name=Two Words"])
|
||||
self.assertEqual(env["DXVK_HUD"], "1")
|
||||
bat = self.write("Games/GOG/Batman/Batman.exe", b"MZ")
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat), "-d3d9"])
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--options", "", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat)])
|
||||
|
||||
def test_launch_options_split_like_steam_does(self):
|
||||
split = RUN["split_options"]
|
||||
self.assertEqual(split(""), ({}, []))
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat"))
|
||||
|
||||
|
||||
class DeviceControlsTest(unittest.TestCase):
|
||||
def test_sync_controls_queued_notifications_are_processed_without_another_frame(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
Path(directory, "state.json").write_text(json.dumps({"brightness": 0.5, "revision": 1}))
|
||||
helper = LIVE["Helper"]("/steam", 0)
|
||||
helper.controls_installed = True
|
||||
page = mock.Mock(events=[])
|
||||
page.ws.pending.return_value = False
|
||||
helper.page = page
|
||||
payload = json.dumps({"id": 1, "options": {"strTitle": "Pick a file"}})
|
||||
def evaluate(expression):
|
||||
for name, value in [(LIVE["BRIGHTNESS_BINDING"], "0.4"), (LIVE["FILE_BINDING"], payload)]:
|
||||
page.events.append({"method": "Runtime.bindingCalled", "params": {"name": name, "payload": value}})
|
||||
return True
|
||||
def drain():
|
||||
events, page.events = page.events, []
|
||||
return events
|
||||
page.evaluate.side_effect = evaluate
|
||||
page.drain.side_effect = drain
|
||||
helper.reconcile = mock.Mock()
|
||||
helper.sync_frame_limit = mock.Mock()
|
||||
helper.ensure_tools = mock.Mock(side_effect=[None, StopIteration])
|
||||
helper.open_chooser = mock.Mock()
|
||||
watcher = mock.Mock()
|
||||
watcher.fileno.return_value = -1
|
||||
watcher.changed.return_value = False
|
||||
globals_ = LIVE["Helper"].serve.__globals__
|
||||
with mock.patch.dict(globals_, {"CONTROLS_DIR": directory,
|
||||
"brightness_request": lambda value: LIVE["brightness_request"](value, directory)}), \
|
||||
mock.patch.dict(globals_["COMPAT"], {"state_path": lambda name: str(Path(directory, name))}), \
|
||||
mock.patch.object(globals_["select"], "select", return_value=([], [], [])) as select_:
|
||||
with self.assertRaises(StopIteration):
|
||||
helper.serve(watcher)
|
||||
self.assertEqual(float(Path(directory, "brightness.request").read_text()), 0.4)
|
||||
helper.open_chooser.assert_called_once_with(payload)
|
||||
self.assertEqual(page.events, [])
|
||||
select_.assert_not_called()
|
||||
|
||||
def test_native_brightness_notifications_do_not_echo_android_readback(self):
|
||||
harness = r"""
|
||||
const assert = require('assert');
|
||||
globalThis.window = globalThis;
|
||||
const requests = [], callbacks = [];
|
||||
const timers = [];
|
||||
globalThis.setTimeout = callback => timers.push(callback);
|
||||
let current = 1;
|
||||
window.droiddeckBrightnessChanged = value => requests.push(Number(value));
|
||||
globalThis.SteamClient = { System: { Display: {
|
||||
RegisterForBrightnessChanges(cb) { callbacks.push(cb); cb({ flBrightness: 1 }); return {}; },
|
||||
SetBrightness(value) {
|
||||
if (current === value) return;
|
||||
current = value;
|
||||
callbacks.forEach(cb => cb({ flBrightness: value }));
|
||||
}
|
||||
} } };
|
||||
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
const bridge = window.__droiddeckBrightness;
|
||||
bridge.set(0.5);
|
||||
bridge.set(0.5);
|
||||
assert.deepStrictEqual(requests, []);
|
||||
callbacks.forEach(cb => cb({ flBrightness: 0.8 }));
|
||||
assert.deepStrictEqual(requests, [0.8]);
|
||||
bridge.set(0.7992126);
|
||||
assert.deepStrictEqual(requests, [0.8]);
|
||||
for (const value of [NaN, Infinity, -1, 2, '0.5']) callbacks.forEach(cb => cb({ flBrightness: value }));
|
||||
assert.deepStrictEqual(requests, [0.8]);
|
||||
assert.strictEqual(callbacks.length, 1);
|
||||
SteamClient.System.Display.SetBrightness = value => callbacks.forEach(cb => cb({ flBrightness: value + 0.1 }));
|
||||
bridge.set(0.3);
|
||||
assert.deepStrictEqual(requests, [0.8]);
|
||||
callbacks.forEach(cb => cb({ flBrightness: 0.6 }));
|
||||
assert.deepStrictEqual(requests, [0.8, 0.6]);
|
||||
SteamClient.System.Display.SetBrightness = () => {};
|
||||
bridge.set(0.65);
|
||||
timers.forEach(callback => callback());
|
||||
callbacks.forEach(cb => cb({ flBrightness: 0.7 }));
|
||||
assert.deepStrictEqual(requests, [0.8, 0.6, 0.7]);
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
script = Path(directory) / "bridge.js"
|
||||
script.write_text(LIVE["BRIGHTNESS_JS"])
|
||||
test = Path(directory) / "test.js"
|
||||
test.write_text(harness)
|
||||
result = subprocess.run(["node", str(test), str(script)], capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_requests_reject_nonfinite_and_out_of_range_values(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / "brightness.request"
|
||||
for value in ["NaN", "Infinity", "-0.1", "1.1", "invalid", None]:
|
||||
LIVE["brightness_request"](value, directory)
|
||||
self.assertFalse(path.exists())
|
||||
LIVE["brightness_request"]("0.4", directory)
|
||||
self.assertEqual(float(path.read_text()), 0.4)
|
||||
|
||||
def test_failed_request_revision_republishes_the_actual_brightness(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
globals_ = LIVE["Helper"].sync_controls.__globals__
|
||||
previous = globals_["CONTROLS_DIR"]
|
||||
try:
|
||||
globals_["CONTROLS_DIR"] = directory
|
||||
helper = LIVE["Helper"]("/steam", 0)
|
||||
calls = []
|
||||
helper.controls_installed = True
|
||||
helper.page = type("Page", (), {"evaluate": lambda self, expression: calls.append(expression) or True})()
|
||||
path = Path(directory) / "state.json"
|
||||
path.write_text(json.dumps({"brightness": 0.5, "revision": 1}))
|
||||
helper.sync_controls()
|
||||
helper.sync_controls()
|
||||
self.assertEqual(len(calls), 1)
|
||||
path.write_text(json.dumps({"brightness": 0.5, "revision": 2}))
|
||||
helper.sync_controls()
|
||||
self.assertEqual(len(calls), 2)
|
||||
finally:
|
||||
globals_["CONTROLS_DIR"] = previous
|
||||
|
||||
def test_display_bridge_retries_binding_and_install_before_caching_state(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
globals_ = LIVE["Helper"].sync_controls.__globals__
|
||||
previous = globals_["CONTROLS_DIR"]
|
||||
try:
|
||||
globals_["CONTROLS_DIR"] = directory
|
||||
Path(directory, "state.json").write_text(json.dumps({"brightness": 0.5, "revision": 1}))
|
||||
calls, installs, writes = [], ["unavailable", "installed", "present"], []
|
||||
class Page:
|
||||
present = True
|
||||
def call(self, method, params):
|
||||
calls.append((method, params))
|
||||
def evaluate(self, expression):
|
||||
if expression == LIVE["BRIGHTNESS_JS"]:
|
||||
return installs.pop(0)
|
||||
writes.append(expression)
|
||||
return self.present
|
||||
helper = LIVE["Helper"]("/steam", 0)
|
||||
helper.page = Page()
|
||||
helper.sync_controls()
|
||||
self.assertIsNone(helper.controls_state)
|
||||
self.assertFalse(writes)
|
||||
helper.sync_controls()
|
||||
helper.sync_controls()
|
||||
self.assertEqual(len(calls), 2)
|
||||
self.assertEqual(len(writes), 1)
|
||||
self.assertEqual(calls[1], ("Runtime.addBinding", {"name": LIVE["BRIGHTNESS_BINDING"]}))
|
||||
helper.page.present = False
|
||||
Path(directory, "state.json").write_text(json.dumps({"brightness": 0.7, "revision": 2}))
|
||||
helper.sync_controls()
|
||||
self.assertIsNone(helper.controls_state)
|
||||
self.assertFalse(helper.controls_installed)
|
||||
helper.page.present = True
|
||||
helper.sync_controls()
|
||||
self.assertEqual(len(calls), 3)
|
||||
self.assertEqual(helper.controls_state["brightness"], 0.7)
|
||||
finally:
|
||||
globals_["CONTROLS_DIR"] = previous
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -47,6 +47,8 @@ elif a[:1] == ["shell"]:
|
||||
s.setdefault("log_commands", []).append(a)
|
||||
p.write_text(json.dumps(s))
|
||||
if "ls" in a: print(s["session"])
|
||||
elif a[-1].endswith("/device.txt"): print(s.get("report", ""))
|
||||
elif a[-1].endswith("/app.log"): print(s.get("app_log", ""))
|
||||
else: print("package not debuggable")
|
||||
'''
|
||||
|
||||
@@ -112,6 +114,16 @@ class DeviceSmokeTest(unittest.TestCase):
|
||||
self.assertEqual(1, result.returncode, result.stdout)
|
||||
self.assertIn("could not launch", result.stdout)
|
||||
|
||||
def test_fast_path_requires_a_session_activation_log(self):
|
||||
for active in (False, True):
|
||||
with self.subTest(active=active):
|
||||
result, _ = self.run_smoke(
|
||||
session="session", report="proot fast path (eligible) true",
|
||||
app_log="proot: fast path on (66 binds)" if active else "proot: fast path off - too many binds",
|
||||
)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertEqual(active, "PASS proot fast path was on" in result.stdout)
|
||||
|
||||
def test_session_name_remains_one_remote_argument(self):
|
||||
session = "x';id;#"
|
||||
result, state = self.run_smoke(session=session)
|
||||
|
||||
@@ -48,6 +48,8 @@ class FexTestCase(unittest.TestCase):
|
||||
"HOST_PRELOAD": str(self.tmp / "ld.so.preload"),
|
||||
"DEVICE_FONTS": str(self.tmp / "android-fonts"),
|
||||
"FONT_RULES": str(self.tmp / "66-droiddeck-device-fonts.conf"),
|
||||
"OWN_FEX": str(self.tmp / "own"),
|
||||
"OWN_FEX_TAG": str(self.tmp / "own/share/fex-emu/.droiddeck-tag"),
|
||||
}
|
||||
patcher = mock.patch.dict(G, patches)
|
||||
patcher.start()
|
||||
@@ -202,6 +204,75 @@ class LocateTest(FexTestCase):
|
||||
self.assertEqual((fex["bin"], fex["server"], fex["portable"]), (str(tool / "usr/bin/FEX"), str(tool / "usr/bin/FEXServer"), True))
|
||||
self.assertTrue(fex["host_thunks"].endswith("HostThunks") and fex["guest_thunks"].endswith("GuestThunks") and fex["thunks_db"])
|
||||
|
||||
def own_fex(self, tag, loads=True):
|
||||
own = self.tmp / "own"
|
||||
self.write(own / "bin/FEX", mode=0o755)
|
||||
self.write(own / "bin/FEXServer", mode=0o755)
|
||||
self.write(own / "share/fex-emu/.droiddeck-tag", tag + "\n")
|
||||
listing = b"libc.so.6 => /usr/lib/libc.so.6\n" if loads else b"libxxhash.so.0 => not found\n"
|
||||
patcher = mock.patch.object(G["subprocess"], "run", lambda args, **kw: subprocess.CompletedProcess(args, 0, listing))
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
return own
|
||||
|
||||
def test_an_own_build_that_no_longer_loads_is_installed_again_and_skipped(self):
|
||||
tool = self.fex_tool(self.steam)
|
||||
self.own_fex("fex-2610-r7", loads=False)
|
||||
calls = []
|
||||
with mock.patch.dict(os.environ, {"BL_FEX_TAG": "fex-2610-r7"}), \
|
||||
mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(args) or 1):
|
||||
FEX["update_own_fex"]()
|
||||
self.assertEqual([[str(BIN / "droiddeck-fex-update")]], calls)
|
||||
self.assertEqual(FEX["fex_install"]()["bin"], str(tool / "usr/bin/FEX"))
|
||||
|
||||
def test_droiddeck_s_own_build_comes_before_the_steam_tool(self):
|
||||
self.fex_tool(self.steam)
|
||||
own = self.own_fex("fex-2610-r7")
|
||||
fex = FEX["fex_install"]()
|
||||
self.assertEqual((fex["bin"], fex["server"], fex["portable"]), (str(own / "bin/FEX"), str(own / "bin/FEXServer"), False))
|
||||
|
||||
def test_the_build_the_session_names_is_installed_once(self):
|
||||
self.own_fex("fex-2610-r6")
|
||||
calls = []
|
||||
with mock.patch.dict(os.environ, {"BL_FEX_TAG": "fex-2610-r7"}), \
|
||||
mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(args) or 0):
|
||||
FEX["update_own_fex"]()
|
||||
self.write(self.tmp / "own/share/fex-emu/.droiddeck-tag", "fex-2610-r7\n")
|
||||
FEX["update_own_fex"]()
|
||||
self.assertEqual([[str(BIN / "droiddeck-fex-update")]], calls)
|
||||
|
||||
def test_a_failed_build_waits_an_hour_unless_the_session_names_another(self):
|
||||
self.own_fex("fex-2610-r6")
|
||||
Path(G["STATE"]).mkdir(parents=True, exist_ok=True)
|
||||
calls = []
|
||||
tag = {"BL_FEX_TAG": "fex-2610-r7"}
|
||||
with mock.patch.dict(os.environ, tag), \
|
||||
mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(os.environ["BL_FEX_TAG"]) or 1):
|
||||
FEX["update_own_fex"]()
|
||||
FEX["update_own_fex"]()
|
||||
failed = Path(G["STATE"]) / "update-failed"
|
||||
os.utime(failed, (failed.stat().st_atime, failed.stat().st_mtime - 3601))
|
||||
FEX["update_own_fex"]()
|
||||
os.environ["BL_FEX_TAG"] = "fex-2610-r8"
|
||||
FEX["update_own_fex"]()
|
||||
self.assertEqual(["fex-2610-r7", "fex-2610-r7", "fex-2610-r8"], calls)
|
||||
|
||||
def test_a_missing_updater_falls_back_to_the_fex_already_here(self):
|
||||
self.fex_tool(self.steam)
|
||||
Path(G["STATE"]).mkdir(parents=True, exist_ok=True)
|
||||
with mock.patch.dict(os.environ, {"BL_FEX_TAG": "fex-2610-r7"}), \
|
||||
mock.patch.object(G["subprocess"], "call", mock.Mock(side_effect=FileNotFoundError)):
|
||||
FEX["update_own_fex"]()
|
||||
self.assertEqual(FEX["fex_install"]()["bin"], str(self.steam / "steamapps/common/FEX-Emu/usr/bin/FEX"))
|
||||
|
||||
def test_no_build_is_installed_without_one_from_the_session(self):
|
||||
calls = []
|
||||
with mock.patch.dict(os.environ, {}, clear=False), \
|
||||
mock.patch.object(G["subprocess"], "call", lambda args, **kw: calls.append(args) or 0):
|
||||
os.environ.pop("BL_FEX_TAG", None)
|
||||
FEX["update_own_fex"]()
|
||||
self.assertEqual([], calls)
|
||||
|
||||
def test_library_folders_are_read(self):
|
||||
other = self.tmp / "other"
|
||||
(other / "steamapps/common").mkdir(parents=True)
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import json
|
||||
import runpy
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
|
||||
TOOL = COMPAT["TOOL"]
|
||||
OLD = {"name": "DroidDeck-Proton-11-11.2", "display": "DroidDeck-Proton 11-11.2", "dir": "DroidDeck-Proton 11-11.2", "valve": False}
|
||||
NEW = {"name": "DroidDeck-Proton-11-11.4", "display": "DroidDeck-Proton 11-11.4", "dir": "DroidDeck-Proton 11-11.4", "valve": False}
|
||||
VALVE = {"name": TOOL, "display": "Proton Experimental ARM64", "dir": "Proton - Experimental (ARM64)", "valve": True}
|
||||
GE = {"name": "GE-Proton11-7", "display": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False}
|
||||
|
||||
|
||||
def config_text(entries):
|
||||
mapping = "".join('"%s" { "name" "%s" "config" "" "priority" "%s" }' % (app, name, "75" if app == "0" else "250") for app, name in entries)
|
||||
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
|
||||
|
||||
|
||||
class DroidDeckProtonDefaultTest(unittest.TestCase):
|
||||
def run_default(self, state, mapping, catalog, apps=(), request=None, settle=True):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
directory = Path(tmp)
|
||||
(directory / "state.json").write_text(json.dumps(state))
|
||||
if request is not None:
|
||||
(directory / "request.json").write_text(json.dumps(request))
|
||||
config = directory / "config.vdf"
|
||||
config.write_text(config_text(mapping))
|
||||
default = COMPAT["register_default"](str(config), list(apps), catalog=catalog, directory=str(directory), settle=settle)
|
||||
return default, COMPAT["read_config_mapping"](str(config)), json.loads((directory / "state.json").read_text())
|
||||
|
||||
def test_a_replacement_seen_while_steam_runs_still_moves_the_default_later(self):
|
||||
_, mapping, state = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "tools": [VALVE, OLD]}, [("0", OLD["name"])], [VALVE, NEW], settle=False)
|
||||
self.assertEqual(state["tools"], [VALVE, NEW])
|
||||
self.assertIn(OLD["name"], state["own_builds"])
|
||||
default, mapping, state = self.run_default(state, [("0", OLD["name"])], [VALVE, NEW])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"]})
|
||||
|
||||
def test_a_valve_default_picked_in_steam_after_a_replacement_is_kept(self):
|
||||
default, mapping, _ = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "tools": [VALVE, OLD]}, [("0", TOOL)], [VALVE, NEW])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
|
||||
def test_the_first_start_with_droiddeck_proton_makes_it_the_default_for_following_titles(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": TOOL, "auto": {"42": TOOL}}, [("0", TOOL), ("42", TOOL), ("43", TOOL)], [VALVE, NEW], ["42", "43"])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"], "42": NEW["name"], "43": TOOL})
|
||||
self.assertEqual(state["default"], NEW["name"])
|
||||
self.assertTrue(state["own_proton"])
|
||||
|
||||
def test_a_default_picked_after_the_switch_is_kept(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": NEW["name"], "own_proton": True, "applied": 1, "tools": [VALVE, NEW]},
|
||||
[("0", NEW["name"])], [VALVE, NEW], request={"seq": 2, "valve": True, "dir": VALVE["dir"]})
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": TOOL, "own_proton": True, "tools": [VALVE, NEW]}, [("0", TOOL)], [VALVE, NEW])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
|
||||
def test_a_replaced_build_moves_its_default_and_titles_to_the_newest(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "auto": {"42": OLD["name"]}, "tools": [VALVE, OLD, GE]},
|
||||
[("0", OLD["name"]), ("42", OLD["name"]), ("43", OLD["name"]), ("44", GE["name"]), ("45", TOOL)],
|
||||
[VALVE, NEW, GE], ["42", "43", "44", "45"])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"], "42": NEW["name"], "43": NEW["name"], "44": GE["name"], "45": TOOL})
|
||||
self.assertEqual(state["auto"], {"42": NEW["name"]})
|
||||
|
||||
def test_a_replaced_build_does_not_override_a_valve_default(self):
|
||||
default, mapping, _ = self.run_default(
|
||||
{"default": TOOL, "own_proton": True, "tools": [VALVE, OLD]}, [("0", TOOL), ("43", OLD["name"])], [VALVE, NEW], ["43"])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL, "43": NEW["name"]})
|
||||
|
||||
def test_nothing_changes_without_droiddeck_proton(self):
|
||||
default, mapping, state = self.run_default({"default": TOOL}, [("0", TOOL)], [VALVE, GE])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
self.assertNotIn("own_proton", state)
|
||||
|
||||
def test_the_newest_build_is_found_by_version(self):
|
||||
newest, gone = COMPAT["own_proton_moves"]({"tools": [OLD]}, [dict(NEW, name="a", dir="DroidDeck-Proton 11-9.10"), dict(NEW, name="b", dir="DroidDeck-Proton 11-11.1")])
|
||||
self.assertEqual(newest, "b")
|
||||
self.assertEqual(gone, {OLD["name"]})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -413,6 +413,21 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual("Awake", out["wakefulness"])
|
||||
self.assertIn(["shell", "input", "keyevent", "KEYCODE_WAKEUP"], [c["args"] for c in self.calls()])
|
||||
|
||||
def test_proot_profile_queues_only_the_next_session(self):
|
||||
self.configure({"env": {"ok": True}})
|
||||
code, out = self.run_ctl("proot-profile", "enable", "--slow-us", "250")
|
||||
self.assertEqual(0, code, out)
|
||||
self.assertEqual({"op": "set", "lines": ["PROOT_PROFILE=1", "PROOT_PROFILE_SLOW_US=250"], "persistent": False},
|
||||
self.calls("env")[0]["request"])
|
||||
|
||||
def test_proot_profile_report_needs_no_adb_or_device(self):
|
||||
path = self.dir / "session.log"
|
||||
path.write_text('ordinary log')
|
||||
with unittest.mock.patch.object(ctl, "adb_path", side_effect=AssertionError("must stay offline")):
|
||||
code, out = self.run_ctl("proot-profile", "report", str(path))
|
||||
self.assertEqual(0, code, out)
|
||||
self.assertFalse(out["hasCounters"])
|
||||
|
||||
def test_override_pushes_to_the_inbox_first(self):
|
||||
self.configure({
|
||||
"access": {"ok": True, "commands": True, "inbox": "/sdcard/Android/data/x/files/agent-inbox"},
|
||||
|
||||
@@ -6,7 +6,7 @@ import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64"
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-fex-update"
|
||||
SOURCE = SCRIPT.read_text()
|
||||
START = SOURCE.index("fex_install() {")
|
||||
END = SOURCE.index("\n}\n", START) + 3
|
||||
|
||||
@@ -5,9 +5,9 @@ import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64"
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-fex-update"
|
||||
SOURCE = SCRIPT.read_text()
|
||||
START = SOURCE.index("x64_fex() {")
|
||||
START = SOURCE.index("fex_ready() {")
|
||||
END = SOURCE.index("\n}\n", START) + 3
|
||||
X64_FEX = SOURCE[START:END]
|
||||
|
||||
@@ -35,7 +35,7 @@ class FexSelectTest(unittest.TestCase):
|
||||
fex.chmod(0o755)
|
||||
body = (X64_FEX.replace("/usr/local/share/fex-emu/.droiddeck-tag", "$ROOT/tag")
|
||||
.replace("/usr/local/bin/FEX", "$ROOT/FEX"))
|
||||
script = HARNESS + body + 'if x64_fex; then echo "NOW $FEX_NOW|$FEX_FROM"; else echo FAILED; fi\n'
|
||||
script = HARNESS + body + 'if fex_ready; then echo "NOW $FEX_NOW|$FEX_FROM"; else echo FAILED; fi\n'
|
||||
env = dict(os.environ, ROOT=root, LOADS="1" if loads else "0", INSTALLABLE=" ".join(installable))
|
||||
env.pop("BL_FEX_TAG", None)
|
||||
if catalog:
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import contextlib
|
||||
import fcntl
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup"
|
||||
|
||||
|
||||
class FlatpakSetupTest(unittest.TestCase):
|
||||
def run_setup(self, uid, pacman, locked=False, busy=False):
|
||||
with tempfile.TemporaryDirectory() as directory, contextlib.ExitStack() as held:
|
||||
root = Path(directory)
|
||||
if locked:
|
||||
(root / "work/db").mkdir(parents=True)
|
||||
(root / "work/db/db.lck").write_text("")
|
||||
if busy:
|
||||
holder = held.enter_context(open(root / "work/setup.lock", "w"))
|
||||
fcntl.flock(holder, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
bin_dir = root / "bin"
|
||||
bin_dir.mkdir()
|
||||
stubs = {"id": "echo %d" % uid, "curl": "exit 7", "pacman": pacman, "pacman-key": "exit 0"}
|
||||
for name, body in stubs.items():
|
||||
(bin_dir / name).write_text("#!/bin/sh\n%s\n" % body)
|
||||
(bin_dir / name).chmod(0o755)
|
||||
script = root / "setup"
|
||||
script.write_text(SCRIPT.read_text().replace("WORK=/var/cache/droiddeck-flatpak", "WORK=%s/work" % root)
|
||||
.replace("/etc/pacman.d/gnupg/pubring.gpg", str(root / "pubring.gpg"))
|
||||
.replace(" /etc/pacman.conf >", " %s >" % (root / "pacman.conf")))
|
||||
(root / "pacman.conf").write_text("[options]\n[core]\nInclude = /etc/pacman.d/mirrorlist\n")
|
||||
(root / "pubring.gpg").write_text("")
|
||||
env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ["PATH"]))
|
||||
result = subprocess.run(["bash", str(script)], env=env, capture_output=True, text=True, timeout=30)
|
||||
return result.returncode, result.stdout
|
||||
|
||||
def test_a_manual_run_without_root_says_so(self):
|
||||
code, out = self.run_setup(1000, "exit 0")
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("== FAIL needs root", out)
|
||||
self.assertNotIn("Reading the package lists", out)
|
||||
|
||||
def test_an_unreachable_mirror_reports_pacmans_error(self):
|
||||
code, out = self.run_setup(0, "echo \"error: failed retrieving file 'core.db' : Could not resolve host\" >&2; exit 1")
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("== FAIL could not reach the Arch Linux ARM mirrors (error: failed retrieving file 'core.db' : "
|
||||
"Could not resolve host)", out)
|
||||
|
||||
SYNC = ("db=; while [ $# -gt 0 ]; do [ \"$1\" = --dbpath ] && db=$2; shift; done\n"
|
||||
"[ -e \"$db/db.lck\" ] && { echo 'error: failed to synchronize all databases (unable to lock database)' >&2; exit 1; }\n"
|
||||
"mkdir -p \"$db/sync\" && touch \"$db/sync/extra.db\"")
|
||||
|
||||
def test_a_lock_left_by_an_interrupted_run_is_cleared(self):
|
||||
code, out = self.run_setup(0, self.SYNC, locked=True)
|
||||
self.assertNotIn("unable to lock database", out)
|
||||
self.assertIn("== STEP Downloading Flatpak", out)
|
||||
|
||||
def test_a_setup_that_is_still_running_keeps_its_lock(self):
|
||||
code, out = self.run_setup(0, self.SYNC, locked=True, busy=True)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("== FAIL another Flatpak setup is still running", out)
|
||||
self.assertNotIn("Reading the package lists", out)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,139 @@
|
||||
"""The Quick Access Frame Limit follows the panel when its refresh rate changes."""
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat"))
|
||||
|
||||
HARNESS = r"""
|
||||
const assert = require('assert');
|
||||
globalThis.window = globalThis;
|
||||
globalThis.btoa = text => Buffer.from(text, 'binary').toString('base64');
|
||||
let timers = new Map(), nextTimer = 0;
|
||||
globalThis.setTimeout = (callback, ms) => { timers.set(++nextTimer, callback); return nextTimer; };
|
||||
globalThis.clearTimeout = id => timers.delete(id);
|
||||
globalThis.setInterval = () => 0;
|
||||
const fire = async () => {
|
||||
const pending = [...timers.values()]; timers = new Map();
|
||||
for (const callback of pending) await callback();
|
||||
};
|
||||
let rates = [36, 48, 72, 144];
|
||||
const notify = [];
|
||||
const service = {
|
||||
GetState: async () => ({ BSuccess: () => true,
|
||||
Body: () => ({ toObject: () => ({ state: { active_display_info: { supported_frame_rates: rates } } }) }) }),
|
||||
RegisterForNotifyStateChanged(callback) { notify.push(callback); return {}; },
|
||||
SetBlurParams() {},
|
||||
};
|
||||
const writes = [];
|
||||
globalThis.settingsStore = { clientSettings: {
|
||||
gamescope_enable_app_target_framerate: true, gamescope_app_target_framerate: 120, gamescope_disable_framelimit: false } };
|
||||
const varints = bytes => { const out = []; let value = 0, shift = 0;
|
||||
for (const b of bytes) { value += (b & 127) * 2 ** shift; shift += 7; if (b < 128) { out.push(value); value = 0; shift = 0; } }
|
||||
return out; };
|
||||
globalThis.SteamClient = { Settings: { SetSetting(encoded) {
|
||||
const [key, value] = varints([...Buffer.from(encoded, 'base64')]);
|
||||
assert.strictEqual(key, 21002 * 8);
|
||||
writes.push(value);
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = value;
|
||||
} } };
|
||||
const modules = {
|
||||
1: { source: () => 'RegisterForNotifyStateChanged only', exports: { other: { GetState() {} } } },
|
||||
2: { source: () => 'n.MX.SetBlurParams(); n.MX.RegisterForNotifyStateChanged()', exports: { hooks: () => {} } },
|
||||
3: { source: () => 'SetBlurParams RegisterForNotifyStateChanged GetState', exports: { MX: service } },
|
||||
};
|
||||
const webpack = modules => { const require = id => modules[id].exports;
|
||||
require.m = Object.fromEntries(Object.entries(modules).map(([id, m]) => [id, { toString: m.source }]));
|
||||
return require; };
|
||||
globalThis.webpackChunksteamui = { push([, , callback]) { callback(webpack(modules)); } };
|
||||
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
const change = async next => { rates = next; notify.forEach(callback => callback()); };
|
||||
(async () => {
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144], 'a remembered limit the panel does not offer moves to the highest value');
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144], 'unchanged choices are not written again');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], '72 is not offered at 120 Hz');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 60;
|
||||
await change([12, 15, 20, 30, 60]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], '60 is still offered at 60 Hz and is kept');
|
||||
await change([18, 24, 36, 72]);
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], 'a passing rate during a mode switch is not acted on');
|
||||
settingsStore.clientSettings.gamescope_enable_app_target_framerate = false;
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
await change([36, 48, 144]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], 'nothing changes while Steam has the frame limit turned off');
|
||||
settingsStore.clientSettings.gamescope_enable_app_target_framerate = true;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144], 'turning the limit on after a rate change moves an unoffered value');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
const setSetting = SteamClient.Settings.SetSetting;
|
||||
SteamClient.Settings.SetSetting = () => { throw new Error('busy'); };
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
SteamClient.Settings.SetSetting = setSetting;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144, 144], 'a failed write is tried again on the next check');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
SteamClient.Settings.SetSetting = () => Promise.reject(new Error('busy'));
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
SteamClient.Settings.SetSetting = setSetting;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144, 144, 144], 'a rejected write is caught and tried again');
|
||||
delete window.__droiddeckFrameLimit;
|
||||
webpackChunksteamui.push = ([, , callback]) => callback(webpack({ 1: modules[1], 2: modules[2] }));
|
||||
assert.strictEqual(eval(script), 'unavailable');
|
||||
})().catch(error => { console.error(error); process.exit(1); });
|
||||
"""
|
||||
|
||||
|
||||
class FrameLimitSyncTest(unittest.TestCase):
|
||||
def test_limit_is_kept_when_offered_and_moved_to_the_highest_value_otherwise(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
script = Path(directory) / "frame_limit.js"
|
||||
script.write_text(LIVE["FRAME_LIMIT_JS"])
|
||||
test = Path(directory) / "test.js"
|
||||
test.write_text(HARNESS)
|
||||
result = subprocess.run(["node", str(test), str(script)], capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_install_is_retried_until_steam_is_ready_and_reported_once_per_state(self):
|
||||
helper = LIVE["Helper"]("/steam", 0)
|
||||
page = mock.Mock()
|
||||
page.evaluate.side_effect = ["unavailable", "unavailable", "installed"]
|
||||
helper.page = page
|
||||
said = []
|
||||
clock = [100.0]
|
||||
globals_ = LIVE["Helper"].sync_frame_limit.__globals__
|
||||
with mock.patch.dict(globals_, {"say": said.append}), mock.patch.object(globals_["time"], "monotonic", lambda: clock[0]):
|
||||
helper.sync_frame_limit()
|
||||
helper.sync_frame_limit()
|
||||
clock[0] += 10
|
||||
helper.sync_frame_limit()
|
||||
clock[0] += 10
|
||||
helper.sync_frame_limit()
|
||||
clock[0] += 10
|
||||
helper.sync_frame_limit()
|
||||
self.assertEqual(page.evaluate.call_count, 3)
|
||||
self.assertEqual(said, ["frame limit sync: unavailable", "frame limit sync: installed"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,6 +8,7 @@ import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -206,6 +207,35 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
env=env, text=True, capture_output=True, check=True)
|
||||
self.assertEqual(result.stdout.strip(), expected)
|
||||
|
||||
def test_desktop_games_restart_on_the_gpu_with_steams_preloads_handed_back(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
gpu = home / "gpu"
|
||||
gpu.write_text("#!/bin/bash\necho \"gpu LD_PRELOAD=${LD_PRELOAD-unset}\"\nexport BL_DESKTOP_GPU_CHILD=1\nexec \"$@\"\n")
|
||||
gpu.chmod(0o755)
|
||||
launcher = home / "launcher"
|
||||
setup = COMPAT["BL_DESKTOP_GPU_SETUP"].replace("/usr/local/bin/droiddeck-gpu", str(gpu))
|
||||
launcher.write_text("#!/bin/bash\nverb=$1; shift\n" + setup + "echo \"game $verb $* LD_PRELOAD=${LD_PRELOAD-unset} saved=${BL_GPU_SAVED_LD_PRELOAD-unset}\"\n")
|
||||
launcher.chmod(0o755)
|
||||
base = {key: value for key, value in os.environ.items() if not key.startswith("BL_")}
|
||||
base["LD_PRELOAD"] = "overlay.so"
|
||||
for extra, args, expected in (
|
||||
({"BL_DESKTOP": "1"}, ["waitforexitandrun", "game.exe"],
|
||||
["gpu LD_PRELOAD=unset", "game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1", "BL_DESKTOP_GPU": "Off"}, ["waitforexitandrun", "game.exe"],
|
||||
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1"}, ["run", "setup.exe"],
|
||||
["game run setup.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({"BL_DESKTOP": "1"}, ["waitforexitandrun", "iscriptevaluator.exe"],
|
||||
["game waitforexitandrun iscriptevaluator.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
({}, ["waitforexitandrun", "game.exe"],
|
||||
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
||||
):
|
||||
with self.subTest(extra=extra, args=args):
|
||||
result = subprocess.run([str(launcher)] + args, env=dict(base, **extra),
|
||||
text=True, capture_output=True, check=True)
|
||||
self.assertEqual(result.stdout.splitlines(), expected)
|
||||
|
||||
def test_the_install_script_evaluator_gets_its_scripts_marked_first(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
@@ -310,6 +340,14 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertEqual(MODULE["apply_config"](env, config, "42")["TU_DEBUG"], "sysmem")
|
||||
self.assertNotIn("TU_DEBUG", MODULE["apply_config"](env, config, "43"))
|
||||
|
||||
def test_the_vram_cap_comes_before_the_games_own_dxvk_settings(self):
|
||||
cap = MODULE["vram_cap"]
|
||||
self.assertEqual(cap({"BL_VRAM_MB": "4096"})["DXVK_CONFIG"], "dxgi.maxDeviceMemory = 4096")
|
||||
self.assertEqual(cap({"BL_VRAM_MB": "2048", "DXVK_CONFIG": "dxvk.maxFrameRate = 60;"})["DXVK_CONFIG"],
|
||||
"dxgi.maxDeviceMemory = 2048; dxvk.maxFrameRate = 60")
|
||||
for off in ({}, {"BL_VRAM_MB": "0"}, {"BL_VRAM_MB": "lots"}, {"BL_VRAM_MB": "²"}, {"BL_VRAM_MB": "-1"}):
|
||||
self.assertNotIn("DXVK_CONFIG", cap(off))
|
||||
|
||||
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
|
||||
env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"}
|
||||
config = {"version": 1, "games": {"42": {"BL_SYNC": "0", "BL_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "FEX_TSOENABLED": "1"}}}
|
||||
@@ -443,6 +481,13 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertEqual(env["WINEDLLOVERRIDES"], "libsentry.windows.release.x86_64=d")
|
||||
self.assertEqual(extra, ["--rendering-driver", "vulkan"])
|
||||
self.assertEqual(MODULE["engine_fixes"](str(game / "Game.exe"), ["--rendering-driver", "opengl3"])[1], [])
|
||||
script = Path(tmp) / "GDScript Game"
|
||||
script.mkdir()
|
||||
for name in ("Game.exe", "Game.pck", "libsentry.windows.release.x86_64.dll"):
|
||||
(script / name).touch()
|
||||
env, extra, notes = MODULE["engine_fixes"](str(script / "Game.exe"), [])
|
||||
self.assertNotIn("WINEDLLOVERRIDES", env)
|
||||
self.assertEqual(extra, ["--rendering-driver", "vulkan"])
|
||||
other = Path(tmp) / "Other"
|
||||
other.mkdir()
|
||||
(other / "Other.exe").touch()
|
||||
@@ -536,7 +581,95 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
(asylum / name).touch()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(asylum / "BmLauncher.exe"), []), ({}, [], []))
|
||||
|
||||
def test_caravan_sandwitch_and_cyberpunk_run_at_feature_level_12_1(self):
|
||||
def test_d3dgear_capture_hook_beside_the_game_is_turned_off(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
game = Path(tmp) / "The Crew 2"
|
||||
game.mkdir()
|
||||
for name in ("TheCrew2.exe", "TheCrew2_BE.exe", "d3dgear64.dll"):
|
||||
(game / name).touch()
|
||||
env, extra, notes = MODULE["engine_fixes"](str(game / "TheCrew2.exe"), [])
|
||||
self.assertEqual((env, extra), ({"WINEDLLOVERRIDES": "d3dgear64=d"}, []))
|
||||
self.assertTrue(notes)
|
||||
(game / "d3dgear64.dll").rename(game / "D3DGear64.DLL")
|
||||
self.assertEqual(MODULE["engine_fixes"](str(game / "TheCrew2.exe"), [])[0], {"WINEDLLOVERRIDES": "d3dgear64=d"})
|
||||
(game / "D3DGear64.DLL").unlink()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(game / "TheCrew2.exe"), []), ({}, [], []))
|
||||
|
||||
def test_dll_overrides_from_several_fixes_are_all_kept(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
for name in ("Game.exe", "Game.pck", "GodotSharp.dll", "libsentry.windows.release.x86_64.dll", "d3dgear64.dll"):
|
||||
(Path(tmp) / name).touch()
|
||||
env = MODULE["engine_fixes"](str(Path(tmp) / "Game.exe"), [])[0]
|
||||
self.assertEqual(env["WINEDLLOVERRIDES"], "libsentry.windows.release.x86_64=d;d3dgear64=d")
|
||||
|
||||
def test_black_ops_iii_and_dark_souls_remastered_skip_protonfixes(self):
|
||||
for exe in ("/game/Call of Duty Black Ops III/BlackOps3.exe", "/game/DARK SOULS REMASTERED/DarkSoulsRemastered.exe"):
|
||||
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
||||
self.assertEqual((env, extra), ({"PROTONFIXES_DISABLE": "1"}, []))
|
||||
self.assertTrue(notes)
|
||||
self.assertEqual(MODULE["engine_fixes"]("/game/Game/DarkSoulsII.exe", []), ({}, [], []))
|
||||
|
||||
def test_game_cores_are_parsed_from_lists_and_ranges(self):
|
||||
parse = MODULE["parse_cores"]
|
||||
self.assertEqual(parse("0-3,6"), {0, 1, 2, 3, 6})
|
||||
self.assertEqual(parse(" 4, 5 "), {4, 5})
|
||||
for bad in ("", "a", "3-1", "1,,2", "-1", "1-"):
|
||||
self.assertIsNone(parse(bad), bad)
|
||||
|
||||
def test_a_profiles_game_cores_pin_the_game_within_the_online_cores(self):
|
||||
calls = []
|
||||
os_mod = MODULE["os"]
|
||||
with mock.patch.dict(MODULE["game_cores"].__globals__, {"online_cores": lambda: {0, 1, 2, 3, 4, 5, 6, 7}}), \
|
||||
mock.patch.object(os_mod, "sched_setaffinity", side_effect=lambda pid, cores: calls.append(set(cores)), create=True):
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "0-2,9"})
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "junk"})
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "12-13"})
|
||||
MODULE["game_cores"]({})
|
||||
self.assertEqual(calls, [{0, 1, 2}])
|
||||
self.assertEqual(MODULE["parse_cores"]("0,2-7"), {0, 2, 3, 4, 5, 6, 7})
|
||||
|
||||
def test_windows_games_see_only_the_cores_they_are_pinned_to(self):
|
||||
os_mod = MODULE["os"]
|
||||
online = {"online_cores": lambda: {0, 1, 2, 3, 4, 5, 6, 7}}
|
||||
cases = [
|
||||
({"BL_GAME_CPUS": "6,7"}, {6, 7}, "2:6,7", "2:6,7"),
|
||||
({"DROIDDECK_GAME_CORES": "0-2"}, {0, 1, 2}, "3:0,1,2", "3:0,1,2"),
|
||||
({"BL_GAME_CPUS": "0-7"}, set(range(8)), None, None),
|
||||
({}, {6, 7}, None, None),
|
||||
({"BL_GAME_CPUS": "6,7", "WINE_CPU_TOPOLOGY": "4:0,1,2,3"}, {6, 7}, "4:0,1,2,3", "4:0,1,2,3"),
|
||||
({"WINE_CPU_TOPOLOGY": "2:0,1"}, set(range(8)), "2:0,1", "2:0,1"),
|
||||
({"BL_GAME_CPUS": "6,7", "WINE_CPU_TOPOLOGY": ""}, {6, 7}, "", None),
|
||||
({"BL_GAME_CPUS": "6,7", "PROTON_CPU_TOPOLOGY": "1:7"}, {6, 7}, None, "1:7"),
|
||||
({"BL_GAME_CPUS": "9"}, {9}, None, None),
|
||||
]
|
||||
for env, affinity, expected, proton in cases:
|
||||
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_reskate_runs_at_feature_level_12_1(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
reskate = Path(tmp) / "ReSkate"
|
||||
reskate.mkdir()
|
||||
for name in ("Skate.exe", "ReSkate.dll", "ReSkateLauncher.exe", "EAAntiCheat.GameServiceLauncher.exe"):
|
||||
(reskate / name).touch()
|
||||
for exe in ("ReSkateLauncher.exe", "Skate.exe"):
|
||||
env, extra, notes = MODULE["engine_fixes"](str(reskate / exe), [])
|
||||
self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": "12_1"}, []), exe)
|
||||
self.assertTrue(notes)
|
||||
config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "3354750", env)["VKD3D_FEATURE_LEVEL"], "12_1")
|
||||
config["games"] = {"3354750": {"VKD3D_FEATURE_LEVEL": "12_2"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "3354750", env)["VKD3D_FEATURE_LEVEL"], "12_2")
|
||||
skate = Path(tmp) / "Skate"
|
||||
skate.mkdir()
|
||||
for name in ("Skate.exe", "EAAntiCheat.GameServiceLauncher.exe"):
|
||||
(skate / name).touch()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(skate / "EAAntiCheat.GameServiceLauncher.exe"), [])[:2], ({}, []))
|
||||
|
||||
def test_caravan_sandwitch_robocop_and_cyberpunk_run_at_feature_level_12_1(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
caravan = Path(tmp) / "Caravan SandWitch"
|
||||
shipping = caravan / "CaravanSandWitch/Binaries/Win64"
|
||||
@@ -548,8 +681,13 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
(cyberpunk / "bin/x64").mkdir(parents=True)
|
||||
for name in ("REDprelauncher.exe", "bin/x64/Cyberpunk2077.exe"):
|
||||
(cyberpunk / name).touch()
|
||||
robocop = Path(tmp) / "RoboCop Rogue City"
|
||||
(robocop / "RoboCop/Binaries/Win64").mkdir(parents=True)
|
||||
for name in ("RoboCop.exe", "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe"):
|
||||
(robocop / name).touch()
|
||||
games = [caravan / "CaravanSandWitch.exe", caravan / ".droiddeck-launch.bat",
|
||||
shipping / "CaravanSandWitch-Win64-Shipping.exe",
|
||||
robocop / "RoboCop.exe", robocop / "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe",
|
||||
cyberpunk / "REDprelauncher.exe", cyberpunk / "bin/x64/Cyberpunk2077.exe"]
|
||||
for exe in games:
|
||||
env, extra, notes = MODULE["engine_fixes"](str(exe), [])
|
||||
|
||||
@@ -65,7 +65,7 @@ class DesktopGamescopeBackendTest(unittest.TestCase):
|
||||
for name in ("BL_GAMESCOPE_BACKEND", "BL_DEBUG_DIR", "BL_FPS", "BL_REFRESH", "BL_HDR"):
|
||||
env.pop(name, None)
|
||||
env.update(PATH=f"{root}{os.pathsep}{env.get('PATH', '')}",
|
||||
GAMESCOPE_CAPTURE=str(capture), WAYLAND_DISPLAY="desktop-0",
|
||||
GAMESCOPE_CAPTURE=str(capture), WAYLAND_DISPLAY="desktop-0", BL_DESKTOP_GPU_WINDOW="0",
|
||||
SDL_VIDEODRIVER="dummy", GDK_BACKEND="wayland", QT_QPA_PLATFORM="wayland")
|
||||
if backend is not None:
|
||||
env["BL_GAMESCOPE_BACKEND"] = backend
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
from proot_profile import report
|
||||
|
||||
PROGRAM = r'''
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#define PR_NB_SYSNUM 2
|
||||
#define PR_void 0
|
||||
static const char *stringify_sysnum(unsigned nr) { return nr ? "openat" : "void"; }
|
||||
#include "profile.h"
|
||||
int main(void) {
|
||||
errno = EBUSY;
|
||||
if (!dd_profile_enabled()) return errno != EBUSY;
|
||||
if (errno != EBUSY) return 1;
|
||||
for (int i = 0; i < 40; i++) {
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
struct timespec wait = {0, 2000000};
|
||||
nanosleep(&wait, 0);
|
||||
errno = ENOENT;
|
||||
dd_profile_record(1, 1, 123, wall, cpu);
|
||||
if (errno != ENOENT) return 2;
|
||||
if (i == 9) dd_profile_flush();
|
||||
}
|
||||
dd_profile_next = 0;
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
struct timespec wait = {0, 2000000};
|
||||
nanosleep(&wait, 0);
|
||||
dd_profile_record(1, 0, 123, wall, cpu);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ProotProfileTest(unittest.TestCase):
|
||||
def test_snapshots_replace_instead_of_adding_and_tracers_remain_separate(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
path = Path(work) / 'session.log'
|
||||
records = [dict(type='total', tracer=1, id=2, syscall='statx', stage='enter',
|
||||
calls=n, wall_ns=n * 100, cpu_ns=n * 10, max_ns=100) for n in (3, 8)]
|
||||
records.append(dict(records[-1], tracer=2, calls=2))
|
||||
records += [dict(type='total', tracer=1, id=3, syscall='openat', stage='enter',
|
||||
calls=1, wall_ns=1000, cpu_ns=1000, max_ns=1000)]
|
||||
path.write_text('unrelated log\n' + ''.join('prefix proot-profile ' + json.dumps(r) + '\n' for r in records)
|
||||
+ 'proot-profile {truncated\n' + 'proot-profile []\n')
|
||||
result = report(path)
|
||||
self.assertEqual(11, result['handlerCalls'])
|
||||
self.assertEqual(3, result['tracers'])
|
||||
self.assertEqual(2, result['malformedRecords'])
|
||||
self.assertEqual('statx', result['totals'][0]['syscall'])
|
||||
self.assertEqual('openat', report(path, 'cpu')['totals'][0]['syscall'])
|
||||
|
||||
def test_empty_logs_do_not_claim_profiling_ran(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
path = Path(work) / 'session.log'
|
||||
path.write_text('ordinary log\n')
|
||||
self.assertFalse(report(path)['hasCounters'])
|
||||
|
||||
@unittest.skipUnless(shutil.which('cc'), 'C compiler required')
|
||||
def test_real_clocks_bounded_samples_errno_and_periodic_counters(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
source = Path(work) / 'profile.c'
|
||||
binary = Path(work) / 'profile'
|
||||
source.write_text(PROGRAM)
|
||||
subprocess.run(['cc', '-Wall', '-Wextra', '-Werror', '-std=c99', '-I', str(TOOLS / 'proot'),
|
||||
str(source), '-o', str(binary)], check=True)
|
||||
for setting in ('0', ''):
|
||||
result = subprocess.run([binary], env=dict(os.environ, PROOT_PROFILE=setting), capture_output=True, check=True)
|
||||
self.assertEqual(b'', result.stderr)
|
||||
result = subprocess.run([binary], env=dict(os.environ, PROOT_PROFILE='1', PROOT_PROFILE_SLOW_US='1'),
|
||||
capture_output=True, check=True)
|
||||
rows = [json.loads(line.split(b'proot-profile ', 1)[1]) for line in result.stderr.splitlines()]
|
||||
self.assertEqual(33, sum(row['type'] == 'slow' for row in rows))
|
||||
self.assertEqual(32, sum(row['type'] == 'slow' and row['stage'] == 'enter' for row in rows))
|
||||
self.assertGreater(sum(row['type'] == 'total' for row in rows), 2)
|
||||
log = Path(work) / 'session.log'
|
||||
log.write_bytes(result.stderr)
|
||||
counters = report(log)
|
||||
self.assertEqual(41, counters['handlerCalls'])
|
||||
self.assertGreater(counters['handlerWallNs'], counters['handlerCpuNs'])
|
||||
self.assertEqual(40, counters['totals'][0]['calls'])
|
||||
@@ -22,7 +22,7 @@ PACKAGES = [line.split()[1] for line in VARIANTS.read_text().splitlines()
|
||||
def guest_prefix(package):
|
||||
source = SERVICE.read_text()
|
||||
before_environment = source.split("val guest = ArrayList<String>()", 1)[1].split(
|
||||
"addClientEnvironment(guest, steamHere)", 1)[0]
|
||||
"addClientEnvironment(guest,", 1)[0]
|
||||
environment = source.split("private fun addClientEnvironment(", 1)[1].split(
|
||||
'guest.add("HOME=/root")', 1)[0]
|
||||
prefix = []
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"""Steam owns game caps; the nested compositor follows the output refresh rate."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session'
|
||||
|
||||
|
||||
class SessionPacingTest(unittest.TestCase):
|
||||
def launch(self, refresh, **overrides):
|
||||
source = SESSION.read_text()
|
||||
start = source.index(' width=${BL_WIDTH:-1280}')
|
||||
end = source.index('\nfi\n\nbl_displays()', start)
|
||||
block = source[start:end].replace('/usr/local/bin/droiddeck-pipewire', 'pipewire_stub')
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
env = dict(os.environ, XDG_RUNTIME_DIR=directory, BL_REFRESH=str(refresh),
|
||||
BL_MANGOAPP='0', BL_FPS='0', DROIDDECK_GAME_FRAME_LIMIT='0')
|
||||
env.pop('GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST', None)
|
||||
env.update(overrides)
|
||||
script = '''
|
||||
set -u
|
||||
mode=steam
|
||||
pipewire_stub() { return 1; }
|
||||
run_gamescope() { printf 'ARG:%s\\n' "$@"; printf 'FOLLOW:%s\\n' "${GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST:-}"; }
|
||||
''' + block
|
||||
result = subprocess.run(['bash', '-c', script], env=env, capture_output=True,
|
||||
text=True, timeout=5)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.follow = [line.removeprefix('FOLLOW:') for line in result.stdout.splitlines()
|
||||
if line.startswith('FOLLOW:')]
|
||||
return [line.removeprefix('ARG:') for line in result.stdout.splitlines()
|
||||
if line.startswith('ARG:')]
|
||||
|
||||
def test_display_refresh_sets_the_nested_compositor_rate(self):
|
||||
for refresh in (60, 90, 120):
|
||||
with self.subTest(refresh=refresh):
|
||||
args = self.launch(refresh)
|
||||
self.assertEqual(str(refresh), args[args.index('-r') + 1])
|
||||
self.assertIn('-e', args)
|
||||
|
||||
def test_gamescope_follows_the_panel_after_the_starting_rate(self):
|
||||
self.launch(144)
|
||||
self.assertEqual(['1'], self.follow)
|
||||
self.launch(0)
|
||||
self.assertEqual([''], self.follow)
|
||||
|
||||
def test_retired_cap_variables_do_not_override_the_display_rate(self):
|
||||
for performance in ('0', '1'):
|
||||
with self.subTest(performance=performance):
|
||||
args = self.launch(120, BL_FPS='30', DROIDDECK_GAME_FRAME_LIMIT=performance)
|
||||
self.assertEqual('120', args[args.index('-r') + 1])
|
||||
self.assertNotIn('--framerate-limit', args)
|
||||
|
||||
def test_retired_cap_cannot_set_the_rate_when_the_display_rate_is_unknown(self):
|
||||
args = self.launch(0, BL_FPS='30', DROIDDECK_GAME_FRAME_LIMIT='1')
|
||||
self.assertNotIn('-r', args)
|
||||
self.assertNotIn('--framerate-limit', args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -69,6 +69,44 @@ class SteamCompatEnvironmentTest(unittest.TestCase):
|
||||
os.kill(helper_pid, 9)
|
||||
self.fail('droiddeck-steam-compat outlived the session')
|
||||
|
||||
def test_the_x86_64_client_gets_only_the_file_dialog_bridge(self):
|
||||
source = (BIN / 'droiddeck-session').read_text()
|
||||
start = source.index(' if [ "$steam_x64" = 1 ]; then\n { droiddeck-steam-compat --files-only')
|
||||
block = source[start:source.index(' fi\n', start) + len(' fi\n')]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
helper = root / 'droiddeck-steam-compat'
|
||||
helper.write_text('#!/bin/sh\necho "$@" >> "$ARGS_FILE"\n')
|
||||
helper.chmod(0o755)
|
||||
for x64, expected in (('1', '--files-only /steam'), ('0', '/steam')):
|
||||
with self.subTest(x64=x64):
|
||||
args = root / ('args-' + x64)
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
ARGS_FILE=str(args), steam_root='/steam', steam_x64=x64)
|
||||
subprocess.run(['bash', '-c', '_bl_compat_env=(env)\n' + block + 'wait\n'], env=env, timeout=10, check=True)
|
||||
self.assertEqual(args.read_text().split('\n')[0], expected)
|
||||
|
||||
def test_files_only_mode_installs_only_the_file_dialog_hook(self):
|
||||
import runpy
|
||||
compat = runpy.run_path(str(BIN / 'droiddeck-steam-compat'))
|
||||
calls = []
|
||||
|
||||
class Page:
|
||||
def __init__(self, port, path):
|
||||
self.ws = None
|
||||
def evaluate(self, expression):
|
||||
calls.append(('evaluate', expression[:40]))
|
||||
return True
|
||||
def call(self, method, params):
|
||||
calls.append((method, params['name']))
|
||||
|
||||
helper = compat['Helper']('/steam', 1234, files_only=True)
|
||||
helper.attach.__globals__.update(shared_context=lambda port: '/devtools/page/1', Page=Page)
|
||||
self.assertTrue(helper.attach())
|
||||
bindings = [name for method, name in calls if method == 'Runtime.addBinding']
|
||||
self.assertEqual(bindings, [compat['FILE_BINDING']])
|
||||
self.assertIn(('evaluate', compat['FILE_JS'][:40]), calls)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -277,11 +277,40 @@ class CloudHooks(unittest.TestCase):
|
||||
for sh in (compat.LAUNCHER_SH, compat.EXTRA_WRAPPER_SH):
|
||||
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
|
||||
self.assertNotIn('exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
|
||||
self.assertIn('[ $? -eq 10 ] && BL_STORE_EXIT=1', compat.BL_STORE_SETUP)
|
||||
self.assertIn('[ $rc -eq 10 ] && BL_STORE_EXIT=1', compat.BL_STORE_SETUP)
|
||||
self.assertIn('droiddeck-store-launch --exited --code "$rc" "${BL_STORE_ARGS[@]}"', compat.BL_STORE_SETUP)
|
||||
self.assertIn('exec "$@"', compat.BL_STORE_SETUP)
|
||||
|
||||
|
||||
BNET_EXE = '/root/.local/share/Steam/steamapps/compatdata/2596113170/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net.exe'
|
||||
|
||||
|
||||
class BattleNet(unittest.TestCase):
|
||||
def test_a_games_shortcut_is_handed_to_droiddeck_battlenet(self):
|
||||
self.assertEqual([store.BATTLENET, 'launch', 'Fen'], store.battlenet(['waitforexitandrun', BNET_EXE, '--exec=launch Fen'], env={}))
|
||||
self.assertEqual([store.BATTLENET, 'launch', 'OSI'], store.battlenet(['"%s"' % BNET_EXE, '--exec="launch OSI"'], env={}))
|
||||
self.assertEqual([store.BATTLENET, 'open'], store.battlenet([BNET_EXE], env={}))
|
||||
|
||||
def test_anything_else_and_its_own_starts_are_left_alone(self):
|
||||
other = BNET_EXE.replace('2596113170', '123')
|
||||
self.assertIsNone(store.battlenet([other, '--exec=launch Fen'], env={}))
|
||||
self.assertIsNone(store.battlenet(['/x/Diablo IV/Diablo IV.exe'], env={}))
|
||||
self.assertIsNone(store.battlenet([BNET_EXE, '--exec=launch Fen'], env={'BL_BATTLENET': '1'}))
|
||||
self.assertEqual([store.BATTLENET, 'open'], store.battlenet([BNET_EXE, '--exec=launch Fen;rm'], env={}))
|
||||
|
||||
def test_the_launch_runs_there_and_the_wrapper_ends_with_it(self):
|
||||
with patch.dict(os.environ, {}, clear=False), patch.object(store.subprocess, 'call', return_value=0) as call:
|
||||
os.environ.pop('BL_BATTLENET', None)
|
||||
self.assertEqual(store.RAN, store.main([BNET_EXE, '--exec=launch Pro']))
|
||||
call.assert_called_once_with([store.BATTLENET, 'launch', 'Pro'])
|
||||
with patch.dict(os.environ, {}, clear=False), patch.object(store.subprocess, 'call', return_value=1):
|
||||
os.environ.pop('BL_BATTLENET', None)
|
||||
self.assertEqual(store.RAN_FAILED, store.main([BNET_EXE, '--exec=launch Pro']))
|
||||
self.assertIn('[ $rc -eq 11 ] && exit 0', compat.BL_STORE_SETUP)
|
||||
self.assertIn('[ $rc -eq 12 ] && exit 1', compat.BL_STORE_SETUP)
|
||||
self.assertLess(compat.BL_STORE_SETUP.index('droiddeck-store-launch "$@"'), compat.BL_STORE_SETUP.index('[ $rc -eq 11 ] && exit 0'))
|
||||
|
||||
|
||||
class Launchers(unittest.TestCase):
|
||||
def test_both_proton_launchers_ask_before_proton_starts(self):
|
||||
sh = compat.LAUNCHER_SH
|
||||
|
||||
@@ -28,7 +28,8 @@ class ValidateApkTest(unittest.TestCase):
|
||||
def git(self, *args):
|
||||
return subprocess.check_output(["git", "-C", self.root, *args], text=True).strip()
|
||||
|
||||
def validate(self, message="Source change", body="", result="success", stale=False, completed=False, filename="source.kt"):
|
||||
def validate(self, message="Source change", body="", result="success", stale=False, completed=False, filename="source.kt", permission="write", role_name="write"):
|
||||
(self.root / filename).parent.mkdir(parents=True, exist_ok=True)
|
||||
(self.root / filename).write_text(message)
|
||||
self.git("add", filename)
|
||||
self.git("commit", "--allow-empty", "-qm", message)
|
||||
@@ -42,6 +43,8 @@ class ValidateApkTest(unittest.TestCase):
|
||||
path.write_text(json.dumps(event))
|
||||
|
||||
def api(path, *args):
|
||||
if path.endswith("/collaborators/human/permission"):
|
||||
return {"permission": permission, "role_name": role_name}
|
||||
if "/statuses/" in path:
|
||||
self.statuses.append(dict(value.split("=", 1) for value in args if "=" in value))
|
||||
return {}
|
||||
@@ -96,6 +99,19 @@ class ValidateApkTest(unittest.TestCase):
|
||||
self.validate(filename="README.md", result="pending")
|
||||
self.assertEqual(self.statuses[-1]["state"], "success")
|
||||
|
||||
def test_trusted_list_requires_maintainer_pr_opener(self):
|
||||
with self.assertRaisesRegex(RuntimeError, "Only a maintainer"):
|
||||
self.validate(filename=".github/trusted-test-builds.txt")
|
||||
self.assertEqual(self.statuses[-1]["state"], "failure")
|
||||
|
||||
def test_maintainer_can_change_trusted_list(self):
|
||||
self.validate(filename=".github/trusted-test-builds.txt", permission="write", role_name="maintain")
|
||||
self.assertEqual(self.statuses[-1]["state"], "success")
|
||||
|
||||
def test_admin_can_change_trusted_list(self):
|
||||
self.validate(filename=".github/trusted-test-builds.txt", permission="admin", role_name="admin")
|
||||
self.assertEqual(self.statuses[-1]["state"], "success")
|
||||
|
||||
def test_renaming_code_to_documentation_still_requires_compilation(self):
|
||||
(self.root / "source.kt").write_text("source")
|
||||
self.git("add", "source.kt")
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
import array
|
||||
import mmap
|
||||
import os
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
VDEC = ROOT / 'tools/linuxfs/preload/vdec.c'
|
||||
VENC = ROOT / 'tools/linuxfs/preload/venc.c'
|
||||
|
||||
DRIVER = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <poll.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int bl_vdec_open(const char *path, int flags);
|
||||
int bl_vdec_ioctl(int fd, unsigned long req, void *arg, int *rc);
|
||||
void bl_vdec_closed(int fd);
|
||||
void *SDL_LoadObject(const char *name);
|
||||
void *SDL_LoadFunction(void *handle, const char *name);
|
||||
|
||||
struct heap_alloc { uint64_t len; uint32_t fd, fd_flags; uint64_t heap_flags; };
|
||||
struct create_dumb { uint32_t height, width, bpp, flags, handle, pitch; uint64_t size; };
|
||||
struct prime_handle { uint32_t handle, flags; int32_t fd; };
|
||||
struct destroy_dumb { uint32_t handle; };
|
||||
struct drm_device { char **nodes; int available_nodes; };
|
||||
|
||||
static int heap = -1;
|
||||
|
||||
int open(const char *path, int flags, ...) {
|
||||
static int (*real)(const char *, int, ...);
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
int mode = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
if (!real) real = dlsym(RTLD_NEXT, "open");
|
||||
if (strcmp(path, "/dev/dma_heap/system") == 0) return heap = memfd_create("heap", 0);
|
||||
return real(path, flags, mode);
|
||||
}
|
||||
|
||||
int ioctl(int fd, unsigned long req, ...) {
|
||||
static int (*real)(int, unsigned long, ...);
|
||||
va_list ap;
|
||||
va_start(ap, req);
|
||||
void *arg = va_arg(ap, void *);
|
||||
va_end(ap);
|
||||
if (!real) real = dlsym(RTLD_NEXT, "ioctl");
|
||||
if (fd == heap && req == _IOWR('H', 0, struct heap_alloc)) {
|
||||
struct heap_alloc *a = arg;
|
||||
int buf = memfd_create("dmabuf", 0);
|
||||
if (ftruncate(buf, (off_t)a->len) != 0) return -1;
|
||||
a->fd = (uint32_t)buf;
|
||||
return 0;
|
||||
}
|
||||
if (req == _IOW('b', 0, uint64_t)) return 0;
|
||||
return real(fd, req, arg);
|
||||
}
|
||||
|
||||
static int vfd;
|
||||
static int call(unsigned long req, void *arg) {
|
||||
int rc;
|
||||
if (!bl_vdec_ioctl(vfd, req, arg, &rc)) return -100;
|
||||
return rc < 0 ? -errno : 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (bl_vdec_open("/dev/video0", O_RDWR) != -2) return 2;
|
||||
void *drm = SDL_LoadObject("libdrm.so.2");
|
||||
if (!drm) return 3;
|
||||
int (*devices)(uint32_t, struct drm_device **, int) = SDL_LoadFunction(drm, "drmGetDevices2");
|
||||
int (*drm_ioctl)(int, unsigned long, void *) = SDL_LoadFunction(drm, "drmIoctl");
|
||||
if (!devices || !drm_ioctl || !SDL_LoadFunction(drm, "drmModeAtomicCommit")) return 4;
|
||||
struct drm_device *dev[1];
|
||||
if (devices(0, NULL, 0) != 1 || devices(0, dev, 1) != 1 || !(dev[0]->available_nodes & 1)) return 5;
|
||||
int card = open(dev[0]->nodes[0], O_RDWR | O_CLOEXEC);
|
||||
if (card < 0) return 6;
|
||||
|
||||
vfd = bl_vdec_open("/dev/video-dec0", O_RDWR);
|
||||
if (vfd < 0) return 7;
|
||||
struct v4l2_capability cap;
|
||||
if (call(VIDIOC_QUERYCAP, &cap) || (cap.capabilities & 0x04004000) != 0x04004000) return 8;
|
||||
struct v4l2_fmtdesc d = { .index = 1, .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE };
|
||||
if (call(VIDIOC_ENUM_FMT, &d) || d.pixelformat != V4L2_PIX_FMT_HEVC) return 9;
|
||||
struct v4l2_format f = { .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE };
|
||||
f.fmt.pix_mp.width = 1280; f.fmt.pix_mp.height = 720; f.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_HEVC;
|
||||
if (call(VIDIOC_S_FMT, &f)) return 10;
|
||||
struct v4l2_requestbuffers r = { .count = 4, .type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, .memory = V4L2_MEMORY_MMAP };
|
||||
if (call(VIDIOC_REQBUFS, &r) || r.count != 4) return 11;
|
||||
unsigned char *in[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
struct v4l2_plane p = { 0 };
|
||||
struct v4l2_buffer b = { .index = i, .type = r.type, .memory = V4L2_MEMORY_MMAP, .length = 1, .m.planes = &p };
|
||||
if (call(VIDIOC_QUERYBUF, &b)) return 12;
|
||||
in[i] = mmap(NULL, p.length, PROT_READ | PROT_WRITE, MAP_SHARED, vfd, p.m.mem_offset);
|
||||
if (in[i] == MAP_FAILED) return 13;
|
||||
}
|
||||
f = (struct v4l2_format){ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE };
|
||||
f.fmt.pix_mp.width = 1280; f.fmt.pix_mp.height = 736; f.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
|
||||
if (call(VIDIOC_S_FMT, &f) || f.fmt.pix_mp.num_planes != 1) return 14;
|
||||
uint32_t bpl = f.fmt.pix_mp.plane_fmt[0].bytesperline, size = f.fmt.pix_mp.plane_fmt[0].sizeimage;
|
||||
if (bpl != 1280 || size != 1280 * 736 * 3 / 2) return 15;
|
||||
r = (struct v4l2_requestbuffers){ .count = 3, .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, .memory = V4L2_MEMORY_DMABUF };
|
||||
if (call(VIDIOC_REQBUFS, &r) || r.count != 3) return 16;
|
||||
int out[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
struct create_dumb c = { .height = 736, .width = 1280, .bpp = 16 };
|
||||
if (drm_ioctl(card, 0xc02064b2, &c) || !c.handle || c.size < size) return 17;
|
||||
struct prime_handle h = { .handle = c.handle, .flags = O_CLOEXEC };
|
||||
if (drm_ioctl(card, 0xc00c642d, &h)) return 18;
|
||||
struct destroy_dumb x = { .handle = c.handle };
|
||||
if (drm_ioctl(card, 0xc00464b4, &x)) return 19;
|
||||
out[i] = h.fd;
|
||||
}
|
||||
unsigned types[2] = { V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE };
|
||||
if (call(VIDIOC_STREAMON, &types[0]) || call(VIDIOC_STREAMON, &types[1])) return 20;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
struct v4l2_plane p = { .m.fd = out[i] };
|
||||
struct v4l2_buffer b = { .index = i, .type = types[1], .memory = V4L2_MEMORY_DMABUF, .length = 1, .m.planes = &p };
|
||||
if (call(VIDIOC_QBUF, &b)) return 21;
|
||||
}
|
||||
struct pollfd pf = { .fd = vfd, .events = 0xc9 };
|
||||
if (poll(&pf, 1, 0) != 0) return 22;
|
||||
for (int frame = 1; frame <= 5; frame++) {
|
||||
int slot = frame % 4;
|
||||
memset(in[slot], 'a' + frame, 100 + frame);
|
||||
struct v4l2_plane p = { .bytesused = 100 + frame };
|
||||
struct v4l2_buffer b = { .index = slot, .type = types[0], .memory = V4L2_MEMORY_MMAP, .flags = 0x4008, .length = 1, .m.planes = &p };
|
||||
b.timestamp.tv_usec = frame;
|
||||
if (call(VIDIOC_QBUF, &b)) return 23;
|
||||
pf = (struct pollfd){ .fd = vfd, .events = 0xc9 };
|
||||
if (poll(&pf, 1, 30) != 1 || !(pf.revents & POLLIN)) return 24;
|
||||
struct v4l2_plane cp = { 0 };
|
||||
struct v4l2_buffer cb = { .type = types[1], .memory = V4L2_MEMORY_DMABUF, .length = 1, .m.planes = &cp };
|
||||
if (call(VIDIOC_DQBUF, &cb)) return 25;
|
||||
unsigned char *m = mmap(NULL, size, PROT_READ, MAP_SHARED, out[cb.index], 0);
|
||||
printf("%ld %u %c%c %u\n", (long)cb.timestamp.tv_usec, cb.index, m[0], m[(size_t)bpl * 736], cp.bytesused == size);
|
||||
munmap(m, size);
|
||||
pf = (struct pollfd){ .fd = vfd, .events = 0x306 };
|
||||
if (poll(&pf, 1, 0) != 1) return 26;
|
||||
struct v4l2_plane op = { 0 };
|
||||
struct v4l2_buffer ob = { .type = types[0], .memory = V4L2_MEMORY_MMAP, .length = 1, .m.planes = &op };
|
||||
if (call(VIDIOC_DQBUF, &ob) || ob.index != (unsigned)slot) return 27;
|
||||
struct v4l2_plane rp = { .m.fd = out[cb.index] };
|
||||
struct v4l2_buffer rb = { .index = cb.index, .type = types[1], .memory = V4L2_MEMORY_DMABUF, .length = 1, .m.planes = &rp };
|
||||
if (call(VIDIOC_QBUF, &rb)) return 28;
|
||||
}
|
||||
if (call(VIDIOC_STREAMOFF, &types[1])) return 29;
|
||||
f = (struct v4l2_format){ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE };
|
||||
f.fmt.pix_mp.width = 1920; f.fmt.pix_mp.height = 1088; f.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12;
|
||||
if (call(VIDIOC_S_FMT, &f)) return 30;
|
||||
size = f.fmt.pix_mp.plane_fmt[0].sizeimage;
|
||||
r = (struct v4l2_requestbuffers){ .count = 1, .type = types[1], .memory = V4L2_MEMORY_DMABUF };
|
||||
if (call(VIDIOC_REQBUFS, &r)) return 31;
|
||||
struct create_dumb big = { .height = 1088, .width = 1920, .bpp = 16 };
|
||||
if (drm_ioctl(card, 0xc02064b2, &big)) return 32;
|
||||
struct prime_handle bh = { .handle = big.handle, .flags = O_CLOEXEC };
|
||||
if (drm_ioctl(card, 0xc00c642d, &bh)) return 33;
|
||||
if (call(VIDIOC_STREAMON, &types[1])) return 34;
|
||||
struct v4l2_plane bp = { .m.fd = bh.fd };
|
||||
struct v4l2_buffer bb = { .index = 0, .type = types[1], .memory = V4L2_MEMORY_DMABUF, .length = 1, .m.planes = &bp };
|
||||
if (call(VIDIOC_QBUF, &bb)) return 35;
|
||||
memset(in[2], 'z', 50);
|
||||
struct v4l2_plane zp = { .bytesused = 50 };
|
||||
struct v4l2_buffer zb = { .index = 2, .type = types[0], .memory = V4L2_MEMORY_MMAP, .length = 1, .m.planes = &zp };
|
||||
zb.timestamp.tv_usec = 6;
|
||||
if (call(VIDIOC_QBUF, &zb)) return 36;
|
||||
struct v4l2_plane dp = { 0 };
|
||||
struct v4l2_buffer db = { .type = types[1], .memory = V4L2_MEMORY_DMABUF, .length = 1, .m.planes = &dp };
|
||||
if (call(VIDIOC_DQBUF, &db)) return 37;
|
||||
unsigned char *m = mmap(NULL, size, PROT_READ, MAP_SHARED, bh.fd, 0);
|
||||
printf("%ld %u %c%c\n", (long)db.timestamp.tv_usec, db.index, m[0], m[(size_t)1920 * 1088]);
|
||||
bl_vdec_closed(vfd);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
CONFIG = struct.Struct('<IIIIIIII')
|
||||
CAPTURE = struct.Struct('<III')
|
||||
PACKET = struct.Struct('<IIII q')
|
||||
RESULT = struct.Struct('<IiI')
|
||||
|
||||
|
||||
class FakeDecoder(threading.Thread):
|
||||
def __init__(self, path):
|
||||
super().__init__(daemon=True)
|
||||
self.listener = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
self.listener.bind(path)
|
||||
self.listener.listen(1)
|
||||
self.configs, self.packets = [], []
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
try:
|
||||
conn, _ = self.listener.accept()
|
||||
except OSError:
|
||||
return
|
||||
threading.Thread(target=self.serve, args=(conn,), daemon=True).start()
|
||||
|
||||
def serve(self, conn):
|
||||
bitstream, captures, config = None, {}, None
|
||||
while True:
|
||||
fds = array.array('i')
|
||||
msg, ancdata, _, _ = conn.recvmsg(256, socket.CMSG_LEN(4 * fds.itemsize))
|
||||
if not msg:
|
||||
return
|
||||
for level, kind, data in ancdata:
|
||||
if level == socket.SOL_SOCKET and kind == socket.SCM_RIGHTS:
|
||||
fds.frombytes(data[:len(data) - len(data) % fds.itemsize])
|
||||
kind = struct.unpack_from('<I', msg)[0]
|
||||
if kind == 6:
|
||||
config = CONFIG.unpack(msg)
|
||||
self.configs.append(config)
|
||||
bitstream = mmap.mmap(fds[0], config[6] * config[7], prot=mmap.PROT_READ)
|
||||
os.close(fds[0])
|
||||
conn.send(RESULT.pack(9, 0, 0))
|
||||
elif kind == 7:
|
||||
_, index, size = CAPTURE.unpack(msg)
|
||||
captures[index] = mmap.mmap(fds[0], size)
|
||||
os.close(fds[0])
|
||||
elif kind == 8:
|
||||
_, source, nbytes, target, pts = PACKET.unpack(msg)
|
||||
self.packets.append((source, nbytes, target, pts))
|
||||
first = bitstream[source * config[7]]
|
||||
frame = captures[target]
|
||||
frame[0] = first
|
||||
frame[config[4] * config[5]] = ord('u')
|
||||
conn.send(RESULT.pack(9, 0, 1))
|
||||
|
||||
|
||||
class VdecEmulatorTest(unittest.TestCase):
|
||||
def test_remote_play_client_decodes_through_the_app_socket(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp = Path(tmp)
|
||||
driver = tmp / 'driver.c'
|
||||
driver.write_text(DRIVER)
|
||||
binary = tmp / 'streaming_client'
|
||||
subprocess.run(['cc', '-O1', '-pthread', '-DBL_VDEC_ANY_ARCH', '-o', str(binary), str(driver), str(VDEC),
|
||||
str(VENC), '-ldl'], check=True)
|
||||
sock = tmp / 'venc.sock'
|
||||
server = FakeDecoder(str(sock))
|
||||
self.addCleanup(server.listener.close)
|
||||
server.start()
|
||||
done = subprocess.run([str(binary)], env=dict(os.environ, BL_VENC_SOCKET=str(sock)),
|
||||
capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
|
||||
self.assertEqual(done.stdout.split('\n')[:6],
|
||||
['1 0 bu 1', '2 1 cu 1', '3 2 du 1', '4 0 eu 1', '5 1 fu 1', '6 0 zu'])
|
||||
self.assertEqual([c[1:6] for c in server.configs],
|
||||
[(1, 1280, 720, 1280, 736), (1, 1280, 720, 1920, 1088)])
|
||||
self.assertEqual([p[:3] for p in server.packets],
|
||||
[(1, 101, 0), (2, 102, 1), (3, 103, 2), (0, 104, 0), (1, 105, 1), (2, 50, 0)])
|
||||
|
||||
def test_other_programs_keep_the_real_libdrm(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp = Path(tmp)
|
||||
(tmp / 'main.c').write_text(
|
||||
'void *SDL_LoadObject(const char *);\n'
|
||||
'int main(void) { return SDL_LoadObject("libdrm.so.2") != 0; }\n')
|
||||
binary = tmp / 'steam'
|
||||
subprocess.run(['cc', '-O1', '-pthread', '-DBL_VDEC_ANY_ARCH', '-o', str(binary), str(tmp / 'main.c'),
|
||||
str(VDEC), str(VENC), '-ldl'], check=True)
|
||||
done = subprocess.run([str(binary)], capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(done.returncode, 0, done.stderr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -136,6 +136,46 @@ class XboxLaunchTest(unittest.TestCase):
|
||||
self.assertNotIn('DROIDDECK_XBOX_COMMAND_FILE', child_env)
|
||||
self.assertEqual(child_env['XODUS_BRIDGE_KEY'], 'runtime-key')
|
||||
|
||||
def test_launch_view_runs_from_a_short_drive_letter(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root = Path(root)
|
||||
prefix = root / 'compat/pfx'
|
||||
prefix.mkdir(parents=True)
|
||||
runtime = root / 'runtime/windows'; runtime.mkdir(parents=True)
|
||||
for name in xbox['DLLS']:
|
||||
(runtime / name).write_bytes(b'MZ-synthetic')
|
||||
view = root / 'files/xbox-runtime/views/launch-4093691424/droiddeck-xbox-1ZpM3D'
|
||||
(view / 'Bin').mkdir(parents=True)
|
||||
command = root / 'command.json'
|
||||
command.write_text(json.dumps(['/selected/proton', 'waitforexitandrun', '/encrypted/Game.exe']))
|
||||
env = {'STEAM_COMPAT_DATA_PATH': str(prefix.parent), 'DROIDDECK_XBOX_COMMAND_FILE': str(command)}
|
||||
seen = []
|
||||
def call(argv, **kwargs):
|
||||
seen.append((argv, os.readlink(prefix / 'dosdevices/x:')))
|
||||
return 0
|
||||
with patch.dict(os.environ, env), patch.dict(xbox['wine'].__globals__, RUNTIME=runtime.parent), patch('subprocess.run') as initialize, patch('subprocess.call', side_effect=call):
|
||||
initialize.return_value.returncode = 0
|
||||
self.assertEqual(xbox['wine']([str(view / 'Bin/Game.exe')]), 0)
|
||||
self.assertEqual(seen, [(['/selected/proton', 'waitforexitandrun', 'X:\\Bin\\Game.exe'], str(view))])
|
||||
self.assertFalse(os.path.lexists(prefix / 'dosdevices/x:'))
|
||||
|
||||
def test_view_drive_keeps_drives_in_use_and_reuses_a_stale_view(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
root = Path(root)
|
||||
devices = root / 'pfx/dosdevices'; devices.mkdir(parents=True)
|
||||
views = root / 'views'
|
||||
live = views / 'launch-1/droiddeck-xbox-live'; live.mkdir(parents=True)
|
||||
view = views / 'launch-2/droiddeck-xbox-new'; view.mkdir(parents=True)
|
||||
(devices / 'x:').symlink_to(live)
|
||||
(devices / 'w:').symlink_to(root / 'games')
|
||||
(devices / 'v:').symlink_to(views / 'launch-0/droiddeck-xbox-gone')
|
||||
exe, link = xbox['view_drive'](root / 'pfx', str(view / 'Game.exe'))
|
||||
self.assertEqual((exe, link), ('V:\\Game.exe', devices / 'v:'))
|
||||
self.assertEqual(os.readlink(devices / 'v:'), str(view))
|
||||
self.assertEqual(os.readlink(devices / 'x:'), str(live))
|
||||
self.assertEqual(sorted(p.name for p in devices.iterdir()), ['v:', 'w:', 'x:'])
|
||||
self.assertEqual(xbox['view_drive'](root / 'pfx', '/games/Game.exe'), ('/games/Game.exe', None))
|
||||
|
||||
def test_missing_runtime_classes_are_registered_once(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
prefix = Path(root)
|
||||
|
||||
Reference in new issue
Block a user