WIP: fix(vk): a render target is not uploaded from memory for a GPU buffer write older than its drawing #332
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!332
Loading…
Reference in a new issue
No description provided.
Delete branch "Amateurwizrd/Longshot:fix/drawn-target-upload"
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 · Needs: an AMD or Intel GPU, or Linux
Why
The first time the game samples a render target after finalizing it, the renderer asks what changed in the target's storage since. When a GPU buffer wrote that storage, it uploads the whole image from guest memory over what the pass drew. That buffer write was compared only with the last one the texture had seen, never with the drawing, so a target made over a buffer's old storage counted the older write as newer. In Hyrule Field on current
mainthat is 4 or 5 whole uploads of 1920x1080 targets a run in the two minutes after loading.mainalready fixes the other cause of the same uploads, a virtual-pool target drawn before it had a page map (#325, the port of Hookshot's 40955ed3). This PR started as our own version of that change and is now only the part #325 does not cover.How to reproduce
Seen on: Windows 11, RTX 5070 Ti 16 GB, driver 621.01
Settings and switches: Output resolution 2560x1440, Render resolution 75%, otherwise defaults
Steps: load a save, teleport to Hyrule Field (Debug tab), stand for 25 s, open and close the pause menu
Expected: no
upload over a drawn image ... a GPU buffer wrote itlines in the logActual: on main, 4 or 5 of them a run, each a whole 1920x1080 target uploaded from guest memory over what the pass drew (8.4 MB, up to 34 ms)
What changed
A render target the GPU just drew is no longer overwritten from guest memory because of a GPU buffer write into its storage that happened before the drawing. The fix is one comparison in
texture_rendered, with a switch to turn it off for A/B runs.texture_rendered(gpu/vk/vk_texture.cpp), which only a pass calls, now takes GPU buffer writes into the target's storage from earlier submissions as older than the drawing (gpu_wrote_seen), once a frame under the pass's lock. A write in the pass's own submission still counts, since which came first is not known there.tests/test_drawn_target.pycutstexture_written,texture_rendered,texture_released,texture_dirty,texture_gpu_wrote,gpu_wrote_intoand the check intexture_touchout of the source and checks the buffer-write cases with the switch off and on. Onmainits first case fails.docs/development.md, and the two measured builds as run files indocs/tested/.texture_rendered; it costs one compare and store per target per frame.texture_renderedis called only bybegin_pass, under theParLockthattexture_markeddecides, so the store needs no lock of its own.Measurements
Verdict: it works on current main: whole uploads for an older buffer write go from 5, 5, 5 a run on main @
13e8b6dato 0, 0, 0 on this PR @b58993c4, three alternating rounds. Frame rate not measured in this set (the earlier set below claimed no change either way).Hardware: Windows 11 Pro 26200, NVIDIA GeForce RTX 5070 Ti 16 GB, driver 621.01, AMD Ryzen 7 7800X3D, 32 GB
Scene: Hyrule Field (child) by debug teleport from a copied save, standing; the options file as it was for the earlier set (Output 2560x1440 in a 1707x960 window, Render 75%, no frame generation, no frame cap, sound off)
Method: two game folders built the same way from one copy (
game_m332from main @13e8b6da,game_p332from this PR @b58993c4, eachmake_game.py --update); 3 rounds, the first build alternating each round (main, PR / PR, main / main, PR). Each run: teleport, 25 s standing, 5 s in the pause menu. Counts arevk: upload over a drawn imagelines: "for a buffer write" are those endinga GPU buffer wrote it, each a whole image.How to reproduce: load a save, teleport to Hyrule Field (Debug tab), stand for 25 s, open and close the pause menu, and count the
upload over a drawn image ... a GPU buffer wrote itlines in the log.13e8b6dab58993c4The earlier set, on main @
98e2d95fbefore the rebases, with frame rate:main:
98e2d95f(2026-11-14)this PR: fix/drawn-target-upload @
de3b4aabHardware: NVIDIA GeForce RTX 5070 Ti 16 GB, driver 621.01, AMD Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 26200
Scene: Hyrule Field (child) by debug teleport from a copied save, standing; Output resolution 2560x1440 in a 1707x960 window, Render resolution 75%, the game's own upscaler, no frame generation, no frame cap, sound off, the serial replay, no VRAM allowance
Method: 3 rounds, the two builds alternating in each round. One game folder (
longshot v3.0.0-rc.3-27-gf516654c) with onlylongshot_vk.dllswapped (the host interface is unchanged since); both renderers built alone withRX_VK_ONLY=1and the same toolchain (v3.0.0-rc.3-57-g98e2d95fandv3.0.0-rc.3-58-gde3b4aab). Each run: teleport, 25 s standing, 5 s in the pause menu. Counts arevk: upload over a drawn imagelines; "for a buffer write" are those witha GPU buffer wrote it, each a whole image. Slow re-uploads areslow uploadlines markedagain(over 15 ms). Frame rate is the median of the log'sN presents, X fpslines from present 5040 on.How to reproduce: load a save, teleport to Hyrule Field (Debug tab), stand for 25 s, open and close the pause menu, and count the
upload over a drawn image ... a GPU buffer wrote itlines in the log.98e2d95fde3b4aabFrame rate by round, main / this PR: 118.4 / 114.7, 115.7 / 114.5, 114.4 / 114.2. Main ran first in each round here and was faster in each. In the earlier set on
514591a3(this PR's first version), this PR ran first in each round and was faster in each (118.6 / 114.2, 114.8 / 114.2, 115.3 / 114.7). The first run of a round is the faster one on this PC, so no frame rate change is claimed either way. The HUD labels were right in all six runs.The one left with this PR is a 1016 KB range of a 1920x1080 target, a page remapped or written after its finalize: another cause, not touched here.
main @
98e2d95f, round 1:On a build with 40955ed3 and
RX_VK_WATCH_TEX, the buffer writes behind these uploads were 1 to 3,221 frames older than the target's last drawing, in four of four.Flags and settings
One new switch, to turn the change off for comparison.
RX_VK_NO_DRAWN_OVER_BUFFER_WRITE=1Testing
Tested: on Windows 11, RTX 5070 Ti 16 GB, driver 621.01.
3b447163):python -I -B tests/run_all.pywith the pinned llvm-mingw 20261104: 541 passed, 18 failed, 35 skipped; main @9e6f231don the same PC: 540 passed and the same 18 failing (environment checks: portable builder, game font, a few that need tools this PC lacks). None new. The renderer builds with llvm-mingw.tests/test_drawn_target.pypasses here; with main'svk_texture.cpp(--source) its first case fails.Not tested:
RX_VK_PARALLEL=4. Zone changes on foot (the runs teleport once). Sessions longer than two minutes. Frame times (only the 5 s frame-rate readings). AMD and Intel GPUs. Linux. GCC for the new test. Whether the uploads on main ever show on screen. A game run after the rebase.Must be tested:
RX_VK_NO_DRAWN_OVER_BUFFER_WRITE=1, counting theupload over a drawn image ... a GPU buffer wrote itlines and watching the picture after each load; expect fewer such lines without the switch and nothing wrong on screen in either (by hand, test request T-KUWQ; Test Farm: @Beanstalk amd or linux, 6 zone changes with and without RX_VK_NO_DRAWN_OVER_BUFFER_WRITE=1, count those log lines)Risks
What could break: if a buffer write before the pass put texels into part of the target that the pass then does not cover, those texels are now missing from the image; on main the whole drawing was missing instead.
Turning it off:
RX_VK_NO_DRAWN_OVER_BUFFER_WRITE=1gives main's behavior without a rebuild; or revert the commit.Compatibility: Nothing changes.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
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.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.3b447163: builds. Linux not built; the change is standard C++ with no platform call and no path.)Test request T-J359 is open (any GPU, with RX_VK_PARALLEL=4); the description names it and the Testing box is ticked. It can be claimed once a maintainer adds the testing wanted label.
210511373dc42e9b1f88WIP: fix(vk): render targets keep their drawing after the game finalizes themto WIP: fix(vk): a render target is not uploaded from memory for a GPU buffer write older than its drawingNarrowed and re-measured: #325 merged the drawn page map, so this PR is now only the buffer-write case it leaves (one commit,
de3b4aab, switch RX_VK_NO_DRAWN_OVER_BUFFER_WRITE). Force-pushed onto main98e2d95fand measured there: 4, 4 and 5 whole uploads for an older buffer write a run on main, none with this PR. T-J359 named the dropped switch and is closed; T-KUWQ replaces it.c42e9b1f883b447163e0Rebased onto main
9e6f231d(now3b447163). One docs conflict in docs/development.md: kept main's 'the game's' wording and added the RX_VK_NO_DRAWN_OVER_BUFFER_WRITE row. run_all on Windows (CXX=g++): the same failures as main at9e6f231don this PC (toolchain checks), none new; no game run since the rebase.Description moved to main's new template (status line, How to reproduce, Verdict, Risks, Must be tested). Re-checked after the rebase with the pinned llvm-mingw: run_all 541 passed, the same 18 failing as main
9e6f231don this PC, none new; the renderer builds. Measurements are from before the rebase and say so.Reviewer notes moved under What changed (they had landed in Must be tested).
3b447163e018c163233eRebased onto
main@bbe6fdf2. No tests were run here; the test boxes stay yours. One conflict in docs/development.md: main changed the neighbouringRX_VK_ASTC_CPUrow, so both rows are kept (that one, thenRX_VK_NO_DRAWN_OVER_BUFFER_WRITE).Rebased onto main @
13e8b6da(b58993c4), no conflicts, and measured again there: whole uploads for an older GPU buffer write go from 5, 5, 4 a run on main to 0, 0, 0 with this PR (3 alternating rounds, Hyrule Field, game folders built the same way from one copy). The one other kind left, a 1016 KB range of the same 1920x1080 target, shows on both sides and is not this PR's. Measurements updated; the earlier set stays below it.18c163233eb58993c4c9@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 or to this comment.This request was forb58993c, and the PR has changed since (45ef0f0), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.theguyser referenced this pull request2026-11-16 13:51:42 +00:00
Merged main @
f88e6e3a(45ef0f0f): it no longer merged clean. One conflict, in docs/development.md: main's RX_VK_ASTC_REUSE row and this PR's RX_VK_NO_DRAWN_OVER_BUFFER_WRITE row, both kept. tests/test_drawn_target.py now builds main's gpu_wrote_into and texture_released: the fixture includes gpu/vk/wrote_regions.h and stubs reuse_released. Game-free checks for the changed files (tests/run_all.py --changed): no failure that main does not also have on this PC. No game code of this PR changed, so the in-game run above still holds.Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
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.