perf(vk): render targets moved by the game's layout shifts keep their images: no re-creation and re-upload (1 % low +13 %, POC) #2454
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2454
Loading…
Reference in a new issue
No description provided.
Delete branch "Veix/Longshot:wip/render-target-handover"
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
A proof of concept for testing and feedback, not for merging as is: when the game's render-target layout moves, the moved targets take over unused images of their own kind instead of getting new ones. On the walking route's second Castle Town stay the frames over 20 ms drop from 63.5 to 26 (3 runs against 2, interleaved), the 1 % low rises from 41.2 to 46.4 fps, an area entry settles at once (the castle: no frame over 20 ms after 0.25 s, against 7-9 s on
main), and 29 % less image memory is made and destroyed.The game packs its render targets bottom-up into one pool, every frame (the allocator
f_8005ed00). When a target appears or goes (a pass that runs only some frames, an effect, a view), every target behind it moves to a new address. The renderer keys its images by address and create info, so each moved target is a new texture: 12-44 new images in one frame, 20-29 ms frames in the market. The game itself just re-initialises the same targets at their new places.What this changes (
gpu/vk/vk_texture.cpp, all on by default here):RX_VK_TEST_HANDOVER=3,=0off): a render target made new takes the image of an unused target of exactly its create info (not used in this present), so the moved target needs no new image (the 20-29 ms frames). Never a donor, each rule from what was seen without it:RX_VK_TEST_DONOR_ONCE,=0off): drawn at an area's load and read every few presents, like the far LODs' 260x260 RG8 of 9 levels and a 128x128 cube of 8. Without it: far LODs in Hyrule Field darker than onmainuntil seen up close (their drawing given away, then loaded from memory, which never had it). Single-level targets are left out of this rule: the market's layout targets are often drawn in one present before they move, and the rule on all of them took most of the gain back (frames over 20 ms 18 -> 43-51).RX_VK_TEST_HANDOVER_CLEAR=2;=1clears at once, as a new image): a handed-over image is cleared at its first write; a first read keeps the donor's content when the donor was the only candidate (a 3840x2160 R32F target the game reads before it draws it each frame). Without a clear: the donor's old picture showed where the game draws only part of a new target (pop-in). Cleared at once instead: the R32F target lost its content and was loaded from memory, 32 MB, almost every time it moved. With several candidates the content is not kept: which one was the predecessor is not known, and another target's picture would be wrong.RX_VK_TEST_CARRY=1,=0off): a texture made by a read takes its unambiguous predecessor's image and content (exactly one of its size and exact format, GPU-drawn, used in the last two presents and not this one, 256 KB or more; no integer formats) instead of a 32 MB load from memory. Without it: those loads (3840x2160 RGBA8 and R8 targets made by a read, read before drawn), as spikes, for example when Link bumps into people in the market. Integer formats are left out: a 960x540 RG16UI buffer (ids, not a picture) is never carried.vk_temporal.cpp,vk_fsr3_inputs.cpp): "the scene depth may be gone" now checks the depth texture's own id in the destroy log, not whether any texture was destroyed (a hand-over destroys one mid-frame; DLAA left its place before the bloom: a full-screen exposure flicker).LONGSHOT_TEST_DIAG=1(off by default): the investigation's logs and tooling. Without it nothing of it runs: no log lines, no polling. (The in-play D-pad down / F10 toggle of the first version is switched off: content made while it was off stayed off until an area change, which confused comparisons.)It is one commit: a local test branch squashed onto current
main, its code left as it was tested (and a second one that switches the in-play toggle off). Diagnostics and experiments in it, not meant for a clean version (the logs and the host's per-present work only withLONGSHOT_TEST_DIAG=1): the per-frame render-target pool logs inhost/nvn_native.c(HOS_LOG_RT_POOL, the "TEST inits present" lines), theLONGSHOT_TEST_FORCE17/LONGSHOT_TEST_RTPROBElift patches innx2/build.py(off unless set at build time) with R3 / F9 in the host,RX_VK_MOVE_DIAG,RX_VK_LOG_WENT, the "TEST" log lines invk_texture.cpp(hand-overs, donors needed again, carries, made new), and test switches (RX_VK_TEST_HANDOVER_MIN_KB,_POOL_FIRST,RX_VK_TEST_DONOR_READ,RX_VK_TEST_DEFER_UNIQUE,RX_VK_TEST_ONE_LEVEL,RX_VK_TEST_CARRY=2). None of the switches has a row inswitches.def(the log names them as unknown).Read first:
handover_takeandcarry_takeinvk_texture.cpp, the hand-over branch increate, andtexture_touch's deferred clear.Testing
Please no automatic fixes on this branch (
@fix, bot pushes): it is for testing and feedback, and its next form is a clean branch.Tested: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, 3840x2160 DLAA. The walking route (Castle Town, the castle, Castle Town again) and free play in Castle Town and Hyrule Field, by hand, with each part switched on and off. Seen and fixed along the way: pop-in of new targets (the clear), a full-screen exposure flicker with DLAA (the depth guard), far LODs in Hyrule Field darker than on
main(the drawn-once rule). With all of it on: no pop-in, flicker or dark LODs seen. The squashed commit builds on currentmain(Windows, llvm-mingw, without the test build switches).Still to test:
RX_VK_TEST_HANDOVER=0andRX_VK_TEST_CARRY=0(the hand-over and the carry off); report anything that looks different (by hand)Measurements
Verdict: on the second Castle Town stay, frames over 20 ms 63.5 -> 26 (-59 %), 1 % low 41.2 -> 46.4 fps (+13 %), p99 21.5 -> 19.6 ms, fps 62.95 -> 63.9; loads of 30 MB or more 10.5 -> 1.3; image memory made and destroyed 404 -> 287 MB/s. The castle entry is smooth after 0.17-0.25 s (7-9 s on
main). The game's part of a frame is 0.17 ms longer: a caveat of this implementation (below).Setup: Windows 11, Ryzen 9 9900X, RTX 4070 SUPER 12 GB, driver 621.24; 3840x2160 DLAA, uncapped, V-Sync off, the frame gate off,
RX_VK_LOAD=start(every shader loaded before the title, so none is made during a run); the walking route (Castle Town, the castle, Castle Town again). Interleaved: PR, main, PR, main, then one more PR run of this exact commit (the logs off). The second Castle Town stay from 5 s after its entry to its end; the entries over the 10 s after the area change; the image memory and VRAM over the whole run.mainbuilt from8aa5ab87into a second game folder with the same options and shader cache.8aa5ab87(2 runs)f5cf931c(3 runs)The first two PR runs had the logs on (
LONGSHOT_TEST_DIAGdid not exist yet); the third is this commit as it is. The longest stall of an entry (the game loading the area, 33-86 ms) is the same on both sides.Caveat, the game's part (+0.17 ms): the main thread's own CPU time is unchanged (4.24 against 4.34 ms); the game waits for the render thread more often: its catch-ups (a finish, a readback) 6.4 -> 11 per 600 frames, its queue full 1 -> 9-13 times. With the carry off (
RX_VK_TEST_CARRY=0, one run) the catch-ups fall to 2, the game's part to 8.51 ms, and the rest of the gain stays (frames over 20 ms 18, p99 18.9 ms). So it is the carry as it is done here: it walks every texture for each texture made by a read, and a carried texture is marked drawn by the GPU, which likely makes the game's later access wait for a write-back. To be done more efficiently in a clean version (candidates by size and format; the carried texture's state).Risks
switches.def,MKWVK_API_VERSIONis not bumped for the diagnostic callback invk_api.h.RX_VK_TEST_HANDOVER=0turns the hand-over off,RX_VK_TEST_CARRY=0the carry (at the start).longshot_options.inior the 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
mainand passes here.gpu/vk/switches.def.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged).mainand here, for a change that shows on screen.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, 3840x2160 DLAA: the walking route (Castle Town, the castle, Castle Town again) 3 runs of this PR against 2 of main, interleaved, and free play in Castle Town and Hyrule Field by hand. No pop-in, flicker or dark LODs seen with it on; numbers in Measurements.
Possibly related, for context:
WIP: perf(vk): render targets moved by the game's layout take over an unused image of their kind instead of a new one (POC, all on)to WIP: perf(vk): render targets moved by the game's layout shifts keep their images: no re-creation and re-upload (1 % low +13 %, POC)WIP: perf(vk): render targets moved by the game's layout shifts keep their images: no re-creation and re-upload (1 % low +13 %, POC)to perf(vk): render targets moved by the game's layout shifts keep their images: no re-creation and re-upload (1 % low +13 %, POC)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.