Repository navigation
d3d12: the title-texture upload ring gives back large idle buffers, and counts as staging (RT-TITLE-UPLOAD-TRIM) - #2463
Conversation
…nd counts as staging TitleImageUpload's four slots each grew to the largest whole-image upload that went through them and kept that host-visible buffer (system RAM on a discrete GPU) until the device was destroyed, so after a burst of large textures up to four of the largest stayed allocated. The periodic title-texture pass now calls trim(), which, under a try_lock and without waiting for the GPU, releases a slot over LEONIDA_TITLE_UPLOAD_KEEP_MB (default 4) that has been idle for LEONIDA_TITLE_UPLOAD_IDLE_MS (default 2000; 0 keeps the old behaviour) once its last transfer's timeline value is reached. The rule is src/title_upload_trim.h, tested by title_upload_trim_test. The ring's allocations now run under a memory_breakdown staging owner, so the mem probe's breakdown line shows them as staging instead of other, and its texture line says how many buffers were released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
|
Native Windows check on I also measured the ring through the production refresh path on Windows 11, RTX 4090, NVIDIA 616.64. I adapted the test's mapped-plane fixture locally to upload four 4096×2048 R8 textures, each filled with a different byte. I disabled host image copy on the test device to exercise staging. Each copy completed and its full 8 MiB readback matched before the next upload. After 10.5 s idle, an empty queue submission triggered the next refresh and let the regular memory probe print the counters.
A fifth 8 MiB upload with a new fill byte passed full GPU readback in both processes. Khronos validation was enabled and reported zero errors. This checks retention, release and reuse of the staging ring with synthetic textures. The 32 MiB is the ring-capacity difference for this fixture. |
lixonik
left a comment
There was a problem hiding this comment.
Reviewed and tested at d14a81479 (merged cleanly onto main ec91d695c).
The trim policy header (runtime/src/title_upload_trim.h), non-blocking timeline check in transfer_done(), atomic capacity() / trimmed() counters, and Consumer::staging accounting are clean and pass CPU and GPU tests. Two notes inline:
- Small uploads on the round-robin ring can keep oversized slots alive indefinitely:
write()rotatesslots_round-robin and stampsslot.last_used_ns = now_ns()on every upload regardless of size, so steady small uploads (<= 4 MiB) every ~0.5 s keep resettinglast_used_nson all 4 oversized slots and preventtrim()from reclaiming them. - Minor portability note: sibling
std::getenv(...)calls in one argument list intrim().
Verified locally on Windows 11 (MSVC 19.44.35230.0, Ninja Release, NVIDIA GeForce RTX 5070, driver 610.88, Vulkan 1.4.341; note VK_LAYER_KHRONOS_validation is not installed locally so Vulkan validation layers did not run):
title_upload_trim(CPU): passedd3d12_existing_heapandd3d12_host_prefix(GPU): 2/2 passedscripts/check_no_game_data.pyandgit diff --check: clean
AI-assisted.
|
Independent Linux/Wine + NVIDIA check at head
AI-assisted. |
…he trim settings with owned copies Review of ProjectLeonida#2463 by lixonik: - write() stamped a slot's last use on every upload, so steady small uploads going round the ring kept every slot's large buffer from a burst alive for ever. Only an upload over LEONIDA_TITLE_UPLOAD_KEEP_MB stamps it now (title_upload_trim::counts_as_use): a small one fits the buffer trim() leaves behind. - The two variables were read by sibling std::getenv calls, whose results may share a buffer, and the Windows CRT deprecates getenv. title_upload_trim::settings_from_env copies each value (_dupenv_s on Windows). title_upload_trim_test covers both: small uploads every 0.5 s after a large one no longer keep the slot, and both variables are read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
|
@lixonik thanks, both were right. Changed by Claude Code (AI-assisted) in 07326df:
Tested: Linux @ecox982745 @djrolfes the change is small but it touches what you measured: a re-run of your adapted fixture on Generated by Claude Code |
|
Note on #2464, which came out after this PR: it lists Generated by Claude Code |
lixonik
left a comment
There was a problem hiding this comment.
Re-reviewed 07326dfb8 and re-tested:
- Both earlier comments are cleanly addressed:
write()now only updatesslot.last_used_nswhentitle_upload_trim::counts_as_use(bytes, trim_settings())is true (bytes > keep_bytes), so steady small uploads rotating through the ring no longer keep oversized buffers alive indefinitely while in-flight transfers remain protected by the timeline semaphore check intrim().title_upload_trim::settings_from_env()reads both environment variables viaenv_copy()(_dupenv_son Windows, ownedstd::stringcopy on POSIX), avoiding siblingstd::getenvpointer aliasing and MSVC C4996 warnings.
- Tested on NVIDIA GeForce RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341, MSVC 19.44;
VK_LAYER_KHRONOS_validationnot installed locally):title_upload_trim: passed (0.02 s).d3d12_mapped_plane_async: passed (0.21 s).
Looks good to merge (maintainers can weigh overlap with #2464 perf work on d3d12_title_image_upload.h).
AI-assisted (Antigravity, Gemini).
|
Reviewed at head Verification
Notes (non-blocking)
Approve. AI-assisted review + local MSVC verification. |
Claimed in the coordination issue as: RT-TITLE-UPLOAD-TRIM
Overlaps #2021 (the same header, a different change): the two conflict only in
runtime/CMakeLists.txt, whereeach registers a test; whichever lands second keeps both lines.
What and why
TitleImageUpload(runtime/shims/d3d12_title_image_upload.h) is a ring of four slots. Each slot grew to thelargest whole-image upload that went through it and kept that buffer until the device was destroyed. The buffers
are host-visible, so on a discrete GPU they are system RAM: after a burst of large textures (a cutscene's, say)
up to four of the largest stayed allocated for the rest of the run. The ring's memory was also not named in the
mem probe, so it showed up as
other.trim(), called from the periodic title-texture pass (refresh_title_textures) under atry_lock, frees aslot whose buffer is over
LEONIDA_TITLE_UPLOAD_KEEP_MB(4) and that has not been used forLEONIDA_TITLE_UPLOAD_IDLE_MS(2000), once its last transfer has completed. Completion is read withvkGetSemaphoreCounterValue; the pass never waits for the GPU, and a slot whose value can't be read stays.LEONIDA_TITLE_UPLOAD_IDLE_MS=0keeps the old behaviour, for A/B runs.memory_breakdownstaging owner, so[rt] mem-probe breakdownshows it as staging.The
registered image backingline now also says how many buffers were released.runtime/src/title_upload_trim.h, tested bytitle_upload_trim_test: idle limit and size floor,a transfer still running, an empty slot, a clock read before the last use, 0 = off, malformed and huge values.
runtime/README.mdanddocs/d3d12_vulkan.mddescribe the two variables.Tested
ctest117 of 117, with the new test.trim()andcapacity()on a fakedevice (
-Wall -Wextra, no warnings from these files).1,091 targets, including
d3d12_vulkan_device.cpp. Its tests under Wine 9.0 with Xvfb on Mesa lavapipe: 464 of490 pass; the 26 that fail fail the same way on main (checked by building main's two files in the same tree).
LEONIDA_MEM_PROBE=1through acutscene and after it, with
LEONIDA_TITLE_UPLOAD_IDLE_MS=0and with the default, comparing thestagingpartof the breakdown line and the buffer size on the
registered image backingline.AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly.docs/design.md. (n/a: no translator change)🤖 Generated with Claude Code