Skip to content

PRMT's F4E, B4E, RC8, ECL, ECR and RC16 modes translate (chain change) - #2055

Open
Know-It-All-Brother wants to merge 3 commits into
seedds:mainfrom
Know-It-All-Brother:ampere-prmt-modes
Open

Know-It-All-Brother wants to merge 3 commits into
seedds:mainfrom
Know-It-All-Brother:ampere-prmt-modes

Conversation

@Know-It-All-Brother

@Know-It-All-Brother Know-It-All-Brother commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Part of the Ampere accuracy series (#2040). It depends on #2041 for the test: the commits before this PR's own are #2041's and drop out once it lands, so this PR's own change is the last commit.

What and why

PRMT picks bytes from a pair of registers. The translator implemented its default (index) mode and refused the others: F4E, B4E, RC8, ECL, ECR and RC16, which PTX's prmt exposes, so a shader with one failed to translate.

APrmt now does all seven. Byte i of the result is byte k of {c:a}, where s is the selector's low 2 bits and k is computed per mode:

Mode k
index selector nibble i (bit 3 repeats the byte's sign, as before)
F4E s + i
B4E (s − i) & 7
RC8 s
ECL max(s, i)
ECR min(s, i)
RC16 2(s & 1) + (i & 1)

The mode field (bits 72–74) and these formulas come from the Orin's results. My first B4E formula, from memory of PTX's table, was wrong in 1,021 lanes, and the Orin's outputs corrected it. A constant selector still folds at translate time. The index mode's code is unchanged.

Reference entry: "PRMT's byte-select modes" in docs/reference/shaders.md.

How to verify

DMSH_TEST_XLATE=dm/gfx/tools/dmsh_xlate_bin/dmsh_xlate AMPERE_ORIN_ONLY=prmt,prmt_imm python3 dm/gfx/tests/test_dmsh_ampere_orin.py

prmt (one kernel, all seven modes) failed to translate on main and now matches the Orin in all 7,168 lanes, so it comes out of KNOWN. prmt_imm still matches. Only a register selector is in the fixture; the constant-selector path for the six new modes uses the same formulas but hasn't run on the GPU. Mode 7 still fails the shader.

Maxwell's PRMT isn't implemented at all; it only logs "not implemented". That's separate, so I've left it for another change.

Checked

  • Tests: test_dmsh_ampere_orin.py; every other test_dmsh_* gives the same result as on main (test_dmsh_ampere_mem.py, test_dmsh_meshstage.py and test_dmsh_pairs.py fail on main the same way); test_nsp_chain.py, test_xlate_anycpu.py, test_docs.py.
  • Translator: the dlls are rebuilt from this tree with .NET 10; tool_lock.py --update-lock and dmsh_chain.py --header were run (chain 03721d07b37d).
  • Devices and OS: MacBook Pro M5 Max, macOS 27.
  • regress.py: not run. My only local Switch 2 build's shader package comes from an older shader split than main's map, so main's chain can't build it. Ocarina of Time's build already translates every shader, so it can't contain this instruction.
  • Games run: none.

Docs

  • docs/reference/shaders.md has the entry, and python3 dm/tools/docs_symptoms.py was run
  • A chain tool changed: dmsh_chain.py --header was run, and dmsh_chain.h, the translator dlls and the lock are part of the change
  • No game files, keys or data extracted from a game

lint_python.py shows no new findings.

…re_orin.py runs about 190 operations, each the GPU compiler's own machine code for one PTX operation, through the translator, spirv-cross, the chain's MSL rewrites and Metal on this Mac's GPU, and compares every output word with what a Jetson Orin (sm_87) computed from the same 1,024 input rows. The translator tests checked the MSL a few encodings give, not the values; this one finds the FSETP.NE, SHFL lane, F2FP, rounding-mode and signed-zero differences the tracking issue lists, which KNOWN names until each fix takes its entry out. dm/gfx/tools/ampere_orin/capture.py records the fixture on any Linux machine with an Ampere GPU and NVIDIA's driver, with no toolkit or compiler on either side
…ules with its functions, so a rewrite that uses one (struct in PR seedds#1902's hfma_msl) runs as it does in a build instead of raising NameError
…anslate and give the Ampere GPU's bytes: the Ampere emitter only knew the default index mode and stopped with "PRMT mode N" on the others, which bits 72..74 select (Mesa NAK's PrmtMode order). APrmt now takes byte i of the result from byte k of {c:a}, with s the selector's low 2 bits: F4E s + i, B4E (s - i) & 7, RC8 s, ECL max(s, i), ECR min(s, i), RC16 2(s & 1) + (i & 1), with no sign repeat, folding k when the selector is a constant, for both the vector and uniform forms. test_dmsh_ampere_orin.py's prmt, which failed to translate, now matches the Orin in all 7,168 lanes and leaves KNOWN, prmt_imm still matches in all 3,072, and the other dmsh tests are as on main; chain 03721d07b37d
@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
Know-It-All-Brother added a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…), with this branch's translator rebuilt from its own source; chain 26149f762cd0
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.

1 participant