A card counts as small at fifteen places with six different cut-offs, so VRAM rules disagree about what a small card is #1511

Open
opened 2026-11-18 01:46:00 +00:00 by mooki · 1 comment
Member

Type: correctness · Area: renderer, VRAM policy · Part of: #1493

TL;DR

Whether a card is "small" is decided at fifteen places on main, with six cut-offs between 4.5 and 8.5 GiB, on three different quantities (the card, the driver's allowance, the PC's RAM). Three of the fifteen are copies, and one PC can be small for one rule and not for another. The static budgets for textures and mirrors also add up to 93 to 97% of an assumed allowance on 4, 6, 8 and 16 GB cards. The counters are under way in #1339; I propose one function that classifies a card once, and a game-free test that prints the table and fails when two rules disagree.

Breakdown

  • Who it affects: players on 4 to 8 GB cards and integrated GPUs, where the textures get what the other classes leave, and developers who change one cut-off without finding the others.
  • What is wrong: each rule reads the card its own way. Comments and code already disagree in the same files (stale lines below). The per-class budgets leave 3 to 7% of the allowance for render targets, shadows, upscaler images, streams and the driver.
  • What we propose: (1) one function, next to device_policy.h, that turns (card, allowance, RAM, integrated) into one class, and every rule asks it. Where two cut-offs differ on purpose, the function keeps both and names the reason. (2) A game-free table test. (3) Count first: take the by-class counters from #1339 and do not repeat them here.
  • What does not change: step 1 changes no number. The refactor is proved by the same decisions on the same made-up PCs. Moving a cut-off is a separate change with its own paired run.
  • How we would prove it: the existing policy checks on made-up PCs give the same table before and after; the log's policy lines are identical on a 4090 held to 4, 6, 8, 12 and 16 GB by the test switches.

Evidence

Where a card is tested, on main (310e7c9df). "Allowance" is what the driver lets the game use; "card" is the device-local heap.

# Where Tested Cut-off Decides
1 mirror_budget.h:12 card 4.5 GiB or less mirrors at most 256 MB (:32); texture budget at most 2.2 GB (texture_budget.h:33, 45)
2 device_policy.h:110 card 6.5 GiB or less mirrors a third, at most 1,700 MB
3 vk_memory.cpp:3693 card 6.5 GiB or less the same mirror rule, written again where mirrors are sized
4 vk_memory.cpp:5327 card 6.5 GiB or less hot-first mirrors on by default
5 device_policy.h:143 allowance, or integrated GPU with RAM 4.5 GiB, 16 GiB RAM the top texture levels dropped
6 vk_texture.cpp:2187 allowance 4.5 GiB or less the same test, again
7 device_policy.h:156 allowance 6.5 GiB or less spare capture buffers 32 MB
8 device_policy.h:162 allowance 6.5 GiB or less idle staging kept 128 MB, else 256
9 texture_budget.h:28 RAM and card RAM under 12 GiB, card over 6.75 GiB texture budget as a share of the allowance
10 texture_budget.h:29, 44 allowance 8.5 GiB or less 45% instead of 70%
11 astc_bc_policy.h:13 allowance under 8.5 GiB ASTC kept as BC3
12 upscaler_rows.h:266 card under 7 GiB DLSS CNN preset
13 device_policy.h:571 heap under 7 GiB the same rule, again
14 vram_compact.h:18 allowance or heap 8 GiB block sizes (device_policy.h:167-168, vk_vma.cpp:65, 103), floor and damping (vram_compact.h:47, 112, 119, 150, device_policy.h:186)
15 auto_settings.h:64, 86 card in MB 4,608 and 6,656 MB the preset tier, "held at Low"
  • Rows 3, 6 and 13 repeat rows 2, 5 and 12. Row 3's comment describes mirror_budget.h (a quarter; 256 MB on small cards) above code that returns a third on any card up to 6.5 GiB (vk_memory.cpp:3687-3693).
  • One PC can be small for one rule and not for another. A card of 8 GB whose driver allows 6.4 GB at start is small for rows 7 and 8 and not for rows 1 to 4 (it follows from the two quantities; no log of such a PC was checked). The comment at device_policy.h:159-161 is about a laptop card (an RTX 4050 Laptop with 5.7 GB).
  • Stale comments in the same files: the pool block is "128 MB" at vk_vma.cpp:69 and 32 MB in code (:77); the hold line is "85" at vk_texture.cpp:5032 and 80 in code (:5037).
  • texture_frame (vk_texture.cpp:4780-5568, 789 lines) still stacks the rules by min(): the budget by card, the dynamic floor (:5011-5016), the 90% rule (:5021), the hold and reserve lines (:5037-5049), the 97% count line (:5067), driver refusals (:5077), Windows commit (:5097) and Linux pressure (:5125). That is the nine rules of the research.

