WIP: fix(vk): hold the texture a present shows until the window has copied it #2064
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2064
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:fix/vk-present-source-held"
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
The renderer could let go of the texture a present shows before the window had copied it.
do_presentpicks thepresent's source (
texture_for_present), thentexture_frameruns (the eviction pass, the dead render targets' sweep,the retirement of images that served a new texture, the VRAM compaction), and only then does
present_imagecopy thesource to the window. That copy is known to be done only when its frame slot's fence is waited, up to
kPresentSlotsMax(8) presents later. On main only the compaction leaves the source alone, and only the currentpresent's (
present_source). A source picked bytexture_for_present's fallback (a texture rendered at the presentedstorage in another description) keeps its old last use, since a plain blit does not count as one; when another render
target has drawn over its storage, the sweep lets it go at the next present: its Texture erased, its image to the pool or
destroyed while the window may still copy it. A present of nothing and a dropped output (a held present after its
generation's release) left
present_sourcenaming the texture shown before.With this,
texture_for_presentmarks the texture it picks (Texture::presented): its own, the fallback, and theOutput preview's texture. The eviction pass (and its first pass for the compaction's hold, which counts what the dead
targets give back), the sweep, the retirement and the compaction leave a texture a present showed in the last
dead_targets::kPresentHold(9) presents, one more than the frame slots (astatic_assert). A present of nothing and adropped output go through
texture_for_present(nullptr): no source.The result expected: nothing a player sees in normal play, where the shown texture is the game's own output, drawn every
frame and never a candidate to go; the window no longer copies from an image that may have been pooled or destroyed when
a stale fallback is shown.
Split from #1996, as dyst asked in its review (#1996 (comment)):
the hold fixes a lifetime gap that is on main and does not depend on #1996's grace; the rebase onto main's Output preview
and dropped output (dyst's #1996 (comment)) and the
compaction's two passes in step with the hold are from that review.
Read first:
present_heldingpu/vk/dead_targets.h,texture_for_presentingpu/vk/vk_texture.cpp, the sourceline in
do_present(gpu/vk/vk_replay.cpp), thentests/test_present_source_held.py.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
a9d04a2eon main9dd41326, lightjobs of this PC's job queue (
dy1996a,dy1996b), each check in a hidden console,RX_CPMset (the Vulkan headersfound). At the test commit
e016aef5(main's code):tests/test_present_source_held.pyfails in all four cases (thefallback source and the Output preview's texture let go at the next present,
present_sourcenot cleared for a droppedoutput,
kPresentHoldmissing),tests/test_target_retention.pyfails cases 3 and 4 (the shown texture evicted; thehold's pass counting it as given back) and
tests/test_vram_compact.pyfails (the compaction's exclusion). At the headtests/run_all.py --strict --exactovertests/test_present_source_held.py,tests/test_target_retention.py,tests/test_vram_compact.py,tests/test_dead_targets_sweep.py,tests/test_blocks_at_start.py,tests/test_image_reaper.py,tests/test_target_image_pool.py,tests/test_drawn_page_map.pyandtests/test_present_source_crop.py: 8 pass;tests/test_present_source_crop.pyfails here and on main's renderer(
dy1996b, ate016aef5) with the same error, its fixture'shud_sourcestand-in a parameter short. The held test alsopasses with
--cxx clang++.gpu/vk/vk_texture.cppandgpu/vk/vk_replay.cppcompiled (syntax) with the game build'sown commands.
It has NOT run in the game on this PC yet.
Still to test:
9dd41326against this branch, same save and settings, then a still screenshot at an input-free point on each side andmain against itself, expecting the same picture, no FATAL or device lost (by hand)
lost (on the Test Farm, or by hand)
and no device lost (by hand)
python3 -I -B tests/test_present_source_held.py, expecting PASS (by hand)Measurements
Nothing to measure: a lifetime fix with no switch; a shown texture stays at most 9 presents longer (one texture's memory).
Risks
What could break: a texture the present showed stays up to 9 presents after it was last shown (its VRAM, one texture's,
for that long), and the eviction, the sweep, the retirement and the compaction pass it over meanwhile; a write-back such
an eviction would have done comes as late. No switch: a revert is enough. Nothing changes for players' saves, options
or caches. Overlap: #2054 (also siantm's) adds a lazy retirement path that checks
present_source; whichever of the twolands second adds
dead_targets::present_heldto it.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
mainand passes here.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.@Beanstalk This fixes which image the renderer presents from and keeps it held: the present source in gpu/vk/vk_texture.cpp (texture_for_present), the dead-target sweep, eviction, retirement and compaction. No switch: a revert gives back main's code. Please take each picture at a fixed point with no input: right after the start save loads and settles, before any stick input; and take one main-against-itself picture on the same PC too, so the noise level shows. Then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each with the camera turning, and open the Output resolution preview from the menu once; the PR against main on the same PC, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture as main within main's own noise, no crash, device lost or FATAL line; frame time p99 and peak VRAM equal to main's or better, within the run-to-run spread.
@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
Checkout
From your project repository, check out a new branch and test the changes.