Skip to content

An argument block is reused only when its shader was the stage's latest encode - #2249

Closed
lunks wants to merge 1 commit into
seedds:mainfrom
lunks:pr/args-last-sh
Closed

lunks wants to merge 1 commit into
seedds:mainfrom
lunks:pr/args-last-sh

Conversation

@lunks

@lunks lunks commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What and why

A stage's dirty flags (g_args_dirty, g_args_ubo) say what changed since the stage last encoded an argument block, not since a given shader did. A program switch dirties every stage, but a variant of the same program (an alpha, border or logic library) is another NvShader with its own block and no program switch between. Variant A encodes, a binding changes, variant B encodes and clears the flags, A draws again with nothing flagged: it reuses its block, or its copy patched for uniforms only, from before the change, so a draw can bind an old texture or uniform.

Each stage now remembers the shader whose block it last encoded, patched or reused (g_last_sh, forgotten by args_dirty_all), and encode_args_ reuses or patches a block only for that shader. A refusal is counted (@args_refused in the trace rows); it is an upper bound, since it also counts refusals where nothing changed. The rule is ruslan-kyrylyuk's, from #1898's 56e7ee1; this is the change on its own, with a test, and the patch path covered too.

No game failure is attributed to it: it was found by reading. The cost is a full encode instead of a reuse after a variant alternates in a stage.

Checked

  • Tests: new t_args_last_sh (15 checks) runs the sequence A, binding change, B, A: it fails without the change (A's second dispatch writes the old binding; 3 checks) and passes with it. make -C dm/gfx/tests GAME=0400486024DEC000 check_t_args_last_sh check_t_geometry check_t_feedback check_t_dispatch_own check_t_nvn pass; docs_symptoms.py --check and test_docs.py pass.
  • Games run: none on this branch (this author's build runs the same rule on The Legend of Zelda: Ocarina of Time; the refusal count in a long session is not in yet).
  • Devices and OS: M5 Pro, macOS 27.0.
  • regress.py impact origin/main..HEAD reaches every NVN entry point through encode_args_, so this is a change every game takes; no regress.py check report: games are not run here. A run on a game that alternates variants of one program would show whether @args_refused is ever above 0.
  • Not checked: iOS; measurements (frame time, encode time) before and after.

Docs

  • The finding is in docs/reference/rendering.md ("An argument block reused after another variant of its program encoded"), and docs_symptoms.py was run
  • No game files, keys or data extracted from a game in the change or the attachments

…st encode

A stage's dirty flags say what changed since the stage last encoded an argument
block, not since a given shader did. Another variant of the same program (no
program switch, so no args_dirty_all) could encode in between and clear them, and
the first variant then reused, or patched for uniforms only, a block from before
the binding change. Each stage now remembers the shader whose block it last
encoded, patched or reused (g_last_sh); a refused reuse is counted (@args_refused
in the trace rows).

Found by reading seedds#1898's 56e7ee1, which has the same rule. t_args_last_sh runs
the sequence (A, a binding change, variant B, A): it fails without the change (A's
second dispatch writes the old binding) and passes with it. No game failure seen.
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 10, 2026
seedds added a commit that referenced this pull request Nov 14, 2026
…combined program never takes the bound one's ring slot (PR #2249)

A stage's binding changes were flags (g_args_dirty, g_args_ubo) that whichever shader wrote the
stage's next block cleared, so they said nothing about another shader's block: a binding change,
another shader's encode on the stage, then the first shader again reused a block from before the
change. Each change now takes the next number of one sequence for every stage (g_args_gen for any
binding, g_args_ugen for what the uniform slots point at only); a block keeps the numbers it was
written at and is reused only while both hold, patched when only the uniform one moved.

On main every path that puts another shader on a stage marks the stages first, so the one route
found was bind_stages: when the bound combination was the next ring slot to be replaced, a new
combination came back as the same pointer and OP_BIND_PROGRAM (np != S.prog) saw no change. It now
skips that slot. No game failure seen; t_args_gen covers the sequence, shaders taking turns, a
uniform-only change and the slot (its slot checks fail without the bind_stages change).

Regression: OCTOPATH TRAVELER II as main when no other run shared the Mac (19 long frames in
50-130 s, battle reached; runs overlapping other sessions' jobs stalled on main too); Fire Emblem:
Three Houses shader check only (no route).

Co-authored-by: Pedro Nascimento <91118+lunks@users.noreply.github.com>
@seedds

seedds commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Thanks: the diagnosis holds. A stage's dirty flags were cleared by whichever shader wrote the stage's next block, so they said nothing about another shader's block. Landed in a different form in f31276a, crediting you as co-author.

What I found on main: the trigger in the description doesn't occur there. Alpha, logic and border handling are flags and bindings on one NvShader, not separate shaders. Every path that encodes another shader on a stage (geometry capture and kernels, the _bg/_bl/_bgv variants, lean and mesh, tessellation, feedback) marks the stages first, and a program switch marks them all. The one route I found is bind_stages. When the bound combined program is the next of the 64 ring slots to be replaced, a new combination is returned as the same pointer, so OP_BIND_PROGRAM (np != S.prog) sees no change.

What landed:

  • Generations instead of flags. Each binding change takes the next number of one sequence shared by all stages: g_args_gen for any binding, g_args_ugen for what the uniform slots point at only. A block keeps the numbers it was written at and is reused only while both still match, or patched when only the uniform one moved. This makes reuse correct whichever shader encoded in between, with no refusals: shaders that take turns on a stage with no change keep their blocks. It replaces the g_last_sh guard and @args_refused.
  • Slot fix. bind_stages never gives a new combination the slot S.prog names.
  • Test. t_args_gen runs your sequence, shaders taking turns, a uniform-only change, and the ring slot.

Regression: OCTOPATH TRAVELER II ran as main when no other job shared the Mac.

@seedds seedds closed this Nov 14, 2026
kingbumi31 pushed a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…r was the stage's latest encode (Pedro Nascimento)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 pushed a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…r was the stage's latest encode (Pedro Nascimento)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
…r was the stage's latest encode (Pedro Nascimento)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
kingbumi31 added a commit to kingbumi31/no-lag-kart that referenced this pull request Nov 15, 2026
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv)

Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
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