dxbc: check the decoder's per-format instruction counts #539

Closed
csj0oe wants to merge 2 commits from upstream-pr/539 into main
csj0oe commented 2026-11-29 21:08:18 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T21:08:18Z.


What

Sorts every decoded instruction into its instruction format — SOP1, SOP2, SOPC, SOPK, SOPP, SMRD, VOP1/2/C/3/3P, VINTRP, SDWA, DPP, MUBUF, MTBUF, MIMG, EXP, FLAT, DS — and compares the whole-program totals with the counts stated for three hand-assembled programs. Between them the programs hold at least one instruction of all 20 formats: 31 instructions, 30 of them counted.

The point is the formats a mnemonic count cannot see. A DPP row move, a DPP8 exchange and an SDWA sub-dword read are modifiers on a VOP instruction, and packed-math opcodes occupy a separate range, so evidence/shader-instructions/ records all of them under the base mnemonic (a DPP row add appears as v_add_nc_u32).

Every word in the test is what a public assembler produces for the mnemonic beside it: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -show-encoding FILE.s. tools/format-stats/README.md holds the three sources, that command and the hand count for each program, so a reviewer can reproduce the words. Nothing compiled or recorded is committed.

Two counting rules are pinned by the programs rather than assumed:

  • the leading v_nop is in the stream and holds no format, while an s_nop counts as SOPP;
  • the VOP3-encoded lane transfers count as VOP2, while the VOP1-encoded v_readfirstlane_b32 counts as VOP1.

The head no-op that carries data is a longer encoding of the same v_nop, but no public assembler emits it, so the program uses the plain form; that one case is not covered.

Verification

  • cargo test --target x86_64-unknown-linux-gnu -p tuxbox-dxbc --features native-bindings — 117 passed.
  • python tuxbox.py check --no-gpu — every step passes.
<!-- greyfinch-sync:brcly/TuxBox:issue:5555137702 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/539). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-29T21:08:18Z. --- ## What Sorts every decoded instruction into its instruction format — SOP1, SOP2, SOPC, SOPK, SOPP, SMRD, VOP1/2/C/3/3P, VINTRP, SDWA, DPP, MUBUF, MTBUF, MIMG, EXP, FLAT, DS — and compares the whole-program totals with the counts stated for three hand-assembled programs. Between them the programs hold at least one instruction of all 20 formats: 31 instructions, 30 of them counted. The point is the formats a mnemonic count cannot see. A DPP row move, a DPP8 exchange and an SDWA sub-dword read are modifiers on a VOP instruction, and packed-math opcodes occupy a separate range, so `evidence/shader-instructions/` records all of them under the base mnemonic (a DPP row add appears as `v_add_nc_u32`). Every word in the test is what a public assembler produces for the mnemonic beside it: `llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -show-encoding FILE.s`. `tools/format-stats/README.md` holds the three sources, that command and the hand count for each program, so a reviewer can reproduce the words. Nothing compiled or recorded is committed. Two counting rules are pinned by the programs rather than assumed: - the leading `v_nop` is in the stream and holds no format, while an `s_nop` counts as SOPP; - the VOP3-encoded lane transfers count as VOP2, while the VOP1-encoded `v_readfirstlane_b32` counts as VOP1. The head no-op that carries data is a longer encoding of the same `v_nop`, but no public assembler emits it, so the program uses the plain form; that one case is not covered. ## Verification - `cargo test --target x86_64-unknown-linux-gnu -p tuxbox-dxbc --features native-bindings` — 117 passed. - `python tuxbox.py check --no-gpu` — every step passes.
brcly commented 2026-11-29 21:11:48 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:11:48Z.


Thanks. The format counts are a good idea, but the committed instruction words in tools/format-stats/stats/ look like console compiler output (the HLSL sources, the root signature they were compiled with, the leading data no-op and the 256-byte s_code_end padding). That's the same problem #531 had: we can't commit output of the licensed console reference compiler.

Could you build the programs' words yourself instead, the way #531 now does: hand-assembled or generated in the test, with the expected counts next to them? Then this can go in.

One more thing: CONTRIBUTING.md now asks for a few open PRs at a time until they're reviewed (and the pinned #533 tracks who's working on what). Most of tonight's nine are good, but nine at once is hard to review well. Please hold new ones until these land.

<!-- greyfinch-sync:brcly/TuxBox:comment:7262681559 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/539#issuecomment-7262681559). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T21:11:48Z. --- Thanks. The format counts are a good idea, but the committed instruction words in `tools/format-stats/stats/` look like console compiler output (the HLSL sources, the root signature they were compiled with, the leading data no-op and the 256-byte `s_code_end` padding). That's the same problem #531 had: we can't commit output of the licensed console reference compiler. Could you build the programs' words yourself instead, the way #531 now does: hand-assembled or generated in the test, with the expected counts next to them? Then this can go in. One more thing: `CONTRIBUTING.md` now asks for a few open PRs at a time until they're reviewed (and the pinned #533 tracks who's working on what). Most of tonight's nine are good, but nine at once is hard to review well. Please hold new ones until these land.
brcly commented 2026-11-29 22:03:03 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:03:03Z.


Thanks, this addresses it: the words now come from llvm-mc, which anyone can run. We're putting it through the full check on both of our cards now and will merge it (as one squashed commit) if it passes.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263360754 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/539#issuecomment-7263360754). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:03:03Z. --- Thanks, this addresses it: the words now come from `llvm-mc`, which anyone can run. We're putting it through the full check on both of our cards now and will merge it (as one squashed commit) if it passes.
brcly commented 2026-11-29 22:13:37 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:13:37Z.


Merged as beed153e on main (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7263505903 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/539#issuecomment-7263505903). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:13:37Z. --- Merged as beed153e on `main` (squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!539
No description provided.