Extract scalar and vector ALU lowering from lower.rs #84

Closed
feanorsun wants to merge 1 commit from upstream-pr/84 into main
feanorsun commented 2026-11-25 13:39:43 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by feanorsun on 2026-11-25T13:39:43Z.


Move scalar and vector ALU lowering into emit/lower/alu.rs. The parent dispatches through sop and valu. All 52 moved method bodies match the original byte for byte.

This resolves the file-size failure listed under Known problems in the README. The split reduces lower.rs from 630,652 to 453,035 bytes. The new module is 177,971 bytes. Both fit under the existing 524,288-byte limit.

Verification

  • cargo xtask policy passed for all 185 files.
  • cargo check --locked -p victory-shader --all-targets passed with the existing int_value dead-code warning.
  • cargo test --locked -p victory-shader --lib emit::lower:: passed all 44 tests before and after the split.
  • cargo test --locked -p victory-shader --lib emit::opcode_audit::refused_opcodes -- --exact passed.
  • cargo test --locked -p xtask passed all 4 tests, including repository_passes_policy.

Verified on Windows with Rust 1.98.1 (x86_64-pc-windows-gnu). No game was launched and no GPU or D3D12 device tests were run.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6605789412 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/84). Originally posted by [feanorsun](https://github.com/feanorsun) on 2026-11-25T13:39:43Z. --- Move scalar and vector ALU lowering into `emit/lower/alu.rs`. The parent dispatches through `sop` and `valu`. All 52 moved method bodies match the original byte for byte. This resolves the file-size failure listed under **Known problems** in the README. The split reduces `lower.rs` from 630,652 to 453,035 bytes. The new module is 177,971 bytes. Both fit under the existing 524,288-byte limit. ## Verification - `cargo xtask policy` passed for all 185 files. - `cargo check --locked -p victory-shader --all-targets` passed with the existing `int_value` dead-code warning. - `cargo test --locked -p victory-shader --lib emit::lower::` passed all 44 tests before and after the split. - `cargo test --locked -p victory-shader --lib emit::opcode_audit::refused_opcodes -- --exact` passed. - `cargo test --locked -p xtask` passed all 4 tests, including `repository_passes_policy`. Verified on Windows with Rust 1.98.1 (`x86_64-pc-windows-gnu`). No game was launched and no GPU or D3D12 device tests were run.
Adika713 commented 2026-11-25 15:36:11 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T15:36:11Z.


Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data, no GPU device tests.

I used clean detached worktrees and an isolated CARGO_TARGET_DIR per tree. A clean worktree matters here: the policy test in my main checkout also sees two untracked local .log files, which are not part of this PR comparison.

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b:

cargo test -p xtask policy::tests::repository_passes_policy -- --exact --nocapture
cargo test -p xtask
  • policy test: exit 101 — test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 3 filtered out.
  • violation: POLICY: crates/victory-shader/src/emit/lower.rs: 630652 bytes exceeds the 524288-byte limit.
  • full xtask suite: exit 101 — test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out.

After, at this PR's head b5a4046:

cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\policy-84\Cargo.toml -p xtask policy::tests::repository_passes_policy -- --exact --nocapture
cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\policy-84\Cargo.toml -p xtask
  • policy test: exit 0 — test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out.
  • full xtask suite: exit 0 — test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out.
  • File sizes in this tree: lower.rs 453,035 bytes and lower/alu.rs 177,971 bytes, both under the limit.

Overlap: PR #72 head 0771808 also passes both commands (4 passed / 0 failed for xtask), with lower.rs 499,516 bytes and lower/valu.rs 131,464 bytes. I did not write a competing fix.

Not tested: the game or any shader-GPU test; no game files were used.

AI-assisted: OpenCode, model Big Pickle. No game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7167096362 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/84#issuecomment-7167096362). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T15:36:11Z. --- Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data, no GPU device tests. I used clean detached worktrees and an isolated `CARGO_TARGET_DIR` per tree. A clean worktree matters here: the policy test in my main checkout also sees two untracked local `.log` files, which are not part of this PR comparison. Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`: ```powershell cargo test -p xtask policy::tests::repository_passes_policy -- --exact --nocapture cargo test -p xtask ``` - policy test: exit 101 — `test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 3 filtered out`. - violation: `POLICY: crates/victory-shader/src/emit/lower.rs: 630652 bytes exceeds the 524288-byte limit`. - full xtask suite: exit 101 — `test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out`. After, at this PR's head `b5a4046`: ```powershell cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\policy-84\Cargo.toml -p xtask policy::tests::repository_passes_policy -- --exact --nocapture cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\policy-84\Cargo.toml -p xtask ``` - policy test: exit 0 — `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out`. - full xtask suite: exit 0 — `test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out`. - File sizes in this tree: `lower.rs` 453,035 bytes and `lower/alu.rs` 177,971 bytes, both under the limit. Overlap: PR #72 head `0771808` also passes both commands (4 passed / 0 failed for xtask), with `lower.rs` 499,516 bytes and `lower/valu.rs` 131,464 bytes. I did not write a competing fix. Not tested: the game or any shader-GPU test; no game files were used. AI-assisted: OpenCode, model Big Pickle. No game data.
ySKELLETONX commented 2026-11-25 16:36:13 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T16:36:13Z.


Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at b5a4046: cargo test -p victory-shader --lib --locked: 266 passed, 0 failed, 6 ignored, hardware dispatch tests included (main at 01aadd1: 266 passed). Two runs, with #140 applied on top. Without it, parallel victory-shader runs here sometimes crash inside WARP (d3d10warp.dll, STATUS_ACCESS_VIOLATION). main does that too, so it has nothing to do with this PR, but it made the first run of this PR look broken. Workspace tests only; not run in the title.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7168244195 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/84#issuecomment-7168244195). Originally posted by [ySKELLETONX](https://github.com/ySKELLETONX) on 2026-11-25T16:36:13Z. --- Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at `b5a4046`: `cargo test -p victory-shader --lib --locked`: **266 passed, 0 failed, 6 ignored**, hardware dispatch tests included (`main` at `01aadd1`: 266 passed). Two runs, with #140 applied on top. Without it, parallel `victory-shader` runs here sometimes crash inside WARP (`d3d10warp.dll`, STATUS_ACCESS_VIOLATION). `main` does that too, so it has nothing to do with this PR, but it made the first run of this PR look broken. Workspace tests only; not run in the title.
adrianmjim commented 2026-11-25 17:47:27 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T17:47:27Z.


Checked against the game's shaders.rpf on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), with this PR (b5a4046) applied to 01aadd1 and its own target dir. victory translate --validate --list --host-lanes 32-64 with a hash of every emitted program's DXIL (a local, uncommitted patch): all 25,623 emitted programs are byte for byte the same as on 01aadd1, and the counts are unchanged (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765). Two runs of 01aadd1 give the same hashes, so the comparison is deterministic. cargo test -p victory-shader --lib -- --test-threads=1: 266 passed, 0 failed, 6 ignored. Not run in the game.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7170003404 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/84#issuecomment-7170003404). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T17:47:27Z. --- Checked against the game's `shaders.rpf` on an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), with this PR (`b5a4046`) applied to `01aadd1` and its own target dir. `victory translate --validate --list --host-lanes 32-64` with a hash of every emitted program's DXIL (a local, uncommitted patch): **all 25,623 emitted programs are byte for byte the same as on `01aadd1`**, and the counts are unchanged (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765). Two runs of `01aadd1` give the same hashes, so the comparison is deterministic. `cargo test -p victory-shader --lib -- --test-threads=1`: 266 passed, 0 failed, 6 ignored. Not run in the game.
feanorsun commented 2026-11-26 12:48:31 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by feanorsun on 2026-11-26T12:48:31Z.


Closing this in favor of #72, which was opened first and brings lower.rs under the size limit with a smaller refactor. Thanks to everyone who tested both approaches.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7192487528 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/84#issuecomment-7192487528). Originally posted by [feanorsun](https://github.com/feanorsun) on 2026-11-26T12:48:31Z. --- Closing this in favor of #72, which was opened first and brings `lower.rs` under the size limit with a smaller refactor. Thanks to everyone who tested both approaches.

Pull request closed

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
Belobug/VIctory-Belobug-AMD!84
No description provided.