d3d12: look up cached shaders without scanning the cache directory #165

Manually merged
github merged 1 commit from gh-pr/165/head into gh-pr/165/base 2026-11-26 06:35:34 +00:00
Owner

@⁠Jerkin42 on GitHub · 2026-11-25 11:42 UTC · original
Jerkin42:fix/cache-lookups → main · +71 −11 · 1 files · 1 commits · merged 2026-11-25 11:44 UTC

Summary

Under Wine, opening a file that is not there reads the whole directory, because names match without regard to case. Each program request asked for several absent names: its session reply (twice), the cache's .sha256 or .unsupported file, and the destination of the rename that published a copy of a cached program to the session directory.

With 39,463 files in the ProjectScarlett cache and 13,812 copies in the session directory, the loader threads were up to 80% busy, three quarters of it in the kernel, with almost no disk reads. perf showed utf8_mbstowcs, hash_short_file_name and readdir64 in Wine.

This lists both directories once and opens only names they hold. It reads the cache's own file instead of a session copy. A translation the host adds after the listing still works: it is requested, and the host answers from its cache.

Measured on ProjectScarlett (RX 9060 XT, RADV, Proton Experimental), one run each: from leaving the first screen to the start of streaming, 3 min 45 s became 1 min 16 s. Kernel time over the busy part fell from about 360% to 170% of a core. Those runs used our tree, an older main with the same change, not this branch. The second run also had a larger Mesa shader cache limit (12 GB) and the first run's driver cache, so not all of the difference need be this change.

Checks

The verify suites d3d12-exports, heaps, draw, mesh, tables, indirect and stream pass on this branch (on 529c52d); 283 Python tests run, 13 skipped, no failures; cargo check for the Windows target. In game, on our tree, 16 translations deleted from the cache just after launch were requested again and came back. The new unit test is compiled but not run here, since it needs the Windows target.

🤖 Generated with Claude Code

**@⁠Jerkin42** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/brcly/TuxBox/pull/165) `Jerkin42:fix/cache-lookups` → `main` · +71 −11 · 1 files · 1 commits · merged 2026-11-25 11:44 UTC ## Summary Under Wine, opening a file that is not there reads the whole directory, because names match without regard to case. Each program request asked for several absent names: its session reply (twice), the cache's `.sha256` or `.unsupported` file, and the destination of the rename that published a copy of a cached program to the session directory. With 39,463 files in the ProjectScarlett cache and 13,812 copies in the session directory, the loader threads were up to 80% busy, three quarters of it in the kernel, with almost no disk reads. `perf` showed `utf8_mbstowcs`, `hash_short_file_name` and `readdir64` in Wine. This lists both directories once and opens only names they hold. It reads the cache's own file instead of a session copy. A translation the host adds after the listing still works: it is requested, and the host answers from its cache. **Measured** on ProjectScarlett (RX 9060 XT, RADV, Proton Experimental), one run each: from leaving the first screen to the start of streaming, 3 min 45 s became 1 min 16 s. Kernel time over the busy part fell from about 360% to 170% of a core. Those runs used our tree, an older main with the same change, not this branch. The second run also had a larger Mesa shader cache limit (12 GB) and the first run's driver cache, so not all of the difference need be this change. ## Checks The `verify` suites d3d12-exports, heaps, draw, mesh, tables, indirect and stream pass on this branch (on 529c52d); 283 Python tests run, 13 skipped, no failures; `cargo check` for the Windows target. In game, on our tree, 16 translations deleted from the cache just after launch were requested again and came back. The new unit test is compiled but not run here, since it needs the Windows target. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Wine matches file names without regard to case, so opening a name that is
absent reads the whole directory to look for another spelling of it. Every
program request asked for several absent names: its session reply (twice),
the cache's .sha256 or .unsupported file, and the destination of the rename
that published a copy of a cached program to the session directory.

With 39,463 files in the ProjectScarlett cache and 13,812 copies in the
session directory, the loader threads spent most of their time in those
scans: up to 80% busy each, three quarters of it in the kernel, with almost
no disk reads. In user space perf showed utf8_mbstowcs,
hash_short_file_name and readdir64.

List both directories once and open only names they hold. Use the cache's
own file instead of a session copy. A translation the host adds after the
listing still works: it is requested, and the host answers from its cache.

Measured on our tree, an older main with the same change, one run each: from
leaving the first screen to the start of streaming, 3 min 45 s became 1 min
16 s, and kernel time over the busy part fell from about 360% to 170% of a
core. The second run also had a larger Mesa shader cache limit and the first
run's driver cache, so not all of the difference need be this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:35:33 +00:00
github manually merged commit 4b4c08cfe7 into gh-pr/165/base 2026-11-26 06:35:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.