Skip to content

dxc: hash arguments into the DXIL cache key and honor XCL_DXC_ARGS (#559) - #591

Open
Ivankiosan wants to merge 1 commit into
xcl-dev:mainfrom
Ivankiosan:dxc-cache-key-args
Open

Ivankiosan wants to merge 1 commit into
xcl-dev:mainfrom
Ivankiosan:dxc-cache-key-args

Conversation

@Ivankiosan

@Ivankiosan Ivankiosan commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Hash explicit and environment DXC arguments into the DXIL disk cache key, and honor XCL_DXC_ARGS on the cached compilation path. Fixes #559.

Previously, cache_key_for_toolchain only hashed the package version, toolchain identity, profile, entry, and source text, omitting any compiler arguments (extra: &[&str]). Furthermore, compile_cached_in hardcoded an empty argument list &[], ignoring XCL_DXC_ARGS. This caused different optimization levels or custom arguments to collide on the same cache key or be dropped entirely.

This change:

  1. Updates cache_key_for_toolchain and cache_key to append and hash the argument list into the FNV-1a digest. Empty argument lists keep the digest unchanged.
  2. Introduces compile_cached_args to allow callers to pass explicit arguments through the cache.
  3. Plumbs XCL_DXC_ARGS through compile_cached_in so environment-specified arguments reach both the cache key and the compiler.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: hash arguments into cache_key_for_toolchain, expose compile_cached_args, consult XCL_DXC_ARGS in compile_cached_in, and add unit tests verifying key separation and environment variable handling

Tested

  • Hardware: AMD Radeon RX 7600 (8152 MiB VRAM, driver 32.0.32029.2010), AMD x86_64 CPU, Windows 11 Build 26200, rustc 1.100.0 (MSVC), debug & release builds
  • Commands run: cargo test --workspace -- --test-threads=4: 678 passed, 0 failed, 37 ignored
  • SKIPPED GPU tests on adapter: none
  • Title checked: retail title Scarlett retail build (game_scarlett_master.exe)

Regression run

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: AMD Radeon RX 7600
title: xbox
seconds: 20
exit: 0x0
frames shown: 234 (PresentX 235)
presents per 2 s (last 3): 60 60 38
device removals: 0
crashes: 0
peak commit: 10054 MB
xcl-smoke v1
commit: 6c68cc703df3e2d75d5820ee594a4a155ce3ee9e
gpu: AMD Radeon RX 7600
title: xbox
seconds: 20
exit: 0x0
frames shown: 211 (PresentX 213)
presents per 2 s (last 3): 27 52 59
device removals: 0
crashes: 0
peak commit: 9695 MB

Not tested

  • NVIDIA GPUs / Intel Arc GPUs
  • Shaders exceeding 8 MB size threshold under non-default optimization flags

AI use

@fromthemoonx

Copy link
Copy Markdown

NVIDIA run, since Not tested lists NVIDIA GPUs.

Tested

  • Exact head 6c68cc703df3e2d75d5820ee594a4a155ce3ee9e, clean worktree
  • NVIDIA GeForce RTX 3060 (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 687 passed, 0 failed, 41 ignored (lib 647 / 0 / 21)
  • The three new tests passed in that run: cache_key_tracks_the_dxc_arguments, compile_cached_args_distinguishes_argument_lists, compile_cached_in_honors_xcl_dxc_args_env
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • XCL_SAMPLE_* and XCL_DXC_ARGS not set

Not tested

  • A retail title, so no smoke.ps1 run here.
  • Release build; one run of the suite only.

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above and wrote this report from the log.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 6c68cc703df3e2d75d5820ee594a4a155ce3ee9e on AMD RDNA4; the PR was tested on NVIDIA only. I merged it onto current main 18c105a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 692 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 652 passed, 0 failed, 21 ignored
  • 0 SKIPPED; cache_key_tracks_the_dxc_arguments, compile_cached_args_distinguishes_argument_lists and compile_cached_in_honors_xcl_dxc_args_env pass.

Review: An empty argument list keeps the old digest, so existing caches stay valid. One thing in the tests: compile_cached_in_honors_xcl_dxc_args_env sets XCL_DXC_ARGS="-O1" with std::env::set_var in the middle of the xcl lib test binary, which runs with several threads. While it is set, any GPU test compiling through compile_cached / compile_cached_in at the same time reads -O1 from env_dxc_args(), compiles with it and caches under that key. It does not fail anything today, but it makes those runs depend on scheduling. Testing env_dxc_args()'s parsing separately and calling compile_cached_args with an explicit list (as compile_cached_args_distinguishes_argument_lists already does) would keep the environment untouched. Smaller: XCL_DXC_ARGS is split on whitespace, so an argument containing a space cannot be passed.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@KainanP

KainanP commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for wiring XCL_DXC_ARGS into the cache key. I read the diff at 6c68cc7 (not run).

Two things about compile_cached_in_honors_xcl_dxc_args_env:

  1. It sets/removes the process-wide XCL_DXC_ARGS while other tests run in parallel. dxil_cache_round_trip calls compile_cached_in twice and asserts the second is a hit. If the set_var("-O1")/remove_var window falls between those calls, the keys differ ([] vs ["-O1"]) and that test fails intermittently.
  2. It calls compile_cached_in_with(..., &env_dxc_args()...) directly, so the compile_cached_in → env_dxc_args wiring is not actually tested.

Suggestion: split parsing into a pure dxc_args_from(Option<&str>) -> Vec<String> and test that, plus compile_cached_args with explicit lists (already covered), and drop the env mutation. Alternatively, guard every test that touches the variable or compile_cached_in with one shared mutex.

AI use: Claude Code (Claude Opus 5.5) read the diff; not run. Checked by the user before posting.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
Stacked on xcl-dev#591; part of xcl-dev#559. A cached translation can return DXIL before the argument-aware compiler cache is consulted. Bypass RAM and translated-file caches for XCL_DXC_ARGS and replace the process-wide environment test with an isolated real-DXC warm-cache regression.
@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (6c68cc7)

Hardware / environment

  • Commit 6c68cc703df3e2d75d5820ee594a4a155ce3ee9e, verified at detached HEAD.
  • Windows 11 Enterprise Evaluation x64, build 26200, in QEMU. CPU reported by Windows as AuthenticAMD Family 23 Model 113 Stepping 0, approximately 3.9 GHz.
  • Rust 1.100.0 (0ef1bc386), host x86_64-pc-windows-msvc, unoptimized test profile. Loaded DXC compiler and DXIL signer 1.9.2609.5 (compiler revision 01b62ad4).
  • CPU/DXC-only run outside the Arc test wrapper. No GPU mutex was acquired.

Commands and results

  • cargo test --workspace --no-run exited 0. It built the workspace test binaries and executed no tests.
  • With XCL_ADAPTER=NONE_CPU_ONLY, RUST_TEST_NOCAPTURE=1, and XCL_DXC_ARGS initially unset, cargo test -p xcl --lib gpu::recomp::dxc:: -- --test-threads=1 exited 0. The focused log recorded 17 passed, 0 failed, 0 ignored, 0 skipped and 651 filtered out. Skips were counted from case-sensitive lines beginning with SKIPPED .
  • The focused run used one test thread because the environment-variable test changes process-wide state.

Observed behavior

  • The three new tests passed. Different optimization flags and argument token boundaries produced different cache keys. Reusing the same argument list hit the cache. Changing the list or setting XCL_DXC_ARGS=-O1 caused a miss in the synthetic cache tests, and repeating the environment value hit the cache.
  • The installed DXC loaded successfully and compiled a minimal compute shader in the default-argument cache round trip. The repeated request returned identical DXIL from cache.

Not tested

Full GPU workspace suite, game smoke runs, and real DXC compilation with overridden flags. The flag-specific tests used synthetic DXIL.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr591-focused.log and published.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review (OpenAI GPT-6); I inspected the current diff and tests. I did not run tests or the game.

fn env_dxc_args() -> Vec<String> {
std::env::var("XCL_DXC_ARGS")
.ok()
.map(|v| v.split_whitespace().map(String::from).collect())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could XCL_DXC_ARGS use Windows command-line argument parsing, or document the supported quoting format and cover it with a test? With -I "C:\Program Files\DXC Includes", split_whitespace() returns tokens with the quotes attached, so DXC receives a truncated include path and extra arguments. This prevents passing a normal Windows include directory through the new setting. AI-assisted review (OpenAI GPT-6); I inspected the changed argument parsing and tests, and did not run tests or the game.

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.

XCL_DXC_ARGS never reaches the cached compile path; the DXIL cache key also omits the optimisation level

8 participants