vkback: decouple deferred remap releases from vkback-submit callback queue #199
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!199
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-199"
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?
@Mhyster on GitHub · 2026-12-02 07:34 UTC · original
Mhyster:opt/vkback-remap-release-decouple→main· +175 −5 · 3 files · 1 commits · openWhat
Decouples deferred page-mapping remap releases (
maporder::release) fromvkback-submit's blockingJob::Call/ present queue (greenfield/vkback/src/submit.rs,live.rs,lib.rs):Live::remap_frontcalledself.be.queue_call(Box::new(move || crate::maporder::release(seq))), which enqueued aJob::Callbehind any in-flightvkQueuePresent/ blit callbacks and forced an immediatevkQueueSubmitboundary even when all submissions prior to the remap had already been handed to the GPU queue.Submittershares a lightweightRemapGate(submitted: AtomicU64,pending: Mutex<RemapPending>) withvkback-submit:VulkanBackend::release_remap(seq)flushes any held command buffers and checkssubmitted >= self.serial. If every prior submission has already gone throughdev::submit_on(which publishesumem::Memory::reader_submitted), it callsmaporder::release(seq)immediately on the renderer thread without touchingvkback-submitor waiting behind presents.(self.serial, seq)inRemapGate(re-checkingsubmittedunder the lock so no wakeup can be lost), andvkback-submitcallsgate.advance(serial, maporder::release)immediately afterdev::submit_onreturns — beforeJob::Callpresents or subsequent batches'tape::resolve.submit_now) also advanceRemapGate, andgate.closedrains any remaining entries whenvkback-submitexits so teardown cannot hang.Addresses the remap-wait tail latency noted in
docs/TASKS.md(present waits for the remapper) while preserving the exact console queue-order invariant:maporder::releasestill runs only afterdev::submit_onhas publishedreader_submittedfor every prior submission.The reference
vkd3d-protonlibs/vkd3d/command.c(d3d12_command_queue_enqueue_callback/VKD3D_SUBMISSION_QUEUE_USING_CALLBACK):queue_callexists for Vulkan queue operations such as swapchain present that must run on the queue worker;maporder::releaseonly signals a CPU condvar oncereader_submittedis published, so gating it on the submitted timeline serial avoids serializing it behind swapchain presents.Evidence
greenfield/vkback/src/submit.rs:remap_gate_releases_immediately_when_already_submittedremap_gate_defers_until_serial_advances_and_preserves_order(includingclosedrain)remap_gate_concurrent_release_and_advance_drops_nothing(2,000-serial multi-threaded race stress test)cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)(171 passed, 3 ignored; 6/6 policy tests includingfile_size)cargo clippy --all-targets --locked -- -D warningson root native crates,greenfield,greenfield/wine, andgreenfield/vkback/translate.frames.py) and Vulkan validation run (house scene) could not be run in this session (no live game run performed);cargo xwin clippyruns in GitHub Actions CI.Checklist (docs/AGENTS.md)
docs/TASKS.mdnot edited, the fixed item named above (rule 29)unsafeblock has a// SAFETY:comment; no raw pointer around the borrow checker (rule 36)TRANSLATOR_VERSIONbumped if the translator's output changes (rule 27)@firefloc on GitHub · 2026-12-02 10:04 UTC · original
I reproduced an ordering race in
RemapGateat91bd8cawith a unit test that holds the first release callback open.after_serial = 1.advance(1)and pause inside the callback before it publishes remap 10.after_serial. The fast path sees serial 1 and publishes 11. Resume the first callback.The test records
[11, 10]with the PR as written. The remapper acknowledges a single high-water mark, somaporder::is_done(10)can return true after 11 is acknowledged while 10 is still pending.A local candidate uses one mutex for the submitted serial, the FIFO of pending remaps, and publication to
maporder::release. It drains the ready prefix in registration order and advances the gate after a successful submission. With the candidate, the same test returns[10, 11]. The vkback suite on RADV passed 207 tests (4 ignored), and neither candidate run showed a premature acknowledgement.In a warm-cache prison-cell A/B/B/A on RX 7900 XTX, the candidate reduced renderer-to-release p99 from 37.5–41.3 ms to 36.4–36.8 ms. Mean FPS moved in opposite directions between the two pairs. The longer stage here was still remapper take-to-ack, so the performance regression in #171 remains open.
@TheRifai on GitHub · 2026-12-02 15:23 UTC · original
Current-main numbers for the TASKS "Remap release behind the submission thread" row, in case they help the race fix in this PR. Seen on main
963df8e(same code asd59b4f8apart from docs), RX 9070 XT / RADV 26.3.1, GE-Proton11-16, Series X 3840x2160, housert3, 85 s warm-store run withVKB_FREC_ARM=30,34(gpuprof frames serialised, so treat the GPU-adjacent numbers as upper bounds):From the final
page mappings:stats line: deferred remaps released 1,493 (release→done 11,236.8 ms total, 7.53 ms each, longest 398.8 ms, 25 over 50 ms); renderer blocked on one at a present 1,635.1 ms cumulative, longest 178.1 ms, given up 0; reads while a remap was under way 3,508, all on thefillpath.registered not reached 0,reached but never registered 0— the gate itself did not lose a remap in this run.So on the reference card about 1.6 s of a short house run is presents waiting on deferred remaps, with a 178 ms longest single wait; the PR's FIFO/serial fix is aimed at exactly this. I have not reproduced the ordering race you found, and no code change from me.
@vktory6 on GitHub · 2026-12-02 15:28 UTC · original
Thanks, and thanks to firefloc for the race test. That race is real: the PR's own test asserts out-of-order release
[101, 100], butmaporderacknowledges by high-water mark, so a later release can acknowledge an earlier one that hasn't run. Two fixes:submit_nowcurrently advances it even when the submit failed.firefloc's A B B A shows p99 −1 to −4 ms, so it is worth finishing. Note that #218 touches the same code in live.rs.
@firefloc on GitHub · 2026-12-02 17:30 UTC · original
I rechecked
91bd8caand reproduced two ordering failures in a standalone test of the extracted gate. Pausing the release of sequence 10 lets 11 publish first. A later FIFO entry with a lower serial can also pass an earlier entry that is still ineligible. The stress test in the PR sorts the result, so it cannot detect either inversion before the high-water-mark acknowledgement.The submit-success check applies to both
submit_nowand the worker closure. The worker can proceed to another batch after a failed submit, so a later successful serial must also be prevented from crossing a failed predecessor. At present,maporder::{is_done, wait_done}can report success when the renderer stops. Shutdown after submission failure should wake waiters with an explicit failure instead of publishing or acknowledging entries that depended on that submission.A standalone candidate with one mutex over the FIFO and publication and a separate failed state passed six deterministic Rust tests, including a failed submission followed by a higher-serial success and shutdown. This tests the ordering algorithm in isolation. Real call sites, error propagation, and lock order still need integration coverage. #218 also changes the signature of
maporder::release, so preserve the queue attribution when reconciling the branches.@firefloc on GitHub · 2026-12-02 18:50 UTC · original
I integrated the candidate in an isolated copy of
91bd8ca. The submission gate protects the serial, deferred FIFO, and release publication together. The shared helper is used by both the direct and worker submission paths. A failed submit prevents a later successful serial and shutdown from releasing work that was never submitted. An error is reported to waiters on the failure path.The integration also covers a second edge case: a higher remap sequence may already be acknowledged when an older deferred sequence is first handed to the remapper.
maporderkeeps the protocol's numeric high-water mark, but applies it only to sequences that have actually been handed over, including when a later acknowledgement repeats the same high-water mark.The local suite passed 178 vkback tests with 3 ignored. Clippy and the Unix/Windows compile checks passed. The submission failure was injected into the shared helper; this did not exercise a live driver failure. Lock-order review, reconciliation with #218, and validation in the title are still open.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.