Skip to content

NieR:Automata optimization: lean, hoisted and mesh-drawn passthrough geometry; Asian release profile - #416

Closed
JioChoi wants to merge 5 commits into
seedds:mainfrom
JioChoi:nier-optimization
Closed

JioChoi wants to merge 5 commits into
seedds:mainfrom
JioChoi:nier-optimization

Conversation

@JioChoi

@JioChoi JioChoi commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

NieR:Automata's frame rate fell to about 15 fps on an iPhone 15 Pro in heavy scenes, and to 20 fps (50 ms frames) on an M1 Mac in the opening flight. Almost all of that cost came from emulating its four passthrough geometry shaders (IndexBuildIndependent_*: a triangle cull that also writes a visible-index list).

This PR builds on #336 and contains its four commits, rebased onto current main with authorship kept, plus one commit of its own (e7aad44). If #336 merges first, only that commit remains.

What changes

Lean passthrough kernels (dmsh_geometry.lean, nvn_geometry.inc)

  • A passthrough geometry shader cannot change its vertices. For point, line and triangle input, dmsh_build.py now also writes a lean kernel <key>_bl<topology>. It stores only the viewport-mask word, and it reads only the capture words it needs: 4 of 144 for NieR, about 970 lines instead of 10,500.
  • The capture writes each word once, through a slot table.
  • The program's own vertex and fragment shaders then draw the kept primitives. For triangles, one fused index kernel (geo_lean_tri) does this.
  • Instanced or multi-invocation draws, vertex shaders with storage writes, transform feedback and adjacency input keep the full path. So does DM_NVN_GEO_LEAN=0.

Hoisting and batching (geo_hoist_scan, geo_flush)

  • After the first lean geometry draw in a run, the following lean draws are prepared before the render pass opens. Their captures go into one render encoder and their kernels into one compute encoder; replay then draws only their rasters, inside the open pass. DM_NVN_GEO_HOIST=0 turns this off.
  • Before, every geometry draw ended the game's pass and reopened it. In the flight that was 80 load-and-store passes a frame.
  • The CPU side gains a fast path for list draws without restart: one index pass, and the indices themselves serve as the primitive map.

Mesh draws (new dm/gfx/tools/dmsh_mesh.py, geo_mesh_draw)

  • The profile can list vertex / geometry shader pairs in geo_mesh.tsv. dmsh_build.py builds a mesh library <vertex>_<geometry>_m3 for each listed pair, for Mac and iOS.
    • The library holds the vertex shader's pulling entry and the lean kernel body, each in its own namespace, with one mesh entry per depth convention.
    • Each threadgroup takes 32 triangles. It runs the vertex shader once per index, then the kernel per triangle, and marks culled triangles with [[primitive_culled]].
    • The kernel's storage writes and subgroup operations run as before: one triangle per thread, 32 triangles per SIMD group.
  • The host uses the mesh draw for a non-instanced, non-indirect triangle list without restart. It stays inside the open render pass, with no capture pass, compute pass or compaction.
    • The kernel's arguments and the draw's index source go into two free slots of the vertex argument table, which the mesh stage shares.
    • The mesh pipeline builds in the background; until it is ready, the compute path draws the pair.
    • The deferred-encoding recorder (nvn_rec.h) gains drawMeshThreadgroups.
    • DM_NVN_GEO_MESH=0 turns the mesh path off.
  • Why one library per pair: Metal will not build an offline library whose mesh entry calls an unresolved external function, so the kernel cannot be linked in when the pipeline is built.
  • NieR's table lists the 4 kernels × its 24 shadow-map vertex shaders (zmap_vs_*, named by the shaders' .vso / .gso files) = 96 pairs. It is in both the global and the Asian profile, whose shader tables are identical.

Other

  • Upload staging blocks grow to their high-water mark instead of allocating a fresh 32 MB block for each batch.

Asian release profile 0100B8E016F76000

The chain version is now ba772bb1b213. dmsh_mesh.py is a chain tool, and geo_mesh.tsv is one of the profile's inputs.

Measurements (M1 Mac, 720p handheld, otherwise idle)

Scene Before After
Opening flight, frame time 50 ms 16.66 ms (60 fps held for 4 min)
Opening flight, render passes / encoders per frame 205 / 290 39 / 45
Opening flight, GPU per frame 33–43 ms 7.6–10 ms
Resistance Camp (player save): compute path → mesh path, frame time 21.2 ms 16.6 ms
Resistance Camp: CPU translation per frame 16.3 ms 12.0 ms (8.7 ms on this rebased main)
Resistance Camp: GPU per frame 12.3 ms 11.3 ms (9.9 ms on this rebased main)

