WIP: feat(vk): add AMD FSR 4 Frame Generation (MLFI 4.0.2) #2831
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2831
Loading…
Reference in a new issue
No description provided.
Delete branch "nwgat/Longshot:feat/fsr4-framegen"
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
Adds standalone AMD FSR 4 Frame Generation (ML Frame Interpolation 4.0.2) via the AMD FidelityFX SDK v2.4.0 (
amd_fidelityfx_loader_vk.dll+amd_fidelityfx_framegeneration_vk.dll) on supported AMD GPUs, plus 10-bit PQ Native HDR support (A2B10G10R10_UNORM_PACK32) integrated with Longshot's Native HDR framegen buffers.FFX_FRAMEGENERATION_FLAG_NO_SWAPCHAIN_CONTEXT_NOTIFY), executingffxConfigure→ffxDispatchDescFrameGenerationPrepareV2(with reversed depth, render-pixel actor motion, and world-space camera basis fromvk_fsr3_inputs) →ffxDispatchDescFrameGeneration(numGeneratedFrames = 1, up to 2×).opts.framegen_by = 3) and enables AMD Anti-Lag 2 (opts.antilag = 1, synced viamenu_antilag_changed), while keeping both rows manually overridable.color_format) in Native HDR and composites crisp 10-bit PQ HUD pixels onto generated frames viashaders/fg_hud_fsr4_pq.comp(and the learned HUD layerhud.over_pipe/hud.over_pipe_rgba8in SDR).RX_VK_FSR4_FG=0|1forbids or forces FSR 4 FG for a run; DLSS FG (NGX and Streamline) and XeSS paths are untouched.Files to read first:
gpu/vk/vk_fsr4_fg.h,gpu/vk/vk_fsr4_fg.cpp,gpu/vk/vk_framegen.cpp,gpu/vk/menu/framegen.cpp,gpu/vk/fsr3_math.h,gpu/vk/framegen_rows.h, andtests/test_fsr4_fg.py.Testing
Tested:
providers 4.0.2, 3.1.6; using 4.0.2), verified context creation and frame generation in SDR and Native HDR PQ.main @ cb0a2763):test_fsr4_fg.py,test_framegen_by_row.py,test_framegen_dlss_cap.py,test_pacing_policy.py,test_menu_i18n.py(14/14),test_menu_i18n_count.py,test_menu_ini_keys.py,test_pass_barrier.py,test_fsr3fi_hud_mask.py,test_antilag.py,test_framegen_fixed_pace.py.g++ -std=c++20) both with and without-DLONGSHOT_FSR:vk_framegen.cpp,vk_temporal.cpp,menu/framegen.cpp,vk_fsr4_fg.cpp,vk_fsr3_inputs.cpp.Still to test:
d84c9d8b): re-verify in-game SDR, Native HDR PQ (10-bit HUD composite), Auto mode (with Anti-Lag 2 auto-enable), and Fixed 2× after themain @ cb0a2763rebase (by hand).@Beanstalk/ by hand).FSR4_FG_SKIP_NO_LIBRARY/FSR4_FG_SKIP_NO_MODEL) and builds without--upscaler fsr4(@Beanstalk/ CI).Measurements
Verdict: Pending — interleaved A/B frame-time and pacing measurements against
main @ cb0a2763(FSR 4 FG 2× vs FSR 3.1 FG 2× vs FG Off in SDR and Native HDR) still to be recorded while in WIP.Setup: Windows 11, AMD Radeon RX 9070 XT, Adrenalin 26.11.2, 3840×2160 @ 120 Hz.
cb0a2763d84c9d8bRisks
third_party/fidelityfx/framegeneration/include/ffx_framegeneration*.h); no AMD binaries ship with Longshot.RX_VK_FSR4_FG=0disables FSR 4 FG completely for a run; reverting the branch restoresmainwith no save, cache, orlongshot_options.iniincompatibility (an older ini'sframe_generation_by=0stays FSR 3.1 FG / DLSS FG).d84c9d8bafter adapting to upstream's 10-bit Native HDR (3f94da5d), Streamline (6e6f1160,450e63b8), and 45 FPS cap (53607d0d) changes.Checklist
Ready for review
main(cb0a2763); the title is a Conventional Commit.d84c9d8b.)mise run testpasses (any failure that also fails onmainis named). (Targeted unit tests passed; fullmise run testnot yet run.)main, or Measurements says why there is nothing to measure. (Interleaved measurements TBD in WIP.)third_party/untouched; nothing GPL-incompatible. (Note: adds MIT-licensed FFX SDK 2.4.0 headers underthird_party/fidelityfx/framegeneration/include/withPROVENANCE.md/README.md/scripts/fetch.py/mise.lockupdated.)When it applies
RX_VK_FSR4_FGadded with its row ingpu/vk/switches.def.tests/that reads changed source is updated, not weakened.gpu/vk/shaders/fg_hud_fsr4_pq_comp_spv.h).g++on Windows; Linux build pending CI.)mainand here, for a change that shows on screen. (Pending in-game capture ond84c9d8b.)docs/dev/reference/upscalers.md,docs/user/graphics-and-controls.md).Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, AMD Radeon RX 9070 XT, Adrenalin 26.11.2, 4K: FSR 4 FG 4.0.2 verified in 3D gameplay (SDR and Native HDR PQ)
Possibly related, for context:
946ffd684fd84c9d8b1dFound while playing a build with this PR (head
d84c9d8b1) merged on main28cb22b9e: with Frame generation at Auto, the FSR 4 FG context is dropped after every present and made again at the next one.gpu/vk/vk_replay.cpp, after the frame-generation recording:swapchain_framegen()(vk_main.cpp) returns 0 for Auto as well as Off (framegen >= 2 ? ... : 0), so in Autofsr4_fg_idle()runs every present and retires the context, andfsr4_fg_framesmakes a new one on the next frame. The comment above it says the intent is "idle only at Off".From the play log (Windows 11, RX 9070 XT, Adrenalin 26.11.2, 5120x1440): 249
FSR FG 4.0.2 made for 5120x1440lines in one session, 209 of them one frame after the previous, median 95.7 ms of CPU each (the first 16.3 s). The game was CPU-bound with Auto on.The fix I ran with:
framegen_now()isopts.framegenas it runs (1 at Auto, 0 at Off). With it,test_fsr4_fg.py,test_framegen_by_row.py,test_framegen_dlss_cap.py,test_present_held_image.pyandtest_rt_pin.pypass. Fixed 2x was not affected (swapchain_framegen()is 2 there). Not checked in game beyond the context being made once: a test that changes the row to Auto and counts context creations over several presents would catch it.d84c9d8b1d49bc23ee1c@review
Please rebase too!
Recommendation: Request changes. Auto mode repeatedly destroys and recreates the FSR 4 FG context, producing severe frame stalls. Windows players with non-ASCII installation paths can also lose access to the feature, and the claimed benefit and costs remain unmeasured.
Adds AMD FSR 4 frame generation and a Native HDR HUD composite, with an automatic FSR 4 FG default on supported hardware. It expands frame-generation choices but adds context creation, GPU work and memory use whose costs have not yet been measured.
Blocking (3): must change before merging.
gpu/vk/vk_replay.cpp:5741: Auto mode retires the FSR 4 FG context after every present. (more on the line) Do: Use the running frame-generation mode to distinguish Off from Auto, and add a behavioral test that checks the context stays alive across Auto presents.gpu/vk/vk_fsr4_fg.cpp:198: The Windows loader passes UTF-8 paths to the ANSI file and library APIs. (more on the line) Do: Convert the UTF-8 path to UTF-16 and use GetFileAttributesW and LoadLibraryExW, as required for Windows paths.@fixor@rebasetry first). (for the author)Nits (1): optional.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Preserve the existing FSR 3.1 default until the FSR 4 default is supported by measurements.)@fixcan do L1, L2, L3 and L4.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. The author reports successful SDR and HDR gameplay on an RX 9070 XT before the rebase, but the before-and-after measurement table is empty. A tester reported 249 context creations in Auto mode, with a median 95.7 ms CPU cost per creation, on a build containing
d84c9d8b.Other systems: The new backend changes replay recording, frame-generation input capture, HUD composition and runtime installation. NVIDIA and Intel GPUs, Linux, Steam Deck, fallback paths and the current head's SDR and HDR output still need the runs described in the pull request.
Switches: RX_VK_FSR4_FG is added: unset follows the frame-generation choice, 0 forbids FSR 4 FG, and 1 forces it. It has a switches.def row; the automatic default on supported AMD GPUs has no measurements yet.
Reviewed:
49bc23ee1cagainst4908cc6dad: Read the repository rules, PR template, commit log, main renderer integration diff, FSR 4 backend, frame-generation menu changes, input changes, builder and fetch changes, and new test. Skimmed the remaining test diffs, documentation, provenance, translations and generated shader header; did not read every changed file in full. docs/review-checklist.md is absent.; nothing run (a code review).Checked and fine:
Testing: No code, tests or project scripts were run, as requested. CI is still running. The maintainer-requested rebase was not performed because the review rules expressly prohibit changing git state.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +195,4 @@if (!dev.device || !dev.physical) return l.tried = false, false;std::string where;for (const std::string& dir : library_dirs()) {where += (where.empty() ? "" : ", ") + dir;L2 (blocking): The Windows loader passes UTF-8 paths to the ANSI file and library APIs.
When: When the game or RX_VK_FSR_DIR is in a path containing characters outside the Windows active code page, GetFileAttributesA or LoadLibraryExA cannot find the DLL, so FSR 4 FG is reported unavailable even when the runtime is installed.
Do: Convert the UTF-8 path to UTF-16 and use GetFileAttributesW and LoadLibraryExW, as required for Windows paths.
@ -5738,2 +5739,3 @@// (frame generation at Off or Auto, where DLSS-G is not asked: its feature, if made, let go, vk_dlss.cpp)// (frame generation at Off or Auto, where DLSS-G is not asked; FSR 4 FG runs in Auto too, so idle only at Off)if (swapchain_framegen() < 2) dlss_fg_idle();if (swapchain_framegen() < 1) fsr4_fg_idle();L1 (blocking): Auto mode retires the FSR 4 FG context after every present.
When: swapchain_framegen() returns 0 for both Auto and Off, so an Auto present calls fsr4_fg_idle() and the next eligible present creates a new context. The tester observed a median 95.7 ms CPU creation time and repeated stalls.
Do: Use the running frame-generation mode to distinguish Off from Auto, and add a behavioral test that checks the context stays alive across Auto presents.
49bc23ee1c7b35d7228f9fe11674f8e632dacc9fView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.