WIP: perf(vk): dead render targets are let go as they die, and a texture's end invalidates handles only when it must (RX_VK_RETIRE_LAZY=0 to disable) #2054
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2054
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-retire-lazy"
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
Between the eviction's passes the dead render targets were found by walking every rendered target each present
(
dead_targets_sweep), and under the budget by the pass over the whole cache every tenth present; and every texture'send raised the destroy generation, so every resolved handle of every thread was looked up again after each
retirement.
With this, the candidates are noted when one can first become dead: a texture whose GPU contents begin, or begin again
after a frame without a write (
texture_written,texture_rendered:retire_note_run), is looked up among thetextures the GPU wrote, kept in order of address, and it and the textures whose storage it overlaps are candidates.
Each present looks at the candidates alone, by the pass's own rules, and lets the dead ones go through the pass's own
end (
retire_chosen). The pass still runs over the budget as before, and under it every 600 presents for what this mayhave left (said in the log). A texture's end raises the destroy generation only when the texture was handed out in the
current generation. Main's pool and image reaper are untouched. The result expected: less CPU time a present for the
dead targets, and fewer handle lookups after a retirement.
The switch:
RX_VK_RETIRE_LAZY(new, a kill switch, bool, its row ingpu/vk/switches.def), on by default as thebranch shipped it, read once;
=0gives back main's code: the sweep, the pass everyRX_VK_DEAD_EVERYpresents and anew generation at every texture's end.
From bd3ea307 on
exp/x86-asm-sync, with 8e9cf4ac's test.Read first:
retire_note_run,retire_lazy,retire_chosenanddestroy_lateringpu/vk/vk_texture.cpp, thentests/test_target_overlap.pyandtests/test_target_image_reuse.py.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
4fb14183on main75317e1f. Build jobs of this PC's job queue, the checks in a hidden console:tests/run_all.py --strict --exactontests/test_dead_targets_sweep.py,tests/test_drawn_page_map.py,tests/test_readback_timeout_reuse.py,tests/test_readback_timeout_source.py,tests/test_target_image_pool.py,tests/test_target_image_reuse.py,tests/test_target_overlap.pyand every check--changedpicks for the files this changes (batchCapCut4-b1, logt-CapCut4-vk-retire-lazy.log): 89 checks, 75 passed, 14 failed, 0 skipped; its own checks pass, the switch's read included (fresh processes), andtests/test_target_retention.pywith them, but fortests/test_readback_timeout_source.py, which this change updates and which fails on main the same way before reaching its cases (its fixture has no stand-in forvkDestroyCommandPool: pre-existing); the failing ones fail on their base too, run from a base worktree (t-CapCut3-base-main.log(batchCapCut3-b1)):tests/test_crash_dialog.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_dev_ab.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_frame_overlap.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_linux_pressure.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_low_vram_texture_mips.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_pass_barrier.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_perf_report.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_present_queue_default.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_readback_timeout_source.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_staging_burst.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_target_reuse_memory.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_texel_buffer_ownership.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_ub_update_batch.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log),tests/test_vk_occlusion_queries.py(fails on main @75317e1ftoo, logt-CapCut3-base-main.log).It has NOT run in the game on this PC yet.
Still to test:
75317e1f, this branch withRX_VK_RETIRE_LAZY=0and this branch with it unset (on), each warmed up a minute in the scene first, interleaved (ABBA), at least two runs each, expecting the same picture (no stale or corrupted target), no FATAL or device lost, VRAM about the same, few textures in the 600-present sweep's line, and a median frame time unset lower than withRX_VK_RETIRE_LAZY=0and than main, andRX_VK_RETIRE_LAZY=0the same as main (by hand)75317e1f, this branch withRX_VK_RETIRE_LAZY=0and this branch with it unset (on), warmed up, ABBA, expecting no FATAL or device lost, the same picture and VRAM about the same, and a median frame time unset lower than withRX_VK_RETIRE_LAZY=0and than main, andRX_VK_RETIRE_LAZY=0the same as main (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest and Castle Town's market three minutes each: main @75317e1f, this branch with RX_VK_RETIRE_LAZY=0 and this branch with it unset (on), warmed up, ABBA, the log, frame times and a screenshot)python3 -I -B tests/test_dead_targets_sweep.py, expecting PASS (by hand)Measurements
Verdict: not measured: no micro-benchmark of this port and no run in the game on this PC yet; the in-game A/B is
in Still to test.
RX_VK_RETIRE_LAZYships on, as the branch shipped it; no measurement chose that default yet, the in-game A/B in Still to test does.Risks
What could break: a dead target never noted would hold its VRAM until the 600-present pass (more VRAM, more eviction
on a small card); a handle kept past its texture's end would draw a freed image (a corrupted texture or a device lost).
The candidates are judged by the pass's own rules, and a texture handed out since the last raise still waits for
RX_VK_DEAD_EVERY. The tests rundead_shiftedbeside the pass'sdrawn_over_shiftedon the same textures,texture_written's note,retire_chosenand the generation rule. Turn it off withRX_VK_RETIRE_LAZY=0. Renderercode: the runtime is rebuilt; nothing changes for players' saves, options or caches.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.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.Possibly related, for context:
@Beanstalk This adds RX_VK_RETIRE_LAZY, a kill switch on by default: dead render targets are let go as they die instead of in a later sweep (gpu/vk); RX_VK_RETIRE_LAZY=0 is main's way. It has not run in the game on these PCs yet. Please play Kokiri Forest, then Castle Town Market started from the market-entrance save, then Hyrule Field, two minutes each, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_RETIRE_LAZY=0, with a picture in each compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, device lost or FATAL line; peak VRAM about main's; unset, frame time p99 equal to main's or better and to the switch off.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.