d3d12: keep RDNA2's 2 GB aperture segment from filling (device lost at the first heavy scene with relay 2) #2670
Closed
leonida/mandy
amujark wants to merge 0 commits from
fix/rdna2-aperture-segment into main
pull from: fix/rdna2-aperture-segment
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2670
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/rdna2-aperture-segment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: D3D12-RDNA2-APERTURE-SEGMENT (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7266137587)
What and why
On an RDNA2 card with the default play settings (
LEONIDA_RELAY=2) the host device is removed at the first heavy scene (the opening cinematic):0x887A0007, DRED breadcrumbs empty, "nothing of ours was running on the card", with about 1,250-1,270 host lists alive. It happened in every run, andmainalone does it 72 s in even withLEONIDA_BURY_LAG=16.LEONIDA_RELAY=0survives, at about 8 fps.This is the failure of PastiiJay/klbf-lab#127. The video memory manager's 2 GB aperture segment, which DXGI's budgets leave out, holds the driver's command buffers (1 MB and more per command list).
land()kept the lists of the lastbury_lag()flights, and every host list kept its own prelude for life, so the segment ran full and the scheduler marked the device faulted.The fix is ported by hand from kyokyotosh/VIctory-6700XT (GPL-3.0, as this tree), one commit each, attributed in the messages and the doc comments:
f173347: the host lists of landed flights go back to the pool at once (list::recycle_landed). What their commands named (Held: the wholeDeferred, the texture states, twins and refreshes being found, and theDetached's descriptor state and uploads) waitsbury_lag()throughretire. Both the reaper thread and the path without it use it.018d372:host/segments.rsreads the adapter's segments withD3DKMTQueryStatistics(Wdk_Graphics_Direct3Dfeature). They are logged once at device creation and looked at every 100 ms at most. While an aperture segment holds more thanLEONIDA_SEGMENT_TIGHTpercent of its limit,send_latelands the flights in the air.e3c0703: it is looked at on every send, with hysteresis: tight from 80 % by default, clear below 70 % (0: never). While tight, idle host lists are trimmed to 64, with their bytes taken out of the pool's count. The threshold is a pure function (is_tight) with unit tests.63a773e: preludes come from a pool. One is taken when a list is first submitted with transitions and given back at its reset; 128 are kept idle, 16 while tight. The pool keeps each allocator's creation instant, soLEONIDA_ALLOCATOR_TRIMstill sees its real age.LEONIDA_LAZY_PRELUDE=0still makes one with the list.There is one more change, in the launcher. With the fix and relay 2 on the same card, the lighting rose and fell with where the camera looked and went black, which looks like the automatic exposure reading a late value. The same build in the same place with
LEONIDA_RELAY_COPY=0looked right at 17-20 fps.d3d12/scripts/play-nvidia.ps1setsLEONIDA_RELAY_COPY=1for every card; it now leaves it out on Radeon RX 6000 cards.-More @{LEONIDA_RELAY_COPY='1'}still puts it back (checked with-DryRun). Only the RX 6800 XT is measured.Tested
RX 6800 XT, one run each, Series S profile,
-Log, pipelines already cached:main452d1d1b6, relay 2,LEONIDA_BURY_LAG=16LEONIDA_RELAY_COPY=0(the last commit's default here)cargo test -p leonida-gpu: 556 passed, 1 failed, 47 ignored. The failure,descriptor::host::tests::views_are_made_beside_the_heap_and_copied_in, fails the same way onmain452d1d1b6. The newhost::segments::tests::*andlist::tests::a_trim_keeps_the_first_and_takes_the_restpass.cargo check -p leonida-gpuand--features diagnostics: ok.cargo clippy -p leonida-gpu --features diagnostics: no new warnings in the changed lines.cargo build --locked --profile diag -p leonida --features diagnostics,mimalloc: ok.python -I scripts/check_no_game_data.pyon the changed files: pass. The branch is onmain452d1d1b6and merges cleanly withmain0eab02a8b.GPUs tested: AMD Radeon RX 6800 XT, Adrenalin 32.0.21045.29003, Windows 11 (Ryzen 9 5950X, 32 GB)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)I reproduced a launcher edge case with mixed Radeon and NVIDIA adapters. With both an RTX 4070 SUPER and RX 6800 XT in the controller inventory,
-Adapter 'RTX 4070'still emitsLEONIDA_ADAPTER=RTX 4070, butLEONIDA_RELAY_COPYis now unset at launch and after replaying the F1 command. A savedLEONIDA_ADAPTER=RTX 4070produces the same result.main40e7fe69and after merging1462e3e8(6be18311). Main emitsLEONIDA_RELAY_COPY=1in all controls. The PR retains1with the RTX alone, omits the setting with the RX 6800 XT alone, and omits it on the mixed setup with either card selected. An explicit savedLEONIDA_RELAY_COPY=1still wins on the mixed setup.#indexselectors. Basing the default on the resolved DXGI adapter would keep the workaround scoped to the selected card. Launcher rule · DXGI selection845e0208) gives the same relay settings. In all six cases across three runs,-MotionBlursurvives the F1 replay, and the four motion-blur passes stay enabled.This checks launcher settings with synthetic inputs. Aperture pressure and rendering were outside the probe. AI-assisted with OpenAI Codex.
Independent verification on native Windows 11 Pro (
10.0.26200) + AMD Radeon RX 7900 XTX (gfx1100, driver32.0.32029.2010, Rust1.98):1462e3e8dcleanly ontomain(40e7fe69d) — zero conflicts.cargo test -p leonida-gpu --lib -- --test-threads=4—558 passed; 0 failed; 47 ignored(12.93s), including the newhost::segmentstests.python -I scripts/check_no_game_data.pyon all 6 touched files — PASS.AI-assisted: Antigravity (Gemini 4 Neon)
Thanks, you were right: the launcher judged by every controller in the PC, not by the card the game plays on. Fixed in 077d6084c, as you suggested, by moving the decision to the runtime:
play-nvidia.ps1, andplay.ps1, which had the same default) now setLEONIDA_RELAY_COPY=autoinstead of1, andplay-nvidia.ps1no longer removes it by the controller list.host.rs: when the host device is made, the adapter it is on (EnumAdapterByLuid(device.GetAdapterLuid()), so the default card,LEONIDA_ADAPTERby name and the F1 menu's#indexall count) is checked: AMD vendor id0x1002andRX, optional spaces,6and three digits in DXGI's description (the launcher's oldRX\s*6\d\d\d). Underauto,relay_copy()is off only on such a card and logs which way it went. If the adapter cannot be read it stays on, which was the default before this branch. Its one caller (make_relay_fetch) runs on aHost, after the device exists.1or0still wins: the F1 file and-Moreare applied over the launcher'sauto, and the runtime only treatsautoby card.d3d12/README.mdlists the variable.What was tested:
cargo test -p leonida-gpu --lib -- rx6000 every_line_fits values_cycle: 3 passed (a new table test of the name rule: RX 6800 XT, RX 6700M, RX6600 yes; RX 7900 XTX, RX 580, Radeon(TM) Graphics, an NVIDIA name, "RX 6800" with NVIDIA's vendor id and WARP no; plus the menu's width and cycling tests).play-nvidia.ps1 -DryRun:LEONIDA_RELAY_COPY=autoplain and with-Adapter 'RTX 4070'(which also printsLEONIDA_ADAPTER=RTX 4070);-More @{LEONIDA_RELAY_COPY='1'}prints1.autoshould give what the previous commit gave (relay copy off), which is what the light was measured with.Left as it is: the frame-generation default a few lines below (
$card -match 'RTX\s*(40|50)\d\d') reads the same joined list, so on a mixed PC it can turn on DLSS frame generation while the game runs on the Radeon. That is onmainalready and outside this PR.AI-assisted (Claude Code).
Game-run A/B on Windows AMD RDNA2 (RX 6600 8 GB), the profile this PR is about.
n=1each, and one difference in the caches I could not avoid (below), so read it as a first data point, not a proof.tested: #2670 on RX 6600 8 GB (Windows, AMD 32.0.21045.29003), better: story load + device lost at ~180 s / play for ~290 s, closed by hand, no device lost.
The caveat: B started with every pipeline A and the warm step had made, and made none in play, while A still made 69 in play. Both device losses on
mainon this card (also the cold run in #2464) came while pipelines were being made in play, so part of the difference may be the cache, not this PR. A cleaner pair would be A and B both from the same emptied pipeline cache; I can run that if it helps.Contribution : EI S.O.S INFO LUDO
The cleaner pair, as offered above: A and B from the same emptied caches (Leonida's
pipelinesfolder and AMD'sDxcCachemoved aside before each run), so neither starts with pipelines the other made.tested: #2670 on RX 6600 8 GB, better: device lost ~240 s after the story pack opened / no device lost through ~380 s, closed by hand. Same caches state this time, so the cache caveat of my first comment does not apply here. Still
n=1per side. The frame rate is the same in both (0.2 fps while pipelines are made in play); this PR does not change that, nor should it.Contribution : EI S.O.S INFO LUDO
Added aace3e264: while an aperture segment is tight, the trim this PR adds froze the line of submissions and the title's present for 150-260 ms.
What happened.
trim_idle()andtrim_preludes()ran inline on the submitting thread at the first submission aftersegments::tightturned true. They freed up to ~448 idle host lists and ~112 preludes there, and freeing them is the graphics kernel's time. TwoLEONIDA_TIMELINEcaptures showed it:tight=true/tight=falsepair in the log exactly;The change. The same objects are taken out under the same locks, by the same decision. Only their drop moves to a thread of its own,
leonida-trim. It is not the reaper, which can sit in 70-100 ms spans.LEONIDA_TRIM_ASYNC=0gives the old behaviour.LEONIDA_ABcan switch it live.Measured on an RX 6800 XT (driver 32.0.21045.29003), Ryzen 9 5950X, Series S profile, relay 2, FSR 3.1:
Tests.
trim_tests,host::segmentsand the trim test inlist.rs: 9 passed, with and without--features diagnostics. The diag build passes.AI-assisted.
Checked the release-thread behavior with a real D3D12 buffer at
aace3e264+9f27ba2e1. I passed a 64 KiB hardware buffer throughlet_go_apartand held its destruction behind a channel handshake. WithLEONIDA_TRIM_ASYNC=1, the caller returned while the destructor was still held onleonida-trim. With0, the destructor ran on the caller and it returned only after release. Both arms passed on AMD RADV and RTX 4070 SUPER under Wine 11.22. The seven aperture-policy unit tests passed as well. This isolates ownership and scheduling of the release. Native RDNA2 aperture pressure and frame times remain outside this run.AI-assisted with OpenAI Codex (GPT-6).
Test report on RDNA 2 (RX 6600 8 GB), PR head
aace3e264merged on top ofmainlocally (rebuilt at 18:41 UTC+1 today, with #2764 / #2828 / #2865 / #2904 from main).Setup: AMD Radeon RX 6600 8 GB (driver 32.0.21045.29003), Ryzen 5 3600, 32 GB RAM, Windows 11 build 26300.
scripts/play-d3d12.ps1 -SeriesSwith FSR 3.1,LEONIDA_SUBMIT_FRAMES=0. Retail game data.What I saw (5 sessions today, about 2 h of play in total, longest 51 min):
host::segmentsat device creation0x887A0007Relay stage: stage 2 in every session (
LEONIDA_RELAY=2in the settings line, or unset = default;exact=true). Side note: with relay 2 set, thehostinfo line "what shaders wrote is copied back by a thread of its own … (LEONIDA_RELAY=1)" reads as if relay 1 were set, which confused me at first.Guard off (A/B): same build, same save,
LEONIDA_RELAY=2+LEONIDA_SEGMENT_TIGHT=0, 12 min of play: aperture segment at most 30 MB / 2048 MB, no device removed, 17.3 fps average, 4.3 % of frames over 100 ms.Reading: on this RX 6600 with current
main+ this PR, the 2 GB aperture segment never comes close to filling, with or without the guard, and I could not reproduce the device loss. So on this card the guard is harmless but I can't confirm it is what prevents the loss; the other parts of the PR were not turned off in the A/B. A run of plainmainwithout the PR would be the next step if you want one.AI-assisted (Claude). EI S.O.S INFO LUDO
Closing: this pull request no longer applies to current
main(merge conflict ind3d12/crates/leonida-gpu/src/host.rs), and open pull requests that have fallen out of step withmainare being closed so the list stays workable. If you still want this change, rebase it on currentmainand reopen it (or open a new pull request); it will be looked at again.AI-assisted (Claude Code).
@amujark this was closed only for the
host.rsconflict, and the fix is still needed on RDNA 2 (my report above: RX 6600 8 GB, about 2 h of play without the device lost at the first heavy scene).In case it saves you time: I resolved that conflict on 2 December (main's reaper kept, with this PR's
recycle_landedand preludes in reserve) onlerapeurdu62280-debug/mandy:notre/2670, based on2705632c5. It still merges cleanly on today's main (f6dd2242e). Your commits are kept as they are, so you can rebase onto it or take only the resolution, and reopen.Contribution : EI S.O.S INFO LUDO