From e9987ccb9a95698fa393af002f7e4bb0d8825997 Mon Sep 17 00:00:00 2001 From: Adya <114347520+AdyaGMD@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:39:21 +0000 Subject: [PATCH 1/2] Movie enhancement setting: DM_MOVIE_ENHANCE=0 (the launcher's Movie enhancement, shown for games with an nn::movie NDVE network) leaves out the network a movie frame runs between the decoder and the screen and draws its input into its output; Ocarina of Time's title and opening movies spent 60-70 ms a frame in it on an M1 and played at about 13 of their 24 fps Co-Authored-By: Claude Opus 5.5 --- dm/games/game.py | 12 ++++-- dm/games/settings.tsv | 1 + dm/gfx/nvn/nvn_mtl.m | 57 +++++++++++++++++++++++++++++ dm/tools/tests/test_game_profile.py | 13 +++++++ docs/env_switches.tsv | 1 + docs/settings.md | 10 ++++- 6 files changed, 90 insertions(+), 4 deletions(-) diff --git a/dm/games/game.py b/dm/games/game.py index 53e23ee897..080d08e113 100644 --- a/dm/games/game.py +++ b/dm/games/game.py @@ -105,14 +105,19 @@ def by_build(main_id): # the profile whose build rows register this main build UPSCALER_SOURCE = re.compile(r'/agl_ndsr\.pck#') -def upscaler_keys(g): +# nn::movie's enhancement networks (NDVE files, Movie/Ndve/*.dat.zs): the compute shaders the shader map found in the file's NDVE part (Ocarina of Time's 12: the colour conversion +# and the network a movie frame runs; the file's NDSR pack, the scaler to the output, is not among them). DM_MOVIE_ENHANCE=0 leaves the network out (nvn_mtl.m movie_net_dispatch) +MOVIE_NET_SOURCE = re.compile(r'#NDVE@') + + +def upscaler_keys(g, source=UPSCALER_SOURCE): """the game's own upscaler shaders, from its shader map (shader_split.py's source column): sorted 16-digit keys, none without a map""" p = g.table('shader_map.tsv') if not p.exists(): return [] keys = set() for line in p.read_text(encoding='utf-8').splitlines(): c = line.split('\t') - if len(c) >= 5 and c[2] == 'compute' and UPSCALER_SOURCE.search(c[4]) and re.fullmatch(r'[0-9a-f]{16}', c[3]): keys.add(c[3]) + if len(c) >= 5 and c[2] == 'compute' and source.search(c[4]) and re.fullmatch(r'[0-9a-f]{16}', c[3]): keys.add(c[3]) return sorted(keys) @@ -203,7 +208,7 @@ def header_one(g): if vcr not in ('on', 'off'): sys.exit(f'{g.id}: vconv_range must be on or off: {vcr}') 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) + ups, mvn = upscaler_keys(g), upscaler_keys(g, MOVIE_NET_SOURCE) # 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) 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}') gts = g.get('gpu_timestamps', 'submission') # counter timestamps (nvn_mtl.m rep_ticks): submission = one time per submission, segment = the GPU start / end of the segment holding the report @@ -264,6 +269,7 @@ def header_one(g): f'#define DM_GAME_GPU_TS_SEGMENT {int(gts == "segment")}', 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_MOVIE_NET_KEYS {q(",".join(mvn))}', f'#define DM_GAME_MOVIE_NET_N {len(mvn)}', 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) ''] diff --git a/dm/games/settings.tsv b/dm/games/settings.tsv index 15f4824107..f825616a21 100644 --- a/dm/games/settings.tsv +++ b/dm/games/settings.tsv @@ -20,6 +20,7 @@ DM_RENDER_SCALE range 0.5:1.0:0.05 1.0 fixups:RENDER_SCALE Game Render scale le 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_MOVIE_ENHANCE toggle - 1 DM_GAME_MOVIE_NET_N!=0 Game Movie enhancement The game's network that cleans up its movies. Off plays them as decoded, for slower GPUs. 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. diff --git a/dm/gfx/nvn/nvn_mtl.m b/dm/gfx/nvn/nvn_mtl.m index 5f669e0996..7bb959862a 100644 --- a/dm/gfx/nvn/nvn_mtl.m +++ b/dm/gfx/nvn/nvn_mtl.m @@ -5440,6 +5440,7 @@ @interface NvShader : NSObject { @public id fn, tf_fn, discard_fn, NSMutableDictionary *geo_mesh; // a vertex shader's mesh entries by lean kernel key (geo_mesh_fn; NSNull: none) uint8_t up_mfx; // a compute shader that is the game's own upscaler (DM_GAME_UPSCALER_KEYS, from the shader map): 0 not decided, 1 drawn by MetalFX when DM_UPSCALER=metalfx, 2 not one or one its colour keeps (up_mfx_wanted) uint8_t up_color; // such a shader's colour, from its code at load with DM_UPSCALER=metalfx (up_mfx_color; UP_COLOR_UNREAD otherwise) + uint8_t mv_net; // a compute shader of the game's movie enhancement network file (DM_GAME_MOVIE_NET_KEYS): 0 not decided, then one of MVN_* (movie_net_dispatch) int gs_loc, lay_loc; char gs_comp, lay_comp; // a slice-writing geometry shader (no function: the layer comes from input gs_loc.gs_comp) / a vertex shader with layer entry points writing output lay_loc.lay_comp (dmsh_build.py gs_slice, vs_layer_entry); -1 = none uint64_t cbs_seen; uint32_t cbs_runs; // the command buffer that listed this shader last, and how many have (cbs_note) // The argument buffer encoded last time @@ -12691,6 +12692,7 @@ static int lc_keeps(uint32_t op) { static void dispatch(const p_dispatch *dp); static int up_mfx_wanted(NvShader *cs); static int up_mfx_encode(NvShader *cs); // a game's upscaler through MetalFX (see up_mfx_encode) +static int movie_net_dispatch(NvShader *cs); // the movie enhancement network left out (DM_MOVIE_ENHANCE=0, see movie_net_dispatch) // ---------- Compute dispatches moved ahead of the render pass they would split (DM_NVN_CS_HOIST) ---------- // Metal cannot run a compute dispatch inside a render pass, so a dispatch between two draws of one pass ends it, and on a tile-based GPU every attachment is stored and loaded again: // Breath of the Wild runs one GPU particle dispatch per emitter between the G-buffer's effect draws, six to eight splits of a 1600x900 G-buffer a frame (about 350 MB of attachment @@ -13363,6 +13365,7 @@ static void dispatch(const p_dispatch *dp) { rp_flush(); // A full clear with no draw after it waits for the next pass on its targets, but it comes before this dispatch, which may read or write them as images: land it first, as copy_t2t does image_prepare(prog_get(S.cprog), 0x20); if (up_mfx_wanted(cs) && !dp->ind && up_mfx_encode(cs)) return; // the game's upscaler, drawn by MetalFX instead (DM_UPSCALER=metalfx) + if (DM_GAME_MOVIE_NET_N && !dp->ind && movie_net_dispatch(cs)) return; // a dispatch of the movie enhancement network, left out or replaced by a copy (DM_MOVIE_ENHANCE=0) int own = dispatch_own(); g_dispatch_dim[0] = (uint32_t)dp->x; g_dispatch_dim[1] = (uint32_t)dp->y; g_dispatch_dim[2] = (uint32_t)dp->z; // read back by the driver segment c0 (encode_args_) g_c0_dim_buf = nil; @@ -15146,6 +15149,60 @@ static int up_mfx_encode(NvShader *cs) { (unsigned long)out.pixelFormat, direct ? ", straight" : srgb ? ", through RGBA16F, decoded from sRGB" : ", through RGBA16F"); return 1; } +// ---------- The movie enhancement network left out (DM_MOVIE_ENHANCE) ---------- +// nn::movie's NDVE file (Ocarina of Time's Movie/Ndve/Ndve-Nvn2-vid_seq5.dat.zs) holds the compute shaders a movie frame runs between the decoder and the screen: one converts the +// decoded picture (luma 1920x1080, chroma 960x540) to RGB, eleven dispatches of a network then enhance that picture at the same size, the last of them adding their result to it into +// an RGB10A2 image, and an NDSR shader scales it to the output. On an M1 (8-core GPU) the network took 60-70 ms a frame, so the title and opening movies (24 fps) played at about 13. +// With DM_MOVIE_ENHANCE=0 (the launcher's Movie enhancement: off) the network's dispatches (those of the file's shaders that use storage buffers) are left out and its last one (one +// texture, one image, the same size) becomes a draw of its input into its image: the decoded picture as it is, without the network's clean-up. The other shaders of the file run. +// The steps before the last are left out only while the previous frame's copy was made, so a copy refused (another size, an image that cannot be drawn into) costs no frame +enum { MVN_STAGE = 1, MVN_LAST, MVN_NONE }; +static int g_mvn_ok, g_mvn_left; // the previous last step was replaced by the copy; steps left out since it +static uint64_t g_mvn_copied; +static int movie_enh_off(void) { + static int v = -1; + if (v < 0) { const char *e = getenv("DM_MOVIE_ENHANCE"); v = e && !strcmp(e, "0"); + if (e && strcmp(e, "0") && strcmp(e, "1")) MLOG("[RED] DM_MOVIE_ENHANCE=%s: 1 or 0; keeping the movie enhancement", e); + if (v) MLOG("movie enhancement (DM_MOVIE_ENHANCE): off, the movie network's %d shaders are left out and the decoded picture is drawn as it is", DM_GAME_MOVIE_NET_N); } + return v; +} +static int movie_net_named(NvShader *cs) { + for (const char *k = DM_GAME_MOVIE_NET_KEYS; *k; k += k[16] == ',' ? 17 : 16) if (!strncmp(k, cs->key, 16)) return 1; + return 0; +} +static int movie_net_dispatch(NvShader *cs) { + if (cs->mv_net == MVN_NONE || !movie_enh_off()) return 0; + int nt = 0, ni = 0, nsb = 0, ti = -1, oi = -1; + for (int i = 0; i < cs->rf.nb; i++) { int k = cs->rf.b[i].kind; + if (k == NVN_RB_TEX) { nt++; ti = i; } else if (k == NVN_RB_IMG) { ni++; oi = i; } else if (k == NVN_RB_SBUFP || k == NVN_RB_SBUFU) nsb++; } + if (!cs->mv_net) { + cs->mv_net = !movie_net_named(cs) || !nsb ? MVN_NONE : nt == 1 && ni == 1 ? MVN_LAST : MVN_STAGE; // without storage buffers: the colour conversion, which runs + if (cs->mv_net != MVN_NONE) MLOG("movie network %s: %s", cs->key, cs->mv_net == MVN_LAST ? "its last step, replaced by a draw of its input" : "a step, left out"); + if (cs->mv_net == MVN_NONE) return 0; + } + if (cs->mv_net == MVN_STAGE) { if (!g_mvn_ok) return 0; g_mvn_left++; return 1; } + int tin = (int)(tex_slot_h(S.tex[5], S.img[5], cs->rf.b[ti].reg) & 0xfffff), tout = cs->rf.b[oi].reg < 32 ? (int)(S.img[5][cs->rf.b[oi].reg] & 0xfffff) : 0; + tex_t dout = {0}; id in = nil, out = nil; uint64_t rid = 0; int real = 0; + os_unfair_lock_lock(&g_rmu); + int ok = tin > 0 && tin < g_ntreg && g_treg[tin].ok && tout > 0 && tout < g_ntreg && g_treg[tout].ok; + if (ok) { dout = g_treg[tout].t; in = tex_by_id(tin); out = img_binding(tout, &cs->rf.b[oi], &rid, &real); if (!real) out = nil; } + os_unfair_lock_unlock(&g_rmu); + ok = in && out && in != out && in.textureType == MTLTextureType2D && out.textureType == MTLTextureType2D && in.width == out.width && in.height == out.height && + !fmt_int_or_ds(in.pixelFormat) && !fmt_int_or_ds(out.pixelFormat) && !mtl_fmt_block(out.pixelFormat) && (out.usage & MTLTextureUsageRenderTarget); + if (ok) { + zskip_del(dout.serial); + rp_end(); if (g_blit) { enc_b_end(g_blit); g_blit = nil; } + ubd_land_compute(); + NVNcopyRegion r = {0, 0, 0, (int)in.width, (int)in.height, 1}; + ok = copy_t2t_draw(in, out, 0, 0, 0, 0, &r, &r, 0, 0); + args_dirty_all(); + } + if (!ok && g_mvn_left) MLOG("[RED] movie network %s: the copy was refused after %d steps were left out: this frame's picture is wrong; the network runs from now on", cs->key, g_mvn_left); + if (ok && !g_mvn_copied++) MLOG("movie network: first frame drawn without it, %lux%lu (format %lu) → format %lu; its steps are left out from the next frame", (unsigned long)in.width, (unsigned long)in.height, (unsigned long)in.pixelFormat, (unsigned long)out.pixelFormat); + if (!ok) cs->mv_net = MVN_NONE; // the network runs from now on: its earlier steps are no longer skipped either once g_mvn_ok is 0 + g_mvn_ok = ok; g_mvn_left = 0; + return ok; +} // The present pass: src's valid rectangle drawn into dst (the drawable, or a screenshot's texture) as present_encode draws it, through MetalFX first where fx_encode takes it // (fx: the scaler state to use, nil = bilinear). uvb: the pass's crop constants (one buffer per present allocator, written by the CPU) static int present_encode_m4(id cb, id src, id dst, const int crop[4], id uvb, fx_state *fx) { diff --git a/dm/tools/tests/test_game_profile.py b/dm/tools/tests/test_game_profile.py index ca9b229999..c369deb924 100644 --- a/dm/tools/tests/test_game_profile.py +++ b/dm/tools/tests/test_game_profile.py @@ -67,6 +67,19 @@ def test_from_shader_map(self): self.assertEqual(macros(MAP), ['#define DM_GAME_UPSCALER_KEYS "7629d857a0a93833,c56db3d5a0f1b5af"', '#define DM_GAME_UPSCALER_N 2']) +class MovieNetKeys(unittest.TestCase): + def test_from_shader_map(self): # nn::movie's NDVE part (Ocarina of Time's Movie/Ndve file): its compute shaders, not the file's NDSR pack + mv = ('cs_other.bin\t8\tcompute\tba079f68ae288dba\t/Movie/Ndve/Ndve-Nvn2-vid_seq5.dat.zs#NDVE@0x1423e8\n' + 'cs_other.bin\t9\tcompute\t4f41ccf24f163e0d\t/Movie/Ndve/Ndve-Nvn2-vid_seq5.dat.zs#NDSR@0x104fe0\n') + with tempfile.TemporaryDirectory() as d: + Path(d, ID).mkdir() + (Path(d, ID) / 'game.tsv').write_text(TSV) + (Path(d, ID) / 'shader_map.tsv').write_text(MAP.split('cs_other.bin')[0] + mv) + subprocess.run([sys.executable, str(GAME), 'header', ID, str(Path(d, ID) / 'game.h')], env={**os.environ, 'DM_GAMES_DIR': d}, check=True, capture_output=True) + got = [l for l in (Path(d, ID) / 'game.h').read_text().splitlines() if 'MOVIE_NET' in l] + self.assertEqual(got, ['#define DM_GAME_MOVIE_NET_KEYS "ba079f68ae288dba"', '#define DM_GAME_MOVIE_NET_N 1']) + + if __name__ == '__main__': unittest.main() diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv index 399702b374..12870f610b 100644 --- a/docs/env_switches.tsv +++ b/docs/env_switches.tsv @@ -105,6 +105,7 @@ DM_MOTION_AXES switch `=` such as `x,-z,y`: maps Apple's controller axes to DM_MOTION_GAIN switch `=`: how fast the orientation is pulled toward the measured gravity, in rad/s per unit error (default 0.5; `0` integrates the gyro alone) DM_MOTION_HID switch On the Mac, `0` disables the passive Switch Pro Controller HID motion fallback (`motion_pro_mac.h`); enabled by default when exactly one physical Pro and one GameController Pro can use the same player slot; usable GameController motion takes priority DM_MOTION_LOG diagnostic `=1` logs player 1's mapped motion sample once a second per source (phone / GameController / controller HID; acceleration in G, gyro in revolutions/s), for checking the axes: flat and still reads acc 0 0 -1 +DM_MOVIE_ENHANCE player `0` leaves out the movie enhancement network of nn::movie's NDVE file (Ocarina of Time's Movie/Ndve, 60-70 ms a movie frame on an M1) and draws the decoded picture into its output; `1` (the default) runs it (`nvn_mtl.m` `movie_net_dispatch`). The launcher's Movie enhancement DM_MOVIE_TRACE diagnostic When set, the movie decoder logs every call with its thread and decoder (by default the first 12 calls, then every 2^k-th) DM_MSL_DIR path Parent folder of the shader libraries: NVN loads from `b-/` or the one file `b-.img` beneath it, Vulkan from `vk/`, GL from `gl/`; the app and the Mac launcher set it DM_NICK switch The account nickname the game sees (default `Player`) diff --git a/docs/settings.md b/docs/settings.md index a826eeeacf..c3358d6dbc 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -3,7 +3,7 @@ The screen before the game starts shows the settings the game supports. A setting that only matters while another is on appears under it and disappears when that one is turned off. Tap **Play** to start; the app remembers your choices for the next start. All settings are on one scrollable screen, under **Game**, **Controls** and **Performance**. Tap a menu or move a slider there; no settings page needs opening. **Upscaling** is in **Game**, beside **Console mode**. A Mac app shows the same settings in a [window of its own](#the-mac-settings-window). - [Tested defaults](#tested-defaults) -- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) +- [Game](#game): [Frame rate](#frame-rate), [Render scale](#render-scale), [Console mode](#console-mode), [Upscaling](#upscaling), [Game's upscaler](#games-upscaler), [Movie enhancement](#movie-enhancement), [Game language](#game-language), [Picture](#picture), [Frame-rate counter](#frame-rate-counter) - [Controls](#controls): [Touch feedback](#touch-feedback), [Game rumble](#game-rumble), [Rumble strength](#rumble-strength), [Rumble cutoff](#rumble-cutoff), [Press a button to join](#press-a-button-to-join) - [Performance](#performance): [Frame buffering](#frame-buffering), [Metal 4 pipelines](#metal-4-pipelines), [Pipeline prebuild](#pipeline-prebuild), [Encode thread](#encode-thread), [Hold frames when late](#hold-frames-when-late), [Performance HUD](#performance-hud), [Reset to tested defaults](#reset-to-tested-defaults) - [The Mac settings window](#the-mac-settings-window): [Display mode](#display-mode) @@ -75,6 +75,13 @@ flowchart LR - **Cost:** none in GPU time (it saves 2.5-4 ms a frame in that case); the picture is Apple's scaler's rather than the game's. Frames where the game renders at its output size are not upscaled and keep the game's shader either way. Devices without MetalFX keep the game's upscaler. - **Not the same as [Upscaling](#upscaling):** that one scales the finished picture, HUD included, to the screen; this one replaces the game's own step inside the frame. Both can be on. + +### Movie enhancement + +Shown only for games whose movies go through a network of Nintendo's movie library before they reach the screen: The Legend of Zelda: Ocarina of Time's title and opening movies. **On**, the default, keeps it. **Off** leaves the network out and shows each movie frame as it was decoded: a little softer, at a fraction of the GPU time. + +- **When to change it:** when the movies stutter. On an M1 the network takes 60-70 ms of every movie frame, so the opening movie (24 fps) plays at about 13 fps; off, the movie keeps its pace. +- **On the Mac:** the setting under **Game** in the [settings window](#the-mac-settings-window), or `DM_MOVIE_ENHANCE=0` in its `env.txt`. ### Game language The game's own languages. The app was packed with one of them; pick another here without repacking. A game packed from a dump or a NUP may come without its list: every language is offered then, with a note, and a game that lacks the one you pick may show another. @@ -279,6 +286,7 @@ A line like `DM_PRESENT_SNAP=0` in `Documents/env.txt` (in the Files app, under | Press a button to join | `DM_PAD_PRESS_TO_JOIN` | `1`, `0` | | Upscaling | `DM_PRESENT_UPSCALE` | `off`, `metalfx` | | Game's upscaler | `DM_UPSCALER` | `game`, `metalfx` | +| Movie enhancement | `DM_MOVIE_ENHANCE` | `1`, `0` | | Frame buffering | `DM_PRESENT_SNAP` | `1`, `0` | | Metal 4 pipelines | `DM_PSO_MTL4` | `1`, `0` | | Pipeline prebuild | `DM_PSO_PREBUILD` | `1`, `0` | From 06c2598b2c576ba9139e74686f12f48c62e22562 Mon Sep 17 00:00:00 2001 From: Adya <114347520+AdyaGMD@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:29:52 +0000 Subject: [PATCH 2/2] Movie enhancement off also skips the NDVE engine's network, and the engine's resampler runs alone Since the NDVE engine (nn::ndve's network as the host's kernels) came to main, it took the network's dispatches before movie_net_dispatch could leave them out, so with DM_MOVIE_ENHANCE=0 the whole network still ran. The engine now steps aside when the enhancement is off, and only its resampler takes the game's 4f41ccf2 (ndve_resample_alone), on the picture as decoded: the game's translated resampler took 24 ms of the frame. Ocarina of Time's opening movie on an M1 (8-core GPU), DM_FPS_TARGET=60: 27 ms of GPU a movie frame -> 7 ms, 60 fps held, the movie at its speed (16 s of stream time in 16 s). Co-Authored-By: Claude Opus 5.5 --- dm/gfx/nvn/nvn_mtl.m | 6 +++++- dm/gfx/nvn/nvn_ndve.inc | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dm/gfx/nvn/nvn_mtl.m b/dm/gfx/nvn/nvn_mtl.m index 1736d9cfaa..b5cbbf8c1a 100644 --- a/dm/gfx/nvn/nvn_mtl.m +++ b/dm/gfx/nvn/nvn_mtl.m @@ -14345,6 +14345,8 @@ static int lc_keeps(uint32_t op) { static void dispatch(const p_dispatch *dp); static int up_mfx_wanted(NvShader *cs); static int up_mfx_encode(NvShader *cs); // a game's upscaler through MetalFX (see up_mfx_encode) static int movie_net_dispatch(NvShader *cs); // the movie enhancement network left out (DM_MOVIE_ENHANCE=0, see movie_net_dispatch) +static int movie_enh_off(void); // DM_MOVIE_ENHANCE=0 (see movie_net_dispatch) +static int ndve_resample_alone(NvShader *cs); // nvn_ndve.inc: the engine's resampler with the movie enhancement off static int ndve_engine_dispatch(NvShader *cs, const p_dispatch *dp); // nn::ndve's movie network as the host's kernels (DM_NDVE_ENGINE=1, nvn_ndve.inc) // ---------- Compute dispatches moved ahead of the render pass they would split (DM_NVN_CS_HOIST) ---------- // Metal cannot run a compute dispatch inside a render pass, so a dispatch between two draws of one pass ends it, and on a tile-based GPU every attachment is stored and loaded again: @@ -15128,7 +15130,9 @@ static void dispatch(const p_dispatch *dp) { if (g_nubd && ubd_conflict_cs(cs, dp->ind)) { g_ubd_conflicts++; ubd_land(); } // see ubd_conflict_cs rp_flush(); // A full clear with no draw after it waits for the next pass on its targets, but it comes before this dispatch, which may read or write them as images: land it first, as copy_t2t does image_prepare(prog_get(S.cprog), 0x20); - if (ndve_engine_dispatch(cs, dp)) return; // nn::ndve's movie network as the host's kernels (DM_NDVE_ENGINE=1) + // nn::ndve's movie network as the host's kernels (DM_NDVE_ENGINE=1), unless the movie enhancement is off: then the network is left out (movie_net_dispatch), as the player chose. + // The engine came first, so with Movie enhancement off Ocarina of Time's opening still ran the whole network: 26 ms of a movie frame on an M1, the movie at half speed + if (DM_GAME_MOVIE_NET_N && movie_enh_off() ? ndve_resample_alone(cs) : ndve_engine_dispatch(cs, dp)) return; // off: the engine's resampler alone, on the decoded picture if (up_mfx_wanted(cs) && !dp->ind && up_mfx_encode(cs)) return; // the game's upscaler, drawn by MetalFX instead (DM_UPSCALER=metalfx) if (DM_GAME_MOVIE_NET_N && !dp->ind && movie_net_dispatch(cs)) return; // a dispatch of the movie enhancement network, left out or replaced by a copy (DM_MOVIE_ENHANCE=0) // Threadgroup memory past Metal's 32 KB, in a device buffer (dmsh_rewrite.py tg_spill): a slice for every workgroup of the grid. An indirect dispatch's grid is in GPU memory, written earlier diff --git a/dm/gfx/nvn/nvn_ndve.inc b/dm/gfx/nvn/nvn_ndve.inc index 74f5e82d1c..d9f03a1ccd 100644 --- a/dm/gfx/nvn/nvn_ndve.inc +++ b/dm/gfx/nvn/nvn_ndve.inc @@ -203,6 +203,18 @@ static void ndve_compare(id a, id b, int slot) { slot ? "resampler" : "network", (unsigned long long)*n, c[2 * slot], (unsigned long)a.width, (unsigned long)a.height, c[2 * slot + 1]); } } +// With the movie enhancement off (DM_MOVIE_ENHANCE=0) the network is left out (nvn_mtl.m movie_net_dispatch), but the resampler 4f41ccf2 still runs, on the picture as decoded: +// the game's translated one took 24 ms of an M1's movie frame (8-core GPU), so the movie fell to 30 pictures a second, half its speed. The engine's resampler takes it then +static int ndve_resample_alone(NvShader *cs) { + if (!ndve_mode() || ndve_check() || g_nd.off || ndve_index(cs, NDVE_N - 1) != NDVE_N - 1) return 0; + if (g_nd.state == 0) ndve_build(); + if (g_nd.state != 2) return 0; + const p_bind_buf *w = &S.ssbo[5][2]; void *wb = NULL; uint64_t wo = 0; + if (!w->addr || w->size < 0x3000 || !mtl_gpu_addr(w->addr, 0x3000, &wb, &wo, &g_nd.wrs)) { static int once; if (!once++) MLOG("NDVE engine: the resampler's weights are not bound; the game's resampler runs"); return 0; } + if (!ndve_resample(cs, nil)) return 0; + if (!g_nd.rs_frames++) MLOG("NDVE engine: first movie frame resampled by the engine (the movie enhancement off)"); + return 1; +} // 1 when the dispatch was taken (skipped or replaced by the engine), 0 to run it static int ndve_engine_dispatch(NvShader *cs, const p_dispatch *dp) { const int chk = ndve_check();