Skip to content

An Ampere BRX finds its c1 jump table when the block that loads it was split later - #2010

Closed
Valtterios wants to merge 1 commit into
seedds:mainfrom
Valtterios:ampere-brx-split-predecessors
Closed

Valtterios wants to merge 1 commit into
seedds:mainfrom
Valtterios:ampere-brx-split-predecessors

Conversation

@Valtterios

Copy link
Copy Markdown
Contributor

What and why

16 pixel shaders of Pokémon Pokopia (0400A3A01EE4C000) failed with BRX with no target found in the c1 jump table, although the LDC that loads the table's base is on the only path to the BRX.

Block.Split gives the right half the left half's successors but leaves their predecessor lists naming the left half. FindBrxTableAmpere walks those lists back to the LDC, so when the block holding the LDC was split after its successors were linked (a later branch lands inside it), the walk from the BRX started in the left half, before the load, and gave up. After each split the Ampere decoder now points the moved successors' predecessors at the right half (MovePredecessorsAmpere). The Maxwell decoder is left as it is.

Reference entry: docs/reference/shaders.md, "An Ampere jump table loaded in a block split later".

Checked

  • Tests: test_dmsh_control_flow.py has a new case, test_table_loaded_in_a_block_split_later. It fails on main's translator with the same error and passes with this one. The other dm/gfx/tests/test_dmsh_*.py give the same results with both translators (test_dmsh_ampere_mem, test_dmsh_meshstage and test_dmsh_pairs fail the same way on main here).
  • Shaders: 4,017 of Pokopia's shaders (4,001 picked at random and the 16) were translated with the translator before and after. The 8,002 SPIR-V and reflection files of the 4,001 that translated before are byte-identical. The 16 now translate, and they compile for macOS.
  • Games run: none yet with this commit. Pokopia's 16 shaders were checked through dmsh_build.py, not in play.
  • regress.py check --games: not run. The change is limited to the Ampere decoder's block splits, and the byte-identical comparison above stands in for it on Pokopia. No Switch 1 shader can change.
  • Devices and OS: MacBook Pro (Apple silicon), macOS 27.

Docs

  • The finding is in docs/reference/shaders.md, and python3 dm/tools/docs_symptoms.py was run
  • A chain tool changed: dmsh_chain.py --header was run and dm/gfx/nvn/dmsh_chain.h is part of the change
  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation shader chain The shader translation chain (DMSH_CHAIN): a change rebuilds every game's shaders labels Nov 9, 2026
@Valtterios
Valtterios force-pushed the ampere-brx-split-predecessors branch from e97b983 to 95d5545 Compare November 9, 2026 17:02
…s split later

Symptom: 16 pixel shaders of Pokémon Pokopia (0400A3A01EE4C000) failed with
"BRX with no target found in the c1 jump table", although the LDC of the
table's base (LDC c[0x1][R20+0x790]) is on the only path to the BRX.

