perf(vk): add UBO descriptor delta fast path, 8-slot ub_gap_cache, and lock-free invalidate exits #2899
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2899
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/pc-phase-a-desc-ub-invalidate"
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?
Summary
Cuts CPU descriptor rebuilds and lock contention on the draw and
InvalidateMappedRangehot paths without modifyingvk_state.h(LONGSHOT_SHADER_STAMP) orProgramlayout:ubo_gen[8]sidecar & UBO-only descriptor delta (RX_VK_DESC_DELTA) ingpu/vk/vk_replay.cpp,gpu/vk/vk_internal.h, andgpu/vk/vk_draw.cpp: tracks UBO binds per stage in a sidecar table so draws ignore unused-stagebind_genbumps (Tier 1) and updatec3..c18VkDescriptorBufferInfoentries in place + push only dirty writes while keepingPushed::wordscoherent and obeying Intelub_every(Tier 2).ub_gap_cache(RX_VK_UB_GAP8) ingpu/vk/vk_replay.cpp: avoids 1-slot thrashing across alternating user uniform buffers.RX_VK_WB_LEARN_FAST) ingpu/vk/vk_memory.cpp,gpu/vk/vk_texture.cpp, andhost/nvn_native.c: adds monotonicwb_followed_everPageMarksbeforewb_learn_mu, fast-pathsmemory_writeback_value/texture_gpu_written_inviawb_ever/vw_ever, and filtersCPU_NO_ACCESS/!mem/ zero-sizeInvalidateMappedRangecalls before touching replay or vCores.In
KokiriForest_Child(1280x720), full descriptor builds per draw drop-28.3%(0.92 -> 0.66), warm Avg FPS rises+4.7%(86.67 -> 90.73), 1% Low rises+54.9%(28.38 -> 43.97), and 0.1% Low rises+94.0%(14.25 -> 27.64). Read first:state_ubo_gen()/ub_gap_holds()ingpu/vk/vk_replay.cpp,update_ubo_descriptors()/bind_descriptors_ubo_delta()/draw()ingpu/vk/vk_draw.cpp,wb_followed_everingpu/vk/vk_memory.cpp, andNV(nvnMemoryPoolInvalidateMappedRange)inhost/nvn_native.c.Testing
Tested: Windows 11, Intel Core i7-9700 (8C/8T), NVIDIA GeForce RTX 4060 (driver
621.40), built withdev.py pack+dev.py rt(lift: unchanged). Ran 4 interleaved 35 s runs + 3 extra warm 35 s runs + 2RX_VK_PROF_FINE=115 s runs inKokiriForest_Child(1280x720,RX_VK_IMMEDIATE=1,RX_VK_FRAME_TRACE=1) with0warnings andCPU reads or writes of one left out: 0. Before the independent mark-agreement test changes, targetedtests/run_all.pychecks:25 passed(test_bank_gen,test_desc_clock,test_desc_counts,test_dlss_pre_bloom,test_fallback_pipeline_state,test_hidden_mesh_depth,test_push_state,test_readback_early,test_same_bind,test_sampler_admission,test_target_layouts,test_ub_gap,test_ub_memo,test_ub_threads,test_ub_word_index,test_notes_format,test_nvn_null_pool,test_wb_learn,test_wb_spans,test_readback_part,test_invalidate_quick,test_direct_buffer_writes,test_ub_snap_scope,test_doc_anchors,test_invalidate_vcore);2 failedpre-existing onorigin/main @ 28cb22b9e(test_switch_table.py: upstreamLONGSHOT_LAUNCHER_STARTUPinhost/launcher_startup.h:9, all 3 new rows ingpu/vk/switches.defpassed;test_linux_pressure.py: pre-existingspirv_pack::Store->vs.syntax errors incache_functions.inc). Standalonephase_a_bench.exe(C / Rust#![no_std]/ Win64 AVX2 ASM) verified0mismatches.Still to test:
@Beanstalk linux: build on Linux/AMD RADV and runpython -I -B tests/run_all.py, expecting descriptor,ub_*, and invalidate suites to pass cleanly (@Beanstalk linux).@Beanstalk windows: run full CI check suite plus an Intel Arcub_everycheck, expecting descriptor delta pushes to preserve all object matrices (@Beanstalk windows).Measurements
Verdict: Eliminates -28.3% of full descriptor builds per draw (
0.92 -> 0.66,descriptorstime1.64 -> 1.48–1.55 ms/frame); across warm runs improves Avg FPS+4.7%(86.67 -> 90.73), 1% Low FPS+54.9%(28.38 -> 43.97,P9925.21 -> 18.83 ms), and 0.1% Low FPS+94.0%(14.25 -> 27.64). Standalonephase_a_bench.exemeasures1.67x–1.80x(UBO delta),11.31x–13.85x(8-slotub_gap_cache), and4.55x–28.29x(PageMarks::any).Setup: Windows 11, i7-9700, RTX 4060 (
621.40);KokiriForest_Child(kokiri-start),1280x720(resolution=0,HOS_RES_SCALE=1.0,quality_preset=6),RX_VK_IMMEDIATE=1,frame_generation=0,HOS_FPS_MAX=1000,HOS_AUDIO=0,RX_VK_FRAME_TRACE=1(frames.csv), comparingRX_VK_DESC_DELTA=0 RX_VK_UB_GAP8=0 RX_VK_WB_LEARN_FAST=0vs1on93231e4fc. InitialBASE_1(67.35 Avg / 17.10 1% low) had cold warmup variance, so an extra warm interleaved block (NEW_3,BASE_3,NEW_4) +RX_VK_PROF_FINE=1(FINE_OFF/FINE_ON) ran; table reports all warm 35 s runs (BASE_2,BASE_3vsNEW_1..NEW_4). All 3 switches ship enabled (1).Baseline:
origin/main @ 28cb22b9e(this PR @ 93231e4fcwith the 3 runtime switches=0).0/0/0) @93231e4fc1/1/1) @93231e4fcBASE93.71, 79.63 vsNEW89.20, 97.00, 81.72, 95.01)BASE98.04, 88.97 vsNEW93.28, 99.80, 87.49, 97.28)BASE37.39, 19.37 vsNEW40.84, 46.62, 32.24, 56.17)BASE20.32, 8.17 vsNEW26.88, 27.10, 22.59, 33.98)RX_VK_PROF_FINE=1)phase_a_benchUBO /ub_gap/PageMarks(0mismatches)Risks
Any future draw path reading
c3+for storage/image/texel descriptors must be excluded inprogram_ubo_delta_safe(); compute stage 5, written SSBOs, and storage images already force full rebuilds. Each optimization has an independent=0runtime kill switch (RX_VK_DESC_DELTA=0,RX_VK_UB_GAP8=0,RX_VK_WB_LEARN_FAST=0). No changes tovk_state.h(LONGSHOT_SHADER_STAMP),Programlayout,MKWVK_API_VERSION, saves, or pipeline caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, i7-9700, RTX 4060 (621.40), KokiriForest_Child 1280x720: -28.3% full descriptor builds per draw (0.92 -> 0.66), warm Avg FPS +4.7% (86.67 -> 90.73), 1% Low +54.9% (28.38 -> 43.97), 0.1% Low +94.0% (14.25 -> 27.64), 0 warnings, 0 left-out CPU R/W.
Possibly related, for context:
@review
@beanstalk
Beanstalk test farm · an earlier run: commit
93231e4(the newer results are in a comment below)Commit
93231e4· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm cannot run the requested Python or full CI suites, or establish that every Intel object matrix and invalidate edge case is exercised by these gameplay scenes.
⚠️ Note: Descriptor-build counts, 0.1% lows and standalone microbenchmark results are not measured; the plan measures gameplay frame times instead.
⚠️ Note: The three optimization switches are not isolated individually; the comparison tests the PR's shipping defaults against main.
Started at 00:31 UTC.
Estimate: done in about 4 h, from the queue and the testers online now; some jobs can't start yet.
windows+nvidiawindows+amdlinux+radvintelwindows+intel+gpu-arc-*(GPU "arc *")What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main and the PR on NVIDIA, AMD and Intel hardware, including Windows Intel Arc and Linux RADV; the Arc target will wait if no matching tester is online. Three starts per side measure uncapped CPU-limited gameplay for 35 seconds each in Kokiri Forest and Market, with stationary picture comparisons for rendering errors. A crash, a picture difference beyond the allowed tolerance, or a frame-time regression beyond 15% fails the PR on the affected target. No tester online now matches windows+intel+gpu-arc-*: that target waits for one.
kokiri-start(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, frame_generation=0; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Kokiri Forest, take the picture forest to compare with main, measure forest for 35 s (after 10 s warm-up), teleport to Market, take the picture market to compare with main, measure market for 35 s (after 10 s warm-up); 3 runs on each side.Recommendation: Request changes. The change weakens existing checks for missed write-back and texture marks, which can hide stale GPU data reaching the CPU. Its reported performance gain is also unproven against the base commit and across the affected systems.
The change tries to reduce descriptor rebuilding, uniform-update lookup and invalidate locking. It adds three enabled-by-default switches and more cached state; the available runs show fewer descriptor builds but do not yet establish a reliable player-facing speedup.
Blocking (1): must change before merging.
gpu/vk/vk_texture.cpp:4964: The new early exits make the existing mark-agreement checks compare the marks against themselves, so those checks no longer detect missing marks. (more on the line) Do: Keep an independent locked-table reference in both agreement tests, or run the reference lookups with the fast exits disabled, and add cases that fail when a covered page is omitted from either mark.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. On one Windows/NVIDIA setup, full descriptor builds fell from 0.92 to 0.66 per draw. The reported warm FPS runs overlap substantially: 79.63–93.71 before and 81.72–97.00 after. The before runs use this PR with switches off, rather than the base commit.
Other systems: Descriptor reuse and invalidate behavior affect Windows and Linux, NVIDIA, AMD and Intel GPUs, Steam Deck, texture readbacks and GPU-written buffers. Only Windows/NVIDIA game results are supplied; the Intel snapshot path and the other Tier 1 systems remain unverified.
Switches: RX_VK_DESC_DELTA, RX_VK_UB_GAP8 and RX_VK_WB_LEARN_FAST are added as kill switches, all defaulting to on, with rows in switches.def. Their defaults are not yet supported by measurements on the other affected systems. RX_VK_WB_LEARN_FAST=0 also does not disable the new texture or host invalidate exits.
Reviewed:
93231e4fc5against28cb22b9ed: Read the PR description, comment, commit and diff; AGENTS.md, CONTRIBUTING.md, the PR template, standards, page_marks.h and wb_learn.h. Read the changed regions and related descriptor, replay, write-back, texture and host paths, plus the affected test fixtures. The large changed source files were not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md are absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: No code, tests or project scripts were run, as requested. CI is still running. The maintainer's Beanstalk request could not be submitted within the specified no-network and no-script limits.
Overlaps and merge order: Not checked: network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -4958,6 +4961,7 @@ void texture_describe_written(uint64_t lo, uint64_t size, std::string& out) {}bool texture_gpu_written_in(uint64_t lo, uint64_t size) {if (size && !texture_gpu_written_ever(lo, size)) return false;L1 (blocking): The new early exits make the existing mark-agreement checks compare the marks against themselves, so those checks no longer detect missing marks.
When: If vw_note marks too short a range, texture_gpu_written_in now returns false from the same mark before examining vw, so agree-vw accepts the missed texture. The analogous memory_writeback_value exit makes agree-wb accept a missed wb_ever mark, potentially hiding an invalidate that skips a GPU write-back wait.
Do: Keep an independent locked-table reference in both agreement tests, or run the reference lookups with the fast exits disabled, and add cases that fail when a covered page is omitted from either mark.
@fix
93231e4fc50e96053ad9Recommendation: Approve. The code is ready: only testing is left. The optimization reduces descriptor builds in the reported run, but its frame-rate gain against main and its behavior on other affected systems remain unverified. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
0e96053ad9. I rebased it ontomain(19f9da05ea). I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The pull request reduces descriptor rebuilding and avoids some cache and synchronization work. The test fix checks the lock-free marks against the underlying locked tables, at the cost of additional test code.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven. The reported Windows/NVIDIA runs show full descriptor builds falling from 0.92 to 0.66 per draw and average FPS rising from 86.67 to 90.73, but compare switch settings on the PR head rather than builds of main and the PR.
Other systems: The renderer and synchronization paths also affect Linux, AMD, Intel and other driver configurations. The supplied game run covers Windows with NVIDIA; Linux/AMD and Intel Arc coverage remains outstanding.
Switches: RX_VK_DESC_DELTA, RX_VK_UB_GAP8 and RX_VK_WB_LEARN_FAST are added and default to 1. Their enabled defaults lack measurements against main and coverage on the other affected systems.
Reviewed:
0e96053ad9against19f9da05ea: Read the test fix and tests/invalidate_quick_test.cpp in full, the test harness and relevant mark and table implementations, the PR description, comments, ledger and available repository rules. Skimmed the original renderer diff and commit list; the full base-to-head diff and all changed code files were not read in full. Tooling's adjacent AGENTS.md and docs/review-checklist.md were unavailable.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run. The author reports Windows/NVIDIA game testing before the test fix; the updated checks and other hardware runs remain outstanding.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
Beanstalk test farm
Commit
6520237· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.@rebase
I rebased this pull request onto
main(a5cae004d8): the new head is6520237434.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
0e96053ad96520237434Recommendation: Approve. The code is ready: only testing is left. The claimed frame-rate gain still needs a comparison against main, and the enabled renderer paths need game coverage on other affected systems. Recommend approval; not approved on the forge.
The change reduces descriptor rebuilding and adds cache and lock-free fast paths. It adds renderer and synchronization complexity in exchange for a potential performance gain that has not yet been established against main.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
Since the last review (on
0e96053ad9)Still open: L2 (The measurements do not establish the claimed frame-rate gain against main.); L3 (The enabled renderer and synchronization paths still need game coverage on the other syste…)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. The reported Windows RTX 4060 runs show 86.67 to 90.73 average FPS and 0.92 to 0.66 full descriptor builds per draw, but compare switches off and on in the PR build rather than the PR against main.
Other systems: The descriptor and synchronization paths affect Windows and Linux across GPU vendors and drivers. The supplied game run covers Windows with NVIDIA; Linux/AMD and Intel Arc game coverage remains outstanding.
Switches: RX_VK_DESC_DELTA, RX_VK_UB_GAP8 and RX_VK_WB_LEARN_FAST are new kill switches, all defaulting on and listed in switches.def. Their defaults remain subject to the outstanding performance and hardware coverage.
Reviewed:
6520237434againsta5cae004d8: Read AGENTS.md, CONTRIBUTING.md and the complete PR diff; compared the rebased draw diff with the earlier version. The changed code files and supporting callers were not read in full; the PR template, standards, recorded runs and tests were only skimmed.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run. The author reports Windows/NVIDIA game runs and targeted checks; the updated mark-agreement checks and Linux and Intel coverage remain outstanding. CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
Follow-up now that this is merged (
018dd2ef4, 1 Dec), covering BeanBot's open items.L1 (blocking, mark-agreement checks): BeanBot's
@fixresolved this before the merge.tests/invalidate_quick_test.cppnow checks the lock-free marks against the locked tables directly and has cases for an omitted covered page.@fixdidn't run it, so I ran it onmain(see Testing below).L2 (gain against main) and L3 (other systems): still open, and I'm not going to claim the gain from here.
@beanstalkrun on93231e4was cancelled when@fixpushed a new head, and the head that merged (6520237) was never approved for a run (dashboard: no reports).ub_every). These still need the farm or a tester. All three switches (RX_VK_DESC_DELTA,RX_VK_UB_GAP8,RX_VK_WB_LEARN_FAST) have a=0kill switch if a system shows a problem.CI on the head: "Game-free checks" 1/2 and 2/2, "Website" and "Third-party parts" failed on
6520237. The same four checks also failed onmain's own push runs at the merges around it (19f9da05e,f439f2bb9,018dd2ef4), and #3057 later fixedmain's checks. So these failures are not this PR's. I couldn't open the CI job logs to match them test by test.Testing (this comment): on a clean
main@b4d56f526worktree, Windows / llvm-mingw:tests/test_invalidate_quick.py(@fix's independent mark-agreement cases): pass (266 s) in my #2858 worktree onmainb4d56f526(#2858 doesn't touchtests/invalidate_quick_test.cpporgpu/vk/vk_texture.cpp). On a cleanmain1e782fa4bits compile ran into the check's own 300 s limit while the PC's queue was fully loaded, so no result there.tests/test_direct_buffer_writes.py(changed by this PR): 11 of 11 cases pass on cleanmain1e782fa4b. I lifted the check's 60 s compile limit, which the loaded PC couldn't meet.tests/test_invalidate_vcore.py: thevulkancase passes. Thefallbackcase failed at its 2 s wait for the producer thread (tests/invalidate_vcore_test.cpp:122), with the check running at below-normal priority on a fully loaded PC. I can't tell that apart from load from here. It needs CI or a rerun on an idle PC.@siantm this PR is closed or unknown to the farm.