Shader: translate a whole-wave section that a jump splits with the join's code in each arm #36
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/36"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T10:46:50Z.
Two reductions a branch chooses between that share their end (
cond ? WaveActiveMax(x) : WaveActiveMin(x)) left no block with a whole section, sov_permlanex16_b32was refused. Such a program is translated once more with each section in one block (ir::whole_sections, up to four rounds), and that translation is taken if it succeeds.Bounded. Over all rounds the copies may total at most the program's own instruction count (256 for a smaller program), so a joined program is at most twice the original plus 256. A round past that is skipped and logged; earlier rounds are kept.
Logged. Replacing a translation that already succeeded logs at info (digest, stage, rounds, instructions copied); a rescued refusal and a failed retry log at debug.
Measured. On the Wine route, one compute shader that was refused for
v_permlanex16_b32now translates, and no other container of 19,106 changes. Through the native host's path, a 19,105-shader capture gives one translation replaced, no refusals rescued (the unjoined lowering already handles it on 32 lanes), the bound never reached, and the other 19,104 byte-identical to main. No switch: other programs translate as before.Credit: after darkworldhm/victory-fork-darkworldhm.
Tests: the ported structural test;
sections_are_not_joined_past_the_copy_bound;a_reduction_a_branch_picks_gives_each_lane_its_value_on_metalruns the reduction on Metal with 48 of 64 lanes and checks every lane (it fails with the arms swapped, but passes without the join on this 32-lane host; the 64-lane D3D12 route has no GPU test). victory-shader 221 passed, victory-gpu 145 passed; Windows clippy andxtask policyclean. Notes in docs/native-host.md.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:01:03Z.
Review: CHANGES_REQUESTED
The transformation looks sound. The join's tail runs once on each path, back-edge joins are skipped, and failure falls back to the original translation. Tests, Windows clippy and policy pass merged with current main. Requests:
cond ? WaveActiveMax : WaveActiveMingives the right per-lane value.docs/native-host.md(AGENTS.md asks for one).Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:24Z.
Review: CHANGES_REQUESTED
Please fix the chained-join case first. If
A → B → Chas one section ending inBand another starting inBand ending inC, both fusions can be picked in one round. The rewrite then redirectsAtoCand clearsCusing its original predecessor list, which can erase a reachable restore or store (ir.rs:~394-404). Please add a regression that keeps a visible store inC.Still open from before:
docs/native-host.md.Also, please remove the title-derived shader ID from the source and test comments (
emit/mod.rs:~482,~790,ir.rs:~313). This repo keeps nothing taken from the game.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:54Z.
Review: CHANGES_REQUESTED
Thanks for bounding the copies and adding the min/max fixture. I reproduced the chained-join bug with a synthetic store in C (A → B → C): the retry succeeds and drops the store from DXIL (
ir.rs~401/411 clears C using its original predecessors). Please fix the predecessor handling and add that regression. Please also make the retry logs opt-in behind a documentedVICTORY_*switch (they'reinfo!now, which the app enables by default), and remove the title-derived shader ID from the source (emit/mod.rs~491/860,ir.rs~313), the test comment, the PR description, and the landed history.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:37:01Z.
Thanks. All four points:
sections_are_not_joined_past_the_copy_boundtests it. Across a 19,105-shader capture the bound never triggered.a_reduction_a_branch_picks_gives_each_lane_its_value_on_metalrunscond ? WaveActiveMax : WaveActiveMinon Metal with 48 of 64 lanes active and checks every lane; it fails with the arms swapped. Caveat: on this 32-lane host the unjoined lowering is already right, so it also passes without the join. The 64-lane D3D12 route, where the join matters, has no GPU test.The branch is squashed to one commit.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:38:50Z.
@LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:46:40Z.
Review: CHANGES_REQUESTED
Thanks for bounding the copies; the Metal test runs fine here. Three things are still open:
buffer_store_dword) gets both (A,B) and (B,C) fused in one round, so A takes B's original tail and jumps to a C that was emptied. Reachable stores go from 1 to 0. Please fuse in dependency order or one fusion per round, and add a regression with a visible store in C. (The Metal test also passes without the join on a 32-lane host, so it doesn't guard this.)info!with no switch. Per AGENTS.md, new diagnostics are off by default behind a documentedVICTORY_*variable (e.g.VICTORY_SHADER_JOIN_LOG=1). Please also drop "No switch" from the PR body.emit/mod.rs: the retry comment and thetwo_reductionsdoc;ir.rs). Please replace it with a plain description; squashing doesn't help while it's in the final tree.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T13:17:28Z.
Closing this: I'm continuing this work on my fork, 64bitMango/Native-Victory-macOS, where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.
Pull request closed