Let FSR 3.1 and FSR 4 destroy a context they let go of once the GPU is past its last upscale, instead of waiting for the device.

vk_ffx.cpp context_for (two places) and vk_ffx4.cpp context_for (three) waited for the whole device to be idle, with
the queue lock held, on the thread that replays the game's submissions, before they destroyed an upscale context of
another render size, the least recently used one for a new output size, or (FSR 4) every idle one after a refused
creation: a stall of the present's flip, the completion thread and upload submits at every pause-screen size, reload,
window size, dynamic resolution step or mode change with FSR on.

A context that goes is now let go of (retire_up): it goes into a list (vk_up_defer.h) with the timeline value of the
submission of its last upscale (Up.fence, set after each dispatch) and is destroyed on the same thread once the GPU is
past it, at the points where vk_dlaa.c takes its own list (every evaluation, every pass while none runs, and after
something is let go of). The 90-second trims, vk_ffx_trim_idle and vk_ffx_release_idle (the upscaler off, which no
longer needs retire_idle's wait) let go of theirs the same way. FSR 4's create descriptors, which the API asks to stay
live until the context is destroyed, move from the slot into a calloc'd Made that goes with the context, so the slot
can take a new context while the old one waits. A refused FSR 4 creation now waits on the timeline from the host for
the contexts let go of, no queue touched (vk_upscaler_gpu_wait), and tries again when any went; with
NX2NAVI_UPSCALER_IDLE_WAIT=1 that wait and every let go wait for the device as before. docs/architecture.md says
where the upscalers' releases go.

C-5 is narrowed: on the default path no upscaler waits for the device any more, so these waits no longer touch the
frame generation swapchain's own queues; vk_fg.cpp, vk_fg4.cpp, gfx_present.c, vk_hdr.c, vk_fsr.c and vk_color.c keep
theirs.

Not reproduced before the change (no FSR session log here). Every runtime file compiles, vk_dlaa.c, vk_ffx.cpp and
vk_ffx4.cpp with -Wall -Wextra and no warning; vk_ffx4.cpp's non-Windows stubs compile against vk_ffx.h;
up_defer_check passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:08:28 -05:00
parent 22c86f08a0
commit 9065d1485f
5 changed files with 184 additions and 76 deletions

View File

@@ -803,7 +803,9 @@ static void dead_release(const UpdEntry *e, void *teardown) {
// What the upscalers let go of goes once the GPU is past it: DLSS's here, FSR's in vk_ffx.cpp and vk_ffx4.cpp.
static void upscalers_drain(void) {
if (dead.n) upd_take(&dead, vk_sync_fence_done(), presents_now(), dead_release, NULL);
const uint64_t done = vk_sync_fence_done();
if (dead.n) upd_take(&dead, done, presents_now(), dead_release, NULL);
vk_ffx_dead_take(done); // returns at once with both of its lists empty
}
// A wait for the device, then everything the upscalers let go of that a submission made so far names goes. An image a
@@ -812,6 +814,7 @@ void vk_upscaler_settle(void) {
const uint64_t issued = vk_sync_issued(); // read before the wait: every submission up to it is done after it
vk_upscaler_device_idle();
upd_take(&dead, issued, presents_now(), dead_release, NULL);
vk_ffx_dead_take(issued);
}
void vk_upscaler_let_go(void) {
@@ -3054,7 +3057,6 @@ static void retire_idle(void) {
if (!retire_off_at) retire_off_at = now ? now : 1;
if (now < retire_off_at + RETIRE_PRESENTS || !up_holds()) return;
for (int i = 0; i < SNAPS; i++) retire_snap(&R.s[i]);
if (vk_ffx_holds()) vk_upscaler_device_idle(); // vk_ffx_release_idle destroys the FSR contexts at once
vk_ffx_release_idle();
if (D.failed) { // as idle_release does for a size: frame generation is handed nothing of one from here on
for (int i = 0; i < DLSS_SIZES; i++) retire_size(&D.sizes[i]);