Repository navigation
Vulkan: opt-in memory priorities so unused textures leave VRAM first (RX_VK_MEMORY_PRIORITY=1) - #1132
wrocketdev wants to merge 1 commit into
Conversation
5ff45ed to
e2ec9b8
Compare
|
Rebased onto current main (d224dc0) and force-pushed: no conflicts now, still a single commit. Two things changed with the rebase:
Still opt-in ( |
Joey-Magnus
left a comment
There was a problem hiding this comment.
Two things for the rebase. The branch conflicts with main in gpu/vk/vk_texture.cpp.
- Main's gpu/vk/vk_vma.cpp now has a third image pool, textures_pool(), with a VmaAllocationCreateInfo and a VmaPoolCreateInfo at about lines 122 and 127. Both need
priority = memory_priority::kNormal. Without it, once the extension is on, every texture in that pool is created at priority 0, the lowest. That is the opposite of what this PR is for. It would help if test_memory_priority.py counted the create-infos in vk_vma.cpp, so that a new one can't slip through without a priority. - memory_priority::wanted reads RX_VK_MEMORY_PRIORITY with atoi, and RX_VK_LOG_PRIORITY turns on for any value, including 0. Since #2042, switches use env_on and env_value_off from gpu/vk/compat/hookshot_env.h, so that
=onand=truework and=0means off.
CI has never run on this branch. test_memory_priority.py passes locally on e2ec9b8.
|
Tested this on a 6 GB card, as you asked for. Short version: the extensions work here, but on this card the idle demotion never reaches a texture, and I could not show that the switch helps. What the runs did show is a slow state that comes and goes with the texture cache staying far over its budget, with and without the switch. Details below. Setup
MethodScripted runs, no hands on the pad: a fresh copy of the same save every run (autosave at the Castle Town gate), input through
Resultsfps is the mean of the log's Route 1 (town only), whole route:
Route 2 (area changes), the last 60 s in town. The last column is from the final
So with the switch on all three runs ended slow, and with it off three of four ended fast. But C2 is the patched build with the switch off and it ended just as slow as B1, so I cannot say the switch causes it. In Route 1 it was the other way round (B a little ahead, A2 slow). With this few runs I would call the switch's effect on fps unproven in either direction. What the logs and the code say
What I would try
I am going to look at why the cache stays over its budget, try the first point here, and run the same two routes again. I will post the numbers and the diff. |
…first
When the process holds more VRAM than the driver allows, the driver pages part of it to system memory with no
hint of what matters. With RX_VK_MEMORY_PRIORITY=1, VK_EXT_memory_priority makes every allocation at the default
(0.5), and with VK_EXT_pageable_device_local_memory a texture with memory of its own (a dedicated allocation, or a
sparse image's chunks) that goes unused for 600 presents drops to 0.1 until it is used again: a course left behind,
an area's terrain arrays, rather than what the scene draws.
VMA passes a create-info's priority as given once VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT is set, and a
create-info left at {} has 0, the lowest: every VmaAllocationCreateInfo and VmaPoolCreateInfo now sets 0.5, and
tests/test_memory_priority.py fails on one that does not.
Opt-in until players on 6-8 GB cards confirm it helps (issues 993, 995): not tried in game yet.
RX_VK_PRIORITY_IDLE=<presents> sets the delay (0: never).
Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e2ec9b8 to
c7cd90c
Compare
|
Thanks, both fixed in c7cd90c (rebased onto 3189a42). |
|
Thank you, this is exactly the run it needed. You're right about point 3: on main every texture goes into pool blocks ( The fix I have in mind works per block. With the textures in their own pool (the default; not with |
Draft, not tried in game. It is opt-in (
RX_VK_MEMORY_PRIORITY=1), so nothing changes unless a player turns it on.I am looking for players on 6-8 GB cards (#993, #995) to try it before it goes further.
Problem
On 8 GB cards the process sits at the driver's VRAM limit in Hyrule Field, Castle Town and Kakariko (#993, #995):
the logs show
VRAM: ... used of ... allowedover the allowance. The driver then pages VRAM to system memory, andnothing tells it which allocations matter: a terrain array of an area left behind and the textures the scene draws
are the same to it.
Change
Everything below is behind
RX_VK_MEMORY_PRIORITY=1. Unset, the device is created with the same extensions asbefore, and the renderer behaves as it does now.
vk_main.cpp: asks forVK_EXT_memory_priorityand, with it,VK_EXT_pageable_device_local_memory, each onlywith its feature. One log line says which:
vk: memory priorities: on, pageable device-local memory ...,on, without pageable device-local memory ...,not supported, oroff (RX_VK_MEMORY_PRIORITY=1: on).vk_vma.cpp:VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT. EveryVmaAllocationCreateInfoand both imagepools'
VmaPoolCreateInfo(the textures' and, since vk: render targets' images in VMA blocks of their own; dead targets swept every 10 presents (follow-up to #1416) #1436, the render targets') now setpriority = 0.5. With that flag on, VMA passes the create-info's value asgiven, and a create-info left at
{}is 0, the lowest: without this, every dedicated allocation and both imagepools would be the first paged out. (The field is ignored while the flag is off.)
set_allocation_priority()changes a dedicated allocation's priority, never a shared block's.
vk_texture.cpp:texture_priorities(), every 60 presents when the pageable extension is on. A texture unused forRX_VK_PRIORITY_IDLEpresents (600, about 10 s) drops to 0.1, and goes back to 0.5 once used. Only memory atexture owns changes: dedicated allocations (the big ones, past the 128 MB image blocks) and sparse chunks.
Textures inside pool blocks keep the block's 0.5. Every 600 presents it logs
vk: memory priority: N textures (X MB) at the idle priority.memory_priority.h: the rule and the switches, tested without a GPU bytests/test_memory_priority.py. The testalso fails if a VMA create-info is added later without a priority.
gpu/vk/VULKAN.md.Testing
tests/test_memory_priority.py(C++ rule test plus source checks). The three changed renderer filespass a syntax-only compile against the pinned Vulkan-Headers v1.4.345 and VMA v3.3.0.
How to try it: add
RX_VK_MEMORY_PRIORITY=1tohookshot_env.txt, play the same route with and without it (forexample Kokiri Forest → Hyrule Field → Kakariko → Castle Town market and back), and compare the fps, the worst freezes,
and these lines of
hookshot_log.txt:vk: memory priorities:,vk: memory priority:andVRAM: ... used of ... allowed.Windows already pages video memory on its own, so the gain there may be small. It is aimed at the stalls when VRAM is
full, not at the garbled textures of #993.
Not in this PR
one line (
pi.priorityintarget_images_pool()); left at 0.5 here to keep this PR to the mechanism.Related: #993, #995.
Written with AI assistance (Claude Opus 5.5); the commit carries the
Assisted-by:andCo-Authored-By:trailers.🤖 Generated with Claude Code