Build: hash the translator sources of the tree being built #2789
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2789
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2789"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kalmarv on GitHub · 2026-11-26 13:01 UTC · original
Kalmarv:fix/build-script-source-root→main· +5 −2 · 1 files · 1 commits · opencrates/xcl/build.rshashes the translator sources intoXCL_TRANSLATOR_SOURCE_ID,XCL_PER_LANE_SOURCE_IDandXCL_DIRECT_DXIL_SOURCE_ID, which key the translation cache. It took their root fromenv!("CARGO_MANIFEST_DIR"), the path of the tree that compiled the build script. Cargo names a path package's artifacts by its path relative to the workspace, so worktrees of the repo that share aCARGO_TARGET_DIRshare one build-script binary. When the binary was compiled in tree A and then reran for tree B, it hashed A's sources: B's code got A's ids, and B could load A's cached translations. The script now readsCARGO_MANIFEST_DIRat run time, which Cargo sets to the package being built. Thererun-if-changedpaths were already relative to the package. Found during frame-rate A/B runs, where two worktrees on one target dir shared a DXIL cache.What is in it
Build: hash the translator sources of the tree being built:crates/xcl/build.rsreadsCARGO_MANIFEST_DIRwithstd::env::var_osinstead ofenv!(3 comment lines, 2 changed).Tested
Repro,
cargo check -p xcl --lib: two worktrees of mainb49be18, where B adds one comment line tosrc/gpu/dxil/kernel.rs. A is checked first in a fresh shared target dir, then B; B's own target dir is the reference.XCL_DIRECT_DXIL_SOURCE_IDfrom the build script's output:f0d04875e42b84d5f0d04875e42b84d5gpu/dxil/kernel.rs, shared target dir (Cargo reruns the script)f0d04875e42b84d5(A's)869ae4235dcd0787869ae4235dcd0787869ae4235dcd0787Windows suite at
ed13531, debug,cargo test --workspace --no-fail-fast -- --test-threads=4: 1,431 passed, 4 failed, 47 ignored, 25 SKIPPED notices (21 no wave64, 3 #1426 refusals, 1 no heap windows). The threee2efailures were a missingxcl_testtitle.exe(nocargo build --workspacefirst); after the build all three passed.hle::d3d12x::cpu_writes::tests::writes_land_after_the_queuefailed once withleft: [7, 9] right: [7, 9]and passed 3 of 3 on rerun: it waits only for the first word to read 7 before comparing both, so the second word can still be in flight. This change does not touch it.Windows 11 Pro 26200, RTX 5070 Ti (NVIDIA 610.74), rustc 1.99.0, DXC 1.9.2609.
Tested by others
build.rscompiled once withrustcand run withCARGO_MANIFEST_DIRpointing at a second tree, as when Cargo reuses the build-script binary. With this PR, a comment marker inrecomp/emit.rs,recomp/ssa.rsordxil/kernel.rsof the second tree changed onlyXCL_TRANSLATOR_SOURCE_ID,XCL_PER_LANE_SOURCE_IDorXCL_DIRECT_DXIL_SOURCE_IDrespectively, and one indxil/ops_tests.rschanged none; main's binary changed no id for any marker; run against the first tree, the PR's binary kept the first tree's ids. Not covered by that probe: whether Cargo reruns the script, GPU tests, a title run.Regression run
Title smoke pair, 60 s each, RTX 5070 Ti, NVIDIA 610.74, release builds, beside other jobs on the same machine. Because this change gives every
XCL_*_SOURCE_IDa new value, the PR's build starts with an empty translation cache, so one untimed 60 s run of the PR's build came first, then the usual warm-up run of main, then the pair. Frames 1,250 against 1,281 (98 %), peak commit 23,013 against 20,842 MB (110 %), no crash or device removal.main,
b49be18:This PR,
ed13531:An earlier pair without the PR warm-up failed the commit check: 20,517 against 14,280 MB (144 %), frames 1,394 against 1,549. Its logs show the two sides took different paths, not a slower PR: main stayed on a static screen after about 20 s (no file reads, flat commit), while the PR side went on loading the world (4,688 DirectStorage requests in its last 2 s, 19,215 shader creations against 8,750). Compute pipeline time was similar (1,184 ms against 1,465 ms).
Not tested
xclasFreshand rebuilds nothing, so B's build is A's code and ids (seen in the same repro, before B was touched). That comes from Cargo's mtime check, which no build script can change; a separateCARGO_TARGET_DIRper worktree avoids both.AI use
🤖 Generated with Claude Code
build.rs took the source root from env!("CARGO_MANIFEST_DIR"), fixed when the script is compiled. Worktrees that share a CARGO_TARGET_DIR share that binary (cargo names it by the package's path relative to its workspace), so the XCL_*_SOURCE_ID values hashed the first tree's sources, and a cached translation of one tree could load in another. Read CARGO_MANIFEST_DIR at run time instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>@ettehn on GitHub · 2026-11-26 13:30 UTC · original
Independent Windows check of all three source IDs on
ed13531a2869626a89d0b4b8755fa15c33b0d928againstb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, Windows 11 build 26200, Rust 1.97.1 MSVC.I compiled each revision’s
build.rsonce withrustc --edition=2021, then ran each executable withCARGO_MANIFEST_DIRpointing at the second tree to simulate reuse of the build-script executable. Both unmodified trees produced the same IDs. I added and removed a comment marker in one file at a time in the second tree.recomp/emit.rsXCL_TRANSLATOR_SOURCE_IDchangedrecomp/ssa.rsXCL_PER_LANE_SOURCE_IDchangeddxil/kernel.rsXCL_DIRECT_DXIL_SOURCE_IDchangeddxil/ops_tests.rsAll four controls passed. The PR executable still produced the original IDs when invoked against the first tree while the markers were present in the second. This covers the build script’s source-root selection, all three hash families, and the test-file exclusion. Cargo’s decision to rerun the script, GPU tests, and retail smoke were outside this probe.
OpenAI Codex assisted with the probe and report. The exact model identifier was unavailable in this session.
@Kalmarv on GitHub · 2026-11-26 13:32 UTC · original
@ettehn thank you. Running the build script against a second tree is a cleaner check than my Cargo repro, and it covers all three ids plus the test-file exclusion. It is under Tested by others now. Cargo rerunning the script is covered by the repro in Tested, and the title run by Regression run.
AI use: Claude Code, Claude Opus 5.5 wrote this reply.
@GodlyBDS on GitHub · 2026-11-26 15:36 UTC · original
I found a concrete translated-cache identity mismatch in one archived retail replay built before this fix. The release build based on
082944135cd2b96288470a595861fa608eee08dcplus a local shader patch shared its Cargo target with other worktrees. Its build log records compilation from the intended checkout.I recomputed the source IDs from the archived source revision and patch, then derived the translated-cache namespace using the recorded DXC toolchain and direct-compute mode. The archived executable and its cache growth show the two identities below.
51729fcdc367b2602fefb4d6dc50c458a385e401270fa08753dd401d9485a8ed2fefb4d6dc50c4582be2f94e3e3614c1The runtime added 220 files to the second namespace and zero to the expected one. This establishes a mismatched cache identity in that replay. Individual shader-cache hits and rendering impact remain unresolved.
As a control, I checked a different historical pair that also used a shared Cargo target. The
e877812ebase and the same tree plus theb59d2638texture-placement change both embedded the expected HLSL, per-lane and direct DXIL IDs, and both used the expected namespace37baea7df2f92a9b.AI use — OpenAI Codex (GPT-6 family) audited preserved source patches, executables and cache metadata and prepared this report.
@Decodere on GitHub · 2026-11-26 15:52 UTC · original
Independent Windows 11 / Cargo 1.100 & RTX 4060 (8 GB) release verification of PR #2789 at
ed13531a2869626a89d0b4b8755fa15c33b0d928(parent & merge-baseorigin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). End-to-end Cargo shared-CARGO_TARGET_DIRtwo-worktree reproduction, targeted unit tests, and paired 60 s smoke only; not a full source review.Setup
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200rustc 1.100.0 (0ef1bc386 2026-11-09)/cargo 1.100.0MSVC, DXC1.9.2609.5, release builds, quiet machine (zero concurrent builds/tests during timed runs)Tree A,Tree B) sharing oneCARGO_TARGET_DIR, plus retail workloadtitle: 29640639viascripts/smoke.ps1 -Seconds 60(XCL_NETWORK=0, default flags, no input)End-to-end Cargo 1.100 shared-
CARGO_TARGET_DIRtwo-worktree check (b49be183vsed13531a)Both detached worktrees were created before compiling
build.rsinTree A(cargo check -vv --release -p xcl --lib --message-format=json,build-script-buildfresh: False). One comment line was then appended inTree Bto each hashed source set (crates/xcl/src/gpu/dxbc.rs,crates/xcl/src/gpu/recomp/lower.rs, andcrates/xcl/src/gpu/dxil/bitstream.rs) without touchingbuild.rs, forcing Cargo to markbuild-script-runDirtywhile reusingTree A's compiledbuild-script-buildbinary (fresh: True):build-script-buildfreshXCL_TRANSLATOR_SOURCE_IDXCL_PER_LANE_SOURCE_IDXCL_DIRECT_DXIL_SOURCE_IDb49be183—Tree AFalseDirty(build.rs)699c1853e347d9bb39cdba116441e869f0d04875e42b84d5b49be183—Tree B(edited)TrueDirty(dxbc.rs)699c1853e347d9bb(stale)39cdba116441e869(stale)f0d04875e42b84d5(stale)ed13531a—Tree AFalseDirty(build.rs)699c1853e347d9bb39cdba116441e869f0d04875e42b84d5ed13531a—Tree B(edited)TrueDirty(dxbc.rs)a053e0d91b599a57ada8bcf9eadbcc95456b729fc3a9dc5ded13531a— back toTree A(older mtime)TrueFresh(see note)a053e0d91b599a57ada8bcf9eadbcc95456b729fc3a9dc5db49be183, reusingTree A's build-script binary inTree Bkept all threeXCL_*_SOURCE_IDvalues frozen atTree A's hashes despiteTree B's edited translator sources. Oned13531a,Tree Akeeps exact hash parity withb49be183, and reusing the same compiled binary inTree Brecomputes all three IDs fromTree B.CARGO_TARGET_DIRfingerprint caveat (FYI, outsideenv!fix): Immediately switching back to untouchedTree A(whose file mtimes were older thanTree B's build) under the sameCARGO_TARGET_DIRcaused Cargo1.100.0to reportFresh xcl v0.1.0on the sharedbuild/xcl/f34613a8fd345a29fingerprint, skip re-runningbuild.rs, and replayTree B's cached IDs intoTree A. A quick empirical check addingcargo:rerun-if-env-changed=CARGO_MANIFEST_DIRdid not change this (Cargo checks its own inherited process environment rather than the per-crateCARGO_MANIFEST_DIRit injects into the build script). That remaining case is a Cargo-level shared-target-dir mtime/fingerprint limitation when switching back to an older-mtime worktree without triggering a rebuild, not a flaw in this PR's runtimeCARGO_MANIFEST_DIRread.Targeted release unit tests & build (
ed13531a)cargo test --release -p xcl --lib source_hash: 2 passed, 0 failed, 0 ignored (0.00 s, exit0).cargo build --release -p xcl --bin xcl: clean release build (exit 0).Paired 60 s RTX 4060 smoke (
b49be183vsed13531a)Both runs held steady 60/2 s pacing with
0device removals and0crashes (ed13531atelemetry:6,175 MBpeak /6,114 MBend local VRAM,4,650 MBend non-local VRAM).Base
origin/main(b49be183):PR #2789 head (
ed13531a):Limits of coverage
rustc 1.100.0/cargo 1.100.0MSVC and a single NVIDIA RTX 4060 (8 GB); no Linux/GNU toolchain or cross-compilation test on this host.source_hash, the live Cargo two-worktree repro, release build, and 60 s retail smoke).AI use
Ran the Cargo two-worktree repro,
source_hashunit tests, release build, and paired 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all hashes, Cargo-vvstatuses, test counts, and smoke blocks were extracted directly fromcargo,xcl.log, andscripts/smoke.ps1outputs.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.