The static budgets, computed from main's own formulas (texture_budget.h dedicated_bytes, device_policy.h mirror_budget), with the allowance assumed 90% of the card (7,378 of 8,192 MB was seen in #130) and plenty of RAM:

Card Allowance MB Textures MB Mirrors MB Sum Share
4 GB 3,686 2,200 1,365 3,565 96.7%
6 GB 5,529 3,584 1,700 5,284 95.6%
8 GB 7,372 4,774 2,048 6,822 92.5%
16 GB 14,745 11,000 3,072 14,072 95.4%

Not in those columns: render targets, shadows (about 300 MB), upscaler and frame generation images, streams, and the driver's own. The research reports found, from 393 player logs attached to bug reports (so biased toward trouble): on the 8 GB class (83 logs, 8,616 lines) 13.2% of the VRAM lines were past 97% of the allowance, and the driver's count was about 0.95 GB above the allocator's blocks (median; 2.0 GB at p90; 6,307 samples). Method: the research's field_vram and field_gap scripts over the downloaded logs.

The ledger half, so nobody redoes it: #1339 (open, draft) adds mem_account.h, a registry of pools with their VRAM and RAM bytes, and one vk: budget: line with an unaccounted figure. On an RTX 3090 that figure fell from 426 MB to about 280 MB once every allocator buffer was counted. It counts only; its arbiter, which does change behaviour, is a separate commit. For the shared rule, the same PR adds a seventh predicate (six_gb_card in mirror_budget.h) and removes row 3's copy; rows 2 and 4 to 15 are untouched.

Allocation sites, for what a ledger can still miss: outside vk_vma.cpp there are 73 in 15 files (grep count). Five are direct vkAllocateMemory calls: vk_coopmat.cpp:135, vk_draw.cpp:4880, vk_memory.cpp:274, 520 and vk_texture.cpp:4158. The other 68 call create_image, create_buffer, create_device_buffer, create_buffer_cached or alloc_sparse_block (one of them, vk_fsr4.cpp:337, is a driver hook, not a site). The upscaler libraries allocate on our device and stay unaccounted.

Proposed change

  1. Add one classifier (for example card_class(card, allowance, ram, integrated)) and have rows 1 to 15 call it. Start with an enum that holds the six existing cut-offs, so no number moves.
  2. Delete rows 3, 6 and 13 and the stale comments above.
  3. Add the table test (below). Decide its bound with the owners; the table above is what main gives today.
  4. Later, and separately: move or merge cut-offs one at a time, each with a run on a card of that size.

