From 2388ce5d2343d8deaa137bafe055e22f62301fb2 Mon Sep 17 00:00:00 2001 From: Enzo Ferronha <166016712+Enokine@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:37:51 +0100 Subject: [PATCH 1/2] perf: a long render pass is split and committed while the GPU idles, with a settings panel switch (after nxnative) Mid-submission commits (chunk_maybe_split) happen only between render passes, so a long pass reaches the GPU in one piece when it ends. Breath of the Wild 1.9.0 draws about 2,700 of its 4,100 draws a frame into one G-buffer pass (several same-target SetRenderTargets continued into one Metal pass), and the GPU, done with the shadow passes, waits for it to be translated. seedds/nxnative fixed this with pass_split_try (its PR #1468); this is the same rule on this repository's chunks. At a draw, with nothing committed still on the GPU (g_q4_inflight) and TOTK_PASS_SPLIT draws (default 256, 0 off) since the last commit, draw_inner ends the pass, commits the chunk as chunk_maybe_split does, and the draw opens the pass again. Attachments are always stored and a reopened pass loads them, as after a compute dispatch inside a pass: TAA keeps its jitter for the reopened G-buffer pass, MetalFX does not take its depth again, and a counting occlusion query counts into a new slot that its report adds up (vis_count_begin, g_pass.serial). At most TOTK_PASS_SPLIT_MAX (default 2) splits per NVN pass. Not split: passes opened without all their attachments, ranged, layered or cube-merged passes, hoisted or pending clears, the TBDR rewrites and geometry draws. The settings panel's display page has a switch for it (pass-split.txt above the game's folder, like the GPU keep-alive; TOTK_PASS_SPLIT decides first and greys it out), and "flag pass_split " (TOTK_INPUT_FILE) sets it while the game runs. The chunk line of the log counts the splits per frame, and a second line counts the draws that could have been split, by command buffers still in flight and by passes that may not be. Measured on BotW 1.9.0 (M4 Max, Kakariko, uncapped, flag alternated every 25 s): about 2-3 splits a frame; with the split the GPU stayed at 641 MHz and frames at 10.9 ms p50, without it the clock fell to 344-380 MHz and frames to 14-19 ms, in both pairs. No visual difference was seen. Co-Authored-By: Claude Opus 5.5 --- games/totk/runtime/settings_panel.h | 12 ++++ games/totk/tests/command_q/probe.m | 1 + .../third_party/d2r_gfx/gfx/nvn/hle_nvn.c | 9 ++- .../third_party/d2r_gfx/gfx/nvn/nvn_mtl.m | 58 +++++++++++++++++++ tests/settings_panel_probe.m | 9 ++- 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/games/totk/runtime/settings_panel.h b/games/totk/runtime/settings_panel.h index 41d295f99..7a53b511f 100644 --- a/games/totk/runtime/settings_panel.h +++ b/games/totk/runtime/settings_panel.h @@ -14,6 +14,9 @@ GPU keep-alive switch, default on dm_gfx_keepalive_set (gfx/nvn/nvn_mtl.m), at once; gpu-keepalive.txt above the game's folder (both games); TOTK_GPU_KEEPALIVE first (greyed out) + long-pass split switch, default on dm_gfx_pass_split_set (gfx/nvn/nvn_mtl.m), at once; + pass-split.txt above the game's folder (both games); + TOTK_PASS_SPLIT first (greyed out) resolution 720p / + MetalFX / 1080p / runtime_output_mode_set (game_patches*.c); the player picks, + MetalFX / 2K / 2K + MetalFX (a 4K screen) @@ -140,6 +143,7 @@ void dm_gfx_set_flag(const char *name, int value); void dm_gfx_ssao_start(int pct); int dm_gfx_ssao_locked(void); int dm_gfx_ssao_live(void); void dm_gfx_ssao_set(int pct); /* totk_ssao.h */ void dm_gfx_aniso_start(int n); int dm_gfx_aniso_locked(void); int dm_gfx_aniso(void); void dm_gfx_aniso_set(int n); /* gfx/nvn/nvn_mtl.m */ void dm_gfx_keepalive_start(int on); int dm_gfx_keepalive_locked(void); int dm_gfx_keepalive(void); void dm_gfx_keepalive_set(int on); /* gfx/nvn/nvn_mtl.m */ +void dm_gfx_pass_split_start(int on); int dm_gfx_pass_split_locked(void); int dm_gfx_pass_split(void); void dm_gfx_pass_split_set(int on); /* gfx/nvn/nvn_mtl.m */ #ifdef GAME_BOTW190 int runtime_shadow_res_available(void); int runtime_shadow_res_locked(void); int runtime_shadow_res_saved(void); void runtime_shadow_res_save(int size); /* game_patches_botw.c */ @@ -283,6 +287,7 @@ static void settings_restore_begin(void) { settings_ssao_restore(); if(!dm_gfx_aniso_locked()&&settings_read_int("graphics-aniso.txt",&v)&&v<=16)dm_gfx_aniso_start(v); if(!dm_gfx_keepalive_locked()&&runtime_shared_setting_word("gpu-keepalive.txt",word,sizeof word))dm_gfx_keepalive_start(!strncmp(word,"on",2)); + if(!dm_gfx_pass_split_locked()&&runtime_shared_setting_word("pass-split.txt",word,sizeof word))dm_gfx_pass_split_start(!strncmp(word,"on",2)); settings_effects_restore(); /* Edge smoothing's resolve, kept in graphics-taa-mode.txt: "fast" (one compute pass) or "metalfx" (the default); TOTK_TAA_FAST decides first. The display page's edge smoothing row (off / fast / MetalFX) writes it. */ @@ -868,6 +873,13 @@ static NSArray *settings_rows(void) { if(dm_gfx_keepalive_locked())[rows addObject:settings_fixed(t,settings_on_off(dm_gfx_keepalive()))]; else [rows addObject:settings_row(t,nil,nil,^int{return dm_gfx_keepalive();}, ^(int v){dm_gfx_keepalive_set(v);runtime_shared_setting_save("gpu-keepalive.txt",v?"on":"off","GPU keep-alive");})];} + /* Long-pass split (nvn_mtl.m pass_split_try): a long render pass is committed in parts while the GPU idles, so the GPU + starts on it sooner. Breath of the Wild 1.9.0 uncapped on an M4 Max kept its GPU clock (641 MHz against 344-380 without) + and its frames (10.9 against 14-19 ms); the GPU then works more, so more power at an uncapped frame rate. */ + {NSString *t=settings_text("长通道拆分(GPU 少降频,帧更多)","Long-pass split (steadier GPU clock, more fps)"); + if(dm_gfx_pass_split_locked())[rows addObject:settings_fixed(t,settings_on_off(dm_gfx_pass_split()))]; + else [rows addObject:settings_row(t,nil,nil,^int{return dm_gfx_pass_split();}, + ^(int v){dm_gfx_pass_split_set(v);runtime_shared_setting_save("pass-split.txt",v?"on":"off","long-pass split");})];} int modes=runtime_output_modes(); NSMutableArray *res=[NSMutableArray array];NSMutableArray *resModes=[NSMutableArray array]; static const int order[]={OUTPUT_MODE_720P,OUTPUT_MODE_720P_METALFX,OUTPUT_MODE_OFF,OUTPUT_MODE_METALFX,OUTPUT_MODE_NATIVE,OUTPUT_MODE_NATIVE_METALFX,OUTPUT_MODE_NATIVE_4K,OUTPUT_MODE_NATIVE_5K, diff --git a/games/totk/tests/command_q/probe.m b/games/totk/tests/command_q/probe.m index 41e02d1b7..446cc3f04 100644 --- a/games/totk/tests/command_q/probe.m +++ b/games/totk/tests/command_q/probe.m @@ -161,6 +161,7 @@ void runtime_controller_map_reset(void){} void dm_gfx_set_flag(const char *name,int value){(void)name;(void)value;} void dm_gfx_aniso_start(int n){(void)n;} int dm_gfx_aniso_locked(void){return 0;} int dm_gfx_aniso(void){return 0;} void dm_gfx_aniso_set(int n){(void)n;} /* the display page's anisotropy row (nvn_mtl.m) */ void dm_gfx_keepalive_start(int on){(void)on;} int dm_gfx_keepalive_locked(void){return 0;} int dm_gfx_keepalive(void){return 1;} void dm_gfx_keepalive_set(int on){(void)on;} /* the display page's GPU keep-alive row (nvn_mtl.m, PR #2049) */ +void dm_gfx_pass_split_start(int on){(void)on;} int dm_gfx_pass_split_locked(void){return 0;} int dm_gfx_pass_split(void){return 1;} void dm_gfx_pass_split_set(int on){(void)on;} /* the display page's long-pass split row (nvn_mtl.m) */ /* the leaderboard (board_upload.h): the graphics layer's frame record and picture settings, none here */ void fps_board_start(void){} void fps_board_reset(void){} int fps_board_counting(void){return 0;} int fps_board_snapshot(fps_board_stats *s){(void)s;return 0;} void mtl_board_view(int *ow,int *oh,int *sw,int *sh,int *mfx){*ow=*oh=*sw=*sh=*mfx=0;} void nvn_board_pacing(int *lock,int *interp){*lock=*interp=0;} int mtl_display_hz(void){return 0;} diff --git a/games/totk/third_party/d2r_gfx/gfx/nvn/hle_nvn.c b/games/totk/third_party/d2r_gfx/gfx/nvn/hle_nvn.c index 125a93a17..7bbdabca7 100644 --- a/games/totk/third_party/d2r_gfx/gfx/nvn/hle_nvn.c +++ b/games/totk/third_party/d2r_gfx/gfx/nvn/hle_nvn.c @@ -3284,7 +3284,14 @@ static void tsummary(uint64_t frame) { if (pf && frame > pf) LOG("[nvn] 上传槽等待 至帧 %llu:每帧 %.2f 次 / %.3f ms", frame, (double)(un - pun) / (double)(frame - pf), (double)(uns - puns) / 1e6 / (double)(frame - pf)); pun = un; puns = uns; } { static uint64_t pcc; uint64_t mtl_chunk_commits(void), cc = mtl_chunk_commits(); - if (pf && frame > pf) LOG("[nvn] 分段提交 至帧 %llu:每帧额外 %.2f 段", frame, (double)(cc - pcc) / (double)(frame - pf)); + static uint64_t pps; uint64_t mtl_pass_splits(void), ps = mtl_pass_splits(); + if (pf && frame > pf) LOG("[nvn] 分段提交 至帧 %llu:每帧额外 %.2f 段,其中长通道拆分 %.2f 次 | chunks to frame %llu: %.2f extra a frame, %.2f of them long-pass splits", frame, (double)(cc - pcc) / (double)(frame - pf), + (double)(ps - pps) / (double)(frame - pf), frame, (double)(cc - pcc) / (double)(frame - pf), (double)(ps - pps) / (double)(frame - pf)); + { static uint64_t pb[5]; uint64_t b[5]; void mtl_pass_split_busy(uint64_t[5]); mtl_pass_split_busy(b); double nf = (double)(frame - pf); + if (pf && frame > pf && (b[0] - pb[0] || b[1] - pb[1] || b[2] - pb[2] || b[3] - pb[3] || b[4] - pb[4])) LOG("[nvn] long-pass split candidates to frame %llu, draws per frame: GPU idle %.1f, 1 command buffer in flight %.1f, 2 %.1f, 3+ %.1f, pass not splittable %.1f", + frame, (b[0] - pb[0]) / nf, (b[1] - pb[1]) / nf, (b[2] - pb[2]) / nf, (b[3] - pb[3]) / nf, (b[4] - pb[4]) / nf); + for (int i = 0; i < 5; i++) pb[i] = b[i]; } + pps = ps; pcc = cc; } if (synclog_env() && pf && frame > pf) { static uint64_t pc[2], pb[2], pn[2], pw[2]; double nf = (double)(frame - pf); for (int k = 0; k < 2; k++) { uint64_t c = atomic_load(&g_sw_calls[k]), b = atomic_load(&g_sw_blocked[k]), n = atomic_load(&g_sw_ns[k]), w = atomic_load(&g_sw_newest[k]); diff --git a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m index 890419717..e80d6c8cd 100644 --- a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m +++ b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m @@ -3763,12 +3763,14 @@ static int diag_shader_prefix_csv_matches(const char *key,const char *prefixes) return 0; } static void dead_stat_print(unsigned long long frame); +static void pass_split_set(int draws); // TOTK_PASS_SPLIT, with draw_inner void dm_gfx_set_flag(const char *name, int v) { if (!strcmp(name, "arg_epoch")) { (void)arg_epoch_on(); atomic_store(&g_arg_epoch_on, v != 0); MLOG("[flag] arg_epoch = %d", v != 0); return; } if (!strcmp(name, "arg_epoch_check")) { (void)arg_epoch_on(); atomic_store(&g_arg_epoch_check, v != 0); MLOG("[flag] arg_epoch_check = %d verified=%llu extra=%llu", v != 0, (unsigned long long)atomic_load(&g_arg_epoch_verified), (unsigned long long)atomic_load(&g_arg_epoch_extra)); return; } if (!strcmp(name, "tex_slots")) { (void)tex_slots_on(); atomic_store(&g_tex_slots_on, v != 0); MLOG("[flag] tex_slots = %d", v != 0); return; } if (!strcmp(name, "tex_slots_check")) { (void)tex_slots_on(); atomic_store(&g_tex_slots_check, v != 0); MLOG("[flag] tex_slots_check = %d verified=%llu hits=%llu", v != 0, (unsigned long long)atomic_load(&g_tex_slots_verified), (unsigned long long)atomic_load(&g_tex_slots_hits)); return; } if (!strcmp(name, "render_stream")) { atomic_store(&g_rs_on, v != 0); MLOG("[flag] render_stream = %d (next render pass)", v != 0); return; } + if (!strcmp(name, "pass_split")) { pass_split_set(v); MLOG("[flag] pass_split = %d (a long render pass is split while the GPU idles, after that many draws; 0 off)", v > 0 ? v : 0); return; } if (!strcmp(name, "cube_merge")) { atomic_store(&g_cg_on, v != 0); MLOG("[flag] cube_merge = %d", v != 0); return; } if (!strcmp(name, "skip_invisible")) { skv_set(v); return; } if (!strcmp(name, "skipvc")) { atomic_store(&g_skipvc_any, v); MLOG("[flag] skipvc = %d", v); return; } @@ -17679,6 +17681,61 @@ static void oot_bar_before_draw(NvProg *pr) { static void oot_bar_note_draw(NvProg *pr) { if (g_oot_bar_mode) g_oot_bar_writes |= oot_bar_shader_writes(pr); } +/* TOTK_PASS_SPLIT (after seedds/nxnative's pass_split_try, its PR #1468): mid-submission commits (chunk_maybe_split) happen + only between render passes, so a long pass reaches the GPU in one piece at its end. Breath of the Wild 1.9.0 draws about + 2,700 of its 4,100 draws a frame into one G-buffer pass, and the GPU, done with the shadow passes before it, waits for the + whole pass to be translated (nxnative measured about 2.5 ms of a 9 ms frame; M4 Max at 120 fps, frame p50 / p90 + 8.75 / 9.33 -> 8.34 / 8.68 ms). At a draw, with nothing committed still on the GPU (g_q4_inflight) and TOTK_PASS_SPLIT + draws (default 256, 0 off) since the last commit, the pass is ended, the chunk committed as chunk_maybe_split does, and + the draw opens the pass again: its attachments were stored (always, here) and are loaded, so the pictures are the same. + A split costs a store and a load of the attachments, so it is taken only while the GPU would otherwise wait, and at most + TOTK_PASS_SPLIT_MAX (default 2) times per NVN pass (a SetRenderTargets, g_cg.rt_seq). Not split: passes opened without + all their attachments (g_enc_mode), ranged, layered or cube-merged passes, hoisted or pending clears, the TBDR rewrites + and geometry draws. "flag pass_split " sets it while the game runs (0 off; A/B). */ +static _Atomic int g_pass_split = -1; +static uint64_t g_pass_splits, g_split_rtseq; static int g_split_n; +static uint64_t g_split_busy[5]; // draws past the threshold in an open pass: [0..3] by command buffers still in flight (0, 1, 2, 3+), [4] the pass may not be split +static int pass_split_draws(void) { + int v = atomic_load_explicit(&g_pass_split, memory_order_relaxed); + if (v < 0) { const char *e = getenv("TOTK_PASS_SPLIT"); v = e ? atoi(e) : 256; if (v < 0) v = 0; + int unset = -1; atomic_compare_exchange_strong(&g_pass_split, &unset, v); v = atomic_load(&g_pass_split); } + return v; +} +static void pass_split_set(int draws) { atomic_store(&g_pass_split, draws > 0 ? draws : 0); } +static int pass_split_max(void) { static int v = -1; if (v < 0) { const char *e = getenv("TOTK_PASS_SPLIT_MAX"); v = e ? atoi(e) : 2; } return v; } +uint64_t mtl_pass_splits(void) { return g_pass_splits; } +/* The settings panel's display page switch (settings_panel.h, pass-split.txt; like the GPU keep-alive): on = the default + 256 draws, off = 0. TOTK_PASS_SPLIT decides first and greys the switch out. */ +int dm_gfx_pass_split_locked(void) { return getenv("TOTK_PASS_SPLIT") != NULL; } +int dm_gfx_pass_split(void) { return pass_split_draws() > 0; } +void dm_gfx_pass_split_start(int on) { if (!dm_gfx_pass_split_locked()) pass_split_set(on ? 256 : 0); } +void dm_gfx_pass_split_set(int on) { + if (dm_gfx_pass_split_locked() || dm_gfx_pass_split() == !!on) return; + pass_split_set(on ? 256 : 0); + MLOG("长通道拆分:设置面板%s | long-pass split: %s from the settings panel", on ? "打开" : "关闭", on ? "on" : "off"); +} +void mtl_pass_split_busy(uint64_t v[5]) { for (int i = 0; i < 5; i++) v[i] = g_split_busy[i]; } +static void pass_split_try(void) { + int n = pass_split_draws(); + if (n <= 0 || !g_enc || !g_chunk_size || !g_cb || g_frz_on || tbdr_on() || pt_active()) return; // chunk_maybe_split's conditions, and a pass open + if (g_stat_draw - g_chunk_mark < (uint64_t)n) return; // too soon + /* A continued pass (g_rt_merged: same-target SetRenderTargets, TOTK_RT_CONTINUE) is split like any other: ending one is + what a landed clear and a sampled attachment already do (rp_end), and the halves store and load as the passes did + before continuation. A counting occlusion query is too: each Metal pass counts into its own slot (vis_count_begin, + g_pass.serial) and the report adds all the slots since the reset. A pending clear is not: the reopened pass would + clear instead of loading. */ + int clears = R.clear_d || R.clear_s; for (int i = 0; i < 8; i++) clears |= R.clear_c[i]; + if (clears || g_enc_mode || g_rt_range_active || g_lay.active || g_cg_force_layers || g_hoist_n || g_defer_replaying || g_fz_checking || g_geo_ras.pr) { g_split_busy[4]++; return; } + { int busy = atomic_load_explicit(&g_q4_inflight, memory_order_relaxed); g_split_busy[busy > 3 ? 3 : busy < 0 ? 0 : busy]++; + if (busy) return; } // the GPU has work: a commit would only queue + if (g_split_rtseq != g_cg.rt_seq) { g_split_rtseq = g_cg.rt_seq; g_split_n = 0; } + if (pass_split_max() > 0 && g_split_n >= pass_split_max()) return; + g_split_n++; + rp_end(); + if (g_blit) { enc_b_end(g_blit); g_blit = nil; } + mtl_sub_split(); + if (!g_pass_splits++) MLOG("TOTK: pass split: a long render pass was ended and its chunk committed while the GPU had nothing to do (TOTK_PASS_SPLIT=%d, frame %llu)", n, (unsigned long long)atomic_load(&g_cur_frame)); +} static void draw_inner(const p_draw *dw, const p_draw_idx *di) { NSUInteger native_output_width=0,native_output_height=0; uint64_t native_output_source=0; @@ -17697,6 +17754,7 @@ static void draw_inner(const p_draw *dw, const p_draw_idx *di) { pr->key[0] ? [pr->key[0] substringToIndex:16].UTF8String : "-", pr->key[1] ? [pr->key[1] substringToIndex:16].UTF8String : "-", pr->key[2] ? [pr->key[2] substringToIndex:16].UTF8String : "-", (const void *)S.gst[0], (const void *)S.gst[1], (const void *)S.gst[2]); } } draw_skipped(); return; } // TOTK (iOS): a stage is not translated yet; Mac (async shaders): still in the background + pass_split_try(); // before anything of this draw touches the encoder: the draw opens the pass again when it was split oot_bar_before_draw(pr); if(mesh_indirect_mode()==2)mesh_indirect_written(pr); mesh_batch_written(pr); diff --git a/tests/settings_panel_probe.m b/tests/settings_panel_probe.m index 50d67e839..ccd805ce2 100644 --- a/tests/settings_panel_probe.m +++ b/tests/settings_panel_probe.m @@ -73,6 +73,11 @@ void dm_gfx_set_flag(const char *name, int value) { int dm_gfx_keepalive_locked(void) { return 0; } int dm_gfx_keepalive(void) { return fakeKeepalive; } void dm_gfx_keepalive_set(int on) { fakeKeepalive = on != 0; } +static int fakePassSplit = 1; +void dm_gfx_pass_split_start(int on) { fakePassSplit = on != 0; } +int dm_gfx_pass_split_locked(void) { return 0; } +int dm_gfx_pass_split(void) { return fakePassSplit; } +void dm_gfx_pass_split_set(int on) { fakePassSplit = on != 0; } void dm_gfx_sharpen_set(int pct) { fakeSharpen = pct; } int dm_gfx_sharpen(void) { return fakeSharpen; } static int fakeFxaaReplaced; /* Breath of the Wild 1.9.0: MetalFX replaces the FXAA / upscale draw (gfx/nvn/botw_finish.h) */ @@ -1012,7 +1017,7 @@ int main(int argc, const char **argv) { @autoreleasepool { runtime_input_key_synthetic(18, 1); runtime_input_key_synthetic(18, 1); tick(); runtime_input_key_synthetic(18, 0); tick(); assert(settingsOpen && fakeSettingsCapture && settingsPanel && !settingsPanel.hidden && settingsPanel.superview == window.contentView); assert(NSContainsRect(window.contentView.bounds, settingsPanel.frame)); - assert(settingsPanel.allRows.count == 28 + 3*TOTK_V143 + BOTW_V190 + (TOTK_V143 && totk_hdr_available() ? SETTINGS_HDR_ROWS : 0)); /* + the HDR rows (PR #1129) */ /* 17 (anisotropy last on the display page, controller + assert(settingsPanel.allRows.count == 29 + 3*TOTK_V143 + BOTW_V190 + (TOTK_V143 && totk_hdr_available() ? SETTINGS_HDR_ROWS : 0)); /* + the HDR rows (PR #1129) */ /* 17 (anisotropy last on the display page, controller background input on the input page), the user page's two, then the effects page: FOV, two distances, shadows, depth of field, FXAA, sharpening and effect switches @@ -1444,7 +1449,7 @@ the FXAA row says so (rows are made at each opening). */ /* Pages: Display, Input, User and Key bindings; the page shown last opens again. */ press(18); assert(settingsOpen); [settingsPanel selectPage:SETTINGS_PAGE_DISPLAY]; - assert(settingsPanel.rows.count == 7 && [settingsPanel.rows[0].title isEqualToString:@"Overlay"]); /* edge smoothing, AO and anisotropy are on the effects page; the GPU keep-alive switch is on this one */ + assert(settingsPanel.rows.count == 8 && [settingsPanel.rows[0].title isEqualToString:@"Overlay"]); /* edge smoothing, AO and anisotropy are on the effects page; the GPU keep-alive and long-pass split switches are on this one */ /* Every page's bottom right: 访问主页 (user 2026-11-11, was the display page's star), after the rows for a controller; the version stays clear of it; a result shows for a moment where the version is. */ NSButton *starButton = settingsPanel.homeButton; From daa11d42eff6898fbd4d36c62b9c9074fe515665 Mon Sep 17 00:00:00 2001 From: Enzo Ferronha <166016712+Enokine@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:33:50 +0100 Subject: [PATCH 2/2] perf: the long-pass split is on by default only in Breath of the Wild 1.9.0 on the Mac, where it was measured Review of PR #2191: the gain was measured on BotW 1.9.0 on an M4 Max only. PASS_SPLIT_DEFAULT (nvn_mtl.m) is now 256 draws there (GAME_BOTW190 on the Mac) and 0 elsewhere: Tears of the Kingdom, Breath of the Wild 1.6.0, Ocarina of Time, the Switch 2 games and iPhone / iPad start with it off. The settings panel's switch (pass-split.txt) and TOTK_PASS_SPLIT still turn it on everywhere, at PASS_SPLIT_DRAWS (256) draws. tools/gfx_matrix.py: every configuration, Mac and iOS, compiles with the same warnings as before. Co-Authored-By: Claude Opus 5.5 --- games/totk/runtime/settings_game.h | 6 ++++-- .../third_party/d2r_gfx/gfx/nvn/nvn_mtl.m | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/games/totk/runtime/settings_game.h b/games/totk/runtime/settings_game.h index 8ff9e965e..024d5d3ab 100644 --- a/games/totk/runtime/settings_game.h +++ b/games/totk/runtime/settings_game.h @@ -12,7 +12,8 @@ GPU keep-alive switch, default on dm_gfx_keepalive_set (gfx/nvn/nvn_mtl.m), at once; gpu-keepalive.txt above the game's folder (both games); TOTK_GPU_KEEPALIVE first (greyed out) - long-pass split switch, default on dm_gfx_pass_split_set (gfx/nvn/nvn_mtl.m), at once; + long-pass split switch, default on only in BotW dm_gfx_pass_split_set (gfx/nvn/nvn_mtl.m), at once; + 1.9.0 (PASS_SPLIT_DEFAULT) pass-split.txt above the game's folder (both games); TOTK_PASS_SPLIT first (greyed out) resolution 720p / + MetalFX / 1080p / runtime_output_mode_set (game_patches*.c); the player picks, @@ -704,7 +705,8 @@ static NSArray *settings_rows(void) { ^(int v){dm_gfx_keepalive_set(v);runtime_shared_setting_save("gpu-keepalive.txt",v?"on":"off","GPU keep-alive");})];} /* Long-pass split (nvn_mtl.m pass_split_try): a long render pass is committed in parts while the GPU idles, so the GPU starts on it sooner. Breath of the Wild 1.9.0 uncapped on an M4 Max kept its GPU clock (641 MHz against 344-380 without) - and its frames (10.9 against 14-19 ms); the GPU then works more, so more power at an uncapped frame rate. */ + and its frames (10.9 against 14-19 ms); the GPU then works more, so more power at an uncapped frame rate. On by default + only there (nvn_mtl.m PASS_SPLIT_DEFAULT); Tears of the Kingdom and Breath of the Wild 1.6.0 show it off until switched. */ {NSString *t=settings_text("长通道拆分(GPU 少降频,帧更多)","Long-pass split (steadier GPU clock, more fps)"); if(dm_gfx_pass_split_locked())[rows addObject:settings_fixed(t,settings_on_off(dm_gfx_pass_split()))]; else [rows addObject:settings_row(t,nil,nil,^int{return dm_gfx_pass_split();}, diff --git a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m index 54c546b04..f8f3fc2fb 100644 --- a/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m +++ b/games/totk/third_party/d2r_gfx/gfx/nvn/nvn_mtl.m @@ -18830,32 +18830,41 @@ static void oot_bar_note_draw(NvProg *pr) { 2,700 of its 4,100 draws a frame into one G-buffer pass, and the GPU, done with the shadow passes before it, waits for the whole pass to be translated (nxnative measured about 2.5 ms of a 9 ms frame; M4 Max at 120 fps, frame p50 / p90 8.75 / 9.33 -> 8.34 / 8.68 ms). At a draw, with nothing committed still on the GPU (g_q4_inflight) and TOTK_PASS_SPLIT - draws (default 256, 0 off) since the last commit, the pass is ended, the chunk committed as chunk_maybe_split does, and + draws (PASS_SPLIT_DEFAULT, 0 off) since the last commit, the pass is ended, the chunk committed as chunk_maybe_split does, and the draw opens the pass again: its attachments were stored (always, here) and are loaded, so the pictures are the same. A split costs a store and a load of the attachments, so it is taken only while the GPU would otherwise wait, and at most TOTK_PASS_SPLIT_MAX (default 2) times per NVN pass (a SetRenderTargets, g_cg.rt_seq). Not split: passes opened without all their attachments (g_enc_mode), ranged, layered or cube-merged passes, hoisted or pending clears, the TBDR rewrites and geometry draws. "flag pass_split " sets it while the game runs (0 off; A/B). */ +#define PASS_SPLIT_DRAWS 256 // the threshold the settings switch turns on, and the default where the split is on +/* On by default only where it was measured: Breath of the Wild 1.9.0 on the Mac (review of PR #2191). Other games, other + versions and iPhone / iPad start with it off; the settings switch and TOTK_PASS_SPLIT=256 turn it on there. Widen this + as more games are measured. */ +#if defined(GAME_BOTW190) && !TARGET_OS_IPHONE +#define PASS_SPLIT_DEFAULT PASS_SPLIT_DRAWS +#else +#define PASS_SPLIT_DEFAULT 0 +#endif static _Atomic int g_pass_split = -1; static uint64_t g_pass_splits, g_split_rtseq; static int g_split_n; static uint64_t g_split_busy[5]; // draws past the threshold in an open pass: [0..3] by command buffers still in flight (0, 1, 2, 3+), [4] the pass may not be split static int pass_split_draws(void) { int v = atomic_load_explicit(&g_pass_split, memory_order_relaxed); - if (v < 0) { const char *e = getenv("TOTK_PASS_SPLIT"); v = e ? atoi(e) : 256; if (v < 0) v = 0; + if (v < 0) { const char *e = getenv("TOTK_PASS_SPLIT"); v = e ? atoi(e) : PASS_SPLIT_DEFAULT; if (v < 0) v = 0; int unset = -1; atomic_compare_exchange_strong(&g_pass_split, &unset, v); v = atomic_load(&g_pass_split); } return v; } static void pass_split_set(int draws) { atomic_store(&g_pass_split, draws > 0 ? draws : 0); } static int pass_split_max(void) { static int v = -1; if (v < 0) { const char *e = getenv("TOTK_PASS_SPLIT_MAX"); v = e ? atoi(e) : 2; } return v; } uint64_t mtl_pass_splits(void) { return g_pass_splits; } -/* The settings panel's display page switch (settings_panel.h, pass-split.txt; like the GPU keep-alive): on = the default - 256 draws, off = 0. TOTK_PASS_SPLIT decides first and greys the switch out. */ +/* The settings panel's display page switch (settings_game.h, pass-split.txt; like the GPU keep-alive): on = PASS_SPLIT_DRAWS + draws, off = 0; with nothing saved it shows PASS_SPLIT_DEFAULT. TOTK_PASS_SPLIT decides first and greys the switch out. */ int dm_gfx_pass_split_locked(void) { return getenv("TOTK_PASS_SPLIT") != NULL; } int dm_gfx_pass_split(void) { return pass_split_draws() > 0; } -void dm_gfx_pass_split_start(int on) { if (!dm_gfx_pass_split_locked()) pass_split_set(on ? 256 : 0); } +void dm_gfx_pass_split_start(int on) { if (!dm_gfx_pass_split_locked()) pass_split_set(on ? PASS_SPLIT_DRAWS : 0); } void dm_gfx_pass_split_set(int on) { if (dm_gfx_pass_split_locked() || dm_gfx_pass_split() == !!on) return; - pass_split_set(on ? 256 : 0); + pass_split_set(on ? PASS_SPLIT_DRAWS : 0); MLOG("长通道拆分:设置面板%s | long-pass split: %s from the settings panel", on ? "打开" : "关闭", on ? "on" : "off"); } void mtl_pass_split_busy(uint64_t v[5]) { for (int i = 0; i < 5; i++) v[i] = g_split_busy[i]; }