WIP: perf(vk): re-upload only the part of a texture a GPU write covered (carries on #282) #1223
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1223
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:perf/gpu-write-part"
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?
Why
In Castle Town a compute pipeline binds a 1.75 MB write buffer that lands inside a finished 2560x1440 render target's storage. Every frame of that burst the renderer copies the whole 15 MB image back from guest memory, though the CPU wrote none of it. This uploads only the part the GPU write covered.
This is #282 by @bluetoe, carried on. The PR had a "request changes" review and has had no reply since. The six
perf/feat/test/docscommits are bluetoe's, unchanged apart from conflict resolution and authored under their name. Four of them came after mooki's review and already answer most of it. I added two commits on top, described below.Stacked on #1162. Its first commit (jarynclouatre's) keeps the GPU write records from overlapping. That is the fix for mooki's first point: bluetoe had made the same fix independently, and #1162's version was kept, which already has its own test. Review the last eight commits here; the first four are #1162's.
What changed
bluetoe's commits (see #282 for the full write-up):
gpu_wrote_intoreports the ranges a GPU write covered, clipped to the texture and in image offsets.texture_touchuploads those, plus whatever the CPU wrote since the last upload, in the same pass. Without those CPU writes they would be lost, since the upload movesupload_genpast them. Sparse images keep the whole path, andRX_VK_GPU_WRITE_WHOLE=1restores the old behaviour.vk: gpu-write uploads: N (X MB taken by the upload path, Y MB of written ranges, the whole image would have been Z MB).RX_VK_GPU_WRITE_LOG=1prints one line per event.origin/destinationpush constants.tests/test_gpu_write_part.pyruns the recorder, the lookup, the merging of CPU and GPU ranges, the row choice and its byte count. It includes mooki's nested-write case.Mine:
perf(vk): the GPU unswizzle's count. A dispatch covers whole groups of 32 rows, so with GOB blocks of 8 or 16 rows it also redoes rows past the written band. The tally counted the band, not what was dispatched; it now counts rows as dispatched, each once.test: seven checks cut these functions out of the source by their text, and now look for the new signatures. None is weakened.mooki's review on #282, point by point
test_gpu_write_intervalsand intest_gpu_write_part's nested casec2806167counts what each path takes. My commit counts what the GPU path dispatchesfe587a3eruns it, with a separate CPU write next to the GPU's partFlags and settings
RX_VK_GPU_WRITE_WHOLE=1RX_VK_GPU_WRITE_LOG=1Measurements
main:
ac778751(its renderer built alone,RX_VK_ONLY)this PR: perf/gpu-write-part @
882479a1, built the same wayHardware: RTX 4070 Ti 12 GB, 595.99.02, Ryzen 7 9800X3D, 30 GB, Ubuntu 26.04.1 (kernel 7.0.0-43), headless
Game: one copy of a
v3.0.0-rc.5-26-g71b1edd8folder, the renderer swapped between runsScene:
scripts/memtour.pyfrom the kokiri-start repository save: Market, Kakariko Village, Market, Kokiri Forest, Market, 40 s in each. Output 2560x1440, cap 240,RX_VK_GPU_WRITE_LOG=1.Method: three arms, interleaved three times (part, main, whole, part, main, whole, ...), each a
timingjob inscripts/job_queue.py, so nothing else used the GPU or ran a build alongside. "whole" is this PR's renderer withRX_VK_GPU_WRITE_WHOLE=1; main's renderer has no per-upload line. Frame times exclude the first 10 s after each arrival.The copying, from the per-upload lines (what the upload path took from guest memory, the written ranges it was handed, the whole images):
The number of uploads varies a lot between runs of the same arm, so the comparison is per upload. With this PR an upload took 1.12 MB on average (601 MB over 535), against 3.88 MB with the whole path (2,073 MB over 534): 71% less. Within this PR's runs, the path took 21% of what the whole images would have been, and 1.6 times its written ranges, since a written page brings its whole GOB-block row up. The case in Why, the 2560x1440 target:
gpu-write upload #631: 2560 KB taken by the path, 288 KB of written ranges, 15360 KB whole (the part).Frame times (median of the three runs' medians, ms; p99 in brackets):
No fps effect is claimed either way. This PR's slowest run (c7) was slower in every area, Kokiri Forest included, where there are few GPU-write uploads. The game folder's render resolution is on Auto, which lowered it in play by a different amount in each run, and about 19 GB of swap was in use by other work throughout. The teleport out of Kokiri Forest was refused in every run, and in one run per arm the second Market as well, so the second-stay columns have two runs per arm. Recorded in
docs/tested/2026-11-16-gpu-write-part-trashpanda-run01.md.Testing
Tested:
RX_VK_SHOTS, one every 600 frames, 13 and 12 of them): nothing missing or corrupt with this PR. The walk drifts between runs, so the frames are not the same views.python -I -B tests/run_all.pyon Linux: 652 passed, 23 failed, 21 skipped. The same 23 fail onmain(ac778751) on this PC: they want packages it doesn't have (numpy, zstandard, a game folder for the build tests). None fails only here.test_gpu_write_part,test_gpu_write_intervals,test_upload_retry,test_bc_upload_retry,test_wrote_regions,test_bc_scratch_layers,test_texture_staging_publication,test_guest_holes,test_compressed_over_rt.Not tested: Windows, AMD and Intel. A fixed render resolution, for a cleaner frame-time comparison.
Needs other testers:
RX_VK_GPU_WRITE_LOG=1, expecting the per-upload drop and no texture corruption.Screenshots
Nothing on screen: the change uploads a subset of what was uploaded before, and the Market screenshots described under Testing show no difference from main's.
Risk and rollback
Partial uploads have a known kind of hazard: an unrelated variable sharing an edge page can re-upload stale bytes over a drawn resource. This change copies a strict subset of what the old path copied. One wider change to note: the GPU unswizzle now uploads only the written rows for CPU-written partial uploads too, the same rows the CPU path has always copied, where before it redid the whole level.
RX_VK_NO_PARTIAL=1turns all partial uploads off, andRX_VK_GPU_WRITE_WHOLE=1the GPU-write part only.Assisted-by: Claude Opus 5.5
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.