Vulkan: write-back page map hashed by the page number itself #908
No reviewers
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!908
Loading…
Reference in a new issue
No description provided.
Delete branch "perf-identity-hash-wb-pages"
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?
What
The write-back page map
wb_pages(gpu/vk/vk_memory.cpp,uint32_tpage → value) now usesCommon::FastHash<uint32_t>, which is already ingpu/vk/compat/common/container_hash.h. That hashes a page number by its own value. This is a one-line declaration change plus an include.Why
On Windows (MSVC's STL),
std::hash<uint32_t>is a byte-wise FNV-1a. It scatters the run of neighbouring pages that onewb_pages_notecall writes across the whole bucket array, so every page is a cache miss on its bucket and node. With identity hashing, neighbouring pages land in neighbouring buckets.container_hash.hgives the same reason for the GPU thread's other page maps.On a profile of Hyrule Field with the camera rotating (v2.0.2, RX 9070 XT, Ryzen 7 5700X3D),
wb_pages_noteand its lookups are 3.2% of the Presentation (render) thread, matched against the inlined FNV sites inhookshot_vk.dll.On Linux (libstdc++) and llvm-mingw (libc++),
std::hashof an integer is already the identity, so nothing changes there.Testing
R-stub of the real code.
wb_pages_noteandmemory_writeback_valuewere extracted from source and driven with the profile's patterns. ns per page, median of 5:memory_writeback_value)Identical results. Every lookup answer and the final map contents, including the prune pass, are byte-identical across 43 million answers. That includes a run with a hash that always returns 0, so equality still compares the full key.
Expected gain: about 1.2–1.5% of the render thread on Windows.
Game A/B. This change was part of a batch: v2.0.3 plus this, three lifter-side changes and a renderer-only change. Against stock v2.0.3, median of 3 runs each, with equally warm pipeline caches, Hyrule Field rotating went from 69.7 to 68.0 CPU ms per frame. fps, p99 and frames over 50 ms showed no regression. The game A/B did not isolate this change.
Compile.
vk_memory.cppcompiles on currentmainwith the renderer's flags.Not done: a separate A/B of this change alone, and a run on Linux (no change is expected there).
The same identity hash could also go on the
texture_answerslot cache invk_shader.cpp(~1% of the render thread). I left it out becausevk_shader.cppfeeds the shader-cache stamp, so changing it would invalidate everyone's prepared shaders once.🤖 Generated with Claude Code