Repository navigation
fix(startup): reuse upload ring chunks after GPU completion - #2849
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of head 152a2fd (comment only, no approval). Competing slice: #2847 (older, @Holastor) fixes the same issue (#2837). This is a design choice between the two PRs.
Comparison with #2847 (the point raised on #2847: reuse tied to "any submit")
- #2847 marks a chunk
unsubmittedwhen it is reserved and clears that flag innote_upload_ring_submitfor EVERY chunk when ANY queue executes ANY list. A chunk reserved by a still-recording list can be marked idle by an unrelated submit and then reset. It also keeps one (fence, value) per chunk, so a chunk used on two queues is not fully tracked. - #2849 does not have that hole by design:
- Each list's recording owns a chunk mask (
WrapperOwn::upload_chunks, set inreserve_upload_ringand in theframe_copycache hit).UploadRingChunk::recordingscounts those holds, andreuse_upload_chunkrefuses while it is non-zero. A chunk reserved by a list that has not been reset or released is never recycled. note_submitsORs the masks of the lists actually executed (d3d12_xs_device.cpp,chunks |= list->own().upload_chunks) and stampslast_use[chunk]per queue with that queue's fence value. Reuse needs every queue's stamp completed (UploadQueue::completed), so multi-queue use is covered.- Failed signal stamps
UINT64_MAX(never reusable), andGetCompletedValue() == UINT64_MAX(device removed) is not counted as completion. - A closed list keeps its hold until Reset, Release or a failed Close, because it can be resubmitted.
FrameCopynow stores the slice with itsgeneration; a cached offset into a recycled chunk is rejected, so a stale frame copy cannot point at overwritten bytes. #2847 has no equivalent.
- Each list's recording owns a chunk mask (
- So on "is reuse bound to the completion of the right lists": yes for #2849, no for #2847 as reviewed.
Costs and open points in #2849 (not blockers for the comparison)
- It is the larger change:
Wrapper* listis threaded through everyreserve_upload_ring/ring_copy/frame_copy/upload_from_titlecaller (about 12 callsites ind3d12_draw.inlandd3d12_xs_device.cpp) and the ring now takesallocator_lockinstead of its own lock. I found no nestedallocator_lockacquisition on those paths, but theCreateCommittedResourcecall now runs underallocator_lock; worth a look by whoever owns the locking. - A title that keeps many closed lists un-reset pins their chunks (conservative, same refusal as today, not worse).
- Any other holder of an upload-ring GPU address that outlives a recording (for example a descriptor written once and used by a later list) is not covered by the per-recording mask. This applies to both PRs; I did not find such a case, but it is the question to ask the author.
Tests
tests/upload_reservation_check.cpp(check_ring_reuse) drives the real header logic (reserve_upload_chunk,UploadQueue,reuse_upload_chunk,discard_upload_chunks) with two fake queues. It covers the negative cases: closed list still held, latest submit on every queue, device removal, untracked submit. #2847 has no equivalent unit test of the fence logic.- Two mutations on this head, both caught: dropping the
|| chunk.recordingscheck fails "closed list can be resubmitted"; replacingcompleted >= targetwithtruefails "latest submit on every queue must complete". gate-ring-reuse(WARP and hardware) checks the positive case (new payload accepted after completion). The negative case (no reuse while the queue is still held) is covered by the existinggate-ringfixture, which must keep refusing while the gate is closed; I could not run either fixture here.- Not covered by any unit test: the glue in
d3d12_xs_device.cpp(mask OR innote_submits, discard inlist_reset/list_closefailure /release). Only the D3D12 fixtures exercise it.
Not verified here
- D3D12 fixtures and CI results on this head: CI was still pending when I checked. No Windows run done by me. The PR body claims the fix helps long startup runs; I cannot check that on the real title, so that part stays with @R0Y00 or MasterDomino.
Checked locally: git diff --check origin/main...HEAD clean, python3 tests/docs_links_check.py ok, python3 tests/bidi_controls_check.py ok, c++ -std=c++17 -Isrc tests/upload_reservation_check.cpp passes (rc 0), plus the two mutations above (each reverted with git checkout -- .).
Summary: on the design question #2849 is the more complete answer (per-list holds, per-queue fences, generation check on cached frame copies, unit-level negative controls), at the price of a bigger diff touching every ring caller. #2847 needs its finding 1 fixed before it can be considered. I leave the choice to @R0Y00.
AI-assisted; commands listed were executed locally.
RenzoWit35
left a comment
There was a problem hiding this comment.
Windows run of head 152a2fd (comment only). This adds the D3D12 fixture results that the earlier review could not run.
Environment: Windows 11 build 26300, VS Build Tools 2026 (MSVC 14.51), Windows SDK 10.0.26100, DXC 1.8.2502, dev preset, WARP. D3D12 debug layer not enabled.
Results on this head
ctest --preset dev --no-tests=error -R '^(upload_reservation|startup_address_console_gate.*_warp)$': all 4 pass (upload_reservation,startup_address_console_gate_warp,_gate_ring_warp,_gate_ring_reuse_warp).- Ring-adjacent WARP set,
-R 'upload_reservation|slot133|frame_copy|unified_buffer|startup_address|startup_stream|startup_root|startup_indirect|startup_mesh|startup_compute' -E '_hardware': 173 tests, 171 pass, 0 fail, 2 capability skips (startup_root_heap_warp,startup_slot133_heap_cap_warp_debug1).
Negative control: same build, with src/startup_stubs/d3d12_xs_device.cpp, d3d12_draw.inl and upload_reservation.h taken from the base 2c56d896 and only d3d12_xs_shim rebuilt. gate_warp and gate_ring_warp still pass. gate_ring_reuse_warp fails with {'left': 0, 'right': 32768} wrong pixels, found ['00000000']; expected 03ff5aff left, 355d48ff right, the same numbers as in #2837. So the new mode rejects the old behaviour, and gate-ring still requires the refusal while the queue is held.
Docs: two passages still describe the pre-fix ring:
docs/startup-runtime.md:3322: "refuses exhaustion or allocation failure rather than resetting live storage"docs/experiments.md:16322: thestartup_address_console_gate_ringparagraph. It could also name the newstartup_address_console_gate_ring_reuse_{warp,hardware}mode.
No hardware results from me. Not checked: a real startup run.
AI-assisted; the commands above were run locally.
|
Tested Environment: Windows 11 build 26300.9974, MSVC 19.44.35230, Windows SDK 10.0.26100, NVIDIA GeForce RTX 4090 driver 610.88 (32.0.16.1088), WARP and hardware backends, D3D12 debug layer not enabled. Fixtures ctest --preset dev --no-tests=error -R '^(startup_address_console_gate|upload_reservation$|startup_slot133_heap_cap)'13/13 passed. That covers Full suite: Startup run from #2837 I used the same release build and
The presented picture is no longer black: the loading screen renders. What this does not show: the startup numbers only show that uploads are no longer refused. The revert, which reuses storage without waiting, gives the same numbers. Protection against early reuse is checked only by Doc nits
|
tedin7
left a comment
There was a problem hiding this comment.
Review of #2849 (fixes #2837), exact head cab39c2a (= 152a2fda plus a clean merge of main, 5 commits; the PR's own diff is unchanged).
Merge decision stays open: #2847 and #2849 cover the same issue. No merge from this review until @R0Y00 chooses between them (comparison already posted above).
Correctness (code read, src/startup_stubs/upload_reservation.h, d3d12_xs_device.cpp, d3d12_draw.inl):
- A chunk is reused only when no recording holds it (
recordings == 0) AND every queue that used it has a completed fence value at or past that chunk's last submit. Both conditions are needed and both are checked inreuse_upload_chunk. - A closed list keeps its hold until Reset, failed Close or Release, so a list that is submitted a second time cannot read recycled bytes. A submit whose fence signal fails records
UINT64_MAX, which is never treated as complete (conservative: that chunk is not reused). - Device removal (
GetCompletedValue() == UINT64_MAX) is not treated as completion. frame_copyre-validatesresource+generationbefore reusing a cached offset, so a recycled chunk cannot serve stale cached slices. Lock order (draw_lock, then allocator_lock) matchesqueue_execute. No caller ofreserve_upload_ringholdsallocator_lock.- Known limit, not a blocker: a list that is closed and never reset or released pins its chunks, so a leak of such lists falls back to the old refusal behavior.
Tests and mutations (Linux, GCC, -Wall -Wextra -Werror -fsanitize=address,undefined): tests/upload_reservation_check.cpp passes. Four real mutations each made it fail, and each was reverted with git checkout -- .:
- skip the completion check ->
FAIL: latest submit on every queue must complete - skip the recordings check ->
FAIL: closed list can be resubmitted - no generation bump ->
FAIL: 320 MiB cumulative reservations reuse completed storage - treat an untracked submit as done ->
FAIL: untracked submit prevents reuse
Negative control: with reuse disabled (as on main) the 320 MiB case cannot pass, andgate-ring-reuseexpects payload 18 on the right half where main leaves the null view. I did not rungate-ring-reuseagainst main's source on Windows.
Other Linux checks: tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main...HEAD all clean.
Win2025 WARP (build 26100, MSVC 14.44.35207), head cab39c2a, with --regex '^(upload_reservation|startup_address_console_|startup_stream)':
- dev: 27/27 passed, release: 27/27 passed. Includes
upload_reservation,startup_address_console_gate_ring_reuse_warpand_hardware(hardware ran on WARP),gate_warp,gate_ring_warp. - Real-GPU run not available (RunPod stopped).
This does not claim anything about running the game. AI-assisted; commands listed were executed locally.
|
Win2025 WARP receipt for head cab39c2 after updating with main (PR tests N=27 dev, N=27 release; includes upload_reservation and startup_address_console_gate_ring_reuse_warp/_hardware). Merge held: @R0Y00 to choose between #2847 and #2849.
AI-assisted; commands listed were executed locally. |
|
@R0Y00 a choice is needed here. #2837 is a regression on
Our comparison is in the review comments on both PRs: #2849 (review) and #2847 (review). It points to #2849 as the more complete fix. Which one would you like merged? We will not merge either until you say. AI-assisted; commands listed were executed locally. |
KelboLive
left a comment
There was a problem hiding this comment.
Review: fix(startup): reuse upload ring chunks after GPU completion
This PR solves #2837 — after 256 MiB of cumulative uploads the ring exhausts because chunks never become available again.
How it works
- Track recording references:
UploadChunkMask(bitmask) per recording holds which ring chunks it references. Discarded on list release/reset/close. - Track queue completion:
UploadQueue<Fence>template recordslast_use[index]per chunk per queue. Completed value compared against last-use to determine if the queue is done using the chunk. - Recycle chunks: When a chunk has zero recording references and every queue's fence is past its last-use value, the chunk resets its cursor, bumps its generation counter, and becomes reusable.
- Generation tracking:
UploadReservation::generationandUploadRingChunk::generationallow callers (likeframe_copy) to re-hold a chunk by matching generation.
Comparison with PR #2847 (Holastor)
PR #2847 uses a "closed list" approach: finished chunks stay on a closed list and are reused from there. PR #2849 uses the in-place generation approach: chunks recycle in their original position once all references clear and all queues complete.
Advantages of #2849's approach:
- Simpler data structure: no separate closed list to manage. The global
upload_chunksvector serves as both active pool and recycle target. - Generation-based tracking is cache-friendly — access patterns remain localized to the chunk's original position.
- Clean
UploadQueue<Fence>template makes fence comparison logic encapsulated and testable. - The bitmask (
UploadChunkMask) for recording references is efficient for typical numbers of chunks per recording.
Strengths
- Clean separation of concerns:
hold(),discard_upload_chunks(), andsubmitted()methods keep the reference counting logic isolated. - Fence handling is correct:
last_use[i] = UINT64_MAXwhen signaling fails — this prevents spurious recycling when a queue fails to signal (matching the existing fence-handling conventions). - Lock discipline is consistent: Uses the same
allocator_lockthat guards the upload allocation infrastructure, avoiding new locks or lock ordering issues. - Test gate
gate-ring-reuse: Extends the existing address console test to verify the reuse path draws payload 18 over the right half after completion. - C++17 compatible: Uses
std::arrayand templates without newer C++ extensions.
Minor observations
-
max_upload_chunksassert:static_assert(max_upload_chunks <= 32)guaranteesUploadChunkMaskfits inuint32_t. This is correct but worth noting that changingmax_upload_ring_bytesorinitial_upload_chunk_byteswould need to respect this constraint. -
Chunk growth factor (×2): The doubling growth from 16 MiB up to 256 MiB total is unchanged from the current code. This means at most 16 chunks in the worst case, so the bitmask works comfortably.
-
reuse_upload_chunkis a template: It takesQueuesby const reference. The caller passesqueue_submits(anunordered_map). This works but is slightly indirect — the function only needs indexed access. Could potentially be simplified to accept pointers/indices directly, but this is fine as-is. -
activeindex: Madestatic unsigned activeinreserve_upload_ringinstead ofstatic std::size_t active. Consistent with the unsigned loop indices below.
Verdict
This is a well-structured, correct implementation that avoids the complexity of a separate closed list. The generation scheme cleanly handles the race between recording release and GPU completion without additional synchronization.
Ready to merge. Approving.
The ring now recycles a chunk once no recording holds it and every queue that used it has completed. Replace the passages that still said it never resets storage, and name the new gate_ring_reuse mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
RX 9070 XT results for #2849, plus a docs-only commit, and why we are merging it now. Environment: Windows 11 build 26300.9974, AMD Radeon RX 9070 XT, driver 32.0.32029.2010, Fixtures on ctest --preset release --no-tests=error -j 4 -R '^(upload_reservation|startup_address_console|startup_list_resubmit|startup_slot133_heap_cap|startup_null|startup_stream_draw)'31/31 passed, WARP and hardware. That includes Negative control: same tree with Startup run, matched: same machine, same switches, same input script, 300 s each, run back to back with
Both runs reached the 300 s timeout with no second-chance exception, no trap and no device removal. On Docs commit Why we are merging without the choice from @R0Y00: AI-assisted; the commands above were run locally. |
MasterDomino
left a comment
There was a problem hiding this comment.
Approving at b9c738a8, which is cab39c2a plus a docs-only commit. Evidence on an RX 9070 XT is in #2849 (comment):
- Fixtures: 31/31 passed.
- Negative control: with chunk reuse disabled,
upload_reservationand bothgate_ring_reusetests fail, whilegate_ringstill passes. - Matched 300 s startup run against
main: null bindings drop from 377,651 to 0, textures uploaded rise from 36 to 1,387, and ring refusals drop from 8 to 0.
All comments and reviews were read in full. The open nits were the stale docs passages, and b9c738a8 fixes them.
AI-assisted.
|
Mutation check on the merged code ( Clean
Baseline: 13 passed, 0 skipped. Nine single-site mutations, each applied alone and rebuilt,
What the matrix says:
Scope, since it is easy to over-read this: 13 entries selected by the regex above, one machine, WARP plus one AMD adapter, If a fixture for either case is wanted (a ring draw that fails the fence, or a list released without a reset), I can send one as a PR. AI-assisted. |
Problem
Fixes #2837. Since #2823, every reservation advanced a chunk's cursor, but GPU completion never made those bytes available again. After 256 MiB of cumulative uploads, subsequent draws could receive null bindings for the rest of the process.
Change
Track which chunks each command-list recording references and the latest submission fence for each chunk on each queue. Recycle a chunk once every recording has released it and every queue that used it has completed. A closed list keeps its hold because it can be submitted again. Cached frame copies check the chunk generation before reusing an offset.
Scope
Covers the shared startup upload ring, its callers and its regression fixtures. The 256 MiB cap and refusal of uploads while all storage is busy are preserved.
Verification
c++ -std=c++17 -Wall -Wextra -Werror -fsanitize=address,undefined -Isrc tests/upload_reservation_check.cpp -o upload_check && ./upload_checkpassed with GCC 15 on Linux x86-64 (320 MiB cumulative, covering repeat submission, independent queues, fence failure and device removal), and also passed on macOS ARM64 after rebasing onto2c56d89.gate-ring-reusefor WARP and hardware (ctest --preset dev --no-tests=error -R '^startup_address_console_gate' -V). Windows build and pixel readback remain for CI / hardware verification.Reviewed with mistral-loop: APPROVE (1 round,
mistral-large-4-0+deepseek-v4-1-flash-1017).Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).