WIP: feat(vk): RX_VK_PART_PLAN, a part plan checked against the replay #3279
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3279
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:perf/parallel-replay"
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
The render thread replays every command buffer of a frame alone. Where it is the limit, a second thread recording some of a
submission's parts could make the frame faster; the segment workers that tried it (
RX_VK_PARALLEL, removed in #1763)lost on most PCs and left a tail of faults, because their dry pass had to repeat every side effect the replay makes in
stream order and nothing ever compared it with the replay. This PR is the groundwork for doing it again safely, and
changes nothing a player sees:
replay()'s switch intoapply_state(gpu/vk/vk_replay.cpp), which the replay and the new walk both call. Their logs run on the replay only.plan_run): a walk of a command buffer ahead of its replay, with the state alone, for where itsparts end (
maybe_split's own rule and limits, now inpart_limitsandpart_ramps) and the state each begins with(
NvnState, the ubo generations, the uniform updates before it). A render condition the game did not snap at itssubmit reads live memory, which the stream, the GPU and the replay's write-backs may change before the replay reads
it: the walk reads memory as it is and marks the cuts after it inexact (a snapped one leaves them exact). The walk's
occlusion queries stay in its copy of the state (
occ_take/occ_counter_resettakeplan).RX_VK_PART_PLAN=check(diag, off): plan at eachreplay()and at each met wait, and compare the replay's state atevery planned cut ("vk: part plan" lines;
plan_at, one call an op inreplay()'s loop). The recording is the samebut for timing: the walks delay the replay, so a condition the game did not snap can read memory written in the
meantime, as with any slower replay.
=check-faultleaves the texture binds out of the walk: its control.RX_VK_PART_HELPERS, off by default, forPCs with spare cores):
docs/dev/reference/parallel-replay.md.Read first:
apply_state,plan_run,plan_atand the call at the top ofreplay()'s loop.Testing
Tested: on my PC: AMD Radeon RX 9070 XT (driver 26.11.2), Ryzen 7 5700X3D, Windows 11. The game runs used this change
on
f359e262(the pack's tree isf359e262with the change cherry-picked: the same replay code). The last two commits afterthem change only the check's summary line, the tests and the docs, and give the ramp's mode one helper (
part_ramps,the same
mode == 1as before).RX_VK_PART_PLAN=checkat Market center (the standard test's fountain save, the camera turning, uncapped): at 30,000cuts, 29,198 had the same state and 802 differed, none of them at an exact cut: all came after a render condition the
game did not snap (9,057 cuts did). Of the replay's 39,929 own part ends, 29,997 were where planned and the other 9,932
were skip-tail's (
HOS_FRAME_SKIP_TAIL, which the walk does not model).=check-fault, the control: at 30,000 cuts,29,976 differ.
0ae642a27, game-free),main
302cdf035against this change (346530d6: the change without the check summary's two new counts): the samecommands and picture in its draws and mixed scenes, with and without the Khronos validation layer's synchronization
validation. Both sides showed the same two layer messages, neither about the replay: VALIDATION-SETTINGS and a
cooperative-matrix SPIR-V VUID.
=checkthere: 64 of 64 cuts the same state, all 64 of the replay's own part endswhere planned (walks 35-45 us each);
=check-fault: 64 of 64 differ.tests/test_part_plan.py(game-free):plan_run,apply_state,part_limits,part_ramps, the occlusion functions,the check's compare and
plan_atcut from the source and run on op streams against a model of the replay, with thereal
vk_state.h: cut placement (first part past 32, then 120, the 512 ceiling inside a pass; withRX_VK_PART_ADAPTIVEon, 32, 120, then 240), the before-draw rule, the same state at every cut, conditions (snapped:exact, its own words; live: inexact, both words read from memory), the stop at a wait and the walk after it, uniform
update counting, no occlusion side effects, a clear of no channels, the hook op by op (a met wait, a cut at a wait
compared, skip-tail's part end), =check-fault differs, every member named by the compare. 21 broken variants must fail
(a snapshot one op late, no stop at a wait, uniform updates of no bytes counted, the walk's queries noted for the part,
a live condition taken as exact, a condition's words not read (either word, or a snapped one's own), no cut exact, a
draw that opens no pass, a plain draw that is not drawn taken to begin a part, a clear of no channels that opens one, no
512-draw ceiling, the before-draw rule ignored, the legacy part lengths with
RX_VK_PART_ADAPTIVEon,gridcompared,the walk after a wait begun one op late or from a count of 0, a cut at a wait not checked, a cut the check compares with
nothing, skip-tail's part end counted after its dispatch), and 2 of the source census (an
NvnStatemember left out ofthe compare, a state op handled in
replay()itself); the source checks also holdmaybe_splitandplan_runtopart_limitsandpart_ramps.Two existing checks that cut
replay()'s cases by their labels now look insidereplay()(the walk's draw case has thesame label);
test_early_split_before_drawtakespart_limitsandpart_ramps, and stubs of the plan's hook, into itsfixture.
tests/run_all.py --changed origin/main(the 189 checks that read the changed files) on 346530d6: 178 passed,7 failed, 13 skipped. The 7 fail on main
302cdf035too, run the same way on this PC: test_dlssg, test_input_background,test_present_acquire_ahead, test_present_held_image, test_present_image_free, test_present_semaphores,
test_vk_draw_overhead_lean. On the head, test_part_plan and the four checks the move touches pass, and
mise run lintpasses.
Still to test:
adult Temple of Time route, still input), and the Khronos validation layer's synchronization validation at Market
center with
RX_VK_PART_PLANunset and=checkagainst two base runs, expecting the same pictures and no newVUIDs nor more of them (by hand, running now).
RX_VK_PART_PLANunset, expecting the same frame times within noise and no new errors in the log; and this PR withRX_VK_PART_PLAN=check, expecting its "vk: part plan" summary lines to count 0 cuts that differ at an exact cut(@Beanstalk, the request in the comments).
Measurements
Verdict: no gain meant (groundwork; the switch is off by default) and no cost the game shows: -0.2 % fps and
+2.3 % CPU ms, inside the standard test's 3-pair noise (about 2-3 % CPU ms). The replay bench alone, which times only
the per-draw path, puts the change 1.5-2 % slower, about 0.02 us a draw.
Setup: Windows 11, AMD Radeon RX 9070 XT (driver 26.11.2), Ryzen 7 5700X3D. In the game: the standard test (Market
center from a save at the fountain, the camera turning,
HOS_FPS_MAX=240, 1280x720, a fixed 16:9 profile, a co-load),3 alternating pairs, the medians; the change cherry-picked onto
f359e262(the same replay code as this head), theswitch at its default. Replay bench (#3268, game-free):
microseconds a draw over its fastest frames, 9 runs a side, once with main first and once with this change first.
f359e262f359e262+ 434836628's changeThe pairs' CPU ms: +3.2, -1.0, +2.5 %. std_test marks it diagnostic (under 5 % with 3 pairs).
Why the game's numbers still hold on this head's base, main
302cdf035: the change is the same text on both bases, and itscost is per op in replay()'s loop, which the replay bench below measures on
302cdf035itself: 1.5-2 %, about0.02 us a draw, the same order as the game's +2.3 % CPU ms inside its noise.
302cdf035346530d6 is this head without the check summary's two new counts (diagnostic code only). On the earlier base (main
7bc53f841, 3 runs) the same change measured -3.0 % and -0.8 % a draw, so the sign follows the build's code layout asmuch as the change.
=check, off by default, costs its walks: 4-7 us each in the game, one at each command buffer'sreplay and met wait.
Risks
The state ops now run through
apply_stateon every replay: a mistake in the move would change what a draw binds. Themoved code is the same text (its logs behind
kReal), the source census checks no state op is left inreplay(), thereplay bench records the same commands and picture as main, the game's picture and synchronization validation match the
base (Tested), the standard test above shows the cost, and the check mode compares the walk with the replay in the game.
RX_VK_PART_PLANis off by default; with it off, the only other change is one test of a static an op. A revert isenough. Nothing changes after updating: no setting, cache or shader stamp file is touched (
vk_state.handvk_api.hare unchanged).
If #3117 lands, the mode it ramps in is
part_ramps's one line, formaybe_splitand the plan alike.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.🤖 Generated with Claude Code
Tested in game: AMD Radeon RX 9070 XT (driver 26.11.2), Ryzen 7 5700X3D, Windows 11; Market center (the standard test's fountain save, camera turning, uncapped), the change on
f359e262. RX_VK_PART_PLAN=check: at 30,000 cuts 802 differ, 0 of them at an exact cut (all after a render condition the game did not snap); 29,997 of the replay's 39,929 part ends where planned, the other 9,932 skip-tail's, which the walk does not model. =check-fault (the control): 29,976 of 30,000 differ. Switch off (the default): the standard test's 3-pair A/B, -0.2 % fps and +2.3 % CPU ms, within its noise. A picture comparison against the base is still to run (Still to test).Possibly related, for context:
On BeanBot's pointer to #3117: it is related. #3117 changes which
RX_VK_PART_ADAPTIVEmode ramps the part lengths (mode == 1tomode == 3inmaybe_split), and this PR's plan walk takes its part lengths by the same rule. Before0bdbb4987the walk had its ownmode == 1, so #3117 landing after this would have left the plan ramping wheremaybe_splitno longer does: the=checkrun would show it only as part ends not where planned, and no test would fail.Since
0bdbb4987both askpart_ramps(mode)(gpu/vk/vk_replay.cpp, besidepart_limits), so #3117's change is one line there for both.tests/test_part_plan.pyholdsmaybe_splittopart_ramps, and itsadaptivecase and thelegacy-thresholdsbroken variant check the walk's ramp. Whichever lands second, the merge touches the samemaybe_splitline, so it shows.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.