Repository navigation
Reuse one CPU read buffer for watched textures - #215
tcurtsinger wants to merge 3 commits into
Conversation
…s) into the integration Folds the branch's own READ thread-local into the PR's with_tiled_copy (SCRATCH), keeping the branch's drop of one-off reads over 64 MiB and the staging budget/eviction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
Thanks @tcurtsinger for covering both reuse of the watched-texture read buffer and stale data from unmapped pages. I tested commit Both tests passed (1 passed, 0 failed; 45 filtered for each):
These tests cover the CPU-side tiled-copy buffer and unmapped-page handling. They do not exercise texture upload through a rendered title or GPU sampling. |
|
I opened #495 with the same change before seeing this one; it is a duplicate of #215 and I am closing it in favour of this one. One thing from it may be worth taking, since this PR has the tests. When the host runs out of Windows commit, #495 reserved with let mut read = READ.take();
read.clear();
if read.try_reserve_exact(size).is_err() {
once!(size, "no room to read a texture's memory; not uploaded");
READ.set(read);
return 0;
}
last.asked = now;I did not test that failure branch under real memory pressure. With the equivalent change here (and a larger pagefile at the same time), process private memory stayed flat at about 21 to 22 GB over a 20-minute run. AI-assisted (Claude Code). |
|
Thanks for the report in #495. The scratch buffer now grows with I verified this on Windows D3D12 WARP with a test allocator that refused a 2 MiB request on the first refresh and again on a later update. After each refusal, the same-size refresh succeeded and produced the expected pixels with no new title writes. The committed regression also covers a clean refresh after recovery. This measures the allocation failure path. The effect during a low-memory game session remains unmeasured. Regression test AI-assisted implementation and testing. |
A watched texture kept a second CPU copy of its tiled pixels in
Last::readfor as long as its staging resource lived. The upload only needs those bytes while it detiles. This change reuses one buffer per submitting thread. Each texture keeps its own upload buffer and write-watch timestamp. If the scratch buffer cannot grow, the refresh keeps the previous staging contents and retries on a later submission.Memory measurement
I refreshed 32 synthetic 1024 × 512 RGBA8 textures on one thread using Windows 11 and D3D12 WARP. Each texture occupied 2 MiB in write-watched memory. I pre-touched the source and mapped upload buffers, kept all 32 textures alive, and measured the increase in process private bytes across their first refresh. Each revision ran in three fresh processes.
d2a4bae)0f7052e)All 32 uploads had their expected pixel values. A second refresh read zero bytes for each clean texture. After I rewrote one texture, it refreshed and the other 31 kept their pixels. The measurement covers synthetic uploads.
The native Windows 11 run on our RTX 4080 reached the first mission at 1–2 FPS. The sampled peaks on
d2a4baewere 22.74 GiB of private commit and 13.87 GiB resident. With this change alone they were 22.44 GiB and 13.37 GiB. Both runs ended withDXGI_ERROR_DEVICE_HUNG. Scene timing and sampling intervals differed, so the size of any whole-game memory or frame-time improvement remains uncertain. Baseline result · Subsequent combined test.Checks
440738ethe Windows workspace passed 345 tests with default features and 349 with diagnostics. Six were ignored in each run. The two workspace Clippy configurations passed with warnings denied. The asset policy, diff check and rustfmt on the changed file passed.At the current head of #143 (
525a713), a test merge finds one conflict at the thread-local buffer declaration. Its unwatched path calls the bufferUNWATCHED_SCRATCH. Both paths can use one allocation by keepingSCRATCHand using that name in the unwatched path when the changes are combined. Related PR #143