Skip to content

fix(kyty): refresh VRAM GC thresholds from driver budget and trim recycled images - #345

Merged
simnJS merged 2 commits into
simnJS:AnyKytyfrom
slopgobblercobbler:fix/kyty-vram-budget
Nov 27, 2026
Merged

simnJS merged 2 commits into
simnJS:AnyKytyfrom
slopgobblercobbler:fix/kyty-vram-budget

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

  • Refresh TextureCache and BufferCache GC memory thresholds (m_trigger_gc_memory, m_pressure_gc_memory, m_critical_gc_memory) in RunGarbageCollector() whenever GraphicContext::GetTotalMemoryBudget() changes, so shrinking VK_EXT_memory_budget budgets on Windows/NVIDIA are respected at runtime.
  • Add GraphicContext::TrimRecycledImages() (�ma.cpp) and call it from TextureCache::RunGarbageCollector() when m_total_used_memory >= m_pressure_gc_memory so freed recyclable VkImage allocations are released back to VMA/driver under pressure.
  • Fix TextureCache::RunGarbageCollector() pressure/critical age thresholds (16 -> 8 -> 2 instead of 16 -> 80 -> 160) so higher memory pressure evicts older unused textures instead of skipping them.
  • Add kyty_shim_vram_budget unit test verifying dynamic threshold scaling, critical-pressure eviction, and TrimRecycledImages().

Tested

  • Windows 10/11, NVIDIA GeForce RTX 3070:
    • ctest --test-dir build -R "vram_budget|buffer_cache_pages|image_write_back_alias" --output-on-failure: 3/3 passed (kyty_shim_image_write_back_alias, kyty_shim_buffer_cache_pages, kyty_shim_vram_budget).
    • Vulkan validation gate (ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer): Insert instance layer "VK_LAYER_KHRONOS_validation" confirmed, 0 missing layers, 0 new VUID- errors vs baseline.
    • python tools/check_conventions.py --base origin/AnyKyty and python tools/check_kyty_settings.py: passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Part 1 of kyty: device memory cap does not bound VRAM on NVIDIA/Windows; heap-pinned textures are never freed #315
  • Unblocks: Windows VRAM pressure eviction for Brainrot (PPSA38500) and other titles
  • GPUs tested: NVIDIA GeForce RTX 3070 (Windows, VK_LAYER_KHRONOS_validation 0 new VUID errors)
  • AI-assisted: yes

@github-actions

Copy link
Copy Markdown

The new test checks the threshold formulas by calling UpdateMemoryThresholds() directly, but it would still pass if either RunGarbageCollector() stopped refreshing thresholds. Please add a deterministic budget override, change the reported budget after constructing the caches, and verify that a GC pass updates both caches without calling the threshold setters from the test.

The critical-pressure check also depends on the host budget: if memory reporting is enabled and the reported budget differs from the 6 GiB set by the scaling check, the first GC pass can overwrite the forced zero thresholds. Control the reported budget and usage so the test reliably enters the critical path.

Finally, calling TrimRecycledImages() without checking the recycle pool only exercises the call. Please seed the pool with a known recycled image and assert that the pressure GC pass drains it; otherwise removing the GC call or making trimming a no-op would go undetected.

@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Updated in da0a7be16e:

  • Added deterministic host VRAM budget and usage overrides in BufferCache and TextureCache so vram_budget_gc_test verifies that RunGarbageCollector() refreshes thresholds on both caches without calling UpdateMemoryThresholds() directly from the test, and reliably exercises the critical-pressure path.
  • Seeded the TextureCache recycle pool and asserted that RunGarbageCollector() trims it under pressure.
  • Fixed the Linux asan heap-use-after-free/unmapped access by checking GuestRange::Valid() before reading the recycled image descriptor range.

@github-actions

Copy link
Copy Markdown

The updated test now checks that both caches refresh their thresholds through the GC entry points, drives critical pressure deterministically, and asserts that GC drains the recycle pool.

One verification gap remains: the guest-range check can skip the entire test under Linux ASan. The check avoids the invalid access, but a skip does not verify the GC paths under ASan. Please confirm that kyty_shim_vram_budget reaches its ok marker on Linux ASan rather than returning 77. If the ASan runner cannot provide a valid guest mapping, please split the budget-refresh and recycle-pool checks from the guest-backed eviction check so they still run.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration separates budget refresh and pool trimming from guest-backed eviction. The budget test passed under Linux ASan, and both tests passed on lavapipe. The Linux, Windows, sanitizer, and offline checks passed on the exact integration commit.

@simnJS
simnJS merged commit f56820a into simnJS:AnyKyty Nov 27, 2026
4 checks passed
@polynux polynux mentioned this pull request Nov 27, 2026
2 of 3 tasks

This branch was previously deployed

1 inactive deployment
repository-maintenance — da0a7be1 Deployed Nov 26, 2026 by slopgobblercobbler via review #93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants