Skip to content

Argument tables: uniform-buffer-only changes copy the table and remake those slots - #1472

Closed
Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:args-ubo-only
Closed

Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:args-ubo-only

Conversation

@Xipzer

@Xipzer Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

An argument table whose stage only had uniform buffers rebound since it was last written in the pass is copied from that table, and only its uniform buffer slots are made again.

Why. In Breath of the Wild, 72% of the argument tables encode_args_ writes follow only a uniform buffer rebind on that stage. The full path walks every binding again (textures, samplers, images, driver banks) under g_rmu to produce the same values.

What.

  • g_args_ogen[6]: a per-stage generation that moves at every argument change other than a uniform buffer bind: args_dirty_all, OP_BIND_SSBO, OP_BIND_TEX, OP_BIND_SAMP, OP_BIND_IMG, OP_PUSH_CONST, and the geometry and mesh paths in nvn_geometry.inc that force a stage's table again (g_geo_bind changes there). ubd_dirty and OP_BIND_UBO leave it alone.
  • NvShader keeps ab_ogen (the generation its table was written under), ab_cpu (the table's arena address, so the copy sends no contents message) and cb_only: set once, -1 when a binding follows a uniform buffer's content (SAMPU, TEXU, SBUFU, UBOP, IMGU, TBUFU).
  • In encode_args_, after the full reuse check: when the table is from this pass, the generation is unchanged, and none of the full reuse's other refusals apply (pass dump, compute, drv_read[0] with another base instance, pool or handle table with another pool snapshot, g_res_check_on), the table is copied to a new arena block and each NVN_RB_CBUF slot is made as the full path makes it (zero bank, deferred update shadow or ubp_get).
  • DM_NVN_CB_CHECK=1 writes the full table as well and logs the first difference ([RED] uniform-only table differs ...) and a running count. DM_NVN_CB_FAST=0 turns the path off. Both are in docs/env_switches.tsv.

Compared with the fork commit, this leaves out the fork-only features (TAAU, object motion, MetalFX interpolation) and a profiling hunk, adds IMGU and TBUFU to the cb_only exclusions, bumps the generation in nvn_geometry.inc, and takes htab into the pool snapshot condition as main's full reuse does.

Measured on the Xipzer fork (Mac, Breath of the Wild, encode thread on, two alternated pairs): 11,090 -> 10,670 instructions a draw (-4%). DM_NVN_CB_CHECK=1 compared 21.6 M tables with the full path over a 360-degree camera turn there: no difference. Not measured again on this branch.

Graphics tests pass, also with DM_NVN_CB_CHECK=1, except t_nvn, which aborts with the BotW profile on main too and passes with DM_PRESENT_SNAP=0. test_env_switches passes.

…e those slots

72% of the argument tables BotW writes follow only a uniform buffer rebind on that stage. A per-stage
generation of every other argument change (g_args_ogen) lets such a table be copied from the shader's
last one in the pass, with only its uniform buffer slots made again (not for shaders that read handles
or pointers out of a uniform buffer, cb_only). The geometry and mesh paths that force a stage's table
again move the generation too. DM_NVN_CB_CHECK=1 writes the full table as well and logs a difference;
DM_NVN_CB_FAST=0 turns the path off. Measured on the Xipzer fork (BotW, Mac, encode thread on):
11,090 -> 10,670 instructions a draw (-4%).
@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
Xipzer added a commit to Xipzer/nxnative that referenced this pull request Nov 6, 2026
…off the uniform-only path; geometry and mesh binds move g_args_ogen

Found while porting the uniform-only path upstream (PR seedds#1472): NVN_RB_IMGU and NVN_RB_TBUFU read a handle out of a
uniform buffer too, and nvn_geometry.inc changed stages 2-4's bindings with only g_args_dirty, so the fast path could
copy a table with the previous geometry bindings.

Discord: https://discord.com/channels/1491224015434678394/1524915513606803549
@Xipzer

Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Note: I couldn't run scripts/regress.py check for this one. This Mac has Xcode 27.1 (Metal 32023.921), and the chain lock on main names 27.2's 32023.922, so the local games' shaders don't build against main's chain here. The measurements come from my integration branch, which carries the same change on a lock for 27.1. If you can run the check on your side, I'd appreciate it.

@Xipzer

Xipzer commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing: superseded by adaff73 (PR #1611), which does the same thing on main: OP_BIND_UBO and ubd_dirty set g_args_ubo, and encode_args_ copies the shader's block and rewrites only the uniform slots and the size table. Its allow-list (args_cbuf_only) is stricter than this PR's exclusions and it handles short bindings, which this did not.

Not on main from here: the DM_NVN_CB_CHECK=1 cross-check of a patched table against a full encode, and the off switch. I can send the check as its own PR if it is useful.

@Xipzer Xipzer closed this Nov 13, 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.

1 participant