Skip to content

Shader compile time: DXC compiles without lifetime markers - #1529

Open
Retried wants to merge 2 commits into
xcl-dev:mainfrom
Retried:shader-compile-time
Open

Retried wants to merge 2 commits into
xcl-dev:mainfrom
Retried:shader-compile-time

Conversation

@Retried

@Retried Retried commented Nov 24, 2026 •

Copy link
Copy Markdown

DXC now gets -disable-lifetime-markers for every recompiled program. With HLSL 2021 and SM 6.6 it wraps every local in a lifetime.start / lifetime.end pair. The pair only tells the optimiser that the local is undefined where its scope starts. Without it, the local keeps its last value there, which is one of the values "undefined" already allowed, so no program changes meaning. Programs compile about 6 % faster and their DXIL is 0.6 % smaller. A caller that passes -enable-lifetime-markers (or its own -O) still wins.

Refs #1269

What is in it

  • Tests: retail_pipeline_cost times DXC and the driver per program (crates/xcl/src/gpu/recomp/tests.rs): an ignored test that translates retail records (picked by offset) the way a title gets them, including the split wave64 form, and creates them as compute pipelines. It prints the translation + DXC time, the DXIL size and the driver time. xcl shaders --compile cannot measure the driver: its HLSL is not the split form, and NVIDIA refuses [WaveSize(64)].
  • Recompiler: DXC compiles without lifetime markers (crates/xcl/src/gpu/recomp/dxc.rs): the arguments are now built in arguments(), which adds the flag. Two tests: the exact arguments per size and caller overrides, and a compile with real DXC.

Tested

  • NVIDIA GeForce RTX 2070 SUPER (driver 621.35), Ryzen 7 5800X3D, 32 GB, Windows 10.0.26300.9974, rustc 1.100.0, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)

  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug, XCL_SAMPLE_RPF set): 772 passed, 0 failed, 42 ignored

  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)

  • Compile time on a retail shaders.rpf, before → after:

    measurement before after
    retail_translation_survey, seed 1269, 63 programs, DXC in process (release), b7aa9f3 and this PR run alternately, two rounds; total 62 s / 61 s 58 s / 58 s (−5.7 %)
    same: median / p90 / max 0.24–0.25 / 2.61–2.68 / 9.5–9.6 s 0.23–0.24 / 2.39–2.40 / 9.0–9.1 s
    130 random programs, dxc.exe 141.2 s 133.1 s (−5.7 %), DXIL −0.6 %
    5 heavy compute programs (retail_pipeline_cost), DXC −4 to −16 %
    same, driver (CreateComputePipelineState, DXIL the driver had not seen) −6 to −10 %, one +2 %

    The first version of this description gave 71 s → 64 / 65 s for the sample. The 71 s was measured on an older main, so it was replaced by the alternating runs above.

Regression run

Both runs used an empty XCL_DXIL_CACHE and XCL_TRANSLATED_CACHE=0. Order: main, this PR, main again, and this PR again after the commit message was corrected (same tree). The blocks are the second main run and the last run. The first main run, made while the game files were not yet in the OS file cache, showed 454 frames (same exit, no removals or crashes, peak commit 15737 MB).

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: hehe
seconds: 60
exit: 0x0
frames shown: 1072 (PresentX 1072)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15596 MB
xcl-smoke v1
commit: 3386385bb1b701238b9030a883380adc5ac3e56e
gpu: NVIDIA GeForce RTX 2070 SUPER
title: hehe
seconds: 60
exit: 0x0
frames shown: 1048 (PresentX 1048)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15593 MB

Not tested

  • AMD and Intel GPUs, and the driver time on them; GPUs with wave64.
  • Older DXC versions (the flag exists since 1.6.2106).
  • The smoke run does not show the speedup: after warm-up both runs hold 60 presents per 2 s. The compile measurements above do.
  • Cached DXIL from before stays in use, because the cache key has no flags. It is still valid, but it is not recompiled with the flag until the HLSL changes.

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the tests and this description, and ran the measurements and the test suite on the hardware above.

