Repository navigation
startup: opt-in release of upload ring chunks at a fenced submit - #2949
Conversation
X2W_D3D12_RING_RELEASE_AT_SUBMIT=1 lets a closed command list stop holding its
upload ring chunks once its submit is fenced, instead of holding them until
Reset. The queue fence alone then keeps the chunks from reuse until the GPU has
passed it. In this mode the ring grows in 16 MiB chunks up to 512 MiB.
A later submit of the same list before its Reset fences its chunks again when
their generation is unchanged; a chunk recycled in between is counted and
logged. Unset, the ring behaves as before (doubling chunks up to 256 MiB,
holds until Reset).
- upload_reservation.h: ReleasedUploadChunks, release_upload_chunks_at_submit,
resubmitted_upload_chunks; chunk arrays sized for 512 MiB.
- d3d12_xs_device.cpp: switch, release in note_submits, resubmit check,
cleanup at Reset and Release, ring sizing.
- Tests: upload_reservation check_release_at_submit; new
startup_address_console_gate_ring_keep{,_release}_{warp,hardware}; fixtures
that describe the default ring clear the switch for their process.
- Docs: switch row and ring paragraph in docs/startup-runtime.md, experiment
note docs/experiments/startup-upload-ring-release-at-submit.md.
Refs R0Y00#2837, R0Y00#2849.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
The release-after-submit experiment has a correctness gap in the resubmit case documented by the fixture. note_submits discovers a recycled generation only after ExecuteCommandLists, and the resubmit fences only the intact chunks. The re-executed list can therefore fetch overwritten upload data, and the recycled chunk is also unprotected from later ring reuse while that draw runs. Please detect this before queue submission and either refuse the stale resubmit or retain/reconstruct the recorded bytes. The fixture should assert that the stale list did not execute with replacement bytes; logging the post-submit detection alone cannot establish that.
…-release-at-submit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KelboLive
left a comment
There was a problem hiding this comment.
PR #2949 by @lukaslw-lab — startup: opt-in release of upload ring chunks at a fenced submit
What works
- Clean opt-in via environment variable; completely zero-cost when unset (static const bool on)
- upload_reservation.h additions are minimal and focused: ReleasedUploadChunks struct, release_upload_chunks_at_submit, resubmitted_upload_chunks
- Correct fence guarding: released chunks stay fenced until the GPU passes, preventing premature reuse
- generation tracking properly detects reused-vs-intact chunks on resubmit
- upload ring grows in 16 MiB chunks up to 512 MiB (consistent with initial_upload_chunk_bytes, 32 chunks fits in UploadChunkMask uint32_t)
- note_submits updates chunks mask to include both original holds AND released chunks that need refencing
- Test coverage: gate-ring-keep (without switch, ring stalls at 256 MiB) and gate-ring-keep-release (with switch, ring releases)
- upload_slot133_heap_cap_check.cpp cleared the env var to avoid interfering with default ring tests
- Good doc quality in startup-upload-ring-release-at-submit.md
Issues
- release_upload_chunks_at_submit does not validate that the list's fence is actually signalled before releasing; the caller must ensure that. If someone calls this outside note_submits with a non-signaled fence, chunks become reusable while the GPU still writes to them. Consider adding a DEBUG assertion that chunks[i].fence_value <= queue fence value.
- note_submits only releases held chunks when submit_fence signals successfully (the code path after if (submit_fence_fails()) return). If the fence fails, the list remains in the released_upload_chunks map and its chunks never get cleaned up. Consider clearing the map entry when the fence fails to avoid memory growth.
- The UploadChunkMask type is uint32_t with max_upload_chunks = 32 (512 MiB / 16 MiB). The loop in release_upload_chunks_at_submit does ++i, recording >>= 1 which correctly iterates at most 32 times, but a future increase beyond 32 MiB chunks would silently truncate. The static_assert(max_upload_chunks <= 32) catches overflows but not undersized masks.
- resubmitted_upload_chunks iterates all 32 indices even when released.chunks has few bits set. For correctness this is fine, but worth noting that a bit-iteration pattern (while remaining) would scale better if max_upload_chunks ever changes.
- X2W_D3D12_RING_RELEASE_AT_SUBMIT=1 and the ring-size increase together add ~1 GiB process commit. Consider documenting this in startup-runtime.md alongside other memory-affecting switches.
Recommendations
- Add a runtime assert in note_submits after release_upload_chunks_at_submit: assert(list->own().upload_chunks == 0) to verify the list's original holds were fully released.
- Clear released_upload_chunks[list] in the submit_fence_fails path to avoid leaking map entries.
- In the gate-ring-keep-release test mode, add a negative check: verify that without the env var, the ring does refuse beyond 256 MiB (already covered by gate-ring-keep, but could note it in the test doc comment).
Overall
Well-architected memory optimization that cleanly separates the opt-in path. The generation-based tracking is elegant and the fence-guarding is correct. After the fence-failure cleanup fix, this should be solid.
With X2W_D3D12_RING_RELEASE_AT_SUBMIT=1, a closed list submitted again after one of its released upload chunks was reused would read replaced bytes. The check ran in note_submits, after ExecuteCommandLists, so it could only log. queue_execute now checks each closed list before the execute, with draw_lock and allocator_lock held (released_chunks_recycled). Such a list is left out of that execute, counted and logged, and stays refused until its Reset; the other lists of the call still run. The locks stay held through note_submits, which therefore only re-fences intact chunks. gate-ring-keep-release now reads the target back after A's second submit and asserts the right half still holds payload 32 (A's last draw is payload 31). With the check disabled, A runs and its payload 0 draw shows the replacement bytes (payload 32's colour) on the left half. Docs: the experiment note and docs/startup-runtime.md describe the refusal; the switch row states the ~1 GiB commit cost. Refs R0Y00#2948. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fusal Same settings on a later main: buffer null bindings 50,665 -> 0, no reservation refusals, 0 stale resubmits refused, commit peak 17.9 -> 18.0 GiB, no black frames seen. The switch row now says the ring can add up to about 1 GiB of commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, agreed: the post-submit report could not stop the stale execute. A stale resubmit is now refused before the queue submits it. Change (
Startup run repeated on
|
R0Y00
left a comment
There was a problem hiding this comment.
Independent integration review of 8c183700 with main 6aa59440 (e8e855c8 locally). The recycled-generation check now runs before ExecuteCommandLists, under both locks through submission and refencing. Only accepted lists reach queue execution and GPU-write bookkeeping. The pixel readback confirms that the rejected resubmission left both halves unchanged.
ctest --preset <dev|release> --no-tests=error -V -R '^(upload_reservation|startup_address_console_gate_ring_keep(_release)?_(warp|hardware)|startup_stream_draw_warp|startup_table_alias_warp)$' passed 7/7 in Debug and 7/7 in Release /O2, with no skips. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, and WARP 10.0.26100.9818. The table-alias fixture used the debug layer and GPU-based validation and reported zero debug errors. The ring fixture ran with the debug layer off. The contributor’s broader matrix recorded two matching failures on its unchanged baseline.
Hosted Windows, Linux Python and gfx1013 fixture checks are green. The hosted /O2 job was skipped and the local /O2 run above passed. The matching issue is #2948.
Title: startup: opt-in release of upload ring chunks at a fenced submit
Change
Fixes #ISSUE (after #2849 the upload ring still runs out in the post-load animation). Refs #2837, #2849.
X2W_D3D12_RING_RELEASE_AT_SUBMIT=1(opt-in): a closed command list stops holding its upload ring chunks once its submit is fenced, instead of holding them until Reset. The queue fence still keeps the chunks from reuse until the GPU has passed it. Unset, the ring behaves exactly as onmain.upload_reservation.h:ReleasedUploadChunks,release_upload_chunks_at_submit,resubmitted_upload_chunks; chunk arrays sized for 512 MiB.d3d12_xs_device.cpp:note_submitsreleases each submitted list's holds after a signalled fence (no signal: nothing changes).queue_executeleaves that list out ofExecuteCommandListsbefore the execute (released_chunks_recycled, underdraw_lock+allocator_lock), counts and logs it (... were reused; refused, it is not executed); it stays refused until its Reset, and the other lists of the call still run.startup_list_resubmitstep 2). With the switch, such a resubmit after a chunk reuse is refused, so that list does not run. The mode suits titles that Reset a list before submitting it again; the main executable did so in every measured submit (0 of more than 500,000 over five runs).docs/startup-runtime.md;docs/experiments/startup-upload-ring-release-at-submit.md.discard_upload_chunksat the same call sites and startup: count a failed buffer copy as the null cause ring_full and refuse the draw; report upload ring statistics #2864 areserve_upload_ringcaller; text conflicts only, whichever lands second.Verification
Windows 10 22H2, i7-4790K, RTX 3080 Ti (NVIDIA 32.0.16.1047) and WARP; dev and release; commit
33d31412on6ee878d8.35 tests per preset, run with the switch unset and set: 33/35 pass in each run. The two failures are
startup_list_resubmit_nodebug_hardwareandstartup_list_resubmit_nodebug_untracked_hardware(SegFault). Both fail the same way on unmodifiedmain6ee878d8on this host, with and without the switch.upload_reservation, newcheck_release_at_submit: release, fence guard, reuse, resubmit with one intact and one reused chunk, and the re-fence. Negative controls (local mutations): keeping the holds failsrelease: holds dropped; ignoring generations failsa resubmit finds chunk 1 intact and chunk 0 reused.startup_address_console_gate_ring_keep{,_release}_{warp,hardware}: list A uploads 32 × 16 MiB and is never Reset; a second list then draws payload 32 over the right half; A is submitted again, and the target is read back after that submit.startup_address_console_gate_ring{,_reuse},startup_slot133_heap_cap_capped), so they keep testing the default when it is set in the environment.bufferupload ring reservation refusedChecklist
docs/startup-runtime.md, experiment note)AI-assisted: the change, tests and this description were written with Claude; I ran the startup comparison.
🤖 Generated with Claude Code