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

Open
github-bot wants to merge 3 commits from github-bot/gh-1335 into main AGit
Owner

@⁠Levichu51 on GitHub · 2026-11-24 17:32 UTC · original
Levichu51:test/shader-random-programs → main · +623 −0 · 3 files · 3 commits · open

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.

**@⁠Levichu51** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335) `Levichu51:test/shader-random-programs` → `main` · +623 −0 · 3 files · 3 commits · open 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.
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.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review: random_tests ran ir::build and structure::structure itself, not
the stages translate_with runs, so the bounded rebuild of relative moves
(range::build) was never fuzzed. translate now calls range::build like
translate_with does.

That alone reaches range's fixed point in no program: the generator's
relative moves almost never had an M0 the analysis can bound (240 of
4,096 programs had a move, none was bounded). The generator now adds a
relative move to one instruction in 25, mostly after an M0 set to a
constant or clamped by s_min_u32 or 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 (release, overflow checks on).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:01 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:22 UTC · original · edited 2026-11-25 20:22 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7149484628) · edited 2026-11-25 20:22 UTC <!-- 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)_
Author
Owner

@⁠Levichu51 on GitHub · 2026-11-25 17:54 UTC · original

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

**@⁠Levichu51** on GitHub · 2026-11-25 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7170159857) Rebased onto current main (13f91ca); conflict in emit/mod.rs resolved.
Author
Owner

@⁠Levichu51 on GitHub · 2026-11-25 18:52 UTC · original

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.

**@⁠Levichu51** on GitHub · 2026-11-25 18:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7171511377) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:19 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7179661928) 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.
github-bot force-pushed github-bot/gh-1335 from 3541e51ea6 to 7399813379 2026-11-26 13:13:28 +00:00 Compare
Author
Owner

@⁠Levichu51 on GitHub · 2026-11-26 13:12 UTC · original

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** on GitHub · 2026-11-26 13:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7193024628) 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.
Author
Owner

@⁠Levichu51 on GitHub · 2026-11-26 14:29 UTC · original

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** on GitHub · 2026-11-26 14:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1335#issuecomment-7194898759) 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1335/head:github-bot/gh-1335'
git switch 'github-bot/gh-1335'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1335'
git switch 'github-bot/gh-1335'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1335'
git switch 'github-bot/gh-1335'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1335'
git switch 'main'
git merge --squash 'github-bot/gh-1335'
git switch 'main'
git merge --ff-only 'github-bot/gh-1335'
git switch 'main'
git merge 'github-bot/gh-1335'
git push origin 'main'
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!1335
No description provided.