Recompiler: reuse operands when writing DXIL instruction records #1927

Manually merged
github merged 1 commit from gh-pr/1927/head into gh-pr/1927/base 2026-11-26 05:10:01 +00:00
Owner

@⁠philip-roy-jones on GitHub · 2026-11-24 23:30 UTC · original
philip-roy-jones:recompiler-reuse-bitcode-operands-1269 → main · +37 −12 · 2 files · 1 commits · merged 2026-11-25 01:01 UTC

Part of #1269. Please apply the goal:world-load label from #1833. Two compute shaders traced during world loading contain 36,223 instruction records that each allocated a temporary operand vector.

What is in it

  • crates/xcl/src/gpu/dxil/module.rs reuses one vector for binary operations, calls, PHIs, GEPs and switches. A bitcode-reader test checks the operands after a longer record is followed by a shorter one.

Tested

Upstream 20cf13022f76 / PR 3f50b7903989. Ryzen 7 7700X, Radeon RX 580 (31.0.21925.1001), Windows 11 Pro 26200.9974, Rust 1.100.0 MSVC, DXC 1.9.2609.5.

Release workload, main / PR Bitcode writing, ms Total translation, ms Allocation and reallocation calls
Two traced shaders 6.23 / 4.12 76.81 / 74.91 653,863 / 596,017
3.91 MB shader 44.82 / 35.37 593.14 / 584.37 4,184,219 / 3,857,161

All three shaders produced byte-identical, validated DXIL. Total translation for the larger shader was faster in 10/12 paired rounds. Two-shader trace and larger AMD workload.

  • RX 580 workspace suite on main and the PR reported 885 / 886 passed, 91 / 91 failed, 45 / 45 ignored. The failures matched by name. Both pass counts include 53 hardware skips.

  • The local Windows CI command reported 976 passed, 0 failed, 45 ignored, 1 filtered. 141 tests emitted 261 hardware skip messages on WARP.

  • Independent RTX 3070 run by @⁠upipibi on 3f50b79 with main 20cf130. The operand regression test passed. The direct-DXIL GPU filter matched main with 110 passed, 0 failed and 1 ignored. The sparse test was excluded. Commands and driver version

Commands and measurement details
  • cargo build --release --locked -p xcl. Timings use split wave64 and four switch-based memory windows. The full translator was timed over 24 paired rounds for the two shaders and 12 for the larger one. Identical temporary Module::write_bitcode timers measured the writing stage on each revision (20/20 and 12/12 paired rounds faster). Allocation counts use a separate counting allocator.
  • cargo build --locked --workspace and cargo test --locked --workspace --no-fail-fast -- --test-threads=4. The hardware skips covered 34 wave-size, 6 mesh-shader, 12 unavailable-device and 1 heap-window cases. On each build, 84 failures reported device removal and 6 reported an invalid argument.
  • cargo test --locked -p xcl --lib gpu::dxil::bitreader_tests -- --test-threads=1 --nocapture passed all 4 tests. The RX 580 created eight native-wave64 pipelines across both shader paths and revisions. gpu::dxil::tests::emitted_kernel_runs_on_the_gpu passed on both revisions in a fresh process with XCL_REQUIRE_GPU=wave64.
  • .\scripts\test.ps1 --skip test_title_runs_and_game_folder_is_untouched ran on WARP with Windows SDK DXC 1.8.2502.11.

Regression run

scripts/smoke.ps1 -Game <folder> -Title Retail -Seconds 60 with XCL_DIRECT_DXIL=1 and XCL_PSO_PRELOAD=0. With default asynchronous pipelines, all four cold/warm runs exited with 0xc0000409 before presenting a frame. With XCL_ASYNC_PSO=0, all six runs exited normally. The cold runs showed fewer frames on the PR in both orders. All 737 cached DXIL files matched byte for byte in both cold comparisons.

XCL cache, main / PR Frames shown Peak commit, MB Shader compilations
Cold 903 / 769 47,887 / 45,295 737 / 737
Warm 1,391 / 1,471 72,784 / 71,761 4 / 4
Cold repeat 810 / 787 49,263 / 50,906 737 / 737
Cold retail smoke output

Every run used fresh title data. Cold runs started with empty XCL caches, main first and PR first on the repeat. Warm runs used separate copies of the same upstream-produced cache, PR first.

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: Radeon RX 580 Series
title: Retail
seconds: 60
exit: 0x0
frames shown: 903 (PresentX 904)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 47887 MB
xcl-smoke v1
commit: 3f50b7903989a83f7a37e7f99c8b2e3bd4514016
gpu: Radeon RX 580 Series
title: Retail
seconds: 60
exit: 0x0
frames shown: 769 (PresentX 769)
presents per 2 s (last 3): 35 44 53
device removals: 0
crashes: 0
peak commit: 45295 MB

Not tested

Time to enter the world, driver compilation of the larger shader, retail on NVIDIA, RDNA4 hardware, and optional XCL_SAMPLE_* fixtures.

AI use

OpenAI Codex, GPT-6.2 Astra (gpt-6.2-astra) at maximum reasoning effort (max) wrote the change and test, ran the comparisons and prepared the report.

**@⁠philip-roy-jones** on GitHub · 2026-11-24 23:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/1927) `philip-roy-jones:recompiler-reuse-bitcode-operands-1269` → `main` · +37 −12 · 2 files · 1 commits · merged 2026-11-25 01:01 UTC Part of #1269. Please apply the `goal:world-load` label from #1833. Two compute shaders traced during world loading contain 36,223 instruction records that each allocated a temporary operand vector. **What is in it** - `crates/xcl/src/gpu/dxil/module.rs` reuses one vector for binary operations, calls, PHIs, GEPs and switches. A bitcode-reader test checks the operands after a longer record is followed by a shorter one. **Tested** Upstream `20cf13022f76` / PR `3f50b7903989`. Ryzen 7 7700X, Radeon RX 580 (31.0.21925.1001), Windows 11 Pro 26200.9974, Rust 1.100.0 MSVC, DXC 1.9.2609.5. | Release workload, main / PR | Bitcode writing, ms | Total translation, ms | Allocation and reallocation calls | | --- | ---: | ---: | ---: | | Two traced shaders | 6.23 / 4.12 | 76.81 / 74.91 | 653,863 / 596,017 | | 3.91 MB shader | 44.82 / 35.37 | 593.14 / 584.37 | 4,184,219 / 3,857,161 | All three shaders produced byte-identical, validated DXIL. Total translation for the larger shader was faster in 10/12 paired rounds. [Two-shader trace](https://git.gtahub.st/github/xcl-dev--xcl/issues/1269) and [larger AMD workload](https://git.gtahub.st/github/xcl-dev--xcl/issues/1269). - RX 580 workspace suite on main and the PR reported **885 / 886 passed, 91 / 91 failed, 45 / 45 ignored**. The failures matched by name. Both pass counts include 53 hardware skips. - The local Windows CI command reported 976 passed, 0 failed, 45 ignored, 1 filtered. 141 tests emitted 261 hardware skip messages on WARP. - Independent RTX 3070 run by @⁠upipibi on `3f50b79` with main `20cf130`. The operand regression test passed. The direct-DXIL GPU filter matched main with 110 passed, 0 failed and 1 ignored. The sparse test was excluded. [Commands and driver version](https://git.gtahub.st/github/xcl-dev--xcl/pulls/1927) <details><summary>Commands and measurement details</summary> - `cargo build --release --locked -p xcl`. Timings use split wave64 and four switch-based memory windows. The full translator was timed over 24 paired rounds for the two shaders and 12 for the larger one. Identical temporary `Module::write_bitcode` timers measured the writing stage on each revision (20/20 and 12/12 paired rounds faster). Allocation counts use a separate counting allocator. - `cargo build --locked --workspace` and `cargo test --locked --workspace --no-fail-fast -- --test-threads=4`. The hardware skips covered 34 wave-size, 6 mesh-shader, 12 unavailable-device and 1 heap-window cases. On each build, 84 failures reported device removal and 6 reported an invalid argument. - `cargo test --locked -p xcl --lib gpu::dxil::bitreader_tests -- --test-threads=1 --nocapture` passed all 4 tests. The RX 580 created eight native-wave64 pipelines across both shader paths and revisions. `gpu::dxil::tests::emitted_kernel_runs_on_the_gpu` passed on both revisions in a fresh process with `XCL_REQUIRE_GPU=wave64`. - `.\scripts\test.ps1 --skip test_title_runs_and_game_folder_is_untouched` ran on WARP with Windows SDK DXC 1.8.2502.11. </details> **Regression run** `scripts/smoke.ps1 -Game <folder> -Title Retail -Seconds 60` with `XCL_DIRECT_DXIL=1` and `XCL_PSO_PRELOAD=0`. With default asynchronous pipelines, all four cold/warm runs exited with `0xc0000409` before presenting a frame. With `XCL_ASYNC_PSO=0`, all six runs exited normally. The cold runs showed fewer frames on the PR in both orders. All 737 cached DXIL files matched byte for byte in both cold comparisons. | XCL cache, main / PR | Frames shown | Peak commit, MB | Shader compilations | | --- | ---: | ---: | ---: | | Cold | 903 / 769 | 47,887 / 45,295 | 737 / 737 | | Warm | 1,391 / 1,471 | 72,784 / 71,761 | 4 / 4 | | Cold repeat | 810 / 787 | 49,263 / 50,906 | 737 / 737 | <details><summary>Cold retail smoke output</summary> Every run used fresh title data. Cold runs started with empty XCL caches, main first and PR first on the repeat. Warm runs used separate copies of the same upstream-produced cache, PR first. ``` xcl-smoke v1 commit: 20cf13022f764208384c610c2ae6a3f4eed201a2 gpu: Radeon RX 580 Series title: Retail seconds: 60 exit: 0x0 frames shown: 903 (PresentX 904) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 47887 MB ``` ``` xcl-smoke v1 commit: 3f50b7903989a83f7a37e7f99c8b2e3bd4514016 gpu: Radeon RX 580 Series title: Retail seconds: 60 exit: 0x0 frames shown: 769 (PresentX 769) presents per 2 s (last 3): 35 44 53 device removals: 0 crashes: 0 peak commit: 45295 MB ``` </details> **Not tested** Time to enter the world, driver compilation of the larger shader, retail on NVIDIA, RDNA4 hardware, and optional `XCL_SAMPLE_*` fixtures. **AI use** OpenAI Codex, GPT-6.2 Astra (`gpt-6.2-astra`) at maximum reasoning effort (`max`) wrote the change and test, ran the comparisons and prepared the report.
The bitcode writer builds a fresh vector for each binary operation, call,
phi, GEP and switch. Reuse one vector while emitting the function body.
The two compute shaders traced in #1269 save about 58,000 allocations
and reallocations during translation. Check that a shorter record after
a flagged binop contains only its own operands.

Part of #1269.

Assisted-by: OpenAI Codex (GPT-6.2 Astra, gpt-6.2-astra, maximum reasoning effort)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:59 +00:00
github manually merged commit 3f50b79039 into gh-pr/1927/base 2026-11-26 05:10:01 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:42 UTC · original

NVIDIA run: RTX 3070 8 GB (32-lane waves, split wave64), driver 616.56, Windows 11, debug, 3f50b79 merged onto main 20cf130 (clean).

  • a_shorter_binop_record_has_only_its_own_operands: passes.
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4: 110 passed, 0 failed, 1 ignored, the same as main on this machine. The sparse test was skipped because of #1727.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 23:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1927#issuecomment-7147704203) NVIDIA run: RTX 3070 8 GB (32-lane waves, split wave64), driver 616.56, Windows 11, debug, `3f50b79` merged onto `main` `20cf130` (clean). - `a_shorter_binop_record_has_only_its_own_operands`: passes. - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4`: 110 passed, 0 failed, 1 ignored, the same as `main` on this machine. The sparse test was skipped because of #1727. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠anes66 on GitHub · 2026-11-25 00:41 UTC · original

CPU-only mixed-record check on exact head 3f50b7903989a83f7a37e7f99c8b2e3bd4514016: the synthetic bitcode matched the parent's writer byte for byte. Optional test companion d54e613, directly on that head, adds tests only.

Tested

  • Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. No GPU, DXC or retail data.
  • Added long-to-short record checks for calls (4/12/4 operands), GEPs (6/5), flagged/unflagged binops (4/3), switches (19/5), and PHIs (5/3).
  • Added a mixed module with 8194 binary operations plus those variable-length records. Nine serializations per run must be byte-identical. Optional XCL_TEST_BITCODE_OUT writes this synthetic raw LLVM bitcode for comparison.
  • Ran cargo test --locked -p xcl --lib gpu::dxil::bitreader_tests:: -- --nocapture --test-threads=1 with the PR writer and with only module.rs restored to parent 20cf13022f764208384c610c2ae6a3f4eed201a2: 6 passed / 0 failed / 0 ignored on each, no skips. The same test overlay was retained on both.
  • Direct file comparison of the final fixtures: 79936 bytes, identical; SHA-256 f2f7fed408e1e265ca3b7e39f5139dae858c743062d1804efb90926a3f5f3576.
  • Negative control: clearing the reused buffer only for Bin still permits the existing short-binop case but makes the new mixed case fail on CALL lengths [4,16,20] instead of [4,12,4]. Runtime control edits were restored before the final passing run and commit.

Not tested
Full workspace/GPU suite, shader validator, release, retail shaders, allocation counts, newer-main integration or a controlled performance benchmark. The printed debug writer timings are diagnostics, not evidence of a runtime speed-up. This fixture checks raw bitcode serialization, not shader execution. No competing upstream PR.

AI use
Codex (GPT-6; exact variant unavailable) wrote the tests, ran CPU controls and byte comparisons, and prepared this report.

**@⁠anes66** on GitHub · 2026-11-25 00:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1927#issuecomment-7148781975) CPU-only mixed-record check on exact head `3f50b7903989a83f7a37e7f99c8b2e3bd4514016`: the synthetic bitcode matched the parent's writer byte for byte. Optional test companion [d54e613](https://github.com/anes66/xcl/commit/d54e61308a6221962bf78a4e1f73eca6c84d5078), directly on that head, adds tests only. **Tested** - Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. No GPU, DXC or retail data. - Added long-to-short record checks for calls (4/12/4 operands), GEPs (6/5), flagged/unflagged binops (4/3), switches (19/5), and PHIs (5/3). - Added a mixed module with 8194 binary operations plus those variable-length records. Nine serializations per run must be byte-identical. Optional `XCL_TEST_BITCODE_OUT` writes this synthetic raw LLVM bitcode for comparison. - Ran `cargo test --locked -p xcl --lib gpu::dxil::bitreader_tests:: -- --nocapture --test-threads=1` with the PR writer and with only `module.rs` restored to parent `20cf13022f764208384c610c2ae6a3f4eed201a2`: **6 passed / 0 failed / 0 ignored** on each, no skips. The same test overlay was retained on both. - Direct file comparison of the final fixtures: **79936 bytes, identical**; SHA-256 `f2f7fed408e1e265ca3b7e39f5139dae858c743062d1804efb90926a3f5f3576`. - Negative control: clearing the reused buffer only for `Bin` still permits the existing short-binop case but makes the new mixed case fail on CALL lengths `[4,16,20]` instead of `[4,12,4]`. Runtime control edits were restored before the final passing run and commit. **Not tested** Full workspace/GPU suite, shader validator, release, retail shaders, allocation counts, newer-main integration or a controlled performance benchmark. The printed debug writer timings are diagnostics, not evidence of a runtime speed-up. This fixture checks raw bitcode serialization, not shader execution. No competing upstream PR. **AI use** Codex (GPT-6; exact variant unavailable) wrote the tests, ran CPU controls and byte comparisons, and prepared this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:33 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1927#issuecomment-7150883999) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.