Skip to content

RR runtime: free released input copies while no RR instance exists - #11

Merged
phantoslayer21 merged 1 commit into
mainfrom
fix/rr-release-without-instance
Nov 13, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
fix/rr-release-without-instance

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Reported by @j0nsh1n in #8.

What

The RR runtime now frees released input copies while no RR instance exists. release_transient_locked calls pump()
after deferring a release.

Why

A game that tags its Ray Reconstruction inputs every frame while RR is available but switched off makes the plugin copy
each lifetime-0 input and release the previous copy. The release waits until the frame that recorded the copy has run,
but the deferred list was emptied only by pump(), which runs in instance create, evaluate and destroy. With no
instance, nothing ran it, so every released copy stayed allocated.

Why this is the right place:

  • pump() frees only resources whose frame marker the GPU has written. That is the same test as at evaluate.
  • It takes no lock of its own and calls nothing back. Its only caller here, the adapter's release_transient, holds the
    runtime lock, as create, evaluate and destroy do. (Not every adapter entry takes that lock: the runtime version getter,
    the two describe functions and the frame-time getter don't. None of them touches the deferred list.) The kernel compile thread never takes that lock and
    doesn't touch the deferred list.
  • A copy released while an evaluate recorded with it hasn't run yet is deferred to a serial no older than that
    evaluate's, so it still waits for the evaluate's marker. The fix doesn't change that test; it only runs it at release
    time too.
  • The marker is one "last serial written" word, so the test assumes the game's command lists run in the order they were
    recorded. This change doesn't add that assumption: defer_release and evaluate already rely on it. It does now apply
    when no instance exists, where nothing was freed before.

Measured (Windows, RX 9070-family card, no game)

New test-host job tagloop: one 1706x960 RGBA16F lifetime-0 input copied and released every frame. There is no
instance, no evaluate and no test drain or counters (both of those run the pump). Video memory is read with
QueryVideoMemoryInfo before and after.

Each frame retains the new copy (retain_transient_state, as the plugin's tag handler does), releases the previous
copy, and runs the frame's command list and waits for it. The plugin itself releases the old copy before it retains the
new one; the test does it the other way round on purpose, so that each release lands on a frame that has not run yet,
as a game's frames in flight do. In the plugin's order with a wait every frame, defer_release would free each copy at
once (its marker has already run) and the loop would not show the leak.

runtime 50 frames 200 frames 400 frames
main's runtime +670.8 MiB +2675.8 MiB not run
this branch's runtime +34.8 MiB +60.3 MiB +60.3 MiB

The tagloop job doesn't exist on main, so the "main's runtime" rows were measured with main's runtime library and this
branch's test host. The runtime DLL is byte-identical to the one built from main.

Testing

  • e2e.py now runs tagloop (200 frames) before its scenarios and fails if video memory grows by more than 256 MiB.
    • On this branch: +26.8 MiB, pass.
    • With main's runtime: +2650.2 MiB, so the test host exits with code 12.
  • RR output unchanged: I ran the e2e GPU run (WG_RR_COMPILE_WAIT_ALL=1, both scenarios, aliased and not) with main's
    runtime and with this branch's.
    • 375 of 380 result files are byte-identical: every output texture, every arena dump, and the array-input and border
      results.
    • The other 5 differ only in recorded file paths and in a created-resources count that includes the 200 tagloop
      copies.
  • The e2e CPU reference check of this branch's run passes. Every stage (input, body, head, output, resolve, exposure,
    pool, copies, constants) matches on all 74 evaluated frames, and the deliberately failed call leaves the state
    unchanged. The CPU reference was run on this branch's output only; main's output is compared by the file comparison
    above.

Not tested

A run on Linux/Proton by the reporter would close that gap.

Fixes #8.

A game that tags its Ray Reconstruction inputs every frame while RR is available but switched off makes the plugin copy
each lifetime-0 input (retain_transient_state) and release the previous copy. The release is deferred until the frame
that recorded the copy has run, but the deferred list was emptied only by pump(), which runs in instance create,
evaluate and destroy. With no instance, nothing ran it and every released copy stayed allocated.

release_transient_locked now calls pump() after deferring the release. pump() frees only resources whose frame marker
the GPU has written, takes no lock of its own and calls nothing back, and the adapter entry already holds the runtime
lock, as at create, evaluate and destroy.

rr_test_host gets a job "tagloop <frames> <w> <h> [<limit MiB>]": one RGBA16F lifetime-0 input copied and released
every frame, no instance, no evaluate, no test drain or counters, video memory measured with QueryVideoMemoryInfo.
e2e.py runs it (200 frames of 1706x960) before its scenarios, with a limit of 256 MiB of growth.

Reported by @j0nsh1n in #8.
Fixes #8.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 15:31
@phantoslayer21
phantoslayer21 force-pushed the fix/rr-release-without-instance branch from faa823c to dae0c5b Compare November 13, 2026 15:31
@phantoslayer21
phantoslayer21 merged commit fcd3b5b into main Nov 13, 2026
2 checks passed
@phantoslayer21
phantoslayer21 deleted the fix/rr-release-without-instance branch November 13, 2026 15:56
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 13, 2026
clean/linux/run_wine_tests.py runs three tests in a Wine prefix set up
the way Proton sets up a game's (clean/linux/wine_env.py: vkd3d-proton
d3d12 / d3d12core, DXVK dxgi, Wine's vkd3d libraries for its builtin
d3dcompiler_47), with an optional self-built vkd3d-proton (--vkd3d):

- interop: the existing run-tests.sh (31 tests);
- rr-leak: the RR test host's tagloop job (pull request phantoslayer21#11) against a
  given wronggpu_runtime.dll with a synthetic RR model, with the 256 MiB
  limit of the Windows end-to-end test;
- ags-layout: wg_ags.hlsli's WMMA and conversion helpers on fixed
  register values against a CPU reference of the gfx12 semantics
  (new: ags_layout.hlsl, ags_layout_host.cpp).

run-tests.sh: -fms-extensions for clang-based MinGW (the __try in
descriptor_publish.h), and WG_WINE to pick Proton's wine over a system
wine64.

Verified on an RX 9070 XT, RADV, GE-Proton 11-11, with a vkd3d-proton
built with dxil-spirv PR #362: interop 31/31, rr-leak +37 MiB (limit
256), ags-layout 7/7. Each test fails on the bug it targets: interop
29/31 with "Unknown modifier globallycoherent" before pull request phantoslayer21#12,
rr-leak +2636 MiB with a runtime from before pull request phantoslayer21#11,
ags-layout at CreateComputePipelineState on stock vkd3d-proton; its
comparison rejects lane-swapped and half-swapped results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Shin <85975340+j0nsh1n@users.noreply.github.com>
j0nsh1n added a commit to j0nsh1n/wronggpu that referenced this pull request Nov 14, 2026
From the review of phantoslayer21#52:

- README: the globallycoherent count now agrees (29 of 31, before
  phantoslayer21#12). The leak figures are named as one run on an RX 9070 XT, RADV,
  GE-Proton 11-11 and vkd3d-proton 5b1089c8 + dxil-spirv #362: +2636 MiB
  with a runtime built before phantoslayer21#11, +37.2 MiB with the fix. The launcher
  red check describes what was run (a wg-core check broken on purpose).
  The player advice about DLLs next to the game exe is gone, and the
  opening says the tests don't make Linux a supported platform. The
  vkd3d-proton commit named is the one tested (5b1089c8). It also says
  that --work/prefix is reused if it already is a Wine prefix.
- ags_layout.hlsl: the FloatConversion opcode 0x1c names its source in
  this repository (f2h_hw in clean/rr_f/kernels/rr_fast.hlsli).
- wine_env.py: mscoree / mshtml off and winemenubuilder disabled, so a
  new prefix shows no Mono / Gecko dialog and writes no menu entries.
- run_wine_tests.py: rr-leak fails when video memory does not change at
  all (a stack reporting a constant CurrentUsage), and --work with a
  space is refused (the RR host's job file is split on spaces).

Verified on main c793823 + this branch, GE-Proton 11-11 with a fresh
--work: interop 31/31, rr-leak +37.2 MiB, ags-layout 7/7, launcher
73/230/186/18 checks. No new entries under ~/.local/share/applications.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Shin <85975340+j0nsh1n@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.

RR runtime leaks about 1 GB/s of VRAM while RR is available but off: released input copies are never freed without an evaluate

1 participant