mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-23 11:39:42 -10:00
DM_NVN_CAPTURE: gone texture IDs, the standard thread policy, pool bytes last
- A texture ID whose memory pool was finalized stays registered (the host marks it gone); the capture read the freed pool object through tex_t.pool. Pokemon Scarlet reuses that memory for texture data, which became pool addresses, sizes and a sparse mode: 11 addresses outside every pool, and once an incomplete capture. cap_treg carries gone (a padding byte, 0 in older captures), a gone entry keeps no pool or storage and is not read back, and nvn_replay marks it gone (mtl_reg_tex_gone). t_capture_live finalizes a texture's own pool and fills the object with such bytes: without the fix the capture is incomplete. - Each capture step runs under the standard thread policy and gives the thread its own back after it: the submitting thread can hold a time-constraint policy declared for a few ms a frame, and the kernel ran the step in short slices (Scarlet: 1,178 s to capture frame 3000, now 53 s; BotW frame 5000: 124 s, now 34 s). The log gives each step's time. - Pool bytes are copied last in a submit's step, once, as the live replay of the submit reads them (new regions whole, then the changed blocks); the bytes that changed after a region was found are logged (0 in both games). - regress.py capture: the capture step is bounded by --capture-limit, not the 300 s hang time (a slow step was stopped as a hang). - BotW: the capture that differed from every replay in 1,603 pixels is a rare live outcome of the depth-EQUAL variation (the later replayer gives the same on it; three new captures replay within 0 to 246 pixels). The current capture: 4 of 8 equal, noise 113. Scarlet: 4 of 8, noise 20. Regression check (normal, 3 games): Scarlet (the registry and pool finalize path; 1 new RED, the zero-copy buffer retry under another session's load), BotW (PASS), TotK (screenshots at 50/57 s within its baseline runs' own variation, the opening cutscene at other moments).
This commit is contained in:
1 parent
d0c32447bb
commit
f5aee5aa0d
12 files changed
+126
-44
No files matched your search
@@ -156,7 +156,7 @@ On this Mac the background prewarm also ends before the save loads, so the step
|
||||
|
||||
### The regression route (2026-10-29, current)
|
||||
|
||||
`smoke.tsv` takes the outdoors save (`saves/outdoors` in the NSP folder) with frame-numbered presses, `f300:A` to `f1700:A`; the Zora's Domain save it used before is no longer on the test Mac. Link stands in a field from about 50 s; with the window on screen (M4 Pro) frame 3,000 comes at 57 s and 6,000 at 107 s, while a covered window runs at 20 fps ([covered windows](../../../docs/reference/frame-rate.md)). `regress.py capture` records frame 5000 for `regress.py replay`: noise up to about 150 pixels with 5d2bf73f; captured again at chain `a31235713eee` (2026-10-29, after the record layout changed), every replay gives one digest that differs from the live frame in 1,603 pixels (Open). In 2 of 6 `regress.py check` runs on 2026-10-29 the game stayed at 20 fps from the start (frame 2500 not reached by 60 s: NEW-FAIL): the frame step went from 1 to 3 vsyncs at presents 12–15 on three late frames costing 0.02 vsyncs and never came back; a third run stepped up the same way and returned to 60 (Open).
|
||||
`smoke.tsv` takes the outdoors save (`saves/outdoors` in the NSP folder) with frame-numbered presses, `f300:A` to `f1700:A`; the Zora's Domain save it used before is no longer on the test Mac. Link stands in a field from about 50 s; with the window on screen (M4 Pro) frame 3,000 comes at 57 s and 6,000 at 107 s, while a covered window runs at 20 fps ([covered windows](../../../docs/reference/frame-rate.md)). `regress.py capture` records frame 5000 for `regress.py replay`: noise up to about 150 pixels with 5d2bf73f; one capture at chain `a31235713eee` differed from every replay in 1,603 pixels, a rare live outcome of the depth-EQUAL variation (Frame capture and replay, under Open); later captures replay within 0 to 246 pixels. The current one (chain `2fcec1622a5f`, 2026-10-29): 4 of 8 replays equal the live frame, noise 113 pixels, captured in 34 s. In 2 of 6 `regress.py check` runs on 2026-10-29 the game stayed at 20 fps from the start (frame 2500 not reached by 60 s: NEW-FAIL): the frame step went from 1 to 3 vsyncs at presents 12–15 on three late frames costing 0.02 vsyncs and never came back; a third run stepped up the same way and returned to 60 (Open).
|
||||
|
||||
### Final synchronization and pass validation (2026-10-26, current)
|
||||
|
||||
@@ -195,6 +195,7 @@ Before publishing, the fixes were integrated with main's pipeline archive and GP
|
||||
General host changes first needed here; each applies to every game:
|
||||
|
||||
- **Movies at twice their speed at 60 fps** (issue #636): [Movies hold 30 fps under the frame step](../../../docs/reference/frame-rate.md#movies-hold-30-fps-under-the-frame-step).
|
||||
- **Frame captures under the standard thread policy** (`cap_policy_standard`; also on Pokemon Scarlet): [A frame capture runs under the standard thread policy](../../../docs/reference/nvn-objects.md#a-frame-capture-runs-under-the-standard-thread-policy).
|
||||
- **The options' Labo VR mode answered as not permitted** (reported by MacNativeGames): [Hooks whose return type did not match the SDK](../../../docs/reference/services.md#hooks-whose-return-type-did-not-match-the-sdk).
|
||||
- **Shared performance work, checked independently of prewarm data:** [CPU deswizzle copies use slice and row offsets](../../../docs/reference/nvn-objects.md#cpu-deswizzle-copies-use-slice-and-row-offsets) and [Host symbol indexes avoid repeated name scans](../../../docs/reference/services.md#host-symbol-indexes-avoid-repeated-name-scans). [PR #261](https://github.com/seedds/nxnative/pull/261) reports M2 iPad Pro gameplay on update 1.9.0; local verification covers synthetic correctness and CPU microbenchmarks, without a new game/device run.
|
||||
- **Final #158/#213 gameplay validation:** [Current results](#final-synchronization-and-pass-validation-2026-10-26-current) distinguish the retained pass savings from the timing gains not demonstrated on this Mac.
|
||||
@@ -230,7 +231,7 @@ General host changes first needed here; each applies to every game:
|
||||
|
||||
- The shipped pipeline archive without the device's own earlier prebuild files (the test iPhone's `pso_archive/` still held them, [Pipelines on a cold start](#pipelines-on-a-cold-start)): the footprint against the app's memory limit and the frame times after it.
|
||||
|
||||
- Frame capture and replay ([development.md](../../../docs/development.md#frame-capture-and-replay), GitHub issue #402): a fresh replay does not always give the same digest, with or without segmented submission (open). Outdoors route, frame 4000, `DM_NVN_CUT=0` (2026-10-28, M4 Pro): the live digest in most fresh replays, another in 2 to 7 of 24, among about eight others. The replay has one segment then (nothing is committed before the frame's end), the per-draw pass dumps (state, vertex-stage uniform content, vertex streams) of a matching and a differing replay are identical, every texture the frame has by then is identical at every level after the G-buffer pass (pass 32), and so are that pass's depth and its colour targets 0 and 5; only colour targets 1 and 3 differ (the normal and material outputs of fragment shader `8d56b5cee7c434f6`), and each other digest follows from them. Dropping some of the pass's draws (a probe not kept) narrowed it to 2 pixels where draw 520 of the frame and a later draw both write, the later one usually winning; with depth compare `ALWAYS` for that shader it still varies. Ruled out, each by 16 to 30 fresh replays that still varied: pipelines through the `MTLDevice` (`DM_PSO_MTL4=0`), no prewarm, archive or prediction, the uniform copy worker (`DM_NVN_UB_COPY_THREAD=0`; its shadows also equal synchronous copies), a barrier between every operation of the copy encoder, waiting for every upload batch, a fill pattern in new arena blocks; Metal's API validation reports no error, and shader validation only the [non-resident views](../../../docs/reference/rendering.md#compatible-views-made-from-the-texture-under-a-view) (fixed; not the cause). The earlier reading of Zora's Domain, frame 3000 (one segment boundary between passes 38 and 39 changes the digest, `DM_NVN_CUT=0` always matches), fits this variation too. A second capture of the outdoors route (frame 4000, then frame 5000, same Mac and day) shows the same: with the default segmented submission every fresh replay differs from the live frame, in 97 to 124 pixels (two recurring sets, at most 46 of 255), and with `DM_NVN_CUT=0` between one and five in eight do, in 3 to 124 pixels (also with the `tex_fit` fix); the first difference is again in pass 32, four edge pixels one draw writes (vertex shader `d9670d25c6290936`, fragment `a331f28b1ddbc517`). Ending pass 32 after every draw, or every 100 draws, makes the frame repeat 16 times in 16; every 500 draws, or one break anywhere, does not. What varies is the outcome of depth-equal tests (2026-10-29, frame 5000, `DM_NVN_CUT=0`): pass 32 has draws with depth test `EQUAL` and no depth write (1208–1217 and 1394–1429 in frame 4000), and drawing every such draw with less-or-equal instead (a probe, not kept) makes 16 fresh replays of 16 give one digest, where the unchanged build gave the live one in 11 and another in 5. Nothing the GPU writes in the frame is read by pass 32 (`--writes`, with each writer and reader placed by draw), so its vertex and uniform inputs are the captured bytes in every replay; the depth an `EQUAL` draw compares against, or its own, is then not bit-reproducible from run to run inside a long pass on this GPU. Two more probes (10 fresh replays each): with the `EQUAL` draws' fragment output replaced by their fragment depth's bits in colour target 0 (and their test set to `ALWAYS`), those bits are identical in every replay wherever no later draw covers them; and pass 32's depth buffer at the end of the frame is identical in every replay, also in the two whose pass 32 differs (in 22 and 4 pixels, colour targets 1 and 3 only). The `EQUAL` draws use no depth bias or clamp (46 of 46 in frame 4000). So both operands of the test, as far as they can be read, are the same in every replay while its result is not: the depth the test reads at that moment, inside one long pass, is the remaining suspect, on the GPU's side (partial renders of a long pass are one candidate, not shown). A third replay of the ten differs only after pass 32, so a second varying spot exists later in the frame. Also ruled out there: the regions' addresses (mapped at fixed addresses), the order of separate commits (each waiting on a queue event for the one before), residency (`DM_RES_CHECK=1`) and the vertex / fragment interface. A cause on the GPU side in long passes is likely, not shown; a GPU capture of a matching and a differing replay is the next step. `nvn_replay --max-pixels` judges a change within this noise. A second replay in one process (`--warm`) also differs. Pool blocks after the frame match the live run except counter reports and the blocks the CPU writes during the frame. The variation is this game's, not the replay layer's in general: a frame of Super Mario Bros. Wonder's opening course (59 passes, 436 draws, segmented submission on) gives the live digest in 8 fresh replays of 8 (2026-10-29, M4 Pro). Fixed on the way: block-compressed textures (a 32x32 BC4) and transient render targets rLine truncated
|
||||
- Frame capture and replay ([development.md](../../../docs/development.md#frame-capture-and-replay), GitHub issue #402): a fresh replay does not always give the same digest, with or without segmented submission (open). Outdoors route, frame 4000, `DM_NVN_CUT=0` (2026-10-28, M4 Pro): the live digest in most fresh replays, another in 2 to 7 of 24, among about eight others. The replay has one segment then (nothing is committed before the frame's end), the per-draw pass dumps (state, vertex-stage uniform content, vertex streams) of a matching and a differing replay are identical, every texture the frame has by then is identical at every level after the G-buffer pass (pass 32), and so are that pass's depth and its colour targets 0 and 5; only colour targets 1 and 3 differ (the normal and material outputs of fragment shader `8d56b5cee7c434f6`), and each other digest follows from them. Dropping some of the pass's draws (a probe not kept) narrowed it to 2 pixels where draw 520 of the frame and a later draw both write, the later one usually winning; with depth compare `ALWAYS` for that shader it still varies. Ruled out, each by 16 to 30 fresh replays that still varied: pipelines through the `MTLDevice` (`DM_PSO_MTL4=0`), no prewarm, archive or prediction, the uniform copy worker (`DM_NVN_UB_COPY_THREAD=0`; its shadows also equal synchronous copies), a barrier between every operation of the copy encoder, waiting for every upload batch, a fill pattern in new arena blocks; Metal's API validation reports no error, and shader validation only the [non-resident views](../../../docs/reference/rendering.md#compatible-views-made-from-the-texture-under-a-view) (fixed; not the cause). The earlier reading of Zora's Domain, frame 3000 (one segment boundary between passes 38 and 39 changes the digest, `DM_NVN_CUT=0` always matches), fits this variation too. A second capture of the outdoors route (frame 4000, then frame 5000, same Mac and day) shows the same: with the default segmented submission every fresh replay differs from the live frame, in 97 to 124 pixels (two recurring sets, at most 46 of 255), and with `DM_NVN_CUT=0` between one and five in eight do, in 3 to 124 pixels (also with the `tex_fit` fix); the first difference is again in pass 32, four edge pixels one draw writes (vertex shader `d9670d25c6290936`, fragment `a331f28b1ddbc517`). Ending pass 32 after every draw, or every 100 draws, makes the frame repeat 16 times in 16; every 500 draws, or one break anywhere, does not. What varies is the outcome of depth-equal tests (2026-10-29, frame 5000, `DM_NVN_CUT=0`): pass 32 has draws with depth test `EQUAL` and no depth write (1208–1217 and 1394–1429 in frame 4000), and drawing every such draw with less-or-equal instead (a probe, not kept) makes 16 fresh replays of 16 give one digest, where the unchanged build gave the live one in 11 and another in 5. Nothing the GPU writes in the frame is read by pass 32 (`--writes`, with each writer and reader placed by draw), so its vertex and uniform inputs are the captured bytes in every replay; the depth an `EQUAL` draw compares against, or its own, is then not bit-reproducible from run to run inside a long pass on this GPU. Two more probes (10 fresh replays each): with the `EQUAL` draws' fragment output replaced by their fragment depth's bits in colour target 0 (and their test set to `ALWAYS`), those bits are identical in every replay wherever no later draw covers them; and pass 32's depth buffer at the end of the frame is identical in every replay, also in the two whose pass 32 differs (in 22 and 4 pixels, colour targets 1 and 3 only). The `EQUAL` draws use no depth bias or clamp (46 of 46 in frame 4000). So both operands of the test, as far as they can be read, are the same in every replay while its result is not: the depth the test reads at that moment, inside one long pass, is the remaining suspect, on the GPU's side (partial renders of a long pass are one candidate, not shown). A third replay of the ten differs only after pass 32, so a second varying spot exists later in the frame. Also ruled out there: the regions' addresses (mapped at fixed addresses), the order of separate commits (each waiting on a queue event for the one before), residency (`DM_RES_CHECK=1`) and the vertex / fragment interface. A cause on the GPU side in long passes is likely, not shown; a GPU capture of a matching and a differing replay is the next step. `nvn_replay --max-pixels` judges a change within this noise. A second replay in one process (`--warm`) also differs. Pool blocks after the frame match the live run except counter reports and the blocks the CPU writes during the frame. The variation is this game's, not the replay layer's in general: a frame of Super Mario Bros. Wonder's opening course (59 passes, 436 draws, segmented submission on) gives the live digest in 8 fresh replays of 8 (2026-10-29, M4 Pro). Fixed on the way: block-compressed textures (a 32x32 BC4) and transient render targets rLine truncated
|
||||
- Shrine slowdown (GitHub issues #534, #598): the size-0 fix has not been run in a shrine with a slowdown. A save from before Oman Au's final gate would show whether the refusals end there, or whether another write is behind them (the `residency set` line's `other GPU writes` count).
|
||||
- The frame step can stay at 3 vsyncs (20 fps) after the late frames at the start of the regression route, frames that cost 0.02 vsyncs ([The regression route](#the-regression-route-2026-10-29-current)): in 2 runs of 3 it did not come back to 1. Why the tries at the shorter hold did not take it back is open.
|
||||
- The GPU particles' compute dispatches and the G-buffer decals still split passes; about 800 MB of attachments a frame outdoors.
|
||||
|
||||
@@ -85,10 +85,20 @@ existing [per-depth-mode entry-point mechanism](../../../docs/reference/shaders.
|
||||
- [`smoke.tsv`](smoke.tsv) uses an isolated, fixed copy of the save just after
|
||||
getting up at `<NSP folder>/0100A3D008C5C000-work/smoke-save`. Make that
|
||||
copy before running the regression harness; the save stays outside the repo.
|
||||
`regress.py capture` records its frame 3000 for `regress.py replay`: 7 of 8
|
||||
replays equal the live frame, noise 18 pixels (2026-10-29). The first
|
||||
`regress.py capture` records its frame 3000 for `regress.py replay`: 4 of 8
|
||||
replays equal the live frame, noise 20 pixels (2026-10-29, chain
|
||||
`6ad4d951e3c8`; 7 of 8 and 18 pixels in an earlier capture). The capture
|
||||
takes 53 s ([a frame capture runs under the standard thread
|
||||
policy](../../../docs/reference/nvn-objects.md#a-frame-capture-runs-under-the-standard-thread-policy),
|
||||
resolved; 1,178 s before). The first
|
||||
captures aborted the replay ([a replay's own objects take serials above a
|
||||
capture's](../../../docs/reference/nvn-objects.md#a-replays-own-objects-take-serials-above-a-captures), resolved).
|
||||
Texture IDs 1726 to 1786 in the bedroom stay registered after the game
|
||||
finalizes their textures' memory pools (each texture has a pool of its own)
|
||||
and reuses the pool objects' memory. The capture read texture data there as
|
||||
pool addresses and once stopped incomplete ([a captured texture ID whose memory
|
||||
pool was finalized](../../../docs/reference/nvn-objects.md#a-captured-texture-id-whose-memory-pool-was-finalized),
|
||||
resolved).
|
||||
- **Initial gameplay validation, 2026-10-27, chain `7fbca6dd477d`:**
|
||||
the complete Mac shaders render the character,
|
||||
academy, movie and bedroom. A fresh 10-minute run and a 20-minute reload
|
||||
@@ -213,13 +223,6 @@ existing [per-depth-mode entry-point mechanism](../../../docs/reference/shaders.
|
||||
reports `[RED] NVN unimplemented function called`. Its visual contribution
|
||||
has not been isolated; the diagnostic has not been suppressed.
|
||||
- Outdoor exploration and battles have not been validated yet.
|
||||
- Texture registry entries 1726 to 1786 (serials 15340 to 15387 in the bedroom,
|
||||
2026-10-29) hold a texture whose storage address is data and whose layout size
|
||||
is 0; `DM_NVN_CAPTURE` keeps those addresses as they are (`outside every pool`,
|
||||
`texture registry entry …`). One earlier capture also found one of them over
|
||||
readable memory beside a region (`straddles a region`) and was incomplete. Whether
|
||||
the game registers textures it has not initialized, or writes over registered
|
||||
texture objects, is open.
|
||||
- iPhone gameplay, device memory and touch controls are untested. Audio runs
|
||||
through both Wwise output queues on the Mac without sustained underruns;
|
||||
listening on the iPhone is pending.
|
||||
@@ -230,5 +233,7 @@ existing [per-depth-mode entry-point mechanism](../../../docs/reference/shaders.
|
||||
- [1 GB alignment of regions of 1 GB and more](../../../docs/reference/memory.md#1-gb-alignment-of-regions-of-1-gb-and-more).
|
||||
- [Maps past the application pool fail as on Horizon](../../../docs/reference/memory.md#maps-past-the-application-pool-fail-as-on-horizon).
|
||||
- [A replay's own objects take serials above a capture's](../../../docs/reference/nvn-objects.md#a-replays-own-objects-take-serials-above-a-captures).
|
||||
- [A captured texture ID whose memory pool was finalized](../../../docs/reference/nvn-objects.md#a-captured-texture-id-whose-memory-pool-was-finalized).
|
||||
- [A frame capture runs under the standard thread policy](../../../docs/reference/nvn-objects.md#a-frame-capture-runs-under-the-standard-thread-policy).
|
||||
- [Conservative rasterization remains unimplemented](../../../docs/reference/rendering.md#conservative-rasterization-remains-unimplemented).
|
||||
- [Metal's build folders left by pipeline archive flushes](../../../docs/reference/shaders.md#metals-build-folders-left-by-pipeline-archive-flushes).
|
||||
@@ -64,7 +64,8 @@ typedef struct { uint32_t index, flags; uint64_t mem, size; int32_t vmode, pad;
|
||||
// whose translated shaders take other bindings than the records were made for stops (nvn_replay) instead of drawing with them
|
||||
typedef struct { uint32_t index, nstage; uint64_t serial; uint8_t key[6][8]; uint8_t ok, pad[7]; uint64_t iface[6]; } cap_prog;
|
||||
typedef struct { uint32_t index; int32_t n; uint64_t pool; int64_t off; int32_t tex_base, samp_base; } cap_dpol; // pool: CAP_OBJ(CAP_K_POOL)
|
||||
typedef struct { int32_t tid; uint8_t ok, has_v, pad[2]; tex_t t; view_t v; } cap_treg;
|
||||
// gone: the ID stays registered but its memory pool was finalized (treg_drop_pool_views): t keeps neither its pool nor its storage address, which name memory the game has since reused
|
||||
typedef struct { int32_t tid; uint8_t ok, has_v, gone, pad; tex_t t; view_t v; } cap_treg;
|
||||
typedef struct { int32_t sid, pad; samp_par p; } cap_sreg;
|
||||
// per texture the frame reaches: live = initialized and not finalized (mtl_tex_init); cpu = its host texture is uploaded from its pool (CPU-written, or a texture the
|
||||
// flush tracking of DM_GAME_TEX_DIRTY_UPLOAD made packaged): the replay marks it CPU-written so it takes the same path
|
||||
|
||||
+62
-21
@@ -5,7 +5,7 @@
|
||||
// in Metal that the frame can reach (registered or named by a record), and each submission's record bytes with pointers written as region offsets and object indices. Before
|
||||
// each later submit of the frame, the pool bytes that changed (GPU writes included) and the registry entries that changed. At the present: the presented texture's SHA-256,
|
||||
// read back the same way the replayer reads its own (cap_digest). Each capture step first waits for the GPU (mtl_finish), so what is read is what the next submit sees; that
|
||||
// changes the frame's timing, not what it renders. Unset, the hooks cost one load and a branch per submit and present.
|
||||
// changes the frame's timing, not what it renders. The pool bytes are copied last in each submit's step (cap_mem), as the live replay of the submit reads them. Unset, the hooks cost one load and a branch per submit and present.
|
||||
#include "nvn_capture.h"
|
||||
#include <crt_externs.h>
|
||||
|
||||
@@ -16,7 +16,7 @@ static uint32_t g_cap_submit; // submits captured in the frame so far
|
||||
static uint64_t g_cap_presents; // presents seen (the frame number DM_NVN_SHOT uses)
|
||||
static cap_writer g_cap_w;
|
||||
static uint64_t g_cap_t0, g_cap_ns, g_cap_unmapped, g_cap_segs, g_cap_tex_bytes, g_cap_tex_n, g_cap_tex_skip;
|
||||
typedef struct { uint64_t lo, size; uint32_t kind; uint64_t *hash; } cap_region; // hash: one per 4 KiB block, for the changes before later submits
|
||||
typedef struct { uint64_t lo, size; uint32_t kind, pending; uint64_t *hash; } cap_region; // hash: one per 4 KiB block, for the changes before later submits; pending: bytes not written yet
|
||||
static cap_region *g_cap_reg; static uint32_t g_cap_nreg;
|
||||
static nvn_hmap g_cap_tex = {.klen = sizeof(tex_t)}, g_cap_prog = {.klen = 16}, g_cap_dpol = {.klen = 8 + sizeof(dpool_t)}, g_cap_sync = {.klen = 8}, g_cap_pool = {.klen = 8 + sizeof(pool_t)};
|
||||
static nvn_hmap g_cap_seg = {.klen = 8}, g_cap_read = {.klen = 8};
|
||||
@@ -51,22 +51,18 @@ static int cap_reg_find(uint64_t a) { // the region holding address a (regions
|
||||
while (lo <= hi) { int m = (lo + hi) / 2; if (a < g_cap_reg[m].lo) hi = m - 1; else if (a >= g_cap_reg[m].lo + g_cap_reg[m].size) lo = m + 1; else return m; }
|
||||
return -1;
|
||||
}
|
||||
static void cap_reg_hash(cap_region *r) {
|
||||
static void cap_reg_hash(cap_region *r, const uint8_t *p) { // p: the region's bytes (or the copy that was written)
|
||||
size_t nb = (size_t)((r->size + 4095) / 4096); r->hash = realloc(r->hash, nb * 8);
|
||||
for (size_t b = 0; b < nb; b++) { uint64_t o = (uint64_t)b * 4096; r->hash[b] = cap_hash_block((const uint8_t *)(uintptr_t)r->lo + o, (size_t)MIN(4096, r->size - o)); }
|
||||
for (size_t b = 0; b < nb; b++) { uint64_t o = (uint64_t)b * 4096; r->hash[b] = cap_hash_block(p + o, (size_t)MIN(4096, r->size - o)); }
|
||||
}
|
||||
// Regions are written once their index is fixed; a later region gets the next index, so the sorted order is kept in a separate index table
|
||||
static uint32_t *g_cap_rid; static uint32_t g_cap_nrid; // g_cap_rid[sorted position] = region number in the file
|
||||
static int cap_reg_add(uint64_t lo, uint64_t size, uint32_t kind, uint32_t submit) { // a new disjoint region; returns its sorted position
|
||||
static int cap_reg_add(uint64_t lo, uint64_t size, uint32_t kind) { // a new disjoint region (its bytes are written by cap_mem); returns its sorted position
|
||||
int pos = 0; while (pos < (int)g_cap_nreg && g_cap_reg[pos].lo < lo) pos++;
|
||||
g_cap_reg = realloc(g_cap_reg, (g_cap_nreg + 1) * sizeof *g_cap_reg); g_cap_rid = realloc(g_cap_rid, (g_cap_nreg + 1) * sizeof *g_cap_rid);
|
||||
memmove(g_cap_reg + pos + 1, g_cap_reg + pos, (g_cap_nreg - pos) * sizeof *g_cap_reg); memmove(g_cap_rid + pos + 1, g_cap_rid + pos, (g_cap_nreg - pos) * sizeof *g_cap_rid);
|
||||
g_cap_reg[pos] = (cap_region){lo, size, kind, NULL}; g_cap_rid[pos] = g_cap_nrid++; g_cap_nreg++;
|
||||
uint32_t file_no = g_cap_rid[pos]; cap_region *r = &g_cap_reg[pos]; cap_regn hh = {file_no, r->kind, r->lo, r->size};
|
||||
uint8_t *b = malloc(sizeof hh + r->size); if (!b) { cap_fail("out of memory for a region"); return pos; }
|
||||
memcpy(b, &hh, sizeof hh); memcpy(b + sizeof hh, (const void *)(uintptr_t)r->lo, (size_t)r->size);
|
||||
cap_put(&g_cap_w, CAP_REGN, submit, b, sizeof hh + r->size, 1); free(b);
|
||||
cap_reg_hash(r);
|
||||
g_cap_reg[pos] = (cap_region){lo, size, kind, 1, NULL}; g_cap_rid[pos] = g_cap_nrid++; g_cap_nreg++;
|
||||
cap_reg_hash(&g_cap_reg[pos], (const uint8_t *)(uintptr_t)lo); // the bytes now: cap_mem counts what changed before they were written
|
||||
return pos;
|
||||
}
|
||||
static uint32_t g_cap_cur_submit;
|
||||
@@ -84,7 +80,7 @@ static int cap_enc_addr(void *ctx, uint64_t *field, uint64_t len, int writable)
|
||||
if (i < 0 && len && len <= (1u << 20) && nvn_host_readable(v, len)) { // memory outside the pools a record reads (deferred handles, event words): a region of its own
|
||||
for (uint32_t k = 0; k < g_cap_nreg; k++) if (g_cap_reg[k].lo < v + len && v < g_cap_reg[k].lo + g_cap_reg[k].size) { cap_fail("a record's memory straddles a region");
|
||||
MLOG("[RED] DM_NVN_CAPTURE: %#llx (%llu bytes) straddles region %#llx (%llu bytes): %s", (unsigned long long)v, (unsigned long long)len, (unsigned long long)g_cap_reg[k].lo, (unsigned long long)g_cap_reg[k].size, cap_where(field)); return 1; }
|
||||
i = cap_reg_add(v, len, 1, g_cap_cur_submit);
|
||||
i = cap_reg_add(v, len, 1);
|
||||
}
|
||||
if (i < 0) { if (g_cap_unmapped++ < 8) MLOG("[RED] DM_NVN_CAPTURE: a record names %#llx (%llu bytes), outside every pool: kept as it is (the replay resolves it as the live run does, to nothing): %s", (unsigned long long)v, (unsigned long long)len, cap_where(field)); return 1; }
|
||||
*field = cap_addr(g_cap_rid[i], v - g_cap_reg[i].lo);
|
||||
@@ -294,9 +290,12 @@ static void cap_registries(uint32_t submit) { // the entries that differ from
|
||||
reads = malloc((size_t)MAX(g_ntreg, 1) * sizeof *reads);
|
||||
for (int i = 0; i < g_ntreg; i++) {
|
||||
treg_t *r = &g_treg[i], *o = &g_cap_treg0[i];
|
||||
if (r->ok == o->ok && (!r->ok || (r->has_v == o->has_v && !memcmp(&r->t, &o->t, sizeof r->t) && (!r->has_v || !memcmp(&r->v, &o->v, sizeof r->v))))) continue;
|
||||
cap_treg e = {i, (uint8_t)r->ok, (uint8_t)r->has_v, {0}, r->t, r->v}; o->ok = r->ok; o->has_v = r->has_v; o->t = r->t; o->v = r->v;
|
||||
if (r->ok) reads[nreads++] = r->t;
|
||||
if (r->ok == o->ok && (!r->ok || (r->gone == o->gone && r->has_v == o->has_v && !memcmp(&r->t, &o->t, sizeof r->t) && (!r->has_v || !memcmp(&r->v, &o->v, sizeof r->v))))) continue;
|
||||
cap_treg e = {i, (uint8_t)r->ok, (uint8_t)r->has_v, (uint8_t)(r->ok && r->gone), 0, r->t, r->v}; o->ok = r->ok; o->gone = r->gone; o->has_v = r->has_v; o->t = r->t; o->v = r->v;
|
||||
// An ID whose memory pool was finalized: the pool object is freed, and Pokemon Scarlet reuses the memory (its registry entries read a texture's bytes as their pool's
|
||||
// address, size and mode). Nothing makes a texture from such an ID, so neither the pool nor the storage is captured
|
||||
if (e.gone) e.t.pool = NULL, e.t.mem = NULL;
|
||||
else if (r->ok) reads[nreads++] = r->t;
|
||||
cap_buf_put(&tb, &e, sizeof e);
|
||||
}
|
||||
if (g_cap_nsreg0 < g_nsreg) { g_cap_sreg0 = realloc(g_cap_sreg0, g_nsreg * sizeof *g_cap_sreg0); g_cap_sreg0_ok = realloc(g_cap_sreg0_ok, g_nsreg); memset(g_cap_sreg0_ok + g_cap_nsreg0, 0, g_nsreg - g_cap_nsreg0); g_cap_nsreg0 = g_nsreg; }
|
||||
@@ -340,7 +339,7 @@ static void cap_pools(uint32_t submit) { // regions for pools not covered yet
|
||||
int k = cap_reg_find(lo);
|
||||
if (k < 0 || g_cap_reg[k].lo + g_cap_reg[k].size < hi) {
|
||||
if (k >= 0 || cap_reg_find(hi - 1) >= 0) cap_fail("a pool grew over an existing region during the frame");
|
||||
else cap_reg_add(lo, hi - lo, 0, submit);
|
||||
else cap_reg_add(lo, hi - lo, 0);
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
@@ -348,7 +347,26 @@ static void cap_pools(uint32_t submit) { // regions for pools not covered yet
|
||||
for (int i = 0; i < n; i++) { cap_padd a = {ps[i].lo, ps[i].hi - ps[i].lo}; cap_enc_addr(NULL, &a.mem, 0, 0); cap_buf_put(&b, &a, sizeof a); }
|
||||
cap_put(&g_cap_w, CAP_PADD, submit, b.p, b.n, 1); cap_buf_free(&b); free(ps);
|
||||
}
|
||||
static void cap_diffs(uint32_t submit) { // the 4 KiB blocks of every region that changed since they were last written
|
||||
// The pool bytes, last in a submit's step: the texture readbacks and the records before it take seconds, the game's other threads run meanwhile, and the live replay of the
|
||||
// submit reads the pools as they are once the step ends. A new region is written whole (its bytes once, as they are then); of the others, the 4 KiB blocks that changed since
|
||||
// they were last written. The bytes of new regions that changed after the region was found are counted in the log (0 in Breath of the Wild's and Pokemon Scarlet's frames)
|
||||
static uint64_t cap_reg_write(uint32_t submit) { // the new regions, whole; → their bytes that changed after they were found (what a copy at that point would have missed)
|
||||
uint64_t moved = 0;
|
||||
for (uint32_t i = 0; i < g_cap_nreg; i++) {
|
||||
cap_region *r = &g_cap_reg[i]; if (!r->pending) continue;
|
||||
size_t nb = (size_t)((r->size + 4095) / 4096);
|
||||
for (size_t k = 0; k < nb; k++) { uint64_t o = (uint64_t)k * 4096; size_t len = (size_t)MIN(4096, r->size - o); if (cap_hash_block((const uint8_t *)(uintptr_t)r->lo + o, len) != r->hash[k]) moved += len; }
|
||||
cap_regn hh = {g_cap_rid[i], r->kind, r->lo, r->size}; r->pending = 0;
|
||||
uint8_t *b = malloc(sizeof hh + r->size); if (!b) { cap_fail("out of memory for a region"); continue; }
|
||||
memcpy(b, &hh, sizeof hh); memcpy(b + sizeof hh, (const void *)(uintptr_t)r->lo, (size_t)r->size);
|
||||
cap_reg_hash(r, b + sizeof hh); // of the copy: a write after it is a change for the next diff
|
||||
cap_put(&g_cap_w, CAP_REGN, submit, b, sizeof hh + r->size, 1); free(b);
|
||||
}
|
||||
return moved;
|
||||
}
|
||||
static void cap_mem(uint32_t submit) {
|
||||
uint64_t moved = cap_reg_write(submit);
|
||||
if (moved) MLOG("DM_NVN_CAPTURE: submit %u: %llu bytes of the pools changed while it was captured (written as they are at its end)", submit, (unsigned long long)moved);
|
||||
cap_buf b = {0};
|
||||
for (uint32_t i = 0; i < g_cap_nreg; i++) {
|
||||
cap_region *r = &g_cap_reg[i]; size_t nb = (size_t)((r->size + 4095) / 4096);
|
||||
@@ -375,9 +393,27 @@ static void cap_flush_objs(uint32_t submit) {
|
||||
if (g_cap_kind.n) cap_put(&g_cap_w, CAP_TKND, submit, g_cap_kind.p, g_cap_kind.n, 1);
|
||||
g_cap_pobj.n = g_cap_tobj.n = g_cap_progb.n = g_cap_dpolb.n = g_cap_kind.n = 0;
|
||||
}
|
||||
// A capture step takes seconds to minutes on the thread that submits or presents, which may hold a time-constraint (real-time) policy declared for a few milliseconds a frame
|
||||
// (hle_nvn.c, set_time_constraint_comp). The kernel then lets it run in short slices only: Pokemon Scarlet's pool bytes took 1,175 s to compress where the same data takes 55 s,
|
||||
// and Breath of the Wild's 118 s where it now takes 29. The step runs under the standard policy, and the thread gets its own back after it
|
||||
typedef struct { int rt; thread_time_constraint_policy_data_t p; } cap_policy;
|
||||
static cap_policy cap_policy_standard(void) {
|
||||
cap_policy c = {0}; thread_t th = pthread_mach_thread_np(pthread_self()); mach_msg_type_number_t n = THREAD_TIME_CONSTRAINT_POLICY_COUNT; boolean_t dflt = 0;
|
||||
if (thread_policy_get(th, THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&c.p, &n, &dflt) == KERN_SUCCESS && !dflt) {
|
||||
thread_standard_policy_data_t st = {0};
|
||||
c.rt = thread_policy_set(th, THREAD_STANDARD_POLICY, (thread_policy_t)&st, THREAD_STANDARD_POLICY_COUNT) == KERN_SUCCESS;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
static void cap_policy_restore(cap_policy c) { if (c.rt) thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&c.p, THREAD_TIME_CONSTRAINT_POLICY_COUNT); }
|
||||
static void cap_submit_step(int n, const uint64_t *h);
|
||||
static void cap_present_step(const tex_t *t, const int crop[4]);
|
||||
// Hook: nvnQueueSubmitCommands, under the submit lock, before the submission is replayed
|
||||
void nvn_cap_submit(int n, const uint64_t *h) {
|
||||
if (!nvn_cap_enabled() || g_cap_presents + 1 != (uint64_t)g_cap_frame) return;
|
||||
cap_policy c = cap_policy_standard(); cap_submit_step(n, h); cap_policy_restore(c);
|
||||
}
|
||||
static void cap_submit_step(int n, const uint64_t *h) {
|
||||
uint64_t t0 = now_ns();
|
||||
mtl_finish(); // what the previous submissions wrote is in memory now: the pools and textures are read as this submit will see them
|
||||
g_cap_cur_submit = ++g_cap_submit;
|
||||
@@ -385,14 +421,16 @@ void nvn_cap_submit(int n, const uint64_t *h) {
|
||||
if (!cap_open(&g_cap_w, g_cap_path)) { MLOG("[RED] DM_NVN_CAPTURE: cannot write %s: capture off", g_cap_path); g_cap_done = 1; return; }
|
||||
g_cap_active = 1; g_cap_t0 = t0;
|
||||
cap_head();
|
||||
} else cap_diffs(g_cap_cur_submit);
|
||||
}
|
||||
cap_pools(g_cap_cur_submit);
|
||||
cap_registries(g_cap_cur_submit);
|
||||
nvn_hm_clear(&g_cap_seg, NULL); g_cap_nseg = 0;
|
||||
uint64_t t1 = now_ns(); cap_registries(g_cap_cur_submit);
|
||||
uint64_t t2 = now_ns(); nvn_hm_clear(&g_cap_seg, NULL); g_cap_nseg = 0;
|
||||
uint32_t *top = malloc((size_t)MAX(n, 1) * 4);
|
||||
for (int i = 0; i < n; i++) top[i] = (uint32_t)cap_seg_get(h[i]);
|
||||
for (uint32_t i = 0; i < g_cap_nseg; i++) cap_seg_write(i); // segments called or jumped to are queued while the earlier ones are written
|
||||
cap_flush_objs(g_cap_cur_submit);
|
||||
uint64_t t3 = now_ns(); cap_mem(g_cap_cur_submit);
|
||||
MLOG("DM_NVN_CAPTURE: submit %u: registries and their textures %.1f s, records and their textures %.1f s, pool bytes %.1f s", g_cap_cur_submit, (t2 - t1) / 1e9, (t3 - t2) / 1e9, (now_ns() - t3) / 1e9);
|
||||
if (g_cap_nsync) { uint32_t ns = g_cap_nsync; cap_put(&g_cap_w, CAP_SYNC, g_cap_cur_submit, &ns, 4, 0); }
|
||||
cap_buf s = {0}; uint32_t nn = (uint32_t)n; cap_buf_put(&s, &nn, 4); cap_buf_put(&s, top, (size_t)n * 4);
|
||||
cap_put(&g_cap_w, CAP_SUBM, g_cap_cur_submit, s.p, s.n, 0); cap_buf_free(&s); free(top);
|
||||
@@ -427,10 +465,13 @@ void nvn_cap_present(const tex_t *t, const int crop[4]) {
|
||||
if (g_cap_presents >= (uint64_t)g_cap_frame && !g_cap_active) { MLOG("[RED] DM_NVN_CAPTURE: frame %d presented without a submit: nothing captured", g_cap_frame); g_cap_done = 1; }
|
||||
return;
|
||||
}
|
||||
cap_policy c = cap_policy_standard(); cap_present_step(t, crop); cap_policy_restore(c);
|
||||
}
|
||||
static void cap_present_step(const tex_t *t, const int crop[4]) {
|
||||
uint64_t t0 = now_ns();
|
||||
cap_pres p = {0}; cap_buf px = {0}; char png[1100]; snprintf(png, sizeof png, "%s.live.png", g_cap_path);
|
||||
g_cap_cur_submit = g_cap_submit + 1; g_cap_no_read = 1;
|
||||
if (t) { p.tex = cap_tex_obj(t); cap_flush_objs(g_cap_cur_submit); }
|
||||
if (t) { p.tex = cap_tex_obj(t); cap_flush_objs(g_cap_cur_submit); cap_reg_write(g_cap_cur_submit); }
|
||||
if (crop) memcpy(p.crop, crop, sizeof p.crop);
|
||||
p.frame = (uint32_t)g_cap_frame;
|
||||
if (!t || !cap_digest(t, p.sha256, &p.bytes, &p.width, &p.height, &p.pixfmt, png, &px)) cap_fail("the presented texture could not be read back");
|
||||
|
||||
+12
-6
@@ -4176,15 +4176,21 @@ static id<MTLTexture> tbuf_as_2d(int tid, id<MTLTexture> t, uint64_t *rid) {
|
||||
return v;
|
||||
}
|
||||
void mtl_tb2_stats(uint64_t *binds, uint64_t *made, uint64_t *fail) { *binds = g_tb2_binds; *made = g_tb2_made; *fail = g_tb2_fail; }
|
||||
// The ID stays registered, as in the game's texture pool, but its storage is gone: nothing may make its texture until the game registers the ID again. A draw never binds
|
||||
// such an ID; a walk over every ID does (pool_gpu, which also checks tex_storage_live). Under g_rmu
|
||||
static void treg_gone(treg_t *r) {
|
||||
r->gone = 1;
|
||||
if (r->view) { defer_obj_unref((__bridge id)r->view); CFRelease(r->view); r->view = NULL; r->view_id = r->view_rid = 0; treg_drop_im(r); }
|
||||
}
|
||||
static void treg_drop_pool_views(const void *pool) {
|
||||
os_unfair_lock_lock(&g_rmu);
|
||||
vc_drop_pool(pool);
|
||||
for (int i = 0; i < g_ntreg; i++)
|
||||
if (g_treg[i].ok && (const void *)g_treg[i].t.pool == pool) {
|
||||
// The ID stays registered, as in the game's texture pool, but its storage is gone: nothing may make its texture until the game registers the ID again. A draw never binds
|
||||
// such an ID; a walk over every ID does (pool_gpu, which also checks tex_storage_live)
|
||||
g_treg[i].gone = 1;
|
||||
if (g_treg[i].view) { defer_obj_unref((__bridge id)g_treg[i].view); CFRelease(g_treg[i].view); g_treg[i].view = NULL; g_treg[i].view_id = g_treg[i].view_rid = 0; treg_drop_im(&g_treg[i]); } }
|
||||
for (int i = 0; i < g_ntreg; i++) if (g_treg[i].ok && (const void *)g_treg[i].t.pool == pool) treg_gone(&g_treg[i]);
|
||||
os_unfair_lock_unlock(&g_rmu);
|
||||
}
|
||||
void mtl_reg_tex_gone(int tid) {
|
||||
os_unfair_lock_lock(&g_rmu);
|
||||
if (tid >= 0 && tid < g_ntreg && g_treg[tid].ok) treg_gone(&g_treg[tid]);
|
||||
os_unfair_lock_unlock(&g_rmu);
|
||||
}
|
||||
void mtl_reg_tex(int tid, const tex_t *t, const view_t *v) {
|
||||
|
||||
@@ -234,6 +234,7 @@ void mtl_create_stats(uint64_t *lib, uint64_t *pso); // Cumulative: number of
|
||||
void mtl_read_texels(const tex_t *t, unsigned level, unsigned layer0, const NVNcopyRegion *r, uint8_t *dst, size_t row, size_t img);
|
||||
// Descriptor pool registration (texture ID / sampler ID → object snapshot), program release
|
||||
void mtl_reg_tex(int id, const tex_t *t, const view_t *v);
|
||||
void mtl_reg_tex_gone(int id); // the ID stays registered, its memory pool finalized (dm/gfx/tests/nvn_replay.m: a captured registry entry, as the live run left it)
|
||||
void mtl_reg_image(int id, const tex_t *t, const view_t *v); // RegisterImage declares image use even when the builder omitted IMAGE
|
||||
// textures written by WriteTexels (recorded by serial): the replay layer treats them like packaged textures, uploaded from guest memory and re-uploaded on dirty pages
|
||||
void mtl_tex_cpu_written(const tex_t *t);
|
||||
|
||||
@@ -321,7 +321,7 @@ int main(int argc, char **argv) { @autoreleasepool {
|
||||
if (c->tag == CAP_PADD && s > 1) add_pools(d, c->raw);
|
||||
else if (c->tag == CAP_PDIF) for (size_t o = 0; o + 24 <= c->raw;) { uint32_t r; uint64_t off, len; memcpy(&r, d + o, 4); memcpy(&off, d + o + 8, 8); memcpy(&len, d + o + 16, 8);
|
||||
if (r >= rp_nrg || off + len > rp_rg[r].size || o + 24 + len > c->raw) RFAIL("a pool change outside its region"); memcpy(rp_rg[r].mem + off, d + o + 24, (size_t)len); o += 24 + (size_t)len; }
|
||||
else if (c->tag == CAP_TREG) for (size_t o = 0; o + sizeof(cap_treg) <= c->raw; o += sizeof(cap_treg)) { cap_treg *e = (cap_treg *)(d + o); mtl_reg_tex(e->tid, e->ok ? &e->t : NULL, e->has_v ? &e->v : NULL); }
|
||||
else if (c->tag == CAP_TREG) for (size_t o = 0; o + sizeof(cap_treg) <= c->raw; o += sizeof(cap_treg)) { cap_treg *e = (cap_treg *)(d + o); mtl_reg_tex(e->tid, e->ok ? &e->t : NULL, e->has_v ? &e->v : NULL); if (e->gone) mtl_reg_tex_gone(e->tid); }
|
||||
else if (c->tag == CAP_SREG) for (size_t o = 0; o + sizeof(cap_sreg) <= c->raw; o += sizeof(cap_sreg)) { cap_sreg e; memcpy(&e, d + o, sizeof e); mtl_reg_samp(e.sid, &e.p); }
|
||||
else if (c->tag == CAP_TPIX) fill_tex(d, c->raw);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// DM_NVN_CAPTURE end to end on the GPU, without game files: two frames of synthetic records through the capture hooks, the second one captured; `make check_t_capture_live`
|
||||
// then replays the file with nvn_replay, which must give the same digest. The captured frame depends on everything a capture has to carry: a render target's content
|
||||
// from the frame before (texture readback), pool bytes the CPU wrote before the first submit and between the two submits (regions, block changes), a copy from a pool
|
||||
// into the target and a buffer fill (relocated addresses), a call into a second segment, a texture object outside the records, and a combined program the replay
|
||||
// layer makes for itself (its serial must not be a captured one).
|
||||
// into the target and a buffer fill (relocated addresses), a call into a second segment, a texture object outside the records, a combined program the replay
|
||||
// layer makes for itself (its serial must not be a captured one) and a registered texture whose memory pool was finalized.
|
||||
// ./t_capture_live <capture path>
|
||||
#import <Foundation/Foundation.h>
|
||||
#define nvn_game_fps nvn_game_fps_mtl_default
|
||||
@@ -53,6 +53,14 @@ int main(int argc, char **argv) { @autoreleasepool {
|
||||
{ p_clear_color *c = emit(&f1, OP_CLEAR_COLOR, sizeof *c); *c = (p_clear_color){0, 0xf, {1, 0, 0, 1}}; }
|
||||
copy_block(&f1, &rt, (uint64_t)(uintptr_t)pool, 8, 8); emit(&f1, OP_END, 0);
|
||||
submit(f1.p); nvn_cap_present(&rt, NULL);
|
||||
// a texture on a pool of its own, registered, then the pool finalized as nvnMemoryPoolFinalize does and the pool object's memory reused: the ID stays registered with its
|
||||
// storage gone, and the capture must not read the dead pool object (Pokemon Scarlet: a texture's bytes there read as a sparse pool's mode, or as addresses outside every pool)
|
||||
static pool_t p2; size_t p2sz = 64 << 10; uint8_t *mem2 = NULL; if (posix_memalign((void **)&mem2, (size_t)getpagesize(), p2sz)) return 2;
|
||||
mtl_pool_add(mem2, p2sz); p2 = (pool_t){MAGIC('P', 'O', 'O', 'L'), 0, mem2, p2sz, NULL, 0};
|
||||
tex_t t2 = {.magic = MAGIC('T', 'E', 'X', 0), .serial = nvn_new_serial(), .pool = &p2, .mem = mem2};
|
||||
t2.d = (nvn_texdesc){.target = NVN_TEXTURE_TARGET_2D, .format = NVN_FORMAT_RGBA8, .width = 16, .height = 16, .depth = 1, .levels = 1, .samples = 1};
|
||||
nvn_tex_layout(&t2.d, &t2.L); mtl_tex_init(&t2); mtl_reg_tex(5, &t2, NULL);
|
||||
mtl_pool_del(mem2); mtl_alias_drop_pool(&p2); p2 = (pool_t){0, 0x24924924, (uint8_t *)0x2492492492497f80ull, 0x2492492492497f80ull, NULL, 2};
|
||||
// frame 2: two submits; the CPU writes the pool before each, the second copy reads what was written between them
|
||||
for (int i = 0; i < 16 * 16; i++) { pool[0x10000 + 4 * i] = 200; pool[0x10000 + 4 * i + 1] = (uint8_t)(3 * i); pool[0x10000 + 4 * i + 2] = 90; pool[0x10000 + 4 * i + 3] = 255; }
|
||||
chain a = {{0}, 0};
|
||||
@@ -71,6 +79,7 @@ int main(int argc, char **argv) { @autoreleasepool {
|
||||
submit(b.p);
|
||||
nvn_cap_present(&rt, NULL);
|
||||
if (!g_cap_done || g_cap_failed) { fprintf(stderr, "FAIL: capture %s\n", g_cap_done ? "incomplete" : "not written"); return 1; }
|
||||
if (g_cap_unmapped) { fprintf(stderr, "FAIL: %llu addresses outside every pool (the finalized pool's object read)\n", (unsigned long long)g_cap_unmapped); return 1; }
|
||||
if (*(uint32_t *)(pool + 0x30000) != 0x11223344) { fprintf(stderr, "FAIL: the called segment's buffer fill did not run\n"); return 1; }
|
||||
printf("t_capture_live: frame 2 captured to %s\n", argv[1]);
|
||||
return 0;
|
||||
|
||||
@@ -335,6 +335,8 @@ One line per symptom in the [subsystem references](../reference/): what you see
|
||||
- GPU and resident memory keep growing during texture streaming while pool, residency and serial-object counts stay nearly flat, with no freed pool buffers alive. → [Finalized textures kept by registered descriptor views](../reference/nvn-objects.md#finalized-textures-kept-by-registered-descriptor-views)
|
||||
- the serial table grows by about 10 entries a frame (276,000 after 25,000 frames). → [Dead texture serials kept in a ghost table](../reference/nvn-objects.md#dead-texture-serials-kept-in-a-ghost-table)
|
||||
- `nvn_replay` aborts on a game's capture with `-[NvProg width]: unrecognized selector` (from `rt_dims`) or `-[NvProg mipmapLevelCount]`: a render target resolves to a program. → [A replay's own objects take serials above a capture's](../reference/nvn-objects.md#a-replays-own-objects-take-serials-above-a-captures)
|
||||
- `DM_NVN_CAPTURE` reports `a record names … (0 bytes), outside every pool … texture registry entry …` for some texture IDs, with addresses that look like data; one capture stopped with `a sparse virtual pool (step 1 does not capture page tables): the capture is incomplete`, another with `straddles a region`. → [A captured texture ID whose memory pool was finalized](../reference/nvn-objects.md#a-captured-texture-id-whose-memory-pool-was-finalized)
|
||||
- `regress.py capture` stops with `frame N was not captured within … s` although the game reached the frame before it; a capture takes 5 to 20 minutes where an earlier one of the same frame took 2 to 3, and a sample of the host shows the submitting thread in `lzfseEncodeBase` under `nvn_cap_submit`. → [A frame capture runs under the standard thread policy](../reference/nvn-objects.md#a-frame-capture-runs-under-the-standard-thread-policy)
|
||||
- `FATAL NVN command memory: the game's pool is empty…`. → [Host-lent command memory segments](../reference/nvn-objects.md#host-lent-command-memory-segments)
|
||||
- frames stop after about 15 s; a game thread spins in its command-memory callback (a ring allocator at `main+0x9cc120` waiting for fences that have all signalled). → [What `GetCommandMemoryUsed` counts](../reference/nvn-objects.md#what-getcommandmemoryused-counts)
|
||||
- `CRASH sig=10` in `mtl_exec` after minutes of play, the fault address equal to `x19` and shaped like `0x1000000003`. → [Prerecorded lists in slots of their measured size](../reference/nvn-objects.md#prerecorded-lists-in-slots-of-their-measured-size)
|
||||
|
||||
+1
-1
@@ -294,7 +294,7 @@ The default selection keeps every local build for the chain checks; games with a
|
||||
Per game it checks:
|
||||
- **Chain** (no GPU): the shaders built by each revision's `dmsh_build.py` (a Vulkan game: `vk_shaders.py`), shader by shader: built or failed (newly failing by the rule of `shader_regressions.py`, which it imports; a new shader that fails is listed apart), and the SHA-256 of the MSL, of the reflection without its chain fields and of the variant libraries. A build is kept per chain version, profile inputs and compilers (`<NSP folder>/<id>-work/regress/chain/`), so a revision that did not change the chain reuses it, and the build takes the game's own shader cache (`DMSH_CAS`), so unchanged MSL is not compiled again. A changed chain still translates every shader: Breath of the Wild's 19,592 took 14 minutes on an M2 Max.
|
||||
- **Interface** (no GPU): every pipeline base `pso_offline.py` would put into the archive, from `shader_pairs.tsv` and `pso_pairs.tsv`, whose pixel shader reads a `[[user(locnN)]]` input the vertex shader does not write or writes with another type. `metal-tt` refuses such a pipeline and with it the whole archive (GitHub issue #283).
|
||||
- **Replay** (`replay`, an NVN game with a capture; GPU, no game run): the game's current capture ([Frame capture and replay](#frame-capture-and-replay)) replayed by each revision's `nvn_replay`, built from that revision's tree, with that revision's shader libraries given on its command line, a few times each (`--repeat`, default 3), each replay compared with the live frame. A candidate replay that differs from the live frame in more pixels than the tolerance, twice the capture's measured noise (a few replays see less than the whole spread: Breath of the Wild measured 154, then gave 157), while the baseline's stay within it, is a `REGRESSION`; with both beyond it, `CHANGED` with the baseline's failure as known. A capture that replays exactly has no tolerance: any other frame is a `REGRESSION`. A capture the candidate cannot replay (the record layout changed, or a translated shader now takes other bindings or inputs than the records were made for) is an `ERROR` that asks for a new capture: the replay accepts another chain version as long as every program's bindings still match. `capture` runs the route of each game whose `smoke.tsv` has a `capture` frame with the given revision (wall clock, `DM_PSO_HYBRID=0`, no prebuild), stops once the frame is written, then replays it `--repeat` times (default 8): the largest number of pixels any of them differs from the live frame is the capture's noise, kept with it in `<NSP folder>/<id>-work/regress/captures/` (2026-10-29: Super Mario Bros. Wonder and Tears of the Kingdom 0, Pokemon Scarlet 18, Breath of the Wild 1,603, the same in every replay; its note, Open). A replay takes seconds where a route takes minutes, and checks the replay layer only: the guest, the host's services and frame pacing do not run.
|
||||
- **Replay** (`replay`, an NVN game with a capture; GPU, no game run): the game's current capture ([Frame capture and replay](#frame-capture-and-replay)) replayed by each revision's `nvn_replay`, built from that revision's tree, with that revision's shader libraries given on its command line, a few times each (`--repeat`, default 3), each replay compared with the live frame. A candidate replay that differs from the live frame in more pixels than the tolerance, twice the capture's measured noise (a few replays see less than the whole spread: Breath of the Wild measured 154, then gave 157), while the baseline's stay within it, is a `REGRESSION`; with both beyond it, `CHANGED` with the baseline's failure as known. A capture that replays exactly has no tolerance: any other frame is a `REGRESSION`. A capture the candidate cannot replay (the record layout changed, or a translated shader now takes other bindings or inputs than the records were made for) is an `ERROR` that asks for a new capture: the replay accepts another chain version as long as every program's bindings still match. `capture` runs the route of each game whose `smoke.tsv` has a `capture` frame with the given revision (wall clock, `DM_PSO_HYBRID=0`, no prebuild), stops once the frame is written, then replays it `--repeat` times (default 8): the largest number of pixels any of them differs from the live frame is the capture's noise, kept with it in `<NSP folder>/<id>-work/regress/captures/` (2026-10-29: Super Mario Bros. Wonder and Tears of the Kingdom 0, Pokemon Scarlet 20, Breath of the Wild 113: its depth-EQUAL variation, the game's note, Open). A replay takes seconds where a route takes minutes, and checks the replay layer only: the guest, the host's services and frame pacing do not run.
|
||||
- **Smoke** (Mac host, window, no audio): the route `dm/games/<id>/smoke.tsv` from a copy of its save, under a watchdog: the frame it must reach, a crash, a hang (no frame for `hang` seconds), the prepare step's time, `[RED]` lines the baseline did not print (numbers, addresses and paths normalized), frame times from `DM_NVN_TSV` (a Vulkan or GL game: presents counted from the log), the peak memory footprint, and perceptual hashes of screenshots at fixed times. The full mode first runs the pipeline prebuild (`DM_PSO_PREBUILD=tool`) under a watchdog and starts the game on its archive; `--quick` skips it (`DM_PSO_PREBUILD=0`).
|
||||
|
||||
A route is `key <TAB> value` lines: `save` (a folder in the NSP folder, `run` for `<id>_build/run/save`, `new` for an empty one), `keys` (`DM_KEYS`), `secs` and `quick` (the run lengths), `reach` (`<frame>@<seconds>`), `window` (start and length of the frame-time window), `shots` (seconds), `hang`, `capture` (the frame `regress.py capture` records). A game is `PASS`, `CHANGED` (MSL or numbers differ, nothing worse), `REGRESSION` (new `[RED]` lines, a screenshot, frame time, memory or prepare time beyond the tolerances at the top of the script), `NEW-FAIL` (a shader, the interface check, a crash, a hang or the frame that worked in the baseline fails) or `ERROR`. Failures the baseline has too are listed as known and do not fail the check. `report.json` (its schema is in the script's header) and `report.md` go to `<root>/reports/<date-time>-<command>/`; the screenshots, logs and frame rows stay in `<NSP folder>/<id>-work/regress/runs/`.
|
||||
|
||||
@@ -130,6 +130,20 @@ The game may also write into an NVN object directly, without an NVN call, throug
|
||||
- **Fix:** `nvn_replay` raises the counter to 2^61 before it loads a capture (`nvn_serial_floor`); a live run's serials stay far below that, and external textures take 2^62 and up. `check_t_capture_live` binds two programs to separate stages to cover it.
|
||||
- **Found on:** [Pokemon Scarlet](../../dm/games/0100A3D008C5C000/README.md) (frame 3000 of its regression route).
|
||||
|
||||
### A captured texture ID whose memory pool was finalized
|
||||
|
||||
- **Symptom:** `DM_NVN_CAPTURE` reports `a record names … (0 bytes), outside every pool … texture registry entry …` for some texture IDs, with addresses that look like data; one capture stopped with `a sparse virtual pool (step 1 does not capture page tables): the capture is incomplete`, another with `straddles a region`.
|
||||
- **Cause:** the game finalizes a texture's memory pool, frees the pool object and reuses its memory, and leaves the texture ID registered. The host marks such an ID `gone` (`treg_drop_pool_views`: nothing makes its texture until the ID is registered again), but the capture did not record that state. It walked the entry's texture fields and read the dead pool object through `tex_t.pool`: the bytes now there (Scarlet: a texture's data, such as `0x2492492492497f80`) became the pool's address, size and mode.
|
||||
- **Fix:** a registry entry carries `gone` (`cap_treg`), and a gone entry keeps neither its pool nor its storage address and is not read back. `nvn_replay` registers it and then marks it gone (`mtl_reg_tex_gone`), as the live run left it. Captures made before keep working (the byte was padding, 0). `check_t_capture_live` registers a texture on a pool of its own and finalizes that pool, then fills the pool object with such bytes. Without the fix the capture is incomplete.
|
||||
- **Found on:** [Pokemon Scarlet](../../dm/games/0100A3D008C5C000/README.md) (texture IDs 1726 to 1786 in the bedroom, each texture with a pool of its own).
|
||||
|
||||
### A frame capture runs under the standard thread policy
|
||||
|
||||
- **Symptom:** `regress.py capture` stops with `frame N was not captured within … s` although the game reached the frame before it; a capture takes 5 to 20 minutes where an earlier one of the same frame took 2 to 3, and a sample of the host shows the submitting thread in `lzfseEncodeBase` under `nvn_cap_submit`.
|
||||
- **Cause:** the capture's steps run on the thread that submits or presents, and that thread can hold a time-constraint (real-time) policy declared for a few milliseconds a frame ([time-constraint computation declared below the thread's peaks](frame-rate.md#time-constraint-computation-declared-below-the-threads-peaks)). A step that runs for minutes far exceeds the declaration, and the kernel lets the thread run only in short slices: Pokemon Scarlet's pool bytes took 1,175 s to compress where the same data takes 55 s outside the host. The harness also counted the capture step's 300 s without a frame as a hang.
|
||||
- **Fix:** each capture step runs under the standard policy, and the thread gets its own policy back after it (`cap_policy_standard`, `cap_policy_restore` in `nvn_capture.inc`). Scarlet's frame 3000 now takes 53 s to capture (1,178 s before), Breath of the Wild's frame 5000 34 s (124 s). The log gives each step's time (`submit N: registries and their textures …, records …, pool bytes …`). `regress.py capture` bounds the step by `--capture-limit` instead of the hang time. The pool bytes are also copied last in the step, as the live replay of the submit reads them, and once.
|
||||
- **Found on:** [Pokemon Scarlet](../../dm/games/0100A3D008C5C000/README.md) and [Breath of the Wild](../../dm/games/01007EF00011E000/README.md) (their regression route captures).
|
||||
|
||||
## Command memory
|
||||
|
||||
### Host-lent command memory segments
|
||||
|
||||
+3
-1
@@ -1315,7 +1315,9 @@ def cmd_capture(a):
|
||||
# the wall clock (DM_DETCLOCK stops some games, waiting for guest time); no pipeline prebuild, and no stand-in pipelines, whose draws would differ from the replay's
|
||||
env.update(DM_KEYS=route['keys'], DM_PSO_PREBUILD='0', DM_PSO_HYBRID='0', DM_NVN_CAPTURE=f'{frame}:1:{cap}')
|
||||
say(f' {g.id}: capturing frame {frame} with {tree.id} → {cap}')
|
||||
r = run_watched([art['host'], art['modules']], env, outdir, outdir / 'log.txt', a, limit=a.capture_limit, hang=max(route['hang'], 300), kind='nvn',
|
||||
# the capture step itself shows no frame until it ends (reading back the textures and compressing the pools: about 2 minutes for Breath of the Wild), so only the
|
||||
# capture limit bounds it
|
||||
r = run_watched([art['host'], art['modules']], env, outdir, outdir / 'log.txt', a, limit=a.capture_limit, hang=max(route['hang'], a.capture_limit), kind='nvn',
|
||||
what=f'{g.id} capture', frames=outdir / 'frames.tsv', until=r'DM_NVN_CAPTURE: frame \d+: [^\n]*')
|
||||
if not r['until'] or not cap.is_file():
|
||||
raise HarnessError(f'frame {frame} was not captured within {a.capture_limit:g} s (the game reached frame {r["max_frame"]}; see {outdir / "log.txt"})')
|
||||
|
||||
Reference in new issue
Block a user