Shaders: the DXC cache key leaves out whole-line HLSL comments #3373

Closed
KOLESNiii wants to merge 1 commit from upstream-pr/3373 into main
KOLESNiii commented 2026-11-29 11:01:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T11:01:08Z.


The DXC cache key hashed the full HLSL text, including the translator's per-instruction comments. Each console program starts with two v_nop whose 32-bit literal differs between programs with the same code, and the translator writes them as // 0000: v_nop ; lit 0x…. Those comment lines alone gave identical code a new key, so DXC compiled it again. The key now leaves out whole-line // comments; the source DXC compiles is unchanged. Part of #2088.

Measured on a retail game's DXIL cache from a full preparation (25,797 DXC sources, dumped with a throwaway hook under their cache keys):

  • 9,876 of 25,797 compiles produced a byte-identical copy of another entry; every such pair has the same line count and differs only in comment lines.
  • Keyed without whole-line comments: 15,955 keys for 15,921 distinct DXIL. The other 34 are the linked and whole-program forms of the same source, which already share one cache by design (XCL_LINK_MEM, dxc.rs).
  • dxc.exe on 150 random kept + 150 random redundant sources (one thread): 2.14 s vs 0.71 s mean, so the copies are about 17 % of a cold DXC pass. The driver blob store already dedups identical DXIL, so this saves DXC time only.
  • A translator change that only edits annotations no longer invalidates every DXC entry.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: cache_key_for_toolchain hashes the source without whole-line // comments, plus the optimisation level the source length selects (-O3 / -O1 / -O0), so sources whose comments push them over a length threshold do not share an entry. A comment line ending in \, or following a line that does, stays in the key (line splicing makes it code). The key has a new domain tag.
  • Same file: on a miss, an entry written under the old full-text key is adopted (hard-linked to the new name, copied if linking fails), so existing caches stay warm and the startup pack proof (warm_pack), which checks <key>.dxil, finds them.
  • Tests: comment-only differences share a key, code differences and same-line comments do not, spliced lines count, the -O1 bracket splits keys, and an old-key entry is adopted without compiling.

Tested

  • RTX 2070 SUPER (driver 621.40), AMD Ryzen 5 3600XT, Windows 11 Home 10.0.26300, Rust 1.100.1, debug (suite) / release (smoke)
  • cargo test -p xcl --lib gpu::recomp::dxc::: 37 passed, 0 failed, 0 ignored
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 2621 passed, 0 failed, 49 ignored
  • SKIPPED (27): 21 × no wave64, 3 × the per-lane form refusing f16 ops (#1426), 2 × no heap windows (opt-in), 1 × no GPU_UPLOAD heaps

Regression run
Retail game, 60 s, XCL_PREPARE=0 and XCL_PRESS_AT=25:A on both sides, same DXIL cache.

main (d8bd9a38):

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1485 (PresentX 1485)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17687 MB

this PR (39d97735):

xcl-smoke v1
commit: 39d9773580f4d6544d6367eeb1c69d8700475251
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1581)
presents per 2 s (last 3): 61 60 61
device removals: 0
crashes: 0
peak commit: 16912 MB

DXIL cache in report.json: main 107,906 hits / 7 misses, this PR 106,238 hits / 12 misses from the same cache (entries under the old key are adopted, nothing went cold).

Not tested

  • AMD / RDNA4.
  • A cold full preparation with the new key (hours here); the redundant-compile and timing numbers come from the dumped sources and dxc.exe, not from an XCL run.
  • Both smoke runs skipped startup preparation (XCL_PREPARE=0).

