Xbox Cloud Gaming app for PS5 Homebrew
C
Display: the GPU's switches through display::, and what a display can do (caps)
Rafael Abud Ferreiraddb4e2089e83
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 65acc35..04108ad 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -6,7 +6,6 @@#include "app/ps5_app.h"#include "display/display.h"-#include "display/gpu.h"#include "media/audio_in.h"#include "media/decoder.h"#include "platform/platform.h"@@ -69,8 +68,8 @@ void loadAutoplay() {if (opt.rfind("loss=", 0) == 0) g_autoplay.videoLoss = std::atoi(opt.c_str() + 5);if (opt == "ai") g_autoplay.upscaler = 1;if (opt == "restore") g_autoplay.restore = true;- if (opt.rfind("swap=", 0) == 0) display::gpu::setSwapImages(std::atoi(opt.c_str() + 5));- if (opt == "nopace") display::gpu::setPresentWait(false);+ if (opt.rfind("swap=", 0) == 0) display::setSwapImages(std::atoi(opt.c_str() + 5));+ if (opt == "nopace") display::setPresentWait(false);if (opt == "detailtest") g_autoplay.detailTest = true;if (opt == "pad") g_autoplay.pad = true;if (opt == "consoles") g_autoplay.consoles = true;diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 98e5ae2..2131efb 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -13,7 +13,6 @@#include "app/stream_screen.h"#include "app/updater.h"#include "display/display.h"-#include "display/gpu.h"#include "input/controller.h"#include "input/kbm.h"#include "input/keyboard_nav.h"@@ -208,17 +207,16 @@ int main(int argc, char** argv) {// one that doesn't. Decided once per start, as RADV opens VideoOut once.// With the patched RADV the output starts at 60 Hz and each game's stream// turns 120 Hz on (StreamScreen); without it, the setting decides here.- if (!g_settings.highRefresh || display::gpu::canSwitchRefresh()) {+ if (!g_settings.highRefresh || display::canSwitchRefresh()) {std::string path = platform::dataDir() + "/videoout-60hz.json";platform::writeFileAtomic(path, "{\"attribute3\": 0}\n");::setenv("PS5_VIDEOOUT_PARAM_JSON", path.c_str(), 1);}XC_LOGI("display: 120 Hz output %s", !g_settings.highRefresh ? "off"- : display::gpu::canSwitchRefresh() ? "in games" : "on");+ : display::canSwitchRefresh() ? "in games" : "on");if (g_autoplay.vkTest) {- bool ok = display::gpu::init();- if (ok) display::gpu::probe(300);+ bool ok = display::bringUpTest(300);XC_LOGI("AUTOPLAY END: vktest %s", ok ? "ran" : "failed");for (;;) platform::sleepMs(1000);}diff --git a/src/app/stream_screen.cpp b/src/app/stream_screen.cppindex 6f1ad89..456b1e5 100644--- a/src/app/stream_screen.cpp+++ b/src/app/stream_screen.cpp@@ -7,7 +7,6 @@#include "app/ps5_app.h"#include "app/stream_player.h"#include "display/display.h"-#include "display/gpu.h"#include "input/kbm.h"#include "input/keyboard_nav.h"#include "media/audio_out.h"@@ -131,7 +130,7 @@ void StreamScreen::update(const input::ControllerState& pad, ui::NavInput nav, bif (g_ui) g_ui->setCircleConfirms(prof.circleConfirms);// 120 Hz (VRR) for this game's stream only: the menus stay at 60 Hz// (OLED TVs may flicker under VRR when little is drawn).- highRefresh_ = prof.highRefresh && display::gpu::setHighRefresh(true);+ highRefresh_ = prof.highRefresh && display::setHighRefresh(true);media::audioSetRoute(static_cast<media::AudioRoute>(g_settings.audioRoute));if (g_player) {@@ -511,7 +510,7 @@ void StreamScreen::idle() {input::setTriggerFeel(g_settings.triggerStrength, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses);input::setCircleConfirms(g_settings.circleConfirms);if (g_ui) g_ui->setCircleConfirms(g_settings.circleConfirms);- if (highRefresh_) display::gpu::setHighRefresh(false);+ if (highRefresh_) display::setHighRefresh(false);highRefresh_ = false;}}diff --git a/src/display/display.h b/src/display/display.hindex 40a02bd..3abfcb7 100644--- a/src/display/display.h+++ b/src/display/display.h@@ -13,7 +13,8 @@ constexpr unsigned kWidth = 1920;constexpr unsigned kHeight = 1080;// The GPU (display/gpu.h: FSR upscaling to the 4K display) when `preferGpu`-// and it comes up, else the CPU path below.+// and it comes up, else the CPU path below. The backend is picked at link+// time: display_ps5.cpp on the console, display_null.cpp (no screen) elsewhere.bool init(bool preferGpu = true);void shutdown();// Held by whoever draws a frame (UI thread or video thread).@@ -45,6 +46,31 @@ void setUpscaler(int mode);// Anime4K Restore before the upscale (GPU only).void setRestore(bool on);+// What this display can do, as of now (the GPU's part once init() has run):+// an option it can't honour is hidden or has no effect.+struct DisplayCaps {+ bool upscalers = false; // setUpscaler / setRestore+ bool deband = false; // setDeband+ bool sharpen = false; // setSharpness+ bool highRefreshSwitch = false; // setHighRefresh+ bool presentTiming = false; // lastPresentId / lastShown+};+DisplayCaps caps();++// Before init(): swapchain images (GPU only; 2 = lowest latency, the default).+void setSwapImages(int count);+// Before init(): wait for each frame to reach the screen before the next+// (GPU only, on by default).+void setPresentWait(bool on);+// 119.88 Hz output on, or back to 59.94 Hz, while running (a game's stream+// only); false when the display can't switch or was refused.+bool setHighRefresh(bool on);+// Whether setHighRefresh() can work at all; known before init().+bool canSwitchRefresh();+// Bring-up check instead of init(): the GPU alone, then `frames` test frames+// against the refresh (autoplay "vktest"). False when it didn't come up.+bool bringUpTest(int frames);+// GPU only: the id of the last present(), and the last frame known to be on// the screen (its id, and platform::nowUs() then). False on the CPU path.uint64_t lastPresentId();diff --git a/src/display/display_null.cpp b/src/display/display_null.cppindex 52612c7..339e421 100644--- a/src/display/display_null.cpp+++ b/src/display/display_null.cpp@@ -23,6 +23,12 @@ void setSharpness(int) {}void setDeband(int) {}void setUpscaler(int) {}void setRestore(bool) {}+DisplayCaps caps() { return {}; }+void setSwapImages(int) {}+void setPresentWait(bool) {}+bool setHighRefresh(bool) { return false; }+bool canSwitchRefresh() { return false; }+bool bringUpTest(int) { return false; }uint64_t lastPresentId() { return 0; }bool lastShown(uint64_t&, uint64_t&) { return false; }bool readBackRgb(std::vector<uint8_t>&, int&, int&) { return false; }diff --git a/src/display/display_ps5.cpp b/src/display/display_ps5.cppindex 8802063..1e6eafd 100644--- a/src/display/display_ps5.cpp+++ b/src/display/display_ps5.cpp@@ -503,6 +503,27 @@ void setDeband(int level) { gpu::setDeband(level); }void setUpscaler(int mode) { gpu::setUpscaler(mode); }void setRestore(bool on) { gpu::setRestore(on); }+// The CPU path sharpens too; the rest is the GPU's.+DisplayCaps caps() {+ DisplayCaps c;+ c.upscalers = c.deband = c.presentTiming = gpu::ready();+ c.sharpen = true;+ c.highRefreshSwitch = gpu::canSwitchRefresh();+ return c;+}++// Straight to the GPU, whether it came up or not, as these always went.+void setSwapImages(int count) { gpu::setSwapImages(count); }+void setPresentWait(bool on) { gpu::setPresentWait(on); }+bool setHighRefresh(bool on) { return gpu::setHighRefresh(on); }+bool canSwitchRefresh() { return gpu::canSwitchRefresh(); }++bool bringUpTest(int frames) {+ bool ok = gpu::init();+ if (ok) gpu::probe(frames);+ return ok;+}+uint64_t lastPresentId() { return gpu::ready() ? gpu::lastPresentId() : 0; }bool lastShown(uint64_t& id, uint64_t& atUs) { return gpu::ready() && gpu::lastShown(id, atUs); }diff --git a/tests/test_main.cpp b/tests/test_main.cppindex d1920a7..32054f9 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -7,6 +7,7 @@#include "app/updater.h"#include "app/crash_guard.h"#include "app/report.h"+#include "display/display.h"#include "media/audio_encoder.h"#include "media/decoder.h"#include "media/hw_decoder.h"@@ -1141,6 +1142,9 @@ static void testNullBackends() {CHECK(!kbm.keyboard && !kbm.mouse && kbm.keys.empty() && !kbm.moved);media::HwDecoder hw;CHECK(!hw.init(1920, 1088) && !hw.ready());+ display::DisplayCaps caps = display::caps();+ CHECK(!caps.upscalers && !caps.deband && !caps.sharpen && !caps.highRefreshSwitch && !caps.presentTiming);+ CHECK(!display::canSwitchRefresh() && !display::setHighRefresh(true) && !display::bringUpTest(1));}int main() {