Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
games/upscaler: a profile can make MetalFX the default for the game's…
… own upscaler

DM_UPSCALER=metalfx draws a game's NDSR upscaler shaders with MetalFX's spatial scaler, but only when the player picks it: the default was the game's network for every game. Ocarina of Time was measured faster with it (PR #1459 and its follow-up): on an M4 Pro, kokiri-deck, DM_UPSCALER=metalfx took the frame's GPU p50 from 17.15 to 15.79 ms, and on an M2 Air the upscale from 2.50 to 1.31-1.38 ms. The picture was not washed out; the edges are softer.

The new profile key upscaler (game, the default, or metalfx) becomes DM_GAME_UPSCALER in the profile header. The host's up_mfx_on falls back to it when DM_UPSCALER is unset or not one of the two values (a red line names the bad value), and its log line says whether DM_UPSCALER or the profile chose MetalFX. The launcher's Game's upscaler row takes it as its default. game.py refuses metalfx for a profile whose shader map holds no upscaler shaders, since there would be nothing to replace. Ocarina of Time sets it, so players who never changed the setting move to MetalFX on that game, as a changed tested default does (docs/frontends.md, Saved choices); a saved choice or DM_UPSCALER=game keeps the network. The default applies on iOS too; it was measured on the Mac only.

Checked: test_game_profile.py and test_settings.py (the macro, its validation, the setting's default for Ocarina of Time), test_launcher_settings.py, test_docs.py, docs_patches.py --check, and make -C dm/gfx/tests check_t_upscaler_mfx with GAME=0400486024DEC000 and GAME=040074A01BF12000, which now also runs with DM_UPSCALER unset and with an unknown value: both follow the profile (MetalFX on Ocarina of Time, the game's shader on Donkey Kong Bananza), the test's expectation taken from DM_GAME_UPSCALER. The shader chain is unchanged.
  • Loading branch information
