Repository navigation
Front end: keep upscalers replaced by an output resize until the context is destroyed - #85
Merged
Merged
Conversation
…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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #58
An output resize (
ResizeForFrame) destroyed the old upscaler and its stand-in at once, on the game's recordingthread. 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
Failalready keeps the network until then when it hands a context to AMD's FSR. SoResizeForFrameno longer destroys the old upscaler or stand-in. It moves them to a newreplacedlist on the context, andDestroyContextdestroys that list for both the parked and the non-parked path....; 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.DestroyContextdestroys the kept upscalers under the context's own mutex, where it already destroyed the current one.TestOutputResizeupdated,TestResizeKeepsRetiredandTestResizeCapDefaultadded (clean/fsr/tests/test_frontend.cpp, ctestfsr_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 awronggpu.inisetting). It was 8 in the firstversion 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: arelease 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 thefront end's own query of the runtime's allocation total for the current upscaler (they agree within 3 MiB). The new test mode
resize_realoftest_dll_d3d12does this (by hand, not a ctest).Record: the maintainer's measurement record RECORD-85 (raw outputs kept with it).
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:
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
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 happensbefore a parked destroy; the log line is missing.
1217 checks, 0 failures. The checks cover:DestroyContextdestroys all of them (3 upscalers, 1 stand-in);(
ctest --test-dir out/frontend -R "unit|hosted|diagnostic|support" -E "overlay|split|d3d12"): 16 of 16 passed. Oneof them,
fsr_asi_scan_unit, reports itself as skipped, as on main.Tested
test_frontend(MSVC 19.51, Windows): fails before the fix, passes at this head (above).Not tested
ctestD3D12 tests of BUILDING.md section 7 (-E "unit|hosted|diagnostic|support") were not run on the GPU for this head.