mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 11:09:56 -04:00
Let a destroyed vsync event give its slot when the vsync list is full, instead of ending the process on the 17th.
gfx_vsync_bind kept every SystemEventType address the game ever passed to GetDisplayVsyncEvent, never dropped one, and called rt_fatal on the 17th distinct address. A destroyed event also stayed on the list the vsync thread signals 60 times a second. kernel.c now exports kern_system_event_live (mapped guest memory with a nonzero state byte), and with the list full gfx_vsync_bind gives the first slot whose event is no longer live to the new one, which also takes the destroyed event off the vsync thread's list; it stays fatal only when all 16 are live. Each new listing logs "gfx: vsync event ... bound in slot N, M listed", so a long session's log shows how often new addresses come. Not reproduced before the change: the fresh 0.10.0 session's system event count stayed at 9-10 across its area loads, and no log here covers returns to the title. tests/vsync_bind_check.py cuts gfx_vsync_bind from gfx_present.c with a stub liveness check: a 17th event takes the first destroyed slot, an 18th the next, and with 16 live events the 17th still ends with the fatal. system_event_check now also checks kern_system_event_live. The compile check of every runtime file passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -289,15 +289,29 @@ static void vsync_ensure(void) {
|
||||
plat_rmutex_unlock(&g_start_lock);
|
||||
}
|
||||
|
||||
// Lists a vsync event the vsync thread signals. With the list full, an event the game destroyed since
|
||||
// (kern_system_event_live 0: its state byte is 0 or its memory is gone) gives its slot, which also stops the vsync
|
||||
// thread signalling it; the list ends the process only when all 16 are live. Each new listing is logged, so a long
|
||||
// session's log shows how often the game asks for a vsync event at a new address.
|
||||
void gfx_vsync_bind(uint64_t system_event) {
|
||||
plat_mutex_lock(&g_vs_lock);
|
||||
int have = 0;
|
||||
for (int i = 0; i < g_vs_nev; i++) have |= g_vs_ev[i] == system_event;
|
||||
int slot = g_vs_nev;
|
||||
if (!have) {
|
||||
if (g_vs_nev == 16) rt_fatal("gfx: more than 16 vsync events");
|
||||
g_vs_ev[g_vs_nev++] = system_event;
|
||||
if (slot == 16) {
|
||||
slot = 0;
|
||||
while (slot < 16 && kern_system_event_live(g_vs_ev[slot])) slot++;
|
||||
if (slot == 16) rt_fatal("gfx: more than 16 live vsync events");
|
||||
} else {
|
||||
g_vs_nev++;
|
||||
}
|
||||
g_vs_ev[slot] = system_event;
|
||||
}
|
||||
int listed = g_vs_nev;
|
||||
plat_mutex_unlock(&g_vs_lock);
|
||||
if (!have)
|
||||
rt_log("gfx: vsync event %#llx bound in slot %d, %d listed", (unsigned long long)system_event, slot, listed);
|
||||
vsync_ensure();
|
||||
}
|
||||
|
||||
|
||||
@@ -358,6 +358,7 @@ void kern_event_clear(uint32_t writable); // server-side clear
|
||||
void kern_bind_system_event(Cpu *c, uint64_t ev, int autoclear); // guest thread only
|
||||
void kern_signal_system_event(uint64_t ev); // any thread
|
||||
void kern_clear_system_event(uint64_t ev); // any thread; a bound, live event only
|
||||
int kern_system_event_live(uint64_t ev); // in mapped guest memory, its state byte nonzero
|
||||
int kern_svc(Cpu *c, uint32_t imm); // thread/sync SVCs; 1 if handled
|
||||
uint64_t kern_now_ns(void);
|
||||
extern uint64_t rt_guest_start_ns; // kern_now_ns when the guest started (boot.c), 0 before
|
||||
|
||||
@@ -2259,6 +2259,10 @@ void kern_clear_system_event(uint64_t ev) {
|
||||
if (se_find(ev, NULL) && se_live(ev)) system_event_set(ev, 0);
|
||||
}
|
||||
|
||||
// A SystemEventType that still holds an event: mapped guest memory with its state byte nonzero. For services that keep
|
||||
// their own lists of bound events and reuse the slots of destroyed ones (gfx_present.c gfx_vsync_bind).
|
||||
int kern_system_event_live(uint64_t ev) { return mem_readable(ev + SE_STATE, 1) && se_live(ev); }
|
||||
|
||||
// ---- fibers
|
||||
// The SDK switches fibers by swapping register context, which breaks "RET = C return". Each guest fiber gets a host
|
||||
// fiber (own 256 MiB reserved host stack) and its own Cpu, so a suspended fiber's registers and host frames stay
|
||||
|
||||
Reference in New Issue
Block a user