🤖 Generated with Claude Code

An ignored test for compile-time work (xcl-dev#1269): each record named by its
offset in XCL_SAMPLE_RPF (XCL_RECORDS) is translated and compiled the
way a title gets it (split wave64 on 32-lane GPUs, XCL_RECOMP_WINDOWS),
and then created as a compute pipeline. It prints the translation + DXC
time, the DXIL size and the driver's CreateComputePipelineState time.

`xcl shaders --compile` cannot measure the driver: its HLSL is not the
split form, and NVIDIA refuses [WaveSize(64)]. Run it with
XCL_DXIL_CACHE set to an empty folder and XCL_TRANSLATED_CACHE=0. The
driver keeps its own disk cache, so only DXIL it has not seen gives a
real time. On RTX 2070 SUPER the slowest RT resolve program
(0xd73cab0) takes 9.1 s in DXC and 8.5 s in the driver.

Refs xcl-dev#1269

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Retried
Retried marked this pull request as ready for review November 24, 2026 17:20
@MatyEjsr

Copy link
Copy Markdown

Verified PR #1529 at head commit e06ffce08bdca11410bcba022ec4dbd58f5fbd42 on NVIDIA RTX 3090 (wave32 / split wave64).

Environment

  • OS: Windows 11 Pro for Workstations (10.0.26200, build 26200)
  • CPU: AMD Ryzen 7 7800X3D (8C/8T)
  • GPU: NVIDIA GeForce RTX 3090 (driver 617.42)
  • RAM: 31.4 GB
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), debug build
  • DXC: dxcompiler 1.9.2602.17 (21d28f72), dxil 1.9.2602.17 (Windows SDK 10.0.26100.0)

Tested

  • Clean merge check against origin/main (9e3831e): git merge-tree --write-tree 9e3831e e06ffce exited 0 (no conflicts).
  • cargo build --workspace -j 8: succeeded (10.82s).
  • cargo test --workspace -j 8 -- --test-threads=4: 772 passed, 0 failed, 42 ignored.
    • SKIPPED (4):
      • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
      • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)
      • test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll)
      • uploads_start_from_each_subresources_state (no D3D12 debug layer (0x887A002D))
  • Targeted new tests (arguments_pick_the_level_by_size_and_leave_out_lifetime_markers, dxc_accepts_the_arguments): 2 passed, 0 failed, 0 ignored.
  • Deterministic single-threaded GPU recompiler timing check (cargo test -p xcl --lib gpu::recomp::tests::gpu_ -j 8 -- --test-threads=1, 85 passed, 0 failed, 1 ignored, 2 SKIPPED):
  • Note on high thread counts: under --test-threads=8, gpu_sparse_vram_descriptors_buffers_and_xmem intermittently fails (submit 1 lane 0 mismatch, left 0 vs right 1077) when another test opens UMA concurrently; confirmed pre-existing on main (b7aa9f3, 2/3 runs) and unrelated to PR Shader compile time: DXC compiles without lifetime markers #1529 (passes 3/3 solo and passes under --test-threads=4).

Code review

  • arguments() cleanly isolates DXC argument construction, preserves caller -O* and *lifetime-markers overrides by placing extra last, and leaves the DXIL cache key unchanged so existing cached entries remain valid.
  • retail_pipeline_cost properly drops ManuallyDrop::into_inner(desc.pRootSignature) and stays #[ignore]d behind XCL_SAMPLE_RPF and XCL_RECORDS.

Not tested

  • AMD RDNA / native wave64 and Intel GPUs
  • Release build and older DXC versions
  • D3D12 debug-layer tests (SDK layers DLL not installed)
  • Retail shader pack benchmarks (retail_pipeline_cost, retail_translation_survey) and retail smoke run (XCL_SAMPLE_* unset)

AI use

  • agy with gemini-4-neon-high: ran the builds, test suites, timing comparisons, and code review, and drafted this report.

@nnonno91

Copy link
Copy Markdown

Independent AMD run and lifetime-marker comparison on e06ffce08bdca11410bcba022ec4dbd58f5fbd42.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. Integrated AMD Radeon(TM) Graphics (32.0.21042.62) and NVIDIA GeForce RTX 5090 (32.0.16.1742), selected with XCL_ADAPTER.
  • On AMD with DXC 1.8.2502.11, cargo build --workspace --locked passed. cargo test --locked -p xcl --lib gpu::recomp::dxc::cache_tests -- --test-threads=4 --nocapture passed all 12. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 772 passed, 0 failed, 42 ignored, and zero GPU skips. The bundled title passed.
  • I ran cargo test --locked -p xcl --test lifetime_marker_probe -- --exact lifetime_marker_outputs_match_cpu --nocapture --test-threads=1 using a temporary synthetic compute shader with initialized arrays scoped inside two branches of a loop. In four fresh test processes (DXC 1.8.2502.11 and 1.9.2609.5 on each adapter), XCL compiled to cs_6_6 at -O1 once with the PR default and once with -enable-lifetime-markers. Both versions matched a CPU calculation across all 64 lanes on AMD and 32 on NVIDIA. All unwritten buffer words kept their initial values.
  • dxc.exe -dumpbin showed two llvm.lifetime.start and two llvm.lifetime.end calls when explicitly enabled and zero with the PR default in all four comparisons. The default DXIL was 184 bytes smaller in each pair.

Not tested

Retail shaders, retail title runs, and compile or driver timings. The GPU comparison checks one synthetic shader.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary probe, ran the checks, and drafted this report.

With HLSL 2021 and SM 6.6, DXC puts a lifetime.start / lifetime.end
pair around every local. They only tell the optimiser that a local is
undefined where its scope starts. Without them (-disable-lifetime-markers)
the local holds its last value there, which is one of the values
"undefined" allowed, so no program changes meaning. A caller's own
-enable-lifetime-markers still wins. The DXC arguments are built in
arguments() now, so a test can check them.

Measured on a retail pack, DXC 1.9.2602.17, RTX 2070 SUPER, Ryzen 7 5800X3D:
- seeded sample of 63 programs (retail_translation_survey, seed 1269,
  in-process DXC, main and this commit run alternately, two rounds):
  total 62 / 61 s -> 58 / 58 s (-5.7 %), median 0.24-0.25 -> 0.23-0.24 s,
  p90 2.61-2.68 -> 2.39-2.40 s, max 9.5-9.6 -> 9.0-9.1 s
- 130 random programs, dxc.exe: 141.2 -> 133.1 s (-5.7 %), DXIL -0.6 %
- 5 heavy compute programs as a title compiles them
  (retail_pipeline_cost): DXC -4 to -16 %; driver -6 to -10 %, one +2 %

Cached DXIL from before stays valid (the key has no flags), so nothing
has to be thrown away.

Refs xcl-dev#1269

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Retried
Retried force-pushed the shader-compile-time branch from e06ffce to 3386385 Compare November 24, 2026 18:12
@karthik765

Copy link
Copy Markdown

Tested on AMD Radeon RX 7800 XT with driver 32.0.32029.2010, Windows 11 build 26300.9974, Rust 1.100.0 (MSVC), and DXC 1.9.2602.17.

Both revisions built successfully with cargo build --workspace --locked. Results from cargo test --workspace --locked --no-fail-fast -- --test-threads=4:

Revision Passed Failed Ignored Explicit GPU skips
Upstream merge base b7aa9f3bd212088e0d927439284dc5ed325ce3c7 770 0 41 0
PR head e06ffce08bdca11410bcba022ec4dbd58f5fbd42 772 0 42 0

The native wave64 compute and mesh shader cases and XCL’s synthetic end-to-end title test passed on both revisions. The separate gpu_wave64_ps_whole_wave_reductions run also passed on both with XCL_REQUIRE_GPU=wave64,mesh. The PR’s DXC argument-handling and compiler acceptance tests both passed.

Not tested: Retail game files or shader packs, compile-time speedup, driver pipeline build times, or in-game loading. All XCL_SAMPLE_* variables were unset.

AI use: Codex (GPT-6) ran the tests on the hardware above and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@kais7654

Copy link
Copy Markdown

Ran on the PR's head (3386385): RTX 5070 Laptop (Blackwell, driver 616.87),
Windows 11 26H2, rustc 1.100.0.

cargo build --workspace: ok
cargo test -p xcl --lib gpu::recomp: 191 passed, 0 failed, 19 ignored
(includes the new arguments_pick_the_level_by_size_and_leave_out_lifetime_markers)

One sequencing question: this keeps the >8 MB -O0 band while #1526 removes it —
both touch the same threshold block in dxc.rs, so whichever merges second needs
a rebase of arguments(). Is the intent that #1529 lands first on main and
#1526 rebases on it, or the other way?

Not tested: the 5.7 % compile-time claim itself (no retail pack here), and no
GPU-side check that dropping lifetime markers changes no program's result.
AI use: my local Mistral Vibe agent fetched the branch, ran the build/tests
above and drafted this comment; I checked the diff.

@kleborgn

Copy link
Copy Markdown

Hardware: AMD Radeon RX 7900 XTX (driver 32.0.32029.2010), Ryzen 9 7950X3D, 32 GB, Windows 11 Pro 10.0.26300, rustc 1.100.0; tests in debug, timings in release. DXC 1.8.2505.32 (Windows SDK 10.0.28000.0).

Tested (AMD)

  • Commit 3386385, on its own base: cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 42 ignored. No SKIPPED lines.

  • The same diff applied to main c160d86 (applies cleanly): 860 passed, 0 failed, 43 ignored (main alone: 858 / 0 / 42). SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

  • retail_translation_survey, seed 1269, 1 in 420 (63 programs, 98,123 instructions), DXC in process, release, parent b7aa9f3 and 3386385 run alternately, two rounds each, 0 DXC errors:

    parent this PR
    total 50 s / 50 s 47 s / 49 s
    median 0.23 / 0.24 s 0.22 / 0.23 s
    p90 2.49 / 2.51 s 2.24 / 2.39 s
    max 10.6 / 10.7 s 10.2 / 10.4 s
  • retail_pipeline_cost, three CS_RaytracingResolve_c5cb017e programs (about 72 KB of console code), fresh XCL_DXIL_CACHE, XCL_TRANSLATED_CACHE=0; translation + DXC, parent -> PR (the test file from this PR was copied onto the parent):

    windows DXC DXIL
    1 10.5 -> 9.8 s 818 -> 807 KB
    2 15.9-16.7 -> 13.6-14.9 s 1053 -> 1043 KB
    3 15.3-18.1 -> 14.9-15.9 s 1159 -> 1150 KB

Not tested

  • Driver compile time on AMD: the numbers I have do not separate the PR from run order (whichever side ran first had the faster driver time in all three configurations), so I am not reporting a driver result.
  • Smoke run / retail title (I have the shader pack only), Intel, Nvidia.
  • DXC 1.9.x (the PR author used 1.9.2602.17).

AI use

  • Claude Code, Claude Sonnet 5.5: ran the tests and measurements and drafted this report; the numbers are from real runs on the hardware above.

@Retried

Retried commented Nov 24, 2026

Copy link
Copy Markdown
Author

I am not going to follow this PR up any further. Maintainers can edit the branch, take it over or close it.

On the open question about #1526: the two PRs change the same threshold block in dxc.rs arguments() independently. Whichever lands second needs a small rebase there and keeps both changes: -disable-lifetime-markers from this PR, and the >8 MB band at -O1 from #1526. I have no preference on the order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants