mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
In async mode the layer blocked the game's command recording until the NPU had finished the previous frame, and the NPU could only start once the GPU had finished that frame. CPU and GPU took turns, which is the ~18 ms per-frame stall seen in Cyberpunk with FSR 4.1 on the NPU. Now the next frame's command buffer waits on a host-set event (ev_done) before the post pass, and the event is reset on the GPU right before the retire value that starts the NPU job, so the recording thread never waits. The NPU worker sets the event after every job, also after a timeout; with no job queued it releases both events every 250 ms so a GPU wait without a job cannot hang. The job ring grows from 4 to 8 entries, and a full ring drops that frame's NPU job instead of overwriting one. Same change in the Full (fsr411_full_gpu.c) and Lite (fsr412_lite.c) NPU paths. DROIDDECK_UPSCALE_NPU_CPU_WAIT=1 brings back the old wait for A/B tests.
65 lines
2.1 KiB
C
65 lines
2.1 KiB
C
// DroidDeck glue for the upscaler layer: environment lookup and logging.
|
|
//
|
|
// Every setting is read as DROIDDECK_UPSCALE_<KEY> first and WINLATOR_FSR4_<KEY> second, so
|
|
// launchers written for the upstream layer keep working. Empty values count as unset.
|
|
//
|
|
// Android builds log to logcat. DD_UPSCALE_NO_ANDROID builds (glibc, PRoot guest) log to stderr.
|
|
#pragma once
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
static inline const char *dd_upscale_env(const char *key) {
|
|
char name[96];
|
|
snprintf(name, sizeof name, "DROIDDECK_UPSCALE_%s", key);
|
|
const char *v = getenv(name);
|
|
if (v && *v) return v;
|
|
snprintf(name, sizeof name, "WINLATOR_FSR4_%s", key);
|
|
v = getenv(name);
|
|
return (v && *v) ? v : NULL;
|
|
}
|
|
|
|
// Async NPU: the next frame's command buffer waits on the GPU for the NPU result, so the game's recording thread never
|
|
// blocks on the NPU. DROIDDECK_UPSCALE_NPU_CPU_WAIT=1 brings back the old wait on the recording thread.
|
|
static inline int dd_upscale_npu_gpu_wait(void) {
|
|
const char *v = dd_upscale_env("NPU_CPU_WAIT");
|
|
return !(v && (!strcmp(v, "1") || !strcmp(v, "true")));
|
|
}
|
|
|
|
// Data dir with the SPIR-V passes, weights and QNN files. NULL when no launcher set one.
|
|
static inline const char *dd_upscale_dir(void) {
|
|
const char *dir = dd_upscale_env("DIR");
|
|
if (!dir) {
|
|
dir = getenv("DM_FSR4_DIR");
|
|
if (dir && !*dir) dir = NULL;
|
|
}
|
|
return dir;
|
|
}
|
|
|
|
#ifdef DD_UPSCALE_NO_ANDROID
|
|
#include <stdarg.h>
|
|
|
|
#define DD_LOG_INFO 4
|
|
#define DD_LOG_WARN 5
|
|
#define DD_LOG_ERROR 6
|
|
|
|
__attribute__((format(printf, 3, 4)))
|
|
static inline int dd_upscale_log(int prio, const char *tag, const char *fmt, ...) {
|
|
char msg[1024];
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
vsnprintf(msg, sizeof msg, fmt, ap);
|
|
va_end(ap);
|
|
const char lvl = prio >= DD_LOG_ERROR ? 'E' : (prio == DD_LOG_WARN ? 'W' : 'I');
|
|
return fprintf(stderr, "%c/%s: %s\n", lvl, tag, msg);
|
|
}
|
|
#else
|
|
#include <android/log.h>
|
|
|
|
#define DD_LOG_INFO ANDROID_LOG_INFO
|
|
#define DD_LOG_WARN ANDROID_LOG_WARN
|
|
#define DD_LOG_ERROR ANDROID_LOG_ERROR
|
|
#define dd_upscale_log __android_log_print
|
|
#endif
|