perf(vk): suballocate untouched tails of in-flight staging arenas #2469
Open
Erfboom wants to merge 1 commit from
Erfboom/perf/vk-staging-suballocation into main
pull from: Erfboom/perf/vk-staging-suballocation
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:github/pr/2876
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
2 participants
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!2469
Loading…
Reference in a new issue
No description provided.
Delete branch "Erfboom/perf/vk-staging-suballocation"
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?
Problem
When staging texture uploads, uncompleted in-flight arenas (
value < rec_value) with unused tail capacity were skipped, forcing immediate allocation of fresh 64 MB arenas and pinning tens of megabytes of staging memory.Solution
a.value < rec_value) for remaining unused tail space if no completed arena is available, aligning pasta.usedto at leastnonCoherentAtomSizeand advancing the arena's timeline stamp torec_value.inflight-tailcase totests/texture_staging_publication_test.cppandtests/test_texture_staging_publication.pyto verify that in-flight arenas are suballocated without allocating a new buffer and flush independently.Verification
python3 -I -B tests/test_texture_staging_publication.py --headers /usr/include(passes all cases across coherent and noncoherent caches)I ran the suite merged into main:
tests/test_texture_staging_publication.pyfails because its stubs lackenv_onandcreate_buffer_cached, whichvk_texture.cpp:468now needs.Beyond that:
:468), with no numbers on NVIDIA, AMD or Deck.:3806), and one arena never expires. That's pinned system RAM, which main's comments describe running 16 GB laptops out of memory.The tail reuse (
:449) looks correct. I'd want the host-cached part opt-in or measured.Thanks. I agree with Joey-Magnus's review: the suite failure he found is real (
tests/test_texture_staging_publication.pycutsstaging()out of the source, and its fixturetests/texture_staging_publication_test.cppstubscreate_bufferonly, so it needsenv_onandcreate_buffer_cachedstubs in this PR), and the default change and the 64 to 128 MB keep on small cards are his points, not repeated here. No CI checks have run on the branch.What I checked on top of that:
a.used, aligned to at leastnonCoherentAtomSize(and the ASTC caller's storage offset alignment), so neither the CPU writes nor the flush touch bytes an older submission still reads, and bumpingvaluetorec_valuejust holds the arena until the newest reader completes. It would be worth a case in the fixture: an arena in flight (value < rec_value, not completed) gets a second slice at an aligned offset past the first, with no new arena made.staging()callers already flush their range (vk_texture.cpp:994,:1711). The open question is only speed: the ASTC decoder then reads its blocks over PCIe instead of from BAR VRAM. The existingvk: a staging arena of N MB took X ms to makelog line gives the before/after the description's "100+ ms" claim needs.vramis read withenv_onthree times (two statics plus once more inside thekeeplambda, which could just use the static above it).My suggestion: split it. The tail reuse is a small, clear win I'd approve on its own once the test passes; keep the host-cached arenas and the warm arena behind a switch (or bring numbers from a ReBAR card and a 6 GB one) in a follow-up.
Other open PRs by the same author: #2462 and #2467 also edit
vk_texture.cpp, but in other functions (readback ring, eviction pacing), so no overlap with the staging code here. #2482, #2487 and #2491 are in other files.This flips every ReBAR user to cached host memory, including the buffers the ASTC compute decoder reads as storage. Correctness is fine (both callers flush), but I'd make this opt-in (e.g.
RX_VK_STAGING_HOST=1) until there are numbers, rather than opt-out withRX_VK_STAGING_VRAM. The fixture also needsenv_on/create_buffer_cachedstubs because of this line.This part looks right to me (see the body); a fixture case for an in-flight arena's tail would pin it down.
Rebased onto
mainand updated following the review recommendations:staging()checks uncompleted in-flight arenas (a.value < rec_value) for remaining tail capacity, aligning pasta.usedto at leastnonCoherentAtomSizeand advancinga.valuetorec_value.inflight-tailcase totests/texture_staging_publication_test.cppandtests/test_texture_staging_publication.pyensuring an in-flight arena gets suballocated past its first slice without creating a new arena, bumps its timeline stamp, and flushes independently.python3 -I -B tests/test_texture_staging_publication.py --headers /usr/includepasses cleanly for bothcoherentandnoncoherentcaches.Narrowing it resolves my first review: the host-cached default and the 128 MB keep on small cards are gone, and the fixture needs no new stubs.
The tail reuse in
staging()(gpu/vk/vk_texture.cpp:454) is correct. The slice starts pasta.used, aligned to at leastnonCoherentAtomSize, so neither the CPU writes nor the flush touch bytes an older submission still reads, and raisingvaluetorec_valueonly keeps the arena until its newest reader completes. Completed arenas are still reused from offset 0 first, so this only replaces making a new 64 MB arena, and theinflight-tailcase covers it.I merged it into current main and ran
tests/run_all.py: all pass excepttest_lift_cache.py(fails on main here too) andtest_recorder_sync.py, which timed out under machine load and doesn't touch this code. The CI reds are main's own failures from early Nov 12 and pass on current main, so a re-run should clear them. The description's "pinning tens of megabytes" has no number from the game; thestaging arena ... took X ms to makelog line would show it, but I wouldn't hold the merge on that.