mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-25 06:20:08 -10:00
nvn/pipelines: wait for archive lookup completion (PR #2770)
A non-compiling pipeline lookup returned nil when another thread owned the same base's job. A draw could therefore miss an archived pulling stand-in and compile its own base on the submit thread. Publish the archive result through a separate completion group before any compaction capture or compile. A non-compiling waiter takes that result, or returns nil on a completed archive miss, without waiting for compilation. Keep the compiling completion path unchanged. Include the reciprocal OoT finding and the optional matched phone comparison. Checked with the corrected background predictor: lookup-wait fixture 9, background lookup 17, pending 92, stall 110, depth/stencil 228/231/228/231; docs 6; clang-tidy with no baseline increase; unsigned iOS compile/link fixture; full NieR Automata regression PASS (1,225 shaders, 220 seconds per revision, no new RED or interface changes). The Mac runs were busy and do not establish a gain. The owner waived the iPhone retest on 2026-11-17; phone performance remains unverified. Co-authored-by: Stan Bono <[email protected]>
This commit is contained in:
1 parent
9d3a583644
commit
edc7eff9cf
6 files changed
+125
-4
No files matched your search
@@ -75,6 +75,12 @@ Measured on an M6 Mac with 16 GB, headless, on one walk with camera turns (`walk
|
||||
- The opening movie runs at the movie's own 24 fps pace during the story section and cannot be skipped: about 8 minutes on a new file.
|
||||
- Resolved: at a 30 fps cap (`DM_FPS_TARGET=30`) the title and opening movies played at half speed: the player takes one picture per game frame, and the movies are 60 pictures a second (their times whole milliseconds, also through the opening's story section). The frame step now follows the movie's picture rate: [The frame step follows a movie's picture rate](../../../docs/reference/frame-rate.md#the-frame-step-follows-a-movies-picture-rate) ([PR #2622](https://github.com/seedds/nxnative/pull/2622)). On an M6 at the 30 cap: 10 s of movie in 20.0-24.2 s before, 10.0-10.4 s after, the step 60 while a movie plays and 30 again when its decoder is finalized. Open: where the frames cannot hold 60 (an M1 with the movie network on), the step falls to 30 for late frames, and the thermal cap holds movies at 30; the player's own two-picture mode covers those frames ([A player limited to one picture a frame falls behind its sound](../../../docs/reference/movies.md#a-player-limited-to-one-picture-a-frame-falls-behind-its-sound), the bullet on issue 1501 above).
|
||||
|
||||
### Archive-lookup phone retest
|
||||
|
||||
Not run: the owner waived the combined iPhone retest as a landing requirement on 2026-11-17. The lookup-wait fix ([PR #2770](https://github.com/seedds/nxnative/pull/2770)) and corrected background predictor ([PR #2677](https://github.com/seedds/nxnative/pull/2677)) have host-fixture, unsigned iOS compile/link and Mac regression coverage; their phone performance benefit remains unverified. For an optional future comparison, use corrected background lookups alone against the same host plus lookup-wait, with identical shader libraries, bundled pulling-base archive, prewarm lists, save, frame-rate cap (30 fps) and dynamic-resolution setting. Keep each run's starting device archive and pipeline list identical too; replaying the route first would warm away the race. Record the device, OS, build identities, shader chain and thermal state. The independent storage-takeover, submission-copy and sampler changes are outside this comparison.
|
||||
|
||||
From the same Kakariko save, walk into Hyrule Field and continue towards Castle Town and the castle grounds as time permits, within four minutes per build (under ten minutes of gameplay in all). Save each run's `Documents/log.txt` before the next launch. Compare the `pipelines up to frame` counters for background lookups found, `draws that waited: pulling base not made yet`, bases compiled and submit-thread pipeline time; check for new `[RED]` lines, crashes or missing geometry. The target is to remove draw compiles caused by a concurrent lookup that finds the archived pulling base. Other first-visit stalls need separate attribution. A run that does not overlap those lookups is inconclusive; phone validation remains open regardless of the Mac measurements.
|
||||
|
||||
## Dynamic resolution
|
||||
|
||||
- The controller (v131072; found by fingerprint, so the addresses are only for reading): the parameters are `game__gfx__DynamicResolutionParam` (`LoadThreshold`, `ReduceCounterMax`, `IncreaseCounterMax`, and a list of levels, each a `ResolutionReduceScale` and a `Priority`). Once a frame the update (`main+0x805aa0`) reads the frame's GPU time, subtracts what its cost model predicts at the current size and keeps the trend of that residual. The level function (`main+0x8065e0`) adds the residual to the model's cost at each level and returns the best level under the threshold: 0, the full 1536x864, when the current size fits. The update moves down after `ReduceCounterMax` frames that ask for it and back up after `IncreaseCounterMax`. Scripted `GPULoad` hints from event data (`main+0x31c3de0`) and `OneshotSetDynamicResolutionLoadThreshold` adjust it in cutscenes.
|
||||
@@ -208,6 +214,7 @@ Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25
|
||||
- [Pulling stand-ins made for predicted keys that are never drawn](../../../docs/reference/frame-rate.md#pulling-stand-ins-made-for-predicted-keys-that-are-never-drawn): resolved, frames of 50–170 ms on entering the castle town in every run, with one new pipeline or none.
|
||||
- [Predictions replayed every submission of an area's stand-in warm-up](../../../docs/reference/frame-rate.md#predictions-replayed-every-submission-of-an-areas-stand-in-warm-up): resolved, about 2 ms a frame of submit CPU in the village arrival's stand-in warm-up (issue #2438).
|
||||
- [Predicted keys' bases looked up on the submit thread](../../../docs/reference/frame-rate.md#predicted-keys-bases-looked-up-on-the-submit-thread): resolved in host tests; iPhone testing was waived for landing, with the phone performance benefit unverified. The earlier iPhone play spent up to 3.5 s per 300 frames in predictions on first visits to Hyrule Field and Castle Town (batch OoT-30, C-3).
|
||||
- [A draw that came during another thread's archive lookup compiled its base](../../../docs/reference/frame-rate.md#a-draw-that-came-during-another-threads-archive-lookup-compiled-its-base): resolved in the host's lookup-wait fixture; iPhone testing with corrected background lookups was waived for landing ([PR #2770](https://github.com/seedds/nxnative/pull/2770), [PR #2677](https://github.com/seedds/nxnative/pull/2677)), with the phone performance benefit unverified. The earlier stacked build had 0.3–1.8-second draw waits on an iPhone 17; the Mac measurements do not establish a significant gain.
|
||||
- [A texture written while it is drawn read whole at every use](../../../docs/reference/frame-rate.md#a-texture-written-while-it-is-drawn-read-whole-at-every-use): resolved, frames of 31–59 ms on entering Hyrule Castle Town, a 1800x1380x8 R16 array (38.5 MB) and three block-compressed textures re-uploaded 31–52 times while the loader wrote them, the array 16–17 times whole; 16–17 re-uploads after, the array's 7–9 at 4.7–14.2 MB, one frame of 25 ms at most.
|
||||
- [One Pro Controller read as two players](../../../docs/reference/services.md#one-pro-controller-read-as-two-players): resolved, no music in Kokiri Forest gameplay and its cutscenes; the controller applet opened over and over and the game kept its music suspended while it had focus.
|
||||
- [A keyboard receiver that declares a gamepad takes player 1](../../../docs/reference/services.md#a-keyboard-receiver-that-declares-a-gamepad-takes-player-1): current until the reporter retests ([issue #1657](https://github.com/seedds/nxnative/issues/1657)). A Keychron Link receiver was player 1 and the Pro Controller player 2, so the game took no input; a raw HID pad is now a player from its first button press.
|
||||
|
||||
+13
-4
@@ -9290,7 +9290,8 @@ static nvn_hmap g_pbase = {.klen = sizeof(pbase_key)};
|
||||
static nvn_hmap g_pbase_miss = {.klen = sizeof(pbase_key)};
|
||||
// Only callers for the same base wait on this group; unrelated bases compile in parallel.
|
||||
// compiled: its owner asked the compiler (a compile 0 owner only looks in the archive, and a waiter that needs the base builds it itself when that found none).
|
||||
@interface PbaseBuild : NSObject { @public dispatch_group_t done; id<MTLRenderPipelineState> ps; NSError *error; int compiled; } @end
|
||||
// looked: left once the owner has looked in the archives (or skipped them for a base known missing), found: the base that found, set before; a compile 0 waiter waits on it
|
||||
@interface PbaseBuild : NSObject { @public dispatch_group_t done, looked; id<MTLRenderPipelineState> ps, found; NSError *error; int compiled; } @end
|
||||
@implementation PbaseBuild @end
|
||||
static nvn_hmap g_pbase_pending = {.klen = sizeof(pbase_key)};
|
||||
static os_unfair_lock g_pbase_lock = OS_UNFAIR_LOCK_INIT;
|
||||
@@ -10153,11 +10154,18 @@ static id<MTLRenderPipelineState> pso_build_ex(MTLRenderPipelineDescriptor *d, i
|
||||
known = hm_get_id(&g_pbase_miss, &bk) != nil;
|
||||
if (known && !compile) { os_unfair_lock_unlock(&g_pbase_lock); return nil; }
|
||||
job = hm_get_id(&g_pbase_pending, &bk);
|
||||
if (!job) { job = [PbaseBuild new]; job->done = dispatch_group_create(); dispatch_group_enter(job->done); hm_put_id(&g_pbase_pending, &bk, job); owner = 1; }
|
||||
if (!job) {
|
||||
job = [PbaseBuild new]; job->done = dispatch_group_create(); job->looked = dispatch_group_create();
|
||||
dispatch_group_enter(job->done); dispatch_group_enter(job->looked); hm_put_id(&g_pbase_pending, &bk, job); owner = 1;
|
||||
}
|
||||
}
|
||||
os_unfair_lock_unlock(&g_pbase_lock);
|
||||
if (!job || owner) break;
|
||||
if (!compile) return nil; // another thread is taking or building it: no wait for the Metal compiler
|
||||
// Another thread is taking or building it. A compile 0 call waits for that thread's archive lookup (milliseconds) and takes the base it found, never for its compile.
|
||||
// Returning nil at once, as before, sent a draw that came while a background worker (pso_bg_look, hy_base_kick) looked up its pulling base to no stand-in and then
|
||||
// to a compile of its own base on the submit thread: Ocarina of Time on an iPhone 17, first visits to Hyrule Field and Kakariko, one draw 0.3-1.8 s ("draws that waited:
|
||||
// pulling base not made yet"), while every lookup the workers made found its base
|
||||
if (!compile) { dispatch_group_wait(job->looked, DISPATCH_TIME_FOREVER); base = job->found; if (base) break; return nil; }
|
||||
dispatch_group_wait(job->done, DISPATCH_TIME_FOREVER); base = job->ps;
|
||||
if (base) break;
|
||||
if (job->compiled) { if (e) *e = job->error; return nil; }
|
||||
@@ -10170,6 +10178,7 @@ static id<MTLRenderPipelineState> pso_build_ex(MTLRenderPipelineDescriptor *d, i
|
||||
int from_run = 0; base = known ? nil : arch_lookup(b, vd, &from_run);
|
||||
uint64_t t1 = bp_now();
|
||||
if (base) { g_pb_archived++; g_pt_hit_n++; g_pt_hit_ns += t1 - t0; }
|
||||
job->found = base; dispatch_group_leave(job->looked); // before the compaction's capture below, which compiles
|
||||
if (base && from_run && g_compact_enabled && atomic_load(&g_warm_running)) {
|
||||
// Metal can crash in materializeAirNTFromOnlineForSlice when serializing archive imports mixed with fresh bases (#342).
|
||||
// Work around that framework bug by capturing the original shader functions, without lookupArchives. The normal compiler cache still applies.
|
||||
@@ -13137,7 +13146,7 @@ static int pso_base_made(const pso_key *k, NvShader *vs, NvShader *fs) { return
|
||||
// else its pulling base; when neither is there the draw will wait, so the worker admits the key's build within the prediction's budget (pso_pend_kick_d), and the pulling base is
|
||||
// built for the pair's next miss (hy_base_kick), as hybrid_get does. The draw then finds its base made and only specializes it (tens of microseconds), or takes its stand-in
|
||||
// from the pulling base made. A draw that comes while its lookup is still queued looks it up itself, and the worker then finds it made; one that comes while the worker holds
|
||||
// the base's lookup takes nothing from it and draws as a lookup that found none would (pso_build_ex never waits for another thread's archive lookup without compiling).
|
||||
// the base's lookup waits for its archive result (PbaseBuild.looked), before any compile, and takes the base it found.
|
||||
// g_pp_looked: the bases handed over (submit thread), by the key of the key's own base: a base serves every key that shares it (a key and its variant without depth and stencil)
|
||||
// and is looked up once; workers: one serial queue per performance core (at most 4), at user-initiated QoS, for draws that may come in the same frame
|
||||
static nvn_hmap g_pp_looked = {.klen = sizeof(pbase_key)};
|
||||
|
||||
@@ -395,6 +395,9 @@ t_ubc_wait: t_ubc_wait.m $(MTL_T_DEP)
|
||||
clang $(CFLAGS) -fobjc-arc -o $@ t_ubc_wait.m $(MTL_T_SRC) $(FW)
|
||||
t_pso_pending: t_pso_pending.m $(MTL_T_DEP)
|
||||
clang $(CFLAGS) -fobjc-arc -o $@ t_pso_pending.m $(MTL_T_SRC) $(FW)
|
||||
t_pso_look_wait: t_pso_look_wait.m $(MTL_T_DEP)
|
||||
clang $(CFLAGS) -fobjc-arc -o $@ t_pso_look_wait.m $(MTL_T_SRC) $(FW)
|
||||
check_t_pso_look_wait: RUN_ENV = MTL_DEBUG_LAYER=1
|
||||
t_shmap_warm: t_shmap_warm.m $(MTL_T_DEP)
|
||||
clang $(CFLAGS) -fobjc-arc -o $@ t_shmap_warm.m $(MTL_T_SRC) $(FW)
|
||||
t_pso_bg_look: t_pso_bg_look.m $(MTL_T_DEP)
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// A compile 0 call of pso_build_ex (nvn_mtl.m) for a base another thread holds: it waits for that thread's archive lookup, which takes milliseconds, and takes the base
|
||||
// it found; it never waits for that thread's compile. Before, it returned nil at once, so a draw that came while a background worker looked up its pulling base found no
|
||||
// stand-in and compiled its own base on the submit thread instead (Ocarina of Time on an iPhone 17, first visits: one draw waited 0.3-1.8 s).
|
||||
// The other thread is played here by hand: a job planted in g_pbase_pending, finished from a dispatch_after block. Real Metal 4 compiles of synthetic shaders, no archive.
|
||||
#include "../nvn/nvn_mtl.m"
|
||||
void *front_metal_layer(void) { return NULL; }
|
||||
module_t *module_of(const void *p) { (void)p; return NULL; }
|
||||
module_t *g_mod; int g_nmod;
|
||||
void svc_thread_dump(void) {}
|
||||
uint64_t now_ns(void) { return bp_now(); }
|
||||
static int checks, failed;
|
||||
#define CHECK(c, label) do { checks++; if (!(c)) { failed++; fprintf(stderr, "FAIL: %s\n", label); } else printf("ok: %s\n", label); } while (0)
|
||||
|
||||
static NvProg *program(float z) {
|
||||
NSError *error = nil;
|
||||
NSString *src = [NSString stringWithFormat:@"#include <metal_stdlib>\nusing namespace metal;\n"
|
||||
"vertex float4 v(uint n[[vertex_id]]) { float2 p[3]={float2(-1,-1),float2(3,-1),float2(-1,3)}; return float4(p[n],%f,1); }\n"
|
||||
"fragment float4 f() { return float4(1,0,0,1); }\n", z];
|
||||
id<MTLLibrary> lib = [g_dev newLibraryWithSource:src options:nil error:&error];
|
||||
if (!lib) { fprintf(stderr, "%s\n", error.localizedDescription.UTF8String); exit(1); }
|
||||
NvProg *p = [NvProg new];
|
||||
p->sh[0] = [NvShader new]; p->sh[1] = [NvShader new];
|
||||
snprintf(p->sh[0]->key, sizeof p->sh[0]->key, "lw%.2f-vs", z); snprintf(p->sh[1]->key, sizeof p->sh[1]->key, "lw%.2f-fs", z); p->sh[1]->stage = 1;
|
||||
p->sh[0]->fn = fn4_note([lib newFunctionWithName:@"v"], lib, @"v", nil);
|
||||
p->sh[1]->fn = fn4_note([lib newFunctionWithName:@"f"], lib, @"f", nil);
|
||||
p->sh[1]->rf.color_known = 1; p->sh[1]->rf.color_mask = 1;
|
||||
return p;
|
||||
}
|
||||
// The descriptor of p's pipeline for one colour attachment, and its base's key
|
||||
static MTLRenderPipelineDescriptor *desc(NvProg *p, pso_key *k, pbase_key *bk) {
|
||||
state_reset(); pso_key_fill(k, p->sh[0], p->sh[1], (uint32_t[8]){70}, 0, 0, 1, 0);
|
||||
MTLRenderPipelineDescriptor *d = pso_desc(k, p->sh[0], p->sh[1], nil, 0);
|
||||
pbase_key_of(d, !k->border, bk);
|
||||
return d;
|
||||
}
|
||||
// A job for bk as another thread's would be while it looks in the archive
|
||||
static PbaseBuild *plant(const pbase_key *bk) {
|
||||
PbaseBuild *job = [PbaseBuild new]; job->done = dispatch_group_create(); job->looked = dispatch_group_create();
|
||||
dispatch_group_enter(job->done); dispatch_group_enter(job->looked);
|
||||
os_unfair_lock_lock(&g_pbase_lock); hm_put_id(&g_pbase_pending, bk, job); os_unfair_lock_unlock(&g_pbase_lock);
|
||||
return job;
|
||||
}
|
||||
static void finish(PbaseBuild *job, const pbase_key *bk, id<MTLRenderPipelineState> base) { // what the owner does at the end
|
||||
os_unfair_lock_lock(&g_pbase_lock);
|
||||
job->ps = base; if (base) hm_put_id(&g_pbase, bk, base);
|
||||
hm_rel(nvn_hm_del(&g_pbase_pending, bk)); dispatch_group_leave(job->done);
|
||||
os_unfair_lock_unlock(&g_pbase_lock);
|
||||
}
|
||||
|
||||
int main(void) { @autoreleasepool {
|
||||
setenv("DM_PSO_ARCHIVE", "off", 1); setenv("DM_PSO_MANIFEST", "off", 1); setenv("DM_PSO_USER", "/dev/null", 1);
|
||||
setenv("DM_PSO_PREBUILD", "0", 1); setenv("DM_NVN_PREDICT", "0", 1); setenv("DM_PSO_MTL4", "1", 1);
|
||||
mtl_init(); pso4_init();
|
||||
if (!g_comp4) { printf("no Metal 4 bases on this system: nothing to check\n"); return 0; }
|
||||
dispatch_queue_t other = dispatch_queue_create("t.owner", DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
// 1. The other thread's lookup finds the base after 200 ms: the compile 0 call waits for it and specializes it, with no compile of its own
|
||||
{ NvProg *p = program(.25f); pso_key k; pbase_key bk; MTLRenderPipelineDescriptor *d = desc(p, &k, &bk);
|
||||
NSError *e = nil; id<MTLRenderPipelineState> base = nil;
|
||||
{ MTL4RenderPipelineDescriptor *b = pso_desc4(d, 1, !k.border); base = [g_comp4 newRenderPipelineStateWithDescriptor:b compilerTaskOptions:nil error:&e]; }
|
||||
CHECK(base != nil, "the base builds");
|
||||
PbaseBuild *job = plant(&bk);
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 200 * NSEC_PER_MSEC), other, ^{ job->found = base; dispatch_group_leave(job->looked); finish(job, &bk, base); });
|
||||
uint64_t built = g_pb_built, t0 = bp_now();
|
||||
id<MTLRenderPipelineState> ps = pso_build_ex(d, !k.border, &e, 0);
|
||||
double ms = (bp_now() - t0) / 1e6;
|
||||
CHECK(ps != nil, "a compile 0 call for a base being looked up takes the base the lookup found");
|
||||
CHECK(ms >= 150, "it waited for the lookup");
|
||||
CHECK(g_pb_built == built, "it compiled nothing");
|
||||
dispatch_sync(other, ^{});
|
||||
}
|
||||
// 2. The other thread's lookup finds nothing after 100 ms and then compiles for 2 s: the compile 0 call returns nil after the lookup, not after the compile
|
||||
{ NvProg *p = program(.5f); pso_key k; pbase_key bk; MTLRenderPipelineDescriptor *d = desc(p, &k, &bk);
|
||||
PbaseBuild *job = plant(&bk);
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100 * NSEC_PER_MSEC), other, ^{ dispatch_group_leave(job->looked); usleep(2000000); finish(job, &bk, nil); });
|
||||
NSError *e = nil; uint64_t t0 = bp_now();
|
||||
id<MTLRenderPipelineState> ps = pso_build_ex(d, !k.border, &e, 0);
|
||||
double ms = (bp_now() - t0) / 1e6;
|
||||
CHECK(ps == nil, "a compile 0 call whose base the lookup did not find returns nil");
|
||||
CHECK(ms < 1000, "it does not wait for the other thread's compile");
|
||||
dispatch_sync(other, ^{});
|
||||
}
|
||||
// 3. A compile 0 owner (no other thread): an archive miss still returns nil and marks the base missing; a later compile 0 call returns nil at once
|
||||
{ NvProg *p = program(.75f); pso_key k; pbase_key bk; MTLRenderPipelineDescriptor *d = desc(p, &k, &bk);
|
||||
NSError *e = nil;
|
||||
CHECK(pso_build_ex(d, !k.border, &e, 0) == nil, "a compile 0 owner with no archive finds nothing");
|
||||
os_unfair_lock_lock(&g_pbase_lock); int miss = hm_get_id(&g_pbase_miss, &bk) != nil, pend = hm_get_id(&g_pbase_pending, &bk) != nil; os_unfair_lock_unlock(&g_pbase_lock);
|
||||
CHECK(miss && !pend, "the base is marked missing and its job is gone");
|
||||
CHECK(pso_build_ex(d, !k.border, &e, 1) != nil, "a compiling call then builds it");
|
||||
}
|
||||
printf("lookup waits: %d checks, %d failed\n", checks, failed);
|
||||
return failed != 0;
|
||||
} }
|
||||
@@ -674,6 +674,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
|
||||
- frames of 50–170 ms on entering an area, in every run again, although the prewarm lists and the pipeline archive hold everything the area draws. The long-frame line shows `new pipelines 0` or `1` with tens of milliseconds, and the `pipelines up to frame` line shows that time under `predictions`, with a hundred or more `archive lookups found` at about 1 ms each and as many `pulling pipelines made`, against one or two `draws with a hybrid pipeline`. Ocarina of Time's castle town: one prediction made 160 stand-ins in 104 ms, three predictions 244 in 191 ms. → [Pulling stand-ins made for predicted keys that are never drawn](../reference/frame-rate.md#pulling-stand-ins-made-for-predicted-keys-that-are-never-drawn)
|
||||
- while an area's pipelines are still being built and many draws use a pulling stand-in, the submit thread spends 1 ms or more a frame in predictions: the `pipelines up to frame` line shows thousands of `predictions` per 300 frames, against tens of thousands of `draws with a hybrid pipeline`, while `builds admitted` stays low. → [Predictions replayed every submission of an area's stand-in warm-up](../reference/frame-rate.md#predictions-replayed-every-submission-of-an-areas-stand-in-warm-up)
|
||||
- on a first visit to an area, on an iPhone, the submit thread spends seconds per 300 frames in predictions: the `pipelines up to frame` line shows `predictions` at 1-7 ms each (478 / 3,533 ms, 527 / 1,724 ms in one window each) with tens of `archive lookups found` at tens of milliseconds and as many `pulling pipelines made`, while the game runs at 12-22 fps. → [Predicted keys' bases looked up on the submit thread](../reference/frame-rate.md#predicted-keys-bases-looked-up-on-the-submit-thread)
|
||||
- on a first visit, single frames of 0.3–2 s while the pipeline archive holds the area's pulling bases. The `pipelines up to frame` line shows one to eight `draws that waited: pulling base not made yet` with hundreds of milliseconds each, few `draws with a hybrid pipeline`, and its background lookups finding every base they looked for (`base lookups handed to the background 21 (found 21)`). Ocarina of Time on an iPhone 17, entering Kakariko Village and Hyrule Castle: 1 / 861 ms, 2 / 1,081 ms, 8 / 1,786 ms in one 300-frame window each, against 1 / 95 ms on the build without the background lookups. → [A draw that came during another thread's archive lookup compiled its base](../reference/frame-rate.md#a-draw-that-came-during-another-threads-archive-lookup-compiled-its-base)
|
||||
- frames of 30–150 ms as an area loads, with `new pipelines 0` and a long-frame line such as `texture uploads 31 first + 6 re-uploads, 235.0 MB / 23.7 ms`. With `DM_NVN_REUPLOADS=1` the same large texture is re-uploaded many times within a few frames, several times with the same `submission` number, each for a few written pages (`pages written since its upload: 7 of 2466`). → [A texture written while it is drawn read whole at every use](../reference/frame-rate.md#a-texture-written-while-it-is-drawn-read-whole-at-every-use)
|
||||
- in a `sample` of the queue's thread (`NVN queue replay`), `mtl_sub_commit` has much time of its own and in `gw_put`, though a submission writes few pages. A game that makes many small submissions a frame pays it each time: Ocarina of Time makes about 30. → [A submission's commit read the whole storage-write page set](../reference/frame-rate.md#a-submissions-commit-read-the-whole-storage-write-page-set)
|
||||
- the submit thread spends time in `-[AGXTexture newTextureViewWithPixelFormat:…]` under `tex_by_id` and `img_binding` (a `sample` of the process) in a scene that does not change, and the `texture views by texture (vc_get)` line of the memory report counts views made at about half the rate of views reused, while the number of textures holding views stays flat. Ocarina of Time on the Kokiri Forest deck: 121,284 views made against 454,107 reused by frame 5,700, about 40 a frame. → [Texture views made again for render targets initialized again every frame](../reference/frame-rate.md#texture-views-made-again-for-render-targets-initialized-again-every-frame)
|
||||
|
||||
@@ -846,6 +846,14 @@ Frame pacing: the host's frame step, engine frame limiters, present intervals an
|
||||
- **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game), iPhone 17, the owner's play through Hyrule Field, Kakariko Village and Castle Town on a build without [the first-miss trigger](#predictions-replayed-every-submission-of-an-areas-stand-in-warm-up): up to 3.5 s of predictions per 300 frames in new places.
|
||||
- **Check:** `make -C dm/gfx/tests GAME=<id> check_t_pso_bg_look`: the prediction makes no stand-in on the submit thread and hands the lookup over once; the worker finds a made pulling base and admits nothing, finds no base and admits the key's build, which can be claimed; a key that shares a base already handed over is not handed over again; the draw then takes its stand-in from the base made with no compile. `check_t_pso_pending` covers interleaved prediction budgets and a full-table completion/reclamation race: background admission must keep a waiting draw's completed slot, return that draw's own pipeline and leave the replacement for its own draw. It also checks in-flight diagnostics during concurrent counter updates.
|
||||
|
||||
### A draw that came during another thread's archive lookup compiled its base
|
||||
|
||||
- **Symptom:** on a first visit, single frames of 0.3–2 s while the pipeline archive holds the area's pulling bases. The `pipelines up to frame` line shows one to eight `draws that waited: pulling base not made yet` with hundreds of milliseconds each, few `draws with a hybrid pipeline`, and its background lookups finding every base they looked for (`base lookups handed to the background 21 (found 21)`). Ocarina of Time on an iPhone 17, entering Kakariko Village and Hyrule Castle: 1 / 861 ms, 2 / 1,081 ms, 8 / 1,786 ms in one 300-frame window each, against 1 / 95 ms on the build without the background lookups.
|
||||
- **Cause:** a call of `pso_build_ex` that does not compile (`compile` 0: a draw asking whether its base or its pulling base is made or archived, a prewarm task) returned nil at once when another thread held that base's job in `g_pbase_pending`, so that it would never wait for the Metal compiler. But a job's owner first only looks in the archives, which takes milliseconds, and a non-compiling owner does nothing else. A draw that came during such a lookup of its pulling base therefore found no stand-in. Its own base was already known missing, so the draw then compiled it on the submit thread: about a second on the phone. The background lookups of the prediction (`pso_bg_look`) make this race happen every time: they look up the bases of the draws that come next in the same submission, a few milliseconds before those draws.
|
||||
- **Fix:** general, in the host (`nvn_mtl.m`, `pso_build_ex`, `PbaseBuild.looked`): the owner of a base's job leaves a second group, `looked`, once it has looked in the archives (or skipped them for a base known missing), with the base it found in `found`. It leaves the group before the compaction's capture and before any compile. A non-compiling call that finds another thread's job waits on `looked` and takes `found`. If the lookup found nothing it returns nil as before, without waiting for the compile. The wait is one archive lookup at most.
|
||||
- **Check:** `make -C dm/gfx/tests GAME=<id> check_t_pso_look_wait`: a non-compiling call during another thread's 200 ms lookup takes the base the lookup found and compiles nothing (fails without the fix: it returned nil at once); during a lookup that finds nothing, followed by a 2 s compile, it returns nil after the lookup, not after the compile; a non-compiling owner still marks a missing base.
|
||||
- **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#frame-rate), the owner's play of 2026-11-14 on an iPhone 17 (builds with the prediction's background lookups: 2 fps in Hyrule Castle).
|
||||
|
||||
### A texture written while it is drawn read whole at every use
|
||||
|
||||
- **Symptom:** frames of 30–150 ms as an area loads, with `new pipelines 0` and a long-frame line such as `texture uploads 31 first + 6 re-uploads, 235.0 MB / 23.7 ms`. With `DM_NVN_REUPLOADS=1` the same large texture is re-uploaded many times within a few frames, several times with the same `submission` number, each for a few written pages (`pages written since its upload: 7 of 2466`).
|
||||
|
||||
Reference in new issue
Block a user