Cause: Block.Split gives the right half the left half's successors, but
their predecessor lists still name the left half. FindBrxTableAmpere walks
those lists back to the LDC, so when the block holding the LDC was split
after its successors were linked (a later branch lands inside it), the walk
from the BRX started in the left half, before the load, and met another
write of the register (or the program's start) and gave up.

Fix: after each split the Ampere decoder points the moved successors'
predecessors at the right half. The Maxwell decoder is left as it is.

Checked: test_dmsh_control_flow.py has a new case (a table loaded in a block
split later by a branch back into it): it fails on the translator of main
with the same error and passes with this one; the other control flow cases
pass. 4,017 of Pokopia's shaders (4,001 random ones and the 16), translated
with the translator before and after: the 8,002 SPIR-V and reflection files
of the 4,001 that translated before are byte-identical, and the 16 translate
and compile for macOS. The translator is rebuilt and dmsh_chain.lock and
dmsh_chain.h are updated, so every game's shaders are built again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Valtterios
Valtterios force-pushed the ampere-brx-split-predecessors branch from 95d5545 to 61aa12a Compare November 9, 2026 17:05
seedds added a commit that referenced this pull request Nov 11, 2026
…s split later: Block.Split gave the right half the left half's successors but left their predecessor lists naming the left half. Both decoders walk those lists back from a BRX to the load of its jump table (FindBrxTableAmpere, the Maxwell decoder's FindBrxTargetRange), so when the block holding the LDC was split after its successors were linked (a later branch lands inside it), the walk started in the left half, before the load, and met another write of the register or the program's start: "BRX with no target found in the c1 jump table" on 16 pixel shaders of Pokémon Pokopia (an LDC c[0x1][R20+0x790], then a conditional BRA to the BRX). Split now points each moved successor's predecessor entry at the right half, for both decoders; nothing else reads the decoder's lists except for their count (the IR's BasicBlock lists are another graph). PR #2010 mended the lists after the Ampere decoder's split only and shipped the .NET DLL main no longer uses; its diagnosis, its test and its reference entry are kept, the repair moved into Split, and the native translator is rebuilt (dmsh_chain.lock, DMSH_CHAIN 3ae08e02ec6a: every game's shader libraries rebuild). Checked: test_dmsh_control_flow's new test_table_loaded_in_a_block_split_later fails on the old translator with that error and passes on this one; the 26 dm/gfx/tests/test_dmsh_*.py give the same results with both otherwise (test_dmsh_pairs has one error with both: it needs DM_GAME); test_docs, test_nsp_chain, tool_lock.py --check-tools pass. Old and new translator on every shader of three games, SPIR-V and reflection files compared byte for byte: Splatoon Raiders (Ampere, 27,192 shaders, 54,384 files), Octopath Traveler II (Maxwell, 13,980, 27,960) and Fire Emblem Three Houses (Maxwell, 1,372, 2,744), no file differs and no shader fails with either. The author's run with the PR's form: Pokopia's 16 shaders translate and compile for macOS, 4,001 others byte-identical. Not run: Pokopia's shaders with this form (its files are not on hand), any game, regress.py (no shader of the three games changes), the iPhone. Open: no Maxwell shader that the repair changes is known, so that side is checked by reading only (PR #2010)

Co-authored-by: Valtterios <34726970+Valtterios@users.noreply.github.com>
@seedds

seedds commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Landed on main as 3553400, with you as co-author. Your diagnosis, the test and the reference entry are kept.

Two things differ from the PR:

  • The repair is inside Block.Split, so both decoders get it. The Maxwell decoder's walk from a BRX (FindBrxTargetRange) reads the same predecessor lists and had the same fault. The register usage pass reads the IR's BasicBlock lists, a separate graph, so it is not affected.
  • Main's translator is the native dmsh_xlate now, so the DLL is not taken; the executable is rebuilt and the lock and DMSH_CHAIN (3ae08e02ec6a) updated.

Checked here: your test fails on the old translator and passes on the new one. Old and new translator give byte-identical SPIR-V and reflection files for every shader of Splatoon Raiders (27,192), Octopath Traveler II (13,980) and Fire Emblem Three Houses (1,372).

Not checked here: Pokopia, whose files I do not have at hand. Could you rebuild its shaders on main and confirm that the 16 translate?

@seedds seedds closed this Nov 11, 2026
@Valtterios

Copy link
Copy Markdown
Contributor Author

Thanks for taking it, and for moving the repair into Block.Split. I checked Pokopia's shaders on main: the 16 translate.

How I checked:

  • Pokopia (v655360, one NUP) built on main 084f5aa (chain 3ae08e02ec6a) with build_ipa_from_nsp.py --platform mac --seen-shaders. The build finished, and the 8,157 shaders the profile's playtests list all built.
  • 19 pixel shaders in the split package (ps_rdb.bin) hold one of the six BRX instructions from the original errors. I built those 19 with dmsh_build.py on main and on 7ef8339 (main just before 3553400, chain b8856126d238), Mac target, each with an empty cache:
    • main: 19 of 19 translate and compile for macOS.
    • 7ef8339: 3 translate. The other 16 fail with BRX with no target found in the c1 jump table, with the same six instructions and the same counts as in the PR (4, 4, 3, 3, 1, 1).
    • The 3 that translate with both have identical MSL. Their reflection differs only in the chain field.
  • test_table_loaded_in_a_block_split_later passes on main and fails on 7ef8339.

Not checked: the iOS libraries, a full build of all 131,426 shaders on main, and the game in play with this chain.

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) shader chain The shader translation chain (DMSH_CHAIN): a change rebuilds every game's shaders

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants