perf(vk): re-upload only the part of a texture a GPU write covered #2876
Open
github-sync
wants to merge 2 commits from
github/pr/2876 into main
pull from: github/pr/2876
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:perf/astc-opaque-bc1
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2876
Loading…
Reference in a new issue
No description provided.
Delete branch "github/pr/2876"
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. A storage buffer bound for writing is recorded as its whole bound range, and any texture whose storage overlaps that range is then re-uploaded whole. In Castle Town one of the game's compute pipelines binds a 1.75 MB write buffer whose range lands inside a finalized 2560x1440 render target's storage, and every frame of that burst the renderer copied 15 MB of guest memory over the image, on a path where nothing at all had been written by the CPU (
upload over a drawn image ... 0 KB dirty in 0 ranges, a GPU buffer wrote it). This is one of the costs measured under #2780, where the resident/mirror bookkeeping grows with each area change.What changes.
gpu_wrote_intoreports the ranges it matched, clipped to the texture's storage and merged, in image-relative offsets.texture_touchuploads those ranges instead of the whole image, and the CPU's writes since the last upload in the same pass. That second half is required: the whole upload used to cover those pages, and the upload movesupload_genpast them, so a partial that skipped them would lose them permanently. An event where the CPU also wrote still uploads the full amount.RX_VK_NO_PARTIALandRX_VK_GPU_WRITE_WHOLE=1restore the old behaviour for A/B.vk: gpu-write uploads: N (X MB copied, the whole image would have been Y MB).Measured (Linux, RTX 5070 Ti 16 GB, one save, one process, five area changes: Hyrule Field, Castle Town Market, Kokiri Forest, Hyrule Field, Castle Town Market). Both arms were built from the same tree with the same flags, differing only by this patch, and the tour was run twice per build:
So this is a copy and staging reduction on a path that arrives in bursts, not a frame-rate win on a 16 GB card: 56% less copied on the path, 802-814 MB not copied per tour. No fps effect is claimed, and none was measurable: the same build in the same leg varied by up to 19 fps between samples, which is the noise floor these runs established. On the 8-12 GB cards of #2690 and #2780 the same events compete with a texture budget that is already being evicted past, which is where the saved copying should matter more.
On the measured base. The runs above are from
de866017. The branch is rebased ontofe5e2cb8; upstream's twelve hunks invk_texture.cppdo not touchtexture_gpu_wrote,gpu_wrote_intoor thegpu_dirtydecision, and the rebase applied cleanly apart from an adjacent slow-upload logging line. I did not re-measure on the newer base becauseMKWVK_API_VERSIONmoved from 19 to 21 in between, so amainrenderer will not load under ade866017game folder's host binary and restating the numbers needs a full game build. Say so if you want that before merging.Cache cost for players: none.
nx2/build.py'sHOOKSHOT_SHADER_STAMPhashes the translator sources (eden/,sirit/,compat/,vk_shader.cpp,vk_bank.cpp,vk_state.h,vk_api.h) and deliberately notvk_texture.cpp, so existing translated programs, pipeline notes andhookshot_prepared.binstay valid after this ships.Tests.
tests/test_gpu_write_part.py(new) cuts the recorder and the reporter,texture_gpu_wroteandgpu_wrote_into, out of the source and runs them against stand-ins: a write inside reports its part; one spanning either end is clipped; adjacent writes merge; an unfinished submission is not reported until it completes; the same write is not reported to the same texture twice; a write elsewhere reports nothing. Plus source guards for the switch, the CPU-write union and the sparse exclusion.python -I -B tests/run_all.py: 411 passed, 13 failed, 67 skipped on the measured base (those 13 fail identically on the main branch too), and 453 passed, 1 failed, 69 skipped rebased, where the single failure istests/test_readme_menu_rows.py, which also fails on cleanfe5e2cb8.Also in this branch. One readme line, in a separate commit (
fix(docs)).tests/test_readme_menu_rows.pywants a row for every Insert menu entry, andmainhas been red on it since #2827 added the Gameplay tab's "Skip opening" without one; that is what thePython source checks (ubuntu, part 1/2)failure was showing on the first push. It has nothing to do with the renderer change and I will split it out if a reviewer would rather it land on its own.Not claimed. No visual change is intended. The change copies a strict subset of what the old path copied, so the known hazards of partial upload (the rainbow-sky case, where an unrelated variable sharing an edge page re-uploaded garbage over a drawn LUT) get narrower, not wider. No screenshots attached because nothing on screen should differ; both arms' frames from the tour are available if a reviewer wants a particular scene checked.
Status after the two pushes:
Python source checkson Windows in both shards: my new test compiles a fixture cut fromvk_texture.cpp, which callsgetenv, and the MSVC CRT deprecation plus-Werrorturned it into an error. Fixed with the flag the sibling tests already pass (-D_CRT_SECURE_NO_WARNINGS), verified withclang++andg++.part 1/2failure was pre-existing onmain:tests/test_readme_menu_rows.pyhas been red since #2827 added the Gameplay tab's "Skip opening" row without its readme line. The second commit (fix(docs)) adds that one row. It fails identically with this branch's renderer change stashed out.python -I -B tests/run_all.pygives 488 passed, 0 failed, 35 skipped (the skips needspirv-valand a few Windows-only tools).de866017; the branch is rebased ontofe5e2cb8. Restating them on the newer base needs a full game build becauseMKWVK_API_VERSIONmoved 19 to 21 in between; happy to do it if a reviewer wants it there.