Skip to content

Reduce NVN command record memory for viewports and UBO binds - #1565

Closed
ishtiaq156 wants to merge 4 commits into
seedds:mainfrom
ishtiaq156:fix/nvn-compact-command-records
Closed

ishtiaq156 wants to merge 4 commits into
seedds:mainfrom
ishtiaq156:fix/nvn-compact-command-records

Conversation

@ishtiaq156

@ishtiaq156 ishtiaq156 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Reduce actual NVN command-record memory without changing game assets, shaders or GetCommandMemoryUsed accounting. Game engines use the measured command bytes both as direct offsets in recorded memory and to size resource heaps; avoidable record padding can exhaust those heaps.

  • Variable viewport/swizzle count: SetViewports and SetViewportSwizzles now write only the supplied elements (instead of all 16), retaining original element strides and older capture compatibility.
  • Optional adjacent uniform bindings: DM_NVN_UBO_PAIR=1 writes two consecutive 24-byte OP_BIND_UBO_SMALL records as a single 40-byte op49 payload, saving eight real bytes while preserving both GPU addresses and their order. It never pairs across other commands, segment boundaries, memory-usage queries or insufficient room. The original single-record layout is the default. Replay, lookahead, relocation and capture accept both layouts.
  • Opt-in ordinary indexed draws: DM_NVN_DRAW_ONE=1 records direct single-instance DrawElements / DrawElementsBaseVertex in 32 bytes rather than 40, retaining primitive, index type, count, base vertex and full 64-bit index-buffer address. Replay restores the known instance count 1 and base instance 0. Instanced, indirect and multi-draw variants retain their original layout; capture relocation distinguishes the new payload by record size and accepts old captures. The 40-byte default is retained pending broader direct-command-patching compatibility evidence.

Scope: #1580 remains a separate, unresolved NVN2 model-resource allocation issue. In Wonder Switch 2 Edition's NpcCommonerA, the new direct indexed draw layout reduces the exact model request 0x5424 → 0x5334 (240 real bytes across 30 draws); it still crashes under the original resource table. Whole-frame texture and uniform pair savings similarly did not solve this model allocation. No RESTBL override, null-pool bypass, guessed native byte count or proprietary game resource is included here. This PR is an independently useful compaction, not a permanent Wonder model-memory fix.

Checked

  • On the Switch 1 Wonder game profile, t_nvn 260/260 and t_capture 91/91 checks passed, covering actual command-byte accounting, the unchanged default, opt-in instance defaults, full instanced/indirect compatibility and relocation of both new and legacy indexed-draw formats.
  • The same tests on the Breath of the Wild profile passed 260/260 and 91/91; test_docs 11/11 passed, and git diff --check passed.
  • Isolated Wonder Edition v327680 + Bellabel v131072 headless model probe using the original RESTBL confirmed the recorded 240-byte reduction and still reproduced the real guest allocation failure (pool 0x0, exit 139). No success is claimed for New Game or Continue without the separate temporary diagnostic overlay.
  • Played multiple Wonder courses and Bellabel Park on Mac mini M6/macOS 27.0.1 with the previously documented external diagnostic resource-budget overlay; controller input, audio and rumble worked. This gameplay is not evidence that the original-budget crash has been corrected.

Docs

  • Generic record layout, replay/capture compatibility, measured savings and remaining issue documented in docs/reference/nvn-objects.md.
  • No original ROM, derived shader, app, user save or private game material modified or included.

@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 6, 2026
@ishtiaq156
ishtiaq156 marked this pull request as ready for review November 6, 2026 20:28
@ishtiaq156
ishtiaq156 marked this pull request as draft November 6, 2026 23:00
@ishtiaq156

Copy link
Copy Markdown
Contributor Author

Closing as superseded for the Wonder Edition memory-budget use case. Upstream f02d0474 and the default compact NVN recorder now resolve the original-RESTBL allocation failures without the opt-in record optimizations proposed here.

The optional pairing and draw mechanisms in this PR were not merged verbatim, so this is a scope cleanup rather than a claim that every individual change landed. The verified new allocations are documented in #1580. Thanks to upstream for the general solution.

@ishtiaq156 ishtiaq156 closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants