Repository navigation
startup: list the shader cache once and skip absent mesh57 profiles - #3433
Conversation
With X2W_NATIVE_SHADERS set, every slot-57 pipeline creation opened <variant>.mesh57-state in the cache root. The file almost never exists, and under Wine each missing-name open in a ~274k-entry cache directory costs ~145 ms, so slot-57 creation fell to ~18 per second. Add src/startup_stubs/cache_index.h: a one-time FindFirstFileExW listing of the cache's top-level files, kept as sorted FNV-1a-64 hashes of the ASCII-lowercased names. A lookup answers present, absent or unknown; unknown (failed or missing listing, another directory) falls back to the disk. add() and a contradiction counter cover the runtime's own writes. The first lookup logs "x2w-draw cache index: <n> names in <ms> ms". Only the mesh57 profile lookup uses the index here. Behaviour change: a mesh57 profile written while the process runs is read by the next process. Measured under Wine on a 273,716-file cache: one listing ~1.2 s, one missing-name open ~145 ms. Tests: startup_cache_index (deviceless) and its per-call control, which must fail on the disk-probe count; native_fixed_mesh57* now add 2000 other cache files and 64 profile-less pipelines and require 2 opens for 66 lookups.
Leyukaka
left a comment
There was a problem hiding this comment.
Reviewed adf532c by reading the diff; nothing was built or run. The gate looks correct. Two coverage gaps and one nit.
prepare_native_mesh57returns before the open only onCacheLookup::absent(src/startup_stubs/native_mesh57.inl:259).absentneeds a usable listing, the same directory string, and a name hash in neitherlisted_norwritten_(cache_index.h:101-104);unknownandpresentreach the existingstd::ifstreamopen. A listed name always has its hash in the set, so a collision can only report a missing name aspresent, which takes the existing missing-file return. No refusal is removed. On main the fixture writes both.mesh57-stateprofiles (tests/startup_indirect_draw_indexed.cpp:2167, 2246) before its firstcreate(), and nothing insrcwrites one, so no existing test depends on a profile written after the first lookup.- The Windows job does not run the new or changed assertions. On pull requests it runs
cmake --build --preset prandctest --preset pr(windows.yml:489-493). Theprbuild targets do not includestartup_cache_index_check, and theprtest filter matches neitherstartup_cache_index*nornative_fixed_mesh57_*. This also holds for the presets on main at eab7180. Could you post a Windows run ofctest --preset dev -R '^(startup_cache_index|native_fixed_mesh57(_[a-z_]+)?_warp)'? startup_cache_index_per_call_controlmutatesload()in the test (tests/startup_cache_index_check.cpp:59-68), which is the test's own copy of the gate. The runtimecache_lookup(d3d12_draw.inl:270: environment read, name format) and the gate at native_mesh57.inl:259 are exercised only by thenative_fixed_mesh57_*fixtures (66 lookups, 2 opens), so those are the tests that would catch a change there.- The
ERROR_FILE_NOT_FOUNDbranch (cache_index.h:163) is probably not reached by (f):FindFirstFileExWon<dir>\*in an empty non-root directory returns.and.., so the handle is valid and the loop skips both as directories. Removing the branch would likely leave (f) passing. - Nit: tests/startup_cache_index_check.cpp:4 says 514 lookups; the code does 512 + 3 = 515, as the messages at lines 154-155 say.
git merge-tree --write-tree of adf532c onto main at eab7180 is clean.
tedin7
left a comment
There was a problem hiding this comment.
Reviewed adf532c5eb70d2b0e1b58e0b60944b7154f6c379:
src/startup_stubs/cache_index.h: addsCacheNameIndex(sorted FNV-1a-64 hashes of ASCII-lowercased top-level file names) andCacheDirectoryIndex(std::call_onceFindFirstFileExWlisting,present/absent/unknownlookup,add(), andcount_contradiction()).src/startup_stubs/d3d12_draw.inl&src/startup_stubs/native_mesh57.inl:prepare_native_mesh57checkscache_lookup(L"", variant, L".mesh57-state")and skips opening absent profiles; exportsx2w_d3d12_mesh57_profile_statsfor fixture verification.tests/startup_cache_index_check.cpp&tests/startup_indirect_draw_indexed.cpp: covers 0 disk probes on 515 missing lookups, case-insensitive hits,per-callnegative control (startup_cache_index_per_call_control), concurrent first lookups, andnative_fixed_mesh57*_warp(66 lookups, 2 opens).
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit adf532c5eb70d2b0e1b58e0b60944b7154f6c379:
ctest --preset dev -R '^(startup_cache_index|startup_cache_index_per_call_control|native_fixed_mesh57)' --parallel 3 --no-tests=error --output-on-failure: 12/22 passed (10*_hardwareskipped)ctest --preset release -R '^(startup_cache_index|startup_cache_index_per_call_control|native_fixed_mesh57)' --parallel 3 --no-tests=error --output-on-failure: 12/22 passed (10*_hardwareskipped)
AI-assisted; commands listed were executed locally.
|
Thanks @Leyukaka for the review, and @tedin7 for the Windows run and the merge. Windows run. tedin7's run at adf532c answers this one: Windows Server 2025 (build 26100), MSVC 14.44 with WARP, 12/22 passed, and the 10
Nit. Confirmed: 512 + 3 = 515 lookups, not 514. The PR was merged before I pushed my fix, so neither change is in it. The fix is commit a09c01d on my fork's branch AI-assisted |
Since 71844ba (#3094), with
X2W_NATIVE_SHADERSset, every device slot-57 pipeline creation opens<variant>.mesh57-stateinX2W_SHADER_CACHE. The variant hashes the descriptor and state blocks, so nearly every call asks for a new name, and the file almost never exists. A negative cache would not help.Under Wine, a missing-name open in a large cache directory is expensive, because the case-insensitive lookup reads the whole directory. In a startup run on a 273,723-entry cache, the stand-in made 1,657 such opens (all distinct names, all
STATUS_OBJECT_NAME_NOT_FOUND). Slot-57 creation ran at ~18 per second, ~130 ms per call, for as long as the run lasted.Change
src/startup_stubs/cache_index.h: a one-timeFindFirstFileExWlisting of the cache's top-level files (files only; subdirectories are not indexed), kept as sorted FNV-1a-64 hashes of the ASCII-lowercased names (8 bytes per name). A lookup answers present, absent or unknown. Unknown means the listing failed (any error exceptERROR_FILE_NOT_FOUND) or the lookup names another directory, and the caller looks on disk as before. A hash collision can only report a missing name as present; the caller then opens it and takes its existing missing-file path.add()and a contradiction counter are there for the runtime's own writes; this PR does not use them yet.prepare_native_mesh57skips the open when the listing has no such name. It is the only converted lookup.x2w-draw cache index: <n> names in <ms> ms, or the listing error.x2w_d3d12_mesh57_profile_statsexports the lookup and open counts for the fixtures.Behaviour change: a
.mesh57-stateprofile written while the process runs is read by the next process.docs/startup-runtime.md(X2W_SHADER_CACHE) anddocs/experiments/native-fixed-mesh57.mdsay so.Measured (Wine only)
startup_cache_index_check --measure <dir>, 3 runs on this commitreq_<key>.c67names--measure, same 3 runs--measureThe two miss figures come from different methods.
--measuretimes oneCreateFileWof a missing name. The trace figure is the gap between consecutive lookups on one thread, so it includes the work between them.Caveat: all timings are from Wine (Proton Experimental, wine-11.0) on ext4. I have not measured a missing-name open on Windows/NTFS, where I expect it to be far cheaper. On Windows the index adds one listing per process and changes when a profile becomes visible; it does not change which profiles load.
Tests
New:
startup_cache_index(deviceless) and its per-call control, which probes the disk for every name, as before this change, and must fail on the probe count alone. Thenative_fixed_mesh57*fixtures now add 2,000 other cache files and 64 profile-less pipelines, and require 66 lookups with 2 opens.I don't have MSVC. I built with clang-cl 19 and lld-link against the xwin SDK, and ran the same executables and arguments that those ctest entries register, under Proton wine-11.0 with vkd3d-proton 3.2 (30b0eb9bc). Commit adf532c, on main 212d4b5.
startup_cache_indexstartup_cache_index_check: 0 failedstartup_cache_index_per_call_controlFAIL: (a) 515 disk probes for 515 lookups of missing profiles, expected 0, noFAIL: (b)–(h)native_fixed_mesh57{,_mrt,_varying,_uint_heap,_pixel_heap,_waterfall,_waterfall_fine,_buffers,_constant,_mask}_hardwarenative fixed mesh profile lookups 66, opens 2 (2 profiles, 2000 other cache files)native_fixed_mesh57*_warpdocs_links_check.py,bidi_controls_check.pyNegative control for the fixture change: with the absent-name return disabled (
... == CacheLookup::absent && false), all 10 hardware variants fail withprofile lookups 66, opens 66.Hardware variants: NVIDIA GeForce RTX 4070 Ti SUPER, driver 550.163.01, Debian Linux 6.12 host (no Windows build). The fixture calls
EnableDebugLayer(), but vkd3d-proton does not provide the Windows debug layer's validation.The first fixture process after a fresh wineserver hangs in Vulkan init under this setup, so the runner starts one uncounted warm-up process first. That is a property of the Wine setup, not of this change; it timed out the same way with and without the gate.
Refs #3094 (71844ba).
AI-assisted