Skip to content

victory-shader: hash the lowering tables with Fx instead of SipHash (lowering -16%) - #1002

Closed
pes7 wants to merge 3 commits into
Marvisak:mainfrom
pes7:perf/shader-fx-hash
Closed

pes7 wants to merge 3 commits into
Marvisak:mainfrom
pes7:perf/shader-fx-hash

Conversation

@pes7

@pes7 pes7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Title: Shaders: the lowering tables hash with SipHash - one shared Fx hasher takes 16% off the lowering stage

Rebased onto main 940d32f (head 21ff7f6). The numbers below are from ffe310e, the base they were measured on, because lower.rs and structure.rs were both rewritten upstream since. The map sites upstream added in those files are on the same Fx hasher now - 22 of them in lower.rs alone - otherwise the file would carry two hashers and the claim would only hold for the tables this change knew about. The one place that stays on std::collections is Structured's public fields: they are pub, so a private hasher there is a private type in a public interface, which clippy -D warnings rejects. cargo test --workspace --locked passes, DXIL differential tests included (247 in this crate).

Where the time goes

emit/lower.rs keeps thirty tables keyed by Value, a register or a block index: vals, floats, bools,
lane_bits, phi_at, def_block, params, descriptors, scalar, exports, interps, handles, edges,
ballots, sections... They were std::collections::HashMap, whose default hasher is SipHash-1-3 with a random
per-process seed: setup, two rounds per word, finalisation. structure.rs had already noticed this ("The tables
below have small integer keys; SipHash dominated run time") and defined an Fx multiply-rotate hasher for its own
tables; the lowering stage, which is the larger half of a translation, never got it.

What changes

  • crates/victory-shader/src/hash.rs: the Fx hasher and Map/Set aliases, moved out of structure.rs
    (same 20 lines of hasher; structure.rs now imports it).
  • emit/lower.rs: 26 HashMap and 4 HashSet fields become Map/Set.
  • emit/wave.rs: sections() returns a Map (its caller stores it in one).
  • emit/bench_tests.rs: an #[ignore]d test that builds synthetic GFX10 compute programs - no game data - of
    256 to 16 384 instructions and times each stage, so this change and the next one are numbers rather than
    impressions. cargo test --release -p victory-shader --lib bench_tests -- --ignored --nocapture.

No emitted byte changes: these are lookup tables, and nothing iterates them. The one table whose order reaches the
output (user_reads, the user-data slots) is a BTreeMap and stays one.

Measured

One binary each, the same synthetic programs, ten interleaved rounds per arm (alternating, best of the ten) so the
machine's other work hits both arms:

instructions stage before after ratio
256 lowering 593 514 0.867
1 024 lowering 529 428 0.809
4 096 lowering 514 430 0.837
16 384 lowering 543 463 0.853
256 whole translation 1002 912 0.910
1 024 whole translation 981 920 0.938
4 096 whole translation 1046 968 0.925
16 384 whole translation 1068 965 0.904

Nanoseconds per instruction. ir::build, structure, resource and io are unchanged, as they should be.

Correctness

  • DXIL is byte-identical for all four program sizes: the bench prints an FNV-1a over the emitted bytes, and the
    four digests match between the two arms.
  • cargo test --workspace --locked
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features
  • cargo xtask policy

No game data used anywhere.

Not included

A second experiment, ir::build building its per-instruction reads/writes as (Reg, Value) pairs instead of
Vec<Reg> then a second Vec (two allocations per instruction saved), measured -12 to -20% on ir::build but
was a wash over the whole translation, so it is not in this diff. Say the word if you want it measured again on
main.

@pes7 pes7 mentioned this pull request Nov 24, 2026
MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 24, 2026
emit/lower.rs keeps dozens of tables keyed by values, registers and
block indices and asks them about every instruction. structure.rs
already had an Fx hasher for this reason; move it to crate::hash and use
it in lowering and wave::sections. Upstream measured lowering ~16%
faster (whole translation ~8%), with byte-identical output.

From upstream PR Marvisak#1002 (0e33bfe), adapted: its bench tests are not
taken.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 0e33bfe: cargo test -p victory-shader passes, 120 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Independent follow-up, review them in any order: #1033 (one file, +25/-25) removes two of the four allocations ir::build makes per instruction - ir::build -13%, whole translation -4.7%, byte-identical output. It does not touch anything in this diff.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.

Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.

Measured with the synthetic bench in #1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:

  ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
  translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)

gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Combined measurement of the three open ones, since the individual numbers overlap: this PR, #1033 and #1180 together, one binary pair, twelve interleaved rounds per arm (best of each), nanoseconds per instruction on main ffe310e vs the three applied:

instructions stage main all three ratio
16 384 lower 519 419 0.81
16 384 resource 22 15 0.68
16 384 structure 40 34 0.85
16 384 ir::build 408 372 0.91
16 384 whole translation 1 038 881 0.85
instructions whole translation main -> all three ratio
256 986 -> 852 0.864
1 024 964 -> 810 0.840
4 096 1 014 -> 844 0.832
16 384 1 038 -> 881 0.849

So about -15% per translation together, and the emitted DXIL is byte-identical at all four sizes.

decode is the one stage that pays: it resolves the name it used to be spared (#1180), 110 -> 113 at 16k, and grows Instruction by two words. That is inside the run-to-run spread here, but it is the honest trade.

The remaining profile after all three, per instruction at 16k: lower 419 (48%), SSA construction 259, decode 113, structure 34, io 25, resource 15. The next thing worth attacking is the lowering dispatcher (a match on ~250 opcode-name string arms), which is a structural change, not a one-liner.

@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks - that is the verification this PR needed, and on AMD rather than the Blackwell box I measured on.

Two notes so the record is exact:

  • The head has moved from 0e33bfe to 74e2dbf. The only difference is a second commit that adds the gfx10::decode column to the bench (emit/bench_tests.rs); no production code changed, so your result stands for the current head too.
  • The change itself is CPU-bound, so RDNA3 vs Blackwell does not move the numbers - the card only matters for the valu_tests half of the suite, which you also ran green.

If you have a minute, the numbers themselves are reproducible on your machine with:

cargo test --release -p victory-shader --lib bench_tests -- --ignored --nocapture

It prints nanoseconds per instruction per stage at 256/1k/4k/16k instructions on synthetic GFX10 programs (no game data), and an FNV over the emitted DXIL so a diff shows up immediately. On my machine (Ryzen, Windows 11) lower goes 593 -> 514 at 256 instructions and the whole translation 1002 -> 912; main on the same binary pair is the "before" column. A second CPU would tell us whether that holds or it is a one-machine result - useful either way.

mercuryVM pushed a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
`Instruction::name()` binary-searches the opcode table, and the pipeline
asks about every instruction eight times per translation: `ir::build`,
`structure`, `resource` (which has the most call sites), `io` and
`lower`. The answer cannot change - the encoding and opcode are decoded
from the words and never rewritten - so resolve it once when the
instruction is built and read the field after that.

Measured with the synthetic bench from Marvisak#1002 (no game data), sixteen
interleaved rounds per arm, best of each, nanoseconds per instruction, at
256/1k/4k/16k instructions:

  resource     17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15    (0.47-0.67)
  lower       511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428  (0.90-0.96)
  io           27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22   (0.73-0.85)
  whole       926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96)

`decode` pays the one search it used to be spared (112 -> 115 at 16k,
inside the run-to-run spread); every stage after it reads a field. The
emitted DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
@pes7
pes7 force-pushed the perf/shader-fx-hash branch from fb2f488 to 1522921 Compare November 24, 2026 18:35
@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Where the rest of the time goes, measured on the same synthetic programs with a counting global allocator (temporary, not in this PR). Per instruction:

stage allocations bytes
gfx10::decode 1.17 149
ir::build (includes its own decode) 8.17 965
structure + resource + io + lower 1.4 - 3.3 1.6 KB

And the split inside ir::build, timed by marks: decode 110, then fields + effects + push = ~285 ns per instruction, with link, liveness, SSA renaming and phi cleanup together under 20 ns. So the phase that looks like "SSA" in the table is almost entirely allocation.

At ~35 ns an allocation, 8 of them is ~280 ns - the whole of that phase. The lists are 1-4 elements each:

  • Instruction::words: Vec<u32>, a heap vector for an instruction that is usually one dword;
  • Fields::Sop.src, Fields::Smem.data, Fields::Mubuf.addr, Fields::Valu.src: Vec<Operand>;
  • Inst::reads / Inst::writes: Vec<(Reg, Value)>.

That is where the remaining ~25-30% of a translation sits, and it is a storage change (SmallVec-style inline arrays, or one arena per program with (start, len) in Inst), not an algorithm. It also changes public types in gfx10 and ir, so it does not belong in these three PRs - I would rather do it as its own change with this measurement as the target.

Whether it is worth it: on the real corpus one translation is 26k programs, so ~280 ns per instruction times the instruction count of the corpus. victory translate --list reports the total for the pack; that is what to multiply against.

Happy to take it if the direction sounds right, or to leave it here.

pes7 added a commit to pes7/VIctory that referenced this pull request Nov 24, 2026
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.

Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.

Measured with the synthetic bench in Marvisak#1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:

  ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
  translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)

gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
@pes7
pes7 force-pushed the perf/shader-fx-hash branch from 1522921 to b6db985 Compare November 24, 2026 21:57
@pes7

pes7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto today's main (70564ae), which rewrote much of emit/lower.rs (+3 300 lines: BVH lowering, the low16 table, a changed half_outputs): five conflicts, resolved by keeping the upstream structure and putting the maps on the Fx hasher.

Two things worth knowing about the new head (b6db985):

  • upstream's own additions in that file brought 22 new HashMap/HashSet sites (the whole-file constants analysis, liveness, touched/konst/can_be). They are on crate::hash::{Map, Set} now too, otherwise the file would have two hashers and the claim would only hold for the tables this PR knew about;
  • the diff against main is +420/-103, larger than the original change because it has to carry those sites too.

The measured numbers in the description are from the pre-rebase base (ffe310e), where lower 593 -> 514 and the whole translation 1 002 -> 912 ns per instruction. structure.rs and lower.rs have both changed a lot since, so treat them as the number for the change, not for today's tree - I can re-run the same bench on 70564ae against a main build if anyone wants the current figure before merging.

cargo test -p victory-shader --locked: 209 passed, 0 failed (DXIL differential tests included, so the output is still byte-identical). Both clippy configurations with -D warnings pass, as does cargo xtask policy.

pes7 added a commit to pes7/VIctory that referenced this pull request Nov 24, 2026
`Instruction::name()` binary-searches the opcode table, and the pipeline
asks about every instruction eight times per translation: `ir::build`,
`structure`, `resource` (which has the most call sites), `io` and
`lower`. The answer cannot change - the encoding and opcode are decoded
from the words and never rewritten - so resolve it once when the
instruction is built and read the field after that.

Measured with the synthetic bench from Marvisak#1002 (no game data), sixteen
interleaved rounds per arm, best of each, nanoseconds per instruction, at
256/1k/4k/16k instructions:

  resource     17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15    (0.47-0.67)
  lower       511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428  (0.90-0.96)
  io           27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22   (0.73-0.85)
  whole       926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96)

`decode` pays the one search it used to be spared (112 -> 115 at 16k,
inside the run-to-run spread); every stage after it reads a field. The
emitted DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 24, 2026
`Instruction::words` is a `Vec<u32>` built with `collect()`, so every
decoded instruction allocates for the one to five dwords it has and reads
them back through a pointer. A counter over the pipeline put that at 1.17
allocations and 149 bytes per instruction in decode - the largest single
allocation source there.

The longest instruction the decoder produces is an MIMG with its three
extra address dwords, five in all, so keep them in `[u32; 5]` with a
length byte and return a slice from `words()`. The struct does not grow:
`Vec` is 24 bytes, the array and the byte are 24 with padding. A longer
instruction is now a clean `Isa` error rather than a silent truncation.

Measured standalone against `ffe310e` with the synthetic bench from Marvisak#1002,
twelve interleaved rounds per arm, nanoseconds per instruction:

  decode  48 -> 31,  99 -> 54, 105 -> 82, 104 -> 85        (0.55-0.82)
  whole   977 -> 934, 970 -> 921, 1001 -> 981, 1046 -> 1033 (0.949-0.988)

The emitted DXIL is byte-identical at all four sizes. Honest about the
shape: decode is 18-45% faster, the whole translation is 1-5%, and at
16k instructions that gap is inside this machine's run-to-run spread.
Applied on top of Marvisak#1002 + Marvisak#1033 + Marvisak#1180 the same change measured
0.929-0.957 of the translation.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations with -D warnings; cargo xtask policy.
nazmi pushed a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
`Instruction::name()` binary-searches the opcode table, and the pipeline
asks about every instruction eight times per translation: `ir::build`,
`structure`, `resource` (which has the most call sites), `io` and
`lower`. The answer cannot change - the encoding and opcode are decoded
from the words and never rewritten - so resolve it once when the
instruction is built and read the field after that.

Measured with the synthetic bench from Marvisak#1002 (no game data), sixteen
interleaved rounds per arm, best of each, nanoseconds per instruction, at
256/1k/4k/16k instructions:

  resource     17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15    (0.47-0.67)
  lower       511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428  (0.90-0.96)
  io           27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22   (0.73-0.85)
  whole       926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96)

`decode` pays the one search it used to be spared (112 -> 115 at 16k,
inside the run-to-run spread); every stage after it reads a field. The
emitted DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.

(cherry picked from commit 9e5c130)
(cherry picked from commit 80994e762bb3cfebeab062d4fff018712deff7f2)

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge-candidate) was for an older state of main.


Generated by Claude Code

emit/lower.rs keeps thirty tables keyed by Value, a register or a block
index, and asks them about every instruction of every program. They used
HashMap's default SipHash. structure.rs already had an Fx hasher for the
same reason ("SipHash dominated run time"), but the lowering stage, the
larger half of a translation, never got it.

Move the hasher to crate::hash and use its Map/Set in emit/lower.rs and
wave::sections. No emitted byte changes: nothing iterates these tables,
and the one order that reaches the output (user_data) is a BTreeMap.

Measured with the new emit::bench_tests (synthetic GFX10 compute programs,
no game data), ten interleaved rounds per arm, nanoseconds per instruction:

  instrs   lowering before -> after    whole translation
     256      593 -> 514  (0.867)        1002 -> 912  (0.910)
    1024      529 -> 428  (0.809)         981 -> 920  (0.938)
    4096      514 -> 430  (0.837)        1046 -> 968  (0.925)
   16384      543 -> 463  (0.853)        1068 -> 965  (0.904)

The emitted DXIL is byte-identical for all four sizes. ir::build,
structure, resource and io are unchanged, as they should be.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy: 173 files ok.
@pes7
pes7 force-pushed the perf/shader-fx-hash branch 2 times, most recently from ebdd200 to 21ff7f6 Compare November 25, 2026 11:59
The straight-line program the bench builds has a single block and no phis,
so it cannot say anything about loop handling, which every real shader
has. This adds a second shape: the same body with an `s_cmp_eq_u32` and an
`s_cbranch_scc1` back edge, so the pipeline sees three blocks and the phis
on the header.

Measured with both shapes in one session (min of six runs each, the two
tests alternating so the machine's noise hits both arms): the loop shape
costs 1.07 / 1.14 / 1.11 times the straight-line one per instruction at
256 / 1024 / 4096 instructions. 8192 is the largest body that fits: the
back edge is an `i16` of words.

So blocking, the phis and the loop header add about 10%, and `lower` and
`ir::build` stay within a few percent of their straight-line figures -
there is no large hidden cost in that part to chase.

No game data.
pes7 added a commit to pes7/VIctory that referenced this pull request Nov 25, 2026
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.

Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.

Measured with the synthetic bench in Marvisak#1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:

  ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
  translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)

gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.
@pes7

pes7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Measured on the real corpus, and the result is against this PR: the hasher change does not show up in the title's own shaders.

Setup: the full shaders.rpf of the Xbox build (26 503 containers, 26 084 programs, 40 601 701 IR instructions), victory translate <shaders.rpf> --list. The two binaries ran at the same time, one thread each (--jobs 1) on a 32-core machine, so they shared identical conditions and the difference between them is the change rather than the machine's load:

wall finish line
main 940d32f 659 s 26503 of 26503 containers (100%), 659 s
this PR 21ff7f6 657 s 26503 of 26503 containers (100%), 657 s

-0.3%, inside the noise. The two finished 2 s apart after eleven minutes of work, and the progress lines at 93% were identical to the second.

Why this differs from the bench in this PR: the #[ignore]d bench measures lower on synthetic straight-line and loop programs, where the stage is a large share of the translation and the hash tables are hot. A real program averages 1 557 instructions with loads, stores, control flow and resource analysis around it, so lower's hashing is a much smaller part of the 25 ms a program takes - small enough that -16% of it is invisible.

What the corpus does confirm, and this part is worth having on the record: the translation output is identical to main on all 26 084 programs - every count in the summary (containers, programs, structured, resources by kind, DXIL per stage, each emit:/resources: line) matches, and the only differences between the two --list outputs are the (e.g. ...) examples, which are picked by whichever thread finishes first.

So: a type swap that is neutral in practice. That is not the bar for landing here, so I am closing it rather than leaving it in the queue - the DXIL-identical measurement and the bench stay in the thread for whoever picks the hashing question up again (FIND-1 is the arena change, which is a different and larger lever). Say the word if you want it reopened with this measurement in the description instead.

