fix(vk): an allowance AMD's driver gives as the count itself is taken as past it #1091
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1091
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:vram-at-count"
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?
Type: fix · Risk: low · Tested on: Linux, RTX 3090 (a test allowance that reports like AMD's Windows driver) · Needs: Windows, AMD with 8 GB or less
Why
On Windows with an AMD card of 8 GB or less, the game freezes for 1 to 15 seconds at a time in heavy areas like Hyrule Field and the Market, once video memory fills. The renderer is meant to give textures back before that happens, but AMD's driver tells it there is still room, so it never does, and Windows moves video memory out to system memory instead.
AMD's Windows driver reports a process that is over what it allows as allowed exactly what it uses. In the logs on #1025 (RX 6600, nightly-322) and #933 (RX 6600, rc.4), the allowance follows the count up as the scene loads:
Read as it is, the count is within the allowance (
used <= allowed):vram_compact::room_in_blocksis true, so the 97% squeeze waits;Fixes #1025's VRAM part (its other finding, the write-backs' share of the GPU frame, is separate). See #933, #939.
How to reproduce
Seen on: Windows 11, AMD RX 6600 8 GB, driver 26.10.1 (#1025); rc.4 on another RX 6600 (#933)
Settings and switches: 2560x1440 output, 67% render resolution, the game's own upscaler
Steps: play into Hyrule Field, with other programs using some VRAM
Expected: the renderer gives textures back as VRAM runs short; no freezes
Actual:
VRAM: 5940 MB used of 5940 MB allowed ... (at the driver's limit, room in the blocks: not squeezed)and frames of 1.2-15.7 sOn any card, with this PR's diagnostic switches:
RX_VK_TEST_ALLOWED_FILE=<file>holding7378, changed to5000once in Hyrule Field, withRX_VK_TEST_ALLOWED_FOLLOW=1 RX_VK_IMAGE_PREALLOC=9 RX_VK_ALLOWED_AT_COUNT=0. The log then shows the same line:What changed
An allowance the driver reports as equal to the count (within 16 MB) is now taken as past it: a tenth under the count. Every rule that reads the allowance then sees the count past it and gives memory back, until the driver again reports an allowance above the count.
vram_compact::past_allowance(used, allowed)ingpu/vk/vram_compact.h. Used byvram_usage()ingpu/vk/vk_vma.cpp, sotexture_frame's rules, the mirrors' and the status line all read the same allowance. It logs its first 8 uses:vk: the driver's allowance is the count itself (... MB used of ...): past it, taken as ... MB. An allowance already under the count, or one that isn't known, is left as it is.RX_VK_TEST_ALLOWED_FILE, the test bound read from a file once a second so it can shrink in play; andRX_VK_TEST_ALLOWED_FOLLOW=1, which reports the allowance as the count once past the bound, as AMD's driver does.tests/test_vram_compact.cppcheckspast_allowanceon the two cards' numbers, the cases left alone, and thatroom_in_blocksstops waiting on its result.docs/development.md.Measurements
Verdict: On the RTX 3090 with the allowance reported as AMD's driver does, the fix takes the count back under the real allowance (mostly 4,844-4,936 MB of 5,000, against at or past it in about 3 of 4 samples without the fix). Frame rate is unchanged within the spread. The freezes themselves can't happen on Linux, where nothing is paged out at the allowance, so whether they are gone is for the Windows AMD run below.
Hardware: Linux (CachyOS, kernel 7.3.3), RTX 3090 24 GB, NVIDIA 620.70.06, Ryzen 9 7900X, 30 GB
Scene: Hyrule Field (teleport), 5 s walking forward then 20 s walking while turning the camera; 2560x1440 output, 67% render resolution, the game's own upscaler, uncapped, V-Sync off, no frame generation
Method: each run from a fresh session. The test allowance is 7,378 MB from the start and 5,000 MB from 3 s after Hyrule Field loads, with
RX_VK_TEST_ALLOWED_FOLLOW=1 RX_VK_IMAGE_PREALLOC=9(the RX 6600's 9 starting blocks). Thevk: VRAM:lines after the drop, and fps and frame times fromRX_VK_FRAME_LOGover the walk and the turn.RX_VK_PASS_TIMING=1on both sides. Interleaved: a warm-up, then off, on, off, on.How to reproduce: the switches above,
RX_VK_ALLOWED_AT_COUNT=0for the "before" column.Baseline: the same build with
RX_VK_ALLOWED_AT_COUNT=0, which is main's behaviour. Measured one4d035e9with this change (the renderer built from it, in a game folder ofe4d035e9); rebased since ontof7922126, whose commits don't touch these files.RX_VK_ALLOWED_AT_COUNT=0(warm-up, run 1, run 2)10468ad5(run 1, run 2)5000 of 5000,5768 of 5768)5000 of 4500)In the second run with the fix, the count held at exactly 5,000 MB in 4 of 5 samples, with the textures' budget at 665-1,144 MB under 1.4-2.1 GB of textures. What stays is textures used in the last 60 frames, which the eviction keeps on purpose (
RX_VK_EVICT_MIN_UNUSED; 8 brought back textures made again in a loop and empty rendered ones,vk_texture.cpp). This PR doesn't change that. Whether more needs to give back on Windows is for the run below to show.Flags and settings
One switch with a default for everyone, and two diagnostic ones.
RX_VK_ALLOWED_AT_COUNT0: as the driver says)RX_VK_TEST_ALLOWED_FILERX_VK_TEST_ALLOWED_FOLLOWTesting
Tested: Linux, RTX 3090, NVIDIA 620.70.06, in the game: Hyrule Field with the allowance shrinking in play and reported as AMD's driver does. Reproduced #1025's
not squeezedstate with the fix off, and saw it taken as past the allowance and given back with the fix on (table above). The renderer built from this change runs in a game folder built frome4d035e9.Not tested:
python -I -B tests/run_all.py, including the newpast_allowancechecks intests/test_vram_compact.cpp: not run on this PC. The person I work for runs no test suites on it, so this is left to CI.past_allowancedoesn't exist, sotest_vram_compact.cppdoesn't build there (not run, for the same reason).Must be tested:
VRAM: N MB used of N MB allowed ... not squeezedlines and slow frames of 1 s or more; on this PRthe driver's allowance is the count itselflines,usedfalling under the allowance, and no frames over 1 s (Test Farm: @Beanstalk windows, amd, 8 GB or less: Hyrule Field and the Market, main against this PR, longshot_log.txt'svk: VRAM:andslow framelines)Risks
What could break: a driver that reports the allowance within 16 MB of the count while the process really is within it. The renderer would then give back textures it could keep: more uploads near the limit, not wrong pictures, since the eviction's own rules about what may go are unchanged. Every allowance more than 16 MB over the count is left as it is.
Turning it off:
RX_VK_ALLOWED_AT_COUNT=0Compatibility: Nothing changes: no cache, save or options file, and the renderer's interface is unchanged.
Issues
Fixes #1025
See #933
See #939
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). Not run on this PC (no test suites run on it); left to CI.third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. Added (tests/test_vram_compact.cpp, its own commit first); not run on this PC.tests/that reads changed source updated in this PR, not weakened.tests/test_vram_compact.cppgains thepast_allowancechecks; the checks that readvk_vma.cppcutblocks_at_start,make_pooland the pools, which are unchanged, and the ones usingvram_usagegive it a stand-in of their own.<chrono>,<cstdio>andfopenof a path from the environment (a diagnostic switch).🤖 Generated with Claude Code
Tested in game: RTX 3090, NVIDIA 620.70.06, Linux (CachyOS): Hyrule Field at 2560x1440 / 67%, the test allowance shrinking 7378 -> 5000 MB in play and reported as AMD's Windows driver does (RX_VK_TEST_ALLOWED_FILE + RX_VK_TEST_ALLOWED_FOLLOW, RX_VK_IMAGE_PREALLOC=9). Fix off: '5768 MB used of 5768 MB allowed ... not squeezed', as on the RX 6600 of #1025. Fix on: 'the driver's allowance is the count itself ... taken as 4500 MB' and the count back to 4,844-4,936 of 5,000 MB in most samples; fps the same within the spread (no paging on Linux, so the freezes need the Windows AMD run).
@Beanstalk windows, amd, a card with 8 GB or less (RX 6600 class): Hyrule Field and Castle Town Market, a few minutes each at 2560x1440 output and 67% render resolution with the game's own upscaler, on main and on this PR. On main I expect
vk: VRAM: N MB used of N MB allowed ... (at the driver's limit, room in the blocks: not squeezed)lines and slow frames of 1 s or more once VRAM fills. On this PR I expectvk: the driver's allowance is the count itselflines,usedfalling under the allowance after them, and no frames over 1 s. Please keep longshot_log.txt'svk: VRAM:,vk: status:andslow framelines from both.Beanstalk test farm
Commit
10468ad· tier reviewed · approved by HumanBean · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)A Windows AMD PC with at most 8 GB of VRAM will run Hyrule Field and Castle Town Market for two minutes each on main and the PR; the target may wait for a matching tester. The plan measures VRAM and frame times and compares scene images; a crash, a measured frame of one second or longer on either build, or a large image difference fails the run. The farm cannot specify 2560×1440 output or identify the 67% render-resolution value from the available settings, so those requested conditions are not guaranteed. It also cannot enforce the requested side-specific log sequence or retention of selected log lines; reaching driver pressure is not guaranteed. No tester online now matches windows+amd+vram-le8gb: that target waits for one.
Done. Comment
@Beanstalkto run it again.Possibly related, for context:
WIP: fix(vk): an allowance AMD's driver gives as the count itself is taken as past itto fix(vk): an allowance AMD's driver gives as the count itself is taken as past it