perf(vk): AMD FSR 4's unrolled layers in a pipeline cache of their own, kept across updates, and taken from it with no memory asked #1752
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1752
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:perf/fsr4-own-cache"
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?
Type: perf · Risk: low · Tested on: Windows 11, RX 6700 XT (Adrenalin 26.10.1) · Needs: Linux, AMD (RADV); another AMD card on Windows
TL;DR
AMD FSR 4's three fastest layers (#2798's unrolled ones) take about 50 s and 3 GB of memory each to build the first time, and most updates threw them away, so after each update FSR 4 ran slower for its first minutes while they were built again. They are kept in a file of their own now, which updates keep, and loaded from it in a fraction of a second. A PC with less than 8 GB of memory to spare also gets them now when they are already built, instead of running without them. Checked in game from a new folder (what an update is): 0.1-0.5 s from the file, a cold build without it.
Breakdown
cache/longshot_fsr4_pipelines.bin, and a layer already built is taken from the caches before the memory check.Why
Since #2798 (Hookshot's https://github.com/NotRexed/Hookshot/pull/2798) AMD FSR 4's passes 1, 2 and 12 run as unrolled pipelines, built in the background at the first FSR 4 frames: about 50 s and 3 GB of memory each when the driver compiles them, which is why at most one builds at a time and only with 8 GB of memory to spare (
kBuildHeadroom). They were kept in the translator's pipeline cache, andpcache_drop_staledrops that cache's files whenever the translator changes, which is most updates. On this PC the first start of v3.0.0 built them cold again (48.9 s,48.7 s,50.7 s to buildin its log), though nightly-486 had built them the day before. And the memory check came first: a run with less than 8 GB to spare (not unrolled now: 7103 MB of memory to spare, 8192 wanted, seen here) ran without them even when they were in the caches, at about 4.5 ms for FSR 4's passes instead of 4.0 on an RX 6700 XT.What changed
The unrolled layers get a pipeline cache of their own, outside the translator's files, and are asked of the caches before the memory a compile needs is asked for.
build_unrolledandown_cacheingpu/vk/vk_fsr4.cpp: the layer is first created withVK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BITthrough its own cache; only when that needs a compile doesbuild_headroomdecide, as before. The cache is read at the first build and written after a layer's build whenever its data grew since it was read or last written: the driver may hand a layer over at once from its own disk cache (kept per game folder path), so a quick build is no sign that the file holds it.RX_VK_PCACHE_LOAD=0(or its rule) leaves the file unread and unsaved, as the pipeline cache's file.own_pipeline_cache,own_pipeline_cache_saveandown_cache_compute_pipelineingpu/vk/vk_draw.cpp, besideshared_compute_pipeline: the file read throughpcache_file_read(another driver's or GPU's file is not given to the driver), written throughplay_file_write(a .tmp moved over it, under the fetch lock) when its size changed, and the build with the same compile turn and gates asshared_compute_pipeline.pipeline_cache_file.h's sweep of cut-short saves knows the file's.tmpnames too.tests/test_fsr4_own_cache.pyrunspcache_stamp.h's drop against a folder with the translator's files and FSR 4's: a new translator drops its own files and keeps FSR 4's; it also checks thatbuild_unrolledbuilds and saves through the file and asks the caches before the memory, and runs the sweep on a leftover.tmpof the file.docs/development.md:RX_VK_PCACHE_LOAD=0names the file.tests/test_compute_gate.pyknows the third gated caller ofguarded_compute_held, with the same checks ascached_compute's.Measurements
Verdict: after an update the layers load from their file in 0.1-0.5 s instead of building cold, and a cached layer no longer needs 8 GB to spare. The game-free test fails on main and passes here.
Hardware: Windows 11, RX 6700 XT 12 GB, Adrenalin 26.10.1, Ryzen 5 5600, 16 GB (RAM at JEDEC speed)
Scene: Hyrule Field by day, standing; 2560x1440, AMD FSR 4 Performance, uncapped
Method: the change applied to the v3.0.0 renderer (its
vk_fsr4.cppis main's; renderer built alone) in a copy of a v3.0.0 game folder, headless through the control bridge. An update is a game folder at a new path, so it was run through a directory junction to the same folder (a new path, the same files): AMD's own shader cache is kept per path. The control: a second new path with the file moved away. Log lines below.How to reproduce:
python -I -B tests/test_fsr4_own_cache.py --cxx clang++; in game, FSR 4 on an AMD card, play until the log hasbound in its place from nowfor passes 1, 2 and 12 (the file appears incache/), then start the same build from another path (mklink /J <new> <game folder>and run<new>\bin\longshot.exe), expectingthe unrolled layers' pipeline cache: readandfrom the caches8b0ea786feb6b43etest_fsr4_own_cachenot unrolled nowwith 5.8 GB to spare)not unrolled now ... 8192 wantedNo fps comparison: the change moves when the layers become available, not their speed (4.04 ms against 4.48 ms without them, #2798's numbers), and another game run shared this GPU during these runs.
Flags and settings
None
Testing
Tested: in game as in Measurements (the first start writes the file, about 60 KB; the next reads it and leaves it as it was; a new path reads it; a new path without it does not find the layers). A cold review by a second agent: its points are in (the save rule by size, not by build time; the sweep of cut-short saves;
RX_VK_PCACHE_LOAD=0; no log when the cache could not be made). The new test both ways, and against a broken fix (the memory asked before the cache: it fails). The renderer builds whole from this branch (Windows, llvm-mingw), with a local workaround for main's own Windows build break indescriptor_array_census.h(#1729; not in this PR). The tests that readvk_fsr4.cpp,vk_draw.cpporpcache_stamp.hpass, except ones that fail the same way on main on this PC (test_upscaler_rows,test_pipeline_play_cache,test_prepare_cache_save,test_dev_packs,test_linux_pressure,test_linux_driver_fault_guard,test_pipeline_tour,test_tracy_funcs,test_recorder_sync,test_vk_occlusion_queries,test_draw_stream_visibility,test_fsr_uniform_ownership; each run on main's sources here).Not testable by hand: a real update's first start: the new-path runs stand in for it.
Not tested: Linux (RADV, fsr4-vk), other AMD cards, a driver update (another driver's file is refused by
pcache_file_readand the layers are built as before, then the file is written again).Must be tested:
bound in its place from nowfor passes 1, 2 and 12, then start again, expectingthe unrolled layers' pipeline cache: readandfrom the caches(Test Farm: @Beanstalk linux amd, FSR 4 on, two starts, check the log)Risks
What could break: the file can't be written (a read-only folder): the layers are built as before at each start that has 8 GB to spare, and the log says so. A damaged file: refused by the header check, or the driver ignores what it can't use.
Turning it off:
RX_VK_FSR4_TUNE=0turns the whole tune off, as before; otherwise revert the commit.Compatibility: one new file in
cache/(~60 KB here). It is never pruned: a new AMD library or unroller adds its layers beside the old ones (another ~60 KB each time) rather than replacing them. The translator's pipeline cache is unchanged; the layers' pipelines left in old play files go when those files next go.Issues
See #744 (FSR 4 performance reports)
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
Tested in game: Windows 11, RX 6700 XT, Adrenalin 26.10.1: the change on the v3.0.0 renderer (its vk_fsr4.cpp is main's) in a v3.0.0 game folder, Hyrule Field, FSR 4 Performance, headless: first start writes cache/longshot_fsr4_pipelines.bin, the next reads it; from a new folder path (a junction, as an update) the layers load from the file in 0.1-0.5 s, and without it the cache ask fails (a cold build needed)
Description: fixed the path in Measurements' How to reproduce (a backslash had been eaten).