perf(vk): add per-thread texture/sampler and read-only SSBO descriptor memos #2920
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!2920
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-tex-desc-memo"
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
Adds per-thread L2-resident descriptor memos in
gpu/vk/tex_desc_memo.hsobuild_descriptorsavoids repeating bank-word decoding, handle table lookups, view/layout checks, sampler lookups, and read-only SSBOgpu_buffer_bindcalls across draws that cannot reuse the whole descriptor set (same_desc == false). Controlled byRX_VK_TEX_DESC_MEMO(1on by default,0off,checklive equivalence check against the unmemoized slow path).Key changes:
gpu/vk/tex_desc_memo.h:2048 x 4-wayset-associative Combined-Image-Sampler memo (64-byte PODEntrywithc2_read_word,c2_handle_of,sync_generationsbumpinggen_tagonly when(reg_gen, samp_gen)changes, round-robin eviction, per-entrydestroy_gen+texture_still_resolvedhonoringRX_VK_EXACT_STALE,kOutDepth, andkOutDummycaching for non-zero dummy slots).256 x 2-wayset-associative read-only SSBOBufferRefmemo (SsboEntrykeyed on alignedbase,n, andgpu_bind_stamp()with inlinec0_ssbo_read).gpu/vk/vk_draw.cpp: wirestex_desc_memo_tls,tex_desc_memo_begin_recording(), andRX_VK_TEX_DESC_MEMO=0/1/checkfast/check paths into the SSBO and texture descriptor loops inbuild_descriptors, honoringRX_VK_TOUCH_SLOWandRX_VK_ZERO_SAMPLER.gpu/vk/switches.def: documentsRX_VK_TEX_DESC_MEMO.tests/test_tex_desc_memo.py&tests/test_hos_ab.py: standalone unit/oracle suite compilinggpu/vk/tex_desc_memo.hverbatim alongside realdriver_bank_word/handle_ofslices (including3,000-op oracle trace and 9 brokenMUST_FAILvariants) plusHOS_ABWIREDregistration.Read first:
gpu/vk/tex_desc_memo.h,build_descriptorsandtex_desc_memo_begin_recordingingpu/vk/vk_draw.cpp, andtests/test_tex_desc_memo.py.Testing
Tested: Windows 11, NVIDIA GeForce RTX 4060 (driver
621.40),build-windows/rt-Longshot(1280x720):RX_VK_TEX_DESC_MEMO=checkinMarket_Child(--repo-save market-entrance, 35s in-play headless run):32,600,000 checks, 29,715,363 hits (91.2%), 2,884,637 misses, 0 mismatches.python -I -B tests/run_all.py test_tex_desc_memo test_flat_map test_handle_lookup test_desc_clock test_handle_table_arrays test_tls_objects test_hos_ab test_hos_ab_table test_same_bind:9 passed, 0 failed, 0 skipped.python -I -B tests/test_desc_counts.py:PASS.python -I -B tests/test_sampler_admission.py:PASS(147 sampler cache/admission/policy/limit cases passed).python -I tests/test_switch_table.py: failed solely on pre-existingmainmismatch (LONGSHOT_LAUNCHER_STARTUPinhost/launcher_startup.h:9has no row ingpu/vk/switches.def);RX_VK_TEX_DESC_MEMOpassed cleanly.Still to test:
@Beanstalk linux: build on Linux and runtests/test_tex_desc_memo.pyand in-gameRX_VK_TEX_DESC_MEMO=check, expecting0 mismatches(@Beanstalk linux).Measurements
Verdict: Cuts mean frame time in CPU-bound
Market_Childby -0.377 ms (-2.68%, +1.95 Avg FPS from70.97to72.92fps across51pairedHOS_ABperiods, 95% CI+0.057to+0.691 msstrictly excluding0), reducingdesc_msby -0.324 ms (-10.2%,3.170to2.846 ms) while lifting1%Low (46.35to50.47fps) and0.1%Low (32.18to43.60fps). Ships on by default (RX_VK_TEX_DESC_MEMO=1).Setup: Windows 11, RTX 4060 (
621.40),Market_Child(--repo-save market-entrance),1280x720(resolution=0,threaded_rendering=0,descriptor_reuse=1),HOS_FPS_MAX=1000,HOS_AUDIO=0,RX_VK_IMMEDIATE=1,RX_VK_FRAME_TRACE=1,HOS_AB=RX_VK_TEX_DESC_MEMO=0,3,50across 3 sequential pre-dusk headless runs (51periods pooled viascripts/perf.py ab, where side 1RX_VK_TEX_DESC_MEMO=0runsmain's unmemoizedbuild_descriptorspath).Baseline:
origin/main @ 28cb22b9e(this PR @ 1312ed6fcwithRX_VK_TEX_DESC_MEMO=0).28cb22b9e1312ed6fcdesc_msmeandraw_msmean+0.057to+0.691 ms(side 1 is slower)Risks
thread_localmemo storage per recording thread (2048 x 4 x 64 Btexture memo +256 x 2 x 56 BSSBO memo). Dynamic (gpu_written) textures, depth-feedback edges, writable SSBO bindings, and virtual SSBO mappings bypass the memo, and per-entry generation/epoch checks invalidate stale entries on eviction or bank registration changes.RX_VK_TEX_DESC_MEMO=0switches back to the unmemoized slow path at recording boundaries without rebuilding or changing saves, shader caches, orlongshot_options.ini.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, RTX 4060 (driver 621.40), build-windows/rt-Longshot in Market_Child (--repo-save market-entrance, 1280x720): RX_VK_TEX_DESC_MEMO=check logged 32,600,000 checks, 29,715,363 hits (91.2%), 0 mismatches; 51 paired HOS_AB periods across 3 pre-dusk runs measured -0.377 ms (-2.68%, 70.97 -> 72.92 Avg FPS, 95% CI +0.057 to +0.691 ms).
Possibly related, for context:
@Beanstalk
@review
Beanstalk test farm · an earlier run: commit
1312ed6(the newer results are in a comment below)Commit
1312ed6· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm cannot run the standalone Python oracle suite, and this plan cannot establish the claimed 2.68% speed-up or descriptor-specific timing at its noise threshold.
⚠️ Note: The live check fails on logged mismatches but does not require a check-count log, so absence of a mismatch alone does not prove that every descriptor branch was exercised.
⚠️ Note: The check-mode cell is diagnostic rather than a performance comparison; the default-on path is compared with main separately.
Started at 00:30 UTC.
Estimate: done in about 3 h, from the queue and the testers online now; some jobs can't start yet.
linuxnvidiawindows+nvidiawindows+amdlinux+radvintelWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares uncapped, CPU-oriented frame times against main in the Market and Hyrule Field, with three starts per side and 20-second measurements at each place. It also compares stationary pictures and runs the memo’s live equivalence-check mode through both areas. A crash, descriptor mismatch log, excessive picture difference, or a frame-time regression over the specified limits fails the pull request. Linux, Windows/NVIDIA, Windows/AMD, RADV, NVIDIA, and Intel targets report separately.
check(PR only).market-entrance(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, descriptor_reuse=1; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Market, take the picture market to compare with main, measure market for 20 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 20 s (after 10 s warm-up); 3 runs on each side.market-entrance(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, descriptor_reuse=1; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Market, teleport to Hyrule Field; 1 run on each side.Recommendation: Request changes. The read-only SSBO memo can reuse a binding after its virtual address is remapped, producing the wrong buffer contents. The reported performance gain also needs comparison against the actual base build and coverage of the other affected Tier 1 systems.
The change caches texture, sampler and read-only storage-buffer descriptor resolution per recording thread. It reports a 0.377 ms mean frame-time reduction on one Windows/NVIDIA setup, at a cost of roughly 540 KiB of memo storage per recording thread and additional invalidation logic.
Blocking (1): must change before merging.
gpu/vk/vk_draw.cpp:4959: The SSBO memo keys virtual GPU addresses without tracking their page mappings, bypassing the translation and contiguous-range validation performed by gpu_buffer_bind. (more on the line) Do: Include the virtual mapping generation in the memo validity check and revalidate the mapping and contiguous range, or bypass this memo for virtual addresses. Add a test that remaps and unmaps a cached address.Should fix (1): not blocking, but worth doing before merging.
gpu/vk/vk_draw.cpp:5384: Check mode does not compare the fast path's handle decoding or its touch behavior with the slow path. (more on the line) Do: Have check mode compare the fast decoded handle and exercise or independently validate the fast lookup's touch and resulting descriptor state; cover those comparisons with a test that fails when each is broken.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1 and L2.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven against the base: the reported 70.97 to 72.92 average FPS and 46.35 to 50.47 FPS 1% low come from toggling the switch within the PR build, rather than running base commit
28cb22b9ed. The comparison covers one scene and Windows RTX 4060.Other systems: The descriptor paths affect graphics and compute recordings, virtual buffer mappings, texture uploads and descriptor reuse on both Windows and Linux. The supplied live check covers Windows/NVIDIA only; AMD, Linux and Steam Deck results are still needed.
Switches: RX_VK_TEX_DESC_MEMO is added, defaulting to 1; 0 disables the memo and check enables the live comparison. It has a switches.def row, but the default has only been measured on one system.
Reviewed:
1312ed6fceagainst28cb22b9ed: Read AGENTS.md, CONTRIBUTING.md, the pull request template, docs/dev/standards.md, the commit and diff, tex_desc_memo.h, the changed descriptor and recording paths and their buffer, texture and bank dependencies. Skimmed the test harness, HOS_AB registration and switch table; vk_draw.cpp and test_hos_ab.py were not read in full. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded run artifacts or generated files were supplied.; nothing run (a code review).Checked and fine:
Testing: No commands from the project, builds or tests were run, as requested. The supplied Windows live check reports 32.6 million checks and zero mismatches; its coverage limitation is noted above. 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 HumanBean. Nothing was run; a maintainer decides.
@ -4869,0 +4956,4 @@const uint64_t n = std::max<uint64_t>(((size + (addr - base)) + 3) & ~3ull, 16);BufferRef cached_ref;if (tex_desc_memo::ssbo_lookup(*sm_st, base, n, sm_stamp, cached_ref)) {if (page_table_cover_wanted(base, false)) gp_table_cover(p.key, st, base, n, cached_ref);L1 (blocking): The SSBO memo keys virtual GPU addresses without tracking their page mappings, bypassing the translation and contiguous-range validation performed by gpu_buffer_bind.
When: A read-only SSBO at a virtual address is cached, then its virtual pages are remapped or unmapped without changing pools_gen or mirror_epoch. A subsequent lookup with the same address and size returns the old BufferRef instead of translating the new mapping or returning an unbound descriptor, so the shader reads the previous pool.
Do: Include the virtual mapping generation in the memo validity check and revalidate the mapping and contiguous range, or bypass this memo for virtual addresses. Add a test that remaps and unmaps a cached address.
@ -5159,6 +5381,13 @@ void build_descriptors(const NvnState& s, const Program& p) {const uint32_t handle = is_table ? table[k]: (st.vk_stage == VK_SHADER_STAGE_FRAGMENT_BIT && handle_is_storage_pointer(info, d, k))? 0u : handle_of(s, st, d, k);const tex_desc_memo::PeekResult peek_res =L2 (should fix): Check mode does not compare the fast path's handle decoding or its touch behavior with the slow path.
When: For a non-table c2 descriptor, check mode computes the handle with handle_of and only peeks at the cache; it never calls c2_handle_of or the fast lookup's touch callback. A decoding or touch regression can therefore produce wrong textures with the default enabled while the live check reports zero mismatches.
Do: Have check mode compare the fast decoded handle and exercise or independently validate the fast lookup's touch and resulting descriptor state; cover those comparisons with a test that fails when each is broken.
@fix
1312ed6fce914c6a204cBeanstalk test farm
Commit
914c6a2· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Recommendation: Approve. The reported gain compares the memo against the PR’s disabled path, so the net gain against main under player settings remains unproven. The other affected Tier 1 systems also need runs, and check mode still does not independently compare texture touches. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
914c6a204c. I rebased it ontomain(d1ce3f3f18). I edited its description to match the change.Changed
Not done
Nothing was built or run: the checks run again on the new head.
The change caches texture descriptors and read-only buffer bindings per recording thread to reduce repeated work. It adds roughly 520 KB of thread-local storage per recording thread and introduces cache invalidation and check-mode complexity.
Should fix (1): not blocking, but worth doing before merging.
gpu/vk/vk_draw.cpp:5384: Check mode's touch expectation comes from the memo's own state rather than the slow path, so it cannot establish equivalent touch behavior. When: On a memo hit, lookup invokes the touch callback before texture_view_of runs; touch_expected merely checks the same cached texture and epoch condition. A difference in the work or state produced by the fast touch can therefore be masked before the slow path is observed. Do: Compare the fast and slow touch decisions and resulting relevant state independently, without the first path changing the state used as the other's reference. (for the author:@fixcouldn't: At gpu/vk/vk_draw.cpp:5475, the expected touch still comes from the memo entry's epoch, and the memo lookup touches shared state before the slow lookup. The slow path does not provide an independent t)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 (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven against main: the reported Windows RTX 4060 A/B run measured a 0.377 ms mean frame-time reduction across 51 periods, but its baseline was the PR with the memo disabled rather than a main build.
Other systems: The renderer change can affect Vulkan systems beyond the tested Windows NVIDIA configuration. Linux and the other affected Tier 1 systems have no reported results.
Switches: RX_VK_TEX_DESC_MEMO is added, defaults to 1, and also accepts 0 and check. The default's net cost and benefit against main and on other affected systems remain unmeasured.
Reviewed:
914c6a204cagainstd1ce3f3f18: Read the fix diff and the relevant descriptor and memo paths; skimmed the rules, PR description, reported runs, tests and base diff. The full changed code was not read: the specified base diff contains 52 files, including changes outside the five files listed in the PR.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run code were executed. The reported Windows check-mode run recorded 32.6 million checks and zero mismatches, but its touch comparison has the limitation described in L2; CI has not run on this head.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
Answering what was still open here after the merge. Line numbers are for main
b4d56f526.L1 (blocking: SSBO memo on virtual addresses):
@fixfixed this in914c6a204and that is what was merged.ssbo_lookupandssbo_storeskip every base at or above1 << 40(gpu/vk/tex_desc_memo.h:337-338and:355), so a virtual pool always goes throughgpu_buffer_bind's translation and contiguity check. This is the same1 << 40virtual-pool boundary thatubo_ssbo_fast.h:82andvk_draw.cpp:382use. The remap and unmap cases are intests/test_tex_desc_memo.py:422. As BeanBot noted, that test models the binder's results; only a game run in a scene with virtual-pool SSBOs exercises the real translation path, and none has been done.L2 (check mode: fast handle decoding and touch): half done.
c2_handle_ofthe way the fast path does (vk_draw.cpp:6104-6108) and compares the result with the slow path's handle (fast_handle == handle,:6188).:6120, throughtex_desc_touch_slow,:5479), and its expected value comes from the memo entry's own epoch (touch_expected,:6187). By the timetexture_view_ofruns on the slow path, the texture has already been touched. A fast touch that skips work the slow path would do (an upload, a destroy-generation bump) therefore still reports 0 mismatches.texture_touch_quickdeclined andtexture_touchdid work); compare the two; and add a test that fails when the memo skips a touch the slow path makes. That needs a follow-up PR checked in the game (RX_VK_TEX_DESC_MEMO=check, 0 mismatches). I'm not opening it now because I can't do that game run here.L3 (base vs head at player settings), L4 (Linux, AMD, Steam Deck): still open. What has run: Windows 11 on an RTX 4060 only,
Market_Childat 1280x720. Check mode logged 32.6M checks and 0 mismatches. The paired HOS_AB compared memo on and off inside the PR build: -0.377 ms, 95% CI +0.057..+0.691 ms. No interleaved base-vs-head runs, no player-settings runs and no other hardware. Beanstalk never posted results: the run on1312ed6was superseded, and914c6a2was not approved. These need the farm or someone with the hardware, on main.Also noticed: the "52 changed files" figure came from diffing against an older base; the merged change is the five files listed. Nothing was run for this comment; the farm runs above have not been done.