Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Breath of the Wild above 60 fps and above 1080p, with no game's const…
…ants in the host

Builds tell the loader which further stubs they have through main's rewriter table (ctx.keys of the stubs in the profile's patches.py):
VAR_STEP, RENDER_POOL and the base sizes VIEW_W / VIEW_H / OUTPUT_W / OUTPUT_H. The loader writes the state
page fields beyond +0x40 only for such a build, so AoC's +0x28 and TOTK's +0x8 are never touched and no heap
size or base width of one game is in the host. The page grows to 0x60 bytes. Breath of the Wild's stubs are in its patches.py; its main rewrites byte-identically to the previous patch_nso.py version of this change.

- Variable frame step (DM_FPS_TARGET 61 to 240, refused on a build without VAR_STEP): each frame the host
  publishes the time the previous one took as the VFR's frame ratio (state +0x50, main+0x151d484); the VFR
  override and prerendered movies keep the whole-vsync step. The display link runs at the cap (mode 4, with
  virtual ticks on a screen whose rate is not a multiple of it; no screen mode switch). Steps have no floor at
  the cap: at 120 on a 144 Hz screen a floor of 1/120 s ran the game at 1.12 of real time.
- Interval-stepped logic: the layout system's animation step (menus, HUD; main+0x1280ec8) and a fade
  (main+0x125f114) take the VFR's frame ratio in place of max(interval, 1); menus and the HUD ran at twice the
  speed at 120. Held buttons count the ratio (main+0xeb0f88): the inventory cursor repeated at twice the speed
  at 60 already. The physics step gets a ratio of at least 0.5 (main+0x128106c), three substeps, where two at
  120 blew ragdolls apart. Sites from MacNativeGames PR #103, checked by disassembly.
- Above 1080p (render scale up to 3.0, Mac only): the render buffer pool grows by the factor's square
  (main+0x106d328), the application pool, alias region and the game's fixed heaps by what it adds plus 64 MB
  (state +0x58: the stubs add it to the game's own sizes), and above 1.2 the output takes the views' size.
- The iOS launcher keeps 30 / 60: above 60 is not yet run on an iPhone (DM_FPS_TARGET in env.txt reaches it).

Mac (M2 Max, 144 Hz screen): 119.5 fps at 2560x1440 at the title and in the menus at 1.000 of real time, menus and
the inventory at normal speed; in the open world about 84 fps at 1440p and 74 at 4K with PR #62's implementation of
the same step (two physics substeps a frame at 120, three here; not measured again); at the profile's 60 fps 1.000 of real time. Red lines: BufferInitialize past the end of a pool when the
inventory opens, on main too; MemoryPoolInitialize without storage only at render scale 1.6, as with the first
implementation (PR #62). TOTK, AoC and
Paper Mario: their stubs are unchanged and their tables get no new rows (not run here).

The graphics tests that compile nvn_mtl.m and hle_nvn.c in one translation unit rename nvn_mtl.m's weak nvn_var_fps, as they do nvn_game_fps. dm/host/tests/t_heap_size.c and t_svc_memory.c, which compile hle_svc.c on their own, define dm_mem_extra (0: no render buffer pool grown), as loader.c does in the host.

On cae5ec2's memory layout: the extra goes into the alias size its boundary check (mem_init_once) validates as well as the layout, RESERVE and APP_POOL as before; the heap budget and the map limit take APP_POOL, so they include it.
  • Loading branch information
v0lumehi committed Oct 30, 2026
commit f1eae1e254360d52b0105ccecf8b4f9eff8952fc
4 changes: 3 additions & 1 deletion dm/games/01007EF00011E000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ No `tex_flush_upload` (a minute's boot saw it flush 32 CPU-filled textures with
- **Screens whose rate is not a multiple of 60 (from PR #27).** A cheap 50 ms frame shows 54.5 ms at 165 Hz; counted as late it kept the game at 20 fps for good, so the frame step lets a frame on time show one refresh longer than its hold (`shown_slack`, `nvn_fstep.h`).
- **Resolved: menu repeat twice as fast at 60 fps (2026-10-26).** `sead::ControllerBase::updateDerivativeParams_` (`main+0xeb0ef0`) adds a constant 1.0 (`main+0xeb0f78`..`88`) to each held button's count and repeats when `fmod(count - delay, pulse)` falls below that step, so delays and pulses were counted in frames: holding Down in the System menu for 0.3 s went 5 entries at 60 and 2 at 30 (found by MacNativeGames, `866beb9`). A `FRAME_STEP` stub at `main+0xeb0f88` takes the VFR's ratio (`+0x3c`, interval / 2) instead, keeping 1.0 when there is no VFR or the ratio is not positive. Mac, 60 fps: 0.2 / 0.3 / 0.4 s now move 1 / 2 / 3 entries, as the game does at 30. The pause menu's fast-repeat countdown (`main+0xe67d00`) already reads the VFR's delta.
- `DM_NVN_CUT` growing segments (64, 128, 256 … draws) were tried for fewer commits: the game fell from 60 to 30 fps in the same scene (GPU idle while the long last segments were encoded).
- **Above 60 fps** (`DM_FPS_TARGET=61`–`240` on a build whose rewriter table has `VAR_STEP`; not offered by the iOS launcher: not yet run on an iPhone): a variable frame step. Each frame the host publishes the time the previous one took as the VFR's frame ratio (in 30 fps frames, state page +0x50; stub at `main+0x151d484`), from which every per-core step is taken, so the game keeps real time at any frame rate; a scene that fixes its own interval (the VFR override) and prerendered movies keep the whole-vsync step. The display link runs at the cap (mode 4, `nvn_mtl.m` `link_range`; on a screen whose rate is not a multiple of it, virtual ticks at the cap) and each frame is shown on the next tick. Logic that stepped by the interval and not by the ratio ran at twice the speed at 120: the layout system's animation step (menus, title screen, HUD; `main+0x1280ec8`) and a fade (`main+0x125f114`) take max(interval, 1) × 0.5, and now the ratio; held buttons count 1.0 a frame (`main+0xeb0f88`), so the inventory cursor repeated at twice the speed at 60 already, and now count the ratio; the physics step runs round(6 × ratio) substeps (two at 120, where ragdolls blew apart) and gets at least 0.5, three. These sites come from MacNativeGames (PR #103) and were checked by disassembly. Steps have no floor at the cap: at 120 on a 144 Hz screen frames start 6.9 and 13.9 ms apart in turn, and a floor of 1/120 s ran the game at 1.12 of real time. On the Mac (M2 Max, 2560×1440): 119.5 fps at the title and in the menus at 1.000 of real time; in the open world about 84 fps at 1440p and 74 at 4K with the first implementation of the same step (PR #62), which ran two physics substeps a frame at 120 where this one runs three. Log: `variable frame step: … fps, game time … (… of real time)`.

### The game's own interval controller

Expand All @@ -46,7 +47,8 @@ Used at `DM_FPS_TARGET=0` and for the interval the framework keeps while the VFR

### Render scale

- `DM_RENDER_SCALE=0.5`–`1.0` (also from `Documents/env.txt`) fixes the 3D views at that fraction of 1600×900 docked (1280×720 handheld) and turns the game's dynamic resolution off; 1.0, the default, keeps it. Factors above 1.0 are refused by the loader (the per-frame texture pool's size is unknown).
- `DM_RENDER_SCALE=0.5`–`1.0` (also from `Documents/env.txt`) fixes the 3D views at that fraction of 1600×900 docked (1280×720 handheld) and turns the game's dynamic resolution off; 1.0, the default, keeps it. Factors above 1.0 below.
- **Above 1080p** (render scale above 1.0 on the Mac; the rewriter's table has `RENDER_POOL` and the base sizes `VIEW_W` / `VIEW_H`, `OUTPUT_W` / `OUTPUT_H`): 1.2 = 1920×1080, 1.6 = 2560×1440, 2.4 = 3840×2160 docked. gsys's 115 MB render buffer pool grows by the factor's square rounded up (stub at `main+0x106d328`, state +0x4c), and the application pool, the alias region and the game's fixed heaps around the pool (nninitStartup's at `main+0x71c`, the RootHeap at `main+0xc617c0`; the PlacementMgr heap failed before) grow by what the pool adds plus 64 MB (state +0x58, `hle_svc.c` `g_mem_extra`). Above 1.2 the output grows too: the game composed every frame into 1920×1080 display buffers, so the views were scaled down to them; its size global (`main+0x1e43dc0`) and the docked mode's output width, render size and window crop take the views' size (state +0x40 / +0x48). The loader writes these fields for a build whose table names them, so no game's constants are in the host. Not on iOS: the larger pool comes on top of the guest's address space, which iOS caps at a 6 GB reservation.
- The dynamic-resolution method (`main+0x12666e4`) keeps its scale in s8 (0.8–1.0 in 0.05 steps, `+0x1218`, `main+0x1266818`, or the forced 0.75 / 0.5 of `+0x284 & 0x1800`) and applies it from `main+0x1266880`: the views' scale (`+0x28a0` / `+0x28a4` = s8 × base width (`+0x1214`: 1600 docked, 1280 handheld) / output width), from which the size function (`main+0x106340c`) sizes the scene buffers each frame, the shader ratio `uking_dynamic_resolution_ratio` and the other readers (`main+0xc3c3f4`, an LOD check at `main+0x14126b4`). That block runs only when the dynamic path has just recomputed the scale (`+0x280` bit 4, set at `main+0x1266830`) or in a forced mode, else `main+0x126686c` skips it. The stub sets s8 at the block and, for a factor other than 1.0, takes the block every frame. A multiply in the size function (Tears of the Kingdom's way) would leave the ratio and those readers at the old scale.
- At 0.5 the 1600×900 passes become 800×450 and the 800×450, 400×225, 200×112 and 100×56 chains halve too, while the shadow maps and the 1920×1080 output keep their size and the HUD stays sharp. It holds in handheld mode (960×540 at 0.75). On the Mac (M4 Pro) the GPU time does not change (about 13 ms in the first shrine at 1.0 and at 0.5): a frame has about 650 passes, most of them tiny. Whether it helps an iPhone, whose GPU loads and stores each pass's attachments, is what the setting is for.

Expand Down
121 changes: 119 additions & 2 deletions dm/games/01007EF00011E000/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,130 @@ def frame_step(ctx):
emit(w)
emit(B(here(), 0xeb0f8c)) # back
fs_put(0xeb0f88, [B(0xeb0f88, start)], 'held-button counts step by the VFR ratio (menu repeat in game time at any frame step)')
# Variable frame step (VAR_STEP: a cap above 60, hle_nvn.c vstep_tick). VFR::updateInterval turns the interval into the frame ratio, the frame's length in 30 fps frames
# (interval / [+0x150], 2: 0.5 at 60 fps), keeps it at +0x30 and publishes it at +0x3c, from which every per-core step is taken (main+0x151d7e8: delta frames at +0x108,
# delta time at +0x138). The host's step (state +0x50: the time the last frame took, clamped) is published instead, except while the game's own override is set (cutscenes keep
# their steps); +0x30 keeps the interval's ratio for them. x9, x10 and s2 are dead at main+0x151d484 (w8 holds the changed flag stored next)
fs_site(0x151d484, '2020201e')
start = here(); emit(ADRP(9, here(), FS_STATE_OFF))
for w in (0x3940a66a, # ldrb w10,[x19,#0x29] the VFR's override
0x350000aa, # cbnz w10,orig (+5)
0xbd405122, # ldr s2,[x9,#0x50] the host's step (1/30 s units)
0x1e202048, # fcmp s2,#0.0
0x5400004d, # b.le orig (+2) not set
0x1e204041, # fmov s1,s2 published at +0x3c
0x1e202020): # orig: fcmp s1,s0
emit(w)
emit(B(here(), 0x151d488))
fs_put(0x151d484, [B(0x151d484, start)], 'VFR::updateInterval: the published frame ratio is the host\'s variable step (state page +0x50) when set, unless the game overrides its interval')
# Logic that steps by the interval rather than the frame ratio. The menus (title screen, inventory) and the HUD animated at twice the speed at 120 fps: the layout system's
# animation step is max(interval, 1) × 0.5 (main+0x1280ec8, the getter main+0x583118 reads the VFR's interval through its per-core pointers at +0x48) into +0xb20 of the
# layout system [main+0x1e374b8], and a fade adds max(interval, 1) × 0.5 × 0.2 a frame (main+0x125f114). Both take the VFR's frame ratio (+0x3c) × 2 in place of the interval,
# the same value at whole vsyncs and in cutscenes (ratio = interval / 2). Held buttons count the frame ratio through the stub above (main+0xeb0f88, held-button counts),
# so at the variable step too. The physics step
# (main+0x156f8e8, called from main+0x1281084 with the frame time and the ratio) runs round(6 × ratio) solver substeps: two at 120 fps, where staggered enemies' ragdolls blew
# apart; it gets at least 0.5, three substeps of half the length at 120 fps, as at 60. These sites were found by MacNativeGames (PR #103, games/totk/runtime/game_patches_botw.c)
# and checked here by disassembly. x9 at main+0x1280ecc and x8 at main+0x125f118 are set again before they are read; s9 is only read by the call's argument
for site, reg in ((0x1280ecc, 9), (0x125f118, 8)):
fs_site(site, '0000231e') # ucvtf s0,w0
start = here(); emit(ADRP(reg, here(), 0x1e93890)); emit(LDRX(reg, reg, 0x890 // 8)) # the VFR
emit(0xbd403c00 | reg << 5) # ldr s0,[xN,#0x3c] its frame ratio
emit(0x1e202800) # fadd s0,s0,s0 × 2: the interval it stands for (× 0.5 below)
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'interval step: the VFR\'s frame ratio × 2 in place of max(interval, 1) (UI animation / fade)')
fs_site(0x128106c, '0940201e') # fmov s9,s0
start = here()
for w in (0x1e2c1009, # fmov s9,#0.5
0x1e294809): # fmax s9,s0,s9 at least three physics substeps a frame
emit(w)
emit(B(here(), 0x1281070))
fs_put(0x128106c, [B(0x128106c, start)], 'physics step ratio at least 0.5 (three substeps)')
ctx.keys['VAR_STEP'] = 1
# Render scale above 1.0 (RENDER_POOL). gsys's render buffers (the scene's colour, depth, G-buffer and reduced buffers, gsys::RenderBufferContext) come from two 115 MB pools
# the graphics system makes at start (main+0xed5e70: a compressible texture pool and a virtual range for it), sized by the system's config +0x28, read from [x19+0x4d8] at
# main+0x106d328. Above a scale of about 1.3 the buffers no longer fitted: an allocation came back empty and RenderBufferContext crashed (main+0xed7128). The size is multiplied
# by the host's factor (state +0x4c: ceil(scale²), 0 = as is). x10 and x11 are dead there (x8 and x9 are stored next)
fs_site(0x106d328, '686e42f9')
start = here(); emit(ADRP(10, here(), FS_STATE_OFF))
for w in (0xb9404d4b, # ldr w11,[x10,#0x4c] pool factor
0xf9426e68, # ldr x8,[x19,#0x4d8] the pool size
0x3400004b, # cbz w11,+2 no factor
0x9b0b7d08): # mul x8,x8,x11
emit(w)
emit(B(here(), 0x106d32c))
fs_put(0x106d328, [B(0x106d328, start)], 'render buffer pool size × the host factor (state page +0x4c; 0 = the game\'s 115 MB)')
# The larger pool comes out of the heap the rest of the game shares: nninitStartup sets a fixed 0xc3000000 (3.05 GB, main+0x71c) whatever memory the system reports, and the
# RootHeap inside it is fixed too (0xc1000000, made at main+0xc617c0), so gsys::SystemTask and KingSystem grew inside a RootTask of the same size and PlacementMgr found no room
# for its 328 MB heap. Both grow by the bytes the host adds to the application pool for the larger pool (state +0x58, hle_svc.c mem_extra; 0 = the game's sizes)
fs_site(0x71c, '0060b852')
start = here(); emit(ADRP(16, here(), FS_STATE_OFF))
for w in (0xf9402e10, # ldr x16,[x16,#0x58] the bytes the host adds
0x52b86000, # mov w0,#0xc3000000 the game's heap
0x8b100000): # add x0,x0,x16
emit(w)
emit(B(here(), 0x720))
fs_put(0x71c, [B(0x71c, start)], 'nninitStartup heap size = the game\'s + the host\'s added bytes (state page +0x58)')
fs_site(0xc617c0, '0820b852')
start = here(); emit(ADRP(9, here(), FS_STATE_OFF))
for w in (0xf9402d29, # ldr x9,[x9,#0x58] the bytes the host adds
0x52b82008, # mov w8,#0xc1000000 the game's RootHeap
0x8b090108): # add x8,x8,x9
emit(w)
emit(B(here(), 0xc617c4))
fs_put(0xc617c0, [B(0xc617c0, start)], 'RootHeap size = the game\'s + the host\'s added bytes (state page +0x58)')
ctx.keys['RENDER_POOL'] = '0x7300000'
# Output size (OUTPUT_W / OUTPUT_H: state +0x40 u64 width | height << 32 and +0x48 float width, written by the loader where the 3D views outgrow 1920x1080; 0 = the game's).
# Docked, the game composes each frame into 1920x1080 display buffers whatever its 3D views render at, so a larger render scale was only supersampled down to 1080p. The size
# is a global (main+0x1e43dc0, set at three guarded inits, from which the window and its display buffers are made); the docked mode (main+0x12660bc) sets the output width
# (+0x1210, the divisor of the view scale above, so the 3D views stay at render scale × the docked base width 1600 at +0x1214), the system's render size (main+0x106dc70) and
# the window crop (main+0xe9af58). All four take the host's size; the handheld mode keeps 1280x720. Each stub only rewrites the register the site is setting (x4 at the crop
# holds the height, set just before)
for site in (0xc61ef4, 0xc61f28, 0x12618c4):
fs_site(site, '0987c0f2')
start = here(); emit(ADRP(9, here(), FS_STATE_OFF))
for w in (0xf9402129, # ldr x9,[x9,#0x40] the host's size
0xb5000069, # cbnz x9,+3
0xd280f009, # mov x9,#0x780 the game's 1920x1080
0xf2c08709): # movk x9,#0x438,lsl #32
emit(w)
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], 'output size global = the host\'s (state page +0x40; 0 = 1920x1080)')
fs_site(0x12660cc, '680a09f9'); fs_site(0x12660d4, '0887c0f2'); fs_site(0x1266104, '03f08052')
start = here()
emit(0xf9090a68) # str x8,[x19,#0x1210] the game's widths (1920.0, base 1600.0)
emit(ADRP(8, here(), FS_STATE_OFF))
for w in (0xb9404908, # ldr w8,[x8,#0x48] the host's width (float)
0x34000048, # cbz w8,+2
0xb9121268): # str w8,[x19,#0x1210]
emit(w)
emit(B(here(), 0x12660d0))
fs_put(0x12660cc, [B(0x12660cc, start)], 'docked output width = the host\'s (state page +0x48; 0 = 1920.0)')
start = here(); emit(ADRP(8, here(), FS_STATE_OFF))
for w in (0xf9402108, # ldr x8,[x8,#0x40]
0xb5000068, # cbnz x8,+3
0xd280f008, # mov x8,#0x780
0xf2c08708): # movk x8,#0x438,lsl #32
emit(w)
emit(B(here(), 0x12660d8))
fs_put(0x12660d4, [B(0x12660d4, start)], 'docked render size = the host\'s output size')
start = here(); emit(ADRP(3, here(), FS_STATE_OFF))
for w in (0xf9402063, # ldr x3,[x3,#0x40]
0xb4000083, # cbz x3,+4
0xd360fc64, # lsr x4,x3,#32 height
0x2a0303e3): # mov w3,w3 width
emit(w)
emit(B(here(), 0x1266108))
emit(0x5280f003) # mov w3,#0x780 the game's crop
emit(B(here(), 0x1266108))
fs_put(0x1266104, [B(0x1266104, start)], 'docked window crop = the host\'s output size')
ctx.keys.update(VIEW_W='0x640', VIEW_H='0x384', OUTPUT_W='0x780', OUTPUT_H='0x438') # docked 3D view base 1600x900, output 1920x1080
# Render scale (state +0x10, float written by the loader: DM_RENDER_SCALE, 1.0 by default; independent of the frame step). The dynamic-resolution method (main+0x12666e4) keeps a
# scale in 0.8–1.0 rounded to 0.05 steps (+0x1218, main+0x1266818), or the game's forced 0.75 / 0.5 (+0x284 & 0x1800), in s8; from main+0x1266880 it applies s8: each view's
# scale (+0x28a0 / +0x28a4 = s8 × base width (+0x1214: 1600 docked, 1280 handheld) / output width), from which the scene buffers are sized each frame (main+0x106340c), the
# shader ratio uking_dynamic_resolution_ratio and the other readers (main+0xc3c3f4, an LOD check at main+0x14126b4). Setting s8 there keeps them all consistent (a multiply in the
# size function, TOTK's way, would leave the ratio and those readers at the old scale). The apply block runs only when the dynamic path has just recomputed the scale (+0x280 bit 4,
# set at main+0x1266830) or in a forced mode, else main+0x126686c skips it; with a factor it is taken every frame, as in the dynamic mode, so the factor holds with dynamic
# resolution off too. Factors above 1.0 are refused by the loader: the per-frame texture pool's size is unknown. x8, s0, s1 and the flags are dead at both sites
# resolution off too. Factors above 1.0 grow the render buffer pool and the heaps around it (above). x8, s0, s1 and the flags are dead at both sites
fs_site(0x1266880, '88ae40f9'); fs_site(0x126686c, struct.pack('<I', B(0x126686c, 0x1266950)).hex())
apply = here(); emit(ADRP(8, here(), FS_STATE_OFF))
for w in (0xbd401100, # ldr s0,[x8,#0x10] render scale
Expand Down Expand Up @@ -117,7 +234,7 @@ def frame_step(ctx):
BINDING = [
{'what': 'interval controller: the lower bound and the GPU-time path', 'now': 'build', 'goal': 'game', 'purpose': 'frame rate',
'why': "sead::GameFrameworkNx's interval controller in this build; Tears of the Kingdom shares sead but not this code"},
{'what': '60 fps frame step and render scale (ksys::VFR)', 'now': 'build', 'goal': 'game', 'purpose': 'frame rate',
{'what': 'frame step (whole vsyncs and variable), render scale, output size, heaps and render buffer pool (ksys::VFR and the game setup code)', 'now': 'build', 'goal': 'game', 'purpose': 'frame rate',
'why': "the game's own frame code; the frame-step state page is general",
'blocked': 'frame-step stubs have no function-matched form yet'},
]
Loading