AI use

  • Claude Code with Claude Opus 5.5: found the cause from the cache analysis, wrote the change, the tests and this description, and ran the tests and smoke runs listed above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5550061758 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3373). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-29T11:01:08Z. --- The DXC cache key hashed the full HLSL text, including the translator's per-instruction comments. Each console program starts with two `v_nop` whose 32-bit literal differs between programs with the same code, and the translator writes them as `// 0000: v_nop ; lit 0x…`. Those comment lines alone gave identical code a new key, so DXC compiled it again. The key now leaves out whole-line `//` comments; the source DXC compiles is unchanged. Part of #2088. Measured on a retail game's DXIL cache from a full preparation (25,797 DXC sources, dumped with a throwaway hook under their cache keys): - 9,876 of 25,797 compiles produced a byte-identical copy of another entry; every such pair has the same line count and differs only in comment lines. - Keyed without whole-line comments: 15,955 keys for 15,921 distinct DXIL. The other 34 are the linked and whole-program forms of the same source, which already share one cache by design (`XCL_LINK_MEM`, `dxc.rs`). - `dxc.exe` on 150 random kept + 150 random redundant sources (one thread): 2.14 s vs 0.71 s mean, so the copies are about 17 % of a cold DXC pass. The driver blob store already dedups identical DXIL, so this saves DXC time only. - A translator change that only edits annotations no longer invalidates every DXC entry. **What is in it** - `crates/xcl/src/gpu/recomp/dxc.rs`: `cache_key_for_toolchain` hashes the source without whole-line `//` comments, plus the optimisation level the source length selects (-O3 / -O1 / -O0), so sources whose comments push them over a length threshold do not share an entry. A comment line ending in `\`, or following a line that does, stays in the key (line splicing makes it code). The key has a new domain tag. - Same file: on a miss, an entry written under the old full-text key is adopted (hard-linked to the new name, copied if linking fails), so existing caches stay warm and the startup pack proof (`warm_pack`), which checks `<key>.dxil`, finds them. - Tests: comment-only differences share a key, code differences and same-line comments do not, spliced lines count, the -O1 bracket splits keys, and an old-key entry is adopted without compiling. **Tested** - RTX 2070 SUPER (driver 621.40), AMD Ryzen 5 3600XT, Windows 11 Home 10.0.26300, Rust 1.100.1, debug (suite) / release (smoke) - `cargo test -p xcl --lib gpu::recomp::dxc::`: 37 passed, 0 failed, 0 ignored - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 2621 passed, 0 failed, 49 ignored - SKIPPED (27): 21 × no wave64, 3 × the per-lane form refusing f16 ops (#1426), 2 × no heap windows (opt-in), 1 × no GPU_UPLOAD heaps **Regression run** Retail game, 60 s, `XCL_PREPARE=0` and `XCL_PRESS_AT=25:A` on both sides, same DXIL cache. main (`d8bd9a38`): ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1485 (PresentX 1485) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 17687 MB ``` this PR (`39d97735`): ``` xcl-smoke v1 commit: 39d9773580f4d6544d6367eeb1c69d8700475251 gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1581 (PresentX 1581) presents per 2 s (last 3): 61 60 61 device removals: 0 crashes: 0 peak commit: 16912 MB ``` DXIL cache in `report.json`: main 107,906 hits / 7 misses, this PR 106,238 hits / 12 misses from the same cache (entries under the old key are adopted, nothing went cold). **Not tested** - AMD / RDNA4. - A cold full preparation with the new key (hours here); the redundant-compile and timing numbers come from the dumped sources and `dxc.exe`, not from an XCL run. - Both smoke runs skipped startup preparation (`XCL_PREPARE=0`). **AI use** - Claude Code with Claude Opus 5.5: found the cause from the cache analysis, wrote the change, the tests and this description, and ran the tests and smoke runs listed above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KOLESNiii commented 2026-11-29 11:03:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T11:03:55Z.


Duplicate of #3241 (same cause, opened earlier), which this should be closed in favour of. The measurements and the old-key adoption from this PR are offered there: https://github.com/xcl-dev/xcl/pull/3241

Written with Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7254855678 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3373#issuecomment-7254855678). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-29T11:03:55Z. --- Duplicate of #3241 (same cause, opened earlier), which this should be closed in favour of. The measurements and the old-key adoption from this PR are offered there: https://github.com/xcl-dev/xcl/pull/3241 Written with Claude Code (Claude Opus 5.5).

Pull request closed

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
xcl-dev/xcl!3373
No description provided.