commit a6492ef640c2e7e8f10fd5683e287775a191453d
parent 48fc376015b74580411a5eb8e34dd8670b21fd32
Author: anon <anon@example.com>
Date: Sun, 18 Oct 2026 16:31:07 +0000
Preserve valid matrices for unchanged animation transforms
Diffstat:
3 files changed, 125 insertions(+), 0 deletions(-)
diff --git a/src/Makefile.linux b/src/Makefile.linux
@@ -236,6 +236,8 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric
./build/linux/water-ring
./build/linux/skinning
./build/linux/animation-initialization
+ ./build/linux/animation-transform
+ ./build/linux/animation-transform-paged
./build/linux/vertex-initialization
./build/linux/ground-height
./build/linux/tile-corners
@@ -593,3 +595,9 @@ build/linux/resolved-calls: build/portable/tests/resolved_calls.c runtime/guest_
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@
test: build/linux/resolved-calls
+
+build/linux/animation-transform build/linux/animation-transform-paged: tests/animation_transform.c game/bbr.dll/lifted-0032.c game/bbr.dll/lifted-0055.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+ @mkdir -p $(@D)
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(if $(filter %-paged,$@),-U__linux__) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
+
+test: build/linux/animation-transform build/linux/animation-transform-paged
diff --git a/src/game/bbr.dll/lifted-0032.c b/src/game/bbr.dll/lifted-0032.c
@@ -10037,6 +10037,12 @@ L_25096DD0:
_cf = (uint32_t)((uint32_t)(_flag_a + _flag_b) < (uint32_t)_flag_a);
ecx = ecx + 0x3Cu; /* 0x25096E0C: add ecx, 0x3c */
_flag_k = FK_ADD;
+ /* Keep an unchanged childless frame's already-valid matrix cache. */
+ uint32_t transform_frame = ecx;
+ int keep_transform_cache = !MEM8(ecx + 0x132) &&
+ !MEM32(ecx + 0x74) && MEM32(MEM32(ecx) + 0x2c) == 0x250e34e0 &&
+ !memcmp((const void *)ADDR(ecx + 0x78), (const void *)ADDR(edi), 12) &&
+ !memcmp((const void *)ADDR(ecx + 0x84), (const void *)ADDR(MEM32(ebp + 0xc)), 16);
edx = ecx + 0x78; /* 0x25096E0F: lea edx, [ecx + 0x78] */
eax = edi; /* 0x25096E12: mov eax, edi */
ebx = MEM32(eax); /* 0x25096E14: mov ebx, dword ptr [eax] */
@@ -10070,6 +10076,7 @@ L_25096DD0:
PUSH32(esp, 2); /* 0x25096E56: push 2 */
RECOMP_ICALL(MEM32(eax + 0x2C)); /* 0x25096E58: call dword ptr [eax + 0x2c] */
RECOMP_FLAGS_IN();
+ if (keep_transform_cache) MEM8(transform_frame + 0x132) = 0;
RECOMP_ICALL(0x2507F900u); /* 0x25096E5B: call 0x2507f900 */ /* not lifted */
RECOMP_FLAGS_IN();
eax = MEM32(eax + 0x718); /* 0x25096E60: mov eax, dword ptr [eax + 0x718] */
diff --git a/src/tests/animation_transform.c b/src/tests/animation_transform.c
@@ -0,0 +1,110 @@
+#include "recomp_types.h"
+#include <assert.h>
+
+void sub_25096DD0(void), sub_25096D20(void), sub_25096DC0(void), sub_250E34E0(void);
+static unsigned callbacks, custom_callbacks;
+static uint32_t callback_frames[4], callback_masks[4], callback_dirty[4];
+
+static void manager(void)
+{
+ g_eax = 0x50005000;
+ g_esp += 4;
+}
+
+static void invalidate(void)
+{
+ assert(callbacks < 4);
+ callback_frames[callbacks] = g_ecx;
+ callback_masks[callbacks] = MEM32(g_esp + 4);
+ callback_dirty[callbacks++] = MEM8(g_ecx + 0x132);
+ sub_250E34E0();
+}
+
+static void custom_invalidate(void)
+{
+ ++custom_callbacks;
+ invalidate();
+}
+
+recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
+recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
+recomp_func_t recomp_lookup(uint32_t address)
+{
+ switch (address) {
+ case 0x25096d20: return sub_25096D20;
+ case 0x25096dc0: return sub_25096DC0;
+ case 0x2507f900: return manager;
+ case 0x250e34e0: return invalidate;
+ case 1: return custom_invalidate;
+ default: abort();
+ }
+}
+
+static void test_transform(unsigned shape, unsigned dirty, unsigned changes, uint32_t value)
+{
+ memset((void *)ADDR(0x50000000), 0, 0x10000);
+ callbacks = custom_callbacks = 0;
+ uint32_t frame = 0x5000103c;
+ MEM32(0x50000028) = 0x50001000;
+ MEM32(frame) = MEM32(0x50002000) = 0x50003000;
+ MEM32(0x5000302c) = shape & 4 ? 1 : 0x250e34e0;
+ MEM32(frame + 0x6c) = shape & 1 ? 0x50004000 : 0;
+ MEM32(0x50004074) = shape & 1 ? frame : 0;
+ MEM32(frame + 0x74) = shape & 2 ? 0x50002000 : 0;
+ MEM8(frame + 0x132) = dirty;
+ MEM8(frame + 0x130) = 0x84;
+ MEM8(frame + 0x131) = 0x42;
+ for (unsigned i = 0; i < 3; i++) MEM32(frame + 0x78 + i * 4) = MEM32(0x50008000 + i * 4) = value;
+ for (unsigned i = 0; i < 4; i++) MEM32(frame + 0x84 + i * 4) = MEM32(0x50008020 + i * 4) = value;
+ if (changes & 1) MEM32(0x50008004) ^= 1;
+ if (changes & 2) MEM32(0x50008028) ^= 1;
+
+ /* An empty animation list keeps the real driver focused on the transform. */
+ MEM32(0x50005718) = 0x50006000;
+ MEM32(0x50000020) = 0x50007000;
+ MEM32(0x50007004) = 0x50007100;
+ MEM32(0x50007100) = 0x50007100;
+ g_ecx = 0x50000000;
+ g_esp = 0x5000ff00;
+ MEM32(g_esp + 4) = 0x50008000;
+ MEM32(g_esp + 8) = 0x50008020;
+ *(float *)ADDR(g_esp + 12) = .016f;
+ g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444;
+ g_fp_top = 8;
+
+ sub_25096DD0();
+
+ int keep_cache = !(shape & 6) && !dirty && !changes;
+ assert(MEM8(frame + 0x132) == (keep_cache ? 0 : (dirty | 3)));
+ assert(MEM8(frame + 0x130) == 0x87 && MEM8(frame + 0x131) == 0x42);
+ assert(!memcmp((void *)ADDR(frame + 0x78), (void *)ADDR(0x50008000), 12));
+ assert(!memcmp((void *)ADDR(frame + 0x84), (void *)ADDR(0x50008020), 16));
+ assert(callbacks == (shape & 2 ? 4 : 2));
+ assert(custom_callbacks == (shape & 4 ? callbacks : 0));
+ assert(callback_frames[0] == frame && callback_masks[0] == 1 && callback_dirty[0] == dirty);
+ unsigned second = shape & 2 ? 2 : 1;
+ assert(callback_frames[second] == frame && callback_masks[second] == 2 && callback_dirty[second] == (dirty | 1));
+ if (shape & 2) {
+ assert(callback_frames[1] == 0x50002000 && callback_masks[1] == 1);
+ assert(callback_frames[3] == 0x50002000 && callback_masks[3] == 2);
+ assert(MEM8(0x50002132) == 3 && MEM8(0x50002130) == 3);
+ }
+ assert(g_eax == UINT32_MAX && g_esp == 0x5000ff10);
+ assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444);
+ assert(g_fp_top == 8);
+}
+
+int main(void)
+{
+ assert(guest_map("animation transform fixture", 0x50000000, 0x10000));
+ assert(guest_map("animation transform constants", 0x25150000, 0x10000));
+ *(float *)ADDR(0x25152c10) = 1000;
+ *(double *)ADDR(0x25152f28) = .5;
+ const uint32_t values[] = {0, 0x80000000, 0x3f800000, 0x7fc00001};
+ for (unsigned shape = 0; shape < 8; shape++)
+ for (unsigned dirty = 0; dirty < 16; dirty++)
+ for (unsigned changes = 0; changes < 4; changes++)
+ for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++)
+ test_transform(shape, dirty, changes, values[i]);
+ puts("animation transform: 2048 driver cases preserve callbacks, dirty flags and guest ABI");
+}