perf(vk): exact handle staleness, blocks-hash memo, zero depth clears (three from #2273) #2343
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2343
Loading…
Reference in a new issue
No description provided.
Delete branch "omgitsgela/Longshot:vk-switches-veix"
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
Three fixes from Veix's #2273 handover, which asks for its parts to be taken separately, ported to current main on their own. The pull request's disk-cache half is what #2292 is doing more completely; its RAM-cache half waits behind that. These three changes are what #2273's own Deck measurements (its comments) found to be the whole win: against all three forced off under forced VRAM churn, frames over 60 ms 263 to 146 and staged texture MB 3,067 to 1,617.
Exact staleness (RX_VK_EXACT_STALE). The renderer keeps one destroy generation for all textures, so every resolved texture handle goes stale and every draw of the next frame looks its textures up again and rebuilds its descriptors whenever ANY texture went. Veix's note: closing the pause menu costs 11 ms of lookups and 12 ms of descriptor building in the frame after its own targets went, with the render thread 30-40 ms behind for the frames after it. Each destroyed or moved texture is now logged by its creation number (gone_note); a handle whose own texture did not go stands (texture_still_resolved). Placeholder retirement still invalidates every resolved view. The compaction pass names each moved texture instead of invalidating every handle.
RX_VK_EXACT_STALE=0: as before.Blocks hash memo (RX_VK_HASH_MEMO). Every first whole upload of a decoded ASTC texture hashes its blocks, for #1222's reuse: a turn in Kokiri hashed ~1.8 ms of storage a frame, much of it the same texture made again over storage no page of which was written since. The hash is remembered by the storage and the shape with the memory generation it was taken at, and taken without rereading the storage while
memory_written_sincesays the bytes stand — the same guard the capture paths use. The generation is read before the hash, so a write during it makes the memo older than the bytes, never newer. The reuse census line grows the memo's hits and misses.RX_VK_HASH_MEMO=0: as before.Zero depth clears (RX_VK_DEPTH_ZERO). The game draws its shadow maps at one size (816 x 816) and samples them at another (812, 813) over the same memory, so the whole depth texture is read before the GPU ever drew into it, and the CPU route unswizzles 1-9 MB per read (upload_all_zero takes only storage 32 MB and more). Where such a storage reads all zero — 15 of 25 such reads in Veix's Kokiri sample, 469 of them in a Castle Town arm on a Steam Deck — the image is cleared on the GPU instead. The bytes checked are
guest_bytes', exactly what the CPU route would read, and a depth image cleared to 0 is what unswizzling zero storage makes. Ifupload_all_zeroalready checked the storage, this path does not scan it again.RX_VK_DEPTH_ZERO=0: as before.Read first:
vk_texture.cppgone_note/texture_still_resolvedand the three going sites; then thetexture_view_ofcaller's staleness check invk_draw.cpp; thenblocks_hash_memoized; then the zero-depth block at the top ofupload_inner.See #2273 (the handover), #2292 (the disk cache these deliberately do not touch).
Testing
Tested: Steam Deck LCD (Vangogh, Mesa/RADV), desktop mode, Castle Town walk-and-turn arms over the saved Castle Town center file, with the frame log and trace on. The three changes as they stand here were carried by #2273's head
c8430046in that branch's Deck arms (its comment with the arm table): under forced churn (RX_VK_COMPACT_PCT=60) the three on gave frames over 60 ms 146 against 263 with all three forced off, and staged texture MB 1,617 against 3,067; screenshots of the churn arms showed no texture corruption. The paired boots at THIS branch's head against main are running now; the numbers land in Measurements before this goes ready.Still to test:
Measurements
Paired interleaved boots (Steam Deck LCD, Castle Town walk-and-turn, CASTLE_CYCLES=20, frame log): main against this branch, natural play and forced churn (RX_VK_COMPACT_PCT=60), two boots each per condition, medians. Running at branch head; the table lands before ready.
Verdict: to fill: the #2273-head Deck numbers above say the three together are the win; this branch isolates exactly those three.
Risks
Each change ships behind a switch that reverts to the previous behavior at
=0(all three arekillrows in switches.def). Staleness too lax would show as a stale texture surviving a going: destroy_later and the compaction move loop log the texture's creation number, placeholder retirement invalidates all resolved views, and the log is sized past any sweep. A wrong hash memo would need memory_written_since to miss a write — the guard the capture paths already trust. A zero-check false positive cannot happen (the bytes are the CPU route's own), and a false negative only costs the CPU path as before. Player-visible: nothing on update; no saves or options change.Cost: a 16,384-entry going log (uint32), and the hash memo (a bound: cleared past 200,000 entries).
Tested in game: Steam Deck LCD (Vangogh, Mesa/RADV), desktop mode, Castle Town over the saved Castle Town center file, branch head
80670412(its .so built on the Deck): the game boots, walks the turn route and quits clean; the run log carries the new census line with the hash-memo counters and the depth-zero milestone lines (clears fired during the smoke). Paired interleaved arms against a main control build are running on the same Deck now; their table lands in Measurements before this is marked ready.Possibly related, for context:
@review
Recommendation: Request changes. The new depth-zero path bypasses an existing sparse-memory optimization and can turn a known large shadow-map upload into hundreds of milliseconds of work and substantial extra resident memory. The three independent optimizations also need to be separated under the repository’s one-topic rule.
The change keeps unaffected texture handles, memoizes ASTC block hashes, and clears zero depth textures on the GPU. It may reduce texture work, but its gain at this head is unmeasured and the new zero scan regresses large sparse storage.
Blocking (1): must change before merging.
gpu/vk/vk_texture.cpp:2279: The new scan runs before the existing large-zero path and reads every byte, including uncommitted guest-memory holes. (more on the line) Do: Route large eligible storage through the existing hole-aware zero check first, or make this scan skip holes without faulting them in.Should fix (1): not blocking, but worth doing before merging.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1 and L2.Checks: Failing on this head, which is behind its base, where it passes:
Guide screenshots / Guide images and local UI source review (pull_request).@rebase(or@fix) brings it up to date and runs it again; not held against it.More: does it help, other systems, switches, what was read
Does it help: Unproven. The cited Deck result, 263 to 146 frames over 60 ms and 3,067 to 1,617 MB staged, compares switches on another branch under forced churn; paired measurements against the base at this head are still running.
Other systems: The code affects Vulkan texture uploads and handles across Windows and Linux, GPU vendors, and the Steam Deck. The reported head smoke run covers a Deck; Windows and discrete GPUs remain untested. Texture capture, compaction, descriptor reuse, and sparse guest storage share these paths.
Switches: RX_VK_EXACT_STALE, RX_VK_HASH_MEMO, and RX_VK_DEPTH_ZERO are added as kill switches, all on by default and all listed in switches.def. Their defaults need measurements on the affected systems; RX_VK_DEPTH_ZERO currently exposes the large-storage regression.
Reviewed:
80670412eeagainst0e32bc100d: Read the diff and commit messages, AGENTS.md, CONTRIBUTING.md, the pull request template, and the relevant standards. Read the changed functions and surrounding texture upload, capture, image creation, handle lookup, and generation code; skimmed the rest of the large changed code files and switch table. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs, translations, or generated files were changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds, tests, or project scripts were run. The author reports a successful Deck smoke run at head, with paired measurements still in progress.
Overlaps and merge order: The description identifies #2273 as the handover and #2292 as the disk-cache work; no merge dependency for these three changes is established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -2240,0 +2276,4 @@// samples at another (812, 813) over the same memory. The bytes checked are guest_bytes', as the CPU route reads// them; a depth image cleared to 0 is what unswizzling zero storage makes. RX_VK_DEPTH_ZERO=0: offstatic const bool dz_on = [] { const char* e = getenv("RX_VK_DEPTH_ZERO"); return !(e && env_value_off(e)); }();static std::atomic<int64_t> dz_n{0}, dz_bytes{0}, dz_not{0};L1 (blocking): The new scan runs before the existing large-zero path and reads every byte, including uncommitted guest-memory holes.
When: For the documented 288 MB D16 shadow map at Hyrule Field load, the scan touches the mostly empty storage before upload_all_zero can use its hole-aware scan. The existing code records that reading those holes made guest pages resident and took 203–353 ms on a Deck, instead of skipping them.
Do: Route large eligible storage through the existing hole-aware zero check first, or make this scan skip holes without faulting them in.
@fix
80670412eedb61ebaa76Recommendation: Approve. The pull request still combines three independent renderer optimizations, contrary to the one-topic rule. Its performance gain and behavior across the affected Tier 1 systems also remain unmeasured at this head. 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
db61ebaa76. I rebased it ontomain(1b0a17a827). I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The change aims to reduce texture lookup, hashing and depth-upload work. It adds a destruction log, a bounded hash memo and three default-on switches; the reported fix avoids a redundant scan of eligible large textures.
Should fix (1): not blocking, but worth doing before merging.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L2.Checks: they run again on this head (
Guide screenshots / Guide images and local UI source review (pull_request)failed on the last one); a failure shows on the pull request.Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven. The earlier #2273 run reported 263 to 146 frames over 60 ms and 3,067 to 1,617 MB staged under forced churn, but paired runs of this head against its base have not been reported.
Other systems: The texture paths can affect Vulkan drivers on Windows and Linux, including NVIDIA and AMD GPUs and Steam Deck. The reported head smoke run covers Steam Deck; the other affected Tier 1 systems remain untested.
Switches: RX_VK_EXACT_STALE, RX_VK_HASH_MEMO and RX_VK_DEPTH_ZERO are added as default-on kill switches. Their defaults have not yet been supported by measurements across the affected systems.
Reviewed:
db61ebaa76against1b0a17a827: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, the fix diff and the large-zero upload path. The full base diff includes 93 files and was only skimmed; the remaining changed code was not read in full. No docs/review-checklist.md was present.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. The author reports a Steam Deck game smoke run; paired performance runs and other Tier 1 checks are outstanding.
Overlaps and merge order: The description identifies #2273 as the handover and #2292 as overlapping disk-cache work; merge order is not established.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: perf(vk): exact handle staleness, blocks-hash memo, zero depth clears (three from #2273)to perf(vk): exact handle staleness, blocks-hash memo, zero depth clears (three from #2273)