Skip to content

DXC: sources over 8 MB use -O1, not -O0 - #1526

Open
speed-y wants to merge 2 commits into
xcl-dev:mainfrom
speed-y:dxc/no-o0-fallback
Open

speed-y wants to merge 2 commits into
xcl-dev:mainfrom
speed-y:dxc/no-o0-fallback

Conversation

@speed-y

@speed-y speed-y commented Nov 24, 2026 •

Copy link
Copy Markdown

Part of #1269 (campaign task C4). HLSL sources over 8 MB used to compile at -O0 as a "safety net". Thread measurements show that roughly doubles DXIL (to ~14–30 MB on the giants) and the driver then stalls; -O1 matches -O3 DXIL size and is already used from 1 MB, so the 8 MB band uses -O1 too.

Follow-up for risks raised on the PR / #1269: sources over 64 MB are refused (neither -O0 nor -O1 finishes the ~147–155 MB ones, and -O1 can hold a worker for tens of minutes), and the DXIL cache key includes the default -O so warm entries from the old -O0 band recompile under -O1.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: default_opt_level — -O1 for every source over 1 MB through 64 MB (drops the >8 MB -O0 branch)
  • refuse HLSL over 64 MB before calling DXC; unit tests for the thresholds and the refuse path
  • DXIL cache key hashes the default -O token (warm-cache miss for the old -O0 band)

Tested

  • RTX 5080 (driver 621.24), Windows 11 25H2, rustc 1.100.0, debug for tests / release for smoke
  • .\scripts\test.ps1 at 31fb65e: 780 passed, 0 failed, 41 ignored; SKIPPED GPU: 2 (no wave64), 1 (no heap windows)
  • cargo test -p xcl --lib -- opt_level_tests cache_key_tracks_the_default: 4 passed

Regression run

Main (9e3831e):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5080
title: 7cf5ae7d
seconds: 60
exit: 0x0
frames shown: 1103 (PresentX 1104)
presents per 2 s (last 3): 29 38 15
device removals: 0
crashes: 0
peak commit: 21846 MB

This PR (31fb65e):

xcl-smoke v1
commit: 31fb65e200f8e4a36f81a0d14250411635b453b6
gpu: NVIDIA GeForce RTX 5080
title: 7cf5ae7d
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 61 60 59
device removals: 0
crashes: 0
peak commit: 15105 MB

Not tested

  • AMD; DXC/driver wall-clock on the 8–64 MB band on this machine after the follow-up (covered by others on 122017d); wave64 / heap-window GPU paths (skipped here)
  • Whether 64 MB is the best refuse cut (chosen above the ~30 MB Probes programs that still get -O1 and below the ~147 MB hang)

AI use

  • Cursor (Composer): original change, follow-up refuse/cache-key, tests, smoke, PR updates

The old -O0 fallback roughly doubled DXIL on the largest programs
(xcl-dev#1269), and the driver then stalled on 14-30 MB blobs. -O1 matches
-O3 DXIL size and is already used from 1 MB, so the 8 MB band uses it
too.

Assisted-by: Cursor (Auto / Composer)
Co-authored-by: Cursor <cursoragent@cursor.com>
@pickles976

Copy link
Copy Markdown

Review from the DXC lane: direction fully endorsed — the -O0 "safety net" was measurably self-harm (its ~2× DXIL is exactly what makes the driver stall, so it amplified the failure it existed to prevent, and -O1 matching -O3 output size at lower DXC time makes the >8 MB band's existence indefensible). The override behavior is right too (extra starting with -O wins, and extras are key inputs). One real gap, and it's the warm-cache twin of the #1472 lesson: the default opt level is not part of the positive cache key (key = content + entry/profile + toolchain identity + extras), so every >8 MB shader already cached from the -O0 era keeps being served its bloated artifact after this PR — users with warm caches do not get the driver-stall fix, silently, which is the worst observability shape for a fix whose whole point is stalls. Options, cheapest first: fold the effective default level (or a small compile-policy version constant, best long-term since it also covers future table changes) into the key; or one-time purge keyed on the old policy. Same invariant as the negative markers, one side over: cache entries are capability/policy-scoped, not just content-scoped — worth one sentence in the module docs either way.

@GonZiin GonZiin 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.

I independently reproduced the warm-cache issue from the earlier review using the public dxc::compile_cached_in path. Including the effective default optimization level in the disk key would make existing entries for this size range recompile under the new policy.

Tested

  • Windows 11 Pro build 26300, Ryzen 7 7800X3D, Radeon RX 9070 XT (driver 32.0.32029.2010), DXC 1.8.2502.11, Rust 1.100.0 MSVC, debug.
  • Base 9e3831e1f570d3646e53ab753b19ec07eb8f1485 compiled an 8,388,854-byte synthetic compute shader into 3,340 bytes of DXIL in an empty cache.
  • Head 122017d1ad52ca27a3f5a8d95c7704cff862e80d reported a cache hit and returned the same 3,340 bytes, verified byte for byte. With a separate empty cache, the same head compiled the same source into a different 3,244-byte blob.
  • cargo test -p xcl --lib opt_level_tests at the PR head reported 1 passed, 0 failed, 0 ignored and 0 skips.

Not tested

Retail shaders, driver PSO timing, and the full workspace on this revision.

AI use

Codex (gpt-6.2-sol) wrote and ran the synthetic probe, ran the threshold test, and wrote this report.

@nnonno91

Copy link
Copy Markdown

Independent cache upgrade test on 122017d1ad52ca27a3f5a8d95c7704cff862e80d with base 9e3831e1f570d3646e53ab753b19ec07eb8f1485.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, AMD Radeon(TM) Graphics (32.0.21042.62), Rust 1.100.0 MSVC, DXC 1.9.2609.5, debug.
  • A temporary integration test called dxc::compile_cached_in in fresh processes via cargo test --locked -p xcl --test opt_policy_probe -- --exact opt_policy_probe --nocapture --test-threads=1. The input was a synthetic compute shader padded with a comment to 8,389,027 bytes so it crossed the old cutoff.
Run Cache hit DXIL bytes
Base, empty cache No 3,292
PR, reusing the base’s cache Yes 3,292
PR, empty cache No 3,008
PR, repeating with its own cache Yes 3,008

Explicit -O0 and -O1 controls matched the 3,292-byte and 3,008-byte outputs byte for byte, respectively. The base and PR used the same cache filename for the large fixture.

I also tested an uncommitted local variant that adds a policy tag to the cache key only above the former 8 MiB cutoff. With a copy of the old cache, it compiled the large fixture once to the same -O1 bytes, then hit that new entry. A second fixture at 7,340,451 bytes still hit its original cache entry. The variant added one file and preserved both existing files.

cargo build --workspace --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output passed on both the unmodified PR and the local variant. Each had 777 passed, 0 failed, 41 ignored, and one reported GPU skip (heap_window_out_of_memory_falls_back_to_the_switch_form, no heap windows). The bundled title passed.

Not tested

Retail shaders, retail title runs, and compile or load times. The padded inputs exercise the cache policy.

AI use

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

@ofc0urse

Copy link
Copy Markdown
Contributor

Test of 122017d on a 32 GB machine, for the risk @throny raised in #1269: the sources over 8 MB do not fit in memory here at -O1, and they did not at -O0 either.

Tested: RTX 4060 Ti 8 GB (32-lane waves), driver 621.24, Core i5-14400F, 32 GB RAM with a system-managed pagefile (commit limit 69.5 GB at the time), Windows 11 Pro 26300, release build. Not a clean head: main 9e3831e + this PR cherry-picked, plus a local log-only patch that prints the start and end of every DXC compile of 4 MB or more and can refuse sources over a size (XCL_DXC_MAX_MB, test only). XCL_HEAP_WINDOWS=1 (#680) in all runs, so the sizes below are the heap form's.

Command: xcl shaders <pack> --precompile --only cs --pipelines, a script beside it killing the process when free commit falls under 5 GB.

run build what happened
A this PR 575 pipelines made, then free commit went from ~48 GB to 4.9 GB in about 2 minutes (297 s after start) and the process was killed
B this PR + XCL_DXC_MAX_MB=8 three sources refused at once: 29.5, 29.6 and 147.4 MB of HLSL. 13 sources of 4.3–4.6 MB built at -O1 in 21–32 s each, several at a time; free commit stayed at 49–52 GB. 725 pipelines made so far, 0 refused, still running

Before this PR, the same three sources went through -O0. In a title run on the same base (main 9e3831e, heap form, world loading), process commit went from 33 GB to 82 GB in about 40 s at ~520 s, with xcl-dxc-0 inside dxcompiler.dll at the time; that run was stopped by hand.

So on this machine neither -O0 nor -O1 gets through these sources: one compile grows by tens of GB in a minute or two, faster than wait_for_memory (which counts ~1 GB per running compile) can react. The 147.4 MB one is most likely the 154.6 MB program coenflict measured, in its heap form.

Not tested: which of the three takes the memory (run B refused them together; run A had no per-compile log yet), whether DXC or the driver held it in run A, AMD, a clean PR head.

AI use: Claude Code (Claude Opus 5.5) ran the builds and runs and wrote this; I checked it before posting.

@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 (122017d): 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::dxc: 15 passed, 0 failed

One question above under 25 min: does this cover throny's 155 MB program? With
this change it also gets -O1, which did not finish in 25 min on that measurement
— is there (or should there be) an upper bound above which we still refuse or
fall back?

Not tested: the full suite on this branch, and the >8 MB programs themselves
(no retail pack here). AI use: my local Mistral Vibe agent fetched the branch,
ran the build/tests above and drafted this comment; I checked the diff.

@throny

throny commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

@kais7654 On 122017d there is no upper bound: default_opt_level returns -O1 for every source over 1 MB, so the 155 MB program gets -O1 too. In my measurement on #1269, -O1 didn't finish it within 25 minutes (RTX 4080 machine, DXC 1.9.2602.17). @kole07139's test of this head on #1269 covers three of the programs over 8 MB: DXC took about 3.9 times as long at -O1 on two of them and the driver still ran out of memory, and the third ran out of memory in DXC at either level.

AI use: Claude Code (Claude Opus 5.5).

@kleborgn

kleborgn commented Nov 24, 2026 •

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.

Tested (AMD), updated for head 31fb65e

  • 31fb65e on its own base: cargo test --workspace -- --test-threads=4: 780 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The same diff applied to main 4178e88 (applies cleanly): 895 passed, 0 failed, 42 ignored, in two full runs (main alone: 891 / 0 / 42).

Earlier head 122017d (superseded)

  • On its own base: 777 passed, 0 failed, 41 ignored.
  • Applied to main c160d86: the first full run failed hle::d3d12x::real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state (assertion left != right failed, real.rs:5825) and cargo stopped there. Three more full runs passed, and that test passed 6 of 6 times alone, also on main alone. Plain main passed 4 of 4 full runs. I did not find the cause; @DavidM1911 reports an intermittent single-test flake under parallel scheduling on unmodified main as well. It did not appear in any of the four runs on 31fb65e or 4178e88.

Not tested

  • Any program over 8 MB of HLSL (none in my sample), DXC and driver time with -O1 there, the new 64 MB refusal on a real program, smoke run, Intel, Nvidia.

AI use

  • Claude Code, Claude Sonnet 5.5: ran the tests and drafted this report.

@LocranKing

Copy link
Copy Markdown

Independent Windows release verification on NVIDIA RTX 3060 Ti (122017d1ad52ca27a3f5a8d95c7704cff862e80d vs base main 9e3831e1f570d3646e53ab753b19ec07eb8f1485).

Setup

  • GPU: NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, wave32), driver 32.0.16.2101
  • CPU / RAM: AMD Ryzen 5 5500 (6C/12T), 31.8 GB RAM
  • OS: Windows 11 Home Single Language, build 26200
  • Toolchain: rustc 1.100.0, DXC 1.9.2602.17, --release

Workspace tests (cargo test --workspace --release --no-fail-fast -- --test-threads=4)

  • Exit 0: 777 passed, 0 failed, 41 ignored across 20 result blocks (SKIPPED: 2 no wave64, 2 no D3D12 debug layer, heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).

Regression run (scripts/smoke.ps1, 60 s, XCL_NETWORK=0, title folder name redacted)

  • PR head vs base main: 1586 / 1566 frames (101.3%), 15199 / 14715 MB peak commit (103.3%), 0 device removals, 0 crashes.

Base (main 9e3831e):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14715 MB

PR head (122017d):

xcl-smoke v1
commit: 122017d1ad52ca27a3f5a8d95c7704cff862e80d
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15199 MB

Not tested: offline cold DXC compile on >8 MB HLSL shaders, AMD / wave64 hardware.

AI use: Antigravity (Gemini 4 Neon) built and ran the test suite and smoke pair on this hardware and drafted this report from the captured outputs; reviewed before posting. No game files attached.

The ~147-155 MB retail sources finish at neither -O0 nor -O1 and can
hold a worker for tens of minutes at -O1 (xcl-dev#1269). Refuse them instead.
Hash the default -O into the DXIL cache key so warm entries from the
old -O0 band recompile under -O1.

Assisted-by: Cursor (Composer)
Co-authored-by: Cursor <cursoragent@cursor.com>
@speed-y

speed-y commented Nov 24, 2026

Copy link
Copy Markdown
Author

@throny @kais7654 @kole07139: pushed 31fb65e for the upper-bound risk.

@GonZiin: the DXIL cache key now hashes the default -O token, so warm entries from the old -O0 band miss and recompile under -O1.

AI use: Cursor (Composer).

@JorgeMJM

Copy link
Copy Markdown

Test report for the -O0 / -O1 choice above 8 MB, on an 8 GB laptop card. Counts and timings only.

Setup: RTX 3070 Laptop 8 GB, NVIDIA 621.40, Ryzen 7 5800H, 28 GB RAM, Windows 11 26300, DXC 1.8.2502.11 (Windows SDK 10.0.26100), release. Retail 1.0.2.1 shaders.rpf, compute programs as a 32-lane GPU gets them (split wave64, 4 memory windows).

Method: not this PR's head but the same choice, forced by a local env override in dxc.rs on main b7aa9f3. One program per process through xcl shaders --precompile --only cs --pipelines, filtered to one record by a local patch, fresh XCL_DXIL_CACHE, XCL_PSO_DISK_CACHE=0, XCL_DXC_THREADS=1, XCL_PIPELINE_THREADS=1, CreateComputePipelineState timed around the call. NVIDIA's own shader cache was left on; every DXIL was built once. One run per row. The 11 MB pair ran with CPU boost off (3.2 GHz), the 28 MB rows with it on.

DXC alone (dxc.exe, -E main -T cs_6_6 -HV 2021), the 5 compute programs over 8 MB except the largest:

HLSL -O0 DXC / DXIL -O1 DXC / DXIL
11.2 MB 77 s / 4.3 MB 906 s / 1.8 MB
11.5 MB 79 s / 4.4 MB 932 s / 1.8 MB
11.9 MB 85 s / 4.6 MB 1034 s / 1.9 MB
28.2 MB 159 s / 20.3 MB 250 s / 8.8 MB
28.2 MB 156 s / 20.3 MB 244 s / 8.8 MB

Driver, through the runtime's path:

HLSL DXIL driver total (translate + DXC + driver) peak private
11.2 MB -O0 5.6 MB 1062 s 1165 s 8.4 GB
11.2 MB -O1 2.7 MB 760 s 2238 s 7.9 GB
28.2 MB -O0 – killed at 20 GB (568 s) > 20 GB
28.2 MB -O1 – killed at 20 GB (750 s) > 20 GB

Not tested: this PR's head commit itself, the largest (145 MB) program, other drivers, desktop CPUs, repeated runs, a title run.

AI use: Claude Code (Claude Sonnet 5.5, then Claude Opus 5.5) wrote the local harness, ran the measurements on my machine and drafted this.

@JorgeMJM

Copy link
Copy Markdown

Correction to my report above: the dxc.exe table timed HLSL dumped by xcl shaders --recomp, which translates with 1 memory window unless XCL_RECOMP_WINDOWS is set. The runtime uses 4, and that source is larger (+11 % on a 2.4 MB program here), which is why the same program gave 1.8 MB of DXIL there and 2.7 MB through the runtime. The arguments are the same (-E main -T cs_6_6 -HV 2021 -O1). The driver table went through the runtime's path and stands; the DXC-only times are those of the 1-window form, not what a title compiles.

AI use: Claude Code (Claude Opus 5.5) found the cause and drafted this.

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Test of 31fb65e merged onto main b9b6ea6, against b9b6ea6, on the three programs over 8 MB from @kole07139's test, with their method (A: xcl shaders <record> --precompile --only cs; B: the same with --pipelines, so the driver; one fresh DXIL cache per build and program). The difference from their run is a higher memory cap: a process here was stopped at about 37 – 39 GB of private memory (6 GB of free system commit left) instead of 28 GB.

program build A: translation + DXC DXIL B: driver
the 147 MB one PR refused in 1.6 s (over 64 MB) – –
main stopped at 36.3 GB after 24 s (in DXC) – –
first ~30 MB one PR (-O1) 527 s, 10.2 GB 14.7 MB stopped at 37.4 GB after 218 s
main (-O0) 134 s, 7.9 GB 29.2 MB stopped at 37.4 GB after 433 s
second ~30 MB one PR (-O1) 487 s, 5.2 GB 14.6 MB stopped at 38.8 GB after 145 s
main (-O0) 120 s, 4.1 GB 29.1 MB stopped at 38.2 GB after 329 s
  • The 64 MB refusal works: the program that otherwise takes over 36 GB in DXC within half a minute is refused at once.
  • With 37 – 39 GB, the driver still does not build either ~30 MB program, at -O1 or -O0. At -O1 it reached the cap sooner, as in kole07139's run. So the halved DXIL does not make these two build here either, and their DXC time is about 4 times main's.

Tested: RTX 4080 (driver as in my earlier reports), i9-12900K, 64 GB, Windows 11 26300, DXC 1.9.2602.17, release builds. One run per cell.
Not tested: AMD, a title run, heap windows, the other sources over 8 MB.

AI use: Claude Code (Claude Opus 5.5): ran the tests and wrote this.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/gpu/recomp/dxc.rs
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.