Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c6f5f9a
Donkey Kong Bananza takes a render scale: DM_RENDER_SCALE fixes its s…
seedds Nov 8, 2026
cbce3d5
The acquire sync is the acquired image's release, not every submissio…
seedds Nov 8, 2026
ac10683
Translation and GPU clock for heavy NVN frames: uniform-only argument…
seedds Nov 8, 2026
64625c2
Docs: Donkey Kong Bananza's render scale, frame times by mode and its…
seedds Nov 8, 2026
ca08664
The mesh pipeline memo's key comparison is marked for clang-tidy: pso…
seedds Nov 8, 2026
7431dd9
Donkey Kong Bananza's Canyon Layer map draws its terrain through a me…
seedds Nov 8, 2026
288273e
Merge main into dk-bananza-perf
seedds Nov 9, 2026
03d2598
The GPU clock keeper checks its kernel function before making the pip…
seedds Nov 9, 2026
660473a
Merge main into dk-bananza-perf
seedds Nov 9, 2026
ec3a6c0
t_pso_archive: the compaction marker's path is built from a non-null …
seedds Nov 9, 2026
9181606
The iOS project leaves out the Mac-only IOBluetooth framework the hos…
seedds Nov 9, 2026
628a3b6
Merge branch 'main' of https://github.com/seedds/nxnative into dkfix
seedds Nov 9, 2026
8777fc9
Merge upstream main into dk-bananza-perf
seedds Nov 9, 2026
f11a5e2
lint_c baseline: nvn_mtl.m has one NullDereference fewer (8), as the …
seedds Nov 9, 2026
a659d2b
Merge upstream main into dk-bananza-perf
seedds Nov 10, 2026
207d25e
Merge upstream main into dk-bananza-perf
seedds Nov 10, 2026
591756f
Merge upstream main into dk-bananza-perf
seedds Nov 10, 2026
643ea16
Merge upstream main into dk-bananza-perf
seedds Nov 10, 2026
1867483
Merge upstream main into dk-bananza-perf
seedds Nov 10, 2026
508fa05
Merge upstream main into dk-bananza-perf; CI's three failing checks f…
seedds Nov 11, 2026
80c1174
Merge upstream main into dk-bananza-perf (repairs 508fa05a)
seedds Nov 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dm/games/040074A01BF12000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ Each step below stopped the boot before its fix:
- The terrain's stores through loaded pointers keep reaching memory pools the host learns only afterwards (12 in a 17,700-frame session); each such miss is checked against the uniform shadows that relied on it, and none so far covered a written page ([Global memory at an address loaded from memory](../../../docs/reference/shaders.md#global-memory-at-an-address-loaded-from-memory), Open).
- **Frame rate in busy scenes:** the game picks its own present interval: 3 (20 fps) in its cutscenes, and 1 ↔ 2 (60 ↔ 30 fps) by its frame-rate controller (`main+0x204a18`; settings at `0x703f72b200`: interval 1 to 3, margin -0.2, 2 late frames to go up, 6 to come back). It measures each frame from its start (`+0xf0`) to the later of its submission and the GPU's end (`+0x128`, ticks) and wants interval 2 from 1.2 vsyncs (20 ms). On the Mac (M4 Pro) that measure sits at 17 ms a frame (p90 24): the host's translation (CPU, 5-9 ms) before the GPU's 10-13 ms. The upscaler's HMMA through `simdgroup_matrix` ([Ampere HMMA through simdgroup_matrix](../../../docs/reference/shaders.md#ampere-hmma-through-simdgroup_matrix)) cut the switches by about a fifth; the geometry runs' dependency check, quadratic in the run's length ([Geometry dependency checks skip read-only pairs](../../../docs/reference/shaders.md#geometry-dependency-checks-skip-read-only-pairs)), was about 8 % of the submitting thread, and making it linear cut them from 30 to 12 on the same scripted route. Entering a level stalled for 1.3 s on GPU drains, one or two per geometry draw ([CPU reads after a drain wait only for later writes](../../../docs/reference/rendering.md#cpu-reads-after-a-drain-wait-only-for-later-writes)); one CPU-bound build frame of 195-280 ms remains. Measured without `sample` attached: it suspends the process and makes the submitting thread look stalled. Its geometry draws are mesh draws ([Mesh geometry groups sized to the vertex output](../../../docs/reference/shaders.md#mesh-geometry-groups-sized-to-the-vertex-output)): translation 9.9 → 7.2 ms a frame, GPU p50 11.8 → 9.0 ms on the scripted route. Open: the rest of the translation time in the busiest views (argument encoding, render pass setup), where translation and the GPU together still miss a vsync now and then.
- The NVN2 device values the driver reads from the GPU at run time (17 items: scratch scale factors, L2 size, texture layers and sizes, linear stride alignment, pool page size, …) are still the Switch 1 ones; the constant ones are NVN2's ([The Switch 2's device values](../../../docs/reference/nvn-objects.md#the-switch-2s-device-values)).
- **Render scale (`DM_RENDER_SCALE`):** the stubs in `patches.py` replace the NDSR upscale rate bounds (`NdsrUpscaleMinRate` 1.375, `NdsrUpscaleMaxRate` 1.9, read at `main+0x38dd04` / `+0x38dd98` / `+0x38e104` / `+0x38e194`) and the rate the dynamic-resolution update applies (`main+0x38de2c`) with the loader's 1 / scale (state +0x14), so the scene keeps one size. The game draws only at its table's steps (1.0, 1.375, 1.5, 2.0 of the output, 2304x1296 docked and 1920x1080 handheld) and sizes its targets per step: a rate between the steps snaps down (0.8333 drew 2304x1296 docked); writing 1.2 into the table's 1.375 step (`[main+0x26ce408]+0x78`, +4) drew that step's 1397x786. Handheld 1920x1080 is 0.999.
- **Frame time by mode (M4 MacBook Air, 2560x1440 screen, cool):** handheld 1920x1080 17.0 ms (GPU 15.5, translation 7.8), handheld 1397x786 16.6 ms (GPU 12.6), docked 1676x943 18.8 ms (GPU 16.4, translation 10.6: the docked tier draws more), docked 1536x864 about 18 ms. After `ea0c98df` (NVN queue scheduling) the 1080p frame is 18.1 ms: the submission snapshot adds about 1.2 ms before the replay; the game's GPU event waits and signals send almost every submission through the scheduler.
- **The map:** zoomed out, docked, it renders at the fixed 2304x1296 (no dynamic resolution there): its depth prepass is 1,900-8,000 geometry-shader draws and its lighting pass about 7,600 draws, 8 ms of GPU; 30 → about 55 fps docked, 60 handheld with [Long passes split while the GPU is idle](../../../docs/reference/frame-rate.md#long-passes-split-while-the-gpu-is-idle).
- iOS: longer sessions, current main and other devices remain unvalidated; see the initial [community report](#ios-community-report).

## Found on this game

- [macOS lowers the GPU clock of a frame-paced GPU](../../../docs/reference/frame-rate.md#macos-lowers-the-gpu-clock-of-a-frame-paced-gpu), [The acquire sync is the image's release, not the frame's end](../../../docs/reference/frame-rate.md#the-acquire-sync-is-the-images-release-not-the-frames-end), [Long passes split while the GPU is idle](../../../docs/reference/frame-rate.md#long-passes-split-while-the-gpu-is-idle), [The deferred-update conflict check looked at every binding on each uniform rebind](../../../docs/reference/frame-rate.md#the-deferred-update-conflict-check-looked-at-every-binding-on-each-uniform-rebind), [The store-witness set overflowed](../../../docs/reference/frame-rate.md#the-store-witness-set-overflowed), [Mesh draws looked up their pipeline and run twin every draw](../../../docs/reference/frame-rate.md#mesh-draws-looked-up-their-pipeline-and-run-twin-every-draw): its later layers from 20 to 60 fps handheld on an M4 MacBook Air, its map from 30 (resolved).
- [Reads past a uniform binding's size](../../../docs/reference/shaders.md#reads-past-a-uniform-bindings-size): the comparison at every uniform read took a fifth of the GPU's time on the Freezer Layer (14.6 → 17.5-18.1 ms on an M4, 55 → 30 fps, [issue #2066](https://github.com/seedds/nxnative/issues/2066), the reporter's measurement); 95.5% of its shaders' uniform reads are at fixed offsets, which the host now bounds once a binding. Resolved in the chain; the frame time on that level is not measured again yet (open).
- Calls copy the called list's pieces: its control memory comes from one arena reset twice per arena of command memory, so a call that pointed at the called list replayed overwritten entries: [A recording's end and links are in control memory](../../../docs/reference/nvn-objects.md#a-recordings-end-and-links-are-in-control-memory).
- [Early fragment tests from the control section](../../../docs/reference/shaders.md#early-fragment-tests-from-the-control-section): 2,855 of its 13,546 pixel shaders set the NVN2 flag (control +0x5b), none of them writes depth; before, no NVN2 shader got the attribute.
Expand Down
7 changes: 5 additions & 2 deletions dm/games/040074A01BF12000/geo_mesh.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# kind: evidence vertex key <TAB> geometry key: pairs drawn with a lean passthrough geometry shader, each built as one mesh library (dm/gfx/tools/dmsh_mesh.py). Donkey Kong
# Bananza draws every geometry draw (about 600 a frame in its first level) with this one pair: a non-instanced, non-indirect triangle list without restart, whose vertex shader has
# a pulling entry (the host's "geometry mesh: ... has no mesh library" line names it, and a count of geo_mesh_fn's conditions found no other pair on the scripted route)
# Bananza draws every geometry draw (about 600 a frame in its first level) with the first pair: a non-instanced, non-indirect triangle list without restart, whose vertex shader has
# a pulling entry (the host's "geometry mesh: ... has no mesh library" line names it, and a count of geo_mesh_fn's conditions found no other pair on the scripted route). The Canyon
# Layer's map draws its terrain with the second (same culling kernel, vertex a504d5de36060114): on the compute path each chunk of 64 draws ended the pass, about 40 compute
# encoders and 7 ms of GPU a frame; as a mesh library none (map docked: 143 → 76 passes)
f9c807930abd1234 5d537f7630ec3671
a504d5de36060114 5d537f7630ec3671
47 changes: 47 additions & 0 deletions dm/games/040074A01BF12000/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Donkey Kong Bananza (040074A01BF12000): the rewriter's patches of this game's own builds. dm/tools/patch_nso.py loads every profile's patches.py and applies those of a module's NSO
# build ID; FRAME_STEP as described there ("Registered patches"). This build has no frame-step stubs: its state page carries only the render scale
from nso_asm import ADRP, B

# Render scale (DM_RENDER_SCALE). The scene renders at the NDSR upscaler's output size (2304x1296 docked, 1920x1080 handheld) divided by an upscale rate that dynamic resolution picks
# from a table of steps between two settings of the graphics parameters, NdsrUpscaleMinRate (default 1.375: 1676x943 at best) and NdsrUpscaleMaxRate (1.9, the game's
# 1152x648 in the heavy areas); the parameter objects are registered at main+0x4ca848 / +0x4ca8cc and their values read at +0x64 by the two dynamic-resolution steps
# (main+0x38db98 stepping down, main+0x38e0f0 stepping up). A stub after each of the four reads replaces the value with the loader's rate, 1 / render scale (state +0x14,
# 0 = the game's own), so both bounds are that rate and the scene keeps that size. x16 and x17 are not used in either function
def frame_step(ctx):
here, emit, fs_site, fs_put, FS_STATE_OFF = ctx.here, ctx.emit, ctx.site, ctx.put, ctx.state
for site, ins, why in ((0x38dd04, 0xbd406502, "NdsrUpscaleMinRate (stepping down) = the host render scale's rate"), # ldr s2,[x8,#0x64]
(0x38dd98, 0xbd406545, "NdsrUpscaleMaxRate (stepping down) = the host render scale's rate"), # ldr s5,[x10,#0x64]
(0x38e104, 0xbd406503, "NdsrUpscaleMaxRate (stepping up) = the host render scale's rate"), # ldr s3,[x8,#0x64]
(0x38e194, 0xbd406542, "NdsrUpscaleMinRate (stepping up) = the host render scale's rate")): # ldr s2,[x10,#0x64]
fs_site(site, ins.to_bytes(4, 'little').hex())
start = here(); emit(ins) # the original load
emit(ADRP(16, here(), FS_STATE_OFF))
for w in (0xb9401611, # ldr w17,[x16,#0x14] rate (float bits), 0 = the game's own
0x34000051, # cbz w17,+8
0x1e270220 | (ins & 0x1f)): # fmov sN,w17
emit(w)
emit(B(here(), site + 4))
fs_put(site, [B(site, start)], why)
# The rate the update settles on (s8 at main+0x38de2c, where both steps and the hold meet before it is compared with the current one and applied): the host's rate, so the
# scene reaches it whatever the GPU time says (the steps move one table entry at a time, and only with GPU time to spare: with the bounds alone it stopped at 1536x864)
fs_site(0x38de2c, '697a40f9')
start = here(); emit(0xf9407a69) # ldr x9,[x19,#0xf0] the original instruction
emit(ADRP(16, here(), FS_STATE_OFF))
for w in (0xb9401611, # ldr w17,[x16,#0x14]
0x34000051, # cbz w17,+8
0x1e270228): # fmov s8,w17
emit(w)
emit(B(here(), 0x38de30))
fs_put(0x38de2c, [B(0x38de2c, start)], "upscale rate the dynamic-resolution update applies = the host render scale's rate")
# (Writing a rate between the steps into the table's second step, [main+0x26ce408]+0x78 +4, made the snap land on that step but the scene kept the step's own size, 1397x786
# for 1.2: the targets' sizes are taken per step elsewhere)
# (Storing the host's rate unsnapped at main+0x38df0c does not give sizes between the steps: the targets follow the step, and 1.2 drew at 2304x1296)
ctx.render_scale = 1

FRAME_STEP = {'e25c90c1c136638885659fd55bf8a03b': frame_step}

BINDING = [
{'what': 'render scale (NDSR upscale rate bounds)', 'now': 'build', 'goal': 'game', 'purpose': 'rendering',
'why': "the game's graphics parameter objects, read in its dynamic-resolution steps",
'blocked': 'no function-matched form for stubs yet'},
]
2 changes: 1 addition & 1 deletion dm/gfx/nvn/dmsh_chain.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Generated file (dm/gfx/tools/dmsh_chain.py --header): the B shader library translation chain version this source tree expects (default options), one for every game;
// the host loads only <library dir>/b-<V>/. Run dmsh_chain.py --header after changing the chain's tools and commit this file with the change
#define DMSH_CHAIN "2afd39090b76"
#define DMSH_CHAIN "648f214d66ac"
7 changes: 6 additions & 1 deletion dm/gfx/nvn/hle_nvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,11 @@ NVN(nvnWindowAcquireTexture, NVNwindowAcquireTextureResult, NVNwindow *w, NVNsyn
// The previous present of this texture has not yet been processed by the present thread (display cannot keep up, a whole swapchain round behind): wait for it to be returned, then hand it to the game to draw
uint64_t tk = *idx < 4 ? o->ticket[*idx] : 0;
if (tk) { uint64_t w0 = now_ns(); nvn_queue_present_wait(tk); nvn_queue_present_release(tk); o->ticket[*idx]=0; g_pq_wait_ns += now_ns() - w0; }
if (s) { nvn_sync_release((sync_t *)s); ((sync_t *)s)->fenced = 2; ((sync_t *)s)->fence = mtl_last_fence(); } // The swapchain texture becomes available once the commits before this point have completed (fenced 2: an acquire sync, for the wait ledger)
// The acquire sync: NVN signals it when the image is released by the display, not when all the work submitted so far is done. The host used the latest fence, which made
// the game's wait on it (Donkey Kong Bananza waits every frame, main+0x204298) a wait for the frame it had just submitted: CPU and GPU took turns, 9 ms of a 17 ms frame in the
// wait. Now it is the fence of this image's own last present (the work that drew it and its present copy); the ticket wait above has the present taken. DM_NVN_ACQ_FENCE=last: the old one
static int acq_last = -1; if (acq_last < 0) { const char *e = getenv("DM_NVN_ACQ_FENCE"); acq_last = e && !strcmp(e, "last"); if (acq_last) LOG("[nvn] acquire sync: the latest fence (DM_NVN_ACQ_FENCE=last)"); }
if (s) { nvn_sync_release((sync_t *)s); ((sync_t *)s)->fenced = 2; ((sync_t *)s)->fence = !acq_last && *idx < 4 && o->pfence[*idx] ? o->pfence[*idx] : mtl_last_fence(); } // The swapchain texture becomes available once the commits before this point have completed (fenced 2: an acquire sync, for the wait ledger)
if (!g_fs_start) { g_fs_start = now_ns(); g_fs_wait = pace_ns; } // the frame starts when the first acquire after a present returns: on a display-link tick when on time
return NVN_WINDOW_ACQUIRE_TEXTURE_RESULT_SUCCESS;
}
Expand Down Expand Up @@ -2419,6 +2423,7 @@ NVN(nvnQueuePresentTexture, void, NVNqueue *q, NVNwindow *w, int idx) {
const tex_t *t = CTX(o->tex[idx]); int lc[4]; const int *crop = present_crop(o->crop, (int)t->d.width, (int)t->d.height, lc);
nvn_queue_present_release(o->ticket[idx]);
o->ticket[idx] = nvn_queue_present((queue_t *)q,t,present_period(o) / 1e9,crop);
o->pfence[idx] = mtl_last_fence(); // the image is free again once the work up to its present has completed (acq_fence)
}
gfx_leave();
atomic_fetch_add(&g_nvn_ns, now_ns() - t0);
Expand Down
Loading
Loading