WIP: perf(vk): a submit thread sends the submits the replay holds where nothing else batches them (RX_VK_SUBMIT_WORKER, off) #2156
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2156
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-submit-worker"
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?
Summary
Where submits are neither batched (
RX_VK_BATCH) nor the recorder thread's, the thread that replays a recording makes itsvkQueueSubmit2itself, at every part's end. #1995 had a submit thread for that; it was taken out of #1995 (4f6b9d10)because it was unmeasured and its review found ten points in it. This brings it back on its own, with those points
answered, off by default (an attempt:
RX_VK_SUBMIT_WORKER=1turns it on) until the in-game comparison exists.With the thread on, a recording's submit is held as a batched one is, and a thread of its own (
mkw_vk submit,submit_worker_main) sends what is held at once, under the queue's lock (dev.present_mu), in the order it was held, whilethe replay goes on with the next part. Nothing waits on the thread: every wait for a value, a fence, a recording or a slot
sends what is held first, as with
RX_VK_BATCH. Against the review on #1995:that cannot be started leaves every submit to the replaying thread, with nothing held (L1);
replay_fatal) when the thread is on: none of its signals wouldcome and whatever waits for them would wait for good (L3).
RX_VK_BATCH's own batches keep main's handling;vkQueueSubmit2and its submits are counted in atomic counters of its own, not inPROF_QSUBMIT, thereplaying thread's phase that the stats lines and the menu read without a lock (L4);
submit_worker_stop, 2 s at most)before the swapchain is let go; what it did not send goes with the close's own flush (L5). A stop that joined the thread
leaves no worker behind (
batch_onand the kick say so: the replaying thread submits directly again). A thread that didnot stop in 2 s is in a driver submit, or waits for the queue's lock behind one: the close then lets nothing go and
returns, as it does with a present still running. The back end never destroys the device (no
vkDestroyDevicecall),so that driver call cannot outlive it. The thread is started once a process: asked again it starts nothing;
RX_VK_BATCHset or batched submits, with the recorder thread,with
RX_VK_GPU_TIMELINE(its submit times are taken where the replaying thread submits, L12) or withRX_VK_BENCH;the log says which;
nvnSyncWait) never wait for thequeue's lock: a busy queue is left to the thread, and a flush they make is taken from the budget (L10);
reflex_split_wanted), so a delayed threadnever tags the next frame's commands with the first frame's NVIDIA Reflex id (L11);
vkQueueSubmit2, and the flushes by reason with the mean timefrom held to submitted, to tell driver time moved from delay added (L17);
tests/test_submit_worker.pyruns the source's thread against a fake queue (L14), below.The result expected: the same picture, and the queue submit off the replaying thread; whether that saves anything is not
known: it is not measured (the A/B is in Still to test).
The switch:
RX_VK_SUBMIT_WORKER(new, an attempt, bool, its row ingpu/vk/switches.def, a row for the thread indocs/dev/reference/threads.md), off by default, as dazemc's review asks (72747): unset, empty,0,off,falseornois #1995's code, every submit made by the thread that replays it;1turns the thread on. Read once at the replay'sstart. It acts only with Threaded rendering off: with it on, the recorder thread or the render thread makes the submits.
This is still on #1995 @
9e640b66, which conflicts with current main ingpu/vk/vk_replay.cpp(as #1994 does): the stackis not rebased in this push (their farm requests and runtimes are on their current heads); the three are rebased together
at #1995's next push.
Depends on #1995 (
RX_VK_SLOT_BY_TIMELINE, formerlyRX_VK_SUBMIT_BATCH, at9e640b66) and, under it, #1994(
RX_VK_REPLAYED_CACHE): their commits show in this diff until they merge.From the submit thread of #1995 before
4f6b9d10(bd592530, its head then), which came fromexp/x86-asm-sync.Read first: the submit worker's block (
submit_worker_main,submit_worker_kick,submit_worker_start,submit_worker_stop,reflex_split_wanted,batch_on), thenqueue_flush_locked,queue_flush_for,queue_flush_polland
submit_recording's hold ingpu/vk/vk_replay.cpp; thentests/test_submit_worker.py.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
dfe6b9c5on #1995's head9e640b66(#1994 under it, on main9dd41326), not rebased (Summary). Build jobs of this PC's job queue (sw2156,sw2156b), the checks in a hidden console:tests/test_submit_worker.py, copies of each commit from git: at5825c6e0(the new cases on the earlier code) it fails as it should:stop-resets(the worker still counted on after a stop that joined it),start-twice(std::terminate at the second start) and the close's wiring (the stop's answer not looked at); at the fix3312f165it passes (23 cases, the wiring, the switch read), and at the head too (24 cases: unset and=0off, every other case with=1; the close's give-up branch before the swapchain's retire; novkDestroyDevicecall ingpu/vk).tests/run_all.py --strict --changed 9e640b66picks for the files this changes, at2219dc54(the head before the fixture line below; logsw2156-changed.log): 166 passed, 34 failed, 9 skipped (they need Linux or a Vulkan device). 33 of the 34 fail on #1995 @9e640b66too, each run alone there:tests/test_appimage_player_build.py,tests/test_auto_handheld.py,tests/test_capture_readback_visibility.py,tests/test_crash_dialog.py,tests/test_crash_record.py,tests/test_dev_ab.py,tests/test_dev_packs.py,tests/test_device_lost_exit.py,tests/test_draw_stream_visibility.py,tests/test_flush_nothing_held.py,tests/test_frame_overlap.py,tests/test_fsr_image_retirement.py,tests/test_fsr_uniform_ownership.py,tests/test_gpu_wait_stats.py,tests/test_input_background.py,tests/test_linux_pressure.py,tests/test_menu_keys.py,tests/test_mesh_conv.py,tests/test_perf_report.py,tests/test_prepare_cache_save.py,tests/test_present_queue_default.py,tests/test_present_source_crop.py,tests/test_profiling_mode.py,tests/test_recorder_own_idle.py,tests/test_recorder_sync.py,tests/test_renderer_new_handler.py,tests/test_replay_write_order.py,tests/test_slow_frames.py,tests/test_sparse_mirror.py,tests/test_target_reuse_memory.py,tests/test_ub_update_batch.py,tests/test_upscaler_rows.py,tests/test_vk_occlusion_queries.py. The 34th,tests/test_present_semaphores.py, compiles the close from itsdev.closingline on and did not know the close's newworker_stopped: its fixture declares it (stopped) in3312f165. At the head it passes, withtests/test_submit_worker.py,tests/test_quit_not_crash.pyandtests/test_startup_progress.py, the other checks that read the close (logsw2156b.log).gpu/vk/vk_replay.cppandgpu/vk/vk_main.cppcompiled with the game build's own command (syntax only): pass.It has run in the game on this PC: the A/B in Measurements (held job
seg-pt-sw, 18 Kokiri Forest runs and a Marketpair, Threaded rendering off), with no FATAL, device lost or Vulkan error in any run, and every run closed by itself with
exit code 0 (no close gave up on the queue).
The Test Farm's picture at kokiri-start (HumanBean's run of this pull request, #issuecomment-70269, Windows RX 9060 XT,
RX_VK_SUBMIT_WORKER=0) was taken inside the load's fade-in from black: main's two starts and one of this pull request's were a uniform black frame and the 0.865 start was the finished scene, so the comparison measured when the fade ended, not what was drawn. #1995's run #issuecomment-67740 shows the same scene and camera as main in its pictures, with only the animation's phase differing (Navi's place, Link's idle pose, the curtain).Still to test:
RX_VK_SUBMIT_WORKER=1, and a picture of each at an input-free point beside main against itself (Kokiri Forest and theMarket have run: Measurements), expecting the same picture (by hand)
thread is off with the recorder thread when
RX_VK_SUBMIT_WORKER=1, and the frame times the same as unset (by hand)RX_VK_SUBMIT_WORKER=1and Threadedrendering off, expecting the game to close at once with no crash report (by hand)
off: this branch unset (off) and with
RX_VK_SUBMIT_WORKER=1, warmed up, ABBA, expecting the same picture, no FATAL ordevice lost, and the frame times showing whether
=1gains or loses (Test Farm: linux+nvidia, windows+amd,windows+intel: Kokiri Forest and Hyrule Field three minutes each, Threaded rendering off: this branch unset and with
RX_VK_SUBMIT_WORKER=1, warmed up, ABBA, the log, frame times and a screenshot)
RX_VK_SUBMIT_WORKER=1, expecting the log to say it is off with RADVand the frame times the same as unset (Test Farm: linux+amd, steamdeck: Kokiri Forest one minute with
RX_VK_SUBMIT_WORKER=1 and unset, the log and frame times)
python3 -I -B tests/test_submit_worker.py, expecting PASS (by hand)Measurements
Verdict: the submit thread takes the driver's submits off the replaying thread, and the frame does not show it. In
the CPU-paced comparison on this PC (Kokiri Forest at an 800x600 output, Threaded rendering off, one runtime of this head,
unset against
RX_VK_SUBMIT_WORKER=1, 8 runs a side; In play below), the replaying thread's queue submit went from 0.53 to0.00 ms a frame (p = 0.0002), the submit thread making about 11 submits a frame in 0.60 ms of
vkQueueSubmit2, and thereplay's submit time fell 3.5 % (p = 0.009). But the game's own code took 7 % longer on the same thread (2.88 against
3.07 ms a frame, p = 0.0002), and the median frame was 12.71 against 12.78 ms (p = 0.55): the time moved, the frame did not
gain. Frames of 50 ms or more were 77 against 116 (p = 0.049) in this one sitting, not claimed.
RX_VK_SUBMIT_WORKERshipsoff (an attempt), as dazemc's review asked; this run gives no reason to turn it on.
Baseline: this PR with
RX_VK_SUBMIT_WORKERunset (#1995's path) in the same runtime as=1: one build, so the switchis the only difference. Main itself was not run in this comparison.
In play (held job
seg-pt-sw, 23:44 UTC on 2026-11-23 to 00:35 UTC on 2026-11-24): one runtime of this headdfe6b9c5(on #1995's
9e640b66, on main9dd41326), Threaded rendering off in every run as the menu's Off sets it (RX_VK_ASYNC=0andRX_VK_RECORDER=off: each run's switches line has both, and no run has the render thread's line), since the submit threadworks only with the replay on the submitting thread;
RX_VK_PROF_FINE=1on both sides. Kokiri Forest, 60 s a run,CPU-paced on purpose (an 800x600 window), a warm-up a side, then unset and
=1interleaved (off on on off, four times);every run in the scene's light state, loaded at create, on a desktop at 800x600 at 30 Hz. No run was left out, no load
marker or strike file appeared, and no run's log has a commit-limit line. Then the Market, one run a side, as a reference.
With Threaded rendering off the game's thread also replays and submits: calm game time is the game's own code only, and
the frame is the median frame time. Reach: the submit thread's own line every 120 presents (
vk: submit thread: N submits, X ms in vkQueueSubmit2 ...) on the=1side: in steady play 11.0 to 11.4 submits a frame, 0.58 to 0.62 ms a frame invkQueueSubmit2, each held 16 to 18 us before the thread sent it (0.29 to 0.33 ms a frame in the load).dfe6b9c5, unset, 8 runsdfe6b9c5,RX_VK_SUBMIT_WORKER=1, 8 runsa frame's replay time (ms): submita frame's replay time (ms): drawThe tail is high on both sides (p99 over 40 ms), as in #2030's runs in the same sitting, both on runtimes over main
9dd41326with Threaded rendering off; those long frames are the game's own thread (32 to 54 ms of its code, about 50 to 66ms blocked in them) on both sides. The Market pair (one run a side, a reference): main_blocked 12.64 against 11.52 ms,
replay submit 10.90 against 9.99, p99 51.5 against 42.8, 41 against 17 frames of 50 ms or more, leaning the same way.
Risks
What could break, with the thread on (
RX_VK_SUBMIT_WORKER=1; never on RADV, nor with the recorder thread): a held submitsent out of order or twice (a wrong picture or a device lost), one never sent (a hang: every wait sends what is held
first, as with
RX_VK_BATCH), the close waiting for the thread (2 s at most; a thread still in a driver submit then makesthe close let the swapchain go with the process, as a present still running does, at once), a refused batch stopping the
renderer where #1995 would go on without it, and a poll or a wait with a finite budget no longer sending what is held when
the queue's lock is busy (the thread does: it was woken when the submit was held). Unset or
=0is #1995's code. Renderercode: the runtime is rebuilt; nothing changes for players' saves, options or caches.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.@Beanstalk This gives the Vulkan replay's submits a thread of their own when the replay runs on the submitting thread, that is with Threaded rendering off (gpu/vk); RADV is left out; RX_VK_SUBMIT_WORKER=0 turns it off. It sits on #1995 (
9e640b66, itself on #1994), so its diff against its merge base includes those PRs' commits; the farm cannot take them as the comparison, so please compare with main. Please start from the kokiri-start save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, on) and with RX_VK_SUBMIT_WORKER=0 (off), on Windows with an RTX 4070, Windows with an Arc B580 and Linux with an RTX 3080 Ti (not RADV, which this change leaves out). The farm cannot set Threaded rendering, so with the default settings this run checks that nothing changes; the Threaded-rendering-off path, where the submit thread runs, is checked by hand, unless a tester has a CPU with fewer than 4 cores, where the game runs with Threaded rendering off. The same picture as main within main's own difference from itself; with it unset, frame time p99 equal to main's or better, within the run-to-run spread, and equal to RX_VK_SUBMIT_WORKER=0 or better. The log must have no FATAL, device lost or validation error line. Where Threaded rendering is off, the log must have the submit thread's line every 120 presents with the switch unset and none with RX_VK_SUBMIT_WORKER=0; please report it either way.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk
Beanstalk test farm · an earlier run: commit
6c7991c(the newer results are in a comment below)Commit
6c7991c· approved by HumanBean (reviewed) · dashboard⚠️ Note: The default rendering configuration may use the recorder thread, and RADV disables the submit worker; in either case the worker-on and worker-off runs exercise the same worker path.
⚠️ Note: The farm cannot set Threaded rendering or compare main against itself for a picture-noise threshold; it also cannot compare the PR’s unset switch directly against its off cell here.
⚠️ Note: The requested exact hardware, three-way comparison against the dependency branch, active play, and window-close test are not included.
Done (started 2026-11-21 23:30 UTC, last report 01:41 UTC). Comment
@Beanstalkto run it again.anyWhy it failed
any:forest-field · RX_VK_SUBMIT_WORKER=0 (PR only)screenshot.max_diff:0.0 → 0.9; limit 0.1What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main with the PR’s default and submit-worker-off configurations, starting at the Kokiri checkpoint and measuring two minutes each in Kokiri Forest and Hyrule Field. It compares the settled starting picture and frame times, and fails on crashes, fatal or device-lost logs, validation errors, substantial picture differences, or a p99 frame-time regression over 15%. The run takes roughly an hour per tester; the worker may be inactive under the tester’s default rendering configuration.
0(PR only).kokiri-start, then take the picture kokiri-start to compare with main, teleport to Kokiri Forest, measure forest for 2 min (after 10 s warm-up), teleport to Hyrule Field, measure field for 2 min (after 10 s warm-up); 2 runs on each side.Measurements on `any`, for the PR description
Verdict: fail on any (2 reports):
forest-field screenshot.max_difffailed.Hardware: 1: windows+amd+amd-proprietary+dgpu
AMD Radeon RX 9060 XT, 2.0.416AMD Ryzen 5 5600 6-Core Processor, 32 GB RAM; 2: linux+amd+radv+igpuAMD Radeon 760M Graphics (RADV PHOENIX), 26.0.8AMD Ryzen 5 230 w/ Radeon 760M Graphics, 16 GB RAMScene: forest-field, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); forest-field: 2 game starts a side, forest 120 s after 10 s warm-up, field 120 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)9dd41326c7991cRX_VK_SUBMIT_WORKER=0 (PR only)· field · frame time (p99) (ms)RX_VK_SUBMIT_WORKER=0 (PR only)· forest · frame time (p99) (ms)RX_VK_SUBMIT_WORKER=0 (PR only)· forbidden log linesFlags and settings
RX_VK_SUBMIT_WORKER0As Markdown for the PR description:
The testers' hardware
anyAMD Radeon RX 9060 XT, 2.0.416AMD Ryzen 5 5600 6-Core Processor, 32 GB RAManyAMD Radeon 760M Graphics (RADV PHOENIX), 26.0.8AMD Ryzen 5 230 w/ Radeon 760M Graphics, 16 GB RAM@HumanBean thank you for this run. In its pictures (#issuecomment-70269, report rp_21f5665de94c15dd, Windows RX 9060 XT,
RX_VK_SUBMIT_WORKER=0), main's two starts and the pull request's first are a uniform black frame at kokiri-start, and the 0.865 start is the finished scene: the capture point falls inside the load's fade-in from black, so the comparison measured when the fade ended, not what was drawn. Frame times in that cell were flat (p99 18.8 to 19.0 ms on both sides), with no crash and no forbidden log line. #1995's run #issuecomment-67740 shows the same scene and camera as main in its pictures, with only the animation's phase differing. The request is being restated with the picture taken after the fade-in, and Testing here and on #1995 now says this.@Beanstalk This replaces my request 70219 on this head, so that it follows the farm's picture and hardware rules. Run 70269 took its pictures during the load's fade-in from black in 3 of 4 starts, so the picture difference it reported does not count. This gives the Vulkan replay's submits a thread of their own when the replay runs on the submitting thread, that is with Threaded rendering off (gpu/vk); RADV is left out; RX_VK_SUBMIT_WORKER=0 turns it off. It sits on #1995 (
9e640b66, itself on #1994), so its diff against its merge base includes those PRs' commits; the farm cannot take them as the comparison, so please compare with main. Please start from the kokiri-start save and take the picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between (a picture during the load's fade-in from black is not comparable), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, on) and with RX_VK_SUBMIT_WORKER=0 (off), on Windows with an RX 9060 XT, Windows with an RTX 4070, Windows with an Arc B580 and Linux with an RTX 3080 Ti (not RADV, which this change leaves out). The farm cannot set Threaded rendering, so with the default settings this run checks that nothing changes; the Threaded-rendering-off path, where the submit thread runs, is checked by hand, unless a tester has a CPU with fewer than 4 cores, where the game runs with Threaded rendering off. The same picture as main within main's own difference from itself; with it unset, frame time p99 equal to main's or better, within the run-to-run spread, and equal to RX_VK_SUBMIT_WORKER=0 or better. The log must have no FATAL, device lost or validation error line. Where Threaded rendering is off, the log must have the submit thread's line every 120 presents with the switch unset and none with RX_VK_SUBMIT_WORKER=0; please report it either way.@siantm only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for6c7991c, and the PR has changed since (dfe6b9c), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.The switch ships on, but the on path has never run in the game: not on this PC, and the only farm run was
RX_VK_SUBMIT_WORKER=0with an invalid (fade-in) timing. The game-free test is strong, but it cannot catch a driver's real submit behaviour, a device lost, or a stalled close.Default / evidence (strongest finding).
RX_VK_SUBMIT_WORKERiskill,env_on_or(..., 1): unset means on, not off. The PR's own Measurements says "RX_VK_SUBMIT_WORKERships on (its default, unset); no measurement chose that default yet", and Testing says "It has NOT run in the game on this PC yet." The Test Farm's kokiri-start run was taken withRX_VK_SUBMIT_WORKER=0and its timing was inside the fade-in, so it exercises the off path only. The checklist's "ships at the default the measurements chose" and "measured against main" boxes are unticked. A perf change whose Risks include "a wrong picture or a device lost", "one never sent (a hang)", and a close delay should beRX_VK_SUBMIT_WORKER=0(or anattemptswitch) until the on/off/#1995 A/B exists; the game-free test does not substitute for one real queue.Queue ownership and synchronization. The design looks sound: every
vkQueueSubmit2(dev.queue, ...)is underdev.present_mu. The worker'squeue_flush_lockedtakesstd::lock_guard qk(dev.present_mu); the replaying thread's flushes (queue_flush_for,queue_flush_poll, the cap/reflex split,queue_flush,device_wait_idle_locked) hold it; the present's copy submit is under theqktaken inpresent_image_with_trial;part_submittakes it, and the worker is off with the recorder thread. So two threads cannot submit the same queue concurrently. The lock order is consistent: the kick holdspresent_muand takessubmit_worker.mu; the worker holdsw.muonly while waiting, releases it before takingpresent_mu, and the stop takesw.muonly. No inversion.sw_reason_nsis written underpresent_muand the stats line atpresent_image_with_trialholds the same lock;sw_submit_ns/sw_submitsare atomics;t_submit_workeris thread-local. The worker'sreplay_fatalpath (_Exit(3), nopresent_mu) does not deadlock.Batching condition.
batch_on()is(on || submit_worker_on()) && batch_tl != VK_NULL_HANDLE: the worker reuses the batch hold, the cap,batch_gpu_idle, the timeline (batch_tl) and the Reflex split. It is off with RADV/GCN,RX_VK_BATCHset, the device policy's batched submits, the recorder thread,RX_VK_GPU_TIMELINE,RX_VK_BENCHor nobatch_tl, and the log names which. The held submit is appended underpresent_mu,pend_heldis released, the kick wakes the worker, and the worker sends it in hold order.reflex_split_wantedflushes another game frame's batch first (FR_REFLEX). This matches the PR's description.Fallback. A
std::threadthat throwsstd::system_erroris caught;submit_worker_startedstays false, sobatch_on()is false on NVIDIA and every submit is made by the replaying thread, with nothing held. The test injects the error and covers it.Test. I ran
python -I -B tests/test_submit_worker.py --cxx clang++on6c7991cb: PASS, 4 lines / 20 cases — wake/order, own counter vsPROF_QSUBMIT, Reflex split, start failure, the off matrix, stop/join and a post-stop kick, a refused/lost held batch, polls and zero-budget waits, and the switch read in fresh processes (unset, empty, 0, 1, 2, off, no). It also checks the wiring insubmit_recording,replay_startand the close. What it cannot cover: a real driver'svkQueueSubmit2, a device lost, a stalled submit during close, and the in-game picture. Those are all in Still to test.Threading / lifetime hazards to tighten:
submit_worker_stop()and ignores its bool. The 2 s stop is followed by the close's 5 spresent_mutry-lock; if the worker is stuck invkQueueSubmit2, the close gives up, logs "the swapchain goes with the process", and the held submits are not sent. The Risks' "the close waiting for the thread (2 s at most)" understates the close (2 s + 5 s), and the skipped retire means the held batch is not flushed. If the host then destroys the device while the worker is still invkQueueSubmit2, that is a lifetime hazard; today the comment says the process ends next, so it is bounded, but the bool should be used and the worker's driver call should be known not to outlive the device.submit_worker_startedis never cleared bysubmit_worker_stop(). After the stop,batch_on()remains true and the replaying thread keeps the hold/try-lock path (submit_worker_kick()returns false), not the direct submit. It is harmless while the process is closing, but the state is not reset, and the present line keeps printing the worker's counters.submit_worker_start()is not idempotent: a secondreplay_startin one process would assign to a joinablestd::threadand callstd::terminate.started_up()/start()is once per process today; if a renderer restart can call it twice, guard it.queue_flush_forpath (a zero-timeout wait included) returns with the budget unreduced when the queue's lock is busy and leaves the held submit to the worker. That is the intended L10, but the caller must treat "not ready" as possible while a held submit is queued; the test covers the path, not a real driver's timing.What remains. The in-game A/B (on,
=0, and #1995) on Windows/Linux/AMD/Intel, the close-while-playing run, and the RADV off-log check; the PR is WIP/draft and not mergeable, with the #1995/#1994 commits still in its diff. The head is6c7991cbon #1995's9e640b66; this review is the submit-worker commit only.No approval, no claim.
Beanstalk test farm
Commit
dfe6b9c· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.WIP: perf(vk): a submit thread sends the submits the replay holds where nothing else batches them (RX_VK_SUBMIT_WORKER)to WIP: perf(vk): a submit thread sends the submits the replay holds where nothing else batches them (RX_VK_SUBMIT_WORKER, off)@dazemc thank you for the review (72747), and for running the test. I pushed
5825c6e0,3312f165anddfe6b9c5on top of6c7991cb. They sit on #1995's9e640b66as before. This push does not rebase the stack: #1995 and #1994 conflict with current main invk_replay.cpp, and their farm requests and runtimes are on their current heads, so the three are rebased together at #1995's next push. The description and the title are updated.Default.
dfe6b9c5:RX_VK_SUBMIT_WORKERis now anattemptrow and ships off. Unset or0is #1995's path, and1turns the submit thread on. The A/B (unset against=1, with Threaded rendering off) is in Still to test.Lifetime. The tests for (a) to (c) are
5825c6e0; it fails at6c7991cb(stop-resets,start-twiceand the close's wiring) and passes after the fix in3312f165.(a) The close. It now uses what
submit_worker_stop()returns. If the thread has not stopped after 2 s, it is in a driver submit or waiting for the queue's lock behind one. The close then lets nothing go and returns at once, as it already does when a present is still running, so there is no further 5 s wait on the queue's lock. The driver call cannot outlive the device because the back end never destroys the device: there is novkDestroyDevicecall ingpu/vk, and the device goes with the process. The test checks the close's give-up branch, checks that nogpu/vk/*.cppcallsvkDestroyDevice, and covers a worker stuck invkQueueSubmit2: the stop gives up after 2 s, returns false, and the worker is still counted as there (stop-stuck). Risks now says this instead of "2 s at most".(b) The stop clears
submit_worker_startedonce the thread is joined.batch_on()and the kick then say there is no worker, the replaying thread submits directly again, and the present line stops printing the worker's counts. A stop that timed out leaves it set, since the thread is still there (stop-resets).(c)
submit_worker_start()now runs once per process. Asked again, or after a stop, it logs and starts nothing. Todayreplay_startruns once, so this is a guard (start-twice).(d) I checked the callers and made no change. The finite-budget callers are the capture's write-back wait (250 ms), the fence wait (the game's timeout, its zero-time poll loop included), and
readback_wait_value(RX_VK_READBACK_WAIT_MS, 250 ms). Each then waits on the driver with what is left of its budget, and each already handles a timeout:A busy lock leaves the held submit to the worker, which was woken when the submit was held and sends it as soon as the lock is free, so the driver wait that follows can still see it finish within the budget.
Testing is in the description.
tests/test_present_semaphores.pycompiles the close from itsdev.closingline on, so its fixture now declares the close's newworker_stopped(as stopped). At the head it passes, along with the other checks that read the close. Of the checks that read the changed files, 33 fail, and each fails on #1995's9e640b66too. The two changed sources compile with the game build's command. It has not run in the game yet.@Beanstalk This replaces my request 71056, made for the earlier head
6c7991cb, where the switch was on by default. This adds RX_VK_SUBMIT_WORKER, an attempt off by default: with RX_VK_SUBMIT_WORKER=1 the Vulkan replay's submits go to a thread of their own when the replay runs on the submitting thread, that is with Threaded rendering off (gpu/vk); never on RADV; unset, it is #1995's path. It sits on #1995 (9e640b66, itself on #1994), so its diff against its merge base includes those PRs' commits; the farm cannot take them as the comparison, so please compare with main. Please start from the kokiri-start save and take the picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between (a picture during the load's fade-in from black is not comparable), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, off) and with RX_VK_SUBMIT_WORKER=1 (on), on Windows with an RX 9060 XT, Windows with an RTX 4070, Windows with an Arc B580 and Linux with an RTX 3080 Ti (not RADV, which this change leaves out). The worker only acts with Threaded rendering off, so please set RX_VK_ASYNC=0 (the switch behind the Threaded rendering row) on every side, main's included. The same picture as main within main's own difference from itself; unset, frame time p99 equal to main's; with RX_VK_SUBMIT_WORKER=1, equal to unset or better, within the run-to-run spread. The log must have no FATAL, device lost or validation error line. With RX_VK_SUBMIT_WORKER=1 the log must have the submit thread's line every 120 presents, and unset none. The game must close promptly at the end of each run.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk One more correction to my request 72820 above: RX_VK_ASYNC=0 alone is only half of Threaded rendering off; the recorder thread follows the row separately. Wherever I asked for RX_VK_ASYNC=0, please set RX_VK_RECORDER=off with it, on every side, main's included: the two together are what the Threaded rendering row's Off sets, and this change does not run with the recorder thread on.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk This replaces my request 72820 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This adds RX_VK_SUBMIT_WORKER, an attempt off by default: with RX_VK_SUBMIT_WORKER=1 the Vulkan replay's submits go to a thread of their own when the replay runs on the submitting thread, that is with Threaded rendering off (gpu/vk); never on RADV; unset, it is #1995's path. It sits on #1995 (
9e640b66, itself on #1994), so its diff against its merge base includes those PRs' commits; the farm cannot take them as the comparison, so please compare with main. Please start from the kokiri-start save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on the PR's side unset (the default, off) and with RX_VK_SUBMIT_WORKER=1 (on), on Windows with an RX 9060 XT, Windows with an RTX 4070, Windows with an Arc B580 and Linux with an RTX 3080 Ti (not RADV, which this change leaves out). The worker only acts with Threaded rendering off, so please set RX_VK_ASYNC=0 and RX_VK_RECORDER=off (together, the Threaded rendering row's Off) on every side, main's included. The same picture as main within main's own difference from itself; unset, frame time p99 equal to main's; with RX_VK_SUBMIT_WORKER=1, equal to unset or better, within the run-to-run spread. The log must have no FATAL, device lost or validation error line. With RX_VK_SUBMIT_WORKER=1 the log must have the submit thread's line every 120 presents, and unset none. The game must close promptly at the end of each run.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@dazemc the on/off A/B your review asked for has run (Measurements, "In play"): this head on #1995's, Threaded rendering off, Kokiri Forest CPU-paced at an 800x600 output, unset against
RX_VK_SUBMIT_WORKER=1in one runtime, 8 runs a side, and the Market one a side. On a real driver here (RTX 4060, Windows), the on path ran in every=1run: about 11 submits a frame made by the submit thread, 0.60 ms a frame ofvkQueueSubmit2there, the replaying thread's own queue submit down from 0.53 to 0.00 ms; no device lost, FATAL or Vulkan error, and every run closed by itself with exit code 0 (no close gave up on the queue).What it does to the frame: the replay's submit time fell 3.5 % (p = 0.009), but the game's own code on that thread took 7 % longer (p = 0.0002), and the median frame was level (p = 0.55). So it ships off, as you asked, and this gives no reason to turn it on. Not covered yet: the picture against main and Hyrule Field (Still to test).
@siantm thank you — that answers the point the review raised (72747): the on path has now run in the game, on a real driver.
At
dfe6b9c5, one runtime with Threaded rendering off (RX_VK_ASYNC=0,RX_VK_RECORDER=off), 8 runs a side plus a Market pair, the=1runs show the outcome the review asked about: the submit thread made the queue submits (about 11 a frame, 0.60 ms a frame ofvkQueueSubmit2there) and the replaying thread's own submit went from 0.53 to 0.00 ms. The driver's submits are off the replaying thread, not just moved in a counter. The runs are at this PR's head (dfe6b9c5on #1995's9e640b66), so the A/B is at the current head, not an older one. No device lost, FATAL or Vulkan error, and every run closed by itself with exit code 0 (no close gave up on the queue), which covers the clean-exit and driver-call side for this path. Shipping it off as an attempt, with no claim to turn it on, is what those numbers support.Not settled by this run, and separate from this point: the picture against main, Hyrule Field, the close-while-playing run and the RADV off-log check remain in Still to test, as do the other hardware targets.
@dazemc thank you. The picture against main, Hyrule Field, the close-while-playing run, the RADV off-log check and the other hardware stay in Still to test.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.