WIP:perf(vk): dynamic texture floor and damped contraction for < 7 GB GPUs #1057
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!1057
Loading…
Reference in a new issue
No description provided.
Delete branch "flix331/Longshot:perf/vk-vram-6gb-budget"
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: perf · Risk: medium · Tested on: Windows, NVIDIA GeForce RTX 3050 6GB Laptop GPU (driver 610.62) · Needs: Linux / AMD / 8 GB+ GPU verification
Why
On 6 GB GPUs (such as an RTX 3050 Laptop with
6,001 MBphysical VRAM and5,233 MBdriver allowance), Castle Town Market pushes VRAM close to the driver allowance while VMA texture blocks still hold hundreds of megabytes of free space. Onmain:blocks_at_start()preallocates15%of physical VRAM (~768–1,104 MBlocked in kept blocks) at startup.compact_step()waits until512 MBof returnable free space accumulates before compacting.held_budget()contracts the texture cache by the full excess every pass, which can ratchet the texture budget down sharply (566–1,528 MB) while874–1,202 MBsits free inside VMA blocks.This PR adds proportional compaction thresholds, smaller initial block preallocation (
8%,2–12blocks), a dynamic texture floor with hysteresis (86%–92%sweet spot), and damped contraction (over / 4while within allowance) strictly gated by physical VRAM (device_vram_bytes() < 7 GB) so8 GB+cards remain untouched, while leaving the97%count_lineemergency eviction rule without a floor.What changed
Added
< 7 GBphysical VRAM gating, proportionaldefault_min_free(), dynamic texture floor (update_dynamic_floor), and damped contraction (held_budget) without putting any floor on the97%count_linerule or changingkHoldUnused/kReserveUnused.device_vram_bytes()ingpu/vk/vk_menu.h(defined ingpu/vk/vk_memory.cpp) sovk_texture.cppcan gate constrained-VRAM heuristics by physical VRAM rather than driver allowance.kConstrainedVramBytes(7 GB),is_constrained_vram(),default_min_free(allowed)(allowed / 16clamped to64–512 MB),8%blocks_at_start()for< 7 GBheaps,texture_min_floor(),update_dynamic_floor(),emergency_floor(), and optionalfloor_override/phys_vramdamped contraction inheld_budget()ingpu/vk/vram_compact.h.default_min_free()incompact_step()(whenRX_VK_COMPACT_MBis unset) andupdate_dynamic_floor()/device_vram_bytes()intoheld_budget()intexture_frame()ingpu/vk/vk_texture.cpp, keeping the97%count_linerule untouched.Measurements
Verdict: Significant VRAM stability and headroom improvement on
< 7 GBGPUs without altering native FPS ceilings (RTX 3050 6 GB remains GPU-bound at~29–31 ms/framein native 1080p Market): startup preallocation drops by~530–548 MB(524–542 MBvs1,072 MBfree in blocks),default_min_freeruns10proactive compactions returning7,296 MB, and withRX_VK_COMPACT_MB=512VRAM settles at4,402 MBused of5,233 MBallowed (831 MBheadroom,budget 1,800 MB,2overshoots vs3onmain).8 GB+GPUs keepmainbehavior unchanged.Hardware: Windows 11, NVIDIA GeForce RTX 3050 6GB Laptop GPU (
6,001 MBphysical VRAM,5,233 MBdriver allowance, driver610.62), 16 GB RAM, 12 threadsScene: Castle Town Market (
>= 1,800draws),1920x1080, game's own upscaler (dlss=0), no frame rate cap, syncedlongshot_options.iniMethod:
logs/longshot_log.txtparsed across startup and Market frames (>= 1,800draws:16samples onmain,34samples onPR (b)default~327 MB,18samples onPR (b)+RX_VK_COMPACT_MB=512)How to reproduce: Launch with
VK_ICD_FILENAMESpointing to NVIDIAnv-vk64.json, walk around Castle Town Market, and inspectvk: VRAM:andvk: VRAM compactionlines inlogs/longshot_log.txt.e090cc48e5511648e5511648blocks_at_start)1,869 MB used (1,072 MB free in blocks)1,501 MB used (542 MB free in blocks)1,510 MB used (524 MB free in blocks)5/310(7,296 MBreturned) /49(5,632 MBreturned) /22,383(16samples)2,278(34samples)2,301(18samples)21.54(15.2–31.6)18.76(15.4–25.9)18.32(15.8–21.6)22.44 ms/18.52 ms31.30 ms/20.70 ms30.04 ms/21.49 ms5,423 MB used of 5,233 MB (874 MB free in blocks); textures 2,727 MB (budget 1,528 MB)5,403 MB used of 5,233 MB (816 MB free in blocks); textures 2,558 MB (budget 1,412 MB)4,402 MB used of 5,233 MB (1,098 MB free in blocks); textures 1,007 MB (budget 1,800 MB)Flags and settings
None
Testing
Tested:
nx2/make_game.py --update(llvm-mingw) and tested across two Castle Town Market runs (longshot_log.txt).tests/test_vram_pressure.py:PASS: the shadows go by what is really allocated.Not tested: Linux, AMD, Intel Arc/iGPU,
8 GB+dedicated GPUs, and fulltests/run_all.py.Failed (expected pending maintainer decision on test updates):
tests/test_blocks_at_start.py: fails at line 31 (blocks_at_start(c.gb * GB, kBlock, true, false) == c.blocks) becausecards[]still asserts{4, 4}, {6, 7}(15%) instead of{4, 2}, {6, 3}(8% for< 7 GB).tests/test_vram_compact.py: warnsvk_texture.cpp: texture_frame() no longer has: vram_compact::held_budget(budget, total_bytes, used, reclaim, allowed, pct)because the call now passesdynamic_floor, phys_vram.Must be tested:
main, by hand: checkvk: VRAM:lines inlongshot_log.txt.Risks
What could break: More frequent compactions on
< 7 GBGPUs (default_min_freestarts around327 MBon a5,233 MBallowance instead of512 MB), and smaller initial block preallocation (8%vs15%) may allocate extra blocks on demand during heavy scene transitions.8 GB+GPUs keepmainbehavior.Turning it off: Revert commit
e5511648(or setRX_VK_COMPACT_MB=512/RX_VK_IMAGE_PREALLOCto override compaction threshold and preallocation).Compatibility: Nothing changes (saves,
longshot_options.ini, shader/pipeline caches, and vk ABI are unaffected).Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (pending maintainer decision to updatetests/test_blocks_at_start.pyandtests/test_vram_compact.pyfor< 7 GB8% prealloc andheld_budgetargs).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.Possibly related, for context:
e5511648350bc1d742e40bc1d742e447abc4f5f2Hey! This one seems to be worst on performance?
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.