commit b4fdef2ce5c88b4d8cad66eb3f1808f107cbab64
parent 589d0c85621ff33edf19e4c06ffd5967d33c8b37
Author: anon <anon@example.com>
Date: Sun, 18 Oct 2026 20:14:51 +0000
Filter half-size texture mip rows directly in C
Diffstat:
2 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/src/game/bbr.dll/lifted-0082.c b/src/game/bbr.dll/lifted-0082.c
@@ -8072,6 +8072,54 @@ void sub_25140DFB(void)
}
+ /* Half-size mip rows sample four 32-bit pixels with weights 63,64,64,64.
+ * Keep the filter's truncation and zero-sample mask. Yielding uses the
+ * general path so callbacks still observe its complete guest frame. */
+ if (!recomp_yield_hook && count && count < 16384 && bytes == 4 &&
+ (reader == 0x25141276 || reader == 0x2514132c) &&
+ !MEM32(context + 0x54) && !MEM32(context + 0x58) &&
+ MEM32(context + 0x5c) == count * 2 && pitch >= count * 8 &&
+ MEM32(context + 0x90) == 131072 && MEM32(context + 0xa8) == 65536 &&
+ !(MEM32(context + 0xac) & 65535) && row && row < height && row < 32768 && (int32_t)height > 0) {
+ uint64_t source_begin = (uint64_t)MEM32(context + 0x28) + (uint64_t)(row - 1) * pitch;
+ uint64_t source_end = source_begin + pitch + count * 8;
+ uint64_t output_end = (uint64_t)output + count * 4;
+ uint64_t context_end = (uint64_t)context + 0xbc;
+ if (source_begin && source_end <= 0x100000000ull && output_end <= 0x100000000ull &&
+ (output_end <= source_begin || output >= source_end) &&
+ (output_end <= context || output >= context_end) &&
+ (source_end <= context || source_begin >= context_end)) {
+ uint32_t mask = 0;
+ for (uint32_t x = 0; x < count; ++x) {
+ uint32_t address = (uint32_t)source_begin + x * 8;
+ uint32_t top_left = MEM32(address), top_right = MEM32(address + 4);
+ uint32_t bottom_left = MEM32(address + pitch), bottom_right = MEM32(address + pitch + 4);
+ if (reader == 0x2514132c) {
+ top_left |= 0xff000000; top_right |= 0xff000000;
+ bottom_left |= 0xff000000; bottom_right |= 0xff000000;
+ } else {
+ mask = !top_left | (!top_right << 1) | (!bottom_left << 2) | (!bottom_right << 3);
+ }
+ uint32_t red_blue = (top_left & 0x00ff00ff) * 63 +
+ ((top_right & 0x00ff00ff) + (bottom_left & 0x00ff00ff) + (bottom_right & 0x00ff00ff)) * 64;
+ uint32_t green_alpha = ((top_left >> 8) & 0x00ff00ff) * 63 +
+ (((top_right >> 8) & 0x00ff00ff) + ((bottom_left >> 8) & 0x00ff00ff) +
+ ((bottom_right >> 8) & 0x00ff00ff)) * 64;
+ MEM32(output + x * 4) = ((red_blue >> 8) & 0x00ff00ff) | (green_alpha & 0xff00ff00);
+ g_backedges += mask == 15 ? 5 : 9;
+ }
+ MEM32(context + 0xb4) = mask;
+ MEM32(context + 0xa8) = count * 131072 + 0x8001;
+ MEM32(context + 0xac) -= 0x7fff;
+ g_icall_count += count;
+ eax = output; ecx = mask == 15 ? 0 : 0x00ff00ff; edx = 4;
+ _flag_k = FK_DEC; _flag_a = 1; _flag_b = 1; _cf = 0;
+ RECOMP_FLAGS_OUT();
+ esp += 4;
+ RECOMP_REGS_OUT();
+ return;
+ }
+ }
/* The callback shares this frame, including arguments reused for the row cursor. */
struct {
uint32_t addresses[5], pixels[4], weights[4], bounds[4];
diff --git a/src/tests/texture_resampling.c b/src/tests/texture_resampling.c
@@ -139,4 +139,36 @@ int main(void)
}
}
+ const uint32_t mip_pixels[] = {
+ 0xff0000ff, 0x8000ff00, 0x01020304, 0, 0, 0,
+ 0x40ff0000, 0xffffffff, 0, 0, 0, 0
+ };
+ const uint32_t mip_expected[][3] = {
+ {0xae7f7f7e, 0, 0}, {0xfe7f7f7e, 0xfe000000, 0xfe000000}
+ };
+ for (unsigned opaque = 0; opaque < 2; ++opaque) {
+ memset((void *)ADDR(0x50000000), 0xa5, 0x20000);
+ memcpy((void *)ADDR(0x5000fffe), mip_pixels, sizeof(mip_pixels));
+ MEM32(0x50001020) = 32; MEM32(0x50001024) = 24;
+ MEM32(0x50001028) = 0x5000fffe;
+ MEM32(0x50001054) = 0; MEM32(0x50001058) = 0;
+ MEM32(0x5000105c) = 6; MEM32(0x50001060) = 2;
+ MEM32(0x50001090) = 131072;
+ MEM32(0x500010a8) = 65536; MEM32(0x500010ac) = 65536;
+ MEM32(0x500010b8) = opaque ? 0x2514132c : 0x25141276;
+ g_esp = 0x51010020;
+ MEM32(g_esp + 4) = 3; MEM32(g_esp + 8) = 0x50006000; MEM32(g_esp + 12) = 0x50001000;
+ recomp_yield_hook = NULL;
+ g_backedges = g_icall_count = 0;
+
+ sub_25140DFB();
+
+ for (unsigned x = 0; x < 3; ++x)
+ assert(MEM32(0x50006000 + x * 4) == mip_expected[opaque][x]);
+ assert(MEM32(0x500010b4) == (opaque ? 0 : 15));
+ assert(MEM32(0x500010a8) == 0x68001 && MEM32(0x500010ac) == 0x8001);
+ assert(g_backedges == (opaque ? 27 : 23) && g_icall_count == 3);
+ assert(g_eax == 0x50006000 && g_esp == 0x51010024);
+ assert(MEM32(0x50005ffc) == 0xa5a5a5a5 && MEM32(0x5000600c) == 0xa5a5a5a5);
+ }
}