Recompiler: canonicalize generated HLSL cache keys #3450

Merged
bmjask merged 6 commits from upstream-pr/3450 into main 2026-11-29 20:20:18 +00:00
bmjask commented 2026-11-29 18:08:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T18:08:22Z.


Canonicalizes generated HLSL before looking up DXIL cache entries, removing duplicate DXC work caused only by comments or outer indentation while preserving exact identity for line-sensitive or debug-edited sources.

Stacked on #3449; only commit db569c7d belongs here.

What is in it

  • Conservative generated-HLSL canonical key with exact fallback for line-sensitive constructs.
  • Legacy exact-key entries are promoted without recompilation.
  • Debug-edited HLSL remains exact-keyed.
  • Tests cover canonical equivalence, line-sensitive fallback, promotion, corruption, concurrency, and debug overrides.

Tested

  • NVIDIA GeForce RTX 4090, driver 610.88; Intel Core i9-12900K; Windows 11 Pro build 26200; Rust 1.100.0, debug and bench profiles.
  • Focused DXC cache tests: 14 passed, 0 failed; debug-override tests: 2 passed, 0 failed.
  • cargo test -p xcl --lib generated_cache -- --test-threads=4: 3 passed, 0 failed.
  • .\scripts\test.ps1 at db569c7d: 2,748 passed, 0 failed, 49 ignored; 29 GPU tests explicitly skipped for unsupported/opt-in hardware paths.

Regression run

xcl-smoke v1
commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
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: 16909 MB
xcl-smoke v1
commit: db569c7d35615e3a785597211fb5208ac6107586
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1564 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15026 MB

Not tested

  • Prepared-corpus activation/AOT behavior in the retail-title smoke: the staged corpus was temporarily absent and XCL_PREPARE=0, so the run exercised the runtime/JIT path only.
  • AMD, wave64, heap-window opt-in, GPU_UPLOAD heaps, or dxil.dll paths.

AI use

  • Codex with GPT-5 implemented and tested the change. The final diff and reported commands were reviewed from this worktree.
<!-- greyfinch-sync:ivall/xcl:issue:5553581825 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3450). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-29T18:08:22Z. --- Canonicalizes generated HLSL before looking up DXIL cache entries, removing duplicate DXC work caused only by comments or outer indentation while preserving exact identity for line-sensitive or debug-edited sources. Stacked on #3449; only commit `db569c7d` belongs here. **What is in it** - Conservative generated-HLSL canonical key with exact fallback for line-sensitive constructs. - Legacy exact-key entries are promoted without recompilation. - Debug-edited HLSL remains exact-keyed. - Tests cover canonical equivalence, line-sensitive fallback, promotion, corruption, concurrency, and debug overrides. **Tested** - NVIDIA GeForce RTX 4090, driver 610.88; Intel Core i9-12900K; Windows 11 Pro build 26200; Rust 1.100.0, debug and bench profiles. - Focused DXC cache tests: 14 passed, 0 failed; debug-override tests: 2 passed, 0 failed. - `cargo test -p xcl --lib generated_cache -- --test-threads=4`: 3 passed, 0 failed. - `.\scripts\test.ps1` at `db569c7d`: 2,748 passed, 0 failed, 49 ignored; 29 GPU tests explicitly skipped for unsupported/opt-in hardware paths. **Regression run** ``` xcl-smoke v1 commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d gpu: NVIDIA GeForce RTX 4090 title: 6ca5cab7 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: 16909 MB ``` ``` xcl-smoke v1 commit: db569c7d35615e3a785597211fb5208ac6107586 gpu: NVIDIA GeForce RTX 4090 title: 6ca5cab7 seconds: 60 exit: 0x0 frames shown: 1564 (PresentX 1564) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15026 MB ``` **Not tested** - Prepared-corpus activation/AOT behavior in the retail-title smoke: the staged corpus was temporarily absent and `XCL_PREPARE=0`, so the run exercised the runtime/JIT path only. - AMD, wave64, heap-window opt-in, GPU_UPLOAD heaps, or `dxil.dll` paths. **AI use** - Codex with GPT-5 implemented and tested the change. The final diff and reported commands were reviewed from this worktree.
andrewDoing commented 2026-11-29 19:03:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T19:03:44Z.


