test(shader): translate random GFX10 programs on every test run #1335
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1335"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 byea24ea10);97c78d10+ea24ea10: seed 93 panics with "attempt to subtract with overflow" at lower.rs:1022 (an input element starting at w; fixed by5fbea473). On main, 300,000 programs (release build with overflow checks) all pass.gfx10::opcodes exposes the opcode tables to tests.
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-onlygfx10::opcodesaccessor. 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::translatenow callsrange::buildfollowed byresource::track,io::raiseand emission, the same sequenceemit::translate_withruns onmain, so the bounded rebuild of relative moves is now fuzzed. The newrelative_movegenerator puts an M0 set to a constant, or clamped bys_min_u32/s_and_b32, in front of av_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 withview_marks: true. Callingemit_withwith 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
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.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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:19:37Z.
Code review and Windows 11 verification at head
3541e51ea6d3merged cleanly ontomain(63bcca43c6a0;emit/lower.rsuntouched):crates/victory-shader/src/emit/random_tests.rs,gfx10/mod.rs:335-362):splitmix64->xorshift64over defaultseed = 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 whencount >= 1000.2..=31instructions, bounded[k-6, k+6]branch window, boundedSMEMretry loop) — ran all 4,096 x 2 translations in 4.57 s in debug mode with zero hang risk.cargo xtask policy:192 files ok;cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warningsvictory-shader -- random_programs: 2/2 passed (4.57 s).LGTM.
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.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:
No changes needed here; this PR stays as it is.
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.
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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.