fix(vk): sparse mirror blocks stay bound on AMD's Windows driver on GCN #3256
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3256
Loading…
Reference in a new issue
No description provided.
Delete branch "tobim6/Longshot:sparse-keep"
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?
Summary
On Windows with AMD's driver on a GCN 1-4 card (RX 580 8 GB, driver 0x800106, Adrenalin 23.10.01.14), the game
stops the whole PC with a bugcheck after some minutes of play: first
PAGE_FAULT_IN_NONPAGED_AREAindxgmms2.sys,then
SYSTEM_THREAD_EXCEPTION_NOT_HANDLED(0x7E,C0000005) inamdkmdag.sys. The kernel dump's stack is inamdkmdag.sys'sDdiBuildPagingBuffer, called bydxgmms2.sysbuilding the update forVIDMM_PAGE_TABLE::Convert64K_4Kwhile it paged an allocation in. The game's log before it shows ~8,800 sparse mirrorblock give-backs in the two minutes before the crash:
sparse_releaseunbinds every block all game pools have left,and a block wanted again gets a new allocation and a bind. Every one is a page-table update; on this driver one of them
crashes the kernel.
RX_VK_MIRROR_SPARSE=0also avoids it (reported on Discord), at a frame-rate cost.This adds
sparse_keeptodevice_policy.h: on AMD's Windows driver on GCN (f.amd_win() && f.arch() == GpuArch::AmdGcn, the same devices asa2c_in_pipeline)sparse_releasegives nothing back, so a block stays bounduntil its mirror goes. Sparse mirrors stay on; only the churn goes. A hidden setting,
system/memory-settings:sparse_keep(RX_VK_SPARSE_KEEP, Auto/Off/On), overrides it on any PC.Read first:
gpu/vk/device_policy.h(the field, its rule,Sw::sparse_keep, the log line),gpu/vk/vk_memory.cpp(sparse_release's first line). The setting isgame/mods/memory-settings/mod.toml;game/settings_abi.handsettings_abi.rsare schema-gen's.Testing
Tested: Windows 11 (build 26200), RX 580 8 GB, Adrenalin 23.10.01.14 (driver 0x800106), Xeon E5-2699 v3: played with sparse mirror blocks kept (the same sparse_release return, turned on by RX_VK_SPARSE_KEEP=1 in a build of this branch's first version); the SYSTEM_THREAD_EXCEPTION_NOT_HANDLED BSODs in amdkmdag.sys that the game caused before did not come back.
Before this, the same PC bugchecked in
amdkmdag.sys(kernel dump analysed: the stack above); with sparse blocks kept it has not. This PR's policy turns onthe same
returnby itself on that driver, so it runs the tested path without the switch.Checks (game-free):
schema-gen --check;tests/test_device_policy.py(the new field on all 26 PCs, its switch cases,and rule edges: on for GCN 0x67DF/0x6FDF on AMD's Windows driver; off for Vega 0x687F, RDNA, Linux, RADV),
test_switch_table.py,test_menu_ini_keys.py,test_i18n_complete.pypass. The whole tree built on Windows by thebuilder for the in-game test above. The full suite: CI's
testsjob on this PR.Still to test:
sparse_keepoff), expecting the same asmain(@Beanstalk)sparse_keepon in the log (by hand)Measurements
Nothing to measure for speed: the change only skips unbinds on the one driver; the cost is VRAM, at most the blocks the game has left in still-living mirrors (about 0.5 GB late in a session on the RX 580 8 GB).
Risks
sparse_releaseruns as onmain.If that pushes a 4 GB card over, the setting's Off (
RX_VK_SPARSE_KEEP=0) restoresmain's behaviour.sparse_keep, insettings.toml's options;LS_SETTINGS_LAYOUTchanges (schema-gen).Revert is enough to undo.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (CI'stestsjob: ticked once it passes)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (test_device_policy.py'ssparse_keeprule edges pass here; the run onmainis pending)gpu/vk/switches.def. (aSETTINGrow; Auto)tests/that reads changed source is updated, not weakened. (test_device_policy.py,test_menu_ini_keys.py)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11 (build 26200), RX 580 8 GB, Adrenalin 23.10.01.14 (driver 0x800106), Xeon E5-2699 v3: played with sparse mirror blocks kept (the same sparse_release return, turned on by RX_VK_SPARSE_KEEP=1 in a build of this branch's first version); the SYSTEM_THREAD_EXCEPTION_NOT_HANDLED BSODs in amdkmdag.sys that the game caused before did not come back.
WIP: fix(vk): sparse mirror blocks stay bound on AMD's Windows driver on GCNto fix(vk): sparse mirror blocks stay bound on AMD's Windows driver on GCN@review
Recommendation: Approve. The reported RX 580 run supports the workaround, but the game-free test would still pass if the line that prevents sparse releases were removed. The memory and performance cost on smaller GCN cards also needs measurement before the default is settled. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Keeps sparse mirror blocks bound by default on AMD Windows GCN drivers to reduce page-table churn associated with a reported system crash. This retains otherwise unused VRAM and can leave less mirror budget for new blocks.
Should fix (1): not blocking, but worth doing before merging.
tests/test_device_policy.py:590: The new tests check the policy value but do not check that sparse_release obeys it. (more on the line) Do: Add a game-free behavioral test of sparse release with keep both on and off, including an idle block, so removing the early return fails the test.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_memory.cpp:7131: The cost of retaining unused blocks under the mirror budget is not measured on the smaller cards covered by the default. (more on the line) Do: Compare base and this head over repeated matched long sessions on a 4 GB Windows GCN card, recording retained VRAM, mirror-budget exhaustion, average and 1% low FPS, and frame times.@fixcan do L1.Questions (1) (not confirmed from the code; they don't hold the recommendation)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven overall. The author reports that the prior amdkmdag.sys bugcheck did not recur on an RX 580 8 GB with the same early return enabled, but gives no session duration or repeated comparison. The reported approximately 0.5 GB retained late in a session is not a controlled comparison against the base.
Other systems: Auto leaves the policy off on Linux, RADV, NVIDIA, Intel and AMD Windows RDNA; the override can enable it there. Retained blocks count against the shared mirror budget, so later wanted blocks can remain in guest memory and other mirrors can face more pressure. The cost on 4 GB GCN cards and in longer sessions is not established.
Switches: RX_VK_SPARSE_KEEP adds a hidden Auto/Off/On setting, default Auto: on for AMD proprietary Windows GCN and off elsewhere. It has a switches.def row and documentation. The default's memory and performance tradeoff on smaller affected cards remains unmeasured.
Reviewed:
a25bbd5c90against7bc53f8413: Read the repository rules, PR template, diff and commit message; read the changed sparse release and growth paths, policy changes, setting declaration and relevant test sections. Skimmed generated ABI changes, switch documentation and the remaining portions of the large changed files. docs/review-checklist.md and the sibling Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The author reports a Windows game run and game-free checks; CI was still running.
Overlaps and merge order: Unknown; network access was unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -7128,1 +7128,4 @@void sparse_release() {// (device_policy.h sparse_keep: blocks once given memory stay bound until their mirror goes, on the driver that crashed// in the page-table updates a give-back and a regrow make. The cost: the blocks the game left keep their VRAM)if (dev.policy.sparse_keep) return;L2 (should fix): The cost of retaining unused blocks under the mirror budget is not measured on the smaller cards covered by the default.
When: On a 4 GB Windows GCN card, a long session can retain dead blocks in live mirrors; sparse_grow_all counts them against mirror_budget and leaves newly wanted blocks in guest memory when it runs out of room.
Do: Compare base and this head over repeated matched long sessions on a 4 GB Windows GCN card, recording retained VRAM, mirror-budget exhaustion, average and 1% low FPS, and frame times.
@ -584,6 +587,12 @@ RULES = [("(long long)[] { DeviceFacts f{}; f.vendor_id = 0x1002; f.device_id = 0x73DF; f.driver_id = VK_DRIVER_ID_AMD_PROPRIETARY; f.windows = true; const DevicePolicy p = device_policy(f); return p.a2c_in_pipeline || p.bc_array_no_cube; }()", 0),("(long long)[] { DeviceFacts f{}; f.vendor_id = 0x1002; f.device_id = 0x67DF; f.driver_id = VK_DRIVER_ID_AMD_PROPRIETARY; f.windows = false; const DevicePolicy p = device_policy(f); return p.a2c_in_pipeline || p.bc_array_no_cube; }()", 0),("(long long)[] { DeviceFacts f{}; f.vendor_id = 0x1002; f.device_id = 0x67DF; f.driver_id = VK_DRIVER_ID_MESA_RADV; f.windows = false; const DevicePolicy p = device_policy(f); return p.a2c_in_pipeline || p.bc_array_no_cube; }()", 0),# (sparse_keep: the same devices, Vega (GFX9) not among them; the driver that crashed in the page-table updates its give-backs made)L1 (should fix): The new tests check the policy value but do not check that sparse_release obeys it.
When: Deleting the early return in vk_memory.cpp leaves these policy and override cases passing, while GCN players again release blocks and encounter the page-table churn the fix is meant to prevent.
Do: Add a game-free behavioral test of sparse release with keep both on and off, including an idle block, so removing the early return fails the test.
@fix
@fix
Recommendation: Approve. The code is ready: only testing is left. The reported RX 580 session supports the crash workaround, but its retained VRAM cost on smaller cards covered by the default remains unmeasured. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
9a9e0edfde. I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The change keeps sparse mirror blocks bound on AMD Windows GCN devices to reduce the page-table churn associated with a driver crash. It trades that reduction for higher VRAM use; the added fixture checks release behavior with the policy on and off.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_memory.cpp:7131: The cost of retaining unused blocks under the mirror budget is not measured on the smaller cards covered by the default. When: On a 4 GB Windows GCN card, a long session can retain dead blocks in live mirrors; sparse_grow_all counts them against mirror_budget and leaves newly wanted blocks in guest memory when it runs out of room. Do: Compare base and this head over repeated matched long sessions on a 4 GB Windows GCN card, recording retained VRAM, mirror-budget exhaustion, average and 1% low FPS, and frame times.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes for the reported crash: the author reports that the amdkmdag.sys bugchecks did not recur during play on an RX 580 8 GB with the same early return enabled. The duration and retained-block cost on smaller cards are not reported.
Other systems: Auto leaves the policy off on Linux, RADV and AMD RDNA; the override can enable it elsewhere. The author reports about 0.5 GB of retained blocks late in a session on the 8 GB RX 580, but the effect on smaller GCN cards remains open.
Switches: RX_VK_SPARSE_KEEP and system/memory-settings:sparse_keep are added as a hidden Auto/Off/On setting. Auto enables retention for AMD's Windows driver on GCN and disables it elsewhere; its suitability on smaller cards awaits the VRAM measurement.
Reviewed:
9a9e0edfdeagainst7bc53f8413: Read the repository rules and PR template, the full sparse-mirror test, the release function and its fixture, and the relevant policy and settings changes. Skimmed generated ABI changes, policy test cases and the remaining changed files; not every changed code file was read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run. CI has not yet run on this head; the author reports an in-game RX 580 test and game-free checks on the earlier version.
Overlaps and merge order: Not established from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@rebase
I rebased this pull request onto
main(7c1ffffb57): the new head isded623b044.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
9a9e0edfdeded623b044Recommendation: Request changes. It conflicts with its base branch: bring it up to date (
@​fixor@​rebasetry first). (L3) Keeping sparse blocks bound avoided the reported crash in the RX 580 test, but its memory cost and effect on smaller GCN cards remain unmeasured.The change avoids sparse-block release churn by default on AMD Windows GCN GPUs, retaining the blocks until their mirrors are destroyed. It trades page-table updates for higher retained VRAM and possible pressure on the mirror budget.
Blocking (1): must change before merging.
@​fixor@​rebasetry first). (for the author)Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_memory.cpp:7131: The cost of retaining unused blocks under the mirror budget is not measured on the smaller cards covered by the default. When: On a 4 GB Windows GCN card, a long session can retain dead blocks in live mirrors; sparse_grow_all counts them against mirror_budget and leaves newly wanted blocks in guest memory when it runs out of room. Do: Compare base and this head over repeated matched long sessions on a 4 GB Windows GCN card, recording retained VRAM, mirror-budget exhaustion, average and 1% low FPS, and frame times.Since the last review (on
9a9e0edfde)Still open: L2 (The cost of retaining unused blocks under the mirror budget is not measured on the smaller…)
New: L3 (It conflicts with its base branch: bring it up to date (
@​fixor@​rebasetry first).)Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven across the affected cards. The author reports that the tested RX 580 no longer bugchecked during play with the keep behavior enabled; the description estimates about 0.5 GB retained late in that session. It supplies no smaller-card comparison.
Other systems: Auto leaves AMD RDNA, Linux, RADV and other vendors unchanged; the hidden override can enable the behavior elsewhere. The remaining concern is memory pressure and mirror-budget competition on smaller affected GCN cards.
Switches: RX_VK_SPARSE_KEEP / system/memory-settings:sparse_keep is added as a hidden Auto/Off/On setting. Auto enables it for AMD's Windows driver on GCN and disables it elsewhere; its suitability on smaller cards remains unmeasured.
Reviewed:
ded623b044against7c1ffffb57: Read the repository instructions and pull request template, the diff, the settings definition, sparse-release and memory-budget context, and the rebased ABI changes. The generated ABI files and other changed files were skimmed; the full changed code files were not all read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. The author reports an in-game RX 580 test and passing game-free checks; the supplied CI status still has the description check running.
Overlaps and merge order: Not determined from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
ded623b044d2cdf086e6Rebased onto main (
3145d9d4): the conflict was only the generated settings ABI (game/settings_abi.h, game/crates/host-sys/src/settings_abi.rs), made again by schema-gen (--check passes). test_device_policy, test_sparse_mirror, test_switch_table, test_menu_ini_keys, test_i18n_complete pass on the new head.