D3D12-GPU-CHANGED-RECORDS-AVX2: add AVX2 fast path for 32-byte descriptor changed_records #2689
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2689"
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 ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-30T02:48:25Z.
Claimed in #2570 as
D3D12-GPU-CHANGED-RECORDS-AVX2(#issuecomment-7267296583).What and why
In
d3d12/crates/leonida-gpu/src/descriptor/host.rs,changed_records()scans ~400,000 console descriptor slots (32 bytes each) and mirrors ~40,000 changed slots per frame (d3d12/docs/findings.md). Previously, whenever any 1 of 16 records in a 512-byte chunk differed,changed_records()ranmemcmpon the 512-byte chunk and then re-scanned all 16 records with 16 individualmemcmp+memcpycalls.This change adds a runtime-detected AVX2 fast path (
std::arch::is_x86_feature_detected!("avx2")) forstep == 32:ymmregisters.vpcmpeqbresults withvpandinto a singlevpmovmskb == -1fast-path branch.newymmregister directly with_mm256_storeu_si256(zero second load, zeromemcmp/memcpycalls).changed_records_scalar()on non-AVX2 CPUs or non-32-byte record strides.Verification & Measured
--releaseA/B BenchmarkHardware / OS: native Windows 11 Pro (
10.0.26200), AMD Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX (gfx1100), pinned toolchainrustc 1.98.1.cargo test --release -p leonida-gpu --lib changed_records_bench -- --ignored --nocapture(400,000 × 32 B slots, 50 rounds, bit-exact parity asserted every round):325.9 µs → 309.8 µs/frame(1.05×)432.5 µs → 325.9 µs/frame(1.33×)611.3 µs → 485.1 µs/frame(1.26×)cargo test -p leonida-gpu --lib descriptor::host -- --test-threads=4—53 passed; 0 failed; 2 ignored(0.48s).python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/descriptor/host.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-30T03:27:40Z.
Independent Windows 10 AVX2 check on
ebaa9ec8377dbad29146d2977a920df4ac3b921amerged locally into1d22590b9fb5c0f51a6a7c0405f1f136e0696c0d. Ryzen 9 5950X, Windows 10 22H2 build 19045, Rust 1.98.1 MSVC.changed_recordsparity test passed under--profile diag --features diagnostics. The checked-in ignored benchmark also ran successfully, with 1.22×, 1.70× and 1.65× speedups at 0%, 10% and 100% changed records.opt-level=3. It alternated execution order each round, used the median of 60 rounds per pattern, and verified both output indices and resulting buffers every round. At about 10% changed, the speedup ranges across three fresh processes were 1.17–1.20× periodic, 1.06–1.07× pseudorandom, and 1.21–1.28× for runs of 32 adjacent records. All runs used 400,000 synthetic 32-byte records.CPU microbenchmarks and synthetic data only.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:58:14Z.
Independent check on Windows (not the author), at
08a1cc4a0.cargo testsuite running): 562 passed, 1 failed —descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync,descriptor.rs:2260: assertion failed: host.made(5).mainb17b22d33alone: 570 passed, 0 failed.The same failure appeared for #2701 (which does not touch descriptors) under the same concurrent-load condition, so it looks like a load-sensitive write-watch test rather than this PR's AVX2 path. I reported that separately as a suite finding.
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T17:20:39Z.
Bit-exact CPU composition with the shadow AVX2 paths in #2699
MEASURED. I tested #2689
08a1cc4a0and #269945d09e2d9, separately and together, onmain1d4949d58(combined tree43bb79955). The two tested source files are identical in the corresponding clean merges onad25611b5. Rust 1.98.1, Ryzen 7 7800X3D, optimized native Linux and Windows x64 (Wine 11.22) builds.The standalone fixture extracts
merge_piece,back_piece,changed_runs,changed_records, and their helpers from each tree. It feeds synthetic merge and readback outputs into the record detector and compares against a bytewise reference. The 3,600 cases check 16- and 32-byte records, incomplete trailing records, unaligned slices, overlapping CPU/GPU changes, exact changed ranges and slot IDs, guard bytes, and a repeated publication with no new changes.All 30 runs produced the same 6,955,200 output bytes. That is three runs per platform for
main, each PR alone, both PRs with default dispatch, and both PRs forced to scalar. The combined default runs exercised all four AVX2 paths. The test-only gate recorded zero AVX2 selections in the forced-scalar runs.Scope: synthetic CPU function composition and output parity. AI-assisted: Codex (GPT-6.2 Sol).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T08:33:42Z.
RUN - VERIFY-2689-RTX4060 - by MoonEyes (another person than the author) on head
08a1cc4a0, with #2836, #2835, #2695, #2696, #2689, #2699 and #2705 merged together intomain9372a4d4f(clean).main9372a4d4fand thenmain+ the seven, one run each, same save: 0 device lost, 0 panics, 0 exceptions in both, about 490 s in the world each, alive at the time limit. Frame rate median 17.8 with the seven and 15.0 onmain, not a comparison: other work ran on the PC during themainrun.main9372a4d4f+ the seven (Windows): leonida-hle 243, leonida-gpu 602, leonida-formats 47, leonida 47, leonida-shader 403 of 405: twosource_hash_testsfailed on a stale build script of mine (a target folder shared with an older branch) and pass after a rebuild of it (3 of 3).Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T10:07:48Z.
Merging. Head
08a1cc4a0merges cleanly withmain3393ceec9and does not force a rebase of #2566. CI green on this head and on main. In-game run on the RTX 4060 posted above (this head, with the six others, about 490 s in the world, 0 device lost, pictures compared with main). Tests on main + the seven: leonida-hle, leonida-gpu, leonida-formats, leonida, leonida-shader, 0 failed. Verified on it by KelboLive (Windows) and merzleckeier (bit-exact with #2699). Merged by MoonEyes.AI-assisted (Claude Code).