Shaders: a census that no opcode of the ISA may translate by crashing #2378

Manually merged
github merged 1 commit from gh-pr/2378/head into gh-pr/2378/base 2026-11-26 05:04:05 +00:00
Owner

@⁠borosf on GitHub · 2026-11-25 12:16 UTC · original
borosf:vibe/isa-census-842ca5 → main · +209 −20 · 4 files · 1 commits · merged 2026-11-25 21:56 UTC

Summary

  • A census over the whole ISA: every opcode of every decode table (SOP2/SOPK/SOP1/SOPC/SOPP/SMEM, VOP1/VOP2/VOPC/VOP3/VOP3P, VINTRP, DS, MUBUF/MTBUF/MIMG, FLAT/GLOBAL/SCRATCH) is encoded into a minimal pixel program, and driven through decode → ir → structure → resource → io → emit.
  • The decoder must read back the name each table promises (catches encoders/decoders drifting apart), the translation must be Ok or a refusal naming what it lacks, and catch_unwind turns any panic into a test failure — a title could reach any of these encodings, so none may crash the translator.
  • The tables are pub(crate) now so the census iterates the real decoder tables and stays in sync as opcodes are added.
  • Current map on a PS program with no resources: 546 translated, 686 refused by name or reason, 0 panics. Coverage is now measurable per family with cargo test -- --nocapture (e.g. all VOP3 f64/dot/div ops refuse by name; every FLAT/GLOBAL op hits the flat-memory guard; DS ops hit the LDS-allocation guard).

claiming: ISA-CENSUS (commenting from this account is blocked by the integration's permissions, so the claim rides this PR).

Verification

  • cargo test -p victory-shader --lib: 147 passed, 0 failed (incl. emit::census_tests::every_opcode_translate_or_refuse_never_panic).
  • cargo clippy -p victory-shader --all-targets: identical to pristine main 940d32f.
  • cargo check --target x86_64-pc-windows-msvc -p victory-shader --all-targets: clean.
  • cargo run -p xtask -- policy: 183 files ok. No game data used.
**@⁠borosf** on GitHub · 2026-11-25 12:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2378) `borosf:vibe/isa-census-842ca5` → `main` · +209 −20 · 4 files · 1 commits · merged 2026-11-25 21:56 UTC ## Summary - A census over the whole ISA: every opcode of every decode table (SOP2/SOPK/SOP1/SOPC/SOPP/SMEM, VOP1/VOP2/VOPC/VOP3/VOP3P, VINTRP, DS, MUBUF/MTBUF/MIMG, FLAT/GLOBAL/SCRATCH) is encoded into a minimal pixel program, and driven through decode → ir → structure → resource → io → emit. - The decoder must read back the name each table promises (catches encoders/decoders drifting apart), the translation must be `Ok` or a refusal naming what it lacks, and `catch_unwind` turns any panic into a test failure — a title could reach any of these encodings, so none may crash the translator. - The tables are `pub(crate)` now so the census iterates the real decoder tables and stays in sync as opcodes are added. - Current map on a PS program with no resources: 546 translated, 686 refused by name or reason, 0 panics. Coverage is now measurable per family with `cargo test -- --nocapture` (e.g. all VOP3 f64/dot/div ops refuse by name; every FLAT/GLOBAL op hits the flat-memory guard; DS ops hit the LDS-allocation guard). claiming: ISA-CENSUS (commenting from this account is blocked by the integration's permissions, so the claim rides this PR). ## Verification - `cargo test -p victory-shader --lib`: 147 passed, 0 failed (incl. `emit::census_tests::every_opcode_translate_or_refuse_never_panic`). - `cargo clippy -p victory-shader --all-targets`: identical to pristine main 940d32f. - `cargo check --target x86_64-pc-windows-msvc -p victory-shader --all-targets`: clean. - `cargo run -p xtask -- policy`: 183 files ok. No game data used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:03 +00:00
github manually merged commit fe101492fd into gh-pr/2378/base 2026-11-26 05:04:05 +00:00
Author
Owner

