From 53d3f8ea2ea0bc477f6a4b392defe7159e5ea3b0 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Mon, 2 Nov 2026 09:20:32 +0300 Subject: [PATCH] The 1.2.1 texture loader widens a texture's pool offset unsigned The loader keeps a texture's place in its pool as a 32-bit word (main+0xad4294) and widens it with a sign extend for nvnTextureBuilderSetStorage's offset (main+0xad43f0) and for SetPackagedTextureData's source (main+0xad440c). Past 2 GiB the offset turns negative and the storage lands 4 GiB below the pool (MacNativeGames ca311e2d, seen with a 4K texture pack's heap table in a 3.58 GiB pool). The shipped heap table keeps every pool far below 2 GiB, but TOTK_APP_POOL raised with such a pack's heap table (RomFS mods replace it) can reach it. The new patch set pooloff (TOTK_POOL_OFFSET_PATCH, on by default) widens unsigned: the same value below 2 GiB, right up to 4 GiB. 1.4.3 needs no patch: both of its loaders (main+0x583c34, main+0x27ed214) keep the offset in 64 bits (str x25 / mov x2, x25 / add x1, x25, x8). gen.py accepts both original words, and the lifted C at the sites reads the offset as uint32_t with the set on and as int32_t with it off. Co-Authored-By: Claude Opus 5.5 --- recomp/patches-v121.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index a68eb80a..2a5d1257 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -82,6 +82,17 @@ site aspect main 12521cc bd414260 f81f0fea @page:x10 bd403940 f84107ea # ldr s0 site aspect main 19b36f0 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) site aspect main 1ecdf68 1e211800 f81f0fea @page:x10 bd403940 f84107ea # fdiv s0, s0, s1 (viewport) +# Texture pool offsets past 2 GiB (MacNativeGames ca311e2d). The texture loader keeps a texture's place in its pool as a +# 32-bit offset (main+0xad4294: sub x25, x9, x10, stored as the word w25) and widens it as a signed number for +# nvnTextureBuilderSetStorage's offset and for SetPackagedTextureData's source (the pool's CPU address + offset). The +# shipped heap table keeps every pool far below 2 GiB; a texture pack's heap table with TOTK_APP_POOL raised can make +# one larger (MacNativeGames saw a 3.58 GiB pool), and every texture past 2 GiB then got storage 4 GiB below its pool. +# The offset is widened unsigned instead, the same value below 2 GiB, right up to 4 GiB. 1.4.3 needs no patch: its +# loaders (main+0x583c34, main+0x27ed214) keep the offset in 64 bits. +set pooloff TOTK_POOL_OFFSET_PATCH 1 +site pooloff main ad43f0 93407f22 2a1903e2 # sxtw x2, w25 -> mov w2, w25 (SetStorage offset) +site pooloff main ad440c 8b39c101 8b394101 # add x1, x8, w25, sxtw -> add x1, x8, w25, uxtw (packaged data source) + # Spin waits, from tools/spin_waits.py --exefs build/extracted/v121/exefs --patches recomp/patches-v121.txt: loops that only # another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), TOTK_SPIN=0 keeps the core. spin main ac600 ac620 ac630 # 13 instructions; loads