Skip to content

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

Merged
brcly merged 1 commit into
brcly:mainfrom
Jerkin42:fix/cache-lookups
Nov 25, 2026
Merged

brcly merged 1 commit into
brcly:mainfrom
Jerkin42:fix/cache-lookups

Conversation

@Jerkin42

Copy link
Copy Markdown
Contributor

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

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 <noreply@anthropic.com>
@brcly
brcly merged commit 5dd0d84 into brcly:main Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants