Skip to content

Recompiler: structured code indents at most 8 levels - #1584

Open
Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:indent-cap
Open

Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:indent-cap

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 24, 2026 •

Copy link
Copy Markdown

The structured form limits how deep code nests (MAX_NEST), but not how far it is indented: every nested if and 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 of ActivateRays (#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 in emit_structured and emit_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 617.42), i9-13900K, 32 GB, Windows 11 Pro build 26300, rustc 1.100.0. Suite in debug, smoke runs in release.

  • dee5ada (rebased onto main 0cdc896): cargo build --workspace && cargo test --workspace -- --test-threads=4 gave 1086 passed, 0 failed, 46 ignored, in 20 result blocks, with 24 SKIPPED lines (no wave64, the per-lane f16/f32 refusals from main, no heap windows, no Developer Mode). The rebase kept main's new em.emit_insts call in emit_block and caps its indent; the pc-block fallback from b8b1f49 (structured jumps to outer loop heads): the retail title of #505 commits ~1 GB/s until XCL runs out of memory, before the world load #1307 is not capped, like emit_range.

  • Fails without the change: with MAX_INDENT at 99, structured_indentation_stops_at_the_cap fails (rerun on dee5ada).

  • 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 Recompiler: one skip variable for all forward jumps of structured code #1345), three retail compute programs:

    program instructions HLSL before after
    1 88,863 29,598,855 B 19,264,315 B
    2 88,445 29,524,131 B 19,189,591 B
    3 (ActivateRays) 76,699 151,193,185 B 117,650,689 B
  • 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, 60 s, XCL_PRESS_AT=16:A, a new empty XCL_DXIL_CACHE per run.

main 689f2db:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1239 (PresentX 1239)
presents per 2 s (last 3): 1 11 26
device removals: 0
crashes: 0
peak commit: 25409 MB

This PR, head dee5ada:

xcl-smoke v1
commit: dee5ada101d8cf62a8ae1873b7430b028920e24b
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1181 (PresentX 1181)
presents per 2 s (last 3): 4 0 6
device removals: 0
crashes: 0
peak commit: 24434 MB

The PR's run got 95.3 % of main's frames and 96.2 % of its peak commit.

Not tested

AI use

  • Claude Code. A subagent on Claude Sonnet 5.5 wrote the change and the test and made the HLSL and DXC measurements. Claude Opus 5.5 (the main session) planned it, checked the numbers, wrote this description and reviewed the diff in a second agent of the same model. Subagents on Claude Sonnet 5.5 ran the earlier smoke pairs; the main session did the rebase, the suite and the smoke run on dee5ada.

🤖 Generated with Claude Code

@Pipodi
Pipodi marked this pull request as ready for review November 24, 2026 18:04
@nnonno91

Copy link
Copy Markdown

Independent AMD test of the 1 MiB DXC cutoff on f578e661b340463e47e675082619989e669c8713 against 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.8.2502.11, debug. cargo build --workspace --locked passed. cargo test --locked -p xcl --lib structured_indentation_stops_at_the_cap -- --test-threads=1 passed.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 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=1 generated 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=1 compiled the 5,120-add fixture through XCL’s normal DXC path and explicit -O1/-O3 controls.
Emitted HLSL Source bytes Automatic output matched DXIL bytes
Base 1,120,938 -O1 23,600
PR 792,410 -O3 3,812

Forcing the same optimization level on both sources produced byte-identical DXIL at each of -O1 and -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.

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@nnonno91 thank you. This covers the first point under Not tested: a program that the cap brings under the 1 MiB line.

  • Your 5,120-add fixture drops from 1,120,938 B to 792,410 B, so DXC compiles it at -O3 instead of -O1.
  • At the same level, the base and the PR give byte-identical DXIL. So the only change in the output comes from the level: 23,600 B → 3,812 B of DXIL.
  • Both forms give the right result on 64 lanes on AMD, with the body both run and skipped.

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.

kacper-serewis added a commit to kacper-serewis/xcl that referenced this pull request Nov 24, 2026
Adapt the indentation cap from xcl-dev#1584 for compute and kernel shaders on adapters configured for split waves. Keep the original source when trimming it would change the optimization level. Four synthetic threshold-crossing shaders kept identical DXIL; the RTX 5070 nested shader fixture also preserved register results.

Assisted-by: Codex (gpt-6.2-astra)
Assisted-by: 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, timings in release. DXC 1.8.2505.32 (Windows SDK 10.0.28000.0).

Tested (AMD), commit f578e66

  • On 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 main e9e94ce (applies cleanly): 893 passed, 0 failed, 42 ignored in two full runs (main alone: 892 / 0 / 42). Earlier, on main c160d86: 859 / 0 / 42 (main alone 858).

  • HLSL size, xcl shaders <retail shaders.rpf> --export-hlsl DIR --count 40 --min-kb 400 with a release build of main e9e94ce and 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 with main and this PR interleaved (medians; the -O level is the same before and after, none of the 40 crossed 1 MB or 8 MB):

    program HLSL DXC main -> PR DXIL main / PR
    a2e35984348fb34e 2.2 -> 2.0 MB 16.5 -> 16.1 s 530,684 / 530,684 B
    b3618a0fd76af79c 4.1 -> 3.7 MB 10.6 -> 10.7 s 981,464 / 981,464 B
    6e3fd903765f4376 4.3 -> 3.9 MB 12.2 -> 12.6 s 1,075,400 / 1,075,400 B

    The DXC differences are within the run-to-run spread (about 3 %); the DXIL has the same size.

Not tested

  • Programs of tens of MB of HLSL, where the PR measured -22 % to -35 %; none of mine is above 4.3 MB. Driver time (the DXIL has the same size, but I did not compare it byte for byte), smoke run, Intel, Nvidia.

AI use

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

@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown
Author

@kleborgn thanks for the AMD run. f578e66 passes on its own base, and the same diff on main c160d86 adds 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.

@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, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@LocranKing

Copy link
Copy Markdown

Independent Windows release verification on NVIDIA RTX 3060 Ti (f578e661b340463e47e675082619989e669c8713 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: 1566 / 1566 frames (100.0%), 15676 / 14715 MB peak commit (106.5%), 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 (f578e66):

xcl-smoke v1
commit: f578e661b340463e47e675082619989e669c8713
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: 15676 MB

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.

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@Pipodi
Pipodi marked this pull request as draft November 25, 2026 01:13
emit_structured indented every nested if / loop one more level. A retail
compute program whose loops nest ~65 deep carried 42.7 MB of leading
whitespace in 53.0 MB of HLSL (~80 %, measured on xcl-dev#1345); DXC reads and
keeps those bytes although they mean nothing to it.

Indentation stops at 8 levels (MAX_INDENT); deeper code is written at the
cap. Only whitespace changes. Measured on three retail compute programs
on main alone (no xcl-dev#1345), size of the HLSL file:
  p16  29,598,855 -> 19,264,315 B  (29.6 -> 19.3 MB)
  p17  29,524,131 -> 19,189,591 B  (29.5 -> 19.2 MB)
  p18 151,193,185 -> 117,650,689 B (151.2 -> 117.7 MB)
a saving of 22-35 % on main. Synthetic test program (14 nested ifs):
35346 -> 34498 bytes.

dxc.rs:491-494 picks the DXC level from the raw src.len(), whitespace
included. Programs of about 1.0 - 1.5 MiB move from -O1 to -O3 and
programs of about 8 - 11 MiB from -O0 to -O1. None of the three measured
programs crosses a line (all stay above 8 MiB, at -O0); DXC time p16
69.9 s -> 64.0 s, p17 63.1 s -> 63.2 s.

emit_range (the unstructured fallback) is not capped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013qV4hiM5Sx9hBkPpgAarKX
@Pipodi
Pipodi marked this pull request as ready for review November 25, 2026 01:18
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.

6 participants