Recompiler: stream gpu::effects without Vec<Decoded>/HashSet and avoid copying compute blobs #2646

Closed
Decodere wants to merge 1 commit from upstream-pr/2656 into main
Decodere commented 2026-11-26 05:10:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T05:10:36Z.


What is in it

Eliminates full-shader Vec<Decoded> / HashSet<u64> allocations and Vec<u8> compute-blob copies in crates/xcl/src/gpu/effects.rs, and adds an early-exit path for memory-writing shaders in big_and_image_only:

  • Single-pass streaming analysis (analyze + update_writes): Streams rdna2::decode over &code[off..] preserving the exact ended / S_CODE_END stop rules and update_writes classification (ENC_MIMG, ENC_MUBUF/MTBUF/FLAT/FLAT_GLBL/FLAT_SCRATCH/SMEM, ENC_DS GDS/append/consume/ordered-count/DS_GWS_*). Collects monotonically increasing d.pc into pcs (capped initially to (code.len() / 6).min(256) when stop_on_memory is enabled so early-exiting memory writers avoid large upfront allocations) and validates branch targets with pcs.binary_search(t) instead of building a HashSet<u64>.
  • Dedicated far-jump fallback (analyze_with_far_jumps): Delegates only when S_SETPC_B64 is encountered (after S_CODE_END / early-memory-exit checks), runs rdna2::resolve_far_jumps(&mut insts), preserves the exact last terminator / S_BRANCH / far_target check, and validates branch/indirect targets via insts.binary_search_by_key(&t, |x| x.pc).
  • Zero-copy big_and_image_only with early exit on memory writes: Replaces compute_code() -> Option<Vec<u8>> with is_big_image_only_code(code: &[u8]) -> bool borrowing &f.code (FSPX) and &f.data[p.offset..end] (FSSM, keeping f.error.is_none() and p.offset.checked_add(p.len) checks intact) and calling analyze(code, true).is_some().

Part of #2508
Part of #1833

Tested

  • Edge-case parity & release before-vs-after benchmark (streaming_matches_reference_of_across_edge_cases): Verifies byte-identical of() and analyze(c, true).is_some() parity against verbatim pre-fix of_reference() across empty code, early memory write + trailing undecodable/OOB branch/S_CODE_END, early S_ENDPGM + post-end store, valid & OOB S_SETPC_B64 (including S_SETPC_B64 as final instruction and combined with memory writes), S_SWAPPC_B64/S_CALL_B64, < BIG_CODE, valid & errored FSSM and FSPX containers, and 64 deterministic pseudo-random instruction streams.
    • Release timing (50 iterations on synthetic ~25,000-inst / ~100 KiB FSSM blobs, including xbox::parse):
      • Image-only 100 KiB shader (big_and_image_only): 21,567.7 µs -> 18,940.5 µs (-12.2%, WARP run) / 29,736.1 µs -> 26,312.4 µs (-11.5%, RTX run).
      • Early-memory-write 100 KiB shader (big_and_image_only): 21,436.2 µs -> 12,541.7 µs (-41.5%, WARP run) / 24,440.0 µs -> 12,920.7 µs (-47.1%, RTX run).
  • Post-fix WARP targeted tests (XCL_ADAPTER=warp, XCL_WARP=1, cargo test --release -p xcl --lib "gpu::effects::tests::" -- --test-threads=1 --nocapture): 8 passed; 0 failed; 0 ignored; 0 skipped (3.74s, zero compiler warnings in effects.rs).
  • Clippy check (cargo clippy --all-targets): 0 new warnings in crates/xcl/src/gpu/effects.rs (only the 2 pre-existing type_complexity lints on untouched existing test lines asm and writers).
  • Post-fix RTX 4060 targeted tests (cargo test --release -p xcl --lib "gpu::effects::tests::" -- --test-threads=1 --nocapture): 8 passed; 0 failed; 0 ignored; 0 skipped (4.70s).

Regression run

  • Full release workspace on RTX 4060 (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture): 37 test binaries, 1436 passed; 0 failed; 47 ignored, 29 pre-existing environment-gated SKIPPED lines:

    • 21 skipped: no wave64 (RTX 4060 is wave32)
    • 3 skipped: wave32 per-lane form: refused by driver (f16 arithmetic, f16 packed, f32 conversions)
    • 3 skipped: no D3D12 debug layer (d3d12SDKLayers.dll unavailable on host: debug-layer dred: false/true and uploads_start_from_each_subresources_state)
    • 1 skipped: pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache on Windows)
    • 1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • Paired 60 s RTX 4060 smoke capture (scripts/smoke.ps1):

Base (origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1570 (PresentX 1571)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 13980 MB

PR (caed44ec41eb77a2d619df1f43536e64bab705b6):

xcl-smoke v1
commit: caed44ec41eb77a2d619df1f43536e64bab705b6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1521 (PresentX 1521)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14010 MB

Not tested

  • Full cold-start PSO-build wall-clock profiling across a large retail compute-shader cache beyond the synthetic 100 KiB benchmarks and 60 s smoke capture.
  • The 29 host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).

AI use

Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, benchmarks, and paired 60 s GPU smoke captures were executed directly in this workspace.

<!-- greyfinch-sync:ivall/xcl:issue:5504385562 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T05:10:36Z. --- **What is in it** Eliminates full-shader `Vec<Decoded>` / `HashSet<u64>` allocations and `Vec<u8>` compute-blob copies in `crates/xcl/src/gpu/effects.rs`, and adds an early-exit path for memory-writing shaders in `big_and_image_only`: - **Single-pass streaming analysis (`analyze` + `update_writes`):** Streams `rdna2::decode` over `&code[off..]` preserving the exact `ended` / `S_CODE_END` stop rules and `update_writes` classification (`ENC_MIMG`, `ENC_MUBUF`/`MTBUF`/`FLAT`/`FLAT_GLBL`/`FLAT_SCRATCH`/`SMEM`, `ENC_DS` `GDS`/append/consume/ordered-count/`DS_GWS_*`). Collects monotonically increasing `d.pc` into `pcs` (capped initially to `(code.len() / 6).min(256)` when `stop_on_memory` is enabled so early-exiting memory writers avoid large upfront allocations) and validates branch targets with `pcs.binary_search(t)` instead of building a `HashSet<u64>`. - **Dedicated far-jump fallback (`analyze_with_far_jumps`):** Delegates only when `S_SETPC_B64` is encountered (after `S_CODE_END` / early-memory-exit checks), runs `rdna2::resolve_far_jumps(&mut insts)`, preserves the exact `last` terminator / `S_BRANCH` / `far_target` check, and validates branch/indirect targets via `insts.binary_search_by_key(&t, |x| x.pc)`. - **Zero-copy `big_and_image_only` with early exit on memory writes:** Replaces `compute_code() -> Option<Vec<u8>>` with `is_big_image_only_code(code: &[u8]) -> bool` borrowing `&f.code` (FSPX) and `&f.data[p.offset..end]` (FSSM, keeping `f.error.is_none()` and `p.offset.checked_add(p.len)` checks intact) and calling `analyze(code, true).is_some()`. Part of #2508 Part of #1833 **Tested** - **Edge-case parity & release before-vs-after benchmark (`streaming_matches_reference_of_across_edge_cases`):** Verifies byte-identical `of()` and `analyze(c, true).is_some()` parity against verbatim pre-fix `of_reference()` across empty code, early memory write + trailing undecodable/OOB branch/`S_CODE_END`, early `S_ENDPGM` + post-end store, valid & OOB `S_SETPC_B64` (including `S_SETPC_B64` as final instruction and combined with memory writes), `S_SWAPPC_B64`/`S_CALL_B64`, `< BIG_CODE`, valid & errored FSSM and FSPX containers, and 64 deterministic pseudo-random instruction streams. - Release timing (50 iterations on synthetic ~25,000-inst / ~100 KiB FSSM blobs, including `xbox::parse`): - Image-only 100 KiB shader (`big_and_image_only`): `21,567.7 µs` -> `18,940.5 µs` (`-12.2%`, WARP run) / `29,736.1 µs` -> `26,312.4 µs` (`-11.5%`, RTX run). - Early-memory-write 100 KiB shader (`big_and_image_only`): `21,436.2 µs` -> `12,541.7 µs` (`-41.5%`, WARP run) / `24,440.0 µs` -> `12,920.7 µs` (`-47.1%`, RTX run). - **Post-fix WARP targeted tests** (`XCL_ADAPTER=warp`, `XCL_WARP=1`, `cargo test --release -p xcl --lib "gpu::effects::tests::" -- --test-threads=1 --nocapture`): `8 passed; 0 failed; 0 ignored; 0 skipped` (`3.74s`, zero compiler warnings in `effects.rs`). - **Clippy check** (`cargo clippy --all-targets`): `0` new warnings in `crates/xcl/src/gpu/effects.rs` (only the 2 pre-existing `type_complexity` lints on untouched existing test lines `asm` and `writers`). - **Post-fix RTX 4060 targeted tests** (`cargo test --release -p xcl --lib "gpu::effects::tests::" -- --test-threads=1 --nocapture`): `8 passed; 0 failed; 0 ignored; 0 skipped` (`4.70s`). **Regression run** - **Full release workspace on RTX 4060** (`cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture`): `37` test binaries, `1436 passed; 0 failed; 47 ignored`, `29` pre-existing environment-gated `SKIPPED` lines: - `21` skipped: `no wave64` (RTX 4060 is wave32) - `3` skipped: wave32 `per-lane form: refused` by driver (`f16 arithmetic`, `f16 packed`, `f32 conversions`) - `3` skipped: no D3D12 debug layer (`d3d12SDKLayers.dll` unavailable on host: debug-layer `dred: false`/`true` and `uploads_start_from_each_subresources_state`) - `1` skipped: `pso_measurement_compiles_an_exact_synthetic_record` (cannot disable driver cache on Windows) - `1` skipped: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - **Paired 60 s RTX 4060 smoke capture (`scripts/smoke.ps1`):** Base (`origin/main` `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1570 (PresentX 1571) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 13980 MB ``` PR (`caed44ec41eb77a2d619df1f43536e64bab705b6`): ``` xcl-smoke v1 commit: caed44ec41eb77a2d619df1f43536e64bab705b6 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1521 (PresentX 1521) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14010 MB ``` **Not tested** - Full cold-start PSO-build wall-clock profiling across a large retail compute-shader cache beyond the synthetic 100 KiB benchmarks and 60 s smoke capture. - The `29` host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows). **AI use** Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, benchmarks, and paired 60 s GPU smoke captures were executed directly in this workspace.
luckyteagirl commented 2026-11-26 05:12:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:12:42Z.

Review: COMMENTED


Could analyze_with_far_jumps also cap its initial capacity when stop_on_memory is true? An early S_SETPC_B64 reaches this reservation before any store is checked. If a buffer store follows shortly after it, the function immediately returns, but it has already requested code.len()/6 full Decoded slots instead of a small initial buffer. Main copied the code bytes but grew its decoded-instruction storage on demand. A far-jump-before-store fixture with a long retained suffix would exercise this early-reject path. Source review only at head caed44ec; I did not measure peak memory or timing. AI-assisted with Codex (GPT-6.2 Sol).

<!-- greyfinch-sync:ivall/xcl:review:6068871790 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#pullrequestreview-6068871790). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T05:12:42Z. **Review:** COMMENTED --- Could `analyze_with_far_jumps` also cap its initial capacity when `stop_on_memory` is true? An early `S_SETPC_B64` reaches this reservation before any store is checked. If a buffer store follows shortly after it, the function immediately returns, but it has already requested `code.len()/6` full `Decoded` slots instead of a small initial buffer. Main copied the code bytes but grew its decoded-instruction storage on demand. A far-jump-before-store fixture with a long retained suffix would exercise this early-reject path. Source review only at head `caed44ec`; I did not measure peak memory or timing. AI-assisted with Codex (GPT-6.2 Sol).
DarkPanda69 commented 2026-11-26 06:06:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T05:28:06Z.


Native wave64 run (the wave64 tests skipped on the RTX 4060) on an AMD RX 9070 XT, plus an RTX 3060: the new test passes, and nothing else changes in the GPU suite.

Head caed44e applied on main b49be18, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, card chosen with XCL_ADAPTER:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010) 708 passed, 2 failed, 6 SKIPPED 709 passed, 2 failed, 6 SKIPPED
RTX 3060 (32.0.16.1088) 710 passed, 0 failed, 24 SKIPPED 711 passed, 0 failed, 24 SKIPPED

On both cards, the only result change against main is the new streaming_matches_reference_of_across_edge_cases (ok), with no new skips. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on main.

Not tested: cold-start PSO timings on a retail cache, the D3D12 debug-layer tests (no d3d12SDKLayers.dll here either), a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7183511478 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7183511478). Originally posted by [DarkPanda69](https://github.com/DarkPanda69) on 2026-11-26T05:28:06Z. --- Native wave64 run (the wave64 tests skipped on the RTX 4060) on an AMD RX 9070 XT, plus an RTX 3060: the new test passes, and nothing else changes in the GPU suite. Head `caed44e` applied on `main` `b49be18`, debug, Windows 11 Pro 26200, `cargo test -p xcl --lib -- gpu:: --test-threads=4` on `main` and with the PR, card chosen with `XCL_ADAPTER`: | | `main` | this PR | |---|---|---| | RX 9070 XT (RDNA4, 32.0.32029.2010) | 708 passed, 2 failed, 6 SKIPPED | 709 passed, 2 failed, 6 SKIPPED | | RTX 3060 (32.0.16.1088) | 710 passed, 0 failed, 24 SKIPPED | 711 passed, 0 failed, 24 SKIPPED | On both cards, the only result change against `main` is the new `streaming_matches_reference_of_across_edge_cases` (ok), with no new skips. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on `main`. Not tested: cold-start PSO timings on a retail cache, the D3D12 debug-layer tests (no `d3d12SDKLayers.dll` here either), a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
SlopTart commented 2026-11-26 06:06:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-26T05:34:11Z.


Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.
Targeted run of streaming_matches_reference_of_across_edge_cases: passed (2.78 s).

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7183605481 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7183605481). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-26T05:34:11Z. --- **Tested**: current PR head merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). `gpu_` suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV. Targeted run of `streaming_matches_reference_of_across_edge_cases`: passed (2.78 s). **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
github-actions[bot] commented 2026-12-01 02:32:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:32:43Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298731129 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7298731129). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:32:43Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 08:35:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:35:42Z.


Triage (#1607) – head caed44e

Main already has this change: commit b66b5b03 ("Recompiler: stream gpu::effects without Vec/HashSet and avoid copying compute blobs", merged with the #2959 stack) makes the same 196/36-line change to crates/xcl/src/gpu/effects.rs, including analyze, analyze_with_far_jumps, is_big_image_only_code and the same test. The only difference from main is in analyze_with_far_jumps, where main's later commit e1634cd8 caps the initial allocation; this PR would undo that.
Recommendation: close (superseded by main commit b66b5b03).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7305525875 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7305525875). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:35:42Z. --- **Triage (#1607)** – head caed44e Main already has this change: commit b66b5b03 ("Recompiler: stream gpu::effects without Vec<Decoded>/HashSet and avoid copying compute blobs", merged with the #2959 stack) makes the same 196/36-line change to crates/xcl/src/gpu/effects.rs, including `analyze`, `analyze_with_far_jumps`, `is_big_image_only_code` and the same test. The only difference from main is in `analyze_with_far_jumps`, where main's later commit e1634cd8 caps the initial allocation; this PR would undo that. Recommendation: close (superseded by main commit b66b5b03). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:57:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:57:03Z.


Closing as superseded: this change is already on main (b66b5b03). PR's changed lines are identical to main b66b5b03 (gpu::effects streaming change; compared line by line, 234 lines both); main later added e1634cd8 on top

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311884123 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7311884123). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:57:03Z. --- Closing as superseded: this change is already on `main` (b66b5b03). PR's changed lines are identical to main b66b5b03 (gpu::effects streaming change; compared line by line, 234 lines both); main later added e1634cd8 on top Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2646
No description provided.