Recompiler: structured code indents at most 8 levels #1574
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1584"
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?
Imported from ivall/xcl. Originally posted by Pipodi on 2026-11-24T17:57:25Z.
The structured form limits how deep code nests (
MAX_NEST), but not how far it is indented: every nestedifand loop adds four spaces. On big compute programs most of the HLSL is leading whitespace, which DXC reads and keeps although it means nothing to it. On #1345's form, @wondercrash measured 42.7 MB of whitespace in the 53.0 MB ofActivateRays(#1345 comment 7137676632, point 1). This PR stops indentation at 8 levels and changes nothing else. Part of #1269.What is in it
crates/xcl/src/gpu/recomp/mod.rs:MAX_INDENT = 8, applied inemit_structuredandemit_block.emit_range, the unstructured fallback, is not capped.crates/xcl/src/gpu/recomp/tests.rs:structured_indentation_stops_at_the_cap(14 nested ifs; the widest line is 28 spaces). With the cap at 99 it fails (60 spaces).Tested
RTX 4090 24 GB (driver 621.40), i9-13900K, 32 GB, Windows 11 Pro build 26300, rustc 1.100.0. Suite in debug, smoke runs in release.
Rebased onto
main623d02e4(head6316fa3f), RTX 4090 (driver 621.40), rustc 1.100.0, debug:cargo build --workspace && cargo test --workspace -- --test-threads=4gave 1459 passed, 0 failed, 47 ignored.SKIPPED (28): no wave64 (21), no
xgameruntime.dll(2), no heap windows (1), per-lane f16/f32 cases refused by the per-lane form (3, as onmain),pso_measurement_compiles_an_exact_synthetic_record(cannot disable the driver cache; the log shows a 'missing SDK component' error) (1).Fails without the change: with
MAX_INDENTat 99,structured_indentation_stops_at_the_capfails (rerun ondee5ada).The HLSL and DXC numbers below were measured before the rebase, at
f578e66; the patch is the same.Only whitespace changes. On the three programs below, the HLSL with the cap and with the cap lifted is byte-identical once leading spaces are stripped (sha1 compared).
HLSL size on
main(without #1345), three retail compute programs:ActivateRays)DXC time (one debug run each): program 1 69.9 → 64.0 s, program 2 63.1 → 63.2 s. Program 3 timed out at 280 s both ways.
Regression run
The retail title,
XCL_PRESS_AT=16:A, 60 s,XCL_PREPARE=0, fresh gamesave. Both runs on this machine (RTX 4090, driver 621.40), release builds of clean trees, one untimed warm-up each, then the measured run.main (
623d02e4):This PR's head (
6316fa3f):The PR's run got 100.5 % of
main's frames and 106 % of its peak commit.Not tested
dxc.rs:491-494picks the level from the raw source length, whitespace included, so a program the cap brings under a line gets compiled at a higher level. About 1.0–1.5 MiB moves from-O1to-O3, and about 8–11 MiB from-O0to-O1. None of the three programs above crosses a line (all stay at-O0), and I have not measured a program that does. If #1526 merges, only the 1 MiB line remains.main) falls back to the pc form above128 * program.len()bytes, a limit set on uncapped sizes; with the cap, fewer programs reach it.arguments(src.len(), ..)also keys on raw size.XCL_PRESS_AT=16:Awas set as usual.AI use
dee5ada.🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T18:09:41Z.
Independent AMD test of the 1 MiB DXC cutoff on
f578e661b340463e47e675082619989e669c8713against9e3831e1f570d3646e53ab753b19ec07eb8f1485.Tested
cargo build --workspace --lockedpassed.cargo test --locked -p xcl --lib structured_indentation_stops_at_the_cap -- --test-threads=1passed.cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-outputreported 777 passed, 0 failed, and 41 ignored. One reported GPU skip (heap_window_out_of_memory_falls_back_to_the_switch_form, no heap windows). The bundled title passed.cargo test --locked -p xcl --test indent_threshold_probe -- --exact emit_indentation_samples --nocapture --test-threads=1generated eight synthetic kernels on each revision with 14 nested branches and 1,024–8,192 repeated adds in the body. All HLSL pairs matched after removing leading spaces. Maximum indentation was 60 spaces on base and 28 on the PR. Two fixtures crossed below 1 MiB.cargo test --locked -p xcl --test indent_gpu_probe -- --exact compile_and_run_across_indent_cutoff --nocapture --test-threads=1compiled the 5,120-add fixture through XCL’s normal DXC path and explicit-O1/-O3controls.-O1-O3Forcing the same optimization level on both sources produced byte-identical DXIL at each of
-O1and-O3. Both automatic outputs matched the expected register result across 64 lanes on AMD, with the body both executed and bypassed.Not tested
Retail shaders, retail title runs, DXC or driver timings, and a crossing of the 8 MiB cutoff. The two integration tests were temporary probes.
AI use
OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the probes, ran the checks, and drafted this report.
Imported from ivall/xcl. Originally posted by Pipodi on 2026-11-24T18:11:19Z.
@nnonno91 thank you. This covers the first point under Not tested: a program that the cap brings under the 1 MiB line.
-O3instead of-O1.So the gain for programs near the line is the higher level, and the cap changes nothing else in the DXIL. The 8 MiB line and timings on retail programs are still open; I'll post them here if I get them.
AI use: Claude Code (Claude Opus 5.5) wrote this reply.
Imported from ivall/xcl. Originally posted by kleborgn on 2026-11-24T19:48:39Z.
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
f578e66On its own base:
cargo test --workspace -- --test-threads=4: 777 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
maine9e94ce(applies cleanly): 893 passed, 0 failed, 42 ignored in two full runs (main alone: 892 / 0 / 42). Earlier, onmainc160d86: 859 / 0 / 42 (main alone 858).HLSL size,
xcl shaders <retail shaders.rpf> --export-hlsl DIR --count 40 --min-kb 400with a release build ofmaine9e94ceand one with this PR (same 40 compute programs, 4 windows, native wave64): 50.2 MB -> 47.8 MB (-4.7 %); per program -9.5 % at most, 2 of 40 unchanged, 410 KB to 4.3 MB before. On the 3 files I compared, the HLSL is identical once leading spaces are stripped.DXC time,
xcl shaders ... --measure-pso <record hash> --repeat 1, 3 rounds withmainand this PR interleaved (medians; the-Olevel is the same before and after, none of the 40 crossed 1 MB or 8 MB):a2e35984348fb34eb3618a0fd76af79c6e3fd903765f4376The DXC differences are within the run-to-run spread (about 3 %); the DXIL has the same size.
Not tested
AI use
Imported from ivall/xcl. Originally posted by Pipodi on 2026-11-24T19:49:40Z.
@kleborgn thanks for the AMD run.
f578e66passes on its own base, and the same diff onmainc160d86adds exactly one passing test (858 → 859). That covers the suite on AMD, which the PR's Not tested left open. The cap's effect on HLSL size and DXC time was measured only on NVIDIA here. On AMD it is still open.AI use: Claude Code (Claude Opus 5.5) wrote this reply.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:02:54Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-24T20:03:32Z.
Independent Windows release verification on NVIDIA RTX 3060 Ti (
f578e661b340463e47e675082619989e669c8713vs basemain9e3831e1f570d3646e53ab753b19ec07eb8f1485).Setup
8024 MiB VRAM, wave32), driver32.0.16.210131.8 GBRAM26200rustc 1.100.0, DXC1.9.2602.17,--releaseWorkspace tests (
cargo test --workspace --release --no-fail-fast -- --test-threads=4)0: 777 passed, 0 failed, 41 ignored across 20 result blocks (SKIPPED: 2no wave64, 2no 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)main:1566 / 1566frames (100.0%),15676 / 14715 MBpeak commit (106.5%),0device removals,0crashes.Base (
main9e3831e):PR head (
f578e66):Not tested: cold-cache HLSL size/compile-time measurement on the full retail shader pack, 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.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:48:36Z.
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Imported from ivall/xcl. Originally posted by Pipodi on 2026-11-27T15:43:04Z.
Rebased onto current main (
623d02e4); the suite rerun and the smoke pair on the new head are updated in the description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:11:26Z.
Triage (#1607) – head
6316fa3No open or merged PR caps the structured emitter's indentation; main still writes
" ".repeat(depth)inemit_structuredandem.indent = depthinemit_block.The cap only changes leading whitespace, not the emitted statements, and the test (14 nested ifs, widest line 7 levels) matches the code: if-blocks are emitted at
d<= 7, only loop latches and theLOOP_GUARDline reach 8.emit_range(the pc-dispatch path) is not capped; deepwhilenesting there still indents per level.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-02T15:59:29Z.
Closing: compute shaders now take the direct DXIL path by default, so the HLSL indent cap saves little on the default path, and the checks on the earlier head no longer count. Thanks to everyone who tested it.
Closed by the author (audit by Claude Code, Claude Opus 5.5).
Pull request closed