startup: reuse completed upload ring chunks after GPU execution #2839
Closed
Holastor wants to merge 6 commits from
upstream-pr/2847 into main
pull from: upstream-pr/2847
merge into: R0Y00:main
R0Y00:main
R0Y00:codex/indirect-large-backed-views
R0Y00:codex/word3-preflight-check
R0Y00:codex/vertex-table-two-records
R0Y00:codex/live-index-alias
R0Y00:codex/copied-vertex-buffer-srv
R0Y00:codex/windows-stage-test-output
R0Y00:codex/preserve-live-srv-retirement
R0Y00:codex/share-render-target-tracking
R0Y00:codex/sgd5-negative-offset-fixture
R0Y00:coverage-dashboard
R0Y00:codex/mesh-loose-root
R0Y00:codex/mesh86-cache-padding
R0Y00:codex/xmem-scatter-preflight
R0Y00:codex/mesh-depth-ps
R0Y00:codex/indirect-dispatch-refresh
R0Y00:codex/compute-container-index
R0Y00:codex/startup-compute-formatted-load
R0Y00:codex/compute-indirect-producer
R0Y00:codex/compute-atomic-soffset
R0Y00:codex/mesh-dual-handoff
R0Y00:codex/startup-run-sh-watcher-control
R0Y00:codex/queue31-page-alias
R0Y00:codex/indexed-indirect-compute-root
R0Y00:codex/typed-buffer-view-metadata
R0Y00:codex/translated-indexed-address-alias
R0Y00:codex/fixed-mesh-create-result
R0Y00:codex/xmem-section-lease
R0Y00:codex/startup-slot86-mesh-cache
R0Y00:codex/restore-mesh-barrier-iteration
R0Y00:codex/translated-indirect-upload-index
R0Y00:codex/xapu-completion-opt-in
R0Y00:codex/translated-indexed-rect
R0Y00:codex/translated-indexed-indirect
R0Y00:codex/startup-mesh-lds-integration
R0Y00:codex/startup-console-ms24
R0Y00:codex/startup-slot57-mesh-request
R0Y00:codex/indirect-copy-provenance
R0Y00:codex/present-color-producer-trace
R0Y00:codex/compute-dispatch-binding-trace
R0Y00:codex/translated-indirect-table-buffers
R0Y00:codex/indirect-copy-provenance-base
R0Y00:codex/mix-half-literal-source
R0Y00:codex/translated-indirect-draw
R0Y00:codex/xmem-scatter-diagnostics
R0Y00:codex/slot148-recording-upload
R0Y00:codex/slot70-loading-art-verified
R0Y00:codex/command-list-upload-arena
R0Y00:codex/recover-failed-command-list
R0Y00:codex/startup-heap-timing-notes
R0Y00:codex/align-audio-input-timeline
R0Y00:codex/synthetic-depth-export-control
R0Y00:codex/startup-texture1d-on-windows
R0Y00:codex/1629-packed-position-fixture
R0Y00:codex/cpu-srv-refresh
R0Y00:codex/stream-root-srv-draw
R0Y00:codex/audio-mixer-timer
R0Y00:codex/startup-reload-published-shader
R0Y00:codex/priority-integrate-1284
R0Y00:codex/guest-sixteen-page-record
R0Y00:codex/aot-placed-dxr-batch
R0Y00:codex/guest-directory-selection
R0Y00:codex/gamesave-enumerate-read
R0Y00:codex/readme-archive-to-pixels
R0Y00:codex/pe-placed-view-draw
R0Y00:codex/archive-directory-gpu
R0Y00:codex/slot133-dxr-build
R0Y00:codex/materialize-placed-vertex-view
R0Y00:codex/dstorage-directory-offsets
R0Y00:codex/xg-nine-bc-copy
R0Y00:codex/xg-slot10-bc64-arrays
R0Y00:codex/dxr-guest-address-readback
R0Y00:codex/gpu-va-high-bits
R0Y00:codex/clarify-diagnostic-startup-scope
R0Y00:codex/xg-six-levels
R0Y00:codex/typed-derived-blend
R0Y00:codex/english-legal-text-progress
R0Y00:codex/address-bc-4ks
R0Y00:codex/dstorage-bounded-file-read
R0Y00:codex/wide-srv-offsets-menu
R0Y00:codex/startup-memory-srv
R0Y00:codex/bound-view-tail
R0Y00:codex/language-selector-readback
R0Y00:codex/setup-menu-progress
R0Y00:codex/cpu-plane-refresh
R0Y00:codex/startup-ubyte-vertex
R0Y00:codex/presenter-window-selection
R0Y00:codex/startup-uniform-buffer-lane
R0Y00:codex/intro-loop-timing
R0Y00:codex/static-clzero-loops
R0Y00:codex/document-rtx-intro
R0Y00:codex/startup-insertq
R0Y00:codex/nv12-startup-texture
R0Y00:codex/stream-stage-draw
R0Y00:codex/startup-null-uav-format
R0Y00:codex/startup-draw-capture
R0Y00:codex/shorten-windows-checks
R0Y00:codex/dstorage-rfc1950
R0Y00:codex/startup-dump-fence
R0Y00:codex/pr1135-review-base
R0Y00:codex/startup-stream-requests
R0Y00:codex/startup-chroma-view
R0Y00:codex/readme-graphics-pipeline-streams
R0Y00:codex/static-crt-free-tls
R0Y00:codex/arc-140t-rtx-5080-laptop-gpu-reports
R0Y00:codex/main-startup-progress-entry
R0Y00:codex/signed-dxil-catalogue
R0Y00:codex/reloc-free-preferred-base
R0Y00:codex/quad-dpp-bit-mask
R0Y00:codex/raw-srv-bounds
R0Y00:codex/rx9070-31044-hardware-report
R0Y00:codex/gpu-page-source-provenance
R0Y00:codex/runtime-placeholder-interior
R0Y00:codex/gpu-copy-queue-tile-order
R0Y00:codex/pe-pin-external-providers
R0Y00:codex/xmem-placeholder-reservations
R0Y00:codex/xmem-shared-physical-pages
R0Y00:codex/pe-package-startup
R0Y00:codex/xmem-tools-memory-query
R0Y00:codex/cpu-stack-output-import
R0Y00:codex/pe-load-security-cookie
R0Y00:codex/record-three-bvh-retests
R0Y00:codex/cpu-rbp-frame-anchor
R0Y00:codex/xmem-default-startup
R0Y00:codex/record-rtx-3050-ti-9597
R0Y00:codex/docs-readme-start-here
R0Y00:codex/check-compute-mad24-truncation
R0Y00:codex/docs-discord-community
R0Y00:codex/bound-rcx-branch-mutants
R0Y00:codex/rtx5060ti-bvh-62114
R0Y00:codex/837-neutral-readme-disclaimer
R0Y00:codex/record-rtx-3070-ti
R0Y00:codex/title-neutral-public-wording
R0Y00:codex/exe-shadow-frame-submissions
R0Y00:codex/exe-shadow-runtime-chain
R0Y00:codex/readme-polish
R0Y00:codex/gpu-coverage-nov23
R0Y00:codex/spirv-minlod
R0Y00:codex/shadow-shim-device
R0Y00:codex/exe-two-shadow-frames
R0Y00:codex/shim-dispatch-cleanup
R0Y00:codex/fix-spirv-cache-probe
R0Y00:codex/sampler-use
R0Y00:codex/ballot-bit-extract
R0Y00:codex/packed-fma-release
R0Y00:codex/cpu-packed-fma-o2
R0Y00:codex/publish-coverage-dashboard
R0Y00:codex/mesh-cbv-binding-order
R0Y00:codex/spirv-window-fixture
R0Y00:codex/ps-e32-float-uint
R0Y00:codex/ps-cbuffer-reads
R0Y00:codex/fixed-profile-rescan
R0Y00:codex/shim-compute-integration
R0Y00:codex/readme-visible-coverage
R0Y00:codex/readme-research-navigation
R0Y00:codex/integrate-pr-256
R0Y00:codex/indexed-mesh
R0Y00:codex/sampled-coverage
R0Y00:codex/first-ms
R0Y00:codex/dual-ps
R0Y00:codex/ps-attribute
R0Y00:codex/compute-first
R0Y00:codex/ps-export
R0Y00:codex/readme-research-status
R0Y00:codex/ps-layout
R0Y00:codex/blast-window
R0Y00:codex/chart-caption
R0Y00:codex/reviewer-roles
R0Y00:codex/blast-aot
R0Y00:codex/archive-program
R0Y00:codex/crc-stream-program
R0Y00:codex/exe-image-data-chain
R0Y00:codex/local-cpu-fixture-coverage
R0Y00:codex/exe-bound-frame-chain
R0Y00:codex/exe-mapped-comparison
R0Y00:codex/contribution-dependencies
R0Y00:codex/exe-entry-aot
R0Y00:codex/bink-frame-heap-integration
R0Y00:docs/hardware-seven-reports
R0Y00:codex/bink-custom-heap
R0Y00:codex/bink-heap-callers
R0Y00:codex/discussions-entry-points
R0Y00:codex/gpu-community-batch-64
R0Y00:codex/ffx-scratch-writers
R0Y00:codex/generic-project-documentation
R0Y00:codex/ffx-dispatch-rcas
R0Y00:codex/four-windows-gpu-reports
R0Y00:codex/title-neutral-project-wording
R0Y00:codex/community-coverage-provenance
R0Y00:codex/rcas-packed-texels
R0Y00:codex/community-gpu-retests
R0Y00:codex/community-build-and-gpu-reports
R0Y00:codex/ffx-provider-loop
R0Y00:codex/ffx-recurrent-views
R0Y00:codex/ffx-recurrent-resource
R0Y00:codex/amd-wave64-reports
R0Y00:codex/ffx-backend-slots
R0Y00:codex/upscaler-device-init
R0Y00:codex/ffx-context-lifecycle
R0Y00:codex/ffx-version-query
R0Y00:codex/ffx-provider-contract
R0Y00:codex/typed-object-callback
R0Y00:codex/cpu-ordinal-import
R0Y00:codex/chained-cpu-ranges
R0Y00:codex/cpu-import-call
R0Y00:codex/cpu-direct-call
R0Y00:codex/cpu-leaf-aot
R0Y00:codex/community-project-status
R0Y00:codex/script-state-path-replay
R0Y00:codex/script-state-evidence
R0Y00:codex/bc7-resident-tail
R0Y00:codex/bcpack-mip-tail
R0Y00:codex/bc7-texture-draw
R0Y00:codex/asset-ranges
R0Y00:codex/pixel-constants
R0Y00:codex/pixel-aot
R0Y00:codex/pre-exe-workloads
R0Y00:codex/root-signature-device-coverage
R0Y00:engineering/packed-bvh-leaves
R0Y00:engineering/bvh-build-and-update
R0Y00:engineering/intake-root-roundtrip
R0Y00:community/gpu-check-release
R0Y00:community/english-contributor-entry
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
R0Y00/Xbox2Windows!2839
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2847"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T13:29:00Z.
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:
Output:
Output:
All passed without error.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:31:51Z.
Review: COMMENTED
Review of head
969fa03d(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.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.unsubmitted, the second queue's fence is never added.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).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...HEADclean,python3 tests/docs_links_check.pyok (27 files, 541 links),python3 tests/bidi_controls_check.pyok. 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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:56:57Z.
Review: COMMENTED
Review of head
895a7c0d(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.
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.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.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.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.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".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
152a2fda): #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...HEADclean,python3 tests/docs_links_check.pyok (27 files, 541 links),python3 tests/bidi_controls_check.pyok,py_compile tests/startup_address_console_check.pyok, the two mutations above.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T13:51:51Z.
Thank you @tedin7 for the thorough and insightful review! Both findings have been addressed in
895a7c0d:1. Per-List / Per-Recording Chunk Tracking (Finding 1)
unsubmittedboolean with per-list tracking:recorded_upload_chunks(std::unordered_map<ID3D12CommandList*, std::vector<std::size_t>>) tracks which chunk indices are referenced by each command list during recording (inreserve_upload_ring,frame_copy,ring_copy, andupload_from_title).UploadRingChunktracksunsubmitted_lists. While any unsubmitted list references the chunk,is_upload_chunk_idlereturnsfalse.queue_execute,note_upload_ring_submits(fence, value, native_lists)decrementsunsubmitted_listsand binds that queue's signaled fence value only to the chunks that were actually recorded on those lists.Close()without being submitted,discard_upload_ring(list)decrementsunsubmitted_listsand clears its recorded entries.chunk.submits;is_upload_chunk_idlerequires every queue fence to reach its target value.2. Guarded Fence Logic & Unit Tests (Finding 2)
tests/upload_reservation_check.cpp, added unit tests validating:unsubmitted_lists = 1) ->!is_upload_chunk_idle.completed = 9 < 10) ->!is_upload_chunk_idle.completed = 10 >= 10) ->is_upload_chunk_idle.!is_upload_chunk_idle.is_upload_chunk_idle.3. Negative Control & Mutation Verification (Finding 2)
tests/startup_stream_draw.cpp, added a negative control draw while the queue is still held behind the gate fence:check_gate_ring_reuseintests/startup_address_console_check.pyasserts that this in-flight refusal was logged intrap.log.query(submit.first) < submit.secondinis_upload_chunk_idle:upload_reservation_check.exefailed:FAIL: chunk with in-flight submit is not idlestartup_address_console_gate_ring_reuse_warpfailed:AssertionError: gate-ring-reuse: {'left': 32768, 'right': 0} wrong pixels, found ['136f4aff']; expected 03ff5aff left, 355d48ff right(Demonstrating that premature chunk reuse overwrote chunk 0 with payload 16, exactly reproducing the in-flight corruption).
Evidence on
895a7c0dOutput:
upload_reservation_check: all checks passedImported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T14:25:49Z.
Review: CHANGES_REQUESTED
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:
Still exists (will have link errors):
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:
Recommend: Fix test breakage + review view allocation trade-off, then merge for the upload ring fix.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T14:34:13Z.
Review: COMMENTED
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_submitserases the list's entry inrecorded_upload_chunksat its first submit. A closed list can be passed toExecuteCommandListsagain until its Reset, as the comment inqueue_executesays. On the second submit there is no entry, sochunk.submitskeeps the first submit's fence value. After that value completes,is_upload_chunk_idlereturns 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_copycallsnote_upload_ring_use, which only re-registers the list.reset_upload_chunkdoes 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_submitsruns only insideif (fence && SUCCEEDED(queue->Signal(...))). If the fence cannot be created or signalled (submit_fence_fails()forces this), the chunk gets nosubmitsentry. The list's later Reset dropsunsubmitted_liststo 0, sois_upload_chunk_idlereturns true while that submission may still be in flight.note_submitsmarks 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_chunkon every idle chunk it visits, even whenchunk.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 https://github.com/R0Y00/Xbox2Windows/pull/2849#issuecomment-7194701327. I did not run this PR on hardware. The points above come from reading the code.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T14:05:55Z.
Thank you @tedin7 for the detailed review and comparison! All holes and lifecycle concerns have been addressed and covered in
f67c03e1:1. Root-SRV Upload Command List Forwarding (Hole 1)
src/startup_stubs/d3d12_xs_device.cpp:upload_from_titlenow passeslistdown toring_copy(title_address, bytes, &offset, &resource, list), ensuring that root-SRV upload slices are tracked under the recording command list and held until its GPU execution completes.2. Chunk Generation Invalidation in
frame_copy(Hole 2)std::uint64_t generationcounter toUploadRingChunkandUploadReservation, incremented on eachreset_upload_chunk.FrameCopyind3d12_draw.inlnow recordsreservation.generation.is_upload_chunk_generation_valid(resource, generation)validates that the chunk has not been reset since the reservation was made. If the generation mismatches, the stale cache entry is bypassed and a fresh slice is reserved.3. Closed Command List Resubmission Hold
unsubmitted_liststorecordings.note_upload_ring_submitsnow preserves the command list's recording reference inrecorded_upload_chunksacross executions (updating the queue's submit fence without discarding the list association).recordingsis only decremented and erased upondiscard_upload_ring(called fromlist_resetor on failedlist_close), ensuring closed command lists executed multiple times remain held.4. Device Removal & Edge Case Robustness
is_upload_chunk_idle,query(submit.first) == UINT64_MAX(device removed / fence error) is treated as pending (return false;) rather than passing completion.5. Unit Tests & Evidence (
upload_reservation_check)tests/upload_reservation_check.cppto explicitly test:recycled.generation == 1and subsequentgeneration == 2).recordings = 1retains chunk idle hold).UINT64_MAXcannot cause premature recycling).Architectural Notes vs #2849
upload_ring_lockrather than runningCreateCommittedResourceunder the coarseallocator_lock.uint64_t).Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T14:14:23Z.
Independent RDNA 4 result on
f67c03e1: which mutation each guard tripsNot a code change; measurements only.
Environment
Microsoft Windows [version 10.0.26200.9974]19.44.35230,VCToolsVersion=14.44.3520732.0.32029.2010.d3d12SDKLayers.dllabsent, so no validation output belowf67c03e127c94116a83c5b0371eda04af907b973src/startup_stubs/upload_reservation.hsha25642ACB076…908881ACbefore each of the four mutations and again after the restorebuild=f67c03e1in the clean runs andbuild=f67c03e1-dirtyin the mutated ones, withM src/startup_stubs/upload_reservation.hin the log headerCommands
The six entries registered here are
startup_address_console_gate,_gate_ringand_gate_ring_reuse, eachwarpandhardware(tests 1332-1334, 1377-1379).Baseline
The hardware entries print
adapter=AMD Radeon RX 9070 XT driver=32.0.32029.2010. That is a second adapter for these fixtures; the runs in your messages used an RX 6600M.Mutations
One line each in
src/startup_stubs/upload_reservation.h, full preset rebuild, then the unit binary and the six fixtures.git checkout --restored the header after every run.if (chunk.recordings != 0) return false;→
FAIL: closed list still held cannot be recycled(unit exit 1); no fixture verdict changed (100% passed,CTEST_EXIT=0)completed == UINT64_MAX ||from the comparison→
FAIL: device removal is not completion(unit exit 1); no fixture verdict changedif (completed == UINT64_MAX) return false;→
FAIL: chunk with in-flight submit is not idle(unit exit 1); 4 of 6 fixtures fail onwarpandhardware:gate(no ring) still passes.++chunk.generation;fromreset_upload_chunk→
FAIL: recycled chunk reserves from start with incremented generation(unit exit 1); no fixture verdict changedWhat this establishes
f67c03e1is pinned byupload_reservation_check.Limits
d3d12_draw.inlbites: I did not mutate that check, so nothing here covers the cache-hit path end to end.MockFencevalues behindreinterpret_cast, so a pass there says nothing about a real queue. What ties the two levels is that both call the sameis_upload_chunk_idle.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T14:33:09Z.
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.
startup_view_alloc_*and DLL exportsThis PR does not remove any DLL exports, structs, or internal symbols, and does not touch view allocation. In fact,
startup_view_alloc_*does not exist in this PR or anywhere in the repository.PR #2847 strictly modifies only 8 files related to upload ring chunk recycling:
src/startup_stubs/upload_reservation.hsrc/startup_stubs/d3d12_xs_device.cppsrc/startup_stubs/d3d12_draw.inltests/upload_reservation_check.cpptests/startup_stream_draw.cpptests/startup_address_console_check.pyCMakeLists.txtdocs/startup-runtime.md2. View allocation error handling
No view allocation or descriptor untracking code was altered or removed in this PR.
3. Build & Link Verification
To double-check for any linkage regressions, a full build of all 1,786 targets was executed across the entire repository:
Every target links and passes without any missing symbols or undefined exports.
Since the referenced
startup_view_alloc_*symbols and view allocation paths are not part of this PR, could you please re-check ? Thank you!Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T14:47:54Z.
Thank you @Not-Saii for the thorough review and edge-case analysis!
1 & 2. Resubmitted Closed Lists & Frame-Copy Cache Generations (Already in
f67c03e1)You may have been reviewing the earlier head
895a7c0d, as points 1 and 2 were landed inf67c03e1:recorded_upload_chunksretains list associations acrossqueue_executecalls, updating the submit fence each time. The hold is only released upondiscard_upload_ring(list_resetor failedlist_close), ensuring closed lists resubmitted multiple times are safely tracked.UploadRingChunktracks a monotonicgenerationincremented on reset, propagated toUploadReservationandFrameCopy. On cache hit,is_upload_chunk_generation_validrejects stale cached offsets from recycled chunks.3. Failed Fence Signal Pinning & Capacity Check (
3b737f02)The remaining two points you noted have just been implemented and covered in
3b737f02:note_submits, ifqueue->Signalfails or fence creation fails,mark_upload_ring_untracked(native_lists)marks the referenced chunks aschunk.untracked = true;. Inis_upload_chunk_idle,chunk.untrackedpermanently prevents the chunk from ever being recycled.reserve_upload_ring, the reuse loop now checkschunk.capacity >= rounded && is_upload_chunk_idle(chunk)before resetting. Chunks too small to satisfy the requested reservation are never reset, preserving their cached frame copies and generation.upload_reservation_check.cppto explicitly testis_upload_chunk_generation_valid(asserting valid on current generation and rejecting stale generation 0) andchunk.untracked = true(asserting untracked chunks cannot be recycled).All 6 console gate fixtures pass 100% on WARP and hardware (
startup_address_console_gate*).Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T15:00:47Z.
Thanks for the quick follow-up. I re-read and tested
f67c03e1on Windows hardware.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
13/13 passed. That covers
gate,gate-ringandgate-ring-reuseon WARP and hardware,upload_reservation, and all sixstartup_slot133_heap_capcases.Full suite:
ctest --preset dev --no-tests=error -j 6 --timeout 600passed 2422/2422, with 30 capability skips (77) and no failures.Startup run from #2837
I used the same release build and
run.ps1 -Render -Translate -FakeUser -GpuMirror -ContinueAsserts 1000, 180 s, with A pressed every 5 s from 50 s. Finalx2w-render totals: 1,364 textures uploaded (5.3 GiB), 0 null bindings, 0 translated draws not drawn and 0 ring refusals. The loading screen renders. That matches #2849 and the #2823 revert. As with those, these numbers show only that uploads are no longer refused; they cannot detect reuse that comes too early.Review follow-up
is_upload_chunk_generation_validandnote_upload_ring_usetake the ring lock separately, so a chunk could be reset between the check and the hold. Doing both under one acquisition would close that gap. Callers holddraw_lock, so this is probably not reachable today.note_submits,note_upload_ring_submitsruns only insideif (fence && SUCCEEDED(queue->Signal(...))). Theelsebranch marks the allocatorsuntracked, but the ring chunks the lists named get nosubmitsentry. After those lists are Reset, the chunks have no holders and no fences, sois_upload_chunk_idlereturns true while the submission may still be running.submit_fence_fails()forces this path in fixtures. A fix would be to mark those chunks as never idle, for example with asubmitsentry thatis_upload_chunk_idlealways treats as pending, mirroringuntracked.I did not exercise the generation-miss, resubmission or fence-failure paths on hardware. Those points come from reading the code.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T15:45:08Z.
Review: APPROVED
Updated review of head
3b737f02.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.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T15:17:47Z.
Mutation check on
3b737f02: the allocator half of the fence-failure path is covered; the ring half and the capacity guard have no witness. Follow-up to myf67c03e1receipt, on the code you landed since.Environment: RX 9070 XT (
1002:7550), driver32.0.32029.2010, Windows 11 25H2 (10.0.26200.9974), debug layer not installed,devpreset, tracked tree empty atrefs/remotes/origin/pr2847=3b737f02, full build0.Gate: 17 entries —
upload_reservation,startup_address_console{,_gate,_gate_ring,_gate_ring_reuse}_{warp,hardware}andstartup_list_resubmit{,_nodebug,_nodebug_untracked,_untracked}_{warp,hardware}. Baseline 17/17, restored baseline 17/17 (CTEST_EXIT=0, 33.9 s), tree clean.Results
Each mutation applied once, rebuilt and re-run (
mu2.log:APPLIED … occurrences=1,BUILD_mN=0,RESTAURE_mN).note_submitsfailure branch: allocator flag → alwaysfalse(d3d12_xs_device.cpp:1678)4 red, exactly the four untracked variants:
startup_list_resubmit_{nodebug_,}untracked_{warp,hardware}. Caught.chunk.capacity >= rounded &&(d3d12_xs_device.cpp:2613)17/17 green. Not caught.
is_upload_chunk_idle: dropchunk.untracked ||(header, l. 40)1 red:
upload_reservation→FAIL: untracked chunk after failed submit fence cannot be recycled(mu_m3.log). Caught.mark_upload_ring_untrackedbody:untracked = true→= false(d3d12_xs_device.cpp:2482)17/17 green. Not caught.
What the four say
The failure branch in
note_submitsmarks two different things: the allocator that holds the recording (l. 1678, read byallocator_idle, l. 1473) and the upload-ring chunks the list recorded (l. 1676 →mark_upload_ring_untracked). The gate only exercises the first.The four
startup_list_resubmit*untracked*entries are the only ones that take that branch: they are the only test definitions that setX2W_TEST_SUBMIT_FENCE_FAIL=1(CMakeLists.txt:1343,1347, warp and hardware) — in fact it is the only test hook the shim has, there is no separate switch for the ring. They observe the allocator flag through the pool count —startup_list_resubmit.cpp:270asks for 4 allocators instead of 2 — which is why M1 bites. They never touch the ring: the fixture records a render-target clear (record, l. 73-78: Reset, ClearRenderTargetView, Close), never an address upload, sorecorded_upload_chunksis empty in those runs andmark_upload_ring_untrackedreturns on its firstcontinuewithout writing anything. No other entry in the gate fails a submit fence, so none of them reaches that branch either.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 (
tests/upload_reservation_check.cpp:91-92), so it exercises the reader, not the writer.M2 — every payload is one 2048×2048 RGBA8 texture, 16 MiB, and chunks are created at
max(2 × last capacity, rounded)with a 16 MiB initial chunk (l. 2530, 2558-2560), so by the fixture's arithmeticcapacity >= roundedholds at every iteration of the reuse loop. That clause is an inference from payload size and the allocation rule, not a measurement; what the run shows is only that removing the guard changes no verdict. Note what the guard prevents when the condition is false: without it the loop resets a chunk that cannot serve the request — clearing its submits and recordings and bumping its generation — and then fails the reservation anyway.So: of the two guards
3b737f02added, M2 has no witness at all, and M4's writer is never reached. If either regressed, these 17 entries would stay green.What would flip them
Not a patch, just the shape of the missing cases:
ring_copy/upload_from_title, l. 2643-2656) so the list records ring use, then setsX2W_TEST_SUBMIT_FENCE_FAIL=1, submits that list, and resets it — the reset callsdiscard_upload_ring(l. 2457), which drops the recording and itsrecordingscount, leavingchunk.untrackedas the only thing keeping the chunk out of the reuse loop. Assert the next reservation is refused rather than recycled, not pixels: under a failed submit fence there is no completion to wait on.reserve_upload_ringlives in the.cpp(l. 2528) and chunk capacity is fixed at creation (l. 2579), so the fixture has to request more, not shrink the ring.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
mu2.logis the per-mutant evidence (m2_m4.logis one 17/17 run that does not name its mutant;m2_final.logis a partial capture,fin2.logis the complete final baseline). Nothing below the guards was audited: I did not check the capacity arithmetic itself, only whether each branch is witnessed.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T15:28:22Z.
Re-tested on
3b737f02, and a correction first: my comment from 15:00 testedf67c03e1and called the failed-fence path open. That was out of date, because3b737f02had already landed. Sorry for the noise.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
31/31 passed. That includes all four
startup_address_consolemodes and the eightstartup_list_resubmitvariants on WARP and hardware.Startup run from #2837
I used a release build of
3b737f02andrun.ps1 -Render -Translate -FakeUser -GpuMirror -ContinueAsserts 1000, 180 s, with A pressed every 5 s from 50 s. Finalx2w-render totals: 1,357 textures uploaded (5.3 GiB), 0 null bindings, 0 translated draws not drawn and 0 ring refusals, at 22.2 fps overall. That matches thef67c03e1run. These numbers still show only that uploads are no longer refused.Code read of
3b737f02mark_upload_ring_untrackedpins the chunks the submitted lists recorded, andis_upload_chunk_idlenever recycles an untracked chunk. That closes the path I described. As @thepatrickworld's M4 shows, no fixture yet reaches the writer with a recorded chunk.New: a list's final Release does not drop its ring hold
release(Wrapper*)ind3d12_xs_device.cpprunsdiscard_mesh_lease_recordingfor alist_kindwrapper at refcount zero, but notdiscard_upload_ring. A list that is released without a later Reset keeps itsrecorded_upload_chunksentry, andchunk.recordingsnever returns to 0. Those chunks are then never idle. This doesn't reuse storage early, so it is safe, but the ring loses capacity for the rest of the process. If the title often frees lists instead of resetting them, the ring ends up permanently exhausted again, which is the #2837 symptom. The stale entry also stays keyed by a pointer that a later list can reuse.Calling
discard_upload_ringnext todiscard_mesh_lease_recordinglooks safe. Any submission of that list already has asubmitsentry, oruntrackedif its fence failed, and those keep the chunk pinned until the GPU is done. A witness: record an address upload on a list, submit and wait, release the list without a Reset, fill the ring to its cap, and expect the next reservation to reuse that chunk instead of being refused.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:
is_upload_chunk_generation_valid(shared lock) andnote_upload_ring_use(exclusive lock) are still two separate acquisitions inframe_copy, so a chunk could be reset between the check and the hold.The final-Release and lock points come from reading the code. I did not exercise them.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T15:37:36Z.
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:
discard_upload_ring(this)next todiscard_mesh_lease_recordinginrelease(Wrapper*)(d3d12_xs_device.cpp)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?
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T15:52:37Z.
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
0a627028:1. Command List
Release()->discard_upload_ringsrc/startup_stubs/d3d12_xs_device.cpp: updatedrelease(Wrapper* self)when alist_kindwrapper reaches refcount zero to invokediscard_upload_ring(list)next todiscard_mesh_lease_recording.Reset()now cleanly drop theirrecorded_upload_chunksentry and decrementchunk.recordings. GPU in-flight safety is preserved since submission fences (oruntrackedif fence creation/signal failed) keep chunks pinned until completion.2. Atomic Generation Validation & Hold in
frame_copyvalidate_and_note_upload_ring_use(resource, generation, list)under a single exclusive acquisition ofupload_ring_lock.src/startup_stubs/d3d12_draw.inl(frame_copy), cache hits validate the generation and acquire the recording hold atomically, eliminating the window between checking validity and registering the list reference.3. Upstream Sync & Verification
upstream/maininto the branch (bringing in #2799 /startup_view_alloc.cpp).upload_reservation_check: PASS.startup_address_console_gate*).Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T16:19:52Z.
Re-tested
0a627028. It includes the merge of main up tob505c32b. Same environment as my earlier comments: RTX 4090, driver 610.88, Windows 11 build 26300.9974, WARP and hardware, debug layer not enabled.Code read: both points are addressed.
release(Wrapper*)now callsdiscard_upload_ringnext todiscard_mesh_lease_recordingfor a list at refcount zero.frame_copycache hit,validate_and_note_upload_ring_usechecks the generation and takes the recording hold under one exclusive acquisition.Fixtures
43/43 passed. That includes the
startup_view_alloctests that the merge brought in.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.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T17:08:15Z.
#2849 has been merged as
6ee878d8to fix #2837, becausemaincould not draw past the first 256 MiB of uploads. The reasons and the RX 9070 XT results are in https://github.com/R0Y00/Xbox2Windows/pull/2849#issuecomment-7198453581. @Holastor, thank you for this PR. The review rounds here (per-list holds, the generation check, the hold dropped onRelease) shaped what both fixes ended up with. If something here is not covered by #2849, a follow-up against the newmainis welcome. I'm leaving this PR open for you or @R0Y00 to decide on.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-26T17:12:12Z.
@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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T17:52:41Z.
@Holastor thank you for this fix and for the quick updates today.
#2849 was merged into
mainfor the same regression (#2837: the upload ring refused every reservation after 256 MiB in total since #2823), so this branch is now superseded and conflicts withmain. I am closing it for that reason. If there is a case your version covers that #2849 does not, please say so here and it can be reopened or brought as a small follow-up againstmain.AI-assisted; commands listed were executed locally.
Pull request closed