d3d12: the title-texture upload ring gives back large idle buffers, and counts as staging (RT-TITLE-UPLOAD-TRIM) #2463
Closed
leonida/mandy
kawaii-shakal wants to merge 0 commits from
title-upload-staging-trim into main
pull from: title-upload-staging-trim
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2463
Loading…
Reference in a new issue
No description provided.
Delete branch "title-upload-staging-trim"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
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
Native Windows check on
d14a81479. The Windows-onlyd3d12_vulkan_device.cppcompiled with MSVC 19.44 andgta6rt.exelinked in Release. The stocktitle_upload_trimCPU test andd3d12_mapped_plane_asyncRTX 4090 test both passed.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.
LEONIDA_TITLE_UPLOAD_IDLE_MS=0A 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.
Independent Linux/Wine + NVIDIA check at head
d14a81479(merged cleanly ontoorigin/mainec91d695cin a local integration stack alongside#2467,#2470,#2469,#2461,#2126,#2091, and two local V# patches).7.2.15,wine-11.22,clang-cl+xwincross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver620.73.04, Ryzen 7 5800X, 32 GB RAM. No game files.gta6rtandtitle_upload_trim_testcross-compiled cleanly withclang-cl+xwin;title_upload_trimpassed (4.39 s) under Wine.capacity()/trimmed()counters and non-blockingvkGetSemaphoreCounterValuecheck intransfer_done()before releasing idle slots look clean.AI-assisted.
@lixonik thanks, both were right. Changed by Claude Code (AI-assisted) in 07326dfb:
write()no longer stamps a slot on every upload. Only an upload overLEONIDA_TITLE_UPLOAD_KEEP_MBcounts(
title_upload_trim::counts_as_use), so small uploads going round the ring no longer keep a large buffer froma burst alive; a small one fits the buffer
trim()leaves behind.title_upload_trim_testhas the case youdescribed: 1 MiB uploads every 0.5 s after a 64 MiB one, and the slot is released 2 s after the large one.
title_upload_trim::settings_from_env, which copies each value before the next read(
_dupenv_son Windows, so the CRT's getenv deprecation warning is gone too).Tested: Linux
ctest117/117; Windows build cross-compiled with clang-cl 21 and xwin (gta6rt,title_upload_trim_test), the test passing under Wine 9.0.@ecox982745 @djrolfes the change is small but it touches what you measured: a re-run of your adapted fixture on
this head would confirm the four buffers still go.
Generated by Claude Code
Note on #2464, which came out after this PR: it lists
runtime/shims/d3d12_title_image_upload.hamong the filesthe performance rewrite owns. @aslan2142 if the rewrite covers the upload ring, feel free to close this or take
the change into it; the rule and its test (
src/title_upload_trim.h,title_upload_trim_test) are separate filesand can move as they are. The measured effect is in ecox982745's comment above.
Generated by Claude Code
Re-reviewed
07326dfb8and re-tested: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.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
07326dfb8on Windows 11 (MSVC 202219.44).Verification
title_upload_trim_testandgta6rt.title_upload_trim_test: ok.Notes (non-blocking)
d3d12_title_image_upload.h:93-98,160-299;title_upload_trim.h:53-77;d3d12_vulkan_device.cpp:15661-15668) all look solid.d3d12_title_image_upload.h:37-47,160-172;title_upload_trim.h:80-85): The periodic trim evaluatestransfer_done(d, slot)(pollingvkGetSemaphoreCounterValue) for every non-empty slot even when size/age already disqualify it. Checking size and age first — and querying the shared timeline at most once if any candidate qualifies — avoids redundant Vulkan calls under both locks during steady small uploads.Approve.
AI-assisted review + local MSVC verification.
#2463 | head c9e75ba74a80f77dd399076cf26ce93a63b0083a (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current
main) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(title_upload_trim|memory_breakdown|d3d12_mapped_plane_async)$" --output-on-failure(LEONIDA_VK_VALIDATION=1,LEONIDA_MEM_PROBE=1,LEONIDA_FSDRAW_PROBE=1,LEONIDA_TITLE_UPLOAD_IDLE_MS=1,LEONIDA_TITLE_UPLOAD_KEEP_MB=0) | red mutation: forcingtitle_upload_trim::release()inruntime/src/title_upload_trim.htoreturn falsefailstitle_upload_trimatline 33: tt::release(64 * kMiB, t0, t0 + 2000 * kMs, true, s)| green on PR+main:3/3CTests (title_upload_trim,memory_breakdown, andd3d12_mapped_plane_asynclogging[rt] mem-probe: registered image backing: ... staged fills 1, 0.001 s, buffer 0.0 MiB (0 released idle)) pass in1.02 son RTX 3090 with0Khronos validation errors;test_docs_encoding.py&test_docs_repo_paths.py(6/6 OK) andcheck_no_game_data.py(0violations) pass | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesThanks, both addressed in 15531782:
runtime/test/title_upload_ring_trim_test.cppdrivesTitleImageUpload::trimitself over a fake device whosevkGetSemaphoreCounterValue,vkDestroyBufferandvkFreeMemorycount their calls (a test-only friend seeds a submitted slot). With the counter below the slot's ticket the first trim keeps the buffer andcapacity(); with it at the ticket the second frees buffer and memory exactly once,capacity()drops to 0 andtrimmed()is 1, and a third frees nothing. A counter read that fails (VK_ERROR_DEVICE_LOST) or a missing entry point keeps the buffer, and each slot goes by its own ticket.trim()now checks size and age first, so a slot they keep costs no counter read under the locks; the test counts the reads.Built with clang-cl 21 + xwin (the flags the CMake target gets) and run under Wine: 3/3 pass; with the
reached < slot.valuecomparison removed fromtransfer_done()it fails 3/3 at the first-trim check. Not built with MSVC here. Merges cleanly into main e236b19c.AI-assisted (Claude Code); I ran the builds and checked the results.
Generated by Claude Code
Native Windows follow-up on
15531782. I merged it locally intodcba958e5(tree1bee9a100) and built the unmodified test targets with MSVC 19.44 in Release.title_upload_ring_trim,title_upload_trim, andmemory_breakdowneach passed 3/3. The new ring test uses a fake Vulkan device. It covers the below-ticket hold, the exactly-once free at the ticket, counter lookup failures, and independent slot tickets.d3d12_mapped_plane_asyncalso passed 3/3 on the RTX 4090 (NVIDIA 616.64, Windows 11) with Khronos Vulkan validation 1.4.369 enabled and no diagnostics. This was the stock synthetic GPU smoke test. Ring trimming itself was verified by the CPU fixture above.AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Independent live-ring check of
15531782merged ontomain4014af7fe. CachyOS, clang++ 23.1.5, RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon 610M/Raphael (RADV 26.3.1), Khronos validation 1.4.363. The three stock CPU fixtures (title_upload_ring_trim,title_upload_trim,memory_breakdown) also passed.I used a test-only friend to call the production ring's
prepare,submitandtrimpaths with real Vulkan resources. The ring allocated and mapped an 8 MiB source and submitted a copy to a coherent readback buffer. I added an unsignalled timeline wait to that submission sotrim()ran while the transfer was pending. I set the slot's last-use timestamp to zero to select an already-idle slot without sleeping.With trim on (
KEEP_MB=4,IDLE_MS=1), the real counter was0against ticket1and the first trim kept all 8 MiB. I opened the gate, waited for ticket1, and all 8,388,608 bytes matched. The next trim dropped capacity to zero and counted one release. An extra trim kept that count at one.With
LEONIDA_TITLE_UPLOAD_IDLE_MS=0, the same transfer and full readback passed. The ring kept all 8 MiB and counted zero releases until normal teardown.Measured: 3/3 repetitions for each mode on each GPU, 12/12 total with zero validation diagnostics. This exercises the real map, submission timeline and release path using a synthetic buffer copy. The fixture supplies the command and idle timestamp.
AI-assisted: yes (OpenAI Codex).
Main's rewrite of
d3d12_title_image_upload.h(variable slots with best-fit, batched uploads, GPU detile, fromfix/rendering-correctness) replaces the four-slot ring this PR trims, so it no longer merges. Does the new ring still want idle large slots given back? If so I'll port the trim (release a slot overLEONIDA_TITLE_UPLOAD_KEEP_MBthat is idle and whose ticket the timeline has reached, staging accounting, and the fake-device ring test) onto it; if the rewrite covers this or it isn't wanted, I'll close this one.Generated by Claude Code
I checked the variable-slot uploader on
mainf44904d21to see what it retains today. Native Windows 11, MSVC 19.44 Release, RTX 4090 (NVIDIA 616.64) and Khronos Vulkan validation 1.4.369. I reused the earlier synthetic fixture, which forces staging and checks every byte of four sequential 4096×2048 R8 image readbacks. After 10.5 s idle, I submitted and fenced an empty command list, then did a fifth upload and readback.Both runs reported four staged fills and 8 MiB of staging capacity still held after the idle submission, with zero live slot-70 or slot-133 backing at that point. The fifth upload matched in full, and both runs had zero validation errors. The earlier fixture on the four-slot ring with trimming off retained 32 MiB. Best-fit reuse reduced retention for this sequential case. The new ring still kept its idle allocation.
This confirms retained staging on the merged uploader. The fixture only exercises a sequential stream, so it leaves the multi-slot burst and in-game tradeoff open. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.