I reproduced a wrong cache hit at db569c7d35615e3a785597211fb5208ac6107586 on an RTX 5070. These two valid HLSL inputs differ only in how the preprocessor sees the newline after 3:

Source prefix Uncached GPU result Result when compiled second on the PR head
#define VALUE 3 /*\n*/ ; 3 8
#define VALUE 3\n; 8 3

Both shaders store value() in a UAV, where value() contains return VALUE + 5;. DXC treats the multiline comment as one space, so its first semicolon remains inside the macro. The bare newline ends the second directive. The PR's canonicalizer instead flushes a line at the newline inside the comment, producing the same key for both sources. I ran both population orders with fresh cache directories. In each order the second source hit the first one's cache entry and fenced readback returned the first source's value. The independent compiler runs and the native readbacks agreed on the correct values above.

The companion fix on my fork keeps block-comment newlines out of directive boundaries and versions the canonical key to avoid reusing entries written under the ambiguous key. With that old key seeded, both orders missed on each distinct input, produced 3 and 8 as expected, and hit correctly on a repeat. All 15 DXC cache tests passed on the fix with zero skips. The regression assertion against the unchanged PR head failed on the wrong GPU value, with the other 14 tests passing.

XCL_ADAPTER=5070 cargo test --offline --locked -p xcl --lib gpu::recomp::dxc::cache_tests -- --test-threads=1 --nocapture on RTX 5070 12 GB (616.92), Ryzen 7 5700X3D, Windows 11 26300.10075, Rust 1.100.0, DXC 1.8.2502.11, debug. This is a synthetic shader/cache regression test. Codex with GPT-6.2 Sol built the fixture, ran the controls and wrote the companion fix.

<!-- greyfinch-sync:ivall/xcl:comment:7260975543 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3450#issuecomment-7260975543). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T19:03:44Z. --- I reproduced a wrong cache hit at `db569c7d35615e3a785597211fb5208ac6107586` on an RTX 5070. These two valid HLSL inputs differ only in how the preprocessor sees the newline after `3`: | Source prefix | Uncached GPU result | Result when compiled second on the PR head | | --- | ---: | ---: | | `#define VALUE 3 /*\n*/ ;` | 3 | 8 | | `#define VALUE 3\n;` | 8 | 3 | Both shaders store `value()` in a UAV, where `value()` contains `return VALUE + 5;`. DXC treats the multiline comment as one space, so its first semicolon remains inside the macro. The bare newline ends the second directive. The PR's canonicalizer instead flushes a line at the newline inside the comment, producing the same key for both sources. I ran both population orders with fresh cache directories. In each order the second source hit the first one's cache entry and fenced readback returned the first source's value. The independent compiler runs and the native readbacks agreed on the correct values above. The [companion fix on my fork](https://github.com/andrewDoing/xcl/commit/a838854aa943caf76e749d53c1c64cf67ccb197e) keeps block-comment newlines out of directive boundaries and versions the canonical key to avoid reusing entries written under the ambiguous key. With that old key seeded, both orders missed on each distinct input, produced 3 and 8 as expected, and hit correctly on a repeat. All 15 DXC cache tests passed on the fix with zero skips. The regression assertion against the unchanged PR head failed on the wrong GPU value, with the other 14 tests passing. `XCL_ADAPTER=5070 cargo test --offline --locked -p xcl --lib gpu::recomp::dxc::cache_tests -- --test-threads=1 --nocapture` on RTX 5070 12 GB (616.92), Ryzen 7 5700X3D, Windows 11 26300.10075, Rust 1.100.0, DXC 1.8.2502.11, debug. This is a synthetic shader/cache regression test. Codex with GPT-6.2 Sol built the fixture, ran the controls and wrote the companion fix.
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!3450
No description provided.