Repository navigation
Conversation
|
At head
I added the two assertions below in a temporary checkout of this exact head. Please keep exact-source keys for arbitrary/debug HLSL and enable normalized keys only for a source class whose preprocessor behavior is constrained, or make the normalization preserve all DXC-sensitive line and splice behavior. A regression should compile A into an empty cache, compile B with that cache, assert a miss, and compare B's DXIL with an independent compile. The existing corpus result shows useful deduplication; this check is about preserving its correctness. Two failing regression testsdiff --git a/crates/xcl/src/gpu/recomp/dxc.rs b/crates/xcl/src/gpu/recomp/dxc.rs
index 45d787f8..19d250a9 100644
--- a/crates/xcl/src/gpu/recomp/dxc.rs
+++ b/crates/xcl/src/gpu/recomp/dxc.rs
@@ -1812,6 +1812,20 @@ mod cache_tests {
assert_ne!(key(spliced), key("uint a = 1u; // other \\\nuint b = 2u;\n"));
}
+ #[test]
+ fn cache_key_distinguishes_line_macro_after_comment() {
+ let a = "RWByteAddressBuffer O : register(u0);\n[numthreads(1, 1, 1)]\nvoid main() { O.Store(0, __LINE__); }\n";
+ let b = "RWByteAddressBuffer O : register(u0);\n// differing comment line\n[numthreads(1, 1, 1)]\nvoid main() { O.Store(0, __LINE__); }\n";
+ assert_ne!(cache_key_for_toolchain(a, "main", "cs_6_6", "tc"), cache_key_for_toolchain(b, "main", "cs_6_6", "tc"));
+ }
+
+ #[test]
+ fn cache_key_distinguishes_whitespace_line_splice() {
+ let a = "RWByteAddressBuffer O : register(u0);\n[numthreads(1, 1, 1)]\nvoid main() {\nuint n = 1 // note\n+ 2\n; O.Store(0, n); }\n";
+ let b = a.replacen("// note\n", "// note\\ \n", 1);
+ assert_ne!(cache_key_for_toolchain(a, "main", "cs_6_6", "tc"), cache_key_for_toolchain(&b, "main", "cs_6_6", "tc"));
+ }
+
#[test]
fn cache_key_of_a_long_source_keeps_its_comments() {
// from 1 MiB the length (comments included) picks the -O level (`link_opt_args`)AI use: Codex (GPT-6.2 Sol) reproduced both cases with DXC and ran the exact-head Rust tests; Codex (GPT-6.2 Astra) independently checked the cache-key path. |
|
Cold full preparation data point, this PR together with #3242 (NVIDIA) One cold run of full shader preparation (
Results
What this does not show
A matched cold-run comparison against Measured and written with Claude Code (Claude Opus 5.5). |
9d8ae9b to
65d6bbc
Compare
|
Independent measurement of the same cause, plus one suggestion. #3373 duplicates this PR and will be closed in favour of it. Measured (RTX 2070 SUPER, retail game, the DXIL cache of a full preparation built by 8b957be): I dumped the 25,797 HLSL sources the preparation hands to DXC under their cache keys (dump-only hook, nothing compiled); all 25,797 matched cache entries.
Suggestion: adopt entries written under the old key. With a new key, every existing cache goes cold once after merge: every source is compiled again by DXC (~41,000 CPU-s on this pack), and Measured and written with Claude Code (Claude Opus 5.5). |
|
Thanks @thehollowedone, both cases are real. I reproduced them and fixed them in 65d6bbc (squashed into the PR's one commit, rebased on main d8bd9a3). Confirmed. I added your two tests unchanged at 9d8ae9b: What changed
Tests (debug, RTX 2070 SUPER, DXC from the Windows SDK):
On the new head 65d6bbc:
The description is updated with both blocks. AI use: Claude Code, Claude Opus 5.5, reproduced the cases, wrote the fix and tests, and drafted this reply; the author checked each point. |
|
Current-main audit (2026-11-29): strongest merge candidate in this set. I read the full four-file diff at Cache impact: this changes DXIL cache filenames, so an exact old generated-HLSL entry may miss once after the update. It does not intentionally change the HLSL passed to DXC or the resulting DXIL bytes. Because driver PSO blobs are keyed from the DXIL/descriptor identity, existing PSO blobs should remain reusable when DXC reproduces the same bytes. That makes this substantially safer than an optimizer that changes DXIL. Disposition: mergeable in principle after normal maintainer review; no additional code blocker found in this audit. Review assisted by Codex; exact model name was not exposed in this session. I did not rerun the suite or a full preparation. |
A cold preparation compiled byte-identical DXIL many times: 43 % of its DXC compiles. Each console record starts with two data words, shown in the HLSL as `// 0000: v_nop ; lit 0x...` / `// 000c: ...` comments; they differ per record (an identifier, not code), so programs with the same code had different HLSL text and the key, the full text, differed. Measured (`xcl shaders shaders.rpf --precompile --limit 1500`, a retail game's pack, fresh cache): main wrote 1,601 DXIL files with 919 distinct contents (CS 538 and VS 144 copies); in every identical group the sources differed only in those comment lines. With this change: 919 files, the same 919 contents byte for byte. For programs XCL generates (compile_cached: the recompiler's and emit's HLSL) the key now hashes the code lines: comments (outside string literals) become a space, lines are trimmed, empty lines dropped; line breaks and spaces inside a line stay. DXC still compiles the full text, so its output is unchanged. A source keeps the full-text key (the same key as before) when: - it is 960 KiB or longer: from 1 MiB the length, comments included, picks the -O level (compile_with, link_opt_args); - line numbers could reach the DXIL: it uses __LINE__ or a #line directive (removing a comment line moves the lines below); - it has a backslash before a line break, also with spaces or tabs between, or a ??/ trigraph: DXC splices the next line into a // comment. Any other HLSL keys on its full text: compile_cached_in (a caller's own source) and HLSL a debug hook edited (XCL_DEBUG_PS_SUB, XCL_DEBUG_CS_SUB, XCL_DEBUG_PS_EXPR, XCL_DEBUG_LOD0, the debug colour). Keys of shorter generated sources change once: their DXIL is compiled again on the first run. Builds on the idea of xcl-dev#1582 (closed), which stripped comments for the -O choice but kept the full-text key. The line-number and splice cases were found in review by thehollowedone (tests cache_key_distinguishes_line_macro_after_comment and cache_key_distinguishes_whitespace_line_splice are theirs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65d6bbc to
84bcc5e
Compare
A cold shader preparation runs DXC on byte-identical output many times. On a retail game's pack, a cold full preparation wrote 16,152 DXIL files with only 9,271 distinct contents: 43 % of its DXC compiles produced DXIL the cache already had. Each console record starts with two per-record data words, shown in the HLSL as
// 0000: v_nop ; lit 0x…/// 000c: …comments. The DXIL cache key hashed the full HLSL text, so programs with identical code got different keys.For the HLSL XCL generates (
dxc::compile_cached: the recompiler's andemit's programs), the key now hashes only the code lines: comments outside string literals become a space, lines are trimmed and empty lines dropped. DXC still compiles the full text, so its output is unchanged. A generated source keeps the full-text key (the same key as before) when:-Olevel;__LINE__or a#linedirective;??/trigraph: DXC splices the next line into a//comment.Any other HLSL keeps the full-text key:
compile_cached_in(a caller's own source) and generated HLSL that a debug hook edited (XCL_DEBUG_PS_SUB,XCL_DEBUG_CS_SUB,XCL_DEBUG_PS_EXPR,XCL_DEBUG_LOD0, the debug colour). The line-number and splice cases were found in review by @thehollowedone. The driver cache was already keyed by the DXIL bytes, so this removes repeated DXC work only, not driver compiles.Builds on the idea of #1582 (closed), which removed comments to choose the
-Olevel but kept the full-text key. Independent of #2928, which skips repeated identical-HLSL jobs insideprecompile(). This change catches different HLSL with the same output and doesn't touchprecompile(). Part of #2088.What is in it
crates/xcl/src/gpu/recomp/dxc.rs:cache_key_for_toolchain/generated_cache_key: code-line key forcompile_cached, guarded bycode_lines_keyableandKEY_CODE_LINES_BELOW;cache_key: full-text key forcompile_cached_in;XCL_DXC_SOURCE_DUMP=<dir>(diagnostic, off unless set): writes each source DXC is given to<dir>/<key>.<profile>.hlsl. This is how the offline check's 1,601 sources were dumped, so anyone can recheck which sources share a key.cache_key_leaves_out_comments_and_indentation,cache_key_distinguishes_line_macro_after_commentandcache_key_distinguishes_whitespace_line_splice(the reviewer's),only_sources_whose_line_structure_cannot_reach_the_dxil_drop_their_comments,a_program_compiled_differently_misses_the_cache_of_its_comment_twin(DXC: B compiled after A into the same empty cache misses, and gets the DXIL of an independent compile),cache_key_of_a_long_source_keeps_its_comments,a_linked_program_stays_within_the_code_line_key_margin.crates/xcl/src/gpu/recomp/pso.rs: HLSL edited by a debug hook goes throughcompile_cached_in.crates/xcl/src/shaders.rs: the pack proof recordsgenerated_cache_key, the keycompile_cacheduses.crates/xcl/src/gpu/recomp/emit.rs:mem_accessorsbecomespub(super)for the linked-program test.Tested
cargo build --workspace --tests && cargo test --workspace --no-fail-fast -- --test-threads=4on 84bcc5e (debug; rebased onto main 81bfbf0, run at the same time as the suites of Recompiler: lift literals that differ inside a family (XCL_LIFT_LITERALS) #3262, D3D12.X: port @Saksukella's write-watch changes #2754 and #2891 to main #3242 and Recompiler: the DXIL cache key leaves out comments and indentation #3241): 2735 passed, 8 failed, 49 ignorede2etarget, whose test title had not been built (missing …xcl_testtitle.exe – build first: cargo build --workspace); the other 4 arehle::d3d12x::title_texturestests (a page-count assertion: 11 MiB measured, 16 MiB expected), in code this PR does not touch, which passed in the other two suites run at the same timecargo build --workspace:cargo test -p xcl --test e2e: 5 passed, 0 failed;cargo test -p xcl --lib -- hle::d3d12x::title_textures::tests: 65 passed, 0 failed, 1 ignoredSKIPPEDon this adapter (28): 22 no wave64, 3 f16 instructions refused (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's), 2 no heap windows (opt-inXCL_HEAP_WINDOWS=1), 1 no GPU_UPLOAD heapscargo test -p xcl --lib dxc::cache_tests: 18 passed, 0 failed, 0 ignored)xcl shaders shaders.rpf --precompile --limit 1500into a freshXCL_DXIL_CACHE(XCL_TRANSLATED_CACHE=0):__LINE__,#line,??/or a backslash before a line break, so the 65d6bbc guards leave all their keys as at 9d8ae9b.Regression run
main (d8bd9a3):
this PR's head (65d6bbc):
Both:
scripts/smoke.ps1 -Seconds 60,XCL_PREPARE=0,XCL_PRESS_AT=25:A, run through the local exclusive queue. With preparation off the run compiles few programs, so it checks that nothing breaks, not the dedupe.These runs are on the head before the rebase (65d6bbc); they have not been repeated on 84bcc5e.
Not tested
AI use
🤖 Generated with Claude Code