GPU: AVX2 fast-path and skip-unchanged writes in merge_gpu_writes* #123
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!123
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-123"
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?
@altuux on GitHub · 2026-11-25 14:56 UTC · original
altuux:perf/avx2-merge-gpu-writes→main· +428 −6 · 1 files · 3 commits · openSummary
Optimizes
merge_gpu_writes,merge_gpu_writes_mut, andmerge_gpu_writes_cardincrates/victory-gpu/src/shadow.rs:merge_gpu_writesandmerge_gpu_writes_mutunconditionally copiedtitleback intohost(andold) wheneverhw == ow, even whentitle == host, dirtying cachelines and mapped D3D12 buffers unnecessarily. Added thetw != hwcheck to the scalar fallback (matchingmerge_gpu_writes_card) and a zero-write fast path whenhost == old == title.is_x86_feature_detected!("avx2")dispatch and the existingu64scalar fallback preserved (zero new dependencies). Uses_mm256_cmpeq_epi8+_mm256_blendv_epi8and computes the tight[first, last)span viatrailing_zeros/leading_zeros.merge_gpu_writes_matches_scalar_across_lengths_and_patternsverifying bit-for-bit agreement between scalar and AVX2 paths across unaligned lengths (0..4096) and all CPU/GPU write combinations (including overlapping CPU+GPU writes to the same byte).Synthetic CPU Benchmark (i5-12400, 64 MiB = 1024 × 64 KiB tiles, 5% GPU-modified)
merge_gpu_writes_mut: 15.61 ms → 9.16 ms (1.70× faster, 4.00 → 6.82 GB/s)merge_gpu_writes_card: 13.23 ms → 9.29 ms (1.42× faster, 4.72 → 6.73 GB/s)On mapped Write-Combined D3D12 memory, avoiding redundant writes on unchanged chunks should save additional bandwidth on top of the cached-RAM benchmark above.
legacy is merge_gpu_writes{,_mut} as on main (every unchanged word written back to the copy), scalar skips unchanged words without AVX2, unset takes AVX2 when the processor has it. The test now also compares with the code from main. Co-Authored-By: Claude Opus 5.5 <[email protected]>@sil-kong on GitHub · 2026-11-25 15:02 UTC · original
Tested on Linux (Arch, RX 7900 XT with RADV, Ryzen 9 5900X, GE-Proton10-34's Wine + vkd3d-proton), Belobug main at
01aadd1with this PR applied on top, release build, same save and same spot, warm caches, mean of 8 world frames:The whole frame gains more than the copy-back itself, so not writing unchanged words back seems to spare work in the next submission's copies too. No new rendering problem seen at that spot.
@jmal423 on GitHub · 2026-11-25 16:41 UTC · original
Tested this PR on Windows 11 / AMD Radeon RX 9070 XT (Series X target):
With this PR applied, all prison/corridor walls disappear (likely due to a skipped/mis-merged GPU culling buffer write). Reverting this PR immediately restores all walls.
@altuux on GitHub · 2026-11-25 18:25 UTC · original
@jmal423 Thanks for testing! I couldn't reproduce a difference in the merge logic itself: a 200k-case randomized comparison against the pre-PR functions from
maingives byte-identical results, so if this PR causes it, it's the skipped (redundant) writes to the mapped copy rather than the AVX2 math.I pushed a switch to narrow it down (
cad3975) — could you try the same spot with each of these?VICTORY_MERGE=legacy— exact pre-PR codeVICTORY_MERGE=scalar— skip-unchanged without AVX2Also: which base commit did you apply it on, and do you have any other
VICTORY_*set (especiallyVICTORY_ASYNC_SUBMIT)?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.