Esteban-V committed Nov 14, 2026
commit f0dafa530dfdfddd8aab90157cc49657d539129b
3 changes: 2 additions & 1 deletion dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A Switch 2 game: update v131072, SDK 22.2.8 (`Ounce`). Nintendo EPD's engine (se
| `tex_flush_upload on`, `tex_dirty_upload on` | `game.tsv` | as Tears of the Kingdom: the CPU writes the terrain tiles' height (R32F), blend and hole (RGBA8) maps into textures after creating them. Without the keys those textures stay zero: flat blue holes in the ground around the path with grass floating in them, and grey stone where the console shows dirt |
| `shader_groups`, `shader_note` | `game.tsv` | shaders grouped as `/Shader/`, `/Effect/`, `/Lib/`, `/UI/` |
| `pad_layout full` | `game.tsv` | a 3D field and both sticks |
| `upscaler metalfx` | `game.tsv` | the game's NDSR network drawn by MetalFX's spatial scaler by default (the launcher's Game's upscaler; `DM_UPSCALER=game` keeps the network): M4 Pro GPU p50 17.15 → 15.79 ms, softer edges. Also the default on iOS, measured on the Mac only ([Found on this game](#found-on-this-game)) |

Render conditions, which the host evaluates for every game ([Conditional rendering evaluated at replay](../../../docs/reference/rendering.md#conditional-rendering-evaluated-at-replay); until 2026-11-12 the profile key `render_cond`): agl clears a copy of the prepass depth again under a render condition the console skips. Run unconditionally, the opaque pass's `EQUAL` test fails everywhere ([PR 1299](https://github.com/seedds/nxnative/pull/1299)'s finding).

Expand Down Expand Up @@ -138,7 +139,7 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
- [A long render pass split while the GPU has nothing](../../../docs/reference/frame-rate.md#a-long-render-pass-split-while-the-gpu-has-nothing): the GPU idled about 0.3 ms a frame inside the scene passes (500–800 draws) on an M1 ([PR #2560](https://github.com/seedds/nxnative/pull/2560), measured in another tree); not measured with this host.
- [A frame standing in the present queue after a late frame](../../../docs/reference/frame-rate.md#a-frame-standing-in-the-present-queue-after-a-late-frame): fixed. With the display link on an M2 Pro's ProMotion screen, the title screen at the 30 fps cap in a window showed frames 115.4 ms after the game queued them, 65.4 ms with the drain and the 60 Hz link; in game at the 60 setting, 82-102 ms became 65-70 ms.
- [Frames pile up for the screen at a cap the game holds, without the display link](../../../docs/reference/frame-rate.md#frames-pile-up-for-the-screen-at-a-cap-the-game-holds-without-the-display-link): fixed. With `DM_PRESENT_LINK=0` on the M2 Air, fullscreen, at the 30 fps cap frames reached the screen 109-155 ms after the game queued them; with the screen wait, 57-65 ms, with frame times unchanged (33.3 ms).
- [A game's own upscaler drawn by MetalFX](../../../docs/reference/rendering.md#a-games-own-upscaler-drawn-by-metalfx): resolved. `DM_UPSCALER=metalfx` did nothing here, because its networks are in `agl_ndsr_vr.pck` and `agl_ndsr_vr_light.pck`, which the profile's upscaler keys left out ([issue #1911](https://github.com/seedds/nxnative/issues/1911)). They are named now, as every NDSR pack's compute shaders are: 61 keys, 22 of them `agl_ndsr.pck`'s, which the game ships and does not run, and 2 of the pack inside the movie file, which their code keeps. The network the game runs reads square roots in RGB9E5 and writes R11G11B10F (1440x810 → 1920x1080 handheld), so both copies around MetalFX stay. On an M2 Air the upscale took 1.31-1.38 ms instead of 2.50, and the frame p50 25.5-26.7 ms instead of 27.5-28.2 ([PR #1459](https://github.com/seedds/nxnative/pull/1459), a host before PR #2559). On the M4 Pro (`kokiri-deck`, one run a side, a host on chain `0c434f1b68df` with this change, 2026-11-14) the GPU p50 went from 17.15 to 15.79 ms (mean 16.47 to 15.43), both held at 30 fps by the frame step; the picture's means at the same spot, on frames a little apart, were 38.5 / 33.8 / 16.8 of 255 with the network and 41.1 / 37.4 / 19.4 with MetalFX (darkest 5 %: 4.3 against 7.0), not washed out. The edges are softer than the network's, as the spatial scaler draws them; the game's network stays the default.
- [A game's own upscaler drawn by MetalFX](../../../docs/reference/rendering.md#a-games-own-upscaler-drawn-by-metalfx): resolved. `DM_UPSCALER=metalfx` did nothing here, because its networks are in `agl_ndsr_vr.pck` and `agl_ndsr_vr_light.pck`, which the profile's upscaler keys left out ([issue #1911](https://github.com/seedds/nxnative/issues/1911)). They are named now, as every NDSR pack's compute shaders are: 61 keys, 22 of them `agl_ndsr.pck`'s, which the game ships and does not run, and 2 of the pack inside the movie file, which their code keeps. The network the game runs reads square roots in RGB9E5 and writes R11G11B10F (1440x810 → 1920x1080 handheld), so both copies around MetalFX stay. On an M2 Air the upscale took 1.31-1.38 ms instead of 2.50, and the frame p50 25.5-26.7 ms instead of 27.5-28.2 ([PR #1459](https://github.com/seedds/nxnative/pull/1459), a host before PR #2559). On the M4 Pro (`kokiri-deck`, one run a side, a host on chain `0c434f1b68df` with this change, 2026-11-14) the GPU p50 went from 17.15 to 15.79 ms (mean 16.47 to 15.43), both held at 30 fps by the frame step; the picture's means at the same spot, on frames a little apart, were 38.5 / 33.8 / 16.8 of 255 with the network and 41.1 / 37.4 / 19.4 with MetalFX (darkest 5 %: 4.3 against 7.0), not washed out. The edges are softer than the network's, as the spatial scaler draws them; MetalFX is the profile's default (`upscaler metalfx`).
- [An upscaler's colour read from its code](../../../docs/reference/rendering.md#an-upscalers-colour-read-from-its-code): resolved, the square-rooted shape. Of the 37 compute shaders of the `_vr` packs, 18 networks (`fa3033d05c0a41d6`, `d99fbeeb53d38847`, `04135bb812a0d66e`, `aad7ea7e5c02f41d`, `b106afba1a18faa9` among them) are drawn with their input squared; 12 networks that encode after the square and 7 pre-passes keep their shader. Only the `_vr_light` networks have been seen in play; the colour of the 10 in `_vr` is read from their code only.
- [Pipeline archive files left behind by a major system update](../../../docs/reference/shaders.md#pipeline-archive-files-left-behind-by-a-major-system-update): resolved ([pull request #2539](https://github.com/seedds/nxnative/pull/2539)). After macOS 26.6.2 to 27.2.1 on an M1 Pro, 57 archive files (1.68 GB) were refused at every start and the prebuild was taken as done, so its bases were built at the draws (53 stalls, 39 s, in 24 minutes); the refused files and the stamp now go, and the next start runs the prebuild again (13.4 minutes for the 34,649 pairs on an empty archive, once).
- [A submission's commit read the whole storage-write page set](../../../docs/reference/frame-rate.md#a-submissions-commit-read-the-whole-storage-write-page-set): resolved. About 30 commits a frame each read the 16,384-slot set of pages its storage buffers wrote (256 KB); standing on the Kokiri Forest deck the submit thread went from 42.8–43.9k to 38.7–39.3k instructions per draw (M4 Pro, 640 draws a frame), with no change in frame time, which waits for the GPU there.
Expand Down
2 changes: 2 additions & 0 deletions dm/games/0400486024DEC000/game.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fps_target 60

# ---- Graphics ----
draw_barriers game
# The game's NDSR network drawn by MetalFX's spatial scaler by default (the launcher's Game's upscaler; DM_UPSCALER=game keeps the game's): on an M4 Pro the frame's GPU time 17.15 -> 15.79 ms
upscaler metalfx
# As Tears of the Kingdom: the terrain's height, blend and hole maps are written by the CPU into textures after they are created. Without these keys they stay zero: holes in the ground and the wrong materials
tex_flush_upload on
tex_dirty_upload on
1 change: 1 addition & 0 deletions dm/games/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ One row per profile; the notes are each profile's `README.md`.
| `pso_mtl4` | `on` / `off` (the default): on iOS, render pipelines through MTL4Compiler by default, with the pipeline archive, the prepare step, the hybrid pipelines and the prebuild (on by default on the Mac; `DM_PSO_MTL4=1` / `0` overrides). A setting the game was tested with on an iPhone. It also gives the app the [pipeline archive made offline](../../docs/development.md#the-pipeline-archive-made-offline) (`build_ipa.sh` builds it for the `pso_gpu` key's list when present, else for `g18p`, unless `DM_PSO_GPUS` says otherwise). An iOS build carries the pulling libraries (`_bp`) whatever this key says, since the launcher's Metal 4 pipelines toggle can turn the path on. Profiles with `pso_mtl4 off` get no archive unless a build override selects one. Breath of the Wild sets it on |
| `pso_gpu` | Optional, whitespace-separated GPU architectures: the ones the [pipeline archive made offline](../../docs/development.md#the-pipeline-archive-made-offline) is made for when the profile also sets `pso_mtl4 on`. The bases are made per GPU family and each family's archive costs its own `metal-tt` run, so a profile names exactly the devices it serves. 1-4 tokens, each alphanumeric, with or without the `applegpu_` prefix (for example `g18p applegpu_g19p`); `none` is not a value. Without this key, `pso_mtl4 on` keeps the A19 / A19 Pro default `g18p`; `pso_mtl4 off` gets no archive. The `DM_PSO_GPUS` switch / the NSP script's `--gpu` overrides the archive selection; this key does not enable Metal 4 pipelines |
| `enc_thread` | `on` / `off` (the default): on the Mac, Metal encoding on its own thread by default, as on iOS for every game (`nvn_rec.h` `rec_on`; `DM_NVN_ENC_THREAD=1` / `0` and the launcher's Encode thread override it). For a game that waits on its fence every frame, whose submit thread would otherwise also encode before the wait: Need for Speed: Hot Pursuit Remastered's 60 fps frame took 18.1 ms with encoding on the submit thread and 16.7 on its own |
| `upscaler` | `game` (the default) / `metalfx`: the launcher's **Game's upscaler** by default, for a game whose shader map holds its own upscaler shaders (agl's NDSR network; `game.py` refuses `metalfx` without them). `metalfx` draws them with MetalFX's spatial scaler (`nvn_mtl.m` `up_mfx_on`); `DM_UPSCALER=game` / `metalfx`, the launcher and `env.txt` override it. A setting the game was measured with, the default on the Mac and iOS alike: Ocarina of Time sets it, its frame's GPU time 17.15 → 15.79 ms on an M4 Pro (measured on the Mac only) |
| `fps_target` | Frame rate cap of the rewriter's frame step, for builds that have one (`FRAME_STEP` in the profile's `patches.py`: Tears of the Kingdom 1.4.3, Breath of the Wild 1.9.0, Hyrule Warriors: Age of Calamity 1.3.0, Paper Mario: The Thousand-Year Door 1.0.1, ASTRAL CHAIN 1.0.1), or the engine's own frame limit the host writes into game memory (`hle_fpslock.c`: Monster Hunter Rise 16.0.2, which also needs `present_interval display`; any Unreal Engine 4.2x / 5 build, its `t.MaxFPS` (or `ue_fps_cvar`) and `rhi.SyncInterval` or `nvn.SyncInterval`, found by name by the rewriter, so the game asks for present interval 1 itself, and its fixed frame rate `GEngine->FixedFrameRate`, found by its reflection entry and written while the engine's `bUseFixedFrameRate` is set (DRAGON BALL: Sparking! ZERO's battles, Pikmin 4); Luigi's Mansion 3 1.4.0, its frame limiter's milliseconds per frame, with `present_interval display`; Pokémon Brilliant Diamond 1.3.0, Unity's integer `Application.targetFrameRate`, also with `present_interval display`; EA SPORTS FC 27, Frostbite's simulation rate, found by name on any build, and on 1.8d.310c its frame regulator, also with `present_interval display`; Fire Emblem Fortune's Weave, a target frame rate the game steps by, found by its readers on any build, so the game asks for present interval 1 itself). `0` (the default): the game's own step. `30` / `60`: the host decides each frame's step in whole vsyncs and keeps the frame on screen that long (`hle_nvn.c` `fstep_tick`, `nvn_fstep.h`): 1 at a 60 cap, 2 when 60 does not hold or at a 30 cap (and while a prerendered movie plays), plus one vsync while the game is behind real time after a late frame. Presents follow that hold instead of the interval the game sets. `DM_FPS_TARGET` overrides it, also from `Documents/env.txt`; the log line `frame step: game time … of real time` checks the game's speed. A derived profile (`derive_profile`) whose `main` has no `FRAME_STEP` stubs, while the profile has them for other builds, gets `fps_target 0`: without the stubs the host would present every vsync and the game would run at double speed. On a main with neither a frame step nor an engine limit the host writes, the host keeps the game's own present interval whatever `fps_target` or `DM_FPS_TARGET` says (`hle_fpslock.c` `dm_fps_lock_engine`), except with `present_interval display`, where the cap is the present interval alone: a game whose only limit is its present interval and that steps by the time that passed (Red Dead Redemption) |
| `fps_max` | `60` (the default) or `120`: the highest rate `fps_target` and the player's **Frame rate** take. `120` only for a game with an engine limit the host writes and whose speed was measured at 120 against 60 over the same inputs: the target then follows the frames that fit, 120 or 60 ([120 fps follows the frame step](../../docs/reference/frame-rate.md#120-fps-follows-the-frame-step)). |
| `fps_hold` | `on` (the default): with `fps_target`, three late frames in a row raise the hold above the cap's vsyncs (30 or 20 fps) when the last 30 frames also fall short of the cap on average, and steady frames that fit try the lower hold again. `off`: frames are never held longer than the cap's vsyncs; each is shown as soon as it is ready. For a game whose updates do not wait for the presents and step by the cap whatever the hold (Age of Calamity): there the hold only paces the screen. `DM_FPS_HOLD=on` / `off` overrides it, also from `Documents/env.txt` Paper Mario: The Thousand-Year Door sets it off too: its frame waits for three render worker threads, and holding frames left them idle, so a frame cost more the longer the hold (the hold stuck at 3 vsyncs, 20 fps, on a loaded Mac; 32–58 fps without holds) |
Expand Down
5 changes: 4 additions & 1 deletion dm/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def header_one(g):
mml = g.get('mem_map_limit', 'off') # MapPhysicalMemory refused beyond the application pool, as on Horizon (hle_svc.c): on / off
if mml not in ('on', 'off'): sys.exit(f'{g.id}: mem_map_limit must be on or off: {mml}')
ups = upscaler_keys(g) # the game's own upscaler shaders, which DM_UPSCALER=metalfx (the launcher's Game's upscaler) replaces with MetalFX's spatial scaler (nvn_mtl.m up_mfx_encode)
upm = g.get('upscaler', 'game') # the launcher's Game's upscaler by default (nvn_mtl.m up_mfx_on; DM_UPSCALER overrides): game = the game's own shaders, metalfx = MetalFX's spatial scaler
if upm not in ('game', 'metalfx'): sys.exit(f'{g.id}: upscaler must be game or metalfx: {upm}')
if upm == 'metalfx' and not ups: sys.exit(f"{g.id}: upscaler metalfx needs the game's own upscaler shaders in its shader map (none found)")
dbr = g.get('draw_barriers', 'full') # how draw passes are ordered (nvn_mtl.m barrier_game): full = each waits for all earlier GPU work, game = by the game's own barriers, so vertex work overlaps the previous pass's fragments
if dbr not in ('full', 'game'): sys.exit(f'{g.id}: draw_barriers must be full or game: {dbr}')
om = g.get('op_mode', 'console') # the operation mode reported at start (hle_oe.c dm_opmode; DM_OPMODE overrides): console = docked, handheld = touch screen in use (Super Mario Galaxy's pointer)
Expand Down Expand Up @@ -262,7 +265,7 @@ def header_one(g):
f'#define DM_GAME_TEX_DIRTY_UPLOAD {int(tdu == "on")}',
f'#define DM_GAME_TEX_DYN_SLOTS {int(tds == "on")}',
f'#define DM_GAME_DRAW_BARRIERS_GAME {int(dbr == "game")}',
f'#define DM_GAME_UPSCALER_KEYS {q(",".join(ups))}', f'#define DM_GAME_UPSCALER_N {len(ups)}',
f'#define DM_GAME_UPSCALER_KEYS {q(",".join(ups))}', f'#define DM_GAME_UPSCALER_N {len(ups)}', f'#define DM_GAME_UPSCALER {q(upm)}',
f'#define DM_GAME_VCONV_RANGE {int(vcr == "on")}',
*([f'#define DM_GAME_NVN_API_MAJOR {api.split(".")[0]}', f'#define DM_GAME_NVN_API_MINOR {api.split(".")[1]}'] if g.get('device_api', '') else []), # without the key: by the SDK version (hle_nvn.c nvn_api)
'']
Expand Down
2 changes: 1 addition & 1 deletion dm/games/settings.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DM_DYNAMIC_RESOLUTION toggle - 0 fixups:DYNAMIC_RESOLUTION Game Dynamic resoluti
DM_RENDER_SCALE range 0.5:1.0:0.05 1.0 fixups:RENDER_SCALE Game Render scale level=basic
DM_OPMODE choice 1=Docked,0=Handheld DM_GAME_OPMODE always Game Console mode level=basic
DM_PRESENT_UPSCALE choice off=Standard,metalfx=MetalFX off always Game Upscaling Uses more GPU time and can increase heat.
DM_UPSCALER choice game=Game's own,metalfx=MetalFX game DM_GAME_UPSCALER_N!=0 Game Game's upscaler
DM_UPSCALER choice game=Game's own,metalfx=MetalFX DM_GAME_UPSCALER DM_GAME_UPSCALER_N!=0 Game Game's upscaler
DM_LANG choice languages build:DM_LANG languages>1 Game Game language level=basic
DM_FULLSCREEN choice 0=Window,1=Fullscreen 0 platform:mac Game Display mode level=basic
DM_PICTURE_FIT choice fit=Fit,fill=Fill fit platform:ios Game Picture Fill crops the game's 16:9 picture to cover the screen. Health bars, subtitles or maps near the edges can be cut off. A full-screen picture without cropping needs a patch for each game.
Expand Down
Loading
Loading