RDNA2: keep the 2 GB aperture segment from filling (device loss at world load) #127

Open
github-bot wants to merge 7 commits from github-bot/gh-127 into beta-amd AGit
Owner

@⁠MalarkZA on GitHub · 2026-11-27 13:43 UTC · original
MalarkZA:fix/rdna2-aperture-segment → beta-amd · +337 −78 · 5 files · 7 commits · open

What

On RDNA2 cards, with submissions sent ahead (VICTORY_RELAY=1/2, the play.ps1
default), the host device is removed at the first world load, ~40-51 s in:
0x887A0007, no work in flight (DRED breadcrumbs empty,
"nothing of ours was running on the card"); with the debug layer on:
"Kernel memory failure. There might be a memory leak." (id 834).

Reproduced here on an RX 6900 XT (driver 32.0.21045.29003, Win11 26300) in
every relayed run; upstream reports match on RX 6700 XT / 6800 / 6950 XT
(kyokyotosh/VIctory-6700XT FINDINGS-6700XT.md; avatarmanz/VIctory-7900XTX #394, #289).

Why (GPU ETW trace, FINDINGS-6700XT.md)

The video memory manager's 2 GB aperture segment holds the driver's command
buffers (1 MB + 64 KB per D3D12 command list), upload scratch and the
D3D12_HEAP_TYPE_CUSTOM write-back buffers. land() kept the newest 64
flights' finished lists (up to ~716 host lists) and every host list carried
its own prelude for life (~950 preludes, ~1 MB of the segment each). Live
lists climbed to ~1,150-1,250 at the world load, the segment ran full,
ReserveResource failed and the kernel scheduler marked the device faulted.
No GPU hang, no page fault, no timed-out packet.

What this PR does

Four commits cherry-picked from kyokyotosh/VIctory-6700XT
(f173347, 018d372, e3c0703, 63a773e), kept attributed:

  1. Host lists of landed flights go back to the pool at once; what they held
    waits the bury lag through retire.
  2. The card's memory segments are read with D3DKMTQueryStatistics and said
    once at the start; while an aperture segment holds more than
    VICTORY_SEGMENT_TIGHT percent (85; 0: never) of its limit, flights sent
    ahead land first.
  3. The back-off holds: looked at on every send, all flights land while tight,
    idle host lists trimmed to 64 (on at 80%, off at 70%).
  4. Preludes come from a pool: taken when a list is first submitted with
    transitions, given back at its reset (128 kept idle, 16 while the segment
    is tight).

Two follow-ups for this tree:

  1. trim_idle matches our three-field Idle (the picked pattern predates
    the retire timestamp our list.rs has).
  2. The old per-list PreludeSlot mechanism and VICTORY_MAX_PRELUDES go with
    the pool that replaces them (the prelude-pool pick left them orphaned here;
    scripts/play-3070.ps1 capped them at 32 - see note below).

Measured (RX 6900 XT, Series X, diag build, this PR's base + relay on)

base with this PR, VICTORY_RELAY=2
world load device removed in every run, 37-51 s in (0x887A0007, nothing in flight) none: full opening sequence, stable 12-15 fps, 5+ min
host lists alive 1,148-1,175 at the removal 975
preludes made 283 by 50 s (~950 upstream) 96 for the whole run
relay dying on it active (17.8 flights/frame landed)

VICTORY_RELAY=0 (the workaround) also survives, at 7-8 fps. Upstream: RX 6700
XT 8.8-12.6 fps at relay 2 with zero removals in 10+ min; RX 6950 XT 18.1 fps
same.

CI notes (diffed against the base; the branch carries pre-existing debt)

  • cargo clippy -D warnings, plain and --all-features: this PR adds zero
    new findings (114 pre-existing on the base, unchanged).
  • cargo test --workspace: identical to the base (4 pre-existing
    victory-gpu lib failures: hlehooks, indirect x2, descriptor).
  • asset policy (xtask::repository_passes_policy): zero new violations from
    this PR (pre-existing: klbf-lab.ico/.rc, klbf_card.png,
    shader_cache.rs, tools/patches/*.patch, tools/ghidra-scripts/*).

Note for the 3070 setup: VICTORY_MAX_PRELUDES=32 no longer exists - the
new pool is capped in code at 128 idle / 16 tight. If the 12 GB 3070's smaller
segment needs a lower cap, that is a follow-up (a pool-shaped knob).

**@⁠MalarkZA** on GitHub · 2026-11-27 13:43 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127) `MalarkZA:fix/rdna2-aperture-segment` → `beta-amd` · +337 −78 · 5 files · 7 commits · open **What** On RDNA2 cards, with submissions sent ahead (`VICTORY_RELAY=1/2`, the `play.ps1` default), the host device is removed at the first world load, ~40-51 s in: `0x887A0007`, no work in flight (DRED breadcrumbs empty, "nothing of ours was running on the card"); with the debug layer on: "Kernel memory failure. There might be a memory leak." (id 834). Reproduced here on an RX 6900 XT (driver 32.0.21045.29003, Win11 26300) in every relayed run; upstream reports match on RX 6700 XT / 6800 / 6950 XT (kyokyotosh/VIctory-6700XT FINDINGS-6700XT.md; avatarmanz/VIctory-7900XTX #394, #289). **Why (GPU ETW trace, FINDINGS-6700XT.md)** The video memory manager's 2 GB aperture segment holds the driver's command buffers (1 MB + 64 KB per D3D12 command list), upload scratch and the `D3D12_HEAP_TYPE_CUSTOM` write-back buffers. `land()` kept the newest 64 flights' finished lists (up to ~716 host lists) and every host list carried its own prelude for life (~950 preludes, ~1 MB of the segment each). Live lists climbed to ~1,150-1,250 at the world load, the segment ran full, `ReserveResource` failed and the kernel scheduler marked the device faulted. No GPU hang, no page fault, no timed-out packet. **What this PR does** Four commits cherry-picked from kyokyotosh/VIctory-6700XT (`f173347`, `018d372`, `e3c0703`, `63a773e`), kept attributed: 1. Host lists of landed flights go back to the pool at once; what they held waits the bury lag through `retire`. 2. The card's memory segments are read with `D3DKMTQueryStatistics` and said once at the start; while an aperture segment holds more than `VICTORY_SEGMENT_TIGHT` percent (85; 0: never) of its limit, flights sent ahead land first. 3. The back-off holds: looked at on every send, all flights land while tight, idle host lists trimmed to 64 (on at 80%, off at 70%). 4. Preludes come from a pool: taken when a list is first submitted with transitions, given back at its reset (128 kept idle, 16 while the segment is tight). Two follow-ups for this tree: 5. `trim_idle` matches our three-field `Idle` (the picked pattern predates the retire timestamp our `list.rs` has). 6. The old per-list `PreludeSlot` mechanism and `VICTORY_MAX_PRELUDES` go with the pool that replaces them (the prelude-pool pick left them orphaned here; `scripts/play-3070.ps1` capped them at 32 - see note below). **Measured (RX 6900 XT, Series X, diag build, this PR's base + relay on)** | | base | with this PR, `VICTORY_RELAY=2` | |---|---|---| | world load | device removed in every run, 37-51 s in (`0x887A0007`, nothing in flight) | none: full opening sequence, stable 12-15 fps, 5+ min | | host lists alive | 1,148-1,175 at the removal | 975 | | preludes made | 283 by 50 s (~950 upstream) | 96 for the whole run | | relay | dying on it | active (17.8 flights/frame landed) | `VICTORY_RELAY=0` (the workaround) also survives, at 7-8 fps. Upstream: RX 6700 XT 8.8-12.6 fps at relay 2 with zero removals in 10+ min; RX 6950 XT 18.1 fps same. **CI notes (diffed against the base; the branch carries pre-existing debt)** - `cargo clippy -D warnings`, plain and `--all-features`: this PR adds zero new findings (114 pre-existing on the base, unchanged). - `cargo test --workspace`: identical to the base (4 pre-existing victory-gpu lib failures: hlehooks, indirect x2, descriptor). - asset policy (`xtask::repository_passes_policy`): zero new violations from this PR (pre-existing: `klbf-lab.ico`/`.rc`, `klbf_card.png`, `shader_cache.rs`, `tools/patches/*.patch`, `tools/ghidra-scripts/*`). **Note for the 3070 setup:** `VICTORY_MAX_PRELUDES=32` no longer exists - the new pool is capped in code at 128 idle / 16 tight. If the 12 GB 3070's smaller segment needs a lower cap, that is a follow-up (a pool-shaped knob).
land() kept the newest bury_lag() (64) entries of the landed line, and an entry is a
whole flight: some 700 host lists at the first world load, idle pool empty, so every
new recording made a new list. Each list holds 1 MB+ of the driver's command memory
in a 2 GB aperture segment (RX 6700 XT, 32 GB PC); it ran full and the device was
removed (VidSchMarkDeviceAsError after ReserveResource failed, GPU ETW trace).

Now list::recycle_landed retires what a list's commands named (descriptor state,
uploads, host textures, twins, deferred work: HostList::take_held), so those objects
still wait bury_lag() submissions, and the list and its allocator are reset and pooled
at once. The synchronous path (list::recycle) is unchanged.

Default play.ps1 settings: the device survived the world-load budget cut 26 s longer
(3.7-30 fps) instead of 3-7 s; it is still removed later (FINDINGS-6700XT.md).

(cherry picked from commit f1733477dd84afa6bd4a96ca1615a19235fae666)
(cherry picked from commit 73d277fc11256ac3eac032b5e4aa9187944dc0b3)
host/segments.rs reads the adapter's segments with D3DKMTQueryStatistics (limit,
bytes resident, aperture or not), says them once at the start, and looks again at
most every 100 ms. DXGI's budgets leave the aperture segments out; on an RX 6700 XT
in a 32 GB PC segment 2 is a 2,048 MB aperture that holds the driver's command
buffers, upload heaps and CPU-cached custom heaps, and its running full removed the
device during the first world load.

send_late settles the flights in the air when no idle host list waits and that
segment holds more than VICTORY_SEGMENT_TIGHT percent (85; 0: never) of its limit,
so their lists come back before new ones are made. Needs the windows crate's
Wdk_Graphics_Direct3D feature.

Partial: with it the default settings ran 48 s past the world-load budget cut at
6.7-30 fps and the device was still removed; the back-off first fired at 93% and lists
in flight kept growing (FINDINGS-6700XT.md, next steps).

(cherry picked from commit 018d372438522c684d6a074bb2fba0a6189920d4)
(cherry picked from commit be87988747c4eada05544b516ab0c5317682e53c)
018d372 looked at the segment only when no idle host list waited, first fired at 93%,
and let the lists in flight grow. Now send_late asks segments::tight on every send;
while it holds, every flight lands as it is sent and list::trim_idle lets idle lists
past 64 go with their allocators' command memory (~250-300 MB of the 2 GB segment).
VICTORY_SEGMENT_TIGHT is 80 by default and counts as clear 10 points lower: near the
limit the video memory manager pages and the card waited a second a frame.

RX 6700 XT, default play.ps1 settings: the world load passes, no device removal in
180 s, 4.5-4.7 fps (212 ms/frame) in the world; VICTORY_RELAY=0 gave 2.8.

(cherry picked from commit e3c07030a7b43fa87071fde29f04cae159db9e68)
(cherry picked from commit e9216b6ca0e6f43169943540c16284e2dac9126d)
Each host list kept its prelude (an allocator and a command list) for life: 952
preludes for 1,476 host lists, each with the driver's command memory (1 MB and
more) in the 2 GB aperture segment of an RX 6700 XT in a 32 GB PC. Only lists being
submitted or in the air need one. HostList::prelude is now a Mutex<Option<Prelude>>
filled by take_prelude at submission and emptied into PRELUDES by HostList::reset,
which runs only after the list's submissions finished. VICTORY_LAZY_PRELUDE=0 still
makes one with the list.

Default play.ps1 settings: 101 preludes made instead of ~950, the segment back-off
never fired, no device removal in 180 s, 5.5-7.4 fps (~145 ms/frame) in the world
(4.5-4.7 before, 2.8 with VICTORY_RELAY=0).

(cherry picked from commit 63a773e4420bb7454e10052bd554467e01a07a69)
(cherry picked from commit b09114f7e0fa1420512b60e9806519e50f6d54ec)
(cherry picked from commit 63ffe6c32a3057a18bfe1f01b866c5ad23094888)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:56:46 +00:00
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-27 13:56 UTC · original

One boundary case in segments::tight affects adapters reporting multiple aperture segments. With 80,001/100,000 bytes resident in the first and 160,000/200,000 in the second, both sort to 800 per thousand. The second wins the tie, so back-off stays off even though the first exceeds 80%. Reversing the segments changes the decision. The same case applies at the 70% release threshold.

Patch and two regression tests compare the fractions exactly. The segment source is identical on rdna2-test at eb6feb8 and this PR at 3c825b3. On Windows both tests passed with the patch. Restoring the rounded comparison failed the ordering test. This uses synthetic segment readings. Windows test log

**@⁠HandshakeHackin** on GitHub · 2026-11-27 13:56 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7220137856) One boundary case in `segments::tight` affects adapters reporting multiple aperture segments. With 80,001/100,000 bytes resident in the first and 160,000/200,000 in the second, both sort to 800 per thousand. The second wins the tie, so back-off stays off even though the first exceeds 80%. Reversing the segments changes the decision. The same case applies at the 70% release threshold. [Patch and two regression tests](https://github.com/HandshakeHackin/klbf-lab/commit/966c5629654b558639acdf4b56bfdbbaf05b0c68) compare the fractions exactly. The segment source is identical on `rdna2-test` at `eb6feb8` and this PR at `3c825b3`. On Windows both tests passed with the patch. Restoring the rounded comparison failed the ordering test. This uses synthetic segment readings. [Windows test log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/46010786822/job/140545440369)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-27 14:04 UTC · original

Thanks @⁠MalarkZA, a careful write-up with DRED and debug-layer evidence, and @⁠HandshakeHackin, good catch on the tie in segments::tight. On the AMD line we port changes ourselves with an A/B bench rather than merging, so this one goes to our list next to the kyokyotosh fix already on rdna2-test, and you'll be credited. Next step: could you fold 966c562 into the PR and attach the console of one relayed run that reaches the world with it?

**@⁠PastiiJay** on GitHub · 2026-11-27 14:04 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7220297027) Thanks @⁠MalarkZA, a careful write-up with DRED and debug-layer evidence, and @⁠HandshakeHackin, good catch on the tie in `segments::tight`. On the AMD line we port changes ourselves with an A/B bench rather than merging, so this one goes to our list next to the kyokyotosh fix already on `rdna2-test`, and you'll be credited. Next step: could you fold `966c562` into the PR and attach the console of one relayed run that reaches the world with it?
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-27 14:17 UTC · original

I applied the threshold fix to your exact 3c825b3 head. The combined commit d61c030 is one commit ahead of this PR and can be fast-forwarded onto the author branch. Both aperture tests passed on that tree and the Windows diagnostic build compiled. Build and test log

I have no physical Radeon attached here. The remaining check is the console from a relayed world-load run on this combined revision.

**@⁠HandshakeHackin** on GitHub · 2026-11-27 14:17 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7220594641) I applied the threshold fix to your exact `3c825b3` head. The [combined commit `d61c030`](https://github.com/HandshakeHackin/klbf-lab/commit/d61c03075adc9ff90c9f2c7c8fc89e3ac69c660d) is one commit ahead of this PR and can be fast-forwarded onto the author branch. Both aperture tests passed on that tree and the Windows diagnostic build compiled. [Build and test log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/46012944352/job/140552773916) I have no physical Radeon attached here. The remaining check is the console from a relayed world-load run on this combined revision.
Author
Owner

@⁠MalarkZA on GitHub · 2026-11-27 14:37 UTC · original

Folded in: the PR head is now d61c030 (HandshakeHackin's exact-fraction fix + both regression tests, which pass locally on Windows).

Relayed world-load run on d61c030, RX 6900 XT, diag build, default play.ps1 (VICTORY_RELAY=2, exact=true), console attached:

  • no device removal: ~3.5 min, well past the old 37-51 s point; ended by closing the window
  • in the world: 12-15 fps, 971 host lists alive (steady), relay landing ~19 flights/frame
  • segment 1 (2,048 MB aperture) read at the start; the back-off never fired in this run

Note: the early log line "RDNA 2 adapter: VICTORY_RELAY defaults to 0" is printed for any RDNA 2 card, but play.ps1's explicit VICTORY_RELAY=2 overrides it, and the relay lines confirm the relay was on.

pr127-d61c030-rx6900xt-relay2-console.txt

**@⁠MalarkZA** on GitHub · 2026-11-27 14:37 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7221020278) Folded in: the PR head is now `d61c030` (HandshakeHackin's exact-fraction fix + both regression tests, which pass locally on Windows). Relayed world-load run on `d61c030`, RX 6900 XT, diag build, default `play.ps1` (`VICTORY_RELAY=2`, `exact=true`), console attached: - no device removal: ~3.5 min, well past the old 37-51 s point; ended by closing the window - in the world: 12-15 fps, 971 host lists alive (steady), relay landing ~19 flights/frame - segment 1 (2,048 MB aperture) read at the start; the back-off never fired in this run Note: the early log line "RDNA 2 adapter: VICTORY_RELAY defaults to 0" is printed for any RDNA 2 card, but `play.ps1`'s explicit `VICTORY_RELAY=2` overrides it, and the relay lines confirm the relay was on. [pr127-d61c030-rx6900xt-relay2-console.txt](https://github.com/user-attachments/files/35517259/pr127-d61c030-rx6900xt-relay2-console.txt)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-27 14:47 UTC · original

Thanks @⁠MalarkZA, 3.5 minutes in the world on relay 2 with no device removal, past the old 40-50 s point, is the result we were hoping for. The note about the RDNA 2 log line is useful too. We'll port it onto the AMD line ourselves, crediting you and HandshakeHackin. Next step, if you have the time: a longer relayed session (10 min or more, with some driving) so we can see whether the back-off ever fires.

**@⁠PastiiJay** on GitHub · 2026-11-27 14:47 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7221221865) Thanks @⁠MalarkZA, 3.5 minutes in the world on relay 2 with no device removal, past the old 40-50 s point, is the result we were hoping for. The note about the RDNA 2 log line is useful too. We'll port it onto the AMD line ourselves, crediting you and HandshakeHackin. Next step, if you have the time: a longer relayed session (10 min or more, with some driving) so we can see whether the back-off ever fires.
Author
Owner

@⁠MalarkZA on GitHub · 2026-11-27 15:00 UTC · original

Longer relayed session on the same d61c030, RX 6900 XT, diag build, default play.ps1 (VICTORY_RELAY=2), console attached:

  • ~17 min (14:41-14:58 UTC), no device removal and no errors; ended by closing the window
  • the aperture back-off never fired: no tight/clear line in the whole session
  • in the world: mostly 12-15 fps (median 14), short dips during loading/streaming, up to ~30
  • host lists alive levelled off at ~1,130-1,150 in the second half (971 in the 3.5 min run); the old build lost the device around that count, but here the segment never reached the 80% back-off mark
  • relay active throughout: median ~22 flights/frame landed over the last stretch

pr127-d61c030-rx6900xt-relay2-17min-console.txt

**@⁠MalarkZA** on GitHub · 2026-11-27 15:00 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7221497528) Longer relayed session on the same `d61c030`, RX 6900 XT, diag build, default `play.ps1` (`VICTORY_RELAY=2`), console attached: - ~17 min (14:41-14:58 UTC), no device removal and no errors; ended by closing the window - the aperture back-off never fired: no tight/clear line in the whole session - in the world: mostly 12-15 fps (median 14), short dips during loading/streaming, up to ~30 - host lists alive levelled off at ~1,130-1,150 in the second half (971 in the 3.5 min run); the old build lost the device around that count, but here the segment never reached the 80% back-off mark - relay active throughout: median ~22 flights/frame landed over the last stretch [pr127-d61c030-rx6900xt-relay2-17min-console.txt](https://github.com/user-attachments/files/35518069/pr127-d61c030-rx6900xt-relay2-17min-console.txt)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-27 15:06 UTC · original

Thanks @⁠MalarkZA, 17 minutes on relay 2 with no device loss is the proof we needed, and noting that the old build died around the same list count you now hold is a nice touch. That's enough for us to start the port. One last thing whenever convenient: a BM-v1 run on d61c030, so the fix gets an RX 6000 row on the board.

**@⁠PastiiJay** on GitHub · 2026-11-27 15:06 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7221641666) Thanks @⁠MalarkZA, 17 minutes on relay 2 with no device loss is the proof we needed, and noting that the old build died around the same list count you now hold is a nice touch. That's enough for us to start the port. One last thing whenever convenient: a BM-v1 run on `d61c030`, so the fix gets an RX 6000 row on the board.
Author
Owner

@⁠MalarkZA on GitHub · 2026-11-27 18:16 UTC · original

Created #131 to record the BM-v1 run card as per the docs

**@⁠MalarkZA** on GitHub · 2026-11-27 18:16 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/127#issuecomment-7225319859) Created https://git.gtahub.st/github/PastiiJay--klbf-lab/issues/131 to record the BM-v1 run card as per the docs
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/127/head:github-bot/gh-127'
git switch 'github-bot/gh-127'

Merge

Merge the changes and update on Forgejo.
git switch 'beta-amd'
git merge --no-ff 'github-bot/gh-127'
git switch 'github-bot/gh-127'
git rebase 'beta-amd'
git switch 'beta-amd'
git merge --ff-only 'github-bot/gh-127'
git switch 'github-bot/gh-127'
git rebase 'beta-amd'
git switch 'beta-amd'
git merge --no-ff 'github-bot/gh-127'
git switch 'beta-amd'
git merge --squash 'github-bot/gh-127'
git switch 'beta-amd'
git merge --ff-only 'github-bot/gh-127'
git switch 'beta-amd'
git merge 'github-bot/gh-127'
git push origin 'beta-amd'
This discussion has been locked. Commenting is limited to contributors.
No description provided.