startup: list the shader cache once and skip absent mesh57 profiles #3433

Merged
JohnConnorNPC merged 1 commit from upstream-pr/3433 into main 2026-11-29 08:10:43 +00:00
JohnConnorNPC commented 2026-11-29 07:23:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T07:23:42Z.


Since 71844ba0 (#3094), with X2W_NATIVE_SHADERS set, every device slot-57 pipeline creation opens <variant>.mesh57-state in X2W_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-time FindFirstFileExW listing 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 except ERROR_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_mesh57 skips the open when the listing has no such name. It is the only converted lookup.
  • The first lookup logs x2w-draw cache index: <n> names in <ms> ms, or the listing error.
  • x2w_d3d12_mesh57_profile_stats exports the lookup and open counts for the fixtures.

Behaviour change: a .mesh57-state profile written while the process runs is read by the next process. docs/startup-runtime.md (X2W_SHADER_CACHE) and docs/experiments/native-fixed-mesh57.md say so.

Measured (Wine only)

What Result Source
One missing-name open, 273,716-file cache root 151.3 / 144.8 / 145.0 ms startup_cache_index_check --measure <dir>, 3 runs on this commit
Consecutive missing-name lookups in a 273,723-entry cache root ~155 ms apart file-access trace of a startup run (4 consecutive misses at 2.178 / 2.334 / 2.487 / 2.645 s)
Lookups of existing names, same trace ~8 ms apart on average (median 3 ms) same trace, 2,683 distinct req_<key>.c67 names
One listing of the 273,716-file cache root 2,281 ms on the first run, then 1,175 and 1,212 ms --measure, same 3 runs
Lookup after the listing 0.001 ms --measure

The two miss figures come from different methods. --measure times one CreateFileW of 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. The native_fixed_mesh57* fixtures now add 2,000 other cache files and 64 profile-less pipelines, and require 66 lookups with 2 opens.

ctest --preset dev --no-tests=error -R '^startup_cache_index' -V
ctest --preset dev --no-tests=error -R '^native_fixed_mesh57' -V
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

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 adf532c5, on main 212d4b5f.

Test Result
startup_cache_index pass, startup_cache_index_check: 0 failed
startup_cache_index_per_call_control fails as required (exit 1): FAIL: (a) 515 disk probes for 515 lookups of missing profiles, expected 0, no FAIL: (b)–(h)
native_fixed_mesh57{,_mrt,_varying,_uint_heap,_pixel_heap,_waterfall,_waterfall_fine,_buffers,_constant,_mask}_hardware 10/10 pass, each native fixed mesh profile lookups 66, opens 2 (2 profiles, 2000 other cache files)
native_fixed_mesh57*_warp not run: no WARP under Wine
docs_links_check.py, bidi_controls_check.py pass

Negative control for the fixture change: with the absent-name return disabled (... == CacheLookup::absent && false), all 10 hardware variants fail with profile 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 (71844ba0).

AI-assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5548603219 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3433). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T07:23:42Z. --- Since 71844ba0 (#3094), with `X2W_NATIVE_SHADERS` set, every device slot-57 pipeline creation opens `<variant>.mesh57-state` in `X2W_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-time `FindFirstFileExW` listing 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 except `ERROR_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_mesh57` skips the open when the listing has no such name. It is the only converted lookup. - The first lookup logs `x2w-draw cache index: <n> names in <ms> ms`, or the listing error. - `x2w_d3d12_mesh57_profile_stats` exports the lookup and open counts for the fixtures. Behaviour change: a `.mesh57-state` profile written while the process runs is read by the next process. `docs/startup-runtime.md` (`X2W_SHADER_CACHE`) and `docs/experiments/native-fixed-mesh57.md` say so. ## Measured (Wine only) | What | Result | Source | |---|---|---| | One missing-name open, 273,716-file cache root | 151.3 / 144.8 / 145.0 ms | `startup_cache_index_check --measure <dir>`, 3 runs on this commit | | Consecutive missing-name lookups in a 273,723-entry cache root | ~155 ms apart | file-access trace of a startup run (4 consecutive misses at 2.178 / 2.334 / 2.487 / 2.645 s) | | Lookups of existing names, same trace | ~8 ms apart on average (median 3 ms) | same trace, 2,683 distinct `req_<key>.c67` names | | One listing of the 273,716-file cache root | 2,281 ms on the first run, then 1,175 and 1,212 ms | `--measure`, same 3 runs | | Lookup after the listing | 0.001 ms | `--measure` | The two miss figures come from different methods. `--measure` times one `CreateFileW` of 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. The `native_fixed_mesh57*` fixtures now add 2,000 other cache files and 64 profile-less pipelines, and require 66 lookups with 2 opens. ```powershell ctest --preset dev --no-tests=error -R '^startup_cache_index' -V ctest --preset dev --no-tests=error -R '^native_fixed_mesh57' -V python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` 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 adf532c5, on main 212d4b5f. | Test | Result | |---|---| | `startup_cache_index` | pass, `startup_cache_index_check: 0 failed` | | `startup_cache_index_per_call_control` | fails as required (exit 1): `FAIL: (a) 515 disk probes for 515 lookups of missing profiles, expected 0`, no `FAIL: (b)`–`(h)` | | `native_fixed_mesh57{,_mrt,_varying,_uint_heap,_pixel_heap,_waterfall,_waterfall_fine,_buffers,_constant,_mask}_hardware` | 10/10 pass, each `native fixed mesh profile lookups 66, opens 2 (2 profiles, 2000 other cache files)` | | `native_fixed_mesh57*_warp` | not run: no WARP under Wine | | `docs_links_check.py`, `bidi_controls_check.py` | pass | Negative control for the fixture change: with the absent-name return disabled (`... == CacheLookup::absent && false`), all 10 hardware variants fail with `profile 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 (71844ba0). AI-assisted
Leyukaka commented 2026-11-29 07:47:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T07:47:27Z.

Review: COMMENTED


Reviewed adf532c5 by reading the diff; nothing was built or run. The gate looks correct. Two coverage gaps and one nit.

  • prepare_native_mesh57 returns before the open only on CacheLookup::absent (src/startup_stubs/native_mesh57.inl:259). absent needs a usable listing, the same directory string, and a name hash in neither listed_ nor written_ (cache_index.h:101-104); unknown and present reach the existing std::ifstream open. A listed name always has its hash in the set, so a collision can only report a missing name as present, which takes the existing missing-file return. No refusal is removed. On main the fixture writes both .mesh57-state profiles (tests/startup_indirect_draw_indexed.cpp:2167, 2246) before its first create(), and nothing in src writes 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 pr and ctest --preset pr (windows.yml:489-493). The pr build targets do not include startup_cache_index_check, and the pr test filter matches neither startup_cache_index* nor native_fixed_mesh57_*. This also holds for the presets on main at eab7180c. Could you post a Windows run of ctest --preset dev -R '^(startup_cache_index|native_fixed_mesh57(_[a-z_]+)?_warp)'?
  • startup_cache_index_per_call_control mutates load() in the test (tests/startup_cache_index_check.cpp:59-68), which is the test's own copy of the gate. The runtime cache_lookup (d3d12_draw.inl:270: environment read, name format) and the gate at native_mesh57.inl:259 are exercised only by the native_fixed_mesh57_* fixtures (66 lookups, 2 opens), so those are the tests that would catch a change there.
  • The ERROR_FILE_NOT_FOUND branch (cache_index.h:163) is probably not reached by (f): FindFirstFileExW on <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 adf532c5 onto main at eab7180c is clean.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6101962321 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3433#pullrequestreview-6101962321). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T07:47:27Z. **Review:** COMMENTED --- Reviewed adf532c5 by reading the diff; nothing was built or run. The gate looks correct. Two coverage gaps and one nit. - `prepare_native_mesh57` returns before the open only on `CacheLookup::absent` (src/startup_stubs/native_mesh57.inl:259). `absent` needs a usable listing, the same directory string, and a name hash in neither `listed_` nor `written_` (cache_index.h:101-104); `unknown` and `present` reach the existing `std::ifstream` open. A listed name always has its hash in the set, so a collision can only report a missing name as `present`, which takes the existing missing-file return. No refusal is removed. On main the fixture writes both `.mesh57-state` profiles (tests/startup_indirect_draw_indexed.cpp:2167, 2246) before its first `create()`, and nothing in `src` writes 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 pr` and `ctest --preset pr` (windows.yml:489-493). The `pr` build targets do not include `startup_cache_index_check`, and the `pr` test filter matches neither `startup_cache_index*` nor `native_fixed_mesh57_*`. This also holds for the presets on main at eab7180c. Could you post a Windows run of `ctest --preset dev -R '^(startup_cache_index|native_fixed_mesh57(_[a-z_]+)?_warp)'`? - `startup_cache_index_per_call_control` mutates `load()` in the test (tests/startup_cache_index_check.cpp:59-68), which is the test's own copy of the gate. The runtime `cache_lookup` (d3d12_draw.inl:270: environment read, name format) and the gate at native_mesh57.inl:259 are exercised only by the `native_fixed_mesh57_*` fixtures (66 lookups, 2 opens), so those are the tests that would catch a change there. - The `ERROR_FILE_NOT_FOUND` branch (cache_index.h:163) is probably not reached by (f): `FindFirstFileExW` on `<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 adf532c5 onto main at eab7180c is clean.
tedin7 commented 2026-11-29 08:10:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-29T08:10:40Z.

Review: COMMENTED


Reviewed adf532c5eb70d2b0e1b58e0b60944b7154f6c379:

  • src/startup_stubs/cache_index.h: adds CacheNameIndex (sorted FNV-1a-64 hashes of ASCII-lowercased top-level file names) and CacheDirectoryIndex (std::call_once FindFirstFileExW listing, present/absent/unknown lookup, add(), and count_contradiction()).
  • src/startup_stubs/d3d12_draw.inl & src/startup_stubs/native_mesh57.inl: prepare_native_mesh57 checks cache_lookup(L"", variant, L".mesh57-state") and skips opening absent profiles; exports x2w_d3d12_mesh57_profile_stats for 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-call negative control (startup_cache_index_per_call_control), concurrent first lookups, and native_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 *_hardware skipped)
  • 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 *_hardware skipped)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102030796 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3433#pullrequestreview-6102030796). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-29T08:10:40Z. **Review:** COMMENTED --- Reviewed `adf532c5eb70d2b0e1b58e0b60944b7154f6c379`: - `src/startup_stubs/cache_index.h`: adds `CacheNameIndex` (sorted FNV-1a-64 hashes of ASCII-lowercased top-level file names) and `CacheDirectoryIndex` (`std::call_once` `FindFirstFileExW` listing, `present`/`absent`/`unknown` lookup, `add()`, and `count_contradiction()`). - `src/startup_stubs/d3d12_draw.inl` & `src/startup_stubs/native_mesh57.inl`: `prepare_native_mesh57` checks `cache_lookup(L"", variant, L".mesh57-state")` and skips opening absent profiles; exports `x2w_d3d12_mesh57_profile_stats` for 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-call` negative control (`startup_cache_index_per_call_control`), concurrent first lookups, and `native_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 `*_hardware` skipped) - `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 `*_hardware` skipped) AI-assisted; commands listed were executed locally.
JohnConnorNPC commented 2026-11-29 08:19:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T08:19:40Z.


Thanks @Leyukaka for the review, and @tedin7 for the Windows run and the merge.

Windows run. tedin7's run at adf532c5 answers this one: Windows Server 2025 (build 26100), MSVC 14.44 with WARP, 12/22 passed, and the 10 *_hardware variants skipped. All I had were Wine runs: a clang-cl 19 build under Proton wine-11.0 with vkd3d-proton 3.2. There, startup_cache_index, its per-call control and the 10 native_fixed_mesh57*_hardware variants gave 12/12, and the *_warp variants could not run. I also checked the presets. As you said, the pr build targets don't include startup_cache_index_check, and the pr test filter matches none of these tests, so CI doesn't run them.

per_call_control. Agreed. It mutates the test's own load(), so it guards the header, not the stand-in. The runtime path (cache_lookup's environment read and name format, and the gate in prepare_native_mesh57) is covered only by the native_fixed_mesh57_* fixtures. Their control: I built adf532c5 with the gate disabled (== CacheLookup::absent && false), and all 10 hardware variants failed with native fixed mesh profile lookups 66, opens 66.

ERROR_FILE_NOT_FOUND. Confirmed. I removed that line in a scratch copy and rebuilt startup_cache_index_check. Under Wine it still printed 0 failed, (f) included, because the empty directory lists . and .., so the branch is never taken. Only a directory with no entries at all, such as an empty volume root, could reach it.

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 a09c01d6 on my fork's branch startup/cache-index-mesh57. It drops the ERROR_FILE_NOT_FOUND branch, so a listing with no entries leaves the index unknown and the profile lookup goes to the disk, as before #3433. It says so in both comments, and it changes the (a) comment to 515. At a09c01d6, the same Wine runs gave 12/12 and tests/bidi_controls_check.py passed. I can open it as a small follow-up PR if you want it.

AI-assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7253032612 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3433#issuecomment-7253032612). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-29T08:19:40Z. --- Thanks @Leyukaka for the review, and @tedin7 for the Windows run and the merge. **Windows run.** tedin7's run at adf532c5 answers this one: Windows Server 2025 (build 26100), MSVC 14.44 with WARP, 12/22 passed, and the 10 `*_hardware` variants skipped. All I had were Wine runs: a clang-cl 19 build under Proton wine-11.0 with vkd3d-proton 3.2. There, `startup_cache_index`, its per-call control and the 10 `native_fixed_mesh57*_hardware` variants gave 12/12, and the `*_warp` variants could not run. I also checked the presets. As you said, the `pr` build targets don't include `startup_cache_index_check`, and the `pr` test filter matches none of these tests, so CI doesn't run them. **`per_call_control`.** Agreed. It mutates the test's own `load()`, so it guards the header, not the stand-in. The runtime path (`cache_lookup`'s environment read and name format, and the gate in `prepare_native_mesh57`) is covered only by the `native_fixed_mesh57_*` fixtures. Their control: I built adf532c5 with the gate disabled (`== CacheLookup::absent && false`), and all 10 hardware variants failed with `native fixed mesh profile lookups 66, opens 66`. **`ERROR_FILE_NOT_FOUND`.** Confirmed. I removed that line in a scratch copy and rebuilt `startup_cache_index_check`. Under Wine it still printed `0 failed`, (f) included, because the empty directory lists `.` and `..`, so the branch is never taken. Only a directory with no entries at all, such as an empty volume root, could reach it. **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 a09c01d6 on my fork's branch `startup/cache-index-mesh57`. It drops the `ERROR_FILE_NOT_FOUND` branch, so a listing with no entries leaves the index unknown and the profile lookup goes to the disk, as before #3433. It says so in both comments, and it changes the (a) comment to 515. At a09c01d6, the same Wine runs gave 12/12 and `tests/bidi_controls_check.py` passed. I can open it as a small follow-up PR if you want it. AI-assisted
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3433
No description provided.