Skip to content

Recompiler: preserve a split candidate when direct compact lowering selects a whole PSO #2745

Backlog

Description

@KOLESNiii

Part of #2088 and #2508. Related to #2741, #2301 and #2080.

What happens on main

The direct translator selects a compact or ordinary lowering before it asks the dispatch splitter to plan pieces. The compact emitter keeps the current and next block indices in local alloca slots, and uses the same scheme for loop budget and guest register state. XCL's optimizer leaves the live dispatch locals in the module. Shader::split_compute rejects Alloca and ordinary local loads/stores before it reaches the CFG planner. As a result, choosing compact emission can turn a shader with a valid ordinary chain into a whole-only build. Native wave64, group shape, barriers and other split restrictions still apply. Form selection · Dispatch-local state · Optimize then split · Split restrictions

There is a second constraint even if the locals are promoted to SSA. Compact emission sends every class around the same dispatcher back edge. The resulting strongly connected component stays together in the partitioner, which refuses a component above four times its instruction target. In a standalone Linux probe using the extracted main optimizer and partitioner, the optimizer kept two live dispatch-index allocas. Separately, an artificial acyclic graph with 40 bodies produced 14 pieces at a test limit of 32, and the same body sizes behind a shared dispatcher back edge produced no plan at that limit. This checks the two mechanisms on synthetic IR. Retail eligibility and latency remain to be measured. Loop emission · Partitioner

Proposed work

  1. Test a synthetic guest compute program for which the ordinary form yields a valid chain and compact emission yields a valid whole PSO. Log the selected form and the actual split rejection condition. Respect forced compact, forced plain and split-disabled settings.
  2. On automatic selection, compare compact whole with the eligible ordinary chain on records observed before world entry. Keep the ordinary chain and optional whole fallback separately measurable. Reuse the existing descriptor and ABI checks, including Shaders: record and prewarm chain-ABI whole PSOs demanded before world entry #2741's proposed request identity for fallback capture. Measure native creation and peak commit, plus GPU time with the real dispatch slabs and barriers. Include the cost of a cold whole fallback wherever the caller can need one.
  3. If a combined representation is worth pursuing, try partitioning the ordinary CFG first and applying compact lowering only within selected legal regions. Promotion of compact scalar locals can be investigated independently. The work in itsSio/xcl#3 promotes static scratch arrays, which is adjacent to the local-memory check. A partitioning experiment also needs to preserve cross-piece liveness, barrier legality and dispatch semantics.

#2301's proposed size retry is a useful independent whole-form candidate. A comparison should track whether a smaller whole artifact replaces a useful chain, because the whole byte count alone omits the lost execution option. The end point is time to the first textured world frame with matching output and no increase in skipped work or device removals.

AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for static analysis, standalone Linux probes and drafting.

Activity

  1. CryingLaughing commented on Nov 26, 2026

    @CryingLaughing
    Contributor

    I tested an opt-in implementation that keeps the compact whole fallback and retains compatible ordinary dispatch pieces. The branch is fe87896d84ad581ac8a25b275d0889eaf938f2b0, based on b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7. It requires matching ordered static samplers and gives the option its own cache identity.

    • Normal compute entry point. Five fresh, CPU-only synthetic runs passed with the test-only flags removed. The automatically selected compact whole was byte-identical with the preference off and on (4,524 bytes). Turning the preference on retained the same 24 pieces and 2,400 scratch dwords per group as forced ordinary lowering. The pieces matched byte for byte. A zero split limit suppressed the chain.
    • Native RTX 4080 readback. A smaller test-only fixture matched 784/784 UAV words through both the five-piece path and the compact whole fallback. The first route made zero whole PSOs. The fallback made exactly one. 1 passed, 0 failed, 0 ignored, 0 capability skips.
    • Exact-head suite. cargo build --workspace --locked -j 4 and cargo test --workspace --locked -j 4 -- --test-threads=4 --show-output passed. 1,437 passed, 0 failed, 47 ignored, including 29 capability skips in the pass count.

    RTX 4080 driver 621.01, i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11. The 24-piece case exercised CPU translation and DXIL validation. Retail smoke and native compile timings for large shaders remain untested.

    Current-main integration

    I merged main 8b957bec6f82495aec940944c6bf47faa02db590 with preserved head fe87896d84ad581ac8a25b275d0889eaf938f2b0 in an isolated worktree. The clean local test commit c386deae30a164ff293f732f180e5fbb29c5acc0 and the published verification snapshot have the same source tree fd300287639e99f033dcf5e31e908e185e2362c0. Verification snapshot

    The locked offline build passed and compiled all 37 test harnesses. Three exact synthetic CPU fixtures passed with zero failures, ignored tests, or capability skips. The rerouted disk-cache test covered 12 subprocess settings. The automatic path kept the 7,280-byte compact whole and matched the ordinary five-piece chain with 256 scratch dwords per group. The sampler-order test rejected incompatible ordinary pieces.

    The serial synthetic GPU workspace suite reported 1,448 passed, 0 failed, 47 ignored. It emitted 29 explicit SKIPPED notices, comprising 21 for wave64, three for unsupported Direct DXIL instructions, three for the debug layer, one for driver-cache control, and one for heap windows. The runs used Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, and DXC 1.8.2502.11.

    cargo build --workspace --locked --offline -j 2
    cargo test --workspace --locked --offline -j 2 --no-run
    cargo test --workspace --locked --offline -j 2 --no-fail-fast -- --test-threads=1 --show-output

    The focused library test executable ran gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_compact_nesting_policy, gpu::dxil::kernel::chain_preservation_tests::automatic_compact_can_keep_an_ordinary_compute_chain, and gpu::dxil::kernel::chain_preservation_tests::compact_chain_rejects_ordinary_pieces_with_a_different_sampler_order, each with --exact --test-threads=1 --nocapture. All runs used CARGO_INCREMENTAL=0 XCL_NETWORK=0. The workspace execution also used XCL_ADAPTER=4080.

    The matched retail smoke covers the preserved head fe87896d84ad581ac8a25b275d0889eaf938f2b0. The new integration runs used synthetic data. Independent retail smoke

    Native readback on the current-main integration

    I ran the existing guarded readback fixture on the integration 90918802ee4078a8e28fd76a2b1409b9cc3c2fb5 with the exact fixture tree c46451a4c3560517f9a2260d206a0d426bd39bc7. The test exercised the five preserved ordinary dispatch pieces and forced the compact whole fallback by withholding the allocator. The split scratch requirement was 256 dwords per group. Exact native fixture

    Both routes matched all 784 UAV words after the fence. Each comparison included 736 written words, 32 untouched words in the skipped region, and 16 tail guard words. The pieces route created zero whole PSOs. The compact fallback created exactly one. The focused run reported 1 passed, 0 failed, 0 ignored, zero capability skips on an RTX 4080 with driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC, and DXC 1.8.2502.11.

    cargo test -p xcl --lib --locked --offline -j 2 --no-run --message-format=json
    & $testExecutable gpu::dxil::kernel::chain_preservation_tests::gpu_preserved_compact_chain_and_whole_fallback_match --exact --test-threads=1 --nocapture

    The test executable used XCL_ADAPTER=4080 XCL_TEST_COMPACT_CHAIN_NATIVE=1 XCL_ALLOC_SWAP=0 XCL_PSO_DISK_CACHE=0 XCL_NETWORK=0 and private XCL data and DXIL cache paths. The native run used synthetic data. The existing matched retail smoke covers the preserved branch head fe87896d84ad581ac8a25b275d0889eaf938f2b0. Independent retail smoke

    Supplemental hosted Windows verification

    The fork's windows-2025 job verified the clean checkout at fe87896d84ad581ac8a25b275d0889eaf938f2b0 and passed ./scripts/test.ps1 --skip test_title_runs_and_game_folder_is_untouched with CARGO_INCREMENTAL=0 XCL_NETWORK=0. The 37 harnesses reported 1,436 passed, 0 failed, 47 ignored and emitted 350 SKIPPED notices in the raw log. The runner used Windows Server 2025, Microsoft Basic Render Driver, and Rust 1.100.0 MSVC. The required upstream CI result remains outstanding. Exact hosted job

    Normal-entry correction and large native readback

    The earlier 384-dword result measured test-only slot reuse. The PowerShell runner left XCL_SAMPLE_SLOT_REUSE present with an empty value, and the splitter checks whether it exists. An isolated control reproduced the archived chain bytes with that flag present. The XCL_SAMPLE_PHI_CSE flag alone left this fixture unchanged. I fixed the runner to remove absent variables and reran the five CPU cases on the preserved head fe87896d84ad581ac8a25b275d0889eaf938f2b0. All five passed with zero skips. Automatic lowering with preference on matched the ordinary 24-piece chain with 2,400 scratch dwords per group, and its whole matched the 4,524-byte forced compact output.

    The current-main integration also passed six fresh CPU controls with zero failures, ignores, or skips. Forced ordinary and automatic-with-preference were byte-identical for all 24 pieces and the scratch layout with both test-only flags unset. Forced compact and automatic were byte-identical for the whole shader. Exact current-main fixture

    On the RTX 4080 with driver 621.01, the 142,092-byte guest shader then ran through its 24 pieces and through its forced compact fallback. Both routes matched 7,696 UAV words after the fence, including 7,648 writes, 32 skipped-region words, and 16 tail guards. The pieces route created zero whole PSOs. The fallback created one. The focused native result was 1 passed, 0 failed, 0 ignored, zero capability skips. The test used Windows 11 25H2 build 26200.9974, Core i5-13600K, Rust 1.100.0 MSVC, and DXC 1.8.2502.11.

    cargo test -p xcl --lib --locked --offline -j 2 --no-run --message-format=json
    & $testExecutable gpu::dxil::kernel::chain_preservation_tests::normal_compute_entry_records_profitable_translation --exact --test-threads=1 --nocapture
    & $testExecutable gpu::dxil::kernel::chain_preservation_tests::gpu_normal_compute_entry_preserves_profitable_split_and_compact_fallback --exact --test-threads=1 --nocapture

    The CPU recorder writes ordinary/chain.bin and compact/whole.dxil in separate processes using XCL_DIRECT_COMPACT=0 and 1 respectively, with XCL_TEST_COMPACT_CHAIN_TRANSLATION_DIR set to the corresponding output folder and the split limit at 2,048. The serial native process sets XCL_TEST_COMPACT_CHAIN_REFERENCE_DIR to their parent directory and uses XCL_ADAPTER=4080 XCL_TEST_COMPACT_CHAIN_NORMAL_ENTRY_NATIVE=1 XCL_DIRECT_PREFER_SPLIT=1 XCL_DIRECT_SPLIT_INSTRUCTIONS=2048 XCL_ALLOC_SWAP=0 XCL_PSO_DISK_CACHE=0 XCL_NETWORK=0. It removes XCL_DIRECT_COMPACT, XCL_SAMPLE_SLOT_REUSE, and XCL_SAMPLE_PHI_CSE from its environment. The existing retail evidence remains attached to the preserved head.

    AI use

    • OpenAI Codex assisted with the split-retention implementation, synthetic fixtures, local Windows GPU verification, and report drafting. The exact archived model variant is unverified. Codex (GPT-6, exact serving variant unavailable) checked this update. The linked independent reports are credited to the people who ran them.

    Upstream review status

    The description draft for preserved head fe87896d84ad581ac8a25b275d0889eaf938f2b0 now passes the current description checker locally, including Anon64’s matched 60-second retail smoke. It also includes the corrected 2,400-dword default stride. The exact head has full local GPU results and a supplemental hosted Windows pass on the fork. The official upstream Windows CI run finished with zero jobs. Matched retail smoke · Upstream CI record

    Would an upstream maintainer confirm whether a person should reopen #2810 at that exact head and whether a maintainer with write access can approve the upstream Windows workflow if it awaits approval? The description job also shows GitHub’s event-policy warning for December 2. For a reopening after that date, confirmation that the upstream description workflow can run would establish the path for that check. The PR remains closed pending confirmation. GitHub Actions event policy

    Exact-head serial verification

    On clean preserved fe87896d84ad581ac8a25b275d0889eaf938f2b0, the locked offline workspace build passed. The serial workspace suite on an RTX 4080 with driver 621.01 reported 1,437 passed, 0 failed, 47 ignored across 37 harnesses. The two chain-preservation unit tests passed with zero capability skips. In the whole suite, the 29 explicit notices comprised 21 wave64 cases, three unsupported instructions, three debug-layer cases, one driver-cache control, and one heap-window case. This run used Windows 11 25H2 build 26200.9974, Core i5-13600K, Rust 1.100.0 x64 MSVC, and DXC 1.8.2502.11.

    $env:XCL_ADAPTER = '4080'
    $env:XCL_NETWORK = '0'
    cargo build --workspace --locked --offline -j 3
    cargo test --workspace --locked --offline -j 3 --no-fail-fast -- --test-threads=1 --show-output

    OpenAI Codex (GPT-6, exact serving variant unavailable) ran and checked this serial comparison. The preserved head is the one used in Anon64’s matched retail smoke. Exact-head smoke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions