WIP: perf(vk): the textures' pools keep spare blocks made off the render thread, so an area's first frames make none #2890
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2890
Loading…
Reference in a new issue
No description provided.
Delete branch "(deleted):perf/texture-block-reserve"
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?
Summary
An area's first frames made new 32 MB VRAM blocks for its textures on the render thread: a synchronous
vkAllocateMemory, about 5.7 ms each on AMD's Windows driver (2-34 ms). The textures' pool grew from 24 to 149 blocks over a six-area tour, about 20 blocks per arrival. The images that made a block took 669 of the tour's 737 ms of texture creation.Part of it is a regression: #637 (
8e3dfde6) shrankkImageBlockfrom 128 MB to 32 MB but keptblocks_at_start's count of 2-24. So the blocks made at the start fell from about 3 GB to 768 MB on a 16 GB card.This PR:
vkAllocateMemoryin the frame.RX_VK_TEXTURE_BLOCK_RESERVE=<n>(0: none, as before);RX_VK_IMAGE_PREALLOCas before.Read first:
gpu/vk/texture_block_reserve.h, the reserve section ofgpu/vk/vk_vma.cpp,gpu/vk/vram_compact.h(blocks_at_start).How to see it on main:
RX_VK_LOG_MADE_BURST=50, teleport to Market (child). The images that make a block take 5-34 ms each, the rest 0.01-0.1 ms, andvk: image blocks (textures, compacted)climbs from 24 blocks.Testing
Tested: Windows 11, AMD Radeon RX 6800, driver 26.10.1, a pack over main
28cb22b9, the tour in Measurements. No visual differences seen in the tour's areas.218 taken, 254 made ahead, 57 made in the frame anyway: 14 render targets (they have their own pool), 12 sampled textures larger than a block, and the rest held back by the 100 ms refill rule, since changed.Checks:
tests/test_texture_block_reserve.py(new): the rules, and the reserve thread run against a stand-in VMA that followsVmaBlockVector::Free's empty-block rule.test_blocks_at_start.py(its fixture fixed; it fails on main),test_device_policy.py,test_memory_priority.pyandtest_mem_account.pypass.clang++ -fsyntax-onlywith the builder's flags onvk_vma.cpp,vk_texture.cppandvk_main.cpp.Still to test:
vk: image blockslines and frame times with main).Measurements
Verdict: each change does the work it targets (below), but on its own none moves total stutter at area changes beyond run-to-run noise. Together with its two sibling PRs, the worst frame at an arrival is 15-25% shorter. An earlier claim here of "-20% stutter in the loads" was mostly how long each load took: the loads' length alone varies from 3,300 to 4,900 frames between runs of the same build.
Setup:
kokiri-start, then teleports to Market (child), Hyrule Field (child), Kakariko Village, Kokiri Forest, Hyrule Field (adult) and Lake Hylia (adult). 25 s in each with the camera turning, plus 20 s walking in circles in Hyrule Field.RX_VK_FRAME_TRACE=1).28cb22b9(5)In play (the walk and the camera turns, outside the arrivals), every run of every build has a median frame of 9.8-10.0 ms and 0-1 frames of 33 ms or more.
What the worst arrival frames are spent on, in the runs with all three: draw 100-440 ms, mostly in the recording's commands (up to 396 ms: the first bindings of vertex and index buffers, which import host memory and make mirrors) and descriptors. A change that imports pools ahead of their first binding is being measured on top of these three.
Risks
VK_ERROR_OUT_OF_DEVICE_MEMORYshortly after arriving in Market (7.8 of 15.5 GB of VRAM in use), and the game stopped drawing. It has not come back in nine runs since, and no run of main or the nightly (about 20) has refused a submit. Until it is explained, treat this PR as a possible cause.RX_VK_TEXTURE_BLOCK_RESERVE=0withRX_VK_IMAGE_PREALLOC=24gives main's behaviour; otherwise a revert. Nothing changes in saves, settings or caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (Not run yet: the checks reading the changed files pass, apart from failures they share with main.)main, or Measurements says why there is nothing to measure. (Measured: no stutter gain on its own beyond the noise.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. (Rows added; defaults to be confirmed by this PR's own A/B.)tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11, AMD Radeon RX 6800, driver 26.10.1, i7-13700: a pack over main
28cb22b9with the texture block reserve, shader parse cache and sparse bind PRs together, six teleport tours through Market, Hyrule Field (child and adult), Kakariko, Kokiri Forest and Lake Hylia with the player's settings; no visual differences, loads stutter about 20% less, frame rate in play unchanged. One run (the first after the build) froze with refused submits (VK_ERROR_OUT_OF_DEVICE_MEMORY), not seen again in nine runs: under investigation, see Risks.Possibly related, for context:
Measurements corrected: each change built alone over main (two runs each), against five runs of main. The earlier '-20% stutter in the loads' was mostly load length varying between runs. On its own this change does not move visible stutter at arrivals beyond the noise; with its two siblings the worst arrival frame is 15-25% shorter. Staying WIP while the next change (imports made ahead of their first binding) is measured on top.
Closing as not significant: the stutter a player sees at an area change is not measurably lower with this change, alone or together with its siblings (#2890, #2891, #2892) and three further fixes. Each does the work it targets; the frames that stutter just move to other work.
Setup: Windows 11, RX 6800, driver 26.10.1, the player's settings, uncapped. A six-teleport tour, each run a separate launch in timing mode. Visible stutter is what frames of 25 ms or more spend over 16.7 ms, from 1 s before control returns to 2 s after, summed over the six arrivals.
28cb22b9(8 runs)What did show:
What holds an arrival frame now, from symbolized samples: host-memory imports of the game's re-created area pools (39% of the replay thread), and mirrors rebuilt after the loading screen (~16%). The first frame of an area pays for whatever is first used in it; moving one cost earlier did not shorten that frame overall.
The branches stay on conongnang's fork in case someone picks this up.
🤖 Generated with Claude Code
Pull request closed