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

Open
github-bot wants to merge 1 commit from github-bot/gh-2656 into main AGit
Owner

@⁠Decodere on GitHub · 2026-11-26 05:10 UTC · original
Decodere:fix-gpu-effects-streaming-and-zero-copy → main · +196 −36 · 1 files · 1 commits · open

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.

**@⁠Decodere** on GitHub · 2026-11-26 05:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2656) `Decodere:fix-gpu-effects-streaming-and-zero-copy` → `main` · +196 −36 · 1 files · 1 commits · open **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.
Replace Vec<Decoded> + HashSet<u64> in gpu::effects::of with a single-pass
streaming decoder over sorted instruction PCs, delegating to an explicit
far-jump path only when S_SETPC_B64 appears. Add early-exit on memory
writes and zero-copy slice borrowing for FSPX and FSSM compute shaders in
big_and_image_only.

Part of #2508
Part of #1833
Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:44 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-26 05:28 UTC · original

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.

**@⁠DarkPanda69** on GitHub · 2026-11-26 05:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7183511478) 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.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-26 05:34 UTC · original

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.

**@⁠SlopTart** on GitHub · 2026-11-26 05:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/2656#issuecomment-7183605481) **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.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 05:12 UTC · original · reviewed

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).

**@⁠luckyteagirl** on GitHub · 2026-11-26 05:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2656#pullrequestreview-6068871790) · **reviewed** 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).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2656/head:github-bot/gh-2656'
git switch 'github-bot/gh-2656'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2656'
git switch 'github-bot/gh-2656'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2656'
git switch 'github-bot/gh-2656'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2656'
git switch 'main'
git merge --squash 'github-bot/gh-2656'
git switch 'main'
git merge --ff-only 'github-bot/gh-2656'
git switch 'main'
git merge 'github-bot/gh-2656'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.