feat: shader census counts the translation's own costs per shader hash #570
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/570"
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 LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T23:46:10Z.
What
VICTORY_SHADER_CENSUS=<file>already madevictory translateappend one line per emitted program, with its instruction kinds. The line now also carries what the translator knows to be costly on the host. These are counts only, with no code:added_barrierindexed_selectv_movrels/d/sd_b32): one per register M0 may name, up to the program's VGPR countwide64loopslds_bytesthreads,wave_sizeWaveSizethe shader requires (0 = none)c_minmax,c_minmax_k,c_round,c_trig,c_perm,c_pk16,c_legacy_k: with an inline or literal constant),v_rndne_f32,v_sin/cos_f32,v_perm_b32, packed f16 arithmetic, legacy multiplies. Each took 2-6x the GPU time of the closest HLSL in a chain bench on the 4060 Laptopform=as is,without early-outs,local waves (APPROXIMATE),loose LDS (APPROXIMATE),wave-wide branches...root_cbvs/srvs/uavs,user_dwords,samplersThe existing kinds (
guard_select,clamp,loop_counter,wave_op,barrier, LDS/buffer/texture traffic...) are unchanged. Each line starts with the label, which ends in#<16-digit hash>, the same hash the run log uses.VICTORY_TRANSLATE_ONLY=<hash,...>limits the run to those shaders.Why
YUYING234's GPU-timed run on Marvisak/VIctory#3505 (4060 Laptop) puts 92 % of the card's time in the title's own commands. Almost all of it is in a handful of compute shaders (
3cf39f44…,82a2ad6d…,4518151a…,dd24ff46…, and7b2c3c1d…at 50 ms a dispatch). We cannot look at those shaders and must not. A tester who owns the game can run this and post the counts for those hashes. That tells us which translation cost to attack: wave64 exchanges, indexed-register select chains, loop counters, and so on.How
Tags (Meetingongroup_syncbarriers,Indexedon movrel selects) are counted inModule::census. Tags only exist while counting and are never written, so the DXIL does not change.census::with(f)turns counting on for one thread. Tests use it, and so can tools that want one program's counts.census::form():emitnotes which retry produced the program.Census::defaultis now written out, because 33 kinds is pastDefaultfor arrays.The translator's source files change, so the shader cache key changes once (as with any translator change). The translation itself is identical.
Tests
census_counts_the_barriers_and_lds_two_host_waves_add: a wave64 program with a lane-mask count, on a 32-lane host, has ≥ 2 added barriers, ≥ 8 LDS bytes and 64 threads. The same program on a 64-lane host, and a variant without the exchange, have 0 and 0.census_counts_indexed_register_selects_and_64_bit_results:v_movrels_b32 v5, v1in a 16-VGPR program gives exactly 15 indexed selects, andv_lshlrev_b64giveswide64 ≥ 1. A plain move gives 0 for all three.census::withdo not exist.cargo test -p victory-shader --libon the RTX 4060 Laptop: 340 passed, 6 ignored.cargo check -p victorypasses. Full pytest (WARP): 1454 passed, 529 skipped.Update (2026-11-28): two commits after the first census
YUYING234 posted the census lines for the five hashes on #3505. Two things came out of them:
a2b484b4fix:loopscounted forward edges. The census counted every branch to a lower-numbered block. The lowering appends its own blocks (critical-edge blocks, the joins of guarded stores), so their forward branches into the next console block counted as loops: 64-247 for skinning programs that have 1-4 loops (loop_counteris 3 per loop). It now counts the back edges on the depth-first path (Module::back_edges, whichsingle_latchesuses). Test:census_counts_loops_not_forward_edges_into_earlier_blocks(a diamond whose edge block was made last, a loop whose latch was made last, and a header numbered after its latch) fails before (left: 1, right: 0).a7767758feat:c_minmax...c_legacy(row above), counted from the console program. Test:spelled_out_instructions_by_class.cargo test -p victory-shader --lib --releaseon the RTX 4060 Laptop: 371 passed, 24 ignored (with the med3 PR on top).cargo xtask policy: 381 files ok. The translation is unchanged.AI use: written and tested by Claude Code (Claude Opus 5.5) for KainanP. The tests were run on synthetic programs only; no game shader was used.
🤖 Generated with Claude Code
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:15:43Z.
Main just took #563 (the VIctory copy moved to Vice-Tay
4f15f09e) and #564 (memory stack), and this PR now conflicts inthird_party/victory/crates/victory-shader/src/emit/bitcode.rs,third_party/victory/crates/victory-shader/src/emit/mod.rs. Please rebase on current main, rerun the tests for the files you touch, and force-push.Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T00:59:00Z.
Rebased on main
132da61and force-pushed: the head is nowa37407f1, one commit, and it shows MERGEABLE.bitcode.rs:Module::tagkeeps main's clamp exception:tag == Tag::Clamp || census::counting().mod.rs:census::set_form("as is")now comes after main's newWAVE64-PAIRS-ONLYblock, just before the firstemit_program.The translation itself is unchanged. On the RTX 4060 Laptop,
cargo test -p victory-shader --lib(with #571 on top) gives 369 passed, 0 failed, 21 ignored, andcargo check -p victorypasses.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.