Skip to content

feat(botw): HDR / EDR on BotW 1.9.0 on the Mac, from TOTK's HDR engine - #2387

Open
orcakhan wants to merge 4 commits into
ly05010419:mainfrom
orcakhan:orcakhan/hdr
Open

orcakhan wants to merge 4 commits into
ly05010419:mainfrom
orcakhan:orcakhan/hdr

Conversation

@orcakhan

@orcakhan orcakhan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What

Breath of the Wild 1.9.0 on the Mac gets HDR / EDR output from the TOTK HDR engine (#1129), with the same switch (Off / Auto / On, #2222) and the same "HDR game brightness" row on the effects page. BotW 1.6.0 and iOS do not change.

  • Compose twin: BotW 1.9.0's scene compose (f7ee6fe1, the tone mapping) gets an HDR twin, as TOTK 1.4.3's compose does. botw_hdr_compose_source checks its anchors and refuses any other layout. TOTK's edit refuses BotW's compose, and BotW's edit refuses TOTK's.
  • FP16 companions: BotW's RGB10A2 targets get FP16 companions, as R11G11B10F targets already do on TOTK. The blend rewrite for a format without alpha now applies only to R11G11B10F companions (g_hdr_draw_rgb_only).
  • Companion limit: going past the limit (24 in one frame) no longer aborts the game. That target keeps its own format for the frame, and the log says so once. The runs below never reached it.
  • Final copy: the canvas copy into the presented image (vertex e4b5b096, fragment ecb4242e, a plain nearest copy) keeps the FP16 canvas, and the window shows it as EDR.
  • HDR layer (TOTK and BotW, the shared frontend): on macOS 26 the window's layer uses preferredDynamicRange high, toneMapMode ifSupported and contentsHeadroom, in place of wantsExtendedDynamicRangeContent. The canvas is drawn for the display's potential headroom, capped by the peak row, and tagged with it; macOS maps it to what the display has now. The current headroom is no longer read: an external HDR display can report 1.0 while it shows HDR (also seen with an HDR video; Apple developer forum thread 810008), and the game showed no HDR there.
  • Which builds have it: TOTK_HDR_MAC (in totk_hdr.h) names them: TOTK on the Mac, and BotW 1.9.0. It replaces the repeated TARGET_OS_OSX && !defined(GAME_BOTW) tests.
  • Known gaps:
    • the pause menu shows SDR content in the EDR window, because the compose does not run there;
    • HDR forced On on an SDR display looks washed out (the HDR curve squeezed into SDR white). Auto keeps HDR off there.

Performance (shared with TOTK)

The tone-map functions were the cost: the runtime compiles shaders in MTLMathModeSafe, so they ran in precise math.

  • Relaxed math: the HDR functions now compile under #pragma METAL fp math_mode(relaxed), which keeps NaN and infinity, unlike fast. The game's code after them goes back to safe.
  • Folded matrices: the BT.709 → BT.2020 → XYZ → LMS chain of the hue and purity donor is folded into constant matrices.
  • Result: the BotW compose twin at 1080p went from 1.12 to 0.29 ms of GPU time. TOTK's twin uses the same functions: in game, TOTK's HDR cost went from 2.9 to 1.2 ms a frame (below).

Measured (M4 Pro, macOS 27.2)

These runs used the previous layer (wantsExtendedDynamicRangeContent), except the TOTK tagged-layer runs marked below.

BotW 1.9.0 (uncapped, the same spot)

Build GPU ms / frame
HDR off 6.95
HDR on, before the math change 8.46
HDR on, this PR ~7.7

That spot is CPU-bound at about 100 fps, so fps barely moves. The FP16 copies cost about 0.2 ms; the rest of the difference was the tone map.

BotW 1.9.0, Kakariko Village at night (a 100% save, Link by a lit campfire, lanterns on; uncapped, up to 240 fps)

Each run is 60 s in the world; the figures are its last 45 s, from TOTK_BENCH_FRAMES. The runs alternated (main, PR on, PR off, twice). main has no BotW HDR: its runs are the game in SDR, and no twin loaded in them.

Build HDR fps Median frame 1% low
main (786ddc0) — 101.9 / 104.5 9.79 / 9.57 ms 71.6 / 73.1 fps
this PR off 101.7 / 101.2 9.81 / 9.86 ms 71.7 / 71.5 fps
this PR on 97.9 / 97.8 10.12 / 10.12 ms 65.1 / 64.6 fps
  • HDR's cost here: about 0.3 ms a frame by the median, about 4% fps. The scene is CPU-bound, so most of the GPU cost does not show.
  • 1% low: it drops more, from about 71.5 to 65 fps; no frame went over 50 ms.
  • HDR off against main: no measurable difference. The two main runs differ from each other by 0.22 ms.

TOTK 1.4.3 (up to 144 fps, a new save loaded by autoload)

Each run is 60 s in the world; the figures are its last 45 s, from TOTK_BENCH_FRAMES. The main and PR runs alternated (main, PR, main, PR).

Build HDR fps Median frame
main (786ddc0) on 68.7 / 69.0 14.47 / 14.44 ms
this PR on 76.9 / 79.0 12.95 / 12.53 ms
this PR off 86.4 / 86.2 11.53 / 11.56 ms
this PR, tagged layer on 77.1 / 77.2 12.92 / 12.91 ms

This spot is GPU-bound, so the tone map shows in fps. By the median frame, HDR cost 2.9 ms a frame on main and costs 1.2 ms with this PR: about 12% more fps with HDR on. One PR run had two ~110 ms frames; the GPU took 11–12 ms in both, so they did not come from the HDR shaders. The other PR runs had none. The tagged layer (macOS maps the canvas to the display) costs nothing measurable: 1% low 68.2 / 67.4 fps against 67.3 / 68.0, longest frame 16 / 21 ms.

Tests

  • tests/botw_hdr_compose_probe.m (new; run by tests/test_botw_hdr.py and needs BOTW190_SHADER_SEED) draws the game's compose and the twin on the GPU, one pixel at a time:
    • with HDR off, the twin draws exactly the game's picture;
    • with HDR on, a dark grey keeps the game's value and a bright grey goes above SDR white;
    • the bloom setting scales the bloom texture, not the scene;
    • nine saturated colours stay within 5e-3 of the unfolded chain computed in double precision, which checks the folded matrices.
  • test_final_copy_keys: the two final-copy keys in hdr_capture exist in the shader seed, and the fragment samples a single texture. A wrong key would leave the picture SDR without any error.
  • test_hdr_auto also covers BotW 1.6.0 (no HDR). settings_panel_probe.m counts BotW 1.9.0's HDR rows.
  • Test suite: Python 3.14 (the tools/deps ui-pack environment, as CI):
    • run_source_tests.py core: 2392 tests OK, 31 skipped for unrelated local data (OoT, the shader inbox, fontTools);
    • run_source_tests.py settings: 8 tests OK, 3 skipped (the shader inbox).
  • Builds: totk-native, -v143, -botw160 and -botw190 all build, and so does Ocarina of Time's oot-native, which shares nvn_mtl.m (its frontend gets an empty front_hdr_present_headroom; its layer is not tagged). nvn_mtl.m passes a syntax-only compile against the iOS SDK as TOTK 1.4.3 and BotW 1.9.0. I could not run the full build_app.py --platform ios (no game files for it here).

Played on a Mac: BotW 1.9.0, 60 s with HDR on:

  • the twin was ready;
  • the FP16 canvas was kept in every frame (4801);
  • the window was in EDR;
  • 94–107 fps, no errors.

Played on a Mac: BotW 1.9.0, Kakariko Village at night (the runs above, and one played by hand with HDR on):

  • the twin was ready, the FP16 canvas was kept in every frame, and the window was in EDR;
  • the companion limit was never reached;
  • the campfire, lanterns, sky and UI were checked by eye with HDR on and look right.

Played on a Mac: BotW 1.9.0 with the tagged layer:

  • built-in XDR screen, Kakariko at night: tagged 16, the screen's current headroom rose to 8.3 in the world (as with the previous layer), and the FP16 canvas was kept in every frame;
  • another Mac with an external HDR display that reports current headroom 1.0: with the display's HDR on, the game's HDR shows (brighter fire and lights, more colour, checked by eye), where the previous layer showed none. macOS reported the granted headroom (the tag, 4.18) on another screen's NSScreen;
  • with the display's HDR off, or the window on an SDR display, Auto keeps the game SDR.

Played on a Mac: TOTK 1.4.3 with the tagged layer, two runs of 60 s with HDR on: both twins ready, tagged 16, the built-in screen's current headroom at 8.3, the FP16 canvas kept in every frame, no shader failed to compile, the companion limit never reached.

Played on a Mac: TOTK 1.4.3 (before the layer change), the installed app updated to this branch, eight runs of 60–90 s (HDR on and off):

  • both twins were ready (compose 0ac9a549, post ac58fc18);
  • with HDR on, the FP16 canvas was kept in every frame and the window was in EDR;
  • the companion limit was never reached, and no shader failed to compile;
  • the picture was checked by eye with HDR on and looks right.
  • Loading screens show SDR: the window turns EDR only while there is an FP16 canvas to show (existing code, not changed here).

Not tested: TOTK's picture by eye with the tagged layer, handheld mode, MetalFX, iPhone / iPad.

A separate PR will follow this one: TOTK 1.4.3's HDR bloom setting scales the scene instead of the bloom. It only shows when the setting is moved off 1. Its test goes into this PR's probe, so it waits for this one.

🤖 Generated with Claude Code

BotW 1.9.0's scene compose (f7ee6fe1) gets an HDR twin like TOTK 1.4.3's
compose. Its RGB10A2 targets get FP16 companions. The final copy (vertex
e4b5b096, fragment ecb4242e) keeps the FP16 canvas, and the window shows
it as EDR. The effects page has the HDR rows on BotW 1.9.0. TOTK_HDR_MAC
names the builds that have the engine: TOTK on the Mac and BotW 1.9.0.
BotW 1.6.0 has none.

- The companion limit (24) no longer aborts. A target past it keeps its
  own format for that frame, and the log says so once.
- The blend rewrite for formats without alpha applies only to
  R11G11B10F companions.

perf: the HDR tone map functions compile in relaxed math (it keeps NaN
and infinity; the runtime's mode is safe), and the BT.709 -> LMS chain
of the hue and purity donor is folded into constant matrices. The BotW
compose twin at 1080p went from 1.12 to 0.29 ms of GPU time. TOTK's twin
uses the same functions. In game (BotW, uncapped, same spot): 8.46 to
about 7.7 ms of GPU per frame, against 6.95 ms with HDR off.

Tests: tests/test_botw_hdr.py and tests/botw_hdr_compose_probe.m (needs
BOTW190_SHADER_SEED). They check that the twin with HDR off draws the
game's picture; that a dark grey keeps its value and a bright grey goes
above SDR white; that the bloom setting scales the bloom texture; that
saturated colours match the unfolded chain; and that the final-copy keys
exist in the seed. test_hdr_auto covers BotW 1.6.0.

Played on a Mac: BotW 1.9.0, 60 s, HDR on, ~94-107 fps, no errors. The
pause menu shows SDR content, because the compose does not run there.
Not tested: handheld, MetalFX, iOS build, TOTK in game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orcakhan
orcakhan marked this pull request as draft November 27, 2026 02:19
orcakhan and others added 2 commits November 26, 2026 23:39
…aps it to the display

An external HDR display can report no current EDR headroom (current 1.0, potential above 1) while it shows HDR, even
with an HDR video on it (Apple developer forum thread 810008). The canvas was drawn for that current value, so the game
showed no HDR there.

- On macOS 26 the layer uses preferredDynamicRange high, toneMapMode ifSupported and contentsHeadroom instead of
  wantsExtendedDynamicRangeContent (deprecated in macOS 26).
- The canvas is drawn for the display's potential headroom, capped by the HDR peak row, and tagged with it; the
  presenter keeps the tag at each frame's peak. macOS grants a tagged layer only its tag's headroom (tagged with the
  current 1.2, the built-in XDR screen stayed at 1.2), and maps the canvas down to what the display has now.
- TOTK_HDR_LAYER=legacy (environment or the app's defaults) keeps the previous layer, to compare.

Tested on the built-in XDR screen, BotW 1.9.0 at night: tagged 16, the screen's current headroom rose to 8.3 in the
world, as with the previous layer (legacy: 1.2 to 8.3); the FP16 canvas kept every frame. run_source_tests core (2392
OK, 31 skipped) and settings (8, 3 skipped); the four Mac binaries build. Not tested yet: an external HDR display, the
picture by eye on the built-in screen, TOTK.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…witch is gone

The previous layer (wantsExtendedDynamicRangeContent, kept as TOTK_HDR_LAYER=legacy) showed no HDR on an external HDR
display that reports no current headroom, so it goes.

- The canvas is always drawn for the display's potential headroom (capped by the HDR peak row) and tagged with it;
  the current headroom is no longer read. With an external HDR display, macOS reported the headroom it granted the
  game's window (the tag) on another screen's NSScreen, while the external one stayed at 1.0.
- front_hdr_tag sets the tag and logs each change, from the switch on and from the presenter alike.

Tested: BotW 1.9.0 at night on the built-in XDR screen (tagged 16, current headroom 8.3 in the world, the FP16 canvas
kept every frame); on an external HDR display, HDR shows with the display's HDR on, and the game turns SDR when the
window moves to an SDR display. run_source_tests core (2392 OK, 31 skipped) and settings (8, 3 skipped); the four Mac
binaries build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@orcakhan
orcakhan marked this pull request as ready for review November 27, 2026 03:21
…ants it repeats

- Ocarina of Time's Mac build shares nvn_mtl.m, whose presenter now calls front_hdr_present_headroom: OoT's frontend
  gets an empty one (its layer is not tagged), as it has the other front_hdr_* functions. Without it oot-native
  stopped at the link (undefined _front_hdr_present_headroom).
- botw_hdr_compose_source also requires the luma's red weight (0.2989) and the saturation term's 2/3 in the game's
  compose, which the twin writes as literals; another layout is refused, not given a different saturation.
- A comment no longer calls wantsExtendedDynamicRangeContent deprecated: CAMetalLayer's own property is not.

Tested: oot-native and the four TotK / BotW Mac binaries build; tests.test_botw_hdr with the 1.9.0 shader seed (2 OK);
run_source_tests core (2392 OK, 31 skipped) and settings (8, 3 skipped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant