test(shader): translate random GFX10 programs on every test run #1335

Open
Levichu51 wants to merge 3 commits from upstream-pr/1335 into main
Levichu51 commented 2026-11-24 17:32:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-24T17:32:54Z.


The title translates its shaders in its own process when it creates pipelines, so a panic anywhere in ir, structure, resource, io or emit ends the title, and a translation that differs between runs defeats the shader cache and the pipeline library. Earlier panics of this kind were found by one-off random-input runs; nothing keeps that search going while some 290 open pull requests change the translator.

random_tests assembles 4,096 random but plausible programs per run (about three seconds in a debug build): opcodes from our tables with small register numbers, descriptors loaded from root tables first, branches that land on instructions a few before or after their own (loops among them), v_interp in pixel programs whose input element starts at any channel, and a store or export that needs what the body computes. Compute programs run as 32 or 64 lanes. Each program must translate or be refused with a reason, twice, with the same result; about one in ten reaches DXIL, and the test fails if fewer than one in fifty do, so that it keeps testing emission. A failure names the seeds and lists the first program in SP3. VICTORY_RANDOM_PROGRAMS, VICTORY_RANDOM_SEED and VICTORY_RANDOM_TRACE scale a run up, replay one program, and name the program a stack overflow aborts in.

It finds both earlier random-input bugs at their parent commit, without being aimed at them:

  • 97c78d10: a stack overflow (wave64, a write of exec_hi alone; fixed by ea24ea10);
  • 97c78d10 + ea24ea10: seed 93 panics with "attempt to subtract with overflow" at lower.rs:1022 (an input element starting at w; fixed by 5fbea473). On main, 300,000 programs (release build with overflow checks) all pass.

gfx10::opcodes exposes the opcode tables to tests.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5477176010 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-24T17:32:54Z. --- The title translates its shaders in its own process when it creates pipelines, so a panic anywhere in ir, structure, resource, io or emit ends the title, and a translation that differs between runs defeats the shader cache and the pipeline library. Earlier panics of this kind were found by one-off random-input runs; nothing keeps that search going while some 290 open pull requests change the translator. random_tests assembles 4,096 random but plausible programs per run (about three seconds in a debug build): opcodes from our tables with small register numbers, descriptors loaded from root tables first, branches that land on instructions a few before or after their own (loops among them), v_interp in pixel programs whose input element starts at any channel, and a store or export that needs what the body computes. Compute programs run as 32 or 64 lanes. Each program must translate or be refused with a reason, twice, with the same result; about one in ten reaches DXIL, and the test fails if fewer than one in fifty do, so that it keeps testing emission. A failure names the seeds and lists the first program in SP3. VICTORY_RANDOM_PROGRAMS, VICTORY_RANDOM_SEED and VICTORY_RANDOM_TRACE scale a run up, replay one program, and name the program a stack overflow aborts in. It finds both earlier random-input bugs at their parent commit, without being aimed at them: - 97c78d10: a stack overflow (wave64, a write of exec_hi alone; fixed by ea24ea10); - 97c78d10 + ea24ea10: seed 93 panics with "attempt to subtract with overflow" at lower.rs:1022 (an input element starting at w; fixed by 5fbea473). On main, 300,000 programs (release build with overflow checks) all pass. gfx10::opcodes exposes the opcode tables to tests.
Marvisak commented 2026-11-25 02:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:22:47Z.


Automated triage for the maintainers.

Merge candidate. This adds a seeded random-program test for the shader translator (crates/victory-shader/src/emit/random_tests.rs, #[cfg(test)]) and a test-only gfx10::opcodes accessor. Each program must translate, or be refused with a reason, twice and with identical results. A failure names the seed and prints the program as SP3.

The point from the last review is fixed in 3541e51. random_tests::translate now calls range::build followed by resource::track, io::raise and emission, the same sequence emit::translate_with runs on main, so the bounded rebuild of relative moves is now fuzzed. The new relative_move generator puts an M0 set to a constant, or clamped by s_min_u32/s_and_b32, in front of a v_movrel*/v_swaprel_b32. I checked its SOP1/SOP2/VOP1 encodings against the GFX10 layout, and they are correct.

One optional note: the test emits through emit (no view write marks), while the runtime translates with view_marks: true. Calling emit_with with those options would cover that path too.

Reply to the author: thanks. Making the generator produce boundable M0 values (642 of 4,096 programs now reach the rebuilt program) is exactly what was needed for the range analysis to be exercised, not just called.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149484628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7149484628). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:22:47Z. --- <!-- victory-triage v1 head=3541e51ea6d39ede643d7e5e93fde15d9201d872 verdict=merge-candidate at=2026-11-25T20:22:45Z --> Automated triage for the maintainers. **Merge candidate.** This adds a seeded random-program test for the shader translator (`crates/victory-shader/src/emit/random_tests.rs`, `#[cfg(test)]`) and a test-only `gfx10::opcodes` accessor. Each program must translate, or be refused with a reason, twice and with identical results. A failure names the seed and prints the program as SP3. The point from the last review is fixed in `3541e51`. `random_tests::translate` now calls `range::build` followed by `resource::track`, `io::raise` and emission, the same sequence `emit::translate_with` runs on `main`, so the bounded rebuild of relative moves is now fuzzed. The new `relative_move` generator puts an M0 set to a constant, or clamped by `s_min_u32`/`s_and_b32`, in front of a `v_movrel*`/`v_swaprel_b32`. I checked its SOP1/SOP2/VOP1 encodings against the GFX10 layout, and they are correct. One optional note: the test emits through `emit` (no view write marks), while the runtime translates with `view_marks: true`. Calling `emit_with` with those options would cover that path too. Reply to the author: thanks. Making the generator produce boundable M0 values (642 of 4,096 programs now reach the rebuilt program) is exactly what was needed for the range analysis to be exercised, not just called. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Levichu51 commented 2026-11-25 18:02:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-25T17:54:12Z.


Rebased onto current main (13f91ca); conflict in emit/mod.rs resolved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170159857 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7170159857). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-25T17:54:12Z. --- Rebased onto current main (13f91ca); conflict in emit/mod.rs resolved.
Levichu51 commented 2026-11-25 19:06:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-25T18:52:04Z.


Thanks. translate now goes through crate::range::build, as translate_with does (3541e51).

Switching alone didn't reach range's fixed point: in 4,096 programs, 240 had a relative move and none got a bound, because their M0 was almost never boundable. The generator now adds relative moves mostly after an M0 set to a constant or clamped by s_min_u32 / s_and_b32. Of the default 4,096 programs, 1,363 have a relative move and 642 get a proven bound and a rebuilt program. 500,000 programs pass in release with overflow checks.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171511377 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7171511377). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-25T18:52:04Z. --- Thanks. translate now goes through crate::range::build, as translate_with does (3541e51). Switching alone didn't reach range's fixed point: in 4,096 programs, 240 had a relative move and none got a bound, because their M0 was almost never boundable. The generator now adds relative moves mostly after an M0 set to a constant or clamped by s_min_u32 / s_and_b32. Of the default 4,096 programs, 1,363 have a relative move and 642 get a proven bound and a rebuilt program. 500,000 programs pass in release with overflow checks.
fuzeofficlal commented 2026-11-26 02:06:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:19:37Z.


Code review and Windows 11 verification at head 3541e51ea6d3 merged cleanly onto main (63bcca43c6a0; emit/lower.rs untouched):

  • Determinism & runtime audit (crates/victory-shader/src/emit/random_tests.rs, gfx10/mod.rs:335-362):
    • Fully deterministic (splitmix64 -> xorshift64 over default seed = 1..=4096, no clock/entropy or HashMap nondeterminism), checks both panic-freedom and byte-identical DXIL/error reproducibility across two passes per seed, and requires >= 2% to reach DXIL emit when count >= 1000.
    • Pure static translation (2..=31 instructions, bounded [k-6, k+6] branch window, bounded SMEM retry loop) — ran all 4,096 x 2 translations in 4.57 s in debug mode with zero hang risk.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 192 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • victory-shader -- random_programs: 2/2 passed (4.57 s).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179661928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7179661928). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:19:37Z. --- Code review and Windows 11 verification at head `3541e51ea6d3` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` untouched): - **Determinism & runtime audit (`crates/victory-shader/src/emit/random_tests.rs`, `gfx10/mod.rs:335-362`)**: - Fully deterministic (`splitmix64` -> `xorshift64` over default `seed = 1..=4096`, no clock/entropy or HashMap nondeterminism), checks both panic-freedom and byte-identical DXIL/error reproducibility across two passes per seed, and requires `>= 2%` to reach DXIL emit when `count >= 1000`. - Pure static translation (`2..=31` instructions, bounded `[k-6, k+6]` branch window, bounded `SMEM` retry loop) — ran all 4,096 x 2 translations in **4.57 s** in debug mode with zero hang risk. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `192 files ok`; `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `victory-shader -- random_programs`: **2/2 passed** (4.57 s). LGTM.
Levichu51 commented 2026-11-26 14:01:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-26T13:12:38Z.


Rebased onto current main (63bcca4). Took the optional note: translate now calls emit_with, with write marks on odd seeds (as the title's pipelines are made) and without on even ones, so both paths are fuzzed at no extra cost (7399813). 147 of the default 4,096 programs are translated with marks emitted; 300,000 programs pass in release with overflow checks.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193024628 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7193024628). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-26T13:12:38Z. --- Rebased onto current main (63bcca4). Took the optional note: translate now calls emit_with, with write marks on odd seeds (as the title's pipelines are made) and without on even ones, so both paths are fuzzed at no extra cost (7399813). 147 of the default 4,096 programs are translated with marks emitted; 300,000 programs pass in release with overflow checks.
Levichu51 commented 2026-11-26 15:02:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-26T14:29:36Z.


Follow-up ready: I extended the random-program test to vertex and mesh programs (plus more pixel I/O: depth/stencil exports, f16 interpolation, 16-bit inputs), on the branch test/shader-random-vs-ms in my fork. It builds on this PR, so I'll open it as a separate PR once this one is merged, rebased to a single commit.

Short summary of the follow-up:

  • 4 stages (compute 45%, pixel 25%, vertex 15%, mesh 15%); vertex/mesh cover params (f32, 16-bit, packed), clip distances, per-primitive outputs, exp prim with valid or random indices, mesh limits.
  • Fixes two generator mistakes (s_buffer_* descriptors, SGPR writes over loaded descriptors).
  • The test fails if any stage translates under 1% of its programs.
  • 2.1M programs pass (release, overflow checks; 600k also with debug assertions), no translator bug found.

No changes needed here; this PR stays as it is.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194898759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7194898759). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-26T14:29:36Z. --- Follow-up ready: I extended the random-program test to vertex and mesh programs (plus more pixel I/O: depth/stencil exports, f16 interpolation, 16-bit inputs), on the branch test/shader-random-vs-ms in my fork. It builds on this PR, so I'll open it as a separate PR once this one is merged, rebased to a single commit. Short summary of the follow-up: - 4 stages (compute 45%, pixel 25%, vertex 15%, mesh 15%); vertex/mesh cover params (f32, 16-bit, packed), clip distances, per-primitive outputs, exp prim with valid or random indices, mesh limits. - Fixes two generator mistakes (s_buffer_* descriptors, SGPR writes over loaded descriptors). - The test fails if any stage translates under 1% of its programs. - 2.1M programs pass (release, overflow checks; 600k also with debug assertions), no translator bug found. No changes needed here; this PR stays as it is.
Levichu51 commented 2026-11-27 20:17:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-27T20:17:27Z.


Note for reviewers: the pixel programs this test generates export from v0-v3, which hold the barycentrics, and a direct read of those is refused. So pixel programs here translate only about 2.5% of the time. Nothing is wrong with the test; it just covers pixel emission less than it could. The follow-up #3596 fixes it (export from v2-v5, random operands mostly avoid v0-v1), and pixel programs then translate about 7% of the time. I've left it out of this PR to keep it as reviewed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227359546 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7227359546). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-27T20:17:27Z. --- Note for reviewers: the pixel programs this test generates export from v0-v3, which hold the barycentrics, and a direct read of those is refused. So pixel programs here translate only about 2.5% of the time. Nothing is wrong with the test; it just covers pixel emission less than it could. The follow-up #3596 fixes it (export from v2-v5, random operands mostly avoid v0-v1), and pixel programs then translate about 7% of the time. I've left it out of this PR to keep it as reviewed.
Levichu51 commented 2026-11-29 19:18:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Levichu51 on 2026-11-29T19:18:40Z.


Correction to the description: seed 93 refers to the first version of the generator. Later commits changed what each seed produces, so it no longer reproduces that bug. The two historical bugs were checked with that first version only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7261178177 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7261178177). Originally posted by [Levichu51](https://github.com/Levichu51) on 2026-11-29T19:18:40Z. --- Correction to the description: seed 93 refers to the first version of the generator. Later commits changed what each seed produces, so it no longer reproduces that bug. The two historical bugs were checked with that first version only.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1335:upstream-pr/1335'
git switch 'upstream-pr/1335'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1335'
git switch 'upstream-pr/1335'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1335'
git switch 'upstream-pr/1335'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1335'
git switch 'main'
git merge --squash 'upstream-pr/1335'
git switch 'main'
git merge --ff-only 'upstream-pr/1335'
git switch 'main'
git merge 'upstream-pr/1335'
git push origin 'main'
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
Marvisak/VIctory!1335
No description provided.