@⁠borosf on GitHub · 2026-11-25 12:20 UTC · original

Expanding on why the census is more useful than it looks from a one-line test:

It turns "shader coverage" from an anecdote into a number. The frame-rate problem on world rendering isn't compute cost in translated shaders — it's the draws that never happen because translation refuses. Before this, refusal coverage was known from reading code; now cargo test -- --nocapture prints the complete map: which of the ~1,230 table entries translate, which refuse, and the exact reason per opcode. That's a per-family, per-reason backlog in one command.

It's the input the refusal-kind work needs. The whole-wave refusal logging (per operation kind) only pays off if you know which kinds exist and how much each costs. The census answers that: e.g. v_cmpx_f64 is 17 opcodes behind one reason, the f64 VOP1s are 14 behind another, permlane/mul_lo/min3_i16 are singles. Fixing one reason class and re-running the census gives a measurable delta — the same loop that H-6.3/FIND-7 set up for whole-wave sections, now covering the whole ISA.

It guards the crash path a title can reach. Any of these encodings can appear in real title code, so a panic on one is a runtime crash of the translator, not a test failure. With catch_unwind, a future commit that turns any refusal into a panic fails CI here instead of killing the emulator on a user's machine. The same applies to a new opcode landing in a table: the census picks it up automatically because it walks the tables, so "added but never wired through the pipeline" gets caught.

It pins the decoder contract, not just translation. The name round-trip check means an opcode that decodes under the wrong family — e.g. anything drifting into the SOPP 0x17F window or aliasing a VOP1/VOPC prefix — fails with the exact mismatch. That's the class of bug you normally only find by disassembling a miscompiled shader.

All of this is why it refuses rather than skips: the failure output lists every offender by family, opcode, and name, so a red census tells you what happened before you open the diff.

**@⁠borosf** on GitHub · 2026-11-25 12:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2378#issuecomment-7162244986) Expanding on why the census is more useful than it looks from a one-line test: **It turns "shader coverage" from an anecdote into a number.** The frame-rate problem on world rendering isn't compute cost in translated shaders — it's the draws that never happen because translation refuses. Before this, refusal coverage was known from reading code; now `cargo test -- --nocapture` prints the complete map: which of the ~1,230 table entries translate, which refuse, and the exact reason per opcode. That's a per-family, per-reason backlog in one command. **It's the input the refusal-kind work needs.** The whole-wave refusal logging (per operation kind) only pays off if you know which kinds exist and how much each costs. The census answers that: e.g. `v_cmpx_f64` is 17 opcodes behind one reason, the f64 VOP1s are 14 behind another, permlane/mul_lo/min3_i16 are singles. Fixing one reason class and re-running the census gives a measurable delta — the same loop that H-6.3/FIND-7 set up for whole-wave sections, now covering the whole ISA. **It guards the crash path a title can reach.** Any of these encodings can appear in real title code, so a panic on one is a runtime crash of the translator, not a test failure. With `catch_unwind`, a future commit that turns any refusal into a panic fails CI here instead of killing the emulator on a user's machine. The same applies to a new opcode landing in a table: the census picks it up automatically because it walks the tables, so "added but never wired through the pipeline" gets caught. **It pins the decoder contract, not just translation.** The name round-trip check means an opcode that decodes under the wrong family — e.g. anything drifting into the SOPP 0x17F window or aliasing a VOP1/VOPC prefix — fails with the exact mismatch. That's the class of bug you normally only find by disassembling a miscompiled shader. All of this is why it refuses rather than skips: the failure output lists every offender by family, opcode, and name, so a red census tells you what happened before you open the diff.
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 13:08 UTC · original

First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head fe10149 merged onto main 940d32f, cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast.

The PR's new test(s) pass on this card: emit::census_tests::every_opcode_translate_or_refuse_never_panic. The rest is the same as main on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in victory-gpu, 3 in victory-shader), nothing new.

