Repository navigation
D3D12-GPU-TEXBACK-REUSE-BEFORE: reuse thread-local before buffer in texback::write - #2696
Conversation
|
Independent synthetic Windows check on The eight checked-in tests passed. I also added a temporary synthetic fixture that landed 3, 1, 4, 2 and 1 pages in succession on the same worker. It changed small regions in selected first/interior/last pages, used two unchanged copies, and checked the production written-byte counter as well as final bytes and guard regions. It observed 4, 0, 8, 8 and 0 KiB written. All nine cases passed with AI-assisted. |
|
Independent Wine allocation check. I merged
CPU-only synthetic readbacks. AI-assisted with OpenAI Codex. |
…ite (D3D12-GPU-TEXBACK-REUSE-BEFORE) texback::write() already kept a thread-local TILED buffer (capped at 32 MiB) to avoid per-landing heap allocations, but still allocated and freed a fresh `let mut before = Vec::new()` on every LEONIDA_COPY_BACK read-back (~22/frame in gameplay) to diff 4 KiB pages. Pair `before` with `tiled` in a single thread-local SCRATCH `(Vec<u8>, Vec<u8>)` (both capped at KEPT = 32 MiB) so copy read-backs reuse their snapshot buffer without repeated multi-MB allocations/page faults. AI-assisted: Antigravity (Gemini 4 Neon)
e9e9e2b to
7305728
Compare
|
Independent check on Windows (not the author), at
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned. AI-assisted: yes (opencode). |
Concurrent writeback and late ticket invalidation on the current headMEASURED. I tested Two workers call production All 12 fresh-process runs agreed (three per tree and The stock |
|
RUN - VERIFY-2696-RTX4060 - by MoonEyes (another person than the author) on head
Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data. AI-assisted (Claude Code). |
|
Merging. Head AI-assisted (Claude Code). |
Problem
In
d3d12/crates/leonida-gpu/src/texback.rs,write()already keeps a thread-localTILEDbuffer (capped atKEPT = 32 MiB) to avoid allocating and freeing a multi-MBVec<u8>on every texture read-back. However, line 451 still created a freshlet mut before = Vec::new()on every call, so everyLEONIDA_COPY_BACKread-back (~22/frame in gameplay) allocated, page-faulted, and freed a full texture-sized snapshot buffer just to runchanged_pages().Fix
TILED: RefCell<Vec<u8>>withSCRATCH: RefCell<(Vec<u8>, Vec<u8>)>holding both the tiled destination buffer and thebeforepre-tile snapshot buffer, capping both atKEPT = 32 MiB.copy_readbacks_write_changed_pages_across_reused_scratchverifying repeatedcopy = truelandings write only changed 4 KiB pages across reused scratch storage.Verification
10.0.26200), Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX (gfx1100), pinnedrustc 1.98.1.cargo test -p leonida-gpu --lib texback: 8 passed, 0 failed.python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/texback.rs: PASS.Claimed in #2570 as
D3D12-GPU-TEXBACK-REUSE-BEFORE.AI-assisted: Antigravity (Gemini 4 Neon)