fix(dlss): DLSS Frame Generation (NGX) is let go before the exit without freeing it under a frame #3077
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!3077
Loading…
Reference in a new issue
No description provided.
Delete branch "llun/Longshot:fix/dlss-fg-exit-release"
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 problem: a player quit the game with NVIDIA DLSS Frame Generation on (through NGX), and the graphics driver failed. Their log shows
VK_ERROR_DEVICE_LOSTsoon afterDLSS Frame Gen (NGX): let go for the exit. Their setup: RTX 5070 Ti, NVIDIA 621.40, Windows 11, nightly-1022, sandbox on. In a second log, they turned Frame Generation off before quitting, and the quit was clean.To see it on
main: play with DLSS Frame Generation on at a fixed multiplier, through NGX, then quit. It may take many tries. I did not reproduce it.The likely cause: when the game closes,
dlss_fg_closewaits for the GPU and then frees Frame Generation. A frame that is recorded but not submitted yet is not covered by that wait, so it can use what was just freed. This comes from the log and the code. #2807 fixed the same kind of fault for DLSS 5.The fix:
dlss_fg_let_go), throughtemporal_later, as #2807 does. It is freed once the GPU is done with every frame that used it, and it is not made again.Read first:
dlss_fg_closeanddlss_fg_let_goingpu/vk/vk_dlss.cpp, the call intemporal_idleingpu/vk/vk_temporal.cpp, andtests/test_dlss_fg_exit.py.See #2807, #2933.
Testing
Tested: Windows 11 Pro (build 26300), RTX 5080, NVIDIA 621.47, Ryzen 9 9900X3D, sandbox on, a 1920x1080 window, SDR, V-Sync Off, DLSS (Quality), DLSS Frame Generation 2x through NGX (
dlss_fg_through= NGX).kokiri-startsave, 5 to 8 s in play, then quit through the control bridge (quit). In all 15, Frame Generation was running (feature made for 1920x1080), the log sayslet go for the exit (146 to 224 ms, its frames done on the GPU), the exit code was 0, no log hasFATALor device lost, and Windows' event log has nonvlddmkmevent.longshot_vk.dll(where the fix is), DLSS helper DLL and generated shaders; onlylongshot-game.exediffers.mainwas not run. Triggering the fault can reset the GPU (#2807 tells of a PC that froze), so it was left out. So there is no before and after in the game, only the test below.tests/test_dlss_fg_exit.py(new): fails onmainat "a frame recorded before the close ran on a feature already freed", and passes here, with g++ and llvm-mingw's clang++. It compiles the realdlss_fg_close,dlss_fg_let_go,dlss_fg_idle,fg_releaseanddlss_fg_frames' start, withlater,free_deadandtemporal_idle's start, on a fake renderer whose GPU runs two submissions behind. It also checks: Off and not chosen, never made, parameters alone, a second close, no frame presented (0.5 s), a GPU that never finishes (2 s), and a lock held by a stalled recording thread. Undoing each of 14 parts of the fix makes it fail.-fsyntax-only -Wall -Wextraon the changedgpu/vkfiles with and without NGX (stand-ins for the generated shader headers): no error,vk_dlss.cpphas the same 4 warnings asmain.tests/test_dlss_fg_exit.pypasses, andvk_dlss.cpp,vk_temporal.cppandvk_dlssg.cppcompile with-fsyntax-only, without NGX (stand-ins for the generated shader headers). With NGX on Linux: not compiled here (its header was not found).mise run teston the head: 831 passed, 2 failed, 51 skipped (Windows; the skipped ones need Linux, spirv-val or a tool this PC lacks).test_i18n_complete.pyfails onmaintoo (the preset names with no translations). Correction: in that runtest_lifter.pyfailed for a reason of this PC's, notmain's: cargo ran with an MSVC host toolchain, so its clippy and tests never ran. Run again with1.99.1-x86_64-pc-windows-gnullvm: fmt and clippy pass, andcargo teststops atevery_site_has_one_owner_and_the_sites_are_the_ones_before_the_split(builder/crates/sites/tests/repository.rs), which fails onmainb4d56f526too (#3078's text; not run again onmainfor this PR). cargo stops at the first failing package, so the Rust tests after it did not run.mise run lintpasses.Still to test:
nvlddmkmevent (@Beanstalk DLSS FG NGX exit, Windows RTX 40/50: quit in play 20 times with Frame Generation on, check the log line and the event log)NVRM: Xidindmesg(@Beanstalk DLSS FG NGX exit on Linux NVIDIA: quit in play, check dmesg)mainagainst this PR, the quits with Frame Generation on, to see the fault onmain(by hand; the GPU may reset)Measurements
Nothing about speed in play changes, so there is nothing to measure there: one atomic load in
temporal_idle's closing branch, which only runs at the exit. The exit waits 146 to 224 ms for the release (15 quits, RTX 5080);main's wait was not measured.Risks
maindoes when the queue stays busy.dlss_fg_inputsalready does.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.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: Windows 11 (build 26300), RTX 5080, NVIDIA 621.47, sandbox on, 1920x1080 window, SDR, V-Sync Off, DLSS, DLSS Frame Generation 2x through NGX: 18 starts from kokiri-start (Kokiri Forest), 5 to 9 s in play each, then quit through the control bridge. In all 18 Frame Generation was running, the log says let go for the exit after 133 to 179 ms, the game exited with code 0, with no FATAL or device lost line and no nvlddmkm event in Windows' log. main was not run, and the fault was not reproduced.
Possibly related, for context:
@review
WIP: fix(dlss): DLSS Frame Generation (NGX) is let go before the exit without freeing it under a frameto fix(dlss): DLSS Frame Generation (NGX) is let go before the exit without freeing it under a frameRecommendation: Approve. The code is ready: only testing is left. The new retirement path addresses the identified recorded-but-not-submitted lifetime hazard, and the fake-renderer test exercises it. The reported driver failure has not been reproduced or confirmed fixed, and Linux NGX shutdown remains untested. Recommend approval; not approved on the forge.
DLSS Frame Generation is retired by the recording thread and released after its GPU work completes, with a bounded wait during exit. This removes the unsafe exit-time release path at the cost of a longer quit when the feature is active.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_dlss.cpp:2429: Confirm that the reported device-loss failure is resolved on the affected setup. (more on the line) Do: Reproduce the quit failure on main where feasible, then repeat the same quit scenario on this head and record the results and driver events.gpu/vk/vk_dlss.cpp:2429: Exercise the NGX retirement path on Linux NVIDIA before merge. (more on the line) Do: Run repeated in-game quits with NGX Frame Generation enabled on Linux NVIDIA and check the game log and kernel log for device loss or Xid events.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for the reported driver failure: the author reports 18 clean quits on an RTX 5080 and a game-free test that fails on main and passes here, but did not reproduce the original failure on main. The reported exit wait was 133–179 ms; main was not measured.
Other systems: The changed retirement path applies to NGX builds on Windows and Linux; non-NGX builds use a stub. Streamline has a separate shutdown path. Windows RTX 5080 was exercised in game; Linux NVIDIA and the original RTX 5070 Ti setup remain unverified.
Switches: None added, changed or removed.
Reviewed:
040fb0de48againstb4d56f5264: Read the repository rules, PR template, standards, commit messages, diff and new exit test; inspected the relevant DLSS, temporal, replay and shutdown paths and the changed test assertions. The full output for the larger changed source files and existing tests was truncated, so those files were not all read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no code, tests or project scripts were run. The supplied CI checks were still running.
Overlaps and merge order: Not checked; network access was unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -2425,43 +2426,64 @@ void dlss_fg_idle() {if (g.feature) fg_release(g), logf("vk: DLSS Frame Gen (NGX): frame generation Off or Auto: its feature let go");}void dlss_fg_let_go() {L1 (should fix): Confirm that the reported device-loss failure is resolved on the affected setup.
When: The reported RTX 5070 Ti failure is intermittent, and neither the original setup nor a failing main run is represented by the 18 clean RTX 5080 exits. The fake renderer establishes the modeled lifetime fix but cannot establish that it is the driver's actual failure.
Do: Reproduce the quit failure on main where feasible, then repeat the same quit scenario on this head and record the results and driver events.
L2 (should fix): Exercise the NGX retirement path on Linux NVIDIA before merge.
When: Linux builds use the same changed feature release and timeline retirement path, but the supplied runs cover Windows only; a platform-specific NGX shutdown failure would be missed.
Do: Run repeated in-game quits with NGX Frame Generation enabled on Linux NVIDIA and check the game log and kernel log for device loss or Xid events.
Two corrections to what I posted earlier:
1.99.1-x86_64-pc-windows-gnullvmand ran 15 new quits with Frame Generation on. All 15 were clean: exit code 0, no device lost, and nonvlddmkmevent in Windows. The wait before closing was 146 to 224 ms.longshot_vk.dll, where the fix is, came out the same in both builds.longshot-game.exedid not.test_lifter.py: its first failure came from the same mistake, not frommain. With the right compiler, fmt and clippy pass.cargo testthen stops atevery_site_has_one_owner_and_the_sites_are_the_ones_before_the_split, which #3078 says also fails onmain. The Rust tests after it did not run.Still true: I did not run
main, and I did not reproduce the player's error.