Skip to content

Shaders: read a VALU opcode's name without a heap vector - #1834

Open
slatefield wants to merge 1 commit into
Marvisak:mainfrom
slatefield:shader/valu-name-no-alloc
Open

slatefield wants to merge 1 commit into
Marvisak:mainfrom
slatefield:shader/valu-name-no-alloc

Conversation

@slatefield

Copy link
Copy Markdown
Contributor

valu_dwords did name.split('_').collect::<Vec<&str>>() for every VALU instruction just to check parts.len() == 4 && parts[1] == "cvt", and fields() runs once per instruction.

now it peeks at the five tokens in place and only takes the last one with rsplit in the fallback arm. no alloc, same results.

measured on the isolated fields() loop: -8.9% at 12.1k instructions, -9.3% at 24.2k. stacked with the members() one, ir::build -5.0%. 118 lib tests pass.

outside what #1623/#1180/#1757 change.

valu_dwords split the name into a Vec of pieces for every VALU
instruction only to ask whether it is v_cvt_<dst>_<src>, and fields()
runs once per instruction. Peek at the five pieces in place (and take
the last one with rsplit for the fallback) instead. The fields walk is
8.9-9.3% faster on 12k-24k instruction programs; with the members()
change the IR build is 5.0% faster.
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

NVIDIA run: RTX 3070 8 GB, driver 616.56, plus WARP, Windows 11, debug, 3f20c55 (on main 70564ae). cargo test -p victory-shader --locked: 206 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures on main, so there are no new failures.

AI-assisted (Claude Code). Synthetic tests only.

@dcastell1

Copy link
Copy Markdown

Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. main@ffe310e baseline on this box: 342 passed, 0 failed, 6 ignored.

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace
342 passed; 0 failed; 6 ignored   (exit 0)

Same count as the baseline: reading a VALU opcode's name without a heap allocation is exercised by existing coverage and nothing regresses.

Tree restored afterwards; no game data. AI-assisted (opencode).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.

VALU opcode name read without a heap vector: removes an allocation from opcode-name lookup — small perf fix.

Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 24, 2026
Translation speed (compile-storm CPU): Marvisak#1623 inline instruction words
(decode -18..-45%), Marvisak#1834 VALU names without heap vector, Marvisak#1833 live-set
bit walk, Marvisak#1802 relative shift bounds, Marvisak#1824 dx.op declarations once.
Per-draw/per-list CPU: Marvisak#1825 view-stride table once per list, Marvisak#1826
object names only where logged, Marvisak#1800 capped-heap log spam once per 64Ki.
Tooling: Marvisak#1809 list pipeline keys without cache init.
Locking: Marvisak#1680 pipeline library loads without the global mutex.

Held: Marvisak#1819 (2^20->2^14 loop bound) breaks transcendental convergence
tests (sin/cos/exp/sqrt) — accuracy-lowering, rejected per policy.
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. valu_dwords in crates/victory-shader/src/gfx10/fields.rs used to collect name.split('_') into a Vec for every VALU instruction decoded. It now matches the first five pieces of the iterator directly. I checked that it is equivalent. (Some(_), Some("cvt"), Some(dst), Some(src), None) is exactly the old parts.len() == 4 && parts[1] == "cvt". The fallback rsplit('_').next() is the old parts.last(), and the explicit arms above are unchanged. This removes a heap allocation from the decode path, with no behaviour change.

As with #1833, a translation-time measurement would show the saving, but the change is safe either way.

CI: no check runs on the head commit.


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 3f20c55 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants