perf(formats): hoist XOR texture row/column terms and merge low-bit column runs #251
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!251
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-251"
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?
@Sheffy007 on GitHub · 2026-11-27 05:04 UTC · original
Sheffy007:perf/xor-texture-detile→main· +244 −7 · 3 files · 1 commits · merged 2026-11-27 10:37 UTCSummary
Speeds up
victory_formats::texture::Layout::detileandLayout::tileon XOR swizzle modes (SW_4KB_*_X,SW_64KB_*_X,SW_64KB_*_T), reducing world texture-sync CPU work (#179, #15):Layout::walkpreviously calledxor_addressper element, recomputingy / bh * (pitch / bw),xor.y,xor.z, andpipe_bankfor every columnx. It now precomputes each column's block byte offset andxor.xonce per subresource and computesrow_baseandyz_xoronce per(z, y).1..=32B): Address bits below every bit touched byy,z, orpipe_bankare never flipped byyz_xor, so adjacent columns that advance monotonically inside those low bits (e.g. 16 x 1 B, 8 x 2 B, 4 x 4 B, or 2 x 8 B elements in a 16-byte micro-run) are merged into single compile-time-sized copies (copy_xor_runs::<N>), matching the non-XORcopy_runs::<N>path.cargo test --release -p victory-formats xor_detile_throughput -- --ignored --nocapture), a2048x2048SW_64KB_S_Xdetileruns in ~1.27 ms at 4 B/element and ~5.58 ms at 16 B/element.Verification
modes_are_bijections_and_copies_round_trip,the_pipe_bank_xor_flips_the_pipe_and_bank_bits).partial_xor_runs_with_pipe_bank_xor_round_trip_every_element_size(non-multiple widths + mip tails + non-zeropipe_bankacross1, 2, 4, 8, 16B/element) and ignored benchmarkxor_detile_throughput.cargo test -p victory-formats -p victory-gpu -p victory-metal -p victory-shader -p victory-hle -p victory -p xtaskcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policy@evan-kolberg on GitHub · 2026-11-27 05:12 UTC · original
I ran a paired M4 Pro baseline with Codex using Sheffy007’s existing release benchmark. Both builds detiled the same generated 2048×2048
SW_64KB_S_Xtexture. Each result is the median of eight paired batches, with 20 detiles per batch and parent/head order alternating. Direct parent775712ad· Tested head6db66ea1· Authored benchmarkThe byte comparison used a separate nonconstant generated input on the same layout. The timings cover full CPU detile only.
@LakshanSivakumar on GitHub · 2026-11-27 05:41 UTC · original
The measured speed-up and the byte-identical output in the comment above are convincing. One request before merge: the committed tests are round trips, and tile and detile share the new
walk, so a symmetric mistake would still pass. Please add a test that compareswalkagainst the per-elementxor_addressresult across the modes, then rebase on main.6db66ea1f3to65a60fe177@Sheffy007 on GitHub · 2026-11-27 06:22 UTC · original
Rebased onto
main(2a3b03d) and addedtexture::xor_tests::walk_matches_per_element_xor_address_across_modes, which drivesLayout::walkdirectly and verifies every visited linear byte against the per-elementLayout::xor_addressacross all 8 addressable_X/_Tmodes, element byte widths1..=16, 2D array slices and 3D depth layouts, mip chains (including tail mips), two pipe configurations, and non-zero pipe-bank XOR.@LakshanSivakumar on GitHub · 2026-11-27 06:48 UTC · original
Thank you. This is the test I asked for: it compares
walkagainstxor_addressper element, so a symmetric mistake in tile and detile can no longer pass.One difference between the text and the test. The text says element widths
1..=16, but the loop uses1 << e, which is 1, 2, 4, 8 and 16 only. Can an_Xor_Ttexture have an element width of 3, 6 or 12 bytes? If it can, please add those widths; if not, please change the text to say powers of two.65a60fe177to87861b11ba@Sheffy007 on GitHub · 2026-11-27 09:39 UTC · original
Good catch —
_Xand_Ttextures cannot have element byte widths of3,6, or12: RDNA2Addr2swizzle tables are indexed byelement_log2(0..=4), andLayout::new_for(crates/victory-formats/src/texture.rs:437-438) rejects any non-power-of-twoelement_bytes(!d.element_bytes.is_power_of_two() || d.element_bytes > 16, with 96-bitR32G32B32formats restricted to linear layouts).Updated the doc-comment on
walk_matches_per_element_xor_address_across_modesto say power-of-two element byte widths (1, 2, 4, 8, 16), added explicitErr(Error::Invalid)assertions for[3, 6, 12]acrossXOR_MODES, and rebased ontomain(c1b95875).@LakshanSivakumar on GitHub · 2026-11-27 10:37 UTC · original
Thank you. That answers my question: 3, 6 and 12 cannot occur, and the test now shows the error for them. CI is green and it is rebased.
I have no further points. It still needs my own merge. I have not run it; I rely on evan-kolberg's paired timings and the identical output he reported.
Merged.