In the camp, about 520 geometry draws a frame are mesh draws, and none fall back once their pipelines are built. The picture matches the compute path, shadows included. The mesh path also works with DM_NVN_ENC_THREAD=1 (the iPhone's deferred encoding).

DM_NVN_GEO_LEAN_CHECK=2000@5600 compared the lean kernel with the full kernel on 2,000 flight draws: identical index lists and vertices.

Tests

  • test_dmsh_geometry.py: lean rewrite, its refusals, capture slot writes, and mesh compose plus a Metal compile. OK.
  • make -C dm/gfx/tests run: OK, t_geometry 1,066 checks, 0 failed.
  • make -C dm/host/tests resolution: global and Asian builds, 30 / 60 fps × both modes. OK.
  • test_patches.py, test_launcher_settings.py, test_nsp_chain.py, test_docs.py: OK.
    • test_docs was run with the local work folder moved out of the tree; inside it, that folder's own profile copy has unresolvable links.

scripts/regress.py was not run. This Mac has no games library (/Volumes/NX is absent) and only NieR locally. The change reaches other games through:

  • the geometry path, which applies to any passthrough geometry shader;
  • the upload staging change;
  • a mesh-stage barrier added when a render pass ends.

A regress run on the other geometry-shader games would be good before merging.

Not yet verified

  • The iPhone build with the mesh path (IPA built, not yet played on the iPhone 15 Pro). There, the vertex shader runs once per index rather than once per unique vertex. On the M1 the GPU still came out ahead.
  • Mesh pipelines take 50–280 ms each to build the first time; they build in the background.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DeVTtag93HemhN1mNA4qhW

ThrecL and others added 5 commits October 27, 2026 21:12
…geometry, Asian release profile

Passthrough geometry shaders (NieR's four IndexBuildIndependent_* culling kernels):
- dmsh_geometry.lean: a lean kernel per point / line / triangle input that writes only
  the viewport mask and reads only the capture words it needs; the capture writes each
  word once through a slot table. The program's own vertex shader draws the kept
  primitives (geo_lean_tri: one fused index kernel for triangles).
- geo_hoist_scan / geo_flush: lean draws after the first are prepared before the pass
  opens and batched into one capture encoder and one compute encoder, so the pass is
  not broken per geometry draw. CPU fast path for list draws without restart.
- dmsh_mesh.py: a pair listed in the profile's geo_mesh.tsv gets a mesh library
  <vertex>_<geometry>_m3 (pulling vertex shader + lean kernel body); the host draws a
  non-instanced triangle list as one mesh draw inside the render pass
  (geo_mesh_draw, DM_NVN_GEO_MESH=0 off), with its pipeline built in the background.
- Upload staging blocks grow to their high-water mark instead of allocating fresh
  32 MB blocks per batch.

Profile 0100B8E016F76000 (Asian release, main 98397a10...): the global profile's keys,
its dynamic-resolution and frame-interval cuts moved to this build, and the
k_nier_dr row for its addresses (t_resolution covers it).

M1 Mac, 720p: opening flight 50 ms -> 16.7 ms a frame; Resistance Camp 21.2 ms ->
16.6 ms (translation 184 M -> 91 M instructions a frame with the mesh path).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DeVTtag93HemhN1mNA4qhW
seedds added a commit that referenced this pull request Oct 28, 2026
Reconcile the current #336 geometry, upload and resolution work with #416's
lean passthrough and mesh paths on main. Preserve buffer dependencies,
query ordering, target selection and chain/cache validation.

Keep mesh primitive IDs draw-wide and rebase only local capture reads.
Snapshot recursive split descriptors before child draws reuse the shared
geometry job, fixing the Octopath first-attack index-range corruption.
Retain emitted-vertex feedback, pause/resume ordering and raster discard
through the new jobs without recapturing the synthetic raster reader.

Co-authored-by: JioChoi <[email protected]>
Co-authored-by: ThrecL <[email protected]>
@seedds

seedds commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Thank you for the lean and mesh geometry work, the performance measurements and the Asian release profile, and for preserving the authorship of #336's contributions.

The NieR integration is now on main in 2c31212f, crediting both contributors. It reconciles these geometry paths with the shared renderer and includes the controls from #336 and the Asian profile. The integration notes distinguish the original measurements from the reconciled implementation's validation.

I'm closing this PR because the work has been absorbed into main. I appreciate the contribution and the care put into the measurements and testing limits.

@seedds seedds closed this Oct 28, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Reconcile the current seedds#336 geometry, upload and resolution work with seedds#416's
lean passthrough and mesh paths on main. Preserve buffer dependencies,
query ordering, target selection and chain/cache validation.

Keep mesh primitive IDs draw-wide and rebase only local capture reads.
Snapshot recursive split descriptors before child draws reuse the shared
geometry job, fixing the Octopath first-attack index-range corruption.
Retain emitted-vertex feedback, pause/resume ordering and raster discard
through the new jobs without recapturing the synthetic raster reader.

Co-authored-by: JioChoi <[email protected]>
Co-authored-by: ThrecL <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants