WIP: fix(vk): a remap's write-back no longer puts an older target's texels over an image drawn inside it #941
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: needs approval
beanstalk: running
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
testing wanted
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!941
Loading…
Reference in a new issue
No description provided.
Delete branch "Amateurwizrd/Longshot:fix/writeback-nested-target"
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?
Type: fix · Risk: low · Tested on: Windows 11, RTX 5070 Ti 16 GB · Needs: Linux
Why
When the game remaps virtual pages, the renderer writes back every texture the GPU drew in that range, in the texture
cache's hash order. If an old render target is written after a newer image drawn inside its storage, the old target's
stale texels land over the newer image, the pages are marked written, and the newer image is then uploaded again from
that memory: it shows what was there before, not what was drawn. #323 fixed the same mistake for eviction's write-back
and noted this path; this PR closes it. See #323.
How to reproduce
Seen on: the game-free check below, Windows 11, RTX 5070 Ti, driver 621.01. In the game the path is reached (Hyrule Field under a 6,144 MB allowance: pages
0x11637ca000..0x1163896000remapped once a run with a GPU-drawn texture in them), but no wrong picture was seen thereSettings and switches:
RX_VK_TEST_ALLOWED_MB=6144for the in-game path; defaults otherwiseSteps: run
tests/test_remap_writeback_stale.pyagainst main'sgpu/vk/vk_texture.cpp: an old target and an image drawn inside it, listed in both orders, written back over shared stub memoryExpected: the memory holds the newest drawing's texels
Actual: it holds the older target's texels (inner image listed first), or the older image's (target redrawn, listed first)
What changed
A remap's write-back now skips a texture when another image was drawn into its storage since it was last drawn, the
same rule #323 uses for eviction, so both write-back paths treat the newest drawing as the owner of that memory.
texture_flush_to_guestingpu/vk/vk_texture.cppcomputesdrawn_others(todo)once, when there is anything towrite back, and skips each texture for which
evict_reason::write_back_stale(t->last_written, other[i])holds. Askipped texture keeps
gpu_writtenand its image, as one that cannot be written back does; a texture drawn in thesame frame as the other image is still written back, as in #323. Its log line counts the skipped ones:
"N not (another image drawn into their storage since)".
tests/test_remap_writeback_stale.py(new) cutstexture_flush_to_guestanddrawn_othersfrom the sourceunmodified and runs them over stub textures and guest memory, in both orders.
Measurements
Verdict: it passes: the new check fails on main @
13e8b6dain both runs and passes on this PR @366be509in both; inthe game the skip fires once a run on the remap it is for, with the HUD clean on both sides.
Hardware: Windows 11 Pro 26200, RTX 5070 Ti 16 GB, driver 621.01, Ryzen 7 7800X3D, 32 GB
Scene: the game-free check; and Hyrule Field (child) by debug teleport, standing 25 s then 5 s in the pause menu,
RX_VK_TEST_ALLOWED_MB=6144Method: the check run 2 times on each side, interleaved, main with this PR's test file copied in. In the game, 3 rounds alternating main and a build of main with this PR and two other open eviction fixes (#943, #944), each a copy of one game folder updated with
make_game.py --updateHow to reproduce:
python -I -B tests/run_all.py remap_writeback_staleon this branch and on main with the test copied in; in the game, the scene above and theremapped:log lines13e8b6da366be509tests/test_remap_writeback_stale.py(run 1 / run 2)Flags and settings
None
Testing
Tested: on Windows 11 with the pinned llvm-mingw, the 38 checks that read this diff, one at a time, on this PR @
366be509(main @13e8b6da): all pass. In the game, the runs above: no device loss, the HUD clean.Not tested: a picture where the stale write-back showed wrong texels (none found in the scenes tried); the cost of
drawn_others, which walks the texture list once per remap with something to write back (0.1-0.2 ms in the log lineabove).
Must be tested:
gpu/vk/vk_texture.cppRisks
What could break: a texture skipped here keeps its texels only in VRAM; the skip covers its whole storage, so its
texels outside the newer image are not written back either, as #323 does for eviction.
Turning it off: revert the commit.
Compatibility: Nothing changes.
Issues
See #323
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.@Beanstalk linux, build the renderer at this head: it should build with no error in the files this PR changes; no change in play expected from the build alone.
@Amateurwizrd only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it.Tested in game: Windows 11, RTX 5070 Ti 16 GB, driver 621.01, Hyrule Field (child) by debug teleport, 25 s standing and 5 s in the pause menu at RX_VK_TEST_ALLOWED_MB=6144, 3 rounds alternating main @
13e8b6daand a build of main with #941, #943 and #944 together. No device loss, the HUD clean on both sides; #941's skip fired once a run on the same remap. Not run in the game alone at this head.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.