How we would test it

  • Game-free, fails today: a check that lists every comparison of a card, allowance or heap against a GiB constant outside the one function. On main it lists the rows above. After step 1 it lists none.
  • Game-free: extend tests/test_device_policy.py, which already runs device_policy() on made-up PCs of 4, 6, 8 and 24 GB. Print the class each rule used for each card from 4 to 24 GB and the sum of the static budgets against the allowance. Fail when two rules disagree, and when the sum passes the chosen bound.
  • In the game, for step 1: on a 24 GB card with RX_VK_TEST_VRAM_MB and RX_VK_TEST_ALLOWED_MB set to 4, 6, 8, 12 and 16 GB, the log's vk: policy: lines are identical on main and on the branch. This proves no number moved; it makes no speed claim.
  • For any later cut-off change: paired timing on a real card of that size, main against branch, after a null main-against-main pair. None of this runs here yet; the 24 GB card cannot show a small card's effect.
  • #1339 (open, draft): the vk: budget: line and the arbiter. The forge shows it as not mergeable with main today.
  • Where cut-offs came from, by their titles: #637 (dynamic floor, target pool, DLSS CNN presets), #1096 (CNN preset under 7 GB), #1141 (hot-first mirrors on 4 to 6 GB cards), #735 and #237 (mirror budgets). All merged.
  • #1107 (merged): RX_VK_TEST_VRAM_MB, the switch the in-game check uses.
  • #1158 (open): VRAM held for nothing, with frame generation's images. #1493: the umbrella.

New on this forge; not opened on GitHub.

**Type:** correctness · **Area:** renderer, VRAM policy · **Part of:** #1493 ## TL;DR Whether a card is "small" is decided at fifteen places on main, with six cut-offs between 4.5 and 8.5 GiB, on three different quantities (the card, the driver's allowance, the PC's RAM). Three of the fifteen are copies, and one PC can be small for one rule and not for another. The static budgets for textures and mirrors also add up to 93 to 97% of an assumed allowance on 4, 6, 8 and 16 GB cards. The counters are under way in #1339; I propose one function that classifies a card once, and a game-free test that prints the table and fails when two rules disagree. ## Breakdown - **Who it affects:** players on 4 to 8 GB cards and integrated GPUs, where the textures get what the other classes leave, and developers who change one cut-off without finding the others. - **What is wrong:** each rule reads the card its own way. Comments and code already disagree in the same files (stale lines below). The per-class budgets leave 3 to 7% of the allowance for render targets, shadows, upscaler images, streams and the driver. - **What we propose:** (1) one function, next to `device_policy.h`, that turns (card, allowance, RAM, integrated) into one class, and every rule asks it. Where two cut-offs differ on purpose, the function keeps both and names the reason. (2) A game-free table test. (3) Count first: take the by-class counters from #1339 and do not repeat them here. - **What does not change:** step 1 changes no number. The refactor is proved by the same decisions on the same made-up PCs. Moving a cut-off is a separate change with its own paired run. - **How we would prove it:** the existing policy checks on made-up PCs give the same table before and after; the log's policy lines are identical on a 4090 held to 4, 6, 8, 12 and 16 GB by the test switches. ## Evidence Where a card is tested, on main (310e7c9df). "Allowance" is what the driver lets the game use; "card" is the device-local heap. | # | Where | Tested | Cut-off | Decides | |---|---|---|---|---| | 1 | `mirror_budget.h:12` | card | 4.5 GiB or less | mirrors at most 256 MB (`:32`); texture budget at most 2.2 GB (`texture_budget.h:33, 45`) | | 2 | `device_policy.h:110` | card | 6.5 GiB or less | mirrors a third, at most 1,700 MB | | 3 | `vk_memory.cpp:3693` | card | 6.5 GiB or less | the same mirror rule, written again where mirrors are sized | | 4 | `vk_memory.cpp:5327` | card | 6.5 GiB or less | hot-first mirrors on by default | | 5 | `device_policy.h:143` | allowance, or integrated GPU with RAM | 4.5 GiB, 16 GiB RAM | the top texture levels dropped | | 6 | `vk_texture.cpp:2187` | allowance | 4.5 GiB or less | the same test, again | | 7 | `device_policy.h:156` | allowance | 6.5 GiB or less | spare capture buffers 32 MB | | 8 | `device_policy.h:162` | allowance | 6.5 GiB or less | idle staging kept 128 MB, else 256 | | 9 | `texture_budget.h:28` | RAM and card | RAM under 12 GiB, card over 6.75 GiB | texture budget as a share of the allowance | | 10 | `texture_budget.h:29, 44` | allowance | 8.5 GiB or less | 45% instead of 70% | | 11 | `astc_bc_policy.h:13` | allowance | under 8.5 GiB | ASTC kept as BC3 | | 12 | `upscaler_rows.h:266` | card | under 7 GiB | DLSS CNN preset | | 13 | `device_policy.h:571` | heap | under 7 GiB | the same rule, again | | 14 | `vram_compact.h:18` | allowance or heap | 8 GiB | block sizes (`device_policy.h:167-168`, `vk_vma.cpp:65, 103`), floor and damping (`vram_compact.h:47, 112, 119, 150`, `device_policy.h:186`) | | 15 | `auto_settings.h:64, 86` | card in MB | 4,608 and 6,656 MB | the preset tier, "held at Low" | - Rows 3, 6 and 13 repeat rows 2, 5 and 12. Row 3's comment describes `mirror_budget.h` (a quarter; 256 MB on small cards) above code that returns a third on any card up to 6.5 GiB (`vk_memory.cpp:3687-3693`). - One PC can be small for one rule and not for another. A card of 8 GB whose driver allows 6.4 GB at start is small for rows 7 and 8 and not for rows 1 to 4 (it follows from the two quantities; no log of such a PC was checked). The comment at `device_policy.h:159-161` is about a laptop card (an RTX 4050 Laptop with 5.7 GB). - Stale comments in the same files: the pool block is "128 MB" at `vk_vma.cpp:69` and 32 MB in code (`:77`); the hold line is "85" at `vk_texture.cpp:5032` and 80 in code (`:5037`). - `texture_frame` (`vk_texture.cpp:4780-5568`, 789 lines) still stacks the rules by `min()`: the budget by card, the dynamic floor (`:5011-5016`), the 90% rule (`:5021`), the hold and reserve lines (`:5037-5049`), the 97% count line (`:5067`), driver refusals (`:5077`), Windows commit (`:5097`) and Linux pressure (`:5125`). That is the nine rules of the research. The static budgets, computed from main's own formulas (`texture_budget.h dedicated_bytes`, `device_policy.h mirror_budget`), with the allowance assumed 90% of the card (7,378 of 8,192 MB was seen in #130) and plenty of RAM: | Card | Allowance MB | Textures MB | Mirrors MB | Sum | Share | |---|---|---|---|---|---| | 4 GB | 3,686 | 2,200 | 1,365 | 3,565 | 96.7% | | 6 GB | 5,529 | 3,584 | 1,700 | 5,284 | 95.6% | | 8 GB | 7,372 | 4,774 | 2,048 | 6,822 | 92.5% | | 16 GB | 14,745 | 11,000 | 3,072 | 14,072 | 95.4% | Not in those columns: render targets, shadows (about 300 MB), upscaler and frame generation images, streams, and the driver's own. The research reports found, from 393 player logs attached to bug reports (so biased toward trouble): on the 8 GB class (83 logs, 8,616 lines) 13.2% of the VRAM lines were past 97% of the allowance, and the driver's count was about 0.95 GB above the allocator's blocks (median; 2.0 GB at p90; 6,307 samples). Method: the research's `field_vram` and `field_gap` scripts over the downloaded logs. The ledger half, so nobody redoes it: #1339 (open, draft) adds `mem_account.h`, a registry of pools with their VRAM and RAM bytes, and one `vk: budget:` line with an `unaccounted` figure. On an RTX 3090 that figure fell from 426 MB to about 280 MB once every allocator buffer was counted. It counts only; its arbiter, which does change behaviour, is a separate commit. For the shared rule, the same PR adds a seventh predicate (`six_gb_card` in `mirror_budget.h`) and removes row 3's copy; rows 2 and 4 to 15 are untouched. Allocation sites, for what a ledger can still miss: outside `vk_vma.cpp` there are 73 in 15 files (grep count). Five are direct `vkAllocateMemory` calls: `vk_coopmat.cpp:135`, `vk_draw.cpp:4880`, `vk_memory.cpp:274, 520` and `vk_texture.cpp:4158`. The other 68 call `create_image`, `create_buffer`, `create_device_buffer`, `create_buffer_cached` or `alloc_sparse_block` (one of them, `vk_fsr4.cpp:337`, is a driver hook, not a site). The upscaler libraries allocate on our device and stay unaccounted. ## Proposed change 1. Add one classifier (for example `card_class(card, allowance, ram, integrated)`) and have rows 1 to 15 call it. Start with an enum that holds the six existing cut-offs, so no number moves. 2. Delete rows 3, 6 and 13 and the stale comments above. 3. Add the table test (below). Decide its bound with the owners; the table above is what main gives today. 4. Later, and separately: move or merge cut-offs one at a time, each with a run on a card of that size. ## How we would test it - Game-free, fails today: a check that lists every comparison of a card, allowance or heap against a GiB constant outside the one function. On main it lists the rows above. After step 1 it lists none. - Game-free: extend `tests/test_device_policy.py`, which already runs `device_policy()` on made-up PCs of 4, 6, 8 and 24 GB. Print the class each rule used for each card from 4 to 24 GB and the sum of the static budgets against the allowance. Fail when two rules disagree, and when the sum passes the chosen bound. - In the game, for step 1: on a 24 GB card with `RX_VK_TEST_VRAM_MB` and `RX_VK_TEST_ALLOWED_MB` set to 4, 6, 8, 12 and 16 GB, the log's `vk: policy:` lines are identical on main and on the branch. This proves no number moved; it makes no speed claim. - For any later cut-off change: paired timing on a real card of that size, main against branch, after a null main-against-main pair. None of this runs here yet; the 24 GB card cannot show a small card's effect. ## Related - #1339 (open, draft): the `vk: budget:` line and the arbiter. The forge shows it as not mergeable with main today. - Where cut-offs came from, by their titles: #637 (dynamic floor, target pool, DLSS CNN presets), #1096 (CNN preset under 7 GB), #1141 (hot-first mirrors on 4 to 6 GB cards), #735 and #237 (mirror budgets). All merged. - #1107 (merged): `RX_VK_TEST_VRAM_MB`, the switch the in-game check uses. - #1158 (open): VRAM held for nothing, with frame generation's images. #1493: the umbrella. New on this forge; not opened on GitHub.
Collaborator

Possibly related, for context:

  • PR #1057 WIP:perf(vk): dynamic texture floor and damped contraction for < 7 GB GPUs — Open work on VRAM heuristics gated by a single physical-VRAM threshold; related to policy consolidation, but addresses runtime behavior.
  • issue #939 Game: on a 6 GB card VRAM goes over the driver's allowance after a few area changes, Hyrule Field falls from 31 to 14 fps until a restart (GTX 1060, nightly-189) — Measured VRAM pressure and budget behavior on a 6 GB card; a symptom report, not the proposed classifier/refactor.
  • PR #637 perf(vk): optimize < 8 GB VRAM management, dynamic floor, 3-tier target pool, and DLSS CNN presets — Merged VRAM-management changes across low-VRAM tiers; related policies, not threshold inconsistency itself.
Possibly related, for context: - PR #1057 WIP:perf(vk): dynamic texture floor and damped contraction for < 7 GB GPUs — Open work on VRAM heuristics gated by a single physical-VRAM threshold; related to policy consolidation, but addresses runtime behavior. - issue #939 Game: on a 6 GB card VRAM goes over the driver's allowance after a few area changes, Hyrule Field falls from 31 to 14 fps until a restart (GTX 1060, nightly-189) — Measured VRAM pressure and budget behavior on a 6 GB card; a symptom report, not the proposed classifier/refactor. - PR #637 perf(vk): optimize < 8 GB VRAM management, dynamic floor, 3-tier target pool, and DLSS CNN presets — Merged VRAM-management changes across low-VRAM tiers; related policies, not threshold inconsistency itself.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot#1511
No description provided.