graphics: enable VK_EXT_memory_priority + pageable_device_local_memory #301

Closed
github-bot wants to merge 1 commit from gh-pr/301/head into gh-pr/301/base
Owner

@⁠Hyphaed on GitHub · 2026-08-20 14:03 UTC · original
Hyphaed:gb/memory-priority → main · +80 −1 · 3 files · 1 commits · closed without merging

I was reading through the texture cache while working on something related and noticed the renderer already queries VK_EXT_memory_budget and scales its GC bands off the real reported budget. That's more care than most projects take. But once memory actually gets tight, the only lever available is RunGarbageCollector() deleting resources. The driver itself has no idea which of your allocations are worth keeping, so to it everything looks equally disposable.

That's the gap this fills.

VK_EXT_memory_priority lets you tag each allocation 0.0 to 1.0 so the driver knows what to push out first. VK_EXT_pageable_device_local_memory is what lets it actually page device-local memory out instead of just returning VK_ERROR_OUT_OF_DEVICE_MEMORY. Together they give you a cheaper step before the GC has to run: the driver quietly demotes something, rather than you destroying a resource and rebuilding it a few frames later.

It doesn't replace the GC. It takes pressure off it.

Why it's written this way

Both extensions go on together or not at all. Priority on its own only changes which allocation gets the OOM, which isn't much use.

pageableDeviceLocalMemory is a feature bit, not just an extension, so it goes through getFeatures2() and is only requested if the driver actually reports it. Enabling the extension without the feature is invalid usage. If a driver has neither, the pNext chain it sees is exactly what it saw before this patch.

VMA needs VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT or it ignores VmaAllocationCreateInfo::priority entirely, so the priorities would be dead code without it. Easy one to miss.

Only images get bumped (0.8, against VMA's 0.5 default). I went back and forth on buffers and left them alone on purpose. A render target that gets demoted has to be paged back in before the next pass samples it, whereas most buffer content you can re-upload from guest memory you're still holding anyway. But CreateBuffer() is the generic path, it also hands out vertex and index buffers that might be every bit as hot, and guessing wrong there costs performance with nothing in the log to show for it. Splitting staging and tiler scratch out and giving those a low priority looks right to me, but I'd want to measure it before claiming so.

On testing

Both changed translation units compile, and page_manager_tests passes.

I initially tried to build with GCC and hit vk::Extent3D brace-init ambiguity in files I hadn't touched, which had me chasing the wrong thing for a while. Then I actually read .github/workflows/build.yml and saw you build with clang on all three platforms, so GCC was never going to be a meaningful signal. Rebuilt with clang, which is clean.

So: verified under clang, matching CI. I haven't measured a frame-time difference and I'm not claiming one, this is about giving the driver information it didn't have rather than a specific speedup.

Where this came from

Since it's a first PR from me: I work on a Vulkan layer that oversubscribes VRAM by tiering into host DDR and NVMe behind an inflated heap, and both of these extensions carry real weight there under pressure. Your budget-derived GC bands with the in-loop backoff are a better shape than what I had, so I've been borrowing in the other direction. The priority hint seemed like the obvious thing missing next to them.

Happy to resize or split this if you'd rather have it smaller.

**@⁠Hyphaed** on GitHub · 2026-08-20 14:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/301) `Hyphaed:gb/memory-priority` → `main` · +80 −1 · 3 files · 1 commits · closed without merging I was reading through the texture cache while working on something related and noticed the renderer already queries `VK_EXT_memory_budget` and scales its GC bands off the real reported budget. That's more care than most projects take. But once memory actually gets tight, the only lever available is `RunGarbageCollector()` deleting resources. The driver itself has no idea which of your allocations are worth keeping, so to it everything looks equally disposable. That's the gap this fills. `VK_EXT_memory_priority` lets you tag each allocation 0.0 to 1.0 so the driver knows what to push out first. `VK_EXT_pageable_device_local_memory` is what lets it actually page device-local memory out instead of just returning `VK_ERROR_OUT_OF_DEVICE_MEMORY`. Together they give you a cheaper step *before* the GC has to run: the driver quietly demotes something, rather than you destroying a resource and rebuilding it a few frames later. It doesn't replace the GC. It takes pressure off it. ### Why it's written this way **Both extensions go on together or not at all.** Priority on its own only changes which allocation gets the OOM, which isn't much use. **`pageableDeviceLocalMemory` is a feature bit, not just an extension**, so it goes through `getFeatures2()` and is only requested if the driver actually reports it. Enabling the extension without the feature is invalid usage. If a driver has neither, the `pNext` chain it sees is exactly what it saw before this patch. **VMA needs `VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT`** or it ignores `VmaAllocationCreateInfo::priority` entirely, so the priorities would be dead code without it. Easy one to miss. **Only images get bumped** (0.8, against VMA's 0.5 default). I went back and forth on buffers and left them alone on purpose. A render target that gets demoted has to be paged back in before the next pass samples it, whereas most buffer content you can re-upload from guest memory you're still holding anyway. But `CreateBuffer()` is the generic path, it also hands out vertex and index buffers that might be every bit as hot, and guessing wrong there costs performance with nothing in the log to show for it. Splitting staging and tiler scratch out and giving those a low priority looks right to me, but I'd want to measure it before claiming so. ### On testing Both changed translation units compile, and `page_manager_tests` passes. I initially tried to build with GCC and hit `vk::Extent3D` brace-init ambiguity in files I hadn't touched, which had me chasing the wrong thing for a while. Then I actually read `.github/workflows/build.yml` and saw you build with clang on all three platforms, so GCC was never going to be a meaningful signal. Rebuilt with clang, which is clean. So: verified under clang, matching CI. I haven't measured a frame-time difference and I'm not claiming one, this is about giving the driver information it didn't have rather than a specific speedup. ### Where this came from Since it's a first PR from me: I work on a Vulkan layer that oversubscribes VRAM by tiering into host DDR and NVMe behind an inflated heap, and both of these extensions carry real weight there under pressure. Your budget-derived GC bands with the in-loop backoff are a better shape than what I had, so I've been borrowing in the other direction. The priority hint seemed like the obvious thing missing next to them. Happy to resize or split this if you'd rather have it smaller.
The renderer already reads VK_EXT_memory_budget to size its GC bands
(TextureCache's trigger/pressure/critical thresholds are derived from
GetTotalMemoryBudget()), but never tells the driver which allocations are
worth keeping when that budget gets tight. Without a priority hint every
allocation looks equally disposable, so the only lever under pressure is
RunGarbageCollector() destroying resources that then have to be recreated.

Enable the two extensions that give the driver a cheaper option:

  * VK_EXT_memory_priority             - per-allocation 0.0..1.0 hint
  * VK_EXT_pageable_device_local_memory - lets the driver actually page
                                          device-local memory out instead of
                                          failing the allocation

They are enabled as a pair and only when both are advertised, because
priority without pageable memory just changes which allocation gets an
OOM. pageableDeviceLocalMemory is a feature bit, so it is queried through
getFeatures2() and only requested when the driver reports it; drivers
without the extensions see exactly the pNext chain they saw before.

On the VMA side this needs VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT,
without which VmaAllocationCreateInfo::priority is silently ignored.

Only images are given a raised priority (0.8 against VMA's 0.5 default).
A demoted render target has to be paged back in before the next pass that
samples it, while most buffer content can be re-uploaded from guest memory
the emulator still holds. The generic CreateBuffer() path also serves
vertex/index buffers that may be just as hot, so lowering it wholesale
would be a guess. Finer classification (staging, tiler scratch) is a
follow-up for whoever measures it.

This composes with the existing GC rather than replacing it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:16:06 +00:00
github-bot closed this pull request 2026-11-26 09:16:06 +00:00
Author
Owner

@⁠Hyphaed on GitHub · 2026-08-20 14:24 UTC · original

Closing this in favour of a single consolidated PR. I got the build diagnosis wrong here (blamed header shadowing when the real answer is that this project builds with clang, not GCC), and rather than leave a correction sitting on top of a wrong claim I'd rather resubmit cleanly with the full set of changes and a proper verification story. Sorry for the noise.

**@⁠Hyphaed** on GitHub · 2026-08-20 14:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/301#issuecomment-5357226637) Closing this in favour of a single consolidated PR. I got the build diagnosis wrong here (blamed header shadowing when the real answer is that this project builds with clang, not GCC), and rather than leave a correction sitting on top of a wrong claim I'd rather resubmit cleanly with the full set of changes and a proper verification story. Sorry for the noise.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.