Repository navigation
Conversation
VulkanContext::view runs for every colour and depth attachment of every draw and clear the replay records. Its cache was a std::map keyed by a 6-tuple, and destroying an image walked every cached view of every image. ImageViewCache (runtime/src/image_view_cache.h) makes the lookup one hash probe and keeps each image's keys, so a destroy visits only its own views. Same keys, same first-view-wins rule, same views released. image_view_cache_test checks it against the old std::map on fixed and random sequences and benchmarks both (1.7-3.6x faster lookups, 8-500x faster destroys, no allocations on either path, ~155 vs 72 heap bytes per cached view). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows 11 MSVC + dual-GPU review of Environment
Build & Code Audit
Test & Benchmark Results
|
|
Complementary to this, from reading VkImageView view(const ResourceBinding& r, const VkImageSubresourceRange& range) {
std::lock_guard lock(views_mutex_);
const auto key = std::make_tuple(r.image, range.aspectMask, ...);
if (const auto it = views_.find(key); it != views_.end()) return it->second;
A measurement note, since it affects how this change can be validated: I tried to confirm the hash-map delta in |
|
Correction to my earlier note here, because I measured it and the mutex turned out not to be the problem — please ignore that part when reviewing. I added a threaded mode to
So the lock costs nothing measurable at 4 threads, and the sublinear scaling (~2.8x on 4 threads) has some other cause. That kills the What is left, and worth measuring before anyone changes that code: with the mutex gone the scaling does not improve, so the limit is elsewhere — allocator contention, the shared The threaded mode itself is not in this PR; it needs its determinism story (the self-test asserts on counters that several threads increment) before it is worth carrying. |
|
Tested
|
|
Tested Full AI-assisted (Claude Code); I read the full diff before building. |
|
Tested
AI-assisted: yes |
|
Tested 47ae4c9 on RTX 5070 Ti (Blackwell, subgroup 32), NVIDIA 621.01, Windows 11, MSVC 14.44 (VS 2022 17.14 Build Tools), CMake 4.5.1 + Ninja, Vulkan headers fetched, no game copy: pass. I applied the diff to a clone of main at 867d922 (clean git apply) and built image_view_cache_test and d3d12_clear_test. image_view_cache_test: exit 0, "image_view_cache: all checks passed"; its comparison against the old std::map reports (for 1024 images x 4 views) lookup 51.4 -> 21.3 ns and destroy 13175 -> 265 ns with zero allocations in lookups and destroys. d3d12_clear_test, which goes through VulkanContext::view in the changed vulkan_backend.h, ran on the GPU with exit 0 (3D RTVs match WARP, castable RTVs, 232 RTV/DSV clear readbacks matched WARP). No meaningful negative control exists for the new test, since it includes the new header, which main lacks; I did not do a mutation run. The timings are from a loaded machine and only indicative. Only these two targets were run, not the full ctest set. AI-assisted (Claude Code): checked by applying the diff to a private clone of main and building and running the tests above. No game data was used. |
Item: PERF-VIEW-CACHE (claimed in #7913)
VulkanContext::viewhands the replay aVkImageViewfor every colour and depth attachment of every draw and clear (vulkan_replay.hcalls it throughReplayFunctions::image_view). Two costs, both underviews_mutex_:std::mapkeyed by a 6-tuple (image, aspect, mip, layer, layer count, format), so each lookup walked a tree of tuple comparisons.ImageViewCache(runtime/src/image_view_cache.h, standard library only) replaces it:unordered_maplookup per call;erase_imagevisits only that image's views.Behaviour does not change: the key fields are the same, the first view made for a key is kept, and destroy releases the same views through
defer_destroy.resolve_framebuffers_andresolve_passes_are left as they were (rare, small).Measurements
runtime/test/image_view_cache_test.exe --bench, built with clang 21 (llvm-mingw) at RelWithDebInfo on Windows 11. The numbers are the median of 3 runs, oldstd::map→ new cache:The trade-off is memory: about 2.1x the heap per cached view, which is roughly 330 KB more at 4,000 views. These are CPU microbenchmarks of the cache alone. I have no in-game frame-time figure.
Tests
image_view_cache_test(registered in CTest):for_each,clear;std::mapwith its linear destroy scan.ctest --test-dir runtime/build -j8with-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF: 64 of 65 pass, 2 skipped as usual (shader_library_corpus,vk_sync_validation).vk_queue_query_sync, is flaky and not from this change: built from unmodifiedorigin/mainit fails 4 of 6 runs; on this branch, 5 of 6.vk_command_replay,vk_queueandreplay_cpu_bench_selftestpass.scripts/check_no_game_data.pyon the new files andgit diff --check: clean.GPU: NVIDIA (the local Windows 11 machine's driver) for the Vulkan tests in CTest. The change itself is CPU-only.
AI-assisted (Claude Opus 5.5): written and tested by the agent.
🤖 Generated with Claude Code