libretro: surface DisplayLoadingScreen progress through the frontend OSD
HostInterface::DisplayLoadingScreen was a no-op stub in the libretro
backend. The DuckStation interface contract is documented as: a
caller invokes it repeatedly during a bounded long operation with
(value, total) progress counters, throttled by the caller to roughly
10 Hz. In swanstation the existing call sites are:
- GPU_HW::ShaderCompileProgressTracker::Increment (once per
compiled batch/screen-quad/etc. shader, throttled by a 100 ms
interval and a 1-second minimum-time-before-first-message
floor; the total is 1+1+2+(4*9*2*2)+1+(2*2)+4+(2*3)+1 = 172 for
the D3D11 backend)
- texture_replacements.cpp preload loop (once per replacement
texture)
- HostInterfaceProgressCallback (the generic ConsoleProgressCallback
bridge - not used by the libretro path today but still wired in
via the same hook)
Because the libretro implementation discarded all of these, users
saw nothing during shader precompilation. With a cold shader cache
and the texture filter set to xBR or one of the other heavier
options, that's typically tens of seconds of synchronous work on
the runloop thread, during which RetroArch appears to be hung. The
hint that it isn't hung was only visible to anyone willing to
attach a debugger.
Forward DisplayLoadingScreen to the libretro frontend. The mapping:
- When the frontend reports message-interface v1+ (the cached
libretro_msg_interface_version probed in InitInterfaces),
use RETRO_ENVIRONMENT_SET_MESSAGE_EXT with type =
RETRO_MESSAGE_TYPE_PROGRESS, target = RETRO_MESSAGE_TARGET_OSD,
and an int8 progress percentage derived from the
(value, total) pair. RetroArch renders this as a dedicated
progress widget rather than a generic OSD notification.
- When the frontend is older (libretro_msg_interface_version == 0),
fall back to RETRO_ENVIRONMENT_SET_MESSAGE with the formatted
'Compiling Shaders 47/172' text in the message body. The user
still sees the progress count, just without the widget.
The progress percentage is computed in long arithmetic to avoid
overflow on totals up to ~21 million (more than two orders of
magnitude beyond what the shader tracker actually uses, but the
preload-textures path can in theory hit larger totals on a heavily
modded game). The result is clamped to [0,100] to match the
libretro spec.
The displayed text always includes 'value/total' even when the
EXT path is taken, because the spec is explicit that the progress
field is a hint and frontends may ignore it; that way the same
information shows up regardless of which path the frontend uses.
Message duration on the EXT path is set to 1000 ms with priority 3:
the priority matches the libretro header's documented
'frontend-generated notifications' tier (so we don't outrank
later game-relevant messages), and the duration is comfortably
larger than the tracker's 100 ms update interval, so consecutive
calls keep the widget alive smoothly until the operation
completes and the last message ages out.
Empty-message protection is added since SET_MESSAGE_EXT documents
'undefined behavior' for a NULL or empty msg field. Without this,
a stray DisplayLoadingScreen call from anywhere with a null
title would crash the frontend.
libretro_msg_interface_version was already being probed in
InitInterfaces() (since RA 1.9 / 2020) but never consumed; this
commit puts it to use. AddOSDMessage still uses the legacy
SET_MESSAGE path; moving it to SET_MESSAGE_EXT is a separate
change because the semantics around message lifetime
(frames vs ms) differ and AddOSDMessage callers pass an explicit
duration that needs careful translation.
Throttling is unchanged: the existing
ShaderCompileProgressTracker only invokes DisplayLoadingScreen
after the operation has been running for >= 1 second, and then
at most every 100 ms. For warm-cache shader loads (the common
case where everything resolves from disk in <100 ms) this still
produces zero OSD traffic.
Build: zero warnings, zero errors. 100 insertions, 1 deletion in
src/libretro/libretro_host_interface.cpp. .so size 8028240 bytes
(was 8027408, +832 - the new code path is ~80 lines of mostly
straightforward integer arithmetic and one snprintf). 25 retro_*
exports unchanged.
This commit is contained in:
parent
3cc74f4963
commit
10898224d8
1 changed files with 99 additions and 1 deletions
|
|
@ -465,7 +465,105 @@ std::string HostInterface::GetStringSettingValue(const char* section, const char
|
|||
}
|
||||
|
||||
void HostInterface::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/,
|
||||
int progress_max /*= -1*/, int progress_value /*= -1*/) {}
|
||||
int progress_max /*= -1*/, int progress_value /*= -1*/)
|
||||
{
|
||||
// Render progress feedback through the libretro frontend so that
|
||||
// long-running setup steps (shader precompilation, texture preload)
|
||||
// don't look like the core has hung.
|
||||
//
|
||||
// The DuckStation HostInterface contract is documented at the
|
||||
// top of host_interface.h: this is called repeatedly during
|
||||
// bounded long operations with (current, total) progress counters,
|
||||
// and is throttled by the caller to ~10 Hz. Callers in
|
||||
// swanstation are:
|
||||
//
|
||||
// - GPU_HW::ShaderCompileProgressTracker::Increment (every
|
||||
// compiled shader, throttled to >=100ms)
|
||||
// - texture_replacements.cpp preload loop (every replacement
|
||||
// texture)
|
||||
// - HostInterfaceProgressCallback (legacy generic progress)
|
||||
//
|
||||
// For the libretro target, the cleanest mapping is
|
||||
// RETRO_ENVIRONMENT_SET_MESSAGE_EXT with type =
|
||||
// RETRO_MESSAGE_TYPE_PROGRESS, which RetroArch renders as a
|
||||
// dedicated progress widget in the upper-right corner rather
|
||||
// than a generic OSD line. When the frontend's message interface
|
||||
// version is too old to support EXT (libretro_msg_interface_version
|
||||
// == 0, i.e. cores running on RA builds pre-2020 or other
|
||||
// frontends that haven't adopted v1), fall back to plain
|
||||
// SET_MESSAGE with the formatted progress text in the message
|
||||
// body, so the user still sees "Compiling Shaders 47/112"
|
||||
// instead of a frozen window.
|
||||
if (!message || !*message)
|
||||
return;
|
||||
|
||||
// Compute progress percentage. The DisplayLoadingScreen contract
|
||||
// passes progress_min as the starting count (typically 0) and
|
||||
// progress_max as the total; -1 across the trio means
|
||||
// 'indeterminate', which RetroArch represents with progress = -1
|
||||
// on SET_MESSAGE_EXT.
|
||||
int progress_pct = -1;
|
||||
if (progress_max > 0 && progress_value >= 0 && progress_value <= progress_max)
|
||||
{
|
||||
progress_pct = static_cast<int>(
|
||||
(static_cast<long>(progress_value) * 100l) / static_cast<long>(progress_max));
|
||||
if (progress_pct < 0)
|
||||
progress_pct = 0;
|
||||
else if (progress_pct > 100)
|
||||
progress_pct = 100;
|
||||
}
|
||||
|
||||
// Build the displayed string. Including the percentage in the
|
||||
// text body matters even when SET_MESSAGE_EXT is available,
|
||||
// because the libretro spec explicitly says progress is a hint
|
||||
// - some frontends (and RetroArch with certain notification
|
||||
// styles) drop the progress widget and only show the text.
|
||||
char text[256];
|
||||
if (progress_max > 0 && progress_value >= 0)
|
||||
{
|
||||
std::snprintf(text, sizeof(text), "%s %d/%d", message, progress_value, progress_max);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::snprintf(text, sizeof(text), "%s", message);
|
||||
}
|
||||
text[sizeof(text) - 1] = '\0';
|
||||
|
||||
if (libretro_msg_interface_version >= 1)
|
||||
{
|
||||
retro_message_ext msg = {};
|
||||
msg.msg = text;
|
||||
// 1000 ms duration with ~10 Hz update cadence means each frame
|
||||
// of the progress is overwritten by the next one well before
|
||||
// it expires, and the widget stays visible smoothly. The last
|
||||
// call (after CompileShaders returns) ages out naturally after
|
||||
// one second.
|
||||
msg.duration = 1000u;
|
||||
// Priority 3 matches what the libretro header documents as
|
||||
// 'frontend-generated notifications' tier; shader compilation
|
||||
// is roughly that level of importance and we don't want to
|
||||
// outrank game-relevant messages with lower priority later.
|
||||
msg.priority = 3u;
|
||||
msg.level = RETRO_LOG_INFO;
|
||||
msg.target = RETRO_MESSAGE_TARGET_OSD;
|
||||
msg.type = RETRO_MESSAGE_TYPE_PROGRESS;
|
||||
msg.progress = static_cast<int8_t>(progress_pct);
|
||||
g_retro_environment_callback(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback for frontends without SET_MESSAGE_EXT. The text
|
||||
// already contains 'N/M', so the user gets the same information
|
||||
// (minus the progress widget).
|
||||
retro_message legacy = {};
|
||||
legacy.msg = text;
|
||||
// SET_MESSAGE measures duration in frames; assume the
|
||||
// ~60 fps NTSC throttle if the system isn't running yet (we're
|
||||
// most often called from CompileShaders during boot, before
|
||||
// System::GetThrottleFrequency() can return a real value).
|
||||
legacy.frames = 60u;
|
||||
g_retro_environment_callback(RETRO_ENVIRONMENT_SET_MESSAGE, &legacy);
|
||||
}
|
||||
|
||||
|
||||
void HostInterface::AddOSDMessage(std::string message, float duration /*= 2.0f*/)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue