Skip to content

Recompiler: reuse scratch slots across disjoint payload lifetimes - #2322

Draft
akimfomin wants to merge 1 commit into
xcl-dev:mainfrom
akimfomin:codex/compact-scratch-afc5ee8
Draft

akimfomin wants to merge 1 commit into
xcl-dev:mainfrom
akimfomin:codex/compact-scratch-afc5ee8

Conversation

@akimfomin

@akimfomin akimfomin commented Nov 25, 2026 •

Copy link
Copy Markdown

Part of #1269 and a follow-up to Kalmarv’s merged #2126. The PortBridge allocator reuses scratch slots after their last carrying stage and keeps the fixed layout when reuse saves no space.

What is in it

  • A two-file GPL-2.0-only change with provenance and a regression check for slot compaction.

Tested

  • Windows 11, RTX 4070 Ti SUPER driver 617.14, Rust 1.100.0 gnullvm, DXC/DXIL 1.9.2609.5. The exact tree at b3f7ab5574c4489761141e2de0ce31d2eb216412 passed 10 targeted split tests with zero skips. The open Wave32 fixture used 256 DWORDs per group and matched the whole-shader and CPU outputs. The same check on the fixed allocator reported 288.

  • ettehn independently reported 47,712 to 20,064 DWORDs per group on one translation record and eight passing checks on an RTX 5070 Ti Laptop. Report

  • nnonno91 independently passed all 10 targeted tests with zero skips on each of AMD Radeon Graphics and RTX 5090. luckyteagirl independently passed the same 10 without skips on a Radeon RX 6800M. All three runs used the exact PR head. The split readbacks matched and the Wave32 fixture reported 256 DWORDs. The guest-Wave64 split fixture executes as hardware Wave32 halves.

  • On the same Git tree (0e3b7fd2c023d3935f7d4e0b5725751409062e62), the open RTX 4070 Ti SUPER workspace build used cargo build --offline --locked --workspace -j 2. cargo test --offline --locked --workspace -j 2 --no-fail-fast -- --test-threads=4 reported 1,265 passed, 0 failed and 46 ignored. The harness printed 27 additional runtime skip lines inside those totals: 21 unavailable Wave64 paths, three lowering refusals, two missing debug-layer paths and one missing heap-window path.

Regression run

The paired retail xcl-smoke blocks on main and the exact PR head are pending. The PR remains a draft.

Not tested

Paired retail smoke and matched GPU time, cold driver compilation, and scratch sizes for the three workloads Kalmarv requested. The 57.9% scratch reduction above concerns one unnamed translation record. Aggregate-only review package

AI use

OpenAI Codex (GPT-6 family; the exact serving variant was unavailable) assisted with rebasing, testing and drafting.

Stack PortBridge's compact allocator on Kalmarv's merged xcl-dev#2126 baseline. Preserve the earlier scratch layout whenever packing saves no space and retain same-stage ordering.

AI use: OpenAI Codex (GPT-6 family; exact serving variant was not exposed) assisted with rebasing, code review, synthetic regression checks and preparation of this fork branch for human review.
@nnonno91

Copy link
Copy Markdown

Independent Radeon and RTX 5090 check on b3f7ab5574c4489761141e2de0ce31d2eb216412.

Tested

  • Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, SDK DXC/DXIL 1.8.2502.11, unoptimized profile. AMD Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742.
  • cargo test --locked -p xcl --lib gpu::dxil::module::split::tests -- --nocapture --test-threads=1 with XCL_ADAPTER=AMD Radeon and XCL_ADAPTER=NVIDIA GeForce RTX 5090 in separate processes. The runner printed each adapter. Each run gave 10 passed, 0 failed, 0 ignored and no skips.
  • The Wave32 fixture asserted the reused size of 256 dwords per group. The whole-versus-split GPU readbacks passed, including the case that preserves the payload across a reused edge slot.

Not tested

Retail records, compile or GPU timing, title smoke and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the checks, verified the logs and wrote this report.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent RX 6800M verification of exact PR head b3f7ab5574c4489761141e2de0ce31d2eb216412.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; AMD Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64; isolated debug Cargo target.

cargo test --locked -p xcl --lib gpu::dxil::module::split::tests:: -- --test-threads=1 --show-output passed 10 passed, 0 failed, 0 ignored, with no SKIPPED line on the clean head. The suite includes the new slot-lifetime/compaction checks, whole-vs-split GPU readback for Wave32, a guest wave64 program split across hardware wave32 halves, oversized loops, persistent payloads across skipped stages, and divergent 3D forward edges. The suite logged CHAIN_GPU=AMD Radeon RX 6800M. The Wave32 compaction fixture asserted 256 scratch DWORDs per group and passed.

The guest-wave64 split fixture uses KernelOptions { wave64: true, split: true } and runs on wave32 hardware waves; this result is not a test of a native-wave64 dispatch chain. I did not run the full workspace suite, an owned-title smoke pair, the requested three matched GPU measurements, or a shader-pack size survey on this head. A separate title smoke attempt for another PR had just stopped under the available-commit memory guard, so I kept this check focused.

AI use: OpenAI Codex (GPT-6; exact variant unavailable in this session) ran the native Windows suite, checked the exact head and clean worktree, and drafted this report. No game data was used.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@anes66

anes66 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

CPU-only allocator and planner checks passed on exact head b3f7ab5574c4489761141e2de0ce31d2eb216412. Optional companion d039ce5, with parent 440b261, contains tests only: the independent partition/liveness fixture from main plus exhaustive allocator intervals and checks through Module::scratch_slots.

Tested

  • Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug, SDK DXC/DXIL 1.9.2602.17. No GPU device or title run.
  • 8,000 lifetime sets, each allocated in forward and reversed input order: all triples of one/two-word values with inclusive first/last stages in 0–3. Checks deterministic layouts, nonzero slots, bounds, no overlap while two values are live, no growth beyond the fixed layout and full reuse for mutually disjoint intervals.
  • 216 module plans / 1,242 crossing payloads across block-allocation permutations, loop costs and limits. Independent reachability and forward liveness checks cover SCC integrity and exact edge payloads. The actual scratch_slots result is checked against the definition stage and last carrying destination for every value; overlapping inclusive lifetimes cannot share words. A no-saving result must preserve the original fixed offsets.
  • Exact-name selection of payload_slot_intervals_never_overlap_while_both_values_are_live, dispatch_plan_matches_forward_liveness_and_independent_sccs, payload_slots_reopen_only_after_the_last_consumer, oversized_loop_occupies_one_piece_up_to_the_hard_ceiling, and dispatch_chain_wave32_reuses_scratch_before_gpu_run, using cargo test --locked -p xcl --lib -j 2 -- --exact <full names> --nocapture --test-threads=1: 5 passed / 0 failed / 0 ignored / 0 skips.
  • The last selected test takes the author's run_gpu=false path. It builds/validates synthetic pieces and checks the 256-DWORD group layout, then returns before GPU execution.
  • Negative control: changing the release condition from last < first to last <= first makes the interval test fail immediately with three simultaneously-live values assigned to slot 1. Restored before final passing runs and commit.

Not tested
GPU output or timing, the requested matched GPU measurements, real scratch-memory savings, full workspace, release or a title. The CPU checks do not replace those remaining adoption requirements.

Integration follow-up: footprint expectation

With #1906/#1972 optimizer changes in a local combined tree, the existing run_gpu=false fixture has 320 fixed / 288 compact DWORDs per group, with a peak-live-word lower bound of 288. It still saves a full wave plane, but the literal 256 assertion fails. On standalone b3f7ab5, the corresponding values remain 288 / 256, peak 256.

Optional test-only e17bf0b, directly on this head, derives the exact expected footprint from inclusive live intervals plus the continuation tag, requires attaining that lower bound, and separately requires a reduction from the fixed layout. It passes 1/0/0/0 standalone and in the combined snapshot. As a negative control, returning the fixed layout makes it fail at 288 versus the 256-DWORD lower bound; restored before the final passing run. No GPU execution or title run.

@akimfomin

Copy link
Copy Markdown
Author

Thanks to nnonno91, luckyteagirl, and anes66 for checking the exact head. The combined-tree result from anes66 is useful for integration: it still saves a full wave plane, while the literal 256-DWORD fixture assertion depends on the optimizer stack. I’m keeping the head pinned for the current comparisons.

@Kalmarv, if your authorized setup is available and you want to run the comparison, the remaining measurements are scratch DWORDs per group and matched GPU timestamps for the full dispatch chains for ef008c0f (early and late inputs), c3ae6819, and fb1c6d2d. The PortBridge aggregate-only kit checks equal grids, piece counts, and matching outputs for main versus the exact candidate. Please keep workloads and raw inputs on your own machine.

The two standard paired xcl-smoke summary blocks and approval of the fork CI are separate review requirements. This remains a draft. OpenAI Codex assisted with verification and drafting.

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@akimfomin yes, I'll run it. It matters for us too: porting #2097 onto #2126's fixed slots made the seven cascade-shadow programs need 4.4–6× more scratch per group (6d1e4583: about 1.4 MB per 16×16 group), so slot reuse is exactly what those chains need.

Our GPU is busy with world-load stall runs for the next few hours, so it comes after those. Plan: your kit on main and on b3f7ab5 for ef008c0f (early and late inputs), c3ae6819 and fb1c6d2d, comparing scratch DWORDs per group, piece counts, matching outputs and timestamps per full chain. Plus a smoke pair. Workloads and raw inputs stay on this machine, and I'll post aggregates only.

AI use: Claude Code (Claude Opus 5.5).

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