commit 83d91c4561ac88ad61615992cfc423769ab7c9d0
parent 78ca38f7493a52a1c4fdd6691cdcc2e643a94eed
Author: anon <anon@example.com>
Date: Fri, 16 Oct 2026 22:33:06 +0000
Drain the frame-start network queue to avoid starving scene readiness
Diffstat:
4 files changed, 111 insertions(+), 6 deletions(-)
diff --git a/src/Makefile.linux b/src/Makefile.linux
@@ -222,6 +222,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric
./build/linux/fpu-stack
./build/linux/water-ring
./build/linux/tile-corners
+ ./build/linux/network-queue
./build/linux/vertex-upload
./build/linux/vertex-upload-paged
./build/linux/guest-memory
@@ -440,3 +441,9 @@ build/linux/vertex-upload build/linux/vertex-upload-paged: tests/vertex_upload.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(if $(filter %-paged,$@),-U__linux__) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
test: build/linux/vertex-upload build/linux/vertex-upload-paged
+
+build/linux/network-queue: tests/network_queue.c game/ffr.dll/lifted-0000.c game/ffr.dll/lifted-0001.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+ mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
+
+test: build/linux/network-queue
diff --git a/src/game/ffr.dll/lifted-0000.c b/src/game/ffr.dll/lifted-0000.c
@@ -8315,6 +8315,7 @@ L_2F00333A:
}
void sub_2F003350(void) {
+ uint32_t queued_messages;
int _fpu_cmp = 0;
uint32_t _cf = 0;
int _df = 1;
@@ -8429,6 +8430,8 @@ L_2F00341B:
RECOMP_ICALL(MEM32(0x2F013014)); /* 0x2F003424: call dword ptr [0x2f013014] */
RECOMP_FLAGS_IN();
eax = MEM32(esi + 0xB4); /* 0x2F00342A: mov eax, dword ptr [esi + 0xb4] */
+ /* Drain the frame-start queue; arrivals during dispatch wait for the next frame. */
+ queued_messages = eax;
/* test eax, eax */ /* 0x2F003430: test eax, eax */
_flag_a = (uint32_t)(eax); _flag_b = (uint32_t)(eax);
_cf = 0;
@@ -8443,12 +8446,11 @@ L_2F003439:
_flag_a = (uint32_t)(ebx); _flag_b = (uint32_t)(1);
ebx = ebx + 1; /* 0x2F00343B: inc ebx */
_flag_k = FK_INC;
- /* cmp eax, 0xAu */ /* 0x2F00343C: cmp eax, 0xa */
- _flag_a = (uint32_t)(eax); _flag_b = (uint32_t)(0xAu);
+ _flag_a = (uint32_t)(eax); _flag_b = queued_messages;
_cf = (uint32_t)CMP_B(_flag_a, _flag_b);
_flag_k = FK_CMP;
MEM32(ebp + (-0x10)) = ebx; /* 0x2F00343F: mov dword ptr [ebp - 0x10], ebx */
- if (CMP_G(_flag_a, _flag_b)) goto L_2F00349C; /* 0x2F003442: jg 0x2f00349c */
+ if (CMP_AE(_flag_a, _flag_b)) goto L_2F00349C;
L_2F003444:
eax = MEM32(esi + 0xB0); /* 0x2F003444: mov eax, dword ptr [esi + 0xb0] */
ecx = MEM32(eax); /* 0x2F00344A: mov ecx, dword ptr [eax] */
diff --git a/src/game/ffr.dll/lifted-0001.c b/src/game/ffr.dll/lifted-0001.c
@@ -7983,6 +7983,7 @@ L_2F006C40:
}
void sub_2F006C50(void) {
+ uint32_t queued_messages;
int _fpu_cmp = 0;
uint32_t _cf = 0;
int _df = 1;
@@ -8098,6 +8099,8 @@ L_2F00341B:
RECOMP_ICALL(MEM32(0x2F013014)); /* 0x2F003424: call dword ptr [0x2f013014] */
RECOMP_FLAGS_IN();
eax = MEM32(esi + 0xB4); /* 0x2F00342A: mov eax, dword ptr [esi + 0xb4] */
+ /* Drain the frame-start queue; arrivals during dispatch wait for the next frame. */
+ queued_messages = eax;
/* test eax, eax */ /* 0x2F003430: test eax, eax */
_flag_a = (uint32_t)(eax); _flag_b = (uint32_t)(eax);
_cf = 0;
@@ -8112,12 +8115,11 @@ L_2F003439:
_flag_a = (uint32_t)(ebx); _flag_b = (uint32_t)(1);
ebx = ebx + 1; /* 0x2F00343B: inc ebx */
_flag_k = FK_INC;
- /* cmp eax, 0xAu */ /* 0x2F00343C: cmp eax, 0xa */
- _flag_a = (uint32_t)(eax); _flag_b = (uint32_t)(0xAu);
+ _flag_a = (uint32_t)(eax); _flag_b = queued_messages;
_cf = (uint32_t)CMP_B(_flag_a, _flag_b);
_flag_k = FK_CMP;
MEM32(ebp + (-0x10)) = ebx; /* 0x2F00343F: mov dword ptr [ebp - 0x10], ebx */
- if (CMP_G(_flag_a, _flag_b)) goto L_2F00349C; /* 0x2F003442: jg 0x2f00349c */
+ if (CMP_AE(_flag_a, _flag_b)) goto L_2F00349C;
L_2F003444:
eax = MEM32(esi + 0xB0); /* 0x2F003444: mov eax, dword ptr [esi + 0xb0] */
ecx = MEM32(eax); /* 0x2F00344A: mov ecx, dword ptr [eax] */
diff --git a/src/tests/network_queue.c b/src/tests/network_queue.c
@@ -0,0 +1,94 @@
+#include "recomp_types.h"
+#include <assert.h>
+
+void sub_2F003350(void);
+void sub_2F006C50(void);
+static unsigned processed;
+static int locked;
+
+static void append(unsigned message)
+{
+ uint32_t node = 0x50002000 + message * 16;
+ uint32_t tail = MEM32(0x50001004);
+ MEM32(node) = 0x50001000;
+ MEM32(node + 4) = tail;
+ MEM32(node + 8) = message;
+ MEM32(tail) = node;
+ MEM32(0x50001004) = node;
+ ++MEM32(0x500000B4);
+}
+
+static void enter(void)
+{
+ assert(!locked && MEM32(g_esp + 4) == 0x500000B8);
+ locked = 1;
+ g_esp += 8;
+}
+static void leave(void)
+{
+ assert(locked && MEM32(g_esp + 4) == 0x500000B8);
+ locked = 0;
+ g_esp += 8;
+}
+static void delete_node(void)
+{
+ assert(locked);
+ assert(MEM32(g_esp + 4) == 0x50002000 + (processed + 1) * 16);
+ g_esp += 4;
+}
+static void process(void)
+{
+ assert(!locked && g_ecx == 0x50000000);
+ assert(MEM32(g_esp + 4) == ++processed);
+ /* Simulate a producer appending while the consumer releases the lock. */
+ if (processed == 1) append(17);
+ g_esp += 8;
+}
+
+recomp_func_t recomp_lookup(uint32_t address)
+{
+ switch (address) {
+ case 0xF0000001: return enter;
+ case 0xF0000002: return leave;
+ case 0x2F0116B4: return delete_node;
+ case 0x2F001DB0: return process;
+ default: fprintf(stderr, "Unexpected network-queue call %08x\n", address); abort();
+ }
+}
+recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); }
+recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
+
+int main(void)
+{
+ assert(guest_map("network client", 0x50000000, 0x20000));
+ assert(guest_map("network globals", 0x2F010000, 0x10000));
+ recomp_func_t entries[] = {sub_2F003350, sub_2F006C50};
+ for (unsigned entry = 0; entry < 2; ++entry) {
+ MEM32(0x2F013014) = 0xF0000001;
+ MEM32(0x2F013058) = 0xF0000002;
+ MEM32(0x2F01F018) = 0x50000000;
+ MEM8(0x50000088) = 1;
+ MEM32(0x500000B0) = 0x50001000;
+ MEM32(0x500000B4) = 0;
+ MEM32(0x50001000) = MEM32(0x50001004) = 0x50001000;
+ for (unsigned i = 1; i <= 16; ++i) append(i);
+ processed = 0;
+ for (unsigned frame = 0; frame < 3; ++frame) {
+ g_fs_base = 0x5001E000;
+ MEM32(g_fs_base) = 0xFFFFFFFF;
+ g_esp = 0x5001FF00; g_ecx = 0x50000000;
+ g_ebx = 123; g_esi = 234; g_edi = 345; g_ebp = 456;
+
+ entries[entry]();
+
+ assert(processed == (frame == 0 ? 16 : 17));
+ assert(MEM32(0x500000B4) == (frame == 0 ? 1 : 0));
+ assert(MEM32(0x50001000) == (frame == 0 ? 0x50002110 : 0x50001000));
+ assert(!locked);
+ assert(g_esp == 0x5001FF04);
+ assert(g_ebx == 123 && g_esi == 234 && g_edi == 345 && g_ebp == 456);
+ assert(MEM32(g_fs_base) == 0xFFFFFFFF);
+ }
+ }
+ puts("network queue: frame snapshot, FIFO, deferred arrival, empty queue, locks and ABI passed");
+}