@pes7 pes7 closed this Nov 25, 2026
fornorharry added a commit to NitricAcidDev/VIctory-Omega-Fork that referenced this pull request Nov 25, 2026
…ks, constants

Pull requests of fxceless/victory-gta6, each read before it was taken:
- Marvisak#1002: the tiled cascade shadow programs translate exactly on 32-lane hosts
  (f133e35efed2a48a, refused in this machine's log, is one of them);
- Marvisak#1014: the compare of copies in the card's memory hashes a piece with 64
  threads (on; VICTORY_CARD_HASH_WIDE=0: one);
- Marvisak#837: a NaN or an infinity a pixel program exports does not go into the
  colour target (on; VICTORY_NAN_GUARD=0);
- Marvisak#794: a partial texture read-back leaves the bytes beside it;
- Marvisak#1058: small buffers in place with VICTORY_COPY_PLAIN=1;
- Marvisak#799, in part: constant views of at most 64 KiB, s_pack_*_b32_b16, two
  more constant sources of descriptors;
- Marvisak#823, in part: programs that may take the wave-wide form, by hash; one by
  default (particle visibility), the others with VICTORY_WAVE_WIDE_ONLY=all.

Not taken: the rest of Marvisak#823 (the builder kills the title there), of Marvisak#799
(approximate), Marvisak#1069 (this tree notes committed pages already), Marvisak#1044
(fewer storage workers, measured on another kind of machine), Marvisak#1016 (about a
millisecond), Marvisak#827, Marvisak#854 (large; see the handoff).

AI-assisted. Not run with the title.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Marvisak pushed a commit that referenced this pull request Nov 25, 2026
ir::build fills every instruction's register lists twice. `effects()`
collects `Vec<Reg>` (two allocations), and the caller immediately maps
each one into `Vec<(Reg, Value)>` (two more), freeing the first pair. For
lists that are almost always two to four entries, that is four
allocations and two copies per instruction, on every instruction of every
program.

Have `effects()` and its helpers collect the `(Reg, Value)` pairs
directly, with the placeholder the SSA pass fills in. Two allocations per
instruction instead of four; `Inst` and everything downstream are
unchanged.

Measured with the synthetic bench in #1002 (no game data), ten
interleaved rounds per arm, nanoseconds per instruction, at 256/1k/4k/16k
instructions:

  ir::build   308 -> 269, 375 -> 324, 407 -> 340, 402 -> 353  (0.835-0.878)
  translation 898 -> 872, 898 -> 825, 951 -> 875, 956 -> 912  (0.919-0.971)

gfx10::decode, structure, lower and the rest are unchanged. The emitted
DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.

Co-authored-by: pes7 <pes7@users.noreply.github.com>
notquiteog added a commit to notquiteog/victory-nvidia that referenced this pull request Nov 26, 2026
11 files conflicted (53 hunks): draw.rs 5, host.rs 10, indirect.rs 2,
pipeline.rs 2, shader_cache.rs 2, watch.rs 22 in victory-gpu; emit/lower.rs
1, emit/mod.rs 2, emit/wave64_tests.rs 1, ir.rs 5, resource.rs 1 in
victory-shader. Most of this line was in the branch already: its shader
commits came in as pull requests (fxceless Marvisak#1002, Marvisak#1124, the far-jump exit
paths), and its renderer files are fxceless's line, merged just before.

Ours:
- crates/victory-gpu/src/host.rs, draw.rs, indirect.rs, watch.rs, whole
  files (the incoming side: PR Marvisak#1014's 64-thread card hash, a 128-bit key
  for draws' fresh tables, fxceless's write watch; no measurement on our
  threading, and the card compare's HLSL stays unmixed).
- crates/victory-gpu/src/pipeline.rs (the builder's missing pipelines
  named by our make::hashes).
- crates/victory-shader/src/ir.rs, whole file (both sides give a spill
  lane's lives stores of their own; ours is the form the branch has run
  with, the incoming site_webs is the same fix another way).
- crates/victory-shader/src/emit/lower.rs, emit/shader.rs, and the early
  depth part of emit/mod.rs: our early_depth (DEPTH_BEFORE_SHADER, not for
  programs that export depth, stencil or coverage; VICTORY_EARLY_DEPTH) is
  kept and the incoming one (VICTORY_EARLY_Z) removed: two declarations of
  the same flag.
- crates/victory-shader/src/resource.rs, emit/wave64_tests.rs.

Incoming side, combined into ours:
- crates/victory-gpu/src/shader_cache.rs and emit/mod.rs: the wave-wide
  form and the host wave's own first lane for programs listed by hash
  (VICTORY_WAVE_WIDE_ONLY, VICTORY_FIRSTLANE_OWN_ONLY; defaults: four
  compute programs a 32-lane driver refused, three structure-builder
  programs; mravatins 64ffcc0, on RTX 5060 Ti / 5070). The two lists are
  part of the shader cache key, so the cache is translated anew once. Our
  last-resort wave-wide form is unchanged.

Not taken: docs/nvidia-render-baseline.md, scripts/play-nvidia.ps1 (docs
and scripts stay ours; the script starts the game).

Builds: cargo build -j 6 --locked --profile diag -p victory --features
diagnostics. Not run in game.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
iLucasRT pushed a commit to iLucasRT/VInAMD that referenced this pull request Nov 26, 2026
`Instruction::name()` binary-searches the opcode table, and the pipeline
asks about every instruction eight times per translation: `ir::build`,
`structure`, `resource` (which has the most call sites), `io` and
`lower`. The answer cannot change - the encoding and opcode are decoded
from the words and never rewritten - so resolve it once when the
instruction is built and read the field after that.

Measured with the synthetic bench from Marvisak#1002 (no game data), sixteen
interleaved rounds per arm, best of each, nanoseconds per instruction, at
256/1k/4k/16k instructions:

  resource     17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15    (0.47-0.67)
  lower       511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428  (0.90-0.96)
  io           27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22   (0.73-0.85)
  whole       926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96)

`decode` pays the one search it used to be spared (112 -> 115 at 16k,
inside the run-to-run spread); every stage after it reads a field. The
emitted DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.

(cherry picked from commit 146dfef)
Xeltax added a commit to Xeltax/VIcky that referenced this pull request Nov 26, 2026
…ped views, typed offsets refused, fork Marvisak#1002's site pairs

W1a (VICTORY_STORE_DROP=f133e35e:2957c) brought the heads back with the
stairs still gone: what costs them is the one typed-buffer
read-modify-write of CS_ShadowRenderTiledCascadesAlphaCBPPPC (#f133e35e)
at 0x2957c. Its first lane reads the word of its tile in the third
quarter of u17 (table 0x780; 230,400 bytes in W1a's frame 2040, four
words per 16x16 tile of 2560x1440), sets bit 14 and writes the word back.
Each switch below can A/B one cause with the program running in full:

- VICTORY_TYPED_BIT_EXACT=1 (host): typed buffer views of 32-bit integer
  formats are made in the float format of the same width. Translated
  programs declare typed loads and stores as float, and through an
  integer view a store writes the integer the float rounds to (0 for
  most integer bit patterns), where the console moves the bits: the
  read-modify-write would leave 0 for the tile's other flags. From
  GamingRipperDoc's fix in the fork (Marvisak#684, bit_exact_format).
- VICTORY_TYPED_OFFSET=refuse (translator, global): a typed buffer load
  or store whose soffset or built descriptor base is not known to be 0
  is refused instead of going to element `index` from the view's start.
  As RVZO6's VIctory Marvisak#3009 for stores, and for loads with a constant
  offset. Folding the offset into the index is not done: the element's
  size is the host view format's, which the translated program does not
  see. #f133e35e is not concerned: its six typed accesses have soffset
  0, offset 0 and a table descriptor.
- VICTORY_WAVE_SITE_PAIRS=<hash>,...|all (translator, per program, in
  the program's cache key): fork Marvisak#1002's IR forms (brunofgmag,
  eaeb8f17): a pair of scalars parked in two lanes that hold other
  scalars elsewhere moves as a pair where every save and restore of it
  match (WebPair, site_pairs), `s_cbranch_execnz` over a far jump to the
  end is an early-out, and a scalar join that passes one value through
  is a copy of it. With them #f133e35e and its siblings translate
  exactly on 32-lane hosts without the mask copies. ir.rs as in the PR
  (it applied cleanly), each form gated; its card-free tests ported to
  wave64_tests.rs, on and off.

Op dumps now print a buffer or texture UAV's title view description (its
DXGI format first), to tell an integer typed view.

Co-Authored-By: Bruno Magalhães <19572425+brunofgmag@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A4bpLmErkufJL3LGgfR561
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.

3 participants