Shaders: move capture hashing off lock and offload xbox stats #1026

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

@⁠rdj415 on GitHub · 2026-11-24 10:28 UTC · original
rdj415:shaders-capture-lock-offload → main · +168 −18 · 1 files · 1 commits · open

Move shader validation, in-place FNV-1a hashing, and container classification outside the global STATE lock in gpu::shader::capture, and offload non-dump account_xbox FSSM decompression and RDNA2 instruction counting to a low-priority background worker flushed by shader::stats().

A retail title submits 200k+ shader blobs across parallel loading threads while >98% are duplicates of ~3.6k-19k unique shaders (e.g. 204,736 submissions for 3,579 unique shaders in the first 60 s, 15.67M RDNA2 instructions). Previously shader::capture held the global STATE mutex across readable(), heap-copying every duplicate into a Vec<u8>, fnv64(), and classify(), and then ran account_xbox() synchronously on the title's loading threads.

What is in it

  • crates/xcl/src/gpu/shader.rs: run readable() and fnv64() directly on the borrowed slice outside STATE, skip allocating Vec<u8> on duplicate hashes, avoid String allocations on existing stage/kind keys, classify unique blobs outside STATE, and offload non-dump account_xbox() to a low-priority xcl-shader-stats worker thread with a bounded flush in stats().
  • crates/xcl/src/gpu/shader.rs: unit tests covering concurrent multi-thread deduplication, deterministic worker flush on stats(), and unreadable-pointer rejection.

Tested

  • Hardware: NVIDIA GeForce RTX 5060 Ti (16052 MiB VRAM, driver 32.0.16.1664, 32-lane waves), Intel Core i5-12400F, Windows 11 Pro 10.0.26300 (Build 26300), Rust rustc 1.98.0-nightly (096694416 2026-06-29) (x86_64-pc-windows-msvc), Windows SDK DXC 1.8.2502.11 (10.0.26100.0).
  • cargo test -p xcl --lib gpu::shader::tests: 7 passed, 0 failed, 0 ignored.
  • .\scripts\test.ps1 (debug): 675 passed, 3 failed (pre-existing #718 cubemap reuse flake placed_title_textures_share_vram_and_preserve_pixels + 2 PoisonError cascades), 21 ignored; 2 GPU tests skipped (no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware). On a second lib run (cargo test --workspace --tests -- --test-threads=4), all 3 #718 tests passed (677 passed, 1 failed from pre-existing #913 OOM in cross_queue_cycle_and_same_queue_fifo_do_not_deadlock, which passed in isolation: 1 passed, 0 failed).
  • cargo test -p xcl --test '*' -- --test-threads=4 (all integration tests including e2e.rs): 41 passed, 0 failed, 20 ignored.
  • Retail title 60 s smoke run (scripts/smoke.ps1): report.json preserved exact unique=3579, rdna2_instructions=15665903, xbox_hw_stages={"CS":2734,"PS":508,"VS":228} on both main and PR head, while frames shown increased from 500 to 694 in 60 s.

Regression run

main:

xcl-smoke v1
commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 500 (PresentX 500)
presents per 2 s (last 3): 60 62 60
device removals: 0
crashes: 0
peak commit: 8851 MB

PR:

xcl-smoke v1
commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b
gpu: NVIDIA GeForce RTX 5060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 694 (PresentX 694)
presents per 2 s (last 3): 57 60 60
device removals: 0
crashes: 0
peak commit: 8885 MB

Not tested

  • AMD / Intel GPUs and native wave64 tests (skipped on NVIDIA RTX 5060 Ti).
  • XCL_DUMP_SHADERS=1 disk dump path (behavior unchanged, not exercised during smoke run).
  • XCL_SAMPLE_* sample-data tests (environment variables unset).

AI use

  • Antigravity 2.0 (Gemini 4 Neon): diagnosed the contention/accounting overhead in shader::capture, wrote the implementation, unit tests, commit message, and PR description; all builds, tests, and smoke runs were executed on the hardware named above.
**@⁠rdj415** on GitHub · 2026-11-24 10:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026) `rdj415:shaders-capture-lock-offload` → `main` · +168 −18 · 1 files · 1 commits · open Move shader validation, in-place FNV-1a hashing, and container classification outside the global `STATE` lock in `gpu::shader::capture`, and offload non-dump `account_xbox` FSSM decompression and RDNA2 instruction counting to a low-priority background worker flushed by `shader::stats()`. A retail title submits 200k+ shader blobs across parallel loading threads while >98% are duplicates of ~3.6k-19k unique shaders (e.g. 204,736 submissions for 3,579 unique shaders in the first 60 s, 15.67M RDNA2 instructions). Previously `shader::capture` held the global `STATE` mutex across `readable()`, heap-copying every duplicate into a `Vec<u8>`, `fnv64()`, and `classify()`, and then ran `account_xbox()` synchronously on the title's loading threads. **What is in it** - `crates/xcl/src/gpu/shader.rs`: run `readable()` and `fnv64()` directly on the borrowed slice outside `STATE`, skip allocating `Vec<u8>` on duplicate hashes, avoid `String` allocations on existing stage/kind keys, classify unique blobs outside `STATE`, and offload non-dump `account_xbox()` to a low-priority `xcl-shader-stats` worker thread with a bounded flush in `stats()`. - `crates/xcl/src/gpu/shader.rs`: unit tests covering concurrent multi-thread deduplication, deterministic worker flush on `stats()`, and unreadable-pointer rejection. **Tested** - Hardware: NVIDIA GeForce RTX 5060 Ti (16052 MiB VRAM, driver 32.0.16.1664, 32-lane waves), Intel Core i5-12400F, Windows 11 Pro 10.0.26300 (Build 26300), Rust `rustc 1.98.0-nightly (096694416 2026-06-29)` (`x86_64-pc-windows-msvc`), Windows SDK DXC 1.8.2502.11 (10.0.26100.0). - `cargo test -p xcl --lib gpu::shader::tests`: 7 passed, 0 failed, 0 ignored. - `.\scripts\test.ps1` (debug): 675 passed, 3 failed (pre-existing #718 cubemap reuse flake `placed_title_textures_share_vram_and_preserve_pixels` + 2 `PoisonError` cascades), 21 ignored; 2 GPU tests skipped (no wave64: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`). On a second lib run (`cargo test --workspace --tests -- --test-threads=4`), all 3 #718 tests passed (677 passed, 1 failed from pre-existing #913 OOM in `cross_queue_cycle_and_same_queue_fifo_do_not_deadlock`, which passed in isolation: 1 passed, 0 failed). - `cargo test -p xcl --test '*' -- --test-threads=4` (all integration tests including `e2e.rs`): 41 passed, 0 failed, 20 ignored. - Retail title 60 s smoke run (`scripts/smoke.ps1`): `report.json` preserved exact `unique=3579`, `rdna2_instructions=15665903`, `xbox_hw_stages={"CS":2734,"PS":508,"VS":228}` on both `main` and PR head, while frames shown increased from 500 to 694 in 60 s. **Regression run** main: ``` xcl-smoke v1 commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a gpu: NVIDIA GeForce RTX 5060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 500 (PresentX 500) presents per 2 s (last 3): 60 62 60 device removals: 0 crashes: 0 peak commit: 8851 MB ``` PR: ``` xcl-smoke v1 commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b gpu: NVIDIA GeForce RTX 5060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 694 (PresentX 694) presents per 2 s (last 3): 57 60 60 device removals: 0 crashes: 0 peak commit: 8885 MB ``` **Not tested** - AMD / Intel GPUs and native wave64 tests (skipped on NVIDIA RTX 5060 Ti). - `XCL_DUMP_SHADERS=1` disk dump path (behavior unchanged, not exercised during smoke run). - `XCL_SAMPLE_*` sample-data tests (environment variables unset). **AI use** - Antigravity 2.0 (Gemini 4 Neon): diagnosed the contention/accounting overhead in `shader::capture`, wrote the implementation, unit tests, commit message, and PR description; all builds, tests, and smoke runs were executed on the hardware named above.
A retail title submits 200k+ shader blobs across parallel loading threads while >98% are duplicates of ~3.6k-19k unique shaders. Previously shader::capture held the global STATE mutex across readable(), heap-copying every duplicate into a Vec, fnv64(), and classify(), and then ran account_xbox() (FSSM decompression and RDNA2 disassembly) synchronously on the title's loading threads.

Validate readable(), hash the slice in place without copying duplicates, and classify unique blobs outside STATE. Offload non-dump account_xbox() to a low-priority worker thread (xcl-shader-stats) that stats() flushes with a bounded wait before reading STATE so report.json and e2e counts stay identical.

Assisted-by: Antigravity IDE (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:41:02 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 11:31 UTC · original

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib shader: 27 passed, 0 failed, 2 ignored (bench + retail-sample tests) — includes capture_deduplicates_across_threads_and_flushes_xbox_stats and capture_flushes_multiple_unique_console_shaders_from_worker, which exercise the new off-lock hashing/stats path. fnv64 now runs on the borrowed slice before the copy, dedup seen.insert happens under a short lock, and classification/unique accounting moved off it — the lock is no longer held across to_vec/classify.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

**@⁠DavidM1911** on GitHub · 2026-11-24 11:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026#issuecomment-7130211923) Independent verification, merged onto current `main` `384f7f7` locally (clean merge). **Machine:** Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug. - `cargo test -p xcl --lib shader`: **27 passed, 0 failed, 2 ignored** (bench + retail-sample tests) — includes `capture_deduplicates_across_threads_and_flushes_xbox_stats` and `capture_flushes_multiple_unique_console_shaders_from_worker`, which exercise the new off-lock hashing/stats path. `fnv64` now runs on the borrowed slice before the copy, dedup `seen.insert` happens under a short lock, and classification/unique accounting moved off it — the lock is no longer held across `to_vec`/`classify`. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Author
Owner

@⁠throny on GitHub · 2026-11-25 09:20 UTC · original

Test report for exact head 870de7d.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 870de7d as it is (its own base): 719 passed, 0 failed, 41 ignored. SKIPPED: 2 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15841 MB

PR:

xcl-smoke v1
commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b
gpu: NVIDIA GeForce RTX 4080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17407 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

**@⁠throny** on GitHub · 2026-11-25 09:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026#issuecomment-7158199512) Test report for exact head `870de7d`. **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release. - `cargo build --workspace && cargo test --workspace -- --test-threads=4` on `870de7d` as it is (its own base): **719 passed, 0 failed, 41 ignored**. `SKIPPED`: 2 lines (no wave64 on this adapter, and the like). - `scripts/smoke.ps1`, the retail title, 60 s, release builds, `main` `568e7db` first, then this head: main: ``` xcl-smoke v1 commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb gpu: NVIDIA GeForce RTX 4080 title: 21222967 seconds: 60 exit: 0x0 frames shown: 1608 (PresentX 1608) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15841 MB ``` PR: ``` xcl-smoke v1 commit: 870de7ddbcbbfe425c46eb5e574740ca2469b93b gpu: NVIDIA GeForce RTX 4080 title: retail-title seconds: 60 exit: 0x0 frames shown: 1571 (PresentX 1571) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17407 MB ``` **Not tested:** AMD, the head merged onto current `main`, a world load. AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.
Author
Owner

@⁠4usphs on GitHub · 2026-11-25 11:52 UTC · original

AMD run on the exact head 870de7d (870de7ddbc), as pushed on its base 077ce40 (not merged onto current main), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.

Tested

  • Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, XCL_TRANSLATED_CACHE=0; adapter picked with XCL_ADAPTER.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: 716 passed, 3 failed, 41 ignored
    • AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, gfx1036), driver 32.0.21045.29003: 716 passed, 3 failed, 41 ignored
  • No SKIPPED tests on either adapter.
  • This PR's tests capture_deduplicates_across_threads_and_flushes_xbox_stats, capture_flushes_multiple_unique_console_shaders_from_worker, capture_rejects_unreadable_pointer_without_polluting_seen run and pass on both adapters.
  • The 3 failures on each adapter are the title-texture group (placed_title_textures_share_vram_and_preserve_pixels at its cubemap reuse check, transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory): the intermittent failure of #718, which takes the other two with it (#673), not this PR. They pass on their own on this head. cargo test -p xcl --lib -- --test-threads=4 on the base 077ce40 fails the same 3 on the iGPU (that run passed on the RX 9070 XT, so it is intermittent there too).

Not tested

  • smoke or a retail title (I have none), a release build, Linux.

AI use

  • Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
**@⁠4usphs** on GitHub · 2026-11-25 11:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026#issuecomment-7161620782) AMD run on the exact head `870de7d` (870de7ddbcbbfe425c46eb5e574740ca2469b93b), as pushed on its base `077ce40` (not merged onto current `main`), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2. **Tested** - Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, `XCL_TRANSLATED_CACHE=0`; adapter picked with `XCL_ADAPTER`. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: - AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: **716 passed, 3 failed, 41 ignored** - AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, `gfx1036`), driver 32.0.21045.29003: **716 passed, 3 failed, 41 ignored** - No `SKIPPED` tests on either adapter. - This PR's tests `capture_deduplicates_across_threads_and_flushes_xbox_stats`, `capture_flushes_multiple_unique_console_shaders_from_worker`, `capture_rejects_unreadable_pointer_without_polluting_seen` run and pass on both adapters. - The 3 failures on each adapter are the title-texture group (`placed_title_textures_share_vram_and_preserve_pixels` at its cubemap reuse check, `transitions_apply_when_their_list_is_submitted`, `d32s8_targets_take_their_own_size_of_video_memory`): the intermittent failure of #718, which takes the other two with it (#673), not this PR. They pass on their own on this head. `cargo test -p xcl --lib -- --test-threads=4` on the base `077ce40` fails the same 3 on the iGPU (that run passed on the RX 9070 XT, so it is intermittent there too). **Not tested** - smoke or a retail title (I have none), a release build, Linux. **AI use** - Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-25 12:28 UTC · original

Linux / AMD RDNA4 (RADV) test report for head 870de7d merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, --test-threads=1 --nocapture)

  • gpu::shader::tests: 7 passed, 0 failed, 0 ignored, 0 skipped (0.04 s), including capture_deduplicates_across_threads_and_flushes_xbox_stats, capture_flushes_multiple_unique_console_shaders_from_worker, and capture_rejects_unreadable_pointer_without_polluting_seen.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

**@⁠ClosetPie107** on GitHub · 2026-11-25 12:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026#issuecomment-7162418161) Linux / AMD RDNA4 (RADV) test report for head `870de7d` merged locally onto `main` `1a0bbe3` (clean merge). **Environment** - AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS - Proton Experimental (`experimental-11.0-20261112`), vkd3d-proton v3.1 (`#257` + `dxil-spirv` `53aac418`), DXVK `v3.1.1-209`, DXC `1.9.2609.5`, `x86_64-pc-windows-gnu` cross-compile **Tested** (debug test binary under Wine, `--test-threads=1 --nocapture`) - `gpu::shader::tests`: **7 passed, 0 failed, 0 ignored, 0 skipped** (0.04 s), including `capture_deduplicates_across_threads_and_flushes_xbox_stats`, `capture_flushes_multiple_unique_console_shaders_from_worker`, and `capture_rejects_unreadable_pointer_without_polluting_seen`. **Not tested:** full workspace suite, retail title run, native Windows. **AI use:** T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 03:40 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 03:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1026#issuecomment-7181930543) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/1026/head:github-bot/gh-1026'
git switch 'github-bot/gh-1026'

Merge

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