WIP: perf(vk): a scene draw learns the frame's camera is taken without the chain's lock (RX_VK_CHAIN_LOCKLESS) #2005
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!2005
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-chain-lockless"
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
Every draw into a target of the scene's size asks the Upscaler's mode through a chain of calls and takes the temporal chain's mutex in
temporal_note_scene_draw(gpu/vk/vk_temporal.cpp), to learn that this frame's camera, of a target at least as large, was taken already. With the switch on, that answer is read first from two atomics,State::cam_frameandcam_area, whichcam_tellwrites under the lock where the camera is taken (the draw that takes it) or let go (cam_drop, the one place that lets it go, called bystretch,fg_inputsandtemporal_upscale): the area, then the frame. That a draw's two loads are of one camera rests onreplay_mu(vk_replay.cpp): every draw and every upscale that takes or lets go of the camera runs on the replay with it held, so nocam_tellruns between them (the release/acquire pair alone would not rule out a later camera's area with this frame). Where they say "this frame's camera, at least this large" the draw returns, as it returned before at the mode's test or under the lock; else it goes on as before. The expected result is a little less replay CPU time a frame with a temporal upscaler (no Upscaler mode chain and no uncontended mutex for the draws after the one that took the camera); it is not measured. WithRX_VK_PROF_FINE=1(the draw path's fine profile) the scene draws at this test are counted, a frame, by the way they went: the frame log'svk: a frame (fine): scene draws at the camera's test: <n> returned without the chain's lock (RX_VK_CHAIN_LOCKLESS), <n> went on to the lockline, every 120 frames, for the A/B below.Switch:
RX_VK_CHAIN_LOCKLESS(kind kill, on by default as the change proposes, docs/dev/standards.md, Switches; its row ingpu/vk/switches.def). Unset,1or any value but those below: the atomics first.0(or an empty value,false,offorno, in any case, spaces around it not counted): the draw's decision as before (a target the Upscaler's format or mode rejects returns before the lock, the others ask under the lock), the frame read under the lock alone and the atomics neither read nor written; the switch is still tested at each scene draw. It is read once, at its first use (soHOS_ABcannot alternate it); its first read logs what it chose.From bd3ea307 and 4eed88f7 on
exp/x86-asm-sync.Read first:
cam_tell,cam_drop,chain_lockless, the start oftemporal_note_scene_drawandtemporal_scene_draw_reportingpu/vk/vk_temporal.cpp.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
84157f83on main @9dd41326(the branch's earlier commits unchanged by the rebase,git range-diff; then testae8ab7a4, defaultae476851, test9003fc39, counts84157f83), in jobsdyl-2005(light, two checks at once) anddyh-2005(build) of the PC's job queue, each check in a hidden console of its own,RX_CPMset:tests/run_all.py --strict --exact:tests/test_chain_lockless.py(kNoCamera,chain_lockless,cam_tell,cam_drop, the counters, the part oftemporal_note_scene_drawbefore its lock and its test under the lock, cut fromvk_temporal.cpp, over 20,000 random frames, cameras taken and let go by the realcam_dropand draws, withRX_VK_CHAIN_LOCKLESSunset,0and1andRX_VK_PROF_FINEunset,0and1: on (unset or1), a draw returns before the mode and the lock exactly when the cut test under the lock would;0, every draw goes on to the lock, the frame is not read before it and the atomics are never written; withRX_VK_PROF_FINE=1each draw counted once by the way it went andtemporal_scene_draw_reportgiving both counts a frame, then nothing new; otherwise nothing counted or logged; the source has no write to the camera but incam_dropand the draw that takes it, andfine_reportcalls the report; the switch's reader in fresh processes: unset,1,onand another value on,0,off,false,no, empty and spaces off, twice each, set to the other answer after its first read with the setter's result checked),tests/test_psychov35_off.py(Off's realstretch, with a camera told to the atomics, lets it go and tells them),tests/test_switch_table.py: pass.ae8ab7a4test_chain_lockless.pyfails (unset still off); at9003fc39it fails (no counts in the source); at the head it passes.gpu/vk/vk_temporal.cppandgpu/vk/vk_draw.cppcompiled (no object) with the game build's own commands for them, from a local build's compile_commands.json: no error.tests/run_all.py --changed origin/main,RX_CPMset; jobdyh-2005): 171 passed, 19 failed, 6 skipped (Linux only). 18 of the failures fail on main @9dd41326too, the same way, run in the same job:tests/test_crash_dialog.py,tests/test_dev_ab.py,tests/test_dev_packs.py,tests/test_device_lost_exit.py,tests/test_draw_binds.py,tests/test_draw_stream_visibility.py,tests/test_frame_overlap.py,tests/test_fsr_uniform_ownership.py,tests/test_linux_pressure.py,tests/test_mesh_conv.py,tests/test_pipeline_play_cache.py,tests/test_prepare_cache_save.py,tests/test_present_queue_default.py,tests/test_recorder_own_idle.py,tests/test_sampler_admission.py,tests/test_target_reuse_memory.py,tests/test_upscaler_rows.py,tests/test_vk_occlusion_queries.py. The 19th,tests/test_recording_admission.py, failed at the head and passed on main in that job: its parallel worker-slot case fails now and then on main as well (3 of 5 runs onf1f2dc5bin #2003's earlier job fb-2003-3); repeated runs at the head against main are still to do. None stopped for want of the Vulkan headers.tests/test_vbytes.pyis not among them and was not run.It has NOT run in the game on this PC yet.
Still to test:
9dd41326, this PR withRX_VK_CHAIN_LOCKLESS=0and this PR unset (as it ships), all withRX_VK_PROF_FINE=1, each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each. Report the replay's CPU time a frame (vk: a frame's replay time (ms), its draw part) per run and as medians with the spread, and from the unset runs the scene draws a frame that took the shortcut against those that reached the lock (vk: a frame (fine): scene draws at the camera's test: ...); FPS, 1% lows and p99 only beside them (they are bound by the GPU and the present and cannot show a saving this size). Expecting the same picture all three ways (no smearing, no ghosting, no jitter), =0 as main, and unset's replay CPU time lower than =0's beyond the spread; if it is not, the change is dropped (no measured gain, no merge) and this description says so (by hand)RX_VK_CHAIN_LOCKLESS=0, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (by hand or on the farm, not run yet); the change has no vendor, driver or OS path, so this is a picture and stability check, the gain is measured abovetests/test_chain_lockless.py,tests/test_psychov35_off.pywith--cxx g++and--cxx clang++, expecting PASS (by hand)Measurements
Verdict: not measured in play yet: no micro-benchmark and no run in the game on this PC yet; the in-game A/B (replay CPU time a frame and the shortcut's counts, Still to test) comes first.
RX_VK_CHAIN_LOCKLESSships on (kind kill,0gives the draw's decision as before), the value this change proposes (docs/dev/standards.md, Switches); if the A/B shows no gain beyond the spread, the change is dropped.Risks
Unset (the default) a scene draw first reads the two atomics;
RX_VK_CHAIN_LOCKLESS=0decides as on main, the cost then the switch's test at each scene draw. A draw that returns early though the camera was let go since would leave the upscaler without this frame's camera (smearing or ghosting for a frame): the camera is let go incam_dropalone, which tells the atomics, and the test fails on any other write to it; the shortcut's two loads rely onreplay_muserialising the draws and the upscales, as they do today. WithRX_VK_PROF_FINE=1each scene draw at the test adds one relaxed atomic increment (off, one read-once bool). The renderer is compiled again after updating.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Not yet: only the checks in Testing ran.main, or Measurements says why there is nothing to measure. Not yet (Measurements).third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. Its row is in; it ships on, as the change proposes (docs/dev/standards.md, Switches), not measured yet;RX_VK_PROF_FINE's row names the new count line.tests/that reads changed source is updated, not weakened.vk_temporal.cppandvk_draw.cppcompiled with the game build's commands (Testing); no full build.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Recommendation: Request changes. The new check can fail before it starts on a documented Windows setup because the test runner bypasses its llvm-mingw fallback. The draw shortcut can save CPU work, but there are no in-game measurements to justify enabling it by default.
Repeated draws can skip the temporal chain mutex and upscaler mode lookup once the frame has a camera from a target at least as large. The existing replay mutex serializes the camera and frame changes. The patch adds two copies of camera metadata and four places that must keep them in sync.
@fixwill do (7)tests/test_chain_lockless.py:27: The suite resolves {cxx} before this test's compiler fallback runs. (more on the line)gpu/vk/vk_temporal.cpp:345: The comment attributes snapshot consistency to the release/acquire pair. (more on the line)tests/test_chain_lockless.py:182: The fixture simulates invalidation and checks production with a regex. (more on the line)tests/test_chain_lockless.py:121: The switch fixture ignores the result of _putenv_s and setenv. (more on the line)gpu/vk/switches.def:296: The switch row says every scene draw takes the lock when disabled and that any other value enables it. (more on the line)gpu/vk/vk_temporal.cpp:976: Read the frame only when the shortcut is enabled and skip metadata publication when disabled. Consider using replay-owned camera fields to remove the extra stores on both paths.For the author (2) (a run, a measurement or a decision)
gpu/vk/vk_temporal.cpp:976: Measure warmed, interleaved runs of main and the PR with the switch on and off. (more on the line)Checks: Still running:
PR description / Description follows the template (pull_request_target),CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven. The PR reports 39 of 47 selected Windows source checks passed and eight failed on both
ec735e07and base75317e1f. Those checks provide no replay timing, FPS, 1% lows, or frame-time measurements. There are no in-game runs.Other systems: The changed hook is shared by DLSS, DLAA before bloom, FSR 3.1 on the temporal chain, FSR 4, XeSS, Off's stretch, and camera inputs for frame generation without a temporal upscaler. Game mode and FSR 3.1's separate path can still pay for a failed shortcut. The recorder and presenter do not update the camera. The diff changes no shader, GPU allocation, public renderer interface, save format, audio, or input code.
Switches: RX_VK_CHAIN_LOCKLESS is a developer kill switch, on when unset. Empty or whitespace-only values and 0, false, off, or no disable it, ignoring case and surrounding whitespace. It is cached and logged at first use, so HOS_AB cannot alternate it. The sorted table row is present. The on default still needs measurements across supported configurations.
Reviewed:
ec735e077eagainst75317e1f31: Read vk_temporal.cpp, both changed Python tests, the changed switch row and nearby entries, the full diff and commit, AGENTS.md, CONTRIBUTING.md, the Forgejo template, and the developer standards. Traced draw and upscale callers, replay and present locking, the frame counter, the environment parser, and test-runner compiler selection. Skimmed other source checks that read the changed files and the rest of the switch table. No local review-checklist or cited run logs were present. There were no comments, prior reviews, translations, or generated-file changes.; nothing run (a code review).Checked and fine:
Testing: Read-only review. No builds or tests run here. The author reports both edited checks passed with Windows llvm-mingw and that eight selected failures also occur on the base. The full suite, Linux compiler runs, gameplay comparisons, and CI results are pending.
Overlaps and merge order: No overlapping pull request found in the supplied context or local history. Local main has advanced past the tested base. Its switch-table edit is on a different row. Confirm results against current main before merge.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -293,6 +293,7 @@ SW(RX_VK_CAP_FREE_ASYNC, kill, bool, "on: a capture buffer past the spares is deSW(RX_VK_CAP_MIN_MB, tune, int, "2 MB", "The smallest capture buffer size class in MB; 16 is the old behaviour.")SW(RX_VK_CAP_SPARE_MB, hw, int, "32 MB of spare capture buffers on cards allowing 6.5 GB or less; no byte limit elsewhere", "Sets how many MB of spare capture buffers are kept for reuse; 0 means no limit, as before.")SW(RX_VK_CASCADE_BIAS, tune, string, "0,0: nothing added", "Adds a depth bias <units>,<slope> to the sun's shadow cascades.")SW(RX_VK_CHAIN_LOCKLESS, kill, bool, "on: a scene draw learns the frame's camera is taken without the chain's lock", "=0 (or false, off, no) asks the Upscaler's mode and takes the chain's lock at every scene draw, as before; any other value is on. Read once, at its first use (HOS_AB cannot alternate it).")L5 (minor): The switch row says every scene draw takes the lock when disabled and that any other value enables it. A format or mode rejection still returns before locking, and whitespace-only values disable the shortcut. Update the row and PR summary. Describe the disabled variant as restoring the original draw decision, since it still checks the switch and publishes camera metadata.
@ -325,0 +342,4 @@}();return on;}/// (s.mu held) cam changed: what the draws' test reads of it. A camera taken: its pixels before its frame, so a reader thatL2 (minor): The comment attributes snapshot consistency to the release/acquire pair. That ordering guarantees visibility of the earlier area store, but it cannot rule out a later area's store. If a draw and camera capture could overlap across a present, a reader could pair the old frame with the next frame's larger area. Today replay_mu excludes that interleaving in both threaded and synchronous replay. Document that ownership at the fast read and publication, or use the existing replay-owned camera fields directly.
@ -945,2 +973,4 @@// below: the format, the camera's own size and perspective, the largest in the frame, and the upscale's input)if (!color0 || !depth || !camera || camera_size < 0x230 || !temporal_scene_size(width, height)) return;State& s = st();uint64_t now = texture_frame_no();L6 (minor): Measure warmed, interleaved runs of main and the PR with the switch on and off. Cover Kokiri Forest and a heavy scene using the hardware's normal preset and resolution. Report shortcut hits or lock takes, replay CPU time, average FPS, 1% lows, and median and p99 frame time. Include Game mode after switching away from a temporal upscaler, where the retained output size lets draws reach the new branch but there is no current camera to produce hits. Use the results to choose the default.
@ -0,0 +24,4 @@sys.path.insert(0, str(Path(__file__).resolve().parent)) # (tests/srccut.py: python -I leaves this folder off the path)from srccut import block, between # noqa: E402RUN_ALL_ARGS = ["--cxx", "{cxx}"]L1: The suite resolves {cxx} before this test's compiler fallback runs. On Windows with llvm-mingw configured through LONGSHOT_MINGW or bundled in the clone, and no C++ compiler on PATH, run_all --strict fails before launching the fixture. Make the runner's compiler selection honor configured llvm-mingw after CXX, or let this check resolve its compiler before the runner rejects it.
@ -0,0 +118,4 @@const bool first = t::@FN@();#ifdef _WIN32_putenv_s("@NAME@", argv[1]);#elseL4 (minor): The switch fixture ignores the result of _putenv_s and setenv. If the write fails, the cached-value assertion passes without an environment change. Check the setter result and verify the new value before checking the second read. Include no and a whitespace-only value among the off cases.
@ -0,0 +179,4 @@raise SystemExit("temporal_note_scene_draw: the frame is not read again under the lock")if not note.rstrip().rstrip("}").rstrip().endswith("cam_tell(s);"):raise SystemExit("temporal_note_scene_draw: a camera taken is not told to the atomics")# (every camera let go tells the atomics, right after)L3 (minor): The fixture simulates invalidation and checks production with a regex. Replacing a real invalidation and its cam_tell call with s.cam = {} would bypass the regex and leave the test passing while a later same-frame draw could skip capture. Exercise real invalidation paths with a camera already published, then check that the next eligible draw goes through. The existing Off dispatch fixture can cover stretch.
ec735e077e1cdc21f877WIP: perf(vk): a scene draw learns the frame's camera is taken without the chain's lock (RX_VK_CHAIN_LOCKLESS)to WIP: perf(vk): a scene draw learns the frame's camera is taken without the chain's lock (RX_VK_CHAIN_LOCKLESS, off by default)Thank you for the review (#issuecomment-63412). Pushed
1cdc21f8, rebased on main @fd7dc40d(the branch's own commit unchanged by the rebase,git range-diff; main's FPS-footer change added aroute_drawnstand-in totests/test_psychov35_off.pybeside this test commit'senv_onone: both kept); test commit59b5ee5a(its checks fail on the branch's earlier code), fix1cdc21f8; queue job fb-2003-6 (shared with #2003). All checks named below ran in that job on this PC; nothing has run in the game.Default: there is no measurement in play, so
RX_VK_CHAIN_LOCKLESSis now off by default (kind attempt). The in-game A/B that could turn it on is in Still to test.{cxx}before the check's fallback: fixed in59b5ee5athe second way you name:test_chain_lockless.pyno longer declares{cxx}, and resolves--cxx,CXX, the configured llvm-mingw (LONGSHOT_MINGW), then PATH itself.run_all.py --strict --exact tests/test_chain_lockless.pypassed in that job with no compiler on PATH. The runner's own lookup is unchanged (other checks share it).1cdc21f8: the comments atcam_telland at the fast read now say it isreplay_mu(every draw and every upscale that takes or lets go of the camera runs on the replay with it held), and that the release/acquire pair alone would not rule out a later camera's area.1cdc21f8lets the camera go in one place,cam_drop, whichstretch,fg_inputsandtemporal_upscalecall; the fixture runs the realcam_drop, andtest_psychov35_off.pyruns Off's realstretchwith a camera told to the atomics and checks it lets it go and tells them (59b5ee5a). The source check now fails on any write to the camera outsidecam_dropand the draw that takes it (s.cam = {},s.cam.valid = ..., a non-const reference), not only the one spelling.fg_inputsandtemporal_upscaleare not run: they need the upscalers' and Vulkan's stand-ins far beyond these fixtures.59b5ee5a: the fixture returns an error when_putenv_s/setenvfails or the value read back differs, andno, empty and spaces are among the off cases.1cdc21f8(row) and in the description: off is the draw's decision as before (the format or mode rejection returns before the lock), empty and spaces are off, and the switch is still tested at each scene draw.1cdc21f8: the frame is read before the lock only with the switch on, andcam_tellwrites nothing with it off (the fixture checks both). I kept the two atomics rather than reading the replay-owneds.camwithout the chain's mutex: those are plain fields written under it, so the unlocked read would be race-free only throughreplay_mu; the atomics keep the unlocked part to two values. The measurement part is pending, for the owner: warmed, interleaved main / off / on in Kokiri Forest and a heavy scene, Game after a temporal upscaler included (Still to test).@Beanstalk This adds RX_VK_CHAIN_LOCKLESS, off by default: with RX_VK_CHAIN_LOCKLESS=1 a scene-sized draw learns this frame's camera for the temporal upscalers and frame generation from two atomics instead of the chain's lock (gpu/vk/vk_temporal.cpp); unset, main's way. It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes with a temporal upscaler on in the Insert menu (one this farm's builds have), the PR against main on the same PC, on the PR's side with RX_VK_CHAIN_LOCKLESS=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture (no smearing, ghosting or jitter), no crash or validation error; set, frame time p99 equal to unset or better; unset, as main's.
@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 for1cdc21f, and the PR has changed since (84157f8), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Verdict: Request changes. The code is sound: under
replay_muthe shortcut returns only where the draw returned before, and BeanBot's code points are fixed. But the switch now ships off only because it is unmeasured, which docs/dev/standards.md rules out. A perf change also needs a measured gain to merge, and the run the PR plans can't show one this size.For a player: with the switch on, the replay thread does a little less work per scene-sized draw (it skips the Upscaler mode chain and an uncontended mutex once the frame's camera is taken), and the picture stays the same. The gain is real in principle and probably small: a few hundred to a couple of thousand draws a frame, each saving tens to a few hundred ns. It is not measured. The cost is two mirrored atomics,
cam_tell/cam_drop, and a 241-line source-cutting check.Reviewed:
1cdc21f8againstfd7dc40d(merge base with main; it also merges cleanly with main at9dd41326, and main has not touchedvk_temporal.cpp,vk_draw.cppor the Off test since):gpu/vk/vk_temporal.cpp(the diff,State,Camera,temporal_note_scene_drawin full,stretch,fg_inputs,temporal_upscale, every others.mutaker), theswitches.defrow,tests/test_chain_lockless.pyandtests/test_psychov35_off.pyin full; the caller invk_draw.cpp,texture_frame()/frame_noinvk_texture.cppand the present'sreplay_muhold invk_replay.cpp,env_oninlongshot_env.h, the runner'sRUN_ALL_ARGShandling. Nothing run (a code review). Re-review after BeanBot's review ofec735e07, which is no longer on the branch; I judged its points from the reply and the current code.Fixed in this review: nothing.
Checked and fine:
cam_frame == now && area <= cam_areaholds only whiles.camis valid, of this frame and at least that large, and then the test under the lock returns too. Before that, a format or mode rejection returned anyway. No draw that used to take the camera skips it now.s.camholdsreplay_mu: the capturing draw (draw()invk_draw.cpp), andstretch,fg_inputsandtemporal_upscale(called from the draw path), so the two loads are of one camera. The frame counter it compares against (frame_no++intexture_frame) also advances underreplay_mu, indo_present.&&sequences them). Even withoutreplay_mu, a reader that sees the frame sees that camera's area or a later one. A mix of two cameras in the same frame still gives the answer the lock would give at the second load. Release/acquire costs nothing on x86 (including the Deck).s.camis written only incam_dropand the capturing draw (it ends withcam_tell; it has no early return betweenCamera& k = s.camand that call). The source check now catchess.cam = {}, field writes and other references.cam_tellreturns first), so the only cost is a static-bool test per scene draw.on == !kept) or ifcam_tellis dropped fromcam_drop(a draw would return with no camera).test_psychov35_off.pyruns Off's realstretchand checks it lets the camera go and tells the atomics.RUN_ALL_ARGS = []), L2 (the comments namereplay_mu), L4 (setter result and read-back checked;no, empty and spaces are off cases), L5 (the row) and L8 (checklist restored) are fixed in the code and description. L3 is fixed far enough: there is one place that lets the camera go, it is run forstretch, and the regex covers the other ways to write the camera.Assisted-by:trailers on all three commits.Blocking (to change before merge)
gpu/vk/switches.def:297/gpu/vk/vk_temporal.cpp:339: the switch was turned off in1cdc21f8only because it is unmeasured. docs/dev/standards.md, Switches: "It ships at that value from the branch's first push, WIP or not ... Never off just because it is new or unmeasured." Testers and anyone else running the branch get main's path, so they test nothing. Ship it on (env_on_or("RX_VK_CHAIN_LOCKLESS", 1), kindkill, the row and title saying=0restores the old decision), and turn it off or drop the change if the A/B goes against it. (BeanBot's "no measurements to justify enabling it by default" is answered by measuring, not by shipping it off.)=0, on; warmed and interleaved, per the measure skill), and how many scene draws a frame take the shortcut against those that reach the lock. If it is within the spread, the change doesn't earn its code.Suggestions (the author may take or leave)
s.camdirectly. The pair is consistent only because ofreplay_mu(the comment says so), and on that same ground a read ofs.cam.valid/frame/width/heightbefore the mode test, withouts.mu, is race-free: every writer holdsreplay_mu. That drops the two atomics,cam_tell, the off-path write rule and most of the regex check. The atomics avoid formal UB only if a writer ever leavesreplay_mu, and then the shortcut would be wrong anyway. Worth weighing once the gain is known.tests/test_chain_lockless.py:63:under_lockis the fixture's own copy of the test under the lock. Cut the condition from the source (betweenstd::lock_guard lk(s.mu);andreturn; // (the largest one of the frame wins)), so a change there can't leave the shortcut out of step without the check noticing.Testing: source checks on the author's Windows PC (i7-9700, RTX 4060): the two edited checks and the switch table pass, and the 8 failures named also fail on main. CI is still blocked. Nothing has run in the game. The farm request (65036) asks for a picture check and p99 frame time, on and unset, on Linux NVIDIA/AMD, Windows Intel and the Deck. The change has no vendor, driver or OS path (pure CPU logic under the replay's lock), so it is unlikely to differ by hardware. The farm's frame-time criterion can't show a gain this size, and it leaves out Off's stretch, frame-generation-only inputs and Game after a temporal upscaler. The author's own measurement (point 2) should come first.
Overlaps and merge order: no open PR shares its code files apart from the usual
switches.defrow (no conflict with main today). #2053 changes what the present holds but lets gosync_order_muand the replay pin, notreplay_mu, so the invariant this PR rests on still holds with both merged. Either order.@ -294,6 +294,7 @@ SW(RX_VK_CAP_FREE_ASYNC, kill, bool, "on: a capture buffer past the spares is deSW(RX_VK_CAP_MIN_MB, tune, int, "2 MB", "The smallest capture buffer size class in MB; 16 is the old behaviour.")SW(RX_VK_CAP_SPARE_MB, hw, int, "32 MB of spare capture buffers on cards allowing 6.5 GB or less; no byte limit elsewhere", "Sets how many MB of spare capture buffers are kept for reuse; 0 means no limit, as before.")SW(RX_VK_CASCADE_BIAS, tune, string, "0,0: nothing added", "Adds a depth bias <units>,<slope> to the sun's shadow cascades.")SW(RX_VK_CHAIN_LOCKLESS, attempt, bool, "off: a scene draw decides as before (a target the Upscaler's format or mode rejects returns before the lock; the others ask under the temporal chain's lock whether the frame's camera is taken)", "1 (any value but an empty one, 0, false, off or no, in any case, spaces around it not counted): a scene draw first reads two atomics, which the places that take or let go of the camera write, and returns without the mode and the lock when this frame's camera, of a target at least as large, is taken. Off, the atomics are neither read nor written (the switch is still tested at each scene draw). Not measured in play. Read once, at its first use (HOS_AB cannot alternate it).")Blocking 1: turned off only because it is unmeasured. standards.md, Switches: it ships at its intended value from the first push, and is never off just because it is new or unmeasured. Ship it on (kind kill, =0 the old decision), then let the A/B decide.
@ -326,0 +336,4 @@constexpr uint64_t kNoCamera = ~0ull;bool chain_lockless() {static const bool on = [] {const bool v = env_on("RX_VK_CHAIN_LOCKLESS");Blocking 1: env_on_or("RX_VK_CHAIN_LOCKLESS", 1) once it ships on, and the log line to match.
@ -948,0 +987,4 @@// (longshot) RX_VK_CHAIN_LOCKLESS=1: this frame's camera, of a target at least this large, is taken: what the test under the// lock below says, here without it (chain_lockless, above). The two loads are of one camera as replay_mu holds every// writer off (cam_tell)if (chain_lockless() && s.cam_frame.load(std::memory_order_acquire) == texture_frame_no() &&Sound under replay_mu (checked: every s.cam writer and frame_no++ hold it). Suggestion: on that same ground, a direct read of s.cam here (without s.mu) is race-free and drops the mirror. Blocking 2: measure replay CPU time per frame and the shortcut's hit count; FPS/p99 can't show a gain this size.
@ -0,0 +60,4 @@MAIN = r'''/// The test under the lock (vk_temporal.cpp, after it): this frame's camera, of a target at least this largebool under_lock(uint32_t w, uint32_t h) {Suggestion: under_lock is the fixture's copy of the real test under the lock; cut the condition from vk_temporal.cpp so the two can't drift apart unnoticed.
1cdc21f87784157f837e@Beanstalk This makes a scene-sized draw learn this frame's camera for the temporal upscalers and frame generation from two atomics instead of the chain's lock (gpu/vk/vk_temporal.cpp), on by default; RX_VK_CHAIN_LOCKLESS=0 turns it off. Its gain is measured on the author's PC; frame time cannot show it, so this run checks the picture. This head is on main
9dd41326: please compare with main at that merge base. Please play Kokiri Forest for one minute in each Insert-menu upscaling setting that reaches this code: a temporal upscaler this farm's builds have, Off (the stretch), frame generation alone, and Game after a temporal upscaler; the PR's build with the switch unset against RX_VK_CHAIN_LOCKLESS=0, with a picture in each compared, on Windows with NVIDIA and on Linux with AMD (RADV). The same picture in every setting (no smearing, ghosting or jitter), no crash or validation error.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.WIP: perf(vk): a scene draw learns the frame's camera is taken without the chain's lock (RX_VK_CHAIN_LOCKLESS, off by default)to WIP: perf(vk): a scene draw learns the frame's camera is taken without the chain's lock (RX_VK_CHAIN_LOCKLESS)Thank you for the review (#issuecomment-65670). Pushed
84157f83, rebased on main @9dd41326(the branch's earlier commits unchanged by the rebase,git range-diff): testae8ab7a4, defaultae476851, test9003fc39, counts84157f83. The checks named below ran in jobdyl-2005of this PC's queue (Windows 11, llvm-mingw clang 23):test_chain_lockless.py,test_psychov35_off.pyandtest_switch_table.pypass at the head,test_chain_lockless.pyfails at each test commit, andvk_temporal.cppandvk_draw.cppcompile with the game build's commands. The--changedchecks and their failures on main are in jobdyh-2005, queued, and the description will give them. Nothing has run in the game.switches.def:297, and #issuecomment-65667,vk_temporal.cpp:339): you are right.RX_VK_CHAIN_LOCKLESSis on by default again, restored per docs/dev/standards.md (Switches), inae476851:env_on_or(..., 1), kindkill,=0(or empty,false,off,no) gives the draw's decision as before; the row, the title, the comments and the log line match.test_chain_lockless.pyruns unset as on (ae8ab7a4).vk: a frame's replay time (ms)), main,=0and unset, warmed and interleaved, with FPS, 1% lows and p99 only beside it. For the shortcut's share,84157f83counts the scene draws at the camera's test withRX_VK_PROF_FINE=1(the draw path's fine profile, off by default; one relaxed atomic increment a scene draw when on): the frame log gainsvk: a frame (fine): scene draws at the camera's test: <n> returned without the chain's lock (RX_VK_CHAIN_LOCKLESS), <n> went on to the lock, both a frame.test_chain_lockless.py(9003fc39) checks each fixture draw is counted once by the way it went, the line gives both counts a frame and then nothing new, and nothing is counted or logged with it unset or0; it fails at the test commit (no counts in the source) and passes at the head. If the A/B shows no gain beyond the spread, the change is dropped.tests/test_chain_lockless.py:58(#issuecomment-65669): taken inae8ab7a4:under_lockis now cut fromtemporal_note_scene_draw, fromstd::lock_guard lk(s.mu);to the return it makes, and the check fails if that is no longer oneifbefore the return.s.camdirectly instead of the mirror: kept for now, as you suggest weighing it once the gain is known. If the A/B earns the change its place, I'll try the direct read underreplay_muand dropcam_tell, the off-path rule and most of the source check.=0, with a temporal upscaler, Off's stretch, frame generation alone and Game after a temporal upscaler; the gain is to be measured on this PC first.@Beanstalk One correction to my request 65989 above, for its picture point: please take each 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, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.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.