Skip to content

Front end: keep upscalers replaced by an output resize until the context is destroyed - #85

Merged
phantoslayer21 merged 6 commits into
mainfrom
fix/58-resize-retire
Nov 14, 2026
Merged

phantoslayer21 merged 6 commits into
mainfrom
fix/58-resize-retire

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Fixes #58

An output resize (ResizeForFrame) destroyed the old upscaler and its stand-in at once, on the game's recording
thread. Command lists the game recorded before could still use them: the copy into the output after the split, or a
whole list not yet submitted. This PR applies the lifetime rule shared by #63, #58 and #62. For why it is the same
pattern in each component and not a shared helper, see #82.

Changes, by rule point

Rule point Change
1. Release only on proven completion The front end has no fence or marker of its own; it reaches the network only through the public upscaler interface. Its completion boundary is the context's destroy: the FidelityFX contract expects the caller to have finished with the GPU there, and Fail already keeps the network until then when it hands a context to AMD's FSR. So ResizeForFrame no longer destroys the old upscaler or stand-in. It moves them to a new replaced list on the context, and DestroyContext destroys that list for both the parked and the non-parked path.
2. On timeout keep, log one line, release at device removal or exit Nothing in the front end waits or times out here. The resize line in the log now says what is kept: ...; the old upscaler (and its stand-in) is/are kept until the context is destroyed (the game's command lists may still use them). While the device is lost (Platform::deviceLost), nothing of it runs any more and they are destroyed at once (... destroyed now (the device is lost)). At process exit nothing is done, as for a context the game never destroys.
3. No wait longer than one frame under a runtime-wide lock The resize no longer calls the backend's destroy, so the wait for the old network's last frame is gone from the recording thread. DestroyContext destroys the kept upscalers under the context's own mutex, where it already destroyed the current one.
4. CPU test of the retire-until-complete logic TestOutputResize updated, TestResizeKeepsRetired and TestResizeCapDefault added (clean/fsr/tests/test_frontend.cpp, ctest fsr_frontend_unit, which CI runs). The fake backend and stand-in count their destroys.

The bound on kept upscalers: 1 per context

The issue suggests keeping only one replaced upscaler and destroying it at the next resize. Under the rule that would be
a release without proof (the replaced upscaler's last frame may still be in flight when the size changes on two
dispatches in a row), so every replaced upscaler is kept until the context goes. That costs GPU memory, so the number of
size changes per context is bounded by Config::maxOutputResizes (not a wronggpu.ini setting). It was 8 in the first
version of this PR. Measured on the real backend (below), that meant 9 live Model M upscalers and 8.1 GiB of growth at 4K Quality, so the
default is now 1: one kept upscaler holds 0.91 GiB at 4K Quality (0.41 GiB at 1440p). A further size change in the same
context creates nothing (one log line; frames of that size are refused as before and the stand-in or AMD's FSR takes
them). A later change could hand the front end a completion signal (for example from the split service's done fences) so it can free
kept upscalers earlier with proof, and raise this.

GPU memory of the kept upscalers (measured)

Real backend (wronggpu_runtime.dll, D3D12 executor, the default on RDNA 4), AMD Radeon RX 9070 XT with 16 GiB, no game. Runtime: a
release build of main 8ed26e8 plus #155 and #156, SHA-256 13375811ff6a97baad927995ce03e8a280003c292aefbeb0e467f2ce835d7f78.
Model M weights are a synthetic file with the real network shape (memory depends on shape and sizes, not on the values); Model L is a converted
Model L file. Two readings per step: the process's video memory (DXGI QueryVideoMemoryInfo, local segment, this process only) and the
front end's own query of the runtime's allocation total for the current upscaler (they agree within 3 MiB). The new test mode
resize_real of test_dll_d3d12 does this (by hand, not a ctest).
Record: the maintainer's measurement record RECORD-85 (raw outputs kept with it).

Model Output Mode (render size) One upscaler Worst case at the old cap of 8 (8 kept + current), growth of the process
M 3840x2160 Quality (2560x1440) 933 MiB 8317 MiB
M 2560x1440 Quality (1706x960) 419 MiB 3724 MiB
M 3840x2160 native (3840x2160), the largest 1590 MiB not reached (see below); 9 x 1590 would be about 14 GiB
M 2560x1440 native 706 MiB not reached; 9 x 706 would be about 6.2 GiB
L 3840x2160 Quality 1441 MiB 12886 MiB
L 2560x1440 Quality 648 MiB 5781 MiB
L 2560x1440 native 1214 MiB 10878 MiB

Native-ratio runs of Model M stopped at 5 (4K) and 4 (1440p) live upscalers: the D3D12 executor does not take frames whose render size
equals the output size, so AMD's FSR took the context and no further upscaler was created.

Cap chosen: 1. With it the kept upscaler holds 934 MiB at 4K Quality for Model M (the bound of about 1 GB at 4K), and
420 MiB at 1440p; the current upscaler comes on top (measured peak growth 1870 MiB at 4K, 842 MiB at 1440p). It does not meet the bound
for Model L at 4K Quality (1.4 GiB kept) or for Model M at native 4K (1.55 GiB kept); a smaller cap there would mean no resize at all.

Hardware run (this head's cap-1 build, real backend)

Repeated output resizes with the game's command lists in flight: at every step the list recorded for the previous size is submitted after the list for the
new size (the case of #58). 3 contexts in a row per run, each created for the largest size, resized, destroyed:

Run Peak growth (kept + current) Process memory after each of the 3 destroys, over before any context Device removed
4K Quality, Model M, 5 size changes per context 1870 MiB +4, +4, +4 MiB no
1440p Quality, Model M, 5 size changes per context 842 MiB +4, +4, +4 MiB no

No crash, no device removal, memory returns at each context destroy. The size change beyond the bound is refused and logged once per context, as designed. The same test on the first head's
cap of 8 (1440p Quality, 10 size changes, 3 contexts, in-flight lists): 27 upscalers created, 24 kept until the destroys, peak +3724 MiB, +16 MiB after each destroy, no device removal.

Model L at native 4K (which the D3D12 executor refuses) leaves memory behind after a destroy (+1419 MiB for one context with no resize at all;
+3943 MiB after a context that resized twice), constant from cycle to cycle. That is not caused by this PR (it happens without any
resize); every Quality run and the Model M native runs returned to within +2..+16 MiB.

Test

cmake -S clean/fsr -B out/frontend -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DWG_MODEL_K=OFF -DWG_BUILD_ID=ci -DWG_BUILD_ASI=ON
cmake --build out/frontend --target test_frontend
out/frontend/test_frontend.exe
  • Before the fix (commit 769ca3d, tests only): 6 checks fail. The resize destroys the old upscaler
    (g_destroyed == 0) and the stand-in; the first replaced upscaler is gone at the second resize and when a resize happens
    before a parked destroy; the log line is missing.
  • At this head: 1217 checks, 0 failures. The checks cover:
    • both resizes keep the old upscalers and the stand-in (limit raised to 8 in those tests);
    • DestroyContext destroys all of them (3 upscalers, 1 stand-in);
    • a resize while the device is lost destroys the old one at once;
    • a parked destroy destroys the replaced upscaler and parks only the current one;
    • the default limit of 1: one size change keeps the old upscaler, the next creates nothing and logs once, the destroy frees both.
  • The front end's CPU ctest set, as in CI
    (ctest --test-dir out/frontend -R "unit|hosted|diagnostic|support" -E "overlay|split|d3d12"): 16 of 16 passed. One
    of them, fsr_asi_scan_unit, reports itself as skipped, as on main.
  • Public gates on this head: the must-pass gates pass; the leak and number LOOK counts are identical to main's.

Tested

  • test_frontend (MSVC 19.51, Windows): fails before the fix, passes at this head (above).
  • The front end's CPU ctest set (above).
  • On hardware, the real backend: GPU memory per upscaler and worst case, repeated in-flight output resizes with 3 contexts per run, memory at the destroy (above).

Not tested

  • The front end's ctest D3D12 tests of BUILDING.md section 7 (-E "unit|hosted|diagnostic|support") were not run on the GPU for this head.
  • A game that changes its output size while frames are in flight (the hardware run above is a test program with the game's call pattern, not a game).
  • The D3D12 debug layer (not installed on the test PC), so no validation messages were checked.
  • Model M with a real converted model (the Model M runs used a synthetic file of the real shape; Model L used a real converted file).

…fail before the fix)

TestOutputResize expects the old upscaler to stay after a resize; TestResizeKeepsRetired
resizes twice with a stand-in present and expects nothing destroyed before the context
goes, everything destroyed with it, an immediate destroy while the device is lost, and
the replaced upscaler destroyed when a context is parked. Against the current front end
6 checks fail: the resize destroys the old upscaler and stand-in at once (issue #58).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…ext is destroyed

Fixes issue #58. ResizeForFrame no longer destroys the old upscaler and stand-in on the
game's recording thread while command lists recorded before may still use them (the copy
into the output after the split, or a list not yet submitted). The front end has no fence
of its own; its completion boundary is the context's destroy (as for the AMD handoff in
Fail). The replaced ones are kept on the context and destroyed by DestroyContext, parked
or not, or at once while the device is lost. The resize line in the log says which.
This also removes the stall of the backend's destroy (the old network's last frame) from
the resize. At most kMaxResizes upscalers and their stand-ins are kept per context.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 21:24
…ext (#58)

A kept replaced upscaler holds its GPU memory until the context is destroyed. Measured on the
real backend (RX 9070 XT, D3D12 executor): one Model M upscaler is 933 MiB at 4K Quality and
419 MiB at 1440p Quality, so the old limit of 8 kept ones meant 9 live upscalers and 8.1 GiB of
growth at 4K Quality (3.6 GiB at 1440p; Model L 4K Quality 12.6 GiB).

The limit is now Config::maxOutputResizes, default 1: a kept upscaler holds 0.91 GiB at 4K
Quality. A further size change creates nothing (the log says so once; frames of that size are
refused as before). The tests that need several kept upscalers raise the limit; a new test
covers the default.

Adds the by-hand test mode resize_real to test_dll_d3d12 (real runtime, process video memory
by DXGI QueryVideoMemoryInfo and the runtime's own allocation total per step, in-flight lists,
device removal and memory after the destroy).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output resize destroys the old upscaler while the game's queue may still use its buffers

1 participant