One run, unit tests only, title not run.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2378#issuecomment-7163343097) First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head `fe10149` merged onto `main` `940d32f`, `cargo test -p victory-gpu -p victory-shader --lib --no-fail-fast`. The PR's new test(s) pass on this card: `emit::census_tests::every_opcode_translate_or_refuse_never_panic`. The rest is the same as `main` on this card: the 5 known NVIDIA failures from #1744 (2 view heap cap tests in `victory-gpu`, 3 in `victory-shader`), nothing new. One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠borosf on GitHub · 2026-11-25 13:24 UTC · original

Thanks — useful datapoint: the census ran clean on Blackwell (RTX 5070, 621.24), with the same 5 known NVIDIA failures from #1744 as pristine main and nothing new. That's now the census verified across three vendors with the same result — Intel Arc B580 (Battlemage), and this run — all confirming the census itself is platform-stable: it's pure CPU translation, so hardware only enters through the suites everyone already knows.

If anyone's curious what it actually covers beyond the one test name: each opcode in all 19 decode tables is encoded into a pixel program and taken through decode → ir → structure → resource → io → emit, with a name round-trip assert (encoder/decoder can't drift apart), each outcome classified as translate / named refusal / panic, and any panic failing CI — with -- --nocapture printing the per-opcode map (census: 544 translated, 688 refused, 0 panicked).

**@⁠borosf** on GitHub · 2026-11-25 13:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2378#issuecomment-7163723313) Thanks — useful datapoint: the census ran clean on Blackwell (RTX 5070, 621.24), with the same 5 known NVIDIA failures from #1744 as pristine main and nothing new. That's now the census verified across three vendors with the same result — Intel Arc B580 (Battlemage), and this run — all confirming the census itself is platform-stable: it's pure CPU translation, so hardware only enters through the suites everyone already knows. If anyone's curious what it actually covers beyond the one test name: each opcode in all 19 decode tables is encoded into a pixel program and taken through decode → ir → structure → resource → io → emit, with a name round-trip assert (encoder/decoder can't drift apart), each outcome classified as translate / named refusal / panic, and any panic failing CI — with `-- --nocapture` printing the per-opcode map (`census: 544 translated, 688 refused, 0 panicked`).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 14:55 UTC · original

Automated triage for the maintainers.

Merge candidate. A test-only change: emit/census_tests.rs encodes every opcode of every decoder table (gfx10/opcodes.rs, now pub(crate)) into a minimal pixel program and runs it through decode, IR, structure, resources, IO and emit. It fails if the decoder reads back another name than the table gives, or if any opcode panics instead of translating or refusing. I checked the per-family encodings against the field layouts the decoder uses (MUBUF opcode bit 7 in bit 25, MIMG's in bit 0, the literal-eating madmk/fmaak/setreg_imm32 forms), and that nothing outside tests changes. A panic in the translator is a crash a title can reach, so this guard is useful and walks new table entries automatically.

Optional: it eprintln!s about 690 refusal lines on every run; printing only a summary unless asked (e.g. an env var) would keep test logs readable.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 14:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2378#issuecomment-7166032393) <!-- victory-triage v1 head=fe101492fd391da2dace6147d68294cd52528cf1 verdict=merge-candidate at=2026-11-25T14:55:28Z --> Automated triage for the maintainers. **Merge candidate.** A test-only change: `emit/census_tests.rs` encodes every opcode of every decoder table (`gfx10/opcodes.rs`, now `pub(crate)`) into a minimal pixel program and runs it through decode, IR, structure, resources, IO and emit. It fails if the decoder reads back another name than the table gives, or if any opcode panics instead of translating or refusing. I checked the per-family encodings against the field layouts the decoder uses (MUBUF opcode bit 7 in bit 25, MIMG's in bit 0, the literal-eating `madmk`/`fmaak`/`setreg_imm32` forms), and that nothing outside tests changes. A panic in the translator is a crash a title can reach, so this guard is useful and walks new table entries automatically. Optional: it `eprintln!`s about 690 refusal lines on every run; printing only a summary unless asked (e.g. an env var) would keep test logs readable. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2378
No description provided.