Repository navigation
Conversation
In R0Y00#2823 (commit 7256cec), uncompleted reuse of the shared upload ring was removed to prevent GPU in-flight memory corruption. However, because chunks were never recycled once GPU submissions finished, total reservations permanently froze upon reaching the 256 MiB cap, refusing every subsequent upload and leading to black screens and hundreds of thousands of null buffer bindings in long startup runs. Track queue submission fence values on upload chunks that receive unsubmitted writes. When active chunks and free tails cannot satisfy a reservation, inspect completed fence values and reset completed, idle chunks, guaranteeing storage still in flight on the GPU is never reused before completion. Add the gate-ring-reuse fixture to verify that upload reservations succeed once earlier GPU submissions complete, while gate and gate-ring continue to enforce in-flight safety and exhaustion limits. Fixes R0Y00#2837 Refs R0Y00#2823
tedin7
left a comment
There was a problem hiding this comment.
Review of head 969fa03 (comment only, no approval).
Finding 1 (correctness, can bring back the corruption #2823 fixed): chunk reuse is tied to "any submit", not to the lists that use the chunk.
reserve_upload_chunk(upload_reservation.h) setsunsubmitted = truewhen a chunk is reserved, i.e. while a command list is still being recorded.note_upload_ring_submit(d3d12_xs_device.cpp, called fromnote_submits) clearsunsubmittedon EVERY chunk and binds it to the fence value of whichever queue just executed, whichever lists that was.- Sequence: list A records a draw and reserves bytes in chunk C (not executed yet). List B (another thread or another queue, recorded earlier) is executed.
note_submitsmarks C as submitted with B's fence value. B completes.is_upload_chunk_idle(C)is true. When the ring is full,reset_upload_chunk(C)runs and new data overwrites the bytes list A still has to read. That is the same in-flight corruption as before #2823, only rarer. - A chunk used by lists on two queues has the same hole: the first submit clears
unsubmitted, the second queue's fence is never added. - Fix idea: record the chunks (or ring watermark) a list reserved in its own recording state, and bind the fence only when that list is executed (the
list_recordings/retire_address_uploadspath next to it already tracks per-list data). Keep a chunk non-idle until every list that reserved from it has been executed and its fence has passed.
Finding 2 (test coverage): the new tests do not guard the fence logic.
upload_reservation_check.cpponly checks thatreset_upload_chunkzeroes the cursor.is_upload_chunk_idleandnote_upload_ring_submitlive in d3d12_xs_device.cpp and have no unit test: not the "fence not yet passed, must not reuse" case, not the "reserved but not yet executed" case from finding 1.gate-ring-reusechecks only the good case (everything completed, one more payload must be accepted). It would catch a ring that never recycles, but not one that recycles too early. A negative control is missing: run the reuse draw while the queue is still waiting on the gate fence and require it to be refused (left half keeps payload 0, no overwrite).- I could not run the D3D12 fixtures here (Linux only), so I did not try a mutation of the fence comparison. Please add the negative control and show that it fails when
GetCompletedValue() < submit.secondis dropped.
Startup claim. The body says this fixes black screens and null bindings in long startup runs. I have no way to check that on the real title. Fixture results (yours, on WARP and hardware) are a separate thing from that. The merge stays with MasterDomino or @R0Y00, who can verify on the game.
Checked locally: git diff --check origin/main...HEAD clean, python3 tests/docs_links_check.py ok (27 files, 541 links), python3 tests/bidi_controls_check.py ok. Reviewed the code of d3d12_xs_device.cpp, upload_reservation.h, the three test files and CMakeLists.txt. No other open PR covers this slice (follows #2823).
AI-assisted; commands listed were executed locally.
Address review feedback on R0Y00#2847 (tedin7): 1. Tie chunk reuse to the command lists that actually reserve from them. Track recorded chunks per command list in recorded_upload_chunks. Chunks maintain an unsubmitted_lists count and are bound to queue submit fence values only when the lists using them are executed. When a recording is discarded on Reset or failed Close, its reservations are dropped. 2. In upload_reservation_check.cpp, test unsubmitted lists, pending and completed fence values, and multi-queue submissions. 3. In gate-ring-reuse, add a negative control draw while the queue is held behind the gate fence. Verify it is refused and preserves payload 0 on the left half, and verify mutation of the fence check fails the fixture.
|
Thank you @tedin7 for the thorough and insightful review! Both findings have been addressed in 1. Per-List / Per-Recording Chunk Tracking (Finding 1)
2. Guarded Fence Logic & Unit Tests (Finding 2)
3. Negative Control & Mutation Verification (Finding 2)
Evidence on
|
tedin7
left a comment
There was a problem hiding this comment.
Review of head 895a7c0 (comment only, no approval). Updates my earlier comparison with #2849 (same issue, #2837). The choice between the two stays with @R0Y00.
Is reuse now tied to the lists that reserved the chunk? Mostly yes, with one hole.
- Good:
recorded_upload_chunksmaps each list to its chunks,unsubmitted_listskeeps a chunk busy until those lists are executed,note_upload_ring_submitsbinds that queue's fence only to the chunks of the executed lists, anddiscard_upload_ringruns on Reset and on a failed Close. Several queues each keep their own fence inchunk.submits. The "unrelated submit frees a reserved chunk" case from my first review is fixed. - Hole 1 (
d3d12_xs_device.cpp:2623-2628):upload_from_titlegot a newlistargument but does not pass it on:ring_copy(title_address, bytes, &offset, &resource). The root-SRV path (list_root_srv, line ~3983) therefore reserves ring bytes that no list owns. If that chunk has no other holder, it can look idle and be reset while the recording list still has to read it. Fix: passlisttoring_copy. - Hole 2 (
d3d12_draw.inl:1235-1250): aframe_copycache hit adds a hold only when it hits. The cachedoffsetis not checked against a chunk that was reset in between, so a stale offset can point at bytes now owned by another draw. #2849 stores agenerationwith the slice and rejects it; #2847 has nothing like that. - Smaller: a closed list that is executed twice without a Reset is not tracked the second time (the entry is erased at the first submit). #2849 keeps its hold until Reset/Release.
- A failed
Signalleavesunsubmitted_listsraised, so the chunk is never reused. That is safe, only a leak.
Is there a negative control? Yes, for the fence, not for the ownership.
upload_reservation_check.cppnow tests: in-flight submit, unsubmitted list, completed fence, one of two queues still pending.startup_stream_draw.cppadds a draw refused while the queue waits on the gate fence, andcheck_gate_ring_reuseasserts it in the log.- Mutations I ran on Linux (
g++ -std=c++17 -I src tests/upload_reservation_check.cpp): clean build passes. Droppingquery(submit.first) < submit.secondfails with "chunk with in-flight submit is not idle". Dropping theunsubmitted_lists != 0check fails with "chunk with unsubmitted lists is not idle". - Not covered by any test: the per-list bookkeeping itself (
note_upload_ring_submits,discard_upload_ring, thelistplumbing). That is why hole 1 passes all tests. A fixture where a root-SRV upload fills the ring while its list is still recording would catch it.
Compared with #2849 (head 152a2fd): #2847 now closes the main "any submit" bug but still has holes 1 and 2 and keeps per-list state outside the list wrapper. #2849 covers both by design (per-recording chunk mask, per-queue stamps, generation on frame copies). On correctness #2849 is ahead. #2847 is the older PR and its author fixed the first findings quickly. Please pick one; if #2847 is kept, holes 1 and 2 should be fixed first.
Not verified: D3D12 fixtures (WARP and hardware gate tests) were not run by me (Linux only). The black-screen / startup claim cannot be checked without the real title; the merge stays with MasterDomino or @R0Y00.
Checked locally: git diff --check origin/main...HEAD clean, python3 tests/docs_links_check.py ok (27 files, 541 links), python3 tests/bidi_controls_check.py ok, py_compile tests/startup_address_console_check.py ok, the two mutations above.
AI-assisted; commands listed were executed locally.
…removal - Pass command list through upload_from_title to ring_copy to maintain chunk associations. - Add generation counter to UploadRingChunk and FrameCopy to invalidate stale cache hits after chunk reset. - Keep chunk recordings held across queue_execute submissions so closed lists can be safely resubmitted. - Treat UINT64_MAX fence completion query in is_upload_chunk_idle as device removal. - Extend upload_reservation_check with generation, closed list hold and device removal test coverage.
|
Thank you @tedin7 for the detailed review and comparison! All holes and lifecycle concerns have been addressed and covered in 1. Root-SRV Upload Command List Forwarding (Hole 1)
2. Chunk Generation Invalidation in
|
|
Independent RDNA 4 result on Not a code change; measurements only. Environment
CommandsThe six entries registered here are BaselineThe hardware entries print MutationsOne line each in
What this establishes
Limits
AI-assisted. |
KelboLive
left a comment
There was a problem hiding this comment.
This PR has a build-breaking bug and a production regression that need to be addressed before merging.
Build-breaking: startup_view_alloc_* tests will fail to link
The PR removes these symbols but does not remove the tests that reference them:
Removed:
- (DLL export)
-
- struct (DLL export)
- , , (internal symbols)
Still exists (will have link errors):
- — calls at 4 call sites and uses +
- — CMake config still registers the tests
- — test documentation still references them
Fix: Either remove the test + CMake + docs, or keep the exports stubbed.
Production regression: view allocation error handling removed
replaces + with bare . The old code handled real memory pressure by logging which container failed, untracking the descriptor, and continuing cleanly. The new code lets throw up through COM APIs — undefined behavior for the host.
The comments describe this as fixture-only fault injection, but the error path (logging + descriptor untracking) is also production code. Under extreme memory pressure this turns a crash into graceful degradation.
Fix: Keep / for production; keep only the fault injection exports behind a test-only guard.
Upload ring reuse fix itself ✅
The core mechanism is well-designed:
- Generation counter prevents stale data reuse
- Per-chunk submit tracking validates fence values
- Recording count prevents mid-recording reuse
- Closed-list refs preserved on Reset/Close
- UINT64_MAX device removal guard
- Tests validate both negative (in-flight=refuse) and positive (completed=reuse) paths
Recommend: Fix test breakage + review view allocation trade-off, then merge for the upload ring fix.
|
Thank you @KelboLive for reviewing and validating the upload ring reuse mechanism (generation counter, submit tracking, recording counts, closed-list holds, and device removal guards)! Regarding the concerns raised in the first two sections: 1.
|
Not-Saii
left a comment
There was a problem hiding this comment.
Thanks for picking this up. I read the diff against the reuse rule from #2823: storage the GPU may still read is never reused. Three paths can reuse a chunk early. None of them is covered by gate-ring-reuse, which submits each recording once and never hits a frame-copy cache.
1. A resubmitted closed list loses its hold
note_upload_ring_submits erases the list's entry in recorded_upload_chunks at its first submit. A closed list can be passed to ExecuteCommandLists again until its Reset, as the comment in queue_execute says. On the second submit there is no entry, so chunk.submits keeps the first submit's fence value. After that value completes, is_upload_chunk_idle returns true while the second submit may still be reading the chunk.
Suggested fix: keep the recording's entry until Reset, failed Close or final Release. On every submit, update the fence value of each chunk the recording names.
2. Frame-copy cache hits can return reused bytes
On a cache hit, frame_copy calls note_upload_ring_use, which only re-registers the list. reset_upload_chunk does not invalidate earlier offsets. Once the ring is at its cap, a chunk can be reset and refilled within one frame, after the recording that made the copy has completed. A later draw in the same frame then gets the cached (resource, offset), which now points at another reservation's bytes.
Suggested fix: add a generation to the chunk, bumped on reset and stored in FrameCopy. A hit then compares generations under the ring lock and treats a mismatch as a miss.
3. A submit whose fence signal fails becomes reusable after Reset
note_upload_ring_submits runs only inside if (fence && SUCCEEDED(queue->Signal(...))). If the fence cannot be created or signalled (submit_fence_fails() forces this), the chunk gets no submits entry. The list's later Reset drops unsubmitted_lists to 0, so is_upload_chunk_idle returns true while that submission may still be in flight. note_submits marks the allocators untracked in this case for the same reason. The ring chunk should be kept for the process too.
A smaller point: the reuse loop calls reset_upload_chunk on every idle chunk it visits, even when chunk.capacity < rounded. Combined with point 2, that invalidates cached copies without using the space.
For comparison, #2849 handles all three cases. Recording holds there last until Reset, every submit updates a per-queue fence value per chunk, cached copies check a generation, and a failed signal pins the chunk on that queue. I posted hardware results for it in #2849 (comment). I did not run this PR on hardware. The points above come from reading the code.
… before reset - Mark chunks untracked when queue fence signaling or creation fails so they are never recycled. - Only reset idle chunks in reserve_upload_ring when chunk.capacity >= rounded to protect cached frame copies. - Add unit tests in upload_reservation_check for generation validation and untracked chunks.
|
Thank you @Not-Saii for the thorough review and edge-case analysis! 1 & 2. Resubmitted Closed Lists & Frame-Copy Cache Generations (Already in
|
|
Thanks for the quick follow-up. I re-read and 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 Review follow-up
I did not exercise the generation-miss, resubmission or fence-failure paths on hardware. Those points come from reading the code. |
|
Mutation check on Environment: RX 9070 XT ( Gate: 17 entries — ResultsEach mutation applied once, rebuilt and re-run (
What the four sayThe failure branch in The four M4 is therefore green for a stronger reason than masking: the line it mutates is not executed with a recorded chunk anywhere in the gate. The unit test that covers the flag sets it directly ( M2 — every payload is one 2048×2048 RGBA8 texture, 16 MiB, and chunks are created at So: of the two guards What would flip themNot a patch, just the shape of the missing cases:
Limits: one adapter, one driver, one preset, one session. The gate is those 17 entries, not the suite — a mutation that is invisible here could be caught elsewhere, and AI-assisted. |
|
Re-tested on 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|startup_list_resubmit|upload_reservation$|startup_slot133_heap_cap|startup_null|startup_stream_draw)'31/31 passed. That includes all four Startup run from #2837 I used a release build of Code read of
New: a list's final Release does not drop its ring hold
Calling I didn't see this in the 180 s run, which had 0 refusals. That run doesn't show whether the title releases lists without a Reset. Still open, minor: The final-Release and lock points come from reading the code. I did not exercise them. |
|
Good analysis. Two quick thoughts on the new issues: 1. List Release → discard_upload_ring This is significant. The stale recorded_chunks entry keeping a chunk pinned is a plausible alternative root cause for #2837. If the title releases D3D12 command lists without Reset (common for transient lists), the ring permanently loses capacity. The fix you proposed is straightforward:
I would make this a separate PR. It is safe even standalone — if the list was never submitted for uploads, discard_upload_ring is a no-op. 2. Lock ordering in frame_copy Yes, two acquisitions. The window where a chunk could be reset between generation_valid check and note_upload_ring_use is tiny and the generation check itself protects against using reset memory. Still, a single lock covering both would be cleaner. Worth a follow-up but not blocking. On our prior review: We flagged build-breaking test issues (startup_view_alloc referencing removed symbols) and a production regression (bare push_back in view allocation). Have those been addressed since our CHANGES_REQUESTED? |
KelboLive
left a comment
There was a problem hiding this comment.
Updated review of head 3b737f0.
Author has addressed all concerns from my previous review and from tedin7, Not-Saii, and the independent validation:
Per-list chunk tracking: recorded_upload_chunks maps each list to its chunks; unsubmitted_lists (renamed from recordings) keeps a chunk busy until every referencing list is executed and its fence passes.
Generation counter: UploadRingChunk tracks a monotonic generation incremented on reset; FrameCopy records reservation.generation; on cache hit, is_upload_chunk_generation_valid() rejects stale offsets from recycled chunks.
Closed list resubmission: recordings retained across queue_execute calls; hold only released on discard_upload_ring (list_reset or failed list_close).
Device removal: UINT64_MAX fence value treated as pending (not completion).
Failed signal handling: mark_upload_ring_untracked() pins chunks when queue->Signal or fence creation fails.
Capacity-gated reuse: reserve_upload_ring checks chunk.capacity >= rounded before resetting; chunks too small are never reset.
Independent validation: thepatrickworld confirmed all four guards are pinned by upload_reservation_check; three guards have no fixture-visible impact (proving they are defensive, not regressions); only the fence comparison guard is pixel-visible.
My earlier CHANGES_REQUESTED referenced startup_view_alloc_* symbols. Per the author, these do not exist in this PR; the PR touches only the 8 upload ring files listed. The author reports a clean build of all 1786 targets. No view allocation or descriptor untracking code was altered. Reviewing the diff confirms no such changes.
All six gate fixtures pass on WARP and hardware. Unit tests pass. Negative controls and mutation verification are solid.
Approved for merge.
…cache validation lock - Call discard_upload_ring in release() when a list wrapper refcount hits zero to prevent transient lists from permanently pinning chunks. - Combine generation check and note_upload_ring_use into atomic validate_and_note_upload_ring_use under exclusive lock in frame_copy.
|
Thank you @Not-Saii for the thorough 180s startup verification run on the RTX 4090 (1,357 textures / 5.3 GiB uploaded, 0 null bindings, 0 ring refusals, 22.2 FPS) and to @KelboLive for the additional analysis! Both suggested improvements have been implemented and validated in 1. Command List
|
|
Re-tested Code read: both points are addressed.
Fixtures ctest --preset dev --no-tests=error -j 4 -R '^(startup_address_console|startup_list_resubmit|upload_reservation$|startup_slot133_heap_cap|startup_null|startup_stream_draw|startup_view_alloc)'43/43 passed. That includes the Startup run from #2837 (release build, same flags and input as before, 180 s)
The first run stopped early with no ring refusal logged. Earlier runs on this PR and on #2849 never stopped this way, and the repeat with the same build was clean. I have not found the cause, and nothing points at the upload ring. I'm reporting it in case someone sees the same thing after the merge of main. Still not exercised on hardware: a list released without a Reset while its chunks are recorded, and the failed-fence writer (M4 in @thepatrickworld's report). Neither has a fixture yet. |
|
#2849 has been merged as AI-assisted. |
|
@MasterDomino I disagree with merging #2849 ahead of a maintainer decision and closing this out without input from @R0Y00. I'll leave this PR open and wait for a review from @R0Y00. |
|
@Holastor thank you for this fix and for the quick updates today. #2849 was merged into AI-assisted; commands listed were executed locally. |
Summary
Fixes #2837
Refs #2823
In #2823 (commit
7256cecf), uncompleted reuse of the shared upload ring was removed to fix in-flight GPU memory corruption. However, because chunks were never recycled once GPU submissions finished, total reservations permanently froze upon reaching the 256 MiB cap, refusing every subsequent upload and leading to black screens and hundreds of thousands of null buffer bindings in long startup runs.This change:
UploadRingChunk::submitswhenever a queue signals its completion fence innote_submits.unsubmitted = true, which is cleared and bound to the signaled fence value during queue submission.is_upload_chunk_idleandreset_upload_chunk: when capacity is exhausted and no active chunk or unused tail can satisfy a reservation, idle chunks whose GPU work has completed (GetCompletedValue() >= submit.second) are reset and reused from offset 0. Storage still in flight on the GPU is never reused before completion.tests/upload_reservation_check.cpp.gate-ring-reusetest fixture toCMakeLists.txt,tests/startup_stream_draw.cpp, andtests/startup_address_console_check.py, and updatesdocs/startup-runtime.md.Evidence
Commit under test:
969fa03dEnvironment:
Unit test:
.\out\build\dev\upload_reservation_check.exeOutput:
Output:
All passed without error.