Repository navigation
RR runtime: keep an instance's heaps until its last frame completes; no wait at destroy - #82
Merged
Merged
Conversation
…roy unchanged) The deferred-release list of the RR runtime moves into a header-only RetireList (any object with Release, a counted flag for the live-resource total) so that a CPU test can drive it with a fake marker value and fake objects that count Release. The instance destroy goes through retire_instance with its current behaviour: the buffers wait for the frame marker, the descriptor and query heaps are released after the bounded wait. test_rr_retire builds tests/rr_retire_test.cpp and fails here: a destroy with the marker behind the instance's last frame releases both heaps (issue #63). The next commit fixes it. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…no wait at destroy Fixes the premature release of issue #63: - the shader-visible descriptor heap and the timestamp query heap go to the retire list with the instance's last serial, as its buffers do (not counted in live resources); they are released when the frame marker reaches that serial, at device drop, or once the device is removed (pump releases everything kept then); never on a timeout; - a destroy while that frame is still in flight logs one line and keeps the objects; - the 2 s wait before the heap release is gone, and so is the 2 s wait for the timing harvest in destroy_locked: destroy harvests what has completed and waits for nothing while it holds the runtime-wide lock. test_rr_retire now passes. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 13, 2026 21:24
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…lete Review of #82: a later serial does not prove that an earlier list ran (recording order is not submission order), and a device switch released the old device's in-flight objects without proof. - Every list the runtime records into (frame, pass-through, transient copy) writes its serial into a marker slot of its own (rr_retire.h ListMarks); a slot is reused only after its holder proved complete. - An object is released only when every list that may use it proved complete: instance objects wait for all the instance's lists, an old arena or output texture for the instance's lists, a transient copy for its copy list and every frame / pass-through that read it. - Frame and pass-through slots are taken only when their last list proved complete (no "serial % 8" reuse on a later serial). - Device switch: the old device's pending lists, deferred objects, shared pipelines / buffers, marker buffer and device reference are parked until each list proved complete or the device is removed; at most 4 old devices are tracked, beyond that the oldest is left allocated (never released early); both logged. - CPU test: out-of-order submission, a never-submitted list, slot reuse, device switch with work pending, removal, the bound (27 checks). Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
A host run stopped by a time cap lost its buffered output, so a long step (the exact-head perf frames at 2560x1440 take most of a second each) could not be told from a hang. - rr_test_host: stdout / stderr unbuffered; one "step N <command> at T s" line per job command and one per 100 perf frames on stderr. - e2e.py: --gpu-timeout (default 900 s) for the host run; on a failure or timeout host.log keeps what the host printed and the error names the last step; phase lines for the GPU run and the CPU reference; --perf help says to use 0 inside a short GPU time slot. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as draft
November 14, 2026 18:41
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 14, 2026 18:51
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…orgotten Final review of #82: - Marker wraparound: the GPU writes only the low 32 bits of a serial and a free slot keeps its last completed value. ListMarks now remembers each slot's value and skips a serial whose low 32 bits equal it (0 for a fresh slot), so a stale value can never prove a new list after the serials wrap. CPU test forces the wrap (skip_to test hook). - Device-park cap: an old device is never forgotten without being released. Beyond 4 tracked, the oldest is released at once if its lists completed or its device is removed (GetDeviceRemovedReason); otherwise its marker slots are polled for at most 2 s and it is released when they complete; if still pending it stays tracked (soft cap, logged). RetireList::abandon is removed. CPU test: 6 switches with work pending (none completes: all kept, then released once each when they do; the oldest completes during the wait; the oldest's device removed). - The fake GPU of the CPU test maps serials to slots in a std::map (the wraparound test uses serials above 2^32). Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #63
The RR runtime released an instance's shader-visible descriptor heap and timestamp query heap at destroy after a
bounded wait, whether or not the game's command list that uses them had finished, and the destroy could stall the game
thread for up to 2 s + 2 s while holding the runtime-wide lock. This PR applies the lifetime rule shared by #63, #58
and #62, with completion proven per command list. The first version of this PR used a single runtime-wide marker,
and the batch review blocked it; that is fixed here (see "Batch review findings").
Batch review findings, one by one
1. Blocker: a later serial does not prove that an earlier recorded list ran. Fixed.
(
rr_retire.hListMarks). This covers a frame (evaluate), a pass-through and a transient copy (retain).A list counts as complete only when its own slot holds its serial. A later list completing proves nothing about it.
belongs to its current holder: a stale value from the previous holder never proves the new one.
complete (
Instance::lists);included;
defer_releaseof buffers (old arena, old output texture, transient copies) now takes the lists that use theobject, not a serial;
serial % 8and waited until the shared marker passed the slot's old serial. A slot is now taken only when its ownlast list has proved complete. The wait is still at most 5 s, and the evaluate fails as before if no slot frees up.
released when the device is removed. At most 1024 lists can be pending per device; past that, nothing more is recorded
until one completes, and one log line says so.
2. Major: a device switch released the old device's pending objects. Fixed.
drop_device(set-device with another device, the end of prepare, test shutdown) no longer releases anything forwhich a list of that device has not proved complete. Instead it parks the old device's state (
ParkedSet) untileach of its lists proves complete, or
GetDeviceRemovedReasonreports the old device removed. The parked state is:ListMarksand deferred objects;and its live transient copies;
tracking (reclaimed at process exit) and are never released without proof.
complete, or device removed), and one if the bound applies.
Final review findings, one by one
1. Major: a stale marker could falsely complete a new list after the 32-bit value wraps. Fixed.
ListMarksnow records the value each slot holds: 0 when fresh, or the low 32 bits of its last proven holder.beginskips any serial whose low 32 bits equal the chosen slot's current value, so the value a new list waits foralways differs from what the slot already holds, however many serials have gone by. A skipped serial is never handed
out. This replaces the old "never low 32 bits = 0" rule, which covered fresh slots only.
wraparound_stale_marker): a slot is left free holdingxwhile serials jump pastx + 2^32 - 1(testhook
skip_to), and the next list is assigned to that slot. Its serial differs fromxin the low 32 bits, and thestale value does not prove it. The test also checks that a fresh slot never gets a serial ending in 32 zero bits.
2. Major: the cap of 4 tracked old devices forgot pending generations, leaking them permanently. Fixed.
removed.
RetireList::abandonis removed.GetDeviceRemovedReasonreports its device removed.switch), and it is released as soon as they complete.
old devices now tracked. Later pumps still release it when its lists complete or its device is removed.
device_switch_soft_cap), 6 switches with work pending:2000 ms; the soft cap is logged. When the lists complete later, every object of all 6 is released exactly once;
Other changes
rr_test_hostwrites stdout and stderr unbuffered. It printsone
step N <command> at T sline per job command and one line per 100 perf frames, so a run stopped by a time capkeeps its output and names the step it was in.
e2e.pygets--gpu-timeout(default 900 s); on a failure ortimeout the error names the last step. It also prints a line when the GPU run starts and when the CPU reference
starts.
destroystill waits for nothing (rule point 3 of RR releases its descriptor heap and query heap at destroy without waiting for the GPU #63). The 2 s timing-harvest wait stays removed: frames still inflight at destroy are left out of the last timing window.
Test
python -m unittest -v clean.rr_f.runtime.tests.test_rr_retirebuildsrr_retire_test.cpp, which uses fake objectsand a fake marker buffer; "the GPU runs list s" is the write of s into s's slot. Passes, 40 of 40 checks, MSVC /W4
with no warnings. Besides the wraparound and soft-cap tests above, the checks cover:
descriptor heap and query heap are not released. They are released once A completes. The same holds for one
instance with frames 1 and 2 in flight when frame 2 completes first;
still kept. They are released once each at device removal;
completed holder; a stale slot value does not prove the new holder; a cancelled (unrecorded) list gives its slot back;
is pending. Each is released once when the list completes on the old device, or when the old device is removed,
with one log line.
For comparison, the same out-of-order scenario against the first version's
rr_retire.h(head94e02b0, sharedmarker) releases A's heap while A has not run. This was a scratch program, not committed.
GPU run
Built from this branch: the runtime (
rr_runtime.cppand the rest ofsrc/) andrr_test_host. The embedded kernellibrary comes from a build of main
234515a(kernels.json sha256879012b1…, the same manifest as a second,independent build of main). This is valid for three reasons:
234515aand this branch's base;build_dx12.pychanged only in its kernel-set selection (Model L, frame generation), which invalidates the cache keybut not the RR compiles;
wg_platform.hlsliaddition sits behind#if WG_REV_ORDER, which no RR kernel defines.I also recompiled 16 RR kernels from this tree, and all 16 are byte-identical to that build's.
Full e2e:
python -m clean.rr_f.runtime.tests.e2e --perf 0withWG_RR_COMPILE_WAIT_ALL=1, tagloop included, theGPU part in a GPU time slot (cap 170 s). PASS.
Host checks in the same run: retag (a copy released before its list ran is kept until the list runs, then freed) ok
twice; arrayin ok; border ok twice; leak 6 cycles with live resources 3 → 3, instances 0, deferred 0, video memory
unchanged; end with live 3, instances 0, deferred 0.
After the final-review fixes (marker wraparound, soft park cap), the full e2e was run once more on this branch
(
--perf 0, the GPU part in a GPU time slot: 7.0 s, rc 0). PASS, with the same results as the table above:every stage 74 / 74, lifecycle 75 / 75, aliased = unaliased 75 / 75, video memory growth 13.5 MiB over 200 frames.
The host checks (retag twice, arrayin, border twice, leak 6 cycles live 3 -> 3, end with deferred 0) were all ok.
Since that run, main was merged once more; the merge touched no RR or D3D12 kernel/build file.
10 repeat runs of the same GPU job, each in its own GPU time slot, each written to its own folder. Every dumped
frame file (outputs, alpha outputs, and the arena, which holds every state image), 372 files per run, was compared
byte for byte with the run verified above, together with the host's own checks. 10 of 10 passed; the longest took
8.6 s.
The one run that hit the time cap. The first attempt used e2e's default
--perf 600. That job appends timing-onlyperf lines after the checks: 600 exact + 600 exact-ext + 1200 fast frames at 2560x1440, then 60 more. The checks
themselves had all finished within about 8 s, every frame with rc 0. The exact head costs about 0.65 s of GPU time
per frame at that size, so the perf lines alone need more than 13 minutes, and the 170 s cap stopped the run. It was
not a hang. A perf-only A/B run of the same job (30 exact + 60 fast frames, same host, one slot each) gives the same
speed on main
234515aand on this branch: 649.1 vs 649.0 ms of GPU time per exact frame, 19.48 s wall each. Thehost's output of that first attempt was lost to stdout buffering when the cap stopped it; the per-step progress lines
above fix that. The perf timings are not part of the correctness checks.
Tested
test_rr_retire: 40 of 40 checks (MSVC 19.51, Windows);python -m unittest discover -s clean/rr_f/tests -t .:241 tests OK (7 skipped);
test_rr_retire+test_model_pack+test_model_bounds: 8 tests OK.rr_runtime.cppandrr_test_host.cppbuild with the runtime build's compiler flags (/W3, no new warnings).Not tested
real device switch with work pending, and a real device removal. The CPU test covers the logic; the e2e covers the
normal create / evaluate / destroy paths and the transient-copy paths on hardware.
(never released early). The runtime already disables RR for the session after such an exception.
--perf 600inside a GPU slot: it cannot fit in 170 